[CRIU] [PATCH 19/39] files-ids: generate id-s accoding with mnt_id, st->st_dev and st->st_ino

Andrey Vagin avagin at openvz.org
Mon Apr 21 07:23:29 PDT 2014


One device can be mounted a few times, so files are identical only,
if they have the same mnt_id.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c          |  8 ++++----
 file-ids.c         | 32 +++++++++++++++++++-------------
 files.c            |  2 +-
 include/file-ids.h |  5 +++--
 4 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 471ee9e..14a4098 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -278,7 +278,7 @@ static int dump_task_exe_link(pid_t pid, MmEntry *mm)
 	if (fill_fd_params_special(fd, &params))
 		return -1;
 
-	if (fd_id_generate_special(&params.stat, &mm->exe_file_id))
+	if (fd_id_generate_special(&params, &mm->exe_file_id))
 		ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
 
 	close(fd);
@@ -301,7 +301,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
 	if (fill_fd_params_special(fd, &p))
 		return -1;
 
-	if (fd_id_generate_special(&p.stat, &fe.cwd_id)) {
+	if (fd_id_generate_special(&p, &fe.cwd_id)) {
 		ret = dump_one_reg_file(fd, fe.cwd_id, &p);
 		if (ret < 0)
 			return ret;
@@ -316,7 +316,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
 	if (fill_fd_params_special(fd, &p))
 		return -1;
 
-	if (fd_id_generate_special(&p.stat, &fe.root_id)) {
+	if (fd_id_generate_special(&p, &fe.root_id)) {
 		ret = dump_one_reg_file(fd, fe.root_id, &p);
 		if (ret < 0)
 			return ret;
@@ -370,7 +370,7 @@ static int dump_filemap(pid_t pid, struct vma_area *vma_area,
 
 	/* Flags will be set during restore in get_filemap_fd() */
 
-	if (fd_id_generate_special(&p.stat, &id))
+	if (fd_id_generate_special(&p, &id))
 		ret = dump_one_reg_file(vma_area->vm_file_fd, id, &p);
 
 	vma->shmid = id;
diff --git a/file-ids.c b/file-ids.c
index 30f1bbc..3226d15 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -18,6 +18,7 @@
 #include "image.h"
 #include "util.h"
 #include "irmap.h"
+#include "files.h"
 
 static DECLARE_KCMP_TREE(fd_tree, KCMP_FILE);
 
@@ -36,6 +37,7 @@ static inline int fdid_hashfn(unsigned int s_dev, unsigned long i_ino)
 }
 
 struct fd_id {
+	int mnt_id;
 	unsigned int dev;
 	unsigned long ino;
 	u32 id;
@@ -44,41 +46,45 @@ struct fd_id {
 
 static struct fd_id *fd_id_cache[FDID_SIZE];
 
-static void fd_id_cache_one(u32 id, struct stat *st)
+static void fd_id_cache_one(u32 id, struct fd_parms *p)
 {
 	struct fd_id *fi;
 	unsigned hv;
 
 	fi = xmalloc(sizeof(*fi));
 	if (fi) {
-		fi->dev = st->st_dev;
-		fi->ino = st->st_ino;
+		fi->dev = p->stat.st_dev;
+		fi->ino = p->stat.st_ino;
+		fi->mnt_id = p->mnt_id;
 		fi->id = id;
 
-		hv = fdid_hashfn(st->st_dev, st->st_ino);
+		hv = fdid_hashfn(p->stat.st_dev, p->stat.st_ino);
 		fi->n = fd_id_cache[hv];
 		fd_id_cache[hv] = fi;
 	}
 }
 
-static struct fd_id *fd_id_cache_lookup(struct stat *st)
+static struct fd_id *fd_id_cache_lookup(struct fd_parms *p)
 {
+	struct stat *st = &p->stat;
 	struct fd_id *fi;
 
 	for (fi = fd_id_cache[fdid_hashfn(st->st_dev, st->st_ino)];
 			fi; fi = fi->n)
-		if (fi->dev == st->st_dev && fi->ino == st->st_ino)
+		if (fi->dev == st->st_dev &&
+		    fi->ino == st->st_ino &&
+		    fi->mnt_id == p->mnt_id)
 			return fi;
 
 	return NULL;
 }
 
-int fd_id_generate_special(struct stat *st, u32 *id)
+int fd_id_generate_special(struct fd_parms *p, u32 *id)
 {
-	if (st) {
+	if (p) {
 		struct fd_id *fi;
 
-		fi = fd_id_cache_lookup(st);
+		fi = fd_id_cache_lookup(p);
 		if (fi) {
 			*id = fi->id;
 			return 0;
@@ -86,12 +92,12 @@ int fd_id_generate_special(struct stat *st, u32 *id)
 	}
 
 	*id = fd_tree.subid++;
-	if (st)
-		fd_id_cache_one(*id, st);
+	if (p)
+		fd_id_cache_one(*id, p);
 	return 1;
 }
 
-int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st)
+int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p)
 {
 	u32 id;
 	struct kid_elem e;
@@ -106,7 +112,7 @@ int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st)
 		return -ENOMEM;
 
 	if (new_id)
-		fd_id_cache_one(id, st);
+		fd_id_cache_one(id, p);
 
 	fe->id = id;
 	return new_id;
diff --git a/files.c b/files.c
index e8682a6..96f0330 100644
--- a/files.c
+++ b/files.c
@@ -171,7 +171,7 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
 	e.fd	= p->fd;
 	e.flags = p->fd_flags;
 
-	ret = fd_id_generate(p->pid, &e, &p->stat);
+	ret = fd_id_generate(p->pid, &e, p);
 	if (ret == 1) /* new ID generated */
 		ret = ops->dump(lfd, e.id, p);
 
diff --git a/include/file-ids.h b/include/file-ids.h
index 28434f3..6323d98 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -13,8 +13,9 @@
 struct fdinfo_entry;
 struct stat;
 
-extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st);
-extern int fd_id_generate_special(struct stat *, u32 *id);
+struct fd_parms;
+extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p);
+extern int fd_id_generate_special(struct fd_parms *p, u32 *id);
 extern void fd_id_show_tree(void);
 
 #endif /* __CR_FILE_IDS_H__ */
-- 
1.8.5.3



More information about the CRIU mailing list