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

Pino Toscano ptoscano at redhat.com
Fri Jun 26 13:09:37 UTC 2015


In data venerdì 26 giugno 2015 17:35:44, Chen Hanxiao ha scritto:
> Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> ---
>  daemon/uuids.c                 | 31 +++++++++++++++++++++++++++++++
>  generator/actions.ml           | 16 ++++++++++++++++
>  src/MAX_PROC_NR                |  2 +-
>  tests/btrfs/test-btrfs-misc.pl | 11 +++++++++++
>  4 files changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/daemon/uuids.c b/daemon/uuids.c
> index 5238f3e..4530491 100644
> --- a/daemon/uuids.c
> +++ b/daemon/uuids.c
> @@ -85,3 +85,34 @@ do_set_uuid (const char *device, const char *uuid)
>  
>    return r;
>  }
> +
> +int
> +do_set_uuid_random (const char *device)
> +{
> +  int r;
> +
> +  /* How we set the UUID depends on the filesystem type. */
> +  CLEANUP_FREE char *vfs_type = get_blkid_tag (device, "TYPE");
> +  if (vfs_type == NULL)
> +    return -1;
> +
> +  if (fstype_is_extfs (vfs_type))
> +    r = set_e2uuid_random (device);
> +
> +  else if (STREQ (vfs_type, "xfs"))
> +    r = xfs_set_uuid_random (device);
> +
> +  else if (STREQ (vfs_type, "swap"))
> +    r = swap_set_uuid_random (device);
> +
> +  else if (STREQ (vfs_type, "btrfs"))
> +    r = btrfs_set_uuid_random (device);
> +
> +  else {
> +    reply_with_error ("don't know how to set the random UUID for '%s' filesystems",
> +                      vfs_type);
> +    r = -1;

Being a new API, we could make this return ENOTSUP, documenting this
error on unsupported filesystems. This way, users could know an error
is due to a filesystem not supported by this API, instead of a real
failure of one of the programs used.

> +  }
> +
> +  return r;
> +}
> diff --git a/generator/actions.ml b/generator/actions.ml
> index d5e5ccf..0328858 100644
> --- a/generator/actions.ml
> +++ b/generator/actions.ml
> @@ -12593,6 +12593,22 @@ numbered C<partnum> on device C<device>.
>  
>  It returns C<primary>, C<logical>, or C<extended>." };
>  
> +  { defaults with
> +    name = "set_uuid_random"; added = (1, 29, 47);
> +    style = RErr, [Device "device"], [];
> +    proc_nr = Some 455;
> +    tests = [
> +        InitBasicFS, Always, TestRun (
> +            [["set_uuid_random"; "/dev/sda1"]]), [];
> +      ];
> +    shortdesc = "set the random filesystem UUID";

This sounds like it is setting some particular random UUID. I'd be
better as

 "set a random UUID for the filesystem"

> +    longdesc = "\
> +Set the filesystem UUID on C<device> to a random UUID.
> +
> +Only some filesystem types support setting UUIDs.
> +
> +To read the UUID on a filesystem, call C<guestfs_vfs_uuid>." };
> +
>  ]
>  
>  (* Non-API meta-commands available only in guestfish.
> diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
> index 515f19a..4930863 100644
> --- a/src/MAX_PROC_NR
> +++ b/src/MAX_PROC_NR
> @@ -1 +1 @@
> -454
> +455
> diff --git a/tests/btrfs/test-btrfs-misc.pl b/tests/btrfs/test-btrfs-misc.pl
> index b47caab..4982f0d 100755
> --- a/tests/btrfs/test-btrfs-misc.pl
> +++ b/tests/btrfs/test-btrfs-misc.pl
> @@ -64,5 +64,16 @@ if ($err == 0) {
>      warn "$0: skipping test for btrfs UUID change feature is not available\n";
>  }
>  
> +# Setting btrfs random UUID.
> +eval {
> +    $g->set_uuid_random ("/dev/sda1")
> +};
> +# FIXME: ignore ESRCH

What is ESRCH about?

> +my $err = $g->last_errno ();
> +
> +if ($err == Errno::ENOTSUP()) {
> +    warn "$0: skipping test for btrfs UUID change feature is not available\n";
> +}

You need to care in case $err is non-zero, that is a real error.

Thanks,
-- 
Pino Toscano




More information about the Libguestfs mailing list