Skip to content

Commit

Permalink
files: Support ghost directories restore
Browse files Browse the repository at this point in the history
If we have opened and rmdir-ed directory, the dump works OK
creating the ghost file and remap, but restore creates _file_
instead of directory.

Fix this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
xemul committed Jul 4, 2014
1 parent c06727c commit d0097b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions files-reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, char *root,
goto err;
}
ghost_flags = O_WRONLY;
} else if (S_ISDIR(gfe->mode)) {
if (mkdir(gf->remap.path, gfe->mode)) {
pr_perror("Can't make ghost dir");
goto err;
}
ghost_flags = O_DIRECTORY;
} else
ghost_flags = O_WRONLY | O_CREAT | O_EXCL;

Expand Down Expand Up @@ -176,6 +182,7 @@ static int open_remap_ghost(struct reg_file_info *rfi,

gf->id = rfe->remap_id;
gf->remap.users = 0;
gf->remap.is_dir = S_ISDIR(gfe->mode);
list_add_tail(&gf->list, &ghost_files);
gf_found:
rfi->remap = &gf->remap;
Expand Down Expand Up @@ -676,7 +683,14 @@ int open_path(struct file_desc *d,

if (rfi->remap) {
mutex_lock(ghost_file_mutex);
if (rfi_remap(rfi) < 0) {
if (rfi->remap->is_dir) {
/*
* FIXME Can't make directory under new name.
* Will have to open it under the ghost one :(
*/
orig_path = rfi->path;
rfi->path = rfi->remap->path;
} else if (rfi_remap(rfi) < 0) {
static char tmp_path[PATH_MAX];

if (errno != EEXIST) {
Expand Down Expand Up @@ -747,7 +761,10 @@ int open_path(struct file_desc *d,
BUG_ON(!rfi->remap->users);
if (--rfi->remap->users == 0) {
pr_info("Unlink the ghost %s\n", rfi->remap->path);
unlink(rfi->remap->path);
if (rfi->remap->is_dir)
rmdir(rfi->remap->path);
else
unlink(rfi->remap->path);
}

if (orig_path)
Expand Down
1 change: 1 addition & 0 deletions include/files-reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct fd_parms;

struct file_remap {
char *path;
bool is_dir;
unsigned int users;
};

Expand Down

0 comments on commit d0097b2

Please sign in to comment.