From b4c460acc2bd07fc9bb21fb2fed970fa8253ebc8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 16 Apr 2018 09:52:14 +0100 Subject: [PATCH] v2v: Give better diagnostics if filesystem falls back to read-only (RHBZ#1567763). Some filesystems fall back silently to read-only if there are problems such a dirty filesystem and an unrecoverable journal. Almost all conversions involve writing to the root filesystem, so these will inevitably fail later on with a strange error message. Test the root filesystem is writable by creating and deleting a temporary file, and if the creation fails then give better diagnostics. Reported-by: Piotr Kliczewski (cherry picked from commit 201e6d1595c1cdae7f1fbce11626412768b33f99) --- generator/OCaml.ml | 1 + v2v/inspect_source.ml | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/generator/OCaml.ml b/generator/OCaml.ml index e58f387cc..467a1f0d8 100644 --- a/generator/OCaml.ml +++ b/generator/OCaml.ml @@ -40,6 +40,7 @@ let ocaml_errnos = [ "EPERM"; "ESRCH"; "ENOENT"; + "EROFS"; ] (* Generate the OCaml bindings interface. *) diff --git a/v2v/inspect_source.ml b/v2v/inspect_source.ml index 68e1c90aa..2f9f52ea1 100644 --- a/v2v/inspect_source.ml +++ b/v2v/inspect_source.ml @@ -41,16 +41,33 @@ let rec inspect_source root_choice g = let mps = List.sort cmp mps in List.iter ( fun (mp, dev) -> - try g#mount dev mp - with G.Error msg -> - if mp = "/" then ( (* RHBZ#1145995 *) - if String.find msg "Windows" >= 0 && String.find msg "NTFS partition is in an unsafe state" >= 0 then - error (f_"unable to mount the disk image for writing. This has probably happened because Windows Hibernation or Fast Restart is being used in this guest. You have to disable this (in the guest) in order to use virt-v2v.\n\nOriginal error message: %s") msg - else - error "%s" msg - ) - else - warning (f_"%s (ignored)") msg + (try g#mount dev mp + with G.Error msg -> + if mp = "/" then ( (* RHBZ#1145995 *) + if String.find msg "Windows" >= 0 && String.find msg "NTFS partition is in an unsafe state" >= 0 then + error (f_"unable to mount the disk image for writing. This has probably happened because Windows Hibernation or Fast Restart is being used in this guest. You have to disable this (in the guest) in order to use virt-v2v.\n\nOriginal error message: %s") msg + else + error "%s" msg + ) + else + warning (f_"%s (ignored)") msg + ); + + (* Some filesystems (hello, ntfs-3g) can silently fall back to + * a read-only mount. Check the root filesystem is really writable. + * RHBZ#1567763 + *) + if mp = "/" then ( + let file = sprintf "/%s" (String.random8 ()) in + (try g#touch file + with G.Error msg -> + if g#last_errno () = G.Errno.errno_EROFS then + error (f_"filesystem was mounted read-only, even though we asked for it to be mounted read-write. This usually means that the filesystem was not cleanly unmounted. Possible causes include trying to convert a guest which is running, or using Windows Hibernation or Fast Restart.\n\nOriginal error message: %s") msg + else + error (f_"could not write to the guest filesystem: %s") msg + ); + g#rm file + ) ) mps; (* Get list of applications/packages installed. *)