diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 16fce551c3..4ffa92fc9b 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -531,7 +531,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (STRPREFIX(name, "/dev") && driver->scsiLockSpaceDir) { VIR_DEBUG("Trying to find an SCSI ID for %s", name); - if (virStorageFileGetSCSIKey(name, &newName) < 0) + if (virStorageFileGetSCSIKey(name, &newName, false) < 0) goto cleanup; if (newName) { diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index de6f8ec2bd..b5056bbb05 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3778,36 +3778,17 @@ 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 + rc = virStorageFileGetSCSIKey(dev, &serial, true); + if (rc == 0 && serial) + return serial; - if (serial && STRNEQ(serial, "")) { - char *nl = strchr(serial, '\n'); - if (nl) - *nl = '\0'; - } else { - VIR_FREE(serial); - ignore_value(VIR_STRDUP(serial, dev)); - } - -#ifdef WITH_UDEV - cleanup: - virCommandFree(cmd); -#endif + if (rc == -2) + return NULL; + ignore_value(VIR_STRDUP(serial, dev)); return serial; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2fc8ed840e..a2f0670e50 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1428,6 +1428,7 @@ int virStorageFileGetLVMKey(const char *path, /* virStorageFileGetSCSIKey * @path: Path to the SCSI device * @key: Unique key to be returned + * @ignoreError: Used to not report ENOSYS * * Using a udev specific function, query the @path to get and return a * unique @key for the caller to use. @@ -1440,7 +1441,8 @@ int virStorageFileGetLVMKey(const char *path, */ int virStorageFileGetSCSIKey(const char *path, - char **key) + char **key, + bool ignoreError ATTRIBUTE_UNUSED) { int status; virCommandPtr cmd = virCommandNewArgList("/lib/udev/scsi_id", @@ -1480,9 +1482,11 @@ virStorageFileGetSCSIKey(const char *path, } #else int virStorageFileGetSCSIKey(const char *path, - char **key ATTRIBUTE_UNUSED) + char **key ATTRIBUTE_UNUSED, + bool ignoreError) { - virReportSystemError(ENOSYS, _("Unable to get SCSI key for %s"), path); + if (!ignoreError) + virReportSystemError(ENOSYS, _("Unable to get SCSI key for %s"), path); return -1; } #endif diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 1d6161a2c7..03837e9e58 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -390,7 +390,8 @@ bool virStorageIsRelative(const char *backing); int virStorageFileGetLVMKey(const char *path, char **key); int virStorageFileGetSCSIKey(const char *path, - char **key); + char **key, + bool ignoreError); void virStorageAuthDefFree(virStorageAuthDefPtr def); virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);