[Libvir] UUID buffer lengths [was Re: Virtual networking]

Daniel P. Berrange berrange at redhat.com
Tue Jan 23 12:59:49 UTC 2007


On Tue, Jan 23, 2007 at 12:37:50PM +0000, Mark McLoughlin wrote:
> On Tue, 2007-01-23 at 11:20 +0100, Karel Zak wrote:
> 
> > +    char uuid[37];
> > 
> >   Magic number? :-)
> > 
> >   #define UUID_STRLEN	36
> > 
> >    char uuid[UUID_STRLEN+1];
> 
> 	Good point. Here's a proposed API addition to put the buffer lengths as
> macros in libvirt.h.
> 
> 	Anyone got objections to that?

No objections, but I think if we're going to do this, we should take it
one step further and provide APIs for converting between RAW & Printable
versions of UUID in both directions. Currently we're just duping this
conversion code all over the place - with inconsistent use of '-' in
the printable versions.


   /*
    * uuidstr: the printable UUID string
    * uuid: pre-allocated buffer of length VIR_UUID_BUFLEN
    */
   int virUUIDParseString(const char *uuidstr, unsigned char *uuid)

   /*
    * uuid: the raw UUID valu exactly VIR_UUID_BUFLEN bytes long
    * uuidstr: pre-allocated buffer of length VIR_UUID_STRING_BUFLEN 
    *          to be filled in printable UUID
    */
   int virUUIDFormatString(const unsigned char *uuid, char *uuidstr)

Oh and a thing to generate a random UUID too is needed by both the xm_internal
and qemu  & test backends

    int virUUIDGenerate(unsigned char *uuid);

Probably we only need any of this stuff in the internal headers though, rather 
than public facing

> --- libvirt.orig/include/libvirt/libvirt.h.in
> +++ libvirt/include/libvirt/libvirt.h.in
> @@ -187,6 +187,24 @@ struct _virNodeInfo {
>  
>  typedef virNodeInfo *virNodeInfoPtr;
>  
> +/**
> + * VIR_UUID_STRING_BUFLEN:
> + *
> + * This macro provides the length of the buffer required
> + * for virDomainGetUUID()
> + */
> +
> +#define VIR_UUID_BUFLEN (16)
> +
> +/**
> + * VIR_UUID_STRING_BUFLEN:
> + *
> + * This macro provides the length of the buffer required
> + * for virDomainGetUUIDString()
> + */
> +
> +#define VIR_UUID_STRING_BUFLEN (36+1)
> +
>  /* library versionning */


Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 




More information about the libvir-list mailing list