Re: [PATCH v4] npiv: Auto-generate WWN if it's not specified

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

 



On 02/03/2012 04:17 AM, Osier Yang wrote:
> The auto-generated WWN comply with the new addressing schema of WWN:
> 
> <quote>
> the first nibble is either hex 5 or 6 followed by a 3-byte vendor
> identifier and 36 bits for a vendor-specified serial number.
> </quote>
> 
> We choose hex 5 for the first nibble. And use Qumranet's OUI
> (00:1A:4A) as the 3-byte vendor indentifier. The last 36 bits
> are auto-generated.
> 

> +++ b/src/libvirt_private.syms
> @@ -1374,6 +1374,7 @@ virPidFileDeletePath;
>  # virrandom.h
>  virRandomBits;
>  virRandomInitialize;
> +virWWNGenerate;

This should be named with a virRandom prefix; I like

virRandomGenerateWWN

> +#define QUMRANET_OUI "001a4a"
> +
> +int virWWNGenerate(char **wwn) {

Formatting, I would do:

int
virRandomGenerateWWN(char **wwn)
{

> +   int suffix[5];
> +
> +   suffix[0] = virRandomBits(16);

Eep.  That's a waste of random bits (generating a uint16_t for just 4 bits).

> +   suffix[1] = virRandomBits(256);

And that's a usage error.  virRandomBits takes an argument 1-64, not larger.

> +   suffix[2] = virRandomBits(256);
> +   suffix[3] = virRandomBits(256);
> +   suffix[4] = virRandomBits(256);
> +
> +   if (virAsprintf(wwn, "%x%s%x%02x%02x%02x%02x", 0x5, QUMRANET_OUI,

Why not just:

if (virAsprintf(wwn, "5" QUMRANET_OUI "%010llx",
                (unsigned long long) virRandomBits(36)) < 0)

and skip going through a temporary array.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]