Commit 18145c50 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

files-reg: Create fifo ghost node if needed v2

Allow file path remap engine to create fifo nodes.
Note for fifos the copy_file is not called since
we will restore fifo data via pipe-data engine.

v2
 - no need for dev in mknod
 - don't reopen local copy on fifo files
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d16d4baa
...@@ -65,7 +65,7 @@ static int open_remap_ghost(struct reg_file_info *rfi, ...@@ -65,7 +65,7 @@ static int open_remap_ghost(struct reg_file_info *rfi,
{ {
struct ghost_file *gf; struct ghost_file *gf;
struct ghost_file_entry gfe; struct ghost_file_entry gfe;
int gfd, ifd; int gfd, ifd, ghost_flags;
list_for_each_entry(gf, &ghost_files, list) list_for_each_entry(gf, &ghost_files, list)
if (gf->id == rfe->remap_id) if (gf->id == rfe->remap_id)
...@@ -94,7 +94,17 @@ static int open_remap_ghost(struct reg_file_info *rfi, ...@@ -94,7 +94,17 @@ static int open_remap_ghost(struct reg_file_info *rfi,
goto err; goto err;
snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id); snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
gfd = open(gf->path, O_WRONLY | O_CREAT | O_EXCL, gfe.mode);
if (S_ISFIFO(gfe.mode)) {
if (mknod(gf->path, gfe.mode, 0)) {
pr_perror("Can't create node for ghost file\n");
goto err;
}
ghost_flags = O_RDWR; /* To not block */
} else
ghost_flags = O_WRONLY | O_CREAT | O_EXCL;
gfd = open(gf->path, ghost_flags, gfe.mode);
if (gfd < 0) { if (gfd < 0) {
pr_perror("Can't open ghost file"); pr_perror("Can't open ghost file");
goto err; goto err;
...@@ -105,8 +115,10 @@ static int open_remap_ghost(struct reg_file_info *rfi, ...@@ -105,8 +115,10 @@ static int open_remap_ghost(struct reg_file_info *rfi,
goto err; goto err;
} }
if (S_ISREG(gfe.mode)) {
if (copy_file(ifd, gfd, 0) < 0) if (copy_file(ifd, gfd, 0) < 0)
goto err; goto err;
}
close(ifd); close(ifd);
close(gfd); close(gfd);
...@@ -179,6 +191,14 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st) ...@@ -179,6 +191,14 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
if (img < 0) if (img < 0)
return -1; return -1;
gfe.uid = st->st_uid;
gfe.gid = st->st_gid;
gfe.mode = st->st_mode;
if (write_img(img, &gfe))
return -1;
if (S_ISREG(st->st_mode)) {
/* /*
* Reopen file locally since it may have no read * Reopen file locally since it may have no read
* permissions when drained * permissions when drained
...@@ -189,16 +209,9 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st) ...@@ -189,16 +209,9 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
pr_perror("Can't open ghost original file"); pr_perror("Can't open ghost original file");
return -1; return -1;
} }
gfe.uid = st->st_uid;
gfe.gid = st->st_gid;
gfe.mode = st->st_mode;
if (write_img(img, &gfe))
return -1;
if (copy_file(fd, img, st->st_size)) if (copy_file(fd, img, st->st_size))
return -1; return -1;
}
close(fd); close(fd);
close(img); close(img);
......
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