[CRIU] [PATCH 3/4] dump: global image files helpers introduced

Kinsbursky Stanislav skinsbursky at openvz.org
Fri Mar 16 06:25:47 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Global images will be opened in non-exclusive append mode.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 crtools.c         |   17 ++++++++++++++++-
 include/crtools.h |    3 +++
 util.c            |   10 ++++++++++
 3 files changed, 29 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/crtools.c b/crtools.c
index 469a7b3..8e721c0 100644
--- a/crtools.c
+++ b/crtools.c
@@ -199,6 +199,8 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
 		fdset = cr_fdset;
 
 	for (i = 0; i < CR_FD_MAX; i++) {
+		int write_magic = 1;
+
 		if (!(use_mask & CR_FD_DESC_USE(i)))
 			continue;
 
@@ -218,6 +220,13 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
 			}
 		}
 
+		if (flags & O_APPEND) {
+			struct stat tmp;
+
+			if (stat(path, &tmp) == 0)
+				write_magic = 0;
+		}
+
 		ret = open(path, flags, CR_FD_PERM);
 		if (ret < 0) {
 			if (!(flags & O_CREAT))
@@ -237,7 +246,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
 				pr_err("Magic doesn't match for %s\n", path);
 				goto err;
 			}
-		} else {
+		} else if (write_magic) {
 			if (write_img(ret, &fdset_template[i].magic))
 				goto err;
 		}
@@ -265,6 +274,12 @@ struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask)
 	return cr_fdset_open(pid, use_mask, O_RDONLY, NULL);
 }
 
+struct cr_fdset *cr_glob_fdset_open(unsigned long use_mask,
+				    struct cr_fdset *cr_fdset)
+{
+	return cr_fdset_open(0, use_mask, O_WRONLY | O_APPEND | O_CREAT, cr_fdset);
+}
+
 static int parse_ns_string(const char *ptr, unsigned int *flags)
 {
 	const char *end = ptr + strlen(ptr);
diff --git a/include/crtools.h b/include/crtools.h
index 6806cc3..32b8d54 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -88,7 +88,9 @@ extern int get_image_path(char *path, int size, const char *fmt, int pid);
 
 extern char image_dir[];
 extern int open_image_ro(int type, int pid);
+extern int open_glob_image_ro(int type);
 extern int open_image_ro_nocheck(const char *fmt, int pid);
+extern int open_glob_image_ro_nocheck(const char *fmt);
 
 #define LAST_PID_PATH		"/proc/sys/kernel/ns_last_pid"
 #define LAST_PID_PERM		0666
@@ -129,6 +131,7 @@ int cr_check(void);
 
 struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
 struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask);
+struct cr_fdset *cr_glob_fdset_open(unsigned long use_mask, struct cr_fdset *);
 void close_cr_fdset(struct cr_fdset **cr_fdset);
 
 void free_mappings(struct list_head *vma_area_list);
diff --git a/util.c b/util.c
index 1996180..0bf398d 100644
--- a/util.c
+++ b/util.c
@@ -179,6 +179,11 @@ int open_image_ro_nocheck(const char *fmt, int pid)
 	return tmp;
 }
 
+int open_glob_image_ro_nocheck(const char *fmt)
+{
+	return open_image_ro_nocheck(fmt, 0);
+}
+
 int open_image_ro(int type, int pid)
 {
 	int fd;
@@ -198,6 +203,11 @@ int open_image_ro(int type, int pid)
 	return fd;
 }
 
+int open_glob_image_ro(int type)
+{
+	return open_image_ro(type, 0);
+}
+
 static pid_t open_proc_pid = 0;
 static int open_proc_fd = -1;
 


More information about the CRIU mailing list