From 166c58d5bb38a9d9c8ece97f99f3ec15a4580f84 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 29 Sep 2014 12:49:23 +0400 Subject: [PATCH] img: Mark unbufferred images 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 Acked-by: Cyrill Gorcunov --- image-desc.c | 32 ++++++++++++++++++++------------ image.c | 3 ++- include/image-desc.h | 1 + include/image.h | 8 +++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/image-desc.c b/image-desc.c index 3ce7ab55f..3f0a63d89 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 e7f8b8648..246c91b54 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 2ad03dfd3..d1aa06569 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 ee6ca7e42..a1925c8dc 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_DUMP (O_RDWR | O_CREAT | O_TRUNC) -#define O_SHOW (O_RDONLY) -#define O_RSTR (O_RDONLY) #define O_OPT (O_PATH) +#define O_NOBUF (O_DIRECT) + +#define O_DUMP (O_RDWR | O_CREAT | O_TRUNC) +#define O_SHOW (O_RDONLY | O_NOBUF) +#define O_RSTR (O_RDONLY) struct cr_img { int _fd;