Fall back to opening image files readonly if readwrite fails.

Submitted by Pawel Stradomski on July 30, 2018, 4:47 p.m.

Details

Message ID 00000000000055d5fa05723a40d0@google.com
State New
Series "Fall back to opening image files readonly if readwrite fails."
Headers show

Commit Message

Pawel Stradomski July 30, 2018, 4:47 p.m.
This can happen when running in user namespace with auto-dedup enabled.
Right now this means auto-dedup gets disabled.

Signed-off-by: Pawel Stradomski <pstradomski@google.com>
---
 criu/mem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/mem.c b/criu/mem.c
index 44d0e258..0ae0edd2 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -1276,6 +1276,15 @@  static int prepare_vma_ios(struct pstree_item *t, struct task_restore_args *ta)
 	 */
 	pages = open_image(CR_FD_PAGES, opts.auto_dedup ? O_RDWR : O_RSTR,
 				rsti(t)->pages_img_id);
+	/* When running inside namespace we might lack privileges to open the file
+	 * for writing.
+	 * TODO: use userns_call to do the opening instead of downgrading to opening
+	 * read-only.
+	 */
+	if (!pages && opts.auto_dedup) {
+		pr_warn("Failed to open image read-write, trying read-only instead. auto-dedup won't work\n");
+		pages = open_image(CR_FD_PAGES, O_RSTR, rsti(t)->pages_img_id);
+	}
 	if (!pages)
 		return -1;