[CRIU] [PATCH] dump: global image names introduced
Kinsbursky Stanislav
skinsbursky at openvz.org
Mon Mar 19 08:13:38 EDT 2012
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
crtools.c | 6 ++++++
include/crtools.h | 4 ++++
util.c | 10 +++++++++-
3 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/crtools.c b/crtools.c
index 7b8c2af..8d70adf 100644
--- a/crtools.c
+++ b/crtools.c
@@ -236,6 +236,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 a6a15cb..af82b43 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -106,6 +106,9 @@ int open_image(int type, unsigned long flags, ...);
#define open_image_ro(type, ...) open_image(type, O_RDONLY, __VA_ARGS__);
extern int open_image_ro_nocheck(const char *fmt, int pid);
+#define open_glob_image_ro(type) open_image(type, O_RDONLY);
+#define open_glob_image_ro_nocheck(fmt) open_image_ro_nocheck(fmt, 0);
+
#define LAST_PID_PATH "/proc/sys/kernel/ns_last_pid"
#define LAST_PID_PERM 0666
@@ -145,6 +148,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 681acc4..a66782a 100644
--- a/util.c
+++ b/util.c
@@ -166,6 +166,7 @@ int open_image(int type, unsigned long flags, ...)
char path[PATH_MAX];
va_list args;
int ret;
+ int write_magic = 1;
va_start(args, flags);
vsnprintf(path, PATH_MAX, fdset_template[type].fmt, args);
@@ -179,6 +180,13 @@ int open_image(int type, unsigned long flags, ...)
}
}
+ if (flags & O_APPEND) {
+ struct stat tmp;
+
+ if (stat(path, &tmp) == 0)
+ write_magic = 0;
+ }
+
ret = openat(image_dir_fd, path, flags, CR_FD_PERM);
if (ret < 0) {
pr_perror("Unable to open %s", path);
@@ -194,7 +202,7 @@ int open_image(int type, unsigned long flags, ...)
pr_err("Magic doesn't match for %s\n", path);
goto err;
}
- } else {
+ } else if (write_magic) {
if (write_img(ret, &fdset_template[type].magic))
goto err;
}
More information about the CRIU
mailing list