[libvirt] [PATCH v3] Improve SCSI volume key generation

Eric Blake eblake at redhat.com
Tue Apr 5 14:25:26 UTC 2011


On 04/05/2011 05:10 AM, Daniel P. Berrange wrote:
> The SCSI volumes get a better 'key' field based on the fully
> qualified volume path. All SCSI volumes have a unique serial
> available in hardware which can be obtained by sending a
> suitable SCSI command. Call out to udev's 'scsi_id' command
> to fetch this value
> 
> In v3:
>  
>  - Use virCommandSetOutputBuffer/virCommandRun instead
>    of VIR_FDOPEN
>  - Skip serial if it matches empty string
> 
> * src/storage/storage_backend_scsi.c: Improve volume key
>   field value stability and uniqueness
> ---
>  src/storage/storage_backend_scsi.c |   45 ++++++++++++++++++++++++++++++++---
>  1 files changed, 41 insertions(+), 4 deletions(-)
> 

> +#ifdef HAVE_UDEV
> +    virCommandPtr cmd = virCommandNewArgList(
> +        "/lib/udev/scsi_id",
> +        "--replace-whitespace",
> +        "--whitelisted",
> +        "--device", dev,
> +        NULL
> +        );
> +
> +    /* Run the program and capture its output */
> +    virCommandSetOutputBuffer(cmd, &serial);
> +    if (virCommandRun(cmd, NULL) < 0)
> +        goto cleanup;
> +#endif
> +
> +    if (serial && STRNEQ(serial, "")) {
> +        char *nl = strchr(serial, '\n');
> +        if (nl)
> +            *nl = '\0';
> +    } else {
> +        VIR_FREE(serial);
> +        if (!(serial = strdup(dev)))
> +            virReportOOMError();
> +    }
> +
> +#ifdef HAVE_UDEV
> +cleanup:
> +    virCommandFree(cmd);
> +#endif


It seems a bit weird to have two #ifdef sections; but I don't see any
easy way to consolidate them and still properly return failure on a
failed virCommandRun.

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110405/5fdd368f/attachment-0001.sig>


More information about the libvir-list mailing list