Maxim Perevedentsev
2016-Jul-08 11:08 UTC
[Libguestfs] [PATCHv2 0/3] fix btrfs subvolume procession in tools
sparsify case: modified guestfs_is_lv mllib: fixed is_btrfs_subvolume Maxim Perevedentsev (3): mllib: add checking for btrfs subvolume lvm: modify guestfs_is_lv to take mountable sysprep: fix btrfs subvolume processing in fs-uuids daemon/lvm.c | 6 ++++-- generator/actions.ml | 6 +++--- mllib/common_utils.ml | 7 +++++++ mllib/common_utils.mli | 3 +++ sysprep/sysprep_operation_fs_uuids.ml | 16 +++++++++------- 5 files changed, 26 insertions(+), 12 deletions(-) -- 1.8.3.1
Maxim Perevedentsev
2016-Jul-08 11:08 UTC
[Libguestfs] [PATCHv2 1/3] mllib: add checking for btrfs subvolume
This is needed to skip btrfs subvolumes from output of list_filesystems where device is needed. --- mllib/common_utils.ml | 7 +++++++ mllib/common_utils.mli | 3 +++ 2 files changed, 10 insertions(+) diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 77b9acd..35f6545 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -922,3 +922,10 @@ let inspect_mount_root g ?mount_opts_fn root let inspect_mount_root_ro inspect_mount_root ~mount_opts_fn:(fun _ -> "ro") + +let is_btrfs_subvolume g fs + try + ignore (g#mountable_subvolume fs); true + with Guestfs.Error msg as exn -> + if g#last_errno () = Guestfs.Errno.errno_EINVAL then false + else raise exn diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 5b0b9bb..d2ed30c 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -330,3 +330,6 @@ val inspect_mount_root : Guestfs.guestfs -> ?mount_opts_fn:(string -> string) -> val inspect_mount_root_ro : Guestfs.guestfs -> string -> unit (** Like [inspect_mount_root], but mounting every mount point as read-only. *) + +val is_btrfs_subvolume : Guestfs.guestfs -> string -> bool +(** Checks if a filesystem is a btrfs subvolume. *) -- 1.8.3.1
Maxim Perevedentsev
2016-Jul-08 11:08 UTC
[Libguestfs] [PATCHv2 2/3] lvm: modify guestfs_is_lv to take mountable
Calling guestfs_is_lv on btrfs subvolume throws an error. Here we workaround it by taking Mountable instead of Device and returning 'false' for non-device mountables. --- daemon/lvm.c | 6 ++++-- generator/actions.ml | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/daemon/lvm.c b/daemon/lvm.c index 2b61357..4f02206 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -863,9 +863,11 @@ lv_canonical (const char *device, char **ret) /* Test if a device is a logical volume (RHBZ#619793). */ int -do_is_lv (const char *device) +do_is_lv (const mountable_t *mountable) { - return lv_canonical (device, NULL); + if (mountable->type != MOUNTABLE_DEVICE) + return 0; + return lv_canonical (mountable->device, NULL); } /* Return canonical name of LV to caller (RHBZ#638899). */ diff --git a/generator/actions.ml b/generator/actions.ml index e0931b8..2a69db8 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9068,7 +9068,7 @@ I<other> keys." }; { defaults with name = "is_lv"; added = (1, 5, 3); - style = RBool "lvflag", [Device "device"], []; + style = RBool "lvflag", [Mountable "mountable"], []; proc_nr = Some 264; tests = [ InitBasicFSonLVM, Always, TestResultTrue ( @@ -9076,9 +9076,9 @@ I<other> keys." }; InitBasicFSonLVM, Always, TestResultFalse ( [["is_lv"; "/dev/sda1"]]), [] ]; - shortdesc = "test if device is a logical volume"; + shortdesc = "test if mountable is a logical volume"; longdesc = "\ -This command tests whether C<device> is a logical volume, and +This command tests whether C<mountable> is a logical volume, and returns true iff this is the case." }; { defaults with -- 1.8.3.1
Maxim Perevedentsev
2016-Jul-08 11:08 UTC
[Libguestfs] [PATCHv2 3/3] sysprep: fix btrfs subvolume processing in fs-uuids
guestfs_set_uuid wants device as argument. Moreover, btrfstune -U is unable to set uuid for subvolumes, only unmounted partitions are supported. Here we skip btrfs subvolumes. --- sysprep/sysprep_operation_fs_uuids.ml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sysprep/sysprep_operation_fs_uuids.ml b/sysprep/sysprep_operation_fs_uuids.ml index ed4e81a..f125eb0 100644 --- a/sysprep/sysprep_operation_fs_uuids.ml +++ b/sysprep/sysprep_operation_fs_uuids.ml @@ -30,13 +30,15 @@ let rec fs_uuids_perform g root side_effects List.iter (function | _, "unknown" -> () | dev, typ -> - let new_uuid = Common_utils.uuidgen () in - try - g#set_uuid dev new_uuid - with - G.Error msg -> - warning (f_"cannot set random UUID on filesystem %s type %s: %s") - dev typ msg + if not (is_btrfs_subvolume g dev) then ( + let new_uuid = Common_utils.uuidgen () in + try + g#set_uuid dev new_uuid + with + G.Error msg -> + warning (f_"cannot set random UUID on filesystem %s type %s: %s") + dev typ msg + ) ) fses let op = { -- 1.8.3.1
Richard W.M. Jones
2016-Jul-08 12:18 UTC
Re: [Libguestfs] [PATCHv2 3/3] sysprep: fix btrfs subvolume processing in fs-uuids
It all looks good. I'm just going to run the tests and if they pass I'll push it all. Thanks, 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
Possibly Parallel Threads
- [PATCH 0/3] fix btrfs subvolume procession in tools
- Re: [PATCH 1/3] mllib: add checking for btrfs subvolume
- [PATCHv2 2/3] lvm: modify guestfs_is_lv to take mountable
- [PATCH] mllib: factor out mounting of guest root
- [PATCH 1/3] mllib: add checking for btrfs subvolume