[CRIU] [PATCH v4 4/6] files-reg: Move applying ghost file metadata from create_ghost() to separate function

Kirill Tkhai ktkhai at virtuozzo.com
Mon Jan 25 08:40:04 PST 2016


This cleanup makes create_ghost() smaller.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 files-reg.c |   53 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/files-reg.c b/files-reg.c
index 8dbae21..b6c348a 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -136,11 +136,41 @@ static int mkreg_ghost(char *path, u32 mode, struct ghost_file *gf, struct cr_im
 	return ret;
 }
 
+static int ghost_apply_metadata(const char *path, GhostFileEntry *gfe)
+{
+	struct timeval tv[2];
+	int ret = -1;
+
+	if (chown(path, gfe->uid, gfe->gid) < 0) {
+		pr_perror("Can't reset user/group on ghost %s", path);
+		goto err;
+	}
+
+	if (chmod(path, gfe->mode)) {
+		pr_perror("Can't set perms %o on ghost %s", gfe->mode, path);
+		goto err;
+	}
+
+	if (gfe->atim) {
+		tv[0].tv_sec = gfe->atim->tv_sec;
+		tv[0].tv_usec = gfe->atim->tv_usec;
+		tv[1].tv_sec = gfe->mtim->tv_sec;
+		tv[1].tv_usec = gfe->mtim->tv_usec;
+		if (lutimes(path, tv)) {
+			pr_perror("Can't set access and modufication times on ghost %s", path);
+			goto err;
+		}
+	}
+
+	ret = 0;
+err:
+	return ret;
+}
+
 static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_img *img)
 {
 	int ret, len, root_len, try = 0;
 	char path[PATH_MAX];
-	struct timeval tv[2];
 	char *msg;
 
 	root_len = ret = rst_get_mnt_root(gf->remap.rmnt_id, path, sizeof(path));
@@ -199,26 +229,9 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im
 	strcpy(gf->remap.rpath, path + root_len + 1);
 	pr_debug("Remap rpath is %s\n", gf->remap.rpath);
 
-	if (chown(path, gfe->uid, gfe->gid) < 0) {
-		pr_perror("Can't reset user/group on ghost %s", path);
-		goto err;
-	}
-
-	if (chmod(path, gfe->mode)) {
-		pr_perror("Can't set perms %o on ghost %s", gfe->mode, path);
+	ret = -1;
+	if (ghost_apply_metadata(path, gfe))
 		goto err;
-	}
-
-	if (gfe->atim) {
-		tv[0].tv_sec = gfe->atim->tv_sec;
-		tv[0].tv_usec = gfe->atim->tv_usec;
-		tv[1].tv_sec = gfe->mtim->tv_sec;
-		tv[1].tv_usec = gfe->mtim->tv_usec;
-		if (lutimes(path, tv)) {
-			pr_perror("Can't set access and modufication times on ghost %s", path);
-			goto err;
-		}
-	}
 
 	ret = 0;
 err:



More information about the CRIU mailing list