[Libguestfs] [PATCH v3.1 7/9] New API: swap_set_uuid_random

Chen, Hanxiao chenhanxiao at cn.fujitsu.com
Mon Jun 29 03:12:32 UTC 2015


Hi,

> -----Original Message-----
> From: libguestfs-bounces at redhat.com [mailto:libguestfs-bounces at redhat.com] On
> Behalf Of Pino Toscano
> Sent: Friday, June 26, 2015 9:01 PM
> To: libguestfs at redhat.com
> Subject: Re: [Libguestfs] [PATCH v3.1 7/9] New API: swap_set_uuid_random
> 
> In data venerdì 26 giugno 2015 17:35:42, Chen Hanxiao ha scritto:
> > Also introduce get_random_uuid()
> >
> > Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> > ---
> >  daemon/daemon.h |  2 ++
> >  daemon/swap.c   | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 34 insertions(+)
> >
> > diff --git a/daemon/daemon.h b/daemon/daemon.h
> > index 9c8476c..6c07c6a 100644
> > --- a/daemon/daemon.h
> > +++ b/daemon/daemon.h
> > @@ -278,6 +278,8 @@ extern char *ntfs_get_label (const char *device);
> >
> >  /*-- in swap.c --*/
> >  extern int swap_set_uuid (const char *device, const char *uuid);
> > +extern int swap_set_uuid_random (const char *device);
> > +extern char *get_random_uuid (void);
> >
> >  /* ordinary daemon functions use these to indicate errors
> >   * NB: you don't need to prefix the string with the current command,
> > diff --git a/daemon/swap.c b/daemon/swap.c
> > index 26fe30d..923adb2 100644
> > --- a/daemon/swap.c
> > +++ b/daemon/swap.c
> > @@ -34,6 +34,7 @@ GUESTFSD_EXT_CMD(str_mkswap, mkswap);
> >  GUESTFSD_EXT_CMD(str_swapon, swapon);
> >  GUESTFSD_EXT_CMD(str_swapoff, swapoff);
> >  GUESTFSD_EXT_CMD(str_swaplabel, swaplabel);
> > +GUESTFSD_EXT_CMD(str_uuidgen, uuidgen);
> >
> >  /* Confirmed this is true for Linux swap partitions from the Linux sources. */
> >  #define SWAP_LABEL_MAX 16
> > @@ -255,3 +256,34 @@ swap_set_uuid (const char *device, const char *uuid)
> >
> >    return 0;
> >  }
> > +
> > +char *
> > +get_random_uuid (void)
> > +{
> > +  int r;
> > +  char *out;
> > +  CLEANUP_FREE char *err = NULL;
> > +
> > +  r = command (&out, &err, str_uuidgen, NULL);
> > +  if (r == -1) {
> > +    reply_with_error ("%s", err);
> > +    return NULL;
> > +  }
> > +
> > +  /* caller free */
> > +  return out;
> > +
> > +}
> 
> The addition of the get_random_uuid() is worth an own commit.  Also,
> it is not specific to swap, so I'd say to put it directly in guestfsd.c,
> named like uuidgen() (much like the OCaml equivalent in Common_utils).
> 
> Furthermore, you should make sure uuidgen is actually in the appliance:
> while in Fedora is in util-linux (already part of the appliance), e.g.
> in Debian/Ubuntu is in uuid-runtime. Thus you need to add that package
> to the Debian ones in appliance/packagelist.in.
> 

Sure, I'll put this part in guestfsd.c.
As my limited research about util-linux, all other distros expect Debian
already had this package.

> > +int
> > +swap_set_uuid_random (const char *device)
> > +{
> > +  CLEANUP_FREE char *err = NULL;
> > +  CLEANUP_FREE char *uuid_random = NULL;
> > +
> > +  uuid_random = get_random_uuid ();
> > +  if (uuid_random == NULL)
> > +    return -1;
> > +
> > +  return swap_set_uuid (device, uuid_random);
> > +}
> 
> This is nothing specific for swap, and could just be done directly in
> the set_uuid_random implementation, for all the filesystems we have
> tools to change their UUIDs (so swap only so far).
> 
> In practice something like:
> 
>    else if (STREQ (vfs_type, "swap")) {
>      CLEANUP_FREE char *uuid = uuidgen ();
>      if (uuid == NULL)
>        return -1;
> 
>      r = swap_set_uuid (device, uuid);
>    }
> 

Will do in next version.

Regards,
- Chen






More information about the Libguestfs mailing list