[CRIU] [PATCH 3/5] criu: remove all magic of service-fd when it isn't required

Andrei Vagin avagin at virtuozzo.com
Thu Sep 13 02:41:13 MSK 2018


Service descriptors are a set of file descriptors which isn't
intercepted with restored file descriptors.

In all cases, when we don't need to restore file descriptors, we can
skip all magic of service-fd and just save descriptor numbers in a
static array.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/util.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/criu/util.c b/criu/util.c
index bc932923c..e2f947e8a 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -454,8 +454,6 @@ int init_service_fd(void)
 	}
 
 	service_fd_rlim_cur = (int)rlimit.rlim_cur;
-	service_fd_base = service_fd_rlim_cur;
-	BUG_ON(service_fd_base < SERVICE_FD_MAX);
 
 	return 0;
 }
@@ -476,6 +474,7 @@ int service_fd_min_fd(struct pstree_item *item)
 }
 
 static DECLARE_BITMAP(sfd_map, SERVICE_FD_MAX);
+static int sfd_arr[SERVICE_FD_MAX];
 /*
  * Variable for marking areas of code, where service fds modifications
  * are prohibited. It's used to safe them from reusing their numbers
@@ -498,6 +497,12 @@ int install_service_fd(enum sfd_type type, int fd)
 	if (sfds_protected && !test_bit(type, sfd_map))
 		sfds_protection_bug(type);
 
+	if (service_fd_base == 0) {
+		sfd_arr[type] = fd;
+		set_bit(type, sfd_map);
+		return fd;
+	}
+
 	if (dup3(fd, sfd, O_CLOEXEC) != sfd) {
 		pr_perror("Dup %d -> %d failed", fd, sfd);
 		close(fd);
@@ -516,6 +521,9 @@ int get_service_fd(enum sfd_type type)
 	if (!test_bit(type, sfd_map))
 		return -1;
 
+	if (service_fd_base == 0)
+		return sfd_arr[type];
+
 	return __get_service_fd(type, service_fd_id);
 }
 
-- 
2.14.3



More information about the CRIU mailing list