| skipped 19 lines |
20 | 20 | | |
21 | 21 | | #include <sys/utsname.h> |
22 | 22 | | |
23 | | - | #include <sys/time.h> |
24 | | - | #include <sys/resource.h> |
25 | | - | |
26 | 23 | | #include "int.h" |
27 | 24 | | #include "page.h" |
28 | 25 | | #include "common/compiler.h" |
| skipped 21 lines |
50 | 47 | | #include "setproctitle.h" |
51 | 48 | | #include "sysctl.h" |
52 | 49 | | |
53 | | - | static void rlimit_unlimit_nofile(void) |
54 | | - | { |
55 | | - | struct rlimit new; |
56 | | - | |
57 | | - | new.rlim_cur = kdat.sysctl_nr_open; |
58 | | - | new.rlim_max = kdat.sysctl_nr_open; |
59 | | - | |
60 | | - | if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) { |
61 | | - | pr_perror("rlimit: Can't setup RLIMIT_NOFILE for self"); |
62 | | - | return; |
63 | | - | } else |
64 | | - | pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n"); |
65 | | - | |
66 | | - | service_fd_rlim_cur = kdat.sysctl_nr_open; |
67 | | - | } |
68 | | - | |
69 | | - | static int early_init(const char *cmd) |
70 | | - | { |
71 | | - | static const char *nofile_cmds[] = { |
72 | | - | "swrk", "service", |
73 | | - | "dump", "pre-dump", |
74 | | - | "restore", |
75 | | - | }; |
76 | | - | size_t i; |
77 | | - | |
78 | | - | /* |
79 | | - | * Service fd engine implies that file descriptors |
80 | | - | * used won't be borrowed by the rest of the code |
81 | | - | * and default 1024 limit is not enough for high |
82 | | - | * loaded test/containers. Thus use kdat engine |
83 | | - | * to fetch current system level limit for numbers |
84 | | - | * of files allowed to open up and lift up own |
85 | | - | * limits. |
86 | | - | * |
87 | | - | * Note we have to do it before the service fd |
88 | | - | * get inited and we dont exit with errors here |
89 | | - | * because in worst scenario where clash of fd |
90 | | - | * happen we simply exit with explicit error |
91 | | - | * during real action stage. |
92 | | - | * |
93 | | - | * Same time raising limits cause kernel fdtable |
94 | | - | * to bloat so we do this only on the @nofile_cmds: |
95 | | - | * |
96 | | - | * - on dump criu needs additional files for sfd, |
97 | | - | * thus if container already has many files opened |
98 | | - | * we need to have at least not less space when |
99 | | - | * fetching fds from a target process; |
100 | | - | * |
101 | | - | * - on pre-dump we might need a lot of pipes to |
102 | | - | * fetch huge number of pages to dump; |
103 | | - | * |
104 | | - | * - on restore we still need to raise limits since |
105 | | - | * there is no guarantee that on dump we've not |
106 | | - | * been hitting fd limit already; |
107 | | - | * |
108 | | - | * - swrk and service obtain requests on the fly, |
109 | | - | * thus we don't know if on of above will be |
110 | | - | * there thus raise limits. |
111 | | - | */ |
112 | | - | for (i = 0; i < ARRAY_SIZE(nofile_cmds); i++) { |
113 | | - | if (strcmp(nofile_cmds[i], cmd)) |
114 | | - | continue; |
115 | | - | if (!kerndat_files_stat(true)) |
116 | | - | rlimit_unlimit_nofile(); |
117 | | - | break; |
118 | | - | } |
119 | | - | |
120 | | - | if (init_service_fd()) |
121 | | - | return 1; |
122 | | - | |
123 | | - | return 0; |
124 | | - | } |
125 | | - | |
126 | 50 | | int main(int argc, char *argv[], char *envp[]) |
127 | 51 | | { |
128 | 52 | | int ret = -1; |
| skipped 28 lines |
157 | 81 | | goto usage; |
158 | 82 | | |
159 | 83 | | log_set_loglevel(opts.log_level); |
160 | | - | |
161 | | - | if (early_init(argv[optind])) |
162 | | - | return -1; |
163 | 84 | | |
164 | 85 | | if (!strcmp(argv[1], "swrk")) { |
165 | 86 | | if (argc < 3) |
| skipped 357 lines |