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@xxxxxxxxxx +1-801-349-2682 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