[CRIU] [PATCH 3/4] files: Make fd_id_generate_special return ID into pointer

Pavel Emelyanov xemul at parallels.com
Tue Feb 4 08:03:30 PST 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dump.c          | 36 ++++++++++++++++++++----------------
 file-ids.c         |  5 +++--
 files-reg.c        |  3 ++-
 include/file-ids.h |  2 +-
 sk-unix.c          |  2 +-
 5 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 5f0b617..a69e733 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -244,7 +244,7 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
 static int dump_task_exe_link(pid_t pid, MmEntry *mm)
 {
 	struct fd_parms params = FD_PARMS_INIT;
-	int fd, ret;
+	int fd, ret = 0;
 
 	fd = open_proc(pid, "exe");
 	if (fd < 0)
@@ -255,11 +255,10 @@ static int dump_task_exe_link(pid_t pid, MmEntry *mm)
 		return -1;
 	}
 
-	mm->exe_file_id = fd_id_generate_special(&params.stat);
+	if (fd_id_generate_special(&params.stat, &mm->exe_file_id))
+		ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
 
-	ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
 	close(fd);
-
 	return ret;
 }
 
@@ -281,11 +280,11 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
 		return -1;
 	}
 
-	fe.cwd_id = fd_id_generate_special(&p.stat);
-
-	ret = dump_one_reg_file(fd, fe.cwd_id, &p);
-	if (ret < 0)
-		return ret;
+	if (fd_id_generate_special(&p.stat, &fe.cwd_id)) {
+		ret = dump_one_reg_file(fd, fe.cwd_id, &p);
+		if (ret < 0)
+			return ret;
+	}
 
 	close(fd);
 
@@ -299,11 +298,11 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
 		return -1;
 	}
 
-	fe.root_id = fd_id_generate_special(&p.stat);
-
-	ret = dump_one_reg_file(fd, fe.root_id, &p);
-	if (ret < 0)
-		return ret;
+	if (fd_id_generate_special(&p.stat, &fe.root_id)) {
+		ret = dump_one_reg_file(fd, fe.root_id, &p);
+		if (ret < 0)
+			return ret;
+	}
 
 	close(fd);
 
@@ -348,6 +347,8 @@ static int dump_filemap(pid_t pid, struct vma_area *vma_area,
 {
 	struct fd_parms p = FD_PARMS_INIT;
 	VmaEntry *vma = vma_area->e;
+	int ret = 0;
+	u32 id;
 
 	BUG_ON(!vma_area->st);
 	p.stat = *vma_area->st;
@@ -356,9 +357,12 @@ static int dump_filemap(pid_t pid, struct vma_area *vma_area,
 		p.flags = O_RDWR;
 	else
 		p.flags = O_RDONLY;
-	vma->shmid = fd_id_generate_special(&p.stat);
 
-	return dump_one_reg_file(vma_area->vm_file_fd, vma->shmid, &p);
+	if (fd_id_generate_special(&p.stat, &id))
+		ret = dump_one_reg_file(vma_area->vm_file_fd, id, &p);
+
+	vma->shmid = id;
+	return ret;
 }
 
 static int check_sysvipc_map_dump(pid_t pid, VmaEntry *vma)
diff --git a/file-ids.c b/file-ids.c
index 70fabc8..7cac60f 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -26,9 +26,10 @@ void fd_id_show_tree(void)
 	kid_show_tree(&fd_tree);
 }
 
-u32 fd_id_generate_special(struct stat *st)
+int fd_id_generate_special(struct stat *st, u32 *id)
 {
-	return fd_tree.subid++;
+	*id = fd_tree.subid++;
+	return 1;
 }
 
 int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st)
diff --git a/files-reg.c b/files-reg.c
index 424c300..28e963c 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -382,7 +382,8 @@ static int create_link_remap(char *path, int len, int lfd, u32 *idp)
 		tmp--;
 	}
 
-	rfe.id = *idp	= fd_id_generate_special(NULL);
+	fd_id_generate_special(NULL, idp);
+	rfe.id		= *idp;
 	rfe.flags	= 0;
 	rfe.pos		= 0;
 	rfe.fown	= &fwn;
diff --git a/include/file-ids.h b/include/file-ids.h
index bd838ef..28434f3 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -14,7 +14,7 @@ struct fdinfo_entry;
 struct stat;
 
 extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct stat *st);
-extern u32 fd_id_generate_special(struct stat *);
+extern int fd_id_generate_special(struct stat *, u32 *id);
 extern void fd_id_show_tree(void);
 
 #endif /* __CR_FILE_IDS_H__ */
diff --git a/sk-unix.c b/sk-unix.c
index f82fd67..c2991ae 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -581,7 +581,7 @@ int fix_external_unix_sockets(void)
 
 		BUG_ON(sk->sd.already_dumped);
 
-		e.id		= fd_id_generate_special(NULL);
+		fd_id_generate_special(NULL, &e.id);
 		e.ino		= sk->sd.ino;
 		e.type		= SOCK_DGRAM;
 		e.state		= TCP_LISTEN;
-- 
1.8.4.2


More information about the CRIU mailing list