[CRIU] [PATCH 4/5] criu: set RLIMIT_NOFILE to maximum only on restore
Andrei Vagin
avagin at virtuozzo.com
Thu Sep 13 02:41:14 MSK 2018
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/cr-restore.c | 32 ++++++++++++++++++++++++++++++++
criu/crtools.c | 32 --------------------------------
criu/files.c | 3 ++-
3 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 2014d87f5..804a33f83 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2340,10 +2340,42 @@ int prepare_dummy_task_state(struct pstree_item *pi)
return 0;
}
+static void rlimit_unlimit_nofile_self(void)
+{
+ struct rlimit new;
+
+ new.rlim_cur = kdat.sysctl_nr_open;
+ new.rlim_max = kdat.sysctl_nr_open;
+
+ if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) {
+ pr_perror("rlimir: Can't setup RLIMIT_NOFILE for self");
+ return;
+ } else
+ pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
+ service_fd_rlim_cur = kdat.sysctl_nr_open;
+}
+
int cr_restore_tasks(void)
{
int ret = -1;
+ /*
+ * Service fd engine implies that file descriptors
+ * used won't be borrowed by the rest of the code
+ * and default 1024 limit is not enough for high
+ * loaded test/containers. Thus use kdat engine
+ * to fetch current system level limit for numbers
+ * of files allowed to open up and lift up own
+ * limits.
+ *
+ * Note we have to do it before the service fd
+ * get inited and we dont exit with errors here
+ * because in worst scenario where clash of fd
+ * happen we simply exit with explicit error
+ * during real action stage.
+ */
+ rlimit_unlimit_nofile_self();
+
if (cr_plugin_init(CR_PLUGIN_STAGE__RESTORE))
return -1;
diff --git a/criu/crtools.c b/criu/crtools.c
index eb5ff9b86..8e98d1599 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -53,40 +53,8 @@
#include "sysctl.h"
#include "img-remote.h"
-static void rlimit_unlimit_nofile_self(void)
-{
- struct rlimit new;
-
- new.rlim_cur = kdat.sysctl_nr_open;
- new.rlim_max = kdat.sysctl_nr_open;
-
- if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) {
- pr_perror("rlimir: Can't setup RLIMIT_NOFILE for self");
- return;
- } else
- pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
-}
-
static int early_init(void)
{
- /*
- * Service fd engine implies that file descritprs
- * used won't be borrowed by the rest of the code
- * and default 1024 limit is not enough for high
- * loaded test/containers. Thus use kdat engine
- * to fetch current system level limit for numbers
- * of files allowed to open up and lift up own
- * limits.
- *
- * Note we have to do it before the service fd
- * get inited and we don't exit with errors here
- * because in worst scenario where clash of fd
- * happen we simply exit with explicit error
- * during real action stage.
- */
- if (!kerndat_files_stat(true))
- rlimit_unlimit_nofile_self();
-
if (init_service_fd())
return 1;
diff --git a/criu/files.c b/criu/files.c
index 81ee7004f..115390f63 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -44,6 +44,7 @@
#include "autofs.h"
#include "parasite.h"
#include "parasite-syscall.h"
+#include "kerndat.h"
#include "protobuf.h"
#include "util.h"
@@ -898,7 +899,7 @@ int prepare_fd_pid(struct pstree_item *item)
if (ret <= 0)
break;
- if (e->fd >= service_fd_min_fd(item)) {
+ if (e->fd >= kdat.sysctl_nr_open) {
ret = -1;
pr_err("Too big FD number to restore %d\n", e->fd);
break;
--
2.14.3
More information about the CRIU
mailing list