Commit 7eb33a76 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

ghost-files: Save device and inode in image

Because we need to lookup for ghost files from
inotify system where we only have device/inode
as a key, we save dev/ino in ghost image entry.

Note we use in-kernel format for device to be
consistent with inotify and mount related
code base.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 7bd34c69
...@@ -28,14 +28,11 @@ ...@@ -28,14 +28,11 @@
struct ghost_file { struct ghost_file {
struct list_head list; struct list_head list;
u32 id; u32 id;
union {
struct /* for dumping */ { u32 dev;
u32 dev; u32 ino;
u32 ino;
}; struct file_remap remap;
struct file_remap remap; /* for restoring */
};
}; };
static u32 ghost_file_ids = 1; static u32 ghost_file_ids = 1;
...@@ -83,6 +80,14 @@ static int open_remap_ghost(struct reg_file_info *rfi, ...@@ -83,6 +80,14 @@ static int open_remap_ghost(struct reg_file_info *rfi,
if (pb_read_one(ifd, &gfe, PB_GHOST_FILE) < 0) if (pb_read_one(ifd, &gfe, PB_GHOST_FILE) < 0)
goto close_ifd; goto close_ifd;
/*
* For old formats where optional has_[dev|ino] is
* not present we will have zeros here which is quite
* a sign for "absent" fields.
*/
gf->dev = gfe->dev;
gf->ino = gfe->ino;
snprintf(gf->remap.path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id); snprintf(gf->remap.path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
if (S_ISFIFO(gfe->mode)) { if (S_ISFIFO(gfe->mode)) {
...@@ -218,6 +223,10 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st) ...@@ -218,6 +223,10 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
gfe.gid = st->st_gid; gfe.gid = st->st_gid;
gfe.mode = st->st_mode; gfe.mode = st->st_mode;
gfe.has_dev = gfe.has_ino = true;
gfe.dev = MKKDEV(MAJOR(st->st_dev), MINOR(st->st_dev));
gfe.ino = st->st_ino;
if (pb_write_one(img, &gfe, PB_GHOST_FILE)) if (pb_write_one(img, &gfe, PB_GHOST_FILE))
return -1; return -1;
......
...@@ -79,6 +79,7 @@ typedef unsigned char u8; ...@@ -79,6 +79,7 @@ typedef unsigned char u8;
typedef signed char s8; typedef signed char s8;
#define MAJOR(dev) ((dev)>>8) #define MAJOR(dev) ((dev)>>8)
#define MINOR(dev) ((dev) & 0xff)
#define _LINUX_CAPABILITY_VERSION_3 0x20080522 #define _LINUX_CAPABILITY_VERSION_3 0x20080522
#define _LINUX_CAPABILITY_U32S_3 2 #define _LINUX_CAPABILITY_U32S_3 2
......
...@@ -2,4 +2,7 @@ message ghost_file_entry { ...@@ -2,4 +2,7 @@ message ghost_file_entry {
required uint32 uid = 1; required uint32 uid = 1;
required uint32 gid = 2; required uint32 gid = 2;
required uint32 mode = 3; required uint32 mode = 3;
optional uint32 dev = 4;
optional uint64 ino = 5;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment