[CRIU] [PATCH 19/21] pipes: Dump and show fifo files

Cyrill Gorcunov gorcunov at openvz.org
Wed Jun 6 18:21:59 EDT 2012


Basically pipes are superset over fifos,
so we integrate fifo dumping into pipes.c.

The restore will be addressed in another patch.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c       |    8 +++++-
 cr-show.c       |   15 ++++++++++-
 include/image.h |   10 ++++++++
 include/pipes.h |    3 ++
 pipes.c         |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 94 insertions(+), 8 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 1b6c2f6..bed4267 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -495,8 +495,12 @@ static int dump_one_file(pid_t pid, int fd, int lfd, char fd_flags,
             S_ISDIR(p.stat.st_mode))
 		return dump_reg_file(&p, lfd, cr_fdset);
 
-	if (S_ISFIFO(p.stat.st_mode) && (statfs.f_type == PIPEFS_MAGIC))
-		return dump_pipe(&p, lfd, cr_fdset);
+	if (S_ISFIFO(p.stat.st_mode)) {
+		if (statfs.f_type == PIPEFS_MAGIC)
+			return dump_pipe(&p, lfd, cr_fdset);
+		else
+			return dump_fifo(&p, lfd, cr_fdset);
+	}
 
 	return dump_unsupp_fd(&p);
 }
diff --git a/cr-show.c b/cr-show.c
index 31c1565..207203b 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -22,6 +22,7 @@
 #include "image.h"
 #include "uts_ns.h"
 #include "ipc_ns.h"
+#include "pipes.h"
 
 #define DEF_PAGES_PER_LINE	6
 
@@ -206,9 +207,19 @@ void show_pipes(int fd_pipes, struct cr_options *o)
 		ret = read_img_eof(fd_pipes, &e);
 		if (ret <= 0)
 			goto out;
-		pr_msg("id: 0x%8x pipeid: 0x%8x flags: 0x%8x ",
-		       e.id, e.pipe_id, e.flags);
+		pr_msg("id: 0x%8x pipeid: 0x%8x type: %4s flags: 0x%8x ",
+		       e.id, e.pipe_id, pipetype2s(e.type), e.flags);
 		show_fown_cont(&e.fown);
+
+		if (e.len) {
+			int ret = read(fd_pipes, local_buf, e.len);
+			if (ret != e.len) {
+				pr_perror("Can't read %d bytes", e.len);
+				goto out;
+			}
+			local_buf[e.len] = 0;
+			pr_msg(" --> %s", local_buf);
+		}
 		pr_msg("\n");
 	}
 
diff --git a/include/image.h b/include/image.h
index 4acbc86..6374e75 100644
--- a/include/image.h
+++ b/include/image.h
@@ -147,11 +147,21 @@ struct pstree_entry {
 	u32	nr_threads;
 } __packed;
 
+enum {
+	PIPE_TYPE_ANON,
+	PIPE_TYPE_FIFO,
+
+	PIPE_TYPE_MAX,
+};
+
 struct pipe_entry {
 	u32	id;
 	u32	pipe_id;
 	u32	flags;
 	fown_t	fown;
+	u16	type;
+	u16	len;
+	u8	name[0];
 } __packed;
 
 struct pipe_data_entry {
diff --git a/include/pipes.h b/include/pipes.h
index 59a34dc..3a92ca8 100644
--- a/include/pipes.h
+++ b/include/pipes.h
@@ -1,8 +1,11 @@
 #ifndef CR_PIPES_H__
 #define CR_PIPES_H__
 
+extern char *pipetype2s(int type);
+
 extern int collect_pipes(void);
 extern void mark_pipe_master(void);
 extern int dump_pipe(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset);
+extern int dump_fifo(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset);
 
 #endif /* CR_PIPES_H__ */
diff --git a/pipes.c b/pipes.c
index c3aa240..f2bec6a 100644
--- a/pipes.c
+++ b/pipes.c
@@ -9,6 +9,7 @@
 #include "files.h"
 #include "pipes.h"
 #include "util-net.h"
+#include "proc_parse.h"
 
 /*
  * The sequence of objects which should be restored:
@@ -30,6 +31,20 @@ struct pipe_info {
 
 static LIST_HEAD(pipes);
 
+char *pipetype2s(int type)
+{
+	static char *str[PIPE_TYPE_MAX + 1] = {
+		[PIPE_TYPE_ANON]	= "anon",
+		[PIPE_TYPE_FIFO]	= "fifo",
+		[PIPE_TYPE_MAX]		= "unknown",
+	};
+
+	if (type >= PIPE_TYPE_MAX)
+		type = PIPE_TYPE_MAX;
+
+	return str[type];
+}
+
 static void show_saved_pipe_fds(struct pipe_info *pi)
 {
 	struct fdinfo_list_entry *fle;
@@ -394,23 +409,50 @@ err:
 	return ret;
 }
 
-static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
+static int dump_one_typed_pipe(int type, int lfd, u32 id, const struct fd_parms *p)
 {
 	struct pipe_entry pe;
+	char *path;
 
-	pr_info("Dumping pipe %d with id %#x pipe_id %#x\n", lfd, id, p->id);
+	if (type >= PIPE_TYPE_MAX) {
+		pr_err("Unknown pipe type %d on %d\n", type, p->fd);
+		return -1;
+	}
+
+	pr_info("Dumping %s %d with id %#x pipe_id %#x\n",
+		pipetype2s(type), lfd, id, p->id);
 
 	pe.id		= id;
 	pe.pipe_id	= p->id;
 	pe.flags	= p->flags;
 	pe.fown		= p->fown;
+	pe.type		= type;
 
-	if (write_img(fdset_fd(glob_fdset, CR_FD_PIPES), &pe))
-		return -1;
+	switch (type) {
+	case PIPE_TYPE_ANON:
+		pe.len = 0;
+		if (write_img(fdset_fd(glob_fdset, CR_FD_PIPES), &pe))
+			return -1;
+		break;
+	case PIPE_TYPE_FIFO:
+		path = read_proc_selffd_link(lfd, (int *)&pe.len);
+		if (!path)
+			return -1;
+		if (write_img(fdset_fd(glob_fdset, CR_FD_PIPES), &pe))
+			return -1;
+		if (write_img_buf(fdset_fd(glob_fdset, CR_FD_PIPES), path, pe.len))
+			return -1;
+		break;
+	}
 
 	return dump_one_pipe_data(lfd, id, p);
 }
 
+static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
+{
+	return dump_one_typed_pipe(PIPE_TYPE_ANON, lfd, id, p);
+}
+
 static const struct fdtype_ops pipe_ops = {
 	.type		= FDINFO_PIPE,
 	.make_gen_id	= make_gen_id,
@@ -421,3 +463,19 @@ int dump_pipe(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset)
 {
 	return do_dump_gen_file(p, lfd, &pipe_ops, cr_fdset);
 }
+
+static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p)
+{
+	return dump_one_typed_pipe(PIPE_TYPE_FIFO, lfd, id, p);
+}
+
+static const struct fdtype_ops fifo_ops = {
+	.type		= FDINFO_PIPE,
+	.make_gen_id	= make_gen_id,
+	.dump		= dump_one_fifo,
+};
+
+int dump_fifo(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset)
+{
+	return do_dump_gen_file(p, lfd, &fifo_ops, cr_fdset);
+}
-- 
1.7.7.6



More information about the CRIU mailing list