Skip to content

Commit d0097b2

Browse files
committed
files: Support ghost directories restore
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 <[email protected]>
1 parent c06727c commit d0097b2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

files-reg.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, char *root,
9090
goto err;
9191
}
9292
ghost_flags = O_WRONLY;
93+
} else if (S_ISDIR(gfe->mode)) {
94+
if (mkdir(gf->remap.path, gfe->mode)) {
95+
pr_perror("Can't make ghost dir");
96+
goto err;
97+
}
98+
ghost_flags = O_DIRECTORY;
9399
} else
94100
ghost_flags = O_WRONLY | O_CREAT | O_EXCL;
95101

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

177183
gf->id = rfe->remap_id;
178184
gf->remap.users = 0;
185+
gf->remap.is_dir = S_ISDIR(gfe->mode);
179186
list_add_tail(&gf->list, &ghost_files);
180187
gf_found:
181188
rfi->remap = &gf->remap;
@@ -676,7 +683,14 @@ int open_path(struct file_desc *d,
676683

677684
if (rfi->remap) {
678685
mutex_lock(ghost_file_mutex);
679-
if (rfi_remap(rfi) < 0) {
686+
if (rfi->remap->is_dir) {
687+
/*
688+
* FIXME Can't make directory under new name.
689+
* Will have to open it under the ghost one :(
690+
*/
691+
orig_path = rfi->path;
692+
rfi->path = rfi->remap->path;
693+
} else if (rfi_remap(rfi) < 0) {
680694
static char tmp_path[PATH_MAX];
681695

682696
if (errno != EEXIST) {
@@ -747,7 +761,10 @@ int open_path(struct file_desc *d,
747761
BUG_ON(!rfi->remap->users);
748762
if (--rfi->remap->users == 0) {
749763
pr_info("Unlink the ghost %s\n", rfi->remap->path);
750-
unlink(rfi->remap->path);
764+
if (rfi->remap->is_dir)
765+
rmdir(rfi->remap->path);
766+
else
767+
unlink(rfi->remap->path);
751768
}
752769

753770
if (orig_path)

include/files-reg.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct fd_parms;
1313

1414
struct file_remap {
1515
char *path;
16+
bool is_dir;
1617
unsigned int users;
1718
};
1819

0 commit comments

Comments
 (0)