Alter the code to use the virStorageFileGetSCSIKey helper
to fetch the unique key for the SCSI disk. Alter the logic
to follow the former code which would return a duplicate
of @dev when either the virCommandRun succeeded, but returned
an empty string or when WITH_UDEV was not true.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_util.c | 34 ++++++++--------------------------
1 file changed, 8 insertions(+), 26 deletions(-)
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index a84ee5b600..aa1af434de 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -3758,36 +3758,18 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
static char *
virStorageBackendSCSISerial(const char *dev)
{
+ int rc;
char *serial = NULL;
-#ifdef WITH_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);
- ignore_value(VIR_STRDUP(serial, dev));
- }
+ rc = virStorageFileGetSCSIKey(dev, &serial);
+ if (rc == 0 && serial)
+ return serial;
-#ifdef WITH_UDEV
- cleanup:
- virCommandFree(cmd);
-#endif
+ if (rc == -2)
+ return NULL;
+ virResetLastError();
+ ignore_value(VIR_STRDUP(serial, dev));
return serial;
}
--
2.20.1