[CRIU] [PATCH 2/7] servicefd: Add mechanism to find unused high fds

David Francis David.Francis at amd.com
Sat May 17 00:05:34 MSK 2025


During restore, the amdgpu plugin must hold onto fds for
dmabufs as they are transferred from one process to another.

These fds must be chosen not to conflict with other fds used by
restore.

Extend the service_fd system, which already finds unused fds,
to allow request of an unused fd.

Signed-off-by: David Francis <David.Francis at amd.com>
---
 criu/include/servicefd.h |  1 +
 criu/servicefd.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/criu/include/servicefd.h b/criu/include/servicefd.h
index 4265d94ed..f74d8ef43 100644
--- a/criu/include/servicefd.h
+++ b/criu/include/servicefd.h
@@ -47,5 +47,6 @@ extern int install_service_fd(enum sfd_type type, int fd);
 extern int close_service_fd(enum sfd_type type);
 extern void __close_service_fd(enum sfd_type type);
 extern int clone_service_fd(struct pstree_item *me);
+extern int get_unused_high_fd(void);
 
 #endif /* __CR_SERVICE_FD_H__ */
diff --git a/criu/servicefd.c b/criu/servicefd.c
index 06a8d3eba..5034a19f3 100644
--- a/criu/servicefd.c
+++ b/criu/servicefd.c
@@ -25,6 +25,7 @@ int service_fd_rlim_cur;
 
 /* Base of current process service fds set */
 static int service_fd_base;
+static int next_high_fd;
 
 /* Id of current process in shared fdt */
 static int service_fd_id = 0;
@@ -312,5 +313,15 @@ int clone_service_fd(struct pstree_item *me)
 	service_fd_id = id;
 	ret = 0;
 
+	next_high_fd = service_fd_base + 1024;
+
 	return ret;
 }
+
+int get_unused_high_fd(void)
+{
+	if (next_high_fd > service_fd_rlim_cur)
+		return -1;
+	next_high_fd += 1;
+	return next_high_fd - 1;
+}
-- 
2.34.1



More information about the CRIU mailing list