Fall back to opening image files readonly if readwrite fails.

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

Details

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

Commit Message

Paweł 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;
 

Comments

Andrey Vagin Aug. 16, 2018, 11:32 p.m.
Applied, thanks!

On Mon, Jul 30, 2018 at 06:47:34PM +0200, Pawel Stradomski wrote:
> 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(+)
> 
> 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;
>  
> -- 
> 2.18.0.345.g5c9ce644c3-goog
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu