[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Add host UUID (to libvirt capabilities)



On Mon, May 24, 2010 at 08:55:33AM -0400, Stefan Berger wrote:
> Index: libvirt-acl/daemon/libvirtd.c
> ===================================================================
> --- libvirt-acl.orig/daemon/libvirtd.c
> +++ libvirt-acl/daemon/libvirtd.c
> @@ -2718,6 +2718,7 @@ remoteReadConfigFile (struct qemud_serve
>      char *unix_sock_rw_perms = NULL;
>      char *unix_sock_group = NULL;
>      char *buf = NULL;
> +    char *host_uuid = NULL;
>  
>  #if HAVE_POLKIT
>      /* Change the default back to no auth for non-root */
> @@ -2840,6 +2841,10 @@ remoteReadConfigFile (struct qemud_serve
>      GET_CONF_INT (conf, filename, max_requests);
>      GET_CONF_INT (conf, filename, max_client_requests);
>  
> +    GET_CONF_STR (conf, filename, host_uuid);
> +    virSetHostUUIDStr(host_uuid);
> +    VIR_FREE(host_uuid);
> +
>      virConfFree (conf);
>      return 0;
>  
> Index: libvirt-acl/src/util/uuid.h
> ===================================================================
> --- libvirt-acl.orig/src/util/uuid.h
> +++ libvirt-acl/src/util/uuid.h
> @@ -22,6 +22,10 @@
>  #ifndef __VIR_UUID_H__
>  # define __VIR_UUID_H__
>  
> +int virSetHostUUIDStr(const char *host_uuid);
> +int virGetHostUUID(unsigned char *host_uuid);
> +int virGetHostUUIDStr(char *host_uuid);
> +
>  int virUUIDGenerate(unsigned char *uuid);
>  
>  int virUUIDParse(const char *uuidstr,
> Index: libvirt-acl/src/util/uuid.c
> ===================================================================
> --- libvirt-acl.orig/src/util/uuid.c
> +++ libvirt-acl/src/util/uuid.c
> @@ -38,11 +38,14 @@
>  #include "util.h"
>  #include "virterror_internal.h"
>  #include "logging.h"
> +#include "memory.h"
>  
>  #ifndef ENODATA
>  # define ENODATA EIO
>  #endif
>  
> +static unsigned char host_uuid[VIR_UUID_BUFLEN];
> +
>  static int
>  virUUIDGenerateRandomBytes(unsigned char *buf,
>                             int buflen)
> @@ -208,3 +211,154 @@ void virUUIDFormat(const unsigned char *
>               uuid[12], uuid[13], uuid[14], uuid[15]);
>      uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
>  }
> +
> +
> +
> +/**
> + * isValidHostUUID
> + *
> + * @uuid: The UUID to test
> + *
> + * Do some basic tests to check whether the given UUID is
> + * valid as a host UUID.
> + * Basic tests:
> + *  - Not all of the digits may be equal
> + */
> +static int
> +isValidHostUUID(unsigned char *uuid)
> +{
> +    unsigned int i, ctr = 1;
> +    unsigned char c;
> +
> +    if (!uuid)
> +        return 0;
> +
> +    c = uuid[0];
> +
> +    for (i = 1; i < VIR_UUID_BUFLEN; i++)
> +        if (uuid[i] == c)
> +            ctr++;
> +
> +    return (ctr != VIR_UUID_BUFLEN);
> +}
> +
> +static int
> +getDMISystemUUID(char *uuid, int len)
> +{
> +    const char *dmidecodearg[] = { "dmidecode", "-s", "system-uuid", NULL };
> +    const char *const dmidecodeenv[] = { "LC_ALL=C", NULL };
> +    char *binary, *newline;
> +    int dmidecodestdout = -1;
> +    int ret = -1;
> +    pid_t child;
> +
> +    binary = virFindFileInPath(dmidecodearg[0]);
> +    if (binary == NULL || access(binary, X_OK) != 0) {
> +        VIR_FREE(binary);
> +        return -1;
> +    }
> +    dmidecodearg[0] = binary;
> +
> +    if (virExec(dmidecodearg, dmidecodeenv, NULL,
> +                &child, -1, &dmidecodestdout, NULL, VIR_EXEC_CLEAR_CAPS) < 0) {
> +        ret = -1;
> +        goto cleanup;
> +    }

I've just remembered that the DMIDecode data is available from sysfs so we 
can avoid needing to run dmidecode at all. Depending on kernel version it 
can be in either

   "/sys/devices/virtual/dmi/id"
   "/sys/class/dmi/id"

There's some code in src/.node_device/node_device_udev.c the udevGetDMIData()
method which already reads this. We can just do the same, and even make 
udevGetDMIData() call into virGetHostUUID() now

Regards,
Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]