[CRIU] [PATCH 1/2] fds: Introduce service fd-s

Pavel Emelyanov xemul at parallels.com
Fri Mar 16 09:21:45 EDT 2012


These are the fds that help us to do c/r. We want them not to intersect
with any "real-life" ones and thus store them close the the file rlimit
boundary. For now only the logfd one is such.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

-------------- next part --------------
diff --git a/include/crtools.h b/include/crtools.h
index ee35cc7..ac8710d 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -56,6 +56,13 @@ struct cr_options {
 	unsigned int		namespaces_flags;
 };
 
+enum {
+	LOG_FD_OFF = 1,
+	IMG_FD_OFF,
+};
+
+int get_service_fd(int type);
+
 /* file descriptors template */
 struct cr_fd_desc_tmpl {
 	const char	*fmt;			/* format for the name */
diff --git a/log.c b/log.c
index 70f0b9d..c183b52 100644
--- a/log.c
+++ b/log.c
@@ -15,6 +15,7 @@
 #include "compiler.h"
 #include "types.h"
 #include "util.h"
+#include "crtools.h"
 
 #define DEFAULT_LOGLEVEL	LOG_WARN
 #define DEFAULT_LOGFD		STDERR_FILENO
@@ -29,25 +30,14 @@ int log_get_fd(void)
 
 int log_init(const char *output)
 {
-	struct rlimit rlimit;
 	int new_logfd = DEFAULT_LOGFD;
 
-	if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
-		pr_perror("Can't get rlimit");
-		return -1;
+	current_logfd = get_service_fd(LOG_FD_OFF);
+	if (current_logfd < 0) {
+		pr_msg("Can't obtain logfd");
+		goto err;
 	}
 
-	/*
-	 * We might need to transfer this descriptors
-	 * to another process' address space (and file
-	 * descriptors space) so we try to minimize
-	 * potential conflict between descriptors and
-	 * try to reopen them somewhere near a limit.
-	 *
-	 * Still an explicit output file might be
-	 * requested.
-	 */
-
 	if (output) {
 		new_logfd = open(output, O_CREAT | O_WRONLY);
 		if (new_logfd < 0) {
@@ -56,7 +46,6 @@ int log_init(const char *output)
 		}
 	}
 
-	current_logfd = rlimit.rlim_cur - 1;
 	if (reopen_fd_as(current_logfd, new_logfd) < 0)
 		goto err;
 
diff --git a/util.c b/util.c
index 72c2c8f..729de54 100644
--- a/util.c
+++ b/util.c
@@ -247,3 +261,21 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...)
 
 	return openat(dirfd, path, flags);
 }
+
+int get_service_fd(int type)
+{
+	struct rlimit rlimit;
+
+	/*
+	 * Service FDs are thouse that most likely won't
+	 * conflict with any 'real-life' ones
+	 */
+
+	if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
+		pr_perror("Can't get rlimit");
+		return -1;
+	}
+
+	return rlimit.rlim_cur - type;
+}
+


More information about the CRIU mailing list