[CRIU] fifo: Sanitize fifo restore

Pavel Emelyanov xemul at parallels.com
Sun Jul 1 09:56:32 EDT 2012


Don't push open cb onto reg_file_into, pass it into regfiles engine
as an argument.

Note: I haven't merged the fifo zdtms yet, thus this patch is untested.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

-------------- next part --------------
diff --git a/fifo.c b/fifo.c
index 8e227c0..22007c0 100644
--- a/fifo.c
+++ b/fifo.c
@@ -72,9 +72,9 @@ int dump_fifo(struct fd_parms *p, int lfd, const struct cr_fdset *set)
 	return do_dump_gen_file(p, lfd, &fifo_ops, set);
 }
 
-static int __open_fifo_fd(struct reg_file_info *rfi)
+static int do_open_fifo(struct reg_file_info *rfi, void *arg)
 {
-	struct fifo_info *info = rfi->priv;
+	struct fifo_info *info = arg;
 	int new_fifo, fake_fifo = -1;
 
 	/*
@@ -111,24 +111,8 @@ out:
 static int open_fifo_fd(struct file_desc *d)
 {
 	struct fifo_info *info = container_of(d, struct fifo_info, d);
-	struct reg_file_info *rfi;
-	struct file_desc *rd;
 
-	pr_info("\t\tCreating fifo pipe_id=%#x id=%#x\n",
-		info->fe.pipe_id, info->fe.id);
-
-	rd = find_file_desc_raw(FDINFO_REG, info->fe.id);
-	if (!rd) {
-		pr_perror("Can't find regfile for fifo %#x\n", info->fe.id);
-		return -1;
-	}
-
-	rfi = container_of(rd, struct reg_file_info, d);
-	if (rfi->open != __open_fifo_fd)
-		rfi->open = __open_fifo_fd;
-	rfi->priv = info;
-
-	return open_fe_fd(rd);
+	return open_path_by_id(info->fe.id, do_open_fifo, info);
 }
 
 static struct file_desc_ops fifo_desc_ops = {
diff --git a/files-reg.c b/files-reg.c
index 0dbb660..0e38a78 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -340,12 +340,8 @@ int dump_reg_file(struct fd_parms *p, int lfd,
 	return do_dump_gen_file(p, lfd, &regfile_ops, cr_fdset);
 }
 
-static int __open_reg_fd(struct reg_file_info *rfi)
-{
-	return open(rfi->path, rfi->rfe.flags);
-}
-
-int open_fe_fd(struct file_desc *d)
+static int open_path(struct file_desc *d,
+		int(*open_cb)(struct reg_file_info *, void *), void *arg)
 {
 	struct reg_file_info *rfi;
 	int tmp;
@@ -359,7 +355,7 @@ int open_fe_fd(struct file_desc *d)
 			return -1;
 		}
 
-	tmp = rfi->open(rfi);
+	tmp = open_cb(rfi, arg);
 	if (tmp < 0) {
 		pr_perror("Can't open file %s", rfi->path);
 		return -1;
@@ -376,7 +372,7 @@ int open_fe_fd(struct file_desc *d)
 	return tmp;
 }
 
-int open_reg_by_id(u32 id)
+int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void *arg)
 {
 	struct file_desc *fd;
 
@@ -386,7 +382,22 @@ int open_reg_by_id(u32 id)
 		return -1;
 	}
 
-	return open_fe_fd(fd);
+	return open_path(fd, open_cb, arg);
+}
+
+static int do_open_reg(struct reg_file_info *rfi, void *arg)
+{
+	return open(rfi->path, rfi->rfe.flags);
+}
+
+static int open_fe_fd(struct file_desc *fd)
+{
+	return open_path(fd, do_open_reg, NULL);
+}
+
+int open_reg_by_id(u32 id)
+{
+	return open_path_by_id(id, do_open_reg, NULL);
 }
 
 static struct file_desc_ops reg_desc_ops = {
@@ -419,7 +430,6 @@ int collect_reg_files(void)
 			break;
 
 		rfi->remap_path = NULL;
-		rfi->open = __open_reg_fd;
 
 		pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id);
 		file_desc_add(&rfi->d, rfi->rfe.id, &reg_desc_ops);
diff --git a/include/files-reg.h b/include/files-reg.h
index 7de5bb5..08d5170 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -15,15 +15,12 @@ struct reg_file_info {
 
 	char			*remap_path;
 	char			*path;
-
-	int			(*open)(struct reg_file_info *rfi);
-	void			*priv;
 };
 
 extern int open_reg_by_id(u32 id);
+extern int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void *arg);
 extern void clear_ghost_files(void);
 extern int collect_reg_files(void);
-extern int open_fe_fd(struct file_desc *d);
 
 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);


More information about the CRIU mailing list