Pino Toscano
2015-Jan-29 17:54 UTC
[Libguestfs] [PATCH 1/2] sparsify: ignore read-only btrfs snapshots (RHBZ#1079625)
In copy mode, make sure to not zero-free-space read-only btrfs snapshots, as we cannot write to them. --- sparsify/copying.ml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sparsify/copying.ml b/sparsify/copying.ml index 8d77964..4c23939 100644 --- a/sparsify/copying.ml +++ b/sparsify/copying.ml @@ -208,6 +208,11 @@ You can ignore this warning or change it to a hard failure using the * and selected swap partitions. *) let filesystems = g#list_filesystems () in + let btrfs_filesystems = List.filter ( + fun (fs, fstype) -> + fstype = "btrfs" + ) filesystems in + let btrfs_filesystems = List.map fst btrfs_filesystems in let filesystems = List.map fst filesystems in let filesystems = List.sort compare filesystems in @@ -216,6 +221,18 @@ You can ignore this warning or change it to a hard failure using the List.exists (fun fs' -> fs = g#canonical_device_name fs') ignores in + let is_readonly_btrfs_snapshot fs mp + try + let is_btrfs = List.mem fs btrfs_filesystems in + if is_btrfs then ( + try + let vol_info = g#btrfs_subvolume_show mp in + string_find (List.assoc "Flags" vol_info) "readonly" <> -1 + with _ -> false + ) else false + with Not_found -> false + in + List.iter ( fun fs -> if not (is_ignored fs) then ( @@ -230,10 +247,15 @@ You can ignore this warning or change it to a hard failure using the with _ -> false in if mounted then ( - if not quiet then - printf (f_"Fill free space in %s with zero ...\n%!") fs; + if is_readonly_btrfs_snapshot fs "/" then ( + if not quiet then + printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; + ) else ( + if not quiet then + printf (f_"Fill free space in %s with zero ...\n%!") fs; - g#zero_free_space "/" + g#zero_free_space "/" + ) ) else ( let is_linux_x86_swap (* Look for the signature for Linux swap on i386. -- 1.9.3
Pino Toscano
2015-Jan-29 17:54 UTC
[Libguestfs] [PATCH 2/2] sparsify: ignore read-only devices
In copy mode, make sure to not zero-free-space devices mounted as read-only, as we cannot write to them. Related to RHBZ#1079625. --- sparsify/copying.ml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sparsify/copying.ml b/sparsify/copying.ml index 4c23939..9c2c545 100644 --- a/sparsify/copying.ml +++ b/sparsify/copying.ml @@ -233,6 +233,13 @@ You can ignore this warning or change it to a hard failure using the with Not_found -> false in + let is_readonly_device mp + let statvfs = g#statvfs mp in + let flags = statvfs.G.flag in + (* 0x01 is ST_RDONLY in Linux' GNU libc. *) + flags <> -1_L && (flags &^ 0x1_L) <> 0_L + in + List.iter ( fun fs -> if not (is_ignored fs) then ( @@ -250,6 +257,9 @@ You can ignore this warning or change it to a hard failure using the if is_readonly_btrfs_snapshot fs "/" then ( if not quiet then printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; + ) else if is_readonly_device "/" then ( + if not quiet then + printf (f_"Skipping %s, as it is a read-only device.\n%!") fs; ) else ( if not quiet then printf (f_"Fill free space in %s with zero ...\n%!") fs; -- 1.9.3
Richard W.M. Jones
2015-Feb-02 13:18 UTC
[Libguestfs] [PATCH 1/2] sparsify: ignore read-only btrfs snapshots (RHBZ#1079625)
On Thu, Jan 29, 2015 at 06:54:30PM +0100, Pino Toscano wrote:> + let is_readonly_btrfs_snapshot fs mp > + try > + let is_btrfs = List.mem fs btrfs_filesystems in > + if is_btrfs then ( > + try > + let vol_info = g#btrfs_subvolume_show mp in > + string_find (List.assoc "Flags" vol_info) "readonly" <> -1 > + with _ -> falseHmm, catching every exception and ignoring it? I'm guessing you're trying to ignore G.Error only here (Not_found could escape but will be caught by the outer try).> + ) else false > + with Not_found -> false > + inRich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Richard W.M. Jones
2015-Feb-02 13:19 UTC
Re: [Libguestfs] [PATCH 2/2] sparsify: ignore read-only devices
On Thu, Jan 29, 2015 at 06:54:31PM +0100, Pino Toscano wrote:> In copy mode, make sure to not zero-free-space devices mounted as > read-only, as we cannot write to them. > > Related to RHBZ#1079625. > --- > sparsify/copying.ml | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/sparsify/copying.ml b/sparsify/copying.ml > index 4c23939..9c2c545 100644 > --- a/sparsify/copying.ml > +++ b/sparsify/copying.ml > @@ -233,6 +233,13 @@ You can ignore this warning or change it to a hard failure using the > with Not_found -> false > in > > + let is_readonly_device mp > + let statvfs = g#statvfs mp in > + let flags = statvfs.G.flag in > + (* 0x01 is ST_RDONLY in Linux' GNU libc. *) > + flags <> -1_L && (flags &^ 0x1_L) <> 0_L > + in > + > List.iter ( > fun fs -> > if not (is_ignored fs) then ( > @@ -250,6 +257,9 @@ You can ignore this warning or change it to a hard failure using the > if is_readonly_btrfs_snapshot fs "/" then ( > if not quiet then > printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; > + ) else if is_readonly_device "/" then ( > + if not quiet then > + printf (f_"Skipping %s, as it is a read-only device.\n%!") fs; > ) else ( > if not quiet then > printf (f_"Fill free space in %s with zero ...\n%!") fs;Looks good, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Seemingly Similar Threads
- [PATCH 2/2] sparsify: ignore read-only devices
- [PATCH 0/3] sparsify: Ignore read-only LVs (RHBZ#1185561).
- [PATCH 0/1] sparsify: Let --in-place capture ^C and shut down gracefully
- [PATCH 3/3] sparsify: Ignore read-only LVs (RHBZ#1185561).
- Re: [PATCH 3/3] sparsify: Ignore read-only LVs (RHBZ#1185561).