[Libguestfs] [PATCH 1/1] New API: luks_uuid

Richard W.M. Jones rjones at redhat.com
Fri Nov 29 11:35:42 UTC 2019


On Fri, Nov 29, 2019 at 12:18:22PM +0100, Pino Toscano wrote:
> Return the UUID of a LUKS device.
> ---
>  daemon/luks.c             | 25 +++++++++++++++++++++++++
>  generator/actions_core.ml |  8 ++++++++
>  generator/proc_nr.ml      |  1 +
>  lib/MAX_PROC_NR           |  2 +-
>  4 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/daemon/luks.c b/daemon/luks.c
> index 5c48a91eb..d631cb100 100644
> --- a/daemon/luks.c
> +++ b/daemon/luks.c
> @@ -292,3 +292,28 @@ do_luks_kill_slot (const char *device, const char *key, int keyslot)
>  
>    return 0;
>  }
> +
> +char *
> +do_luks_uuid (const char *device)
> +{
> +  const char *argv[MAX_ARGS];
> +  size_t i = 0;
> +
> +  ADD_ARG (argv, i, "cryptsetup");
> +  ADD_ARG (argv, i, "luksUUID");
> +  ADD_ARG (argv, i, device);
> +  ADD_ARG (argv, i, NULL);

Easier than I expected.  I thought we'd have to parse luksDump :-)

ACK

Rich.

> +  char *out = NULL;
> +  CLEANUP_FREE char *err = NULL;
> +  int r = commandv (&out, &err, (const char * const *) argv);
> +
> +  if (r == -1) {
> +    reply_with_error ("%s", err);
> +    return NULL;
> +  }
> +
> +  trim (out);
> +
> +  return out;
> +}
> diff --git a/generator/actions_core.ml b/generator/actions_core.ml
> index 8443ae79e..cb7e8dcd0 100644
> --- a/generator/actions_core.ml
> +++ b/generator/actions_core.ml
> @@ -9728,4 +9728,12 @@ it is useful when you have added a new device or deleted an
>  existing device (such as when the C<guestfs_luks_open> API
>  is used)." };
>  
> +  { defaults with
> +    name = "luks_uuid"; added = (1, 41, 9);
> +    style = RString (RPlainString, "uuid"), [String (Device, "device")], [];
> +    optional = Some "luks";
> +    shortdesc = "get the UUID of a LUKS device";
> +    longdesc = "\
> +This returns the UUID of the LUKS device C<device>." };
> +
>  ]
> diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml
> index efa8c5d21..11a557076 100644
> --- a/generator/proc_nr.ml
> +++ b/generator/proc_nr.ml
> @@ -514,6 +514,7 @@ let proc_nr = [
>  504, "part_get_gpt_attributes";
>  505, "f2fs_expand";
>  506, "lvm_scan";
> +507, "luks_uuid";
>  ]
>  
>  (* End of list.  If adding a new entry, add it at the end of the list
> diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR
> index 80e3e6eab..055b6671a 100644
> --- a/lib/MAX_PROC_NR
> +++ b/lib/MAX_PROC_NR
> @@ -1 +1 @@
> -506
> +507
> -- 
> 2.21.0
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
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




More information about the Libguestfs mailing list