Commit a148e874 authored by Andrei Vagin's avatar Andrei Vagin Committed by Andrei Vagin

criu: set RLIMIT_NOFILE to maximum only on restore

Reviewed-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent d3499999
...@@ -2339,10 +2339,42 @@ int prepare_dummy_task_state(struct pstree_item *pi) ...@@ -2339,10 +2339,42 @@ int prepare_dummy_task_state(struct pstree_item *pi)
return 0; 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 cr_restore_tasks(void)
{ {
int ret = -1; 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)) if (cr_plugin_init(CR_PLUGIN_STAGE__RESTORE))
return -1; return -1;
......
...@@ -52,40 +52,8 @@ ...@@ -52,40 +52,8 @@
#include "setproctitle.h" #include "setproctitle.h"
#include "sysctl.h" #include "sysctl.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) 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()) if (init_service_fd())
return 1; return 1;
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "autofs.h" #include "autofs.h"
#include "parasite.h" #include "parasite.h"
#include "parasite-syscall.h" #include "parasite-syscall.h"
#include "kerndat.h"
#include "protobuf.h" #include "protobuf.h"
#include "util.h" #include "util.h"
...@@ -898,7 +899,7 @@ int prepare_fd_pid(struct pstree_item *item) ...@@ -898,7 +899,7 @@ int prepare_fd_pid(struct pstree_item *item)
if (ret <= 0) if (ret <= 0)
break; break;
if (e->fd >= service_fd_min_fd(item)) { if (e->fd >= kdat.sysctl_nr_open) {
ret = -1; ret = -1;
pr_err("Too big FD number to restore %d\n", e->fd); pr_err("Too big FD number to restore %d\n", e->fd);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment