Pino Toscano
2017-Aug-18 08:56 UTC
[Libguestfs] [PATCH] resize: handle empty UUIDs for swap partitions (RHBZ#1482737)
Avoid passing an empty UUID string to mkswap, which mkswap does not accept (correctly) as new UUID. In addition, print a warning when the UUID of a swap partition changed, since it may require manual fixups in the guest. --- resize/resize.ml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index fbb2d021b..48c75161d 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1347,9 +1347,20 @@ read the man page virt-resize(1). (* Rebuild the swap using the UUID and label of the existing * swap partition. *) - let uuid = g#vfs_uuid target in + let orig_uuid = g#vfs_uuid target in + let uuid + match orig_uuid with + | "" -> None + | uuid -> Some uuid in let label = g#vfs_label target in - g#mkswap ~uuid ~label target + g#mkswap ?uuid ~label target; + (* Check whether the UUID could be set, and warn in case it + * changed. + *) + let new_uuid = g#vfs_uuid target in + if new_uuid <> orig_uuid then + warning (f_"UUID in swap partition %s changed from ‘%s’ to ‘%s’") + target orig_uuid new_uuid; in (* Expand partition content as required. *) -- 2.13.5
Richard W.M. Jones
2017-Aug-18 14:24 UTC
Re: [Libguestfs] [PATCH] resize: handle empty UUIDs for swap partitions (RHBZ#1482737)
On Fri, Aug 18, 2017 at 10:56:12AM +0200, Pino Toscano wrote:> Avoid passing an empty UUID string to mkswap, which mkswap does not > accept (correctly) as new UUID. > > In addition, print a warning when the UUID of a swap partition changed, > since it may require manual fixups in the guest. > --- > resize/resize.ml | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/resize/resize.ml b/resize/resize.ml > index fbb2d021b..48c75161d 100644 > --- a/resize/resize.ml > +++ b/resize/resize.ml > @@ -1347,9 +1347,20 @@ read the man page virt-resize(1). > (* Rebuild the swap using the UUID and label of the existing > * swap partition. > *) > - let uuid = g#vfs_uuid target in > + let orig_uuid = g#vfs_uuid target in > + let uuid > + match orig_uuid with > + | "" -> None > + | uuid -> Some uuid in > let label = g#vfs_label target in > - g#mkswap ~uuid ~label target > + g#mkswap ?uuid ~label target; > + (* Check whether the UUID could be set, and warn in case it > + * changed. > + *) > + let new_uuid = g#vfs_uuid target in > + if new_uuid <> orig_uuid then > + warning (f_"UUID in swap partition %s changed from ‘%s’ to ‘%s’") > + target orig_uuid new_uuid; > inACK 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
Reasonably Related Threads
- [PATCH v2 2/2] resize: expand f2fs partitions
- [PATCH 0/2] Support for expanding f2fs partitions
- [PATCH 2/2] resize: shrink/expand swap partitions
- [PATCH 1/3] uuid: add support to change uuid of swap partition
- [PATCH 3/3] sysprep: fix btrfs subvolume processing in fs-uuids