[CRIU] [PATCH 1/2] files-reg: Use global mutex to serialize ghost
file creation
Cyrill Gorcunov
gorcunov at openvz.org
Mon Sep 17 11:14:22 EDT 2012
Otherwise there is a race between files with same names.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-restore.c | 2 ++
files-reg.c | 17 ++++++++++++++++-
include/files-reg.h | 2 ++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index 49c78e4..92c3175 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -94,6 +94,8 @@ static int prepare_shared(void)
if (prepare_shared_tty())
return -1;
+ if (prepare_shared_reg_files())
+ return -1;
if (collect_reg_files())
return -1;
diff --git a/files-reg.c b/files-reg.c
index b459130..6ffa6fa 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -43,6 +43,8 @@ struct ghost_file {
static u32 ghost_file_ids = 1;
static LIST_HEAD(ghost_files);
+mutex_t *ghost_file_mutex;
+
/*
* This constant is selected without any calculations. Just do not
* want to pick up too big files with us in the image.
@@ -351,12 +353,14 @@ static int open_path(struct file_desc *d,
rfi = container_of(d, struct reg_file_info, d);
- if (rfi->ghost)
+ if (rfi->ghost) {
+ mutex_lock(ghost_file_mutex);
if (link(rfi->ghost->path, rfi->path) < 0) {
pr_perror("Can't link %s -> %s\n",
rfi->ghost->path, rfi->path);
return -1;
}
+ }
tmp = open_cb(rfi, arg);
if (tmp < 0) {
@@ -370,6 +374,7 @@ static int open_path(struct file_desc *d,
pr_info("Unlink the ghost %s\n", rfi->ghost->path);
unlink(rfi->ghost->path);
}
+ mutex_unlock(ghost_file_mutex);
}
if (restore_fown(tmp, rfi->rfe->fown))
@@ -438,6 +443,16 @@ static int collect_one_regfile(void *o, ProtobufCMessage *base)
return 0;
}
+int prepare_shared_reg_files(void)
+{
+ ghost_file_mutex = shmalloc(sizeof(*ghost_file_mutex));
+ if (!ghost_file_mutex)
+ return -1;
+
+ mutex_init(ghost_file_mutex);
+ return 0;
+}
+
int collect_reg_files(void)
{
int ret;
diff --git a/include/files-reg.h b/include/files-reg.h
index f728449..6064442 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -24,6 +24,8 @@ extern int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *
extern void clear_ghost_files(void);
extern int collect_reg_files(void);
+extern int prepare_shared_reg_files(void);
+
extern int dump_reg_file(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset);
extern int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p);
--
1.7.7.6
More information about the CRIU
mailing list