[CRIU] [PATCH 1/8] files: Support ghost directories restore

Pavel Emelyanov xemul at parallels.com
Thu Jul 3 08:06:58 PDT 2014


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 at parallels.com>
---
 files-reg.c         | 21 +++++++++++++++++++--
 include/files-reg.h |  1 +
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/files-reg.c b/files-reg.c
index 4045f93..1b469be 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -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;
 
@@ -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;
@@ -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) {
@@ -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)
diff --git a/include/files-reg.h b/include/files-reg.h
index 27f4dd1..52945b0 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -13,6 +13,7 @@ struct fd_parms;
 
 struct file_remap {
 	char *path;
+	bool is_dir;
 	unsigned int users;
 };
 
-- 
1.8.3.1




More information about the CRIU mailing list