[CRIU] [PATCH] img: Remove empty lazy images after dump

Pavel Emelyanov xemul at parallels.com
Fri May 29 04:45:57 PDT 2015


If dump doesn't generate data into some image file the respective file
is not created at all as it used to be in 1.5. This brings potential
problem -- if the file with the image name exists during dump (e.g. a
dump file left from previous, maybe unsuccessful, dump) then restore
would pick this file and read bad/wrong/fake data from it.

To return the proper behavior back the file with the name of empty image
should be removed.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

diff --git a/image.c b/image.c
index bb0edaa..9182a07 100644
--- a/image.c
+++ b/image.c
@@ -369,9 +369,15 @@ int open_image_lazy(struct cr_img *img)
 
 void close_image(struct cr_img *img)
 {
-	if (lazy_image(img))
+	if (lazy_image(img)) {
+		/*
+		 * Remove the image file if it's there so that
+		 * subsequent restore doesn't read wrong or fake
+		 * data from it.
+		 */
+		unlinkat(get_service_fd(IMG_FD_OFF), img->path, 0);
 		xfree(img->path);
-	else if (!empty_image(img))
+	} else if (!empty_image(img))
 		bclose(&img->_x);
 
 	xfree(img);



More information about the CRIU mailing list