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

Re: [libvirt] [PATCH v2] Improve SCSI volume key generation



On 04/04/2011 10:59 AM, Daniel P. Berrange wrote:
> An update of patch 10 from:
> 
> http://www.redhat.com/archives/libvir-list/2010-November/msg00555.html
> 
> 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
> 
> +static char *
> +virStorageBackendSCSISerial(const char *dev)
> +{
> +    char *serial = NULL;
> +#ifdef HAVE_UDEV
> +    int fd = -1;
> +    FILE *list = NULL;
> +    char line[1024];
> +    virCommandPtr cmd = virCommandNewArgList(
> +        "/lib/udev/scsi_id",
> +        "--replace-whitespace",
> +        "--whitelisted",
> +        "--device", dev,
> +        NULL
> +        );
> +
> +    /* Run the program and capture its output */
> +    virCommandSetOutputFD(cmd, &fd);

Why not just run virCommandSetOutputBuffer, to capture the entire output
into a single string...

> +    if (virCommandRunAsync(cmd, NULL) < 0)
> +        goto cleanup;

...then you just use virCommandRun,

> +
> +    if ((list = VIR_FDOPEN(fd, "r")) == NULL) {

...you don't have to mess with fdopen,

> +        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
> +                              "%s", _("cannot read fd"));
> +        goto cleanup;
> +    }
> +
> +    if (fgets(line, sizeof(line), list)) {

...and you don't have to mess with fgets,

> +cleanup:
> +    if (list)
> +        fclose(list);

and your cleanup gets a lot easier (not to mention that 'make
syntax-check' should have been telling you to use VIR_FORCE_FCLOSE if
you don't make those simplifications).

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

Attachment: signature.asc
Description: OpenPGP digital signature


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