[CRIU] [PATCH 10/15] img: Mark unbufferred images

Pavel Emelyanov xemul at parallels.com
Mon Sep 29 01:49:23 PDT 2014


We have some images that store raw data together with
the pb objects (and one that just stores raw data) and
use custom access to this. E.g. pipe-data images splice
data into them and sk-queue one lseeks the image for
queue packets.

For those using buffered mode mixed with raw may lead
to troubles. Explicitly mark such images, so that the
buffering (next patches) handle such images carefully.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 image-desc.c         | 32 ++++++++++++++++++++------------
 image.c              |  3 ++-
 include/image-desc.h |  1 +
 include/image.h      |  6 ++++--
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/image-desc.c b/image-desc.c
index 3ce7ab5..3f0a63d 100644
--- a/image-desc.c
+++ b/image-desc.c
@@ -3,6 +3,7 @@
 #include "image-desc.h"
 #include "cr-show.h"
 #include "magic.h"
+#include "image.h"
 
 /*
  * The cr fd set is the set of files where the information
@@ -17,6 +18,13 @@
 		.magic	= _name##_MAGIC,	\
 	}
 
+#define FD_ENTRY_F(_name, _fmt, _f)		\
+	[CR_FD_##_name] = {			\
+		.fmt	= _fmt ".img",		\
+		.magic	= _name##_MAGIC,	\
+		.oflags	= _f,			\
+	}
+
 struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(INVENTORY,	"inventory"),
 	FD_ENTRY(FDINFO,	"fdinfo-%d"),
@@ -38,16 +46,16 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(MM,		"mm-%d"),
 	FD_ENTRY(VMAS,		"vmas-%d"),
 	FD_ENTRY(PIPES,		"pipes"),
-	FD_ENTRY(PIPES_DATA,	"pipes-data"),
+	FD_ENTRY_F(PIPES_DATA,	"pipes-data", O_NOBUF), /* splices data */
 	FD_ENTRY(FIFO,		"fifo"),
-	FD_ENTRY(FIFO_DATA,	"fifo-data"),
+	FD_ENTRY_F(FIFO_DATA,	"fifo-data", O_NOBUF), /* the same */
 	FD_ENTRY(PSTREE,	"pstree"),
 	FD_ENTRY(SIGACT,	"sigacts-%d"),
 	FD_ENTRY(UNIXSK,	"unixsk"),
 	FD_ENTRY(INETSK,	"inetsk"),
 	FD_ENTRY(PACKETSK,	"packetsk"),
 	FD_ENTRY(NETLINK_SK,	"netlinksk"),
-	FD_ENTRY(SK_QUEUES,	"sk-queues"),
+	FD_ENTRY_F(SK_QUEUES,	"sk-queues", O_NOBUF), /* lseeks the image */
 	FD_ENTRY(ITIMERS,	"itimers-%d"),
 	FD_ENTRY(POSIX_TIMERS,	"posix-timers-%d"),
 	FD_ENTRY(CREDS,		"creds-%d"),
@@ -58,22 +66,22 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(IPCNS_SEM,	"ipcns-sem-%d"),
 	FD_ENTRY(FS,		"fs-%d"),
 	FD_ENTRY(REMAP_FPATH,	"remap-fpath"),
-	FD_ENTRY(GHOST_FILE,	"ghost-file-%x"),
+	FD_ENTRY_F(GHOST_FILE,	"ghost-file-%x", O_NOBUF),
 	FD_ENTRY(TCP_STREAM,	"tcp-stream-%x"),
 	FD_ENTRY(MNTS,		"mountpoints-%d"),
 	FD_ENTRY(NETDEV,	"netdev-%d"),
-	FD_ENTRY(IFADDR,	"ifaddr-%d"),
-	FD_ENTRY(ROUTE,		"route-%d"),
-	FD_ENTRY(IPTABLES,	"iptables-%d"),
-	FD_ENTRY(TMPFS_IMG,	"tmpfs-%d.tar.gz"),
-	FD_ENTRY(TMPFS_DEV,	"tmpfs-dev-%d.tar.gz"),
+	FD_ENTRY_F(IFADDR,	"ifaddr-%d", O_NOBUF),
+	FD_ENTRY_F(ROUTE,	"route-%d", O_NOBUF),
+	FD_ENTRY_F(IPTABLES,	"iptables-%d", O_NOBUF),
+	FD_ENTRY_F(TMPFS_IMG,	"tmpfs-%d.tar.gz", O_NOBUF),
+	FD_ENTRY_F(TMPFS_DEV,	"tmpfs-dev-%d.tar.gz", O_NOBUF),
 	FD_ENTRY(TTY_FILES,	"tty"),
 	FD_ENTRY(TTY_INFO,	"tty-info"),
 	FD_ENTRY(FILE_LOCKS,	"filelocks"),
 	FD_ENTRY(RLIMIT,	"rlimit-%d"),
-	FD_ENTRY(PAGES,		"pages-%u"),
-	FD_ENTRY(PAGES_OLD,	"pages-%d"),
-	FD_ENTRY(SHM_PAGES_OLD, "pages-shmem-%ld"),
+	FD_ENTRY_F(PAGES,	"pages-%u", O_NOBUF),
+	FD_ENTRY_F(PAGES_OLD,	"pages-%d", O_NOBUF),
+	FD_ENTRY_F(SHM_PAGES_OLD, "pages-shmem-%ld", O_NOBUF),
 	FD_ENTRY(SIGNAL,	"signal-s-%d"),
 	FD_ENTRY(PSIGNAL,	"signal-p-%d"),
 	FD_ENTRY(TUNFILE,	"tunfile"),
diff --git a/image.c b/image.c
index e7f8b86..246c91b 100644
--- a/image.c
+++ b/image.c
@@ -211,7 +211,8 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
 	if (!img)
 		goto errn;
 
-	flags &= ~O_OPT;
+	oflags |= imgset_template[type].oflags;
+	flags &= ~(O_OPT | O_NOBUF);
 
 	va_start(args, flags);
 	vsnprintf(path, PATH_MAX, imgset_template[type].fmt, args);
diff --git a/include/image-desc.h b/include/image-desc.h
index 2ad03df..d1aa065 100644
--- a/include/image-desc.h
+++ b/include/image-desc.h
@@ -101,6 +101,7 @@ enum {
 struct cr_fd_desc_tmpl {
 	const char	*fmt;			/* format for the name */
 	u32		magic;			/* magic in the header */
+	int		oflags;			/* flags for image_open */
 };
 
 extern struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX];
diff --git a/include/image.h b/include/image.h
index ee6ca7e..a1925c8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -69,10 +69,12 @@
 extern bool fdinfo_per_id;
 extern bool ns_per_id;
 
+#define O_OPT	(O_PATH)
+#define O_NOBUF	(O_DIRECT)
+
 #define O_DUMP	(O_RDWR | O_CREAT | O_TRUNC)
-#define O_SHOW	(O_RDONLY)
+#define O_SHOW	(O_RDONLY | O_NOBUF)
 #define O_RSTR	(O_RDONLY)
-#define O_OPT	(O_PATH)
 
 struct cr_img {
 	int _fd;
-- 
1.8.4.2




More information about the CRIU mailing list