[CRIU] [PATCH v6 4/7] mount: Create binfmt_misc image w/o device suffix

Kirill Tkhai ktkhai at virtuozzo.com
Tue Aug 23 09:16:49 PDT 2016


Use name binfmt_misc.img for any mounted binfmt_misc.
Note, that newly created binfmt_misc images won't restore
on old criu.

Iterate over binfmt_misc_list if it's not empty on restore.

Also, because of above, let's change a behaviour of dump and now
we do not create binfmt_misc images if there is no registered
binfmt_misc entries.

v5: New
v6: Use {open,close}_image sequence to determ if image exists
    Iterate over binfmt_misc_list

Suggested-by: Pavel Emelyanov <xemul at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/mount.c |   29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index 768e739..9b22eeb 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1369,7 +1369,7 @@ static int dump_binfmt_misc_entry(int dfd, char *name, struct cr_img *img)
 
 static int binfmt_misc_dump(struct mount_info *pm)
 {
-	struct cr_img *img;
+	struct cr_img *img = NULL;
 	struct dirent *de;
 	DIR *fdir = NULL;
 	int fd, ret;
@@ -1389,10 +1389,6 @@ static int binfmt_misc_dump(struct mount_info *pm)
 	}
 
 	ret = -1;
-	img = open_image(CR_FD_BINFMT_MISC_OLD, O_DUMP, pm->s_dev);
-	if (!img)
-		goto out;
-
 	while ((de = readdir(fdir))) {
 		if (dir_dots(de))
 			continue;
@@ -1401,6 +1397,13 @@ static int binfmt_misc_dump(struct mount_info *pm)
 		if (!strcmp(de->d_name, "status"))
 			continue;
 
+		if (!img) {
+			/* Create image only if an extry exists, i.e. here */
+			img = open_image(CR_FD_BINFMT_MISC, O_DUMP);
+			if (!img)
+				goto out;
+		}
+
 		if (dump_binfmt_misc_entry(fd, de->d_name, img))
 			goto out;
 	}
@@ -1528,8 +1531,24 @@ static int binfmt_misc_restore(struct mount_info *mi)
 	if (!buf)
 		return -1;
 
+	if (!list_empty(&binfmt_misc_list)) {
+		struct binfmt_misc_info *bmi;
+
+		list_for_each_entry(bmi, &binfmt_misc_list, list) {
+			ret = binfmt_misc_restore_bme(mi, bmi->bme, buf);
+			if (ret)
+				break;
+		}
+		goto free_buf;
+	}
+
 	img = open_image(CR_FD_BINFMT_MISC_OLD, O_RSTR, mi->s_dev);
 	if (!img) {
+		pr_err("Can't open binfmt_misc_old image\n");
+		goto free_buf;
+	} else if (empty_image(img)) {
+		close_image(img);
+		ret = 0;
 		goto free_buf;
 	}
 



More information about the CRIU mailing list