[CRIU] [PATCH] files-reg: Adjust file position for /dev/kmsg
Pavel Emelyanov
xemul at parallels.com
Mon Jul 20 09:49:31 PDT 2015
On 07/20/2015 12:51 PM, Cyrill Gorcunov wrote:
> The kernel doesnt allow to call lseek on /dev/kmsg
> if it has been opened with O_WRONLY mode so our
> restore procedure fails.
>
> Add adjust_file_pos() helper which would handle
> this problem on dump.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> files-reg.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/files-reg.c b/files-reg.c
> index 2a6269b2a550..196f1d9bfe9b 100644
> --- a/files-reg.c
> +++ b/files-reg.c
> @@ -9,6 +9,8 @@
> #include <sys/vfs.h>
> #include <ctype.h>
>
> +#include <linux/major.h>
> +
> /* Stolen from kernel/fs/nfs/unlink.c */
> #define SILLYNAME_PREF ".nfs"
> #define SILLYNAME_SUFF_LEN (((unsigned)sizeof(u64) << 1) + ((unsigned)sizeof(unsigned int) << 1))
> @@ -801,6 +803,21 @@ static bool should_check_size(int flags)
> return true;
> }
>
> +static void adjust_file_pos(const struct fd_parms *p, RegFileEntry *rfe)
> +{
> + int maj = major(p->stat.st_rdev);
> + int min = minor(p->stat.st_rdev);
> +
> + /*
> + * If /dev/kmsg is opened in write-only mode the file position
> + * should not be set up upon restore, kernel doesn't allow that.
> + */
> + if (maj == MEM_MAJOR && min == 11) {
> + if ((rfe->flags & O_ACCMODE) == O_WRONLY)
&& rfe->pos == 0, we don't want to screw up somehow changed pos, do we?
> + rfe->pos = -1ULL;
> + }
> +}
> +
> int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
> {
> struct fd_link _link, *link;
> @@ -853,6 +870,8 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
> rfe.size = p->stat.st_size;
> }
>
> + adjust_file_pos(p, &rfe);
Plz, don't put it into generic function. Declare ops for dump_chrdev's
MEM_MAJOR case and fix this up there.
-- Pavel
> +
> rimg = img_from_set(glob_imgset, CR_FD_REG_FILES);
> return pb_write_one(rimg, &rfe, PB_REG_FILE);
> }
>
More information about the CRIU
mailing list