Richard W.M. Jones
2018-Apr-16 09:48 UTC
[Libguestfs] [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 --- 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 bd382cb11..c1a7e5737 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. *) -- 2.16.2
Pino Toscano
2018-Apr-16 10:28 UTC
Re: [Libguestfs] [PATCH] v2v: Give better diagnostics if filesystem falls back to read-only (RHBZ#1567763).
On Monday, 16 April 2018 11:48:08 CEST Richard W.M. Jones wrote:> 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.Another possibility here could be to use the "norecover" mount option. -- Pino Toscano
Richard W.M. Jones
2018-Apr-16 10:42 UTC
Re: [Libguestfs] [PATCH] v2v: Give better diagnostics if filesystem falls back to read-only (RHBZ#1567763).
On Mon, Apr 16, 2018 at 12:28:58PM +0200, Pino Toscano wrote:> On Monday, 16 April 2018 11:48:08 CEST Richard W.M. Jones wrote: > > 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. > > Another possibility here could be to use the "norecover" mount option.Unfortunately I don't have an actual test case covering this bug. But one problem with the norecover option seems to be that it's only understood by ntfs-3g and other filesystems give an error: $ guestfish -N fs -m /dev/sda1:/:norecover libguestfs: error: mount_options: mount exited with status 32: mount: /sysroot: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error. guestfish: ‘/dev/sda1’ could not be mounted. guestfish: Check mount(8) man page to ensure options ‘norecover’ guestfish: are supported by the filesystem that is being mounted. guestfish: Did you mean to mount one of these filesystems? guestfish: /dev/sda1 (ext2) So that would entail some more complex logic to determine if the filesystem is ntfs or not. It's a tricky call. You could equally argue that the ‘norecover’ option is important for data integrity, or that what we currently do (‘recover’, the default) allows us to convert guests with less fuss. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maybe Matching Threads
- Re: [PATCH] v2v: Give better diagnostics if filesystem falls back to read-only (RHBZ#1567763).
- [PATCH] v2v: inspect source: Don't tell people twice to run virt-v2v -v -x (RHBZ#1167623).
- Re: [PATCH 1/2] v2v: fill the list of the EFI system partitions
- Re: [PATCH] v2v: Output saved overlays in a machine-readable fashion
- [PATCH 1/2] Remove most instances of OCaml warning 52.