storage: Rework virStorageBackendSCSISerial

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@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
John Ferlan 2019-01-15 15:59:21 -05:00
parent 9b86bbccb3
commit 8bf89dc837
4 changed files with 17 additions and 31 deletions

View File

@ -531,7 +531,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
if (STRPREFIX(name, "/dev") && if (STRPREFIX(name, "/dev") &&
driver->scsiLockSpaceDir) { driver->scsiLockSpaceDir) {
VIR_DEBUG("Trying to find an SCSI ID for %s", name); VIR_DEBUG("Trying to find an SCSI ID for %s", name);
if (virStorageFileGetSCSIKey(name, &newName) < 0) if (virStorageFileGetSCSIKey(name, &newName, false) < 0)
goto cleanup; goto cleanup;
if (newName) { if (newName) {

View File

@ -3778,36 +3778,17 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
static char * static char *
virStorageBackendSCSISerial(const char *dev) virStorageBackendSCSISerial(const char *dev)
{ {
int rc;
char *serial = NULL; 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 */ rc = virStorageFileGetSCSIKey(dev, &serial, true);
virCommandSetOutputBuffer(cmd, &serial); if (rc == 0 && serial)
if (virCommandRun(cmd, NULL) < 0) return serial;
goto cleanup;
#endif
if (serial && STRNEQ(serial, "")) { if (rc == -2)
char *nl = strchr(serial, '\n'); return NULL;
if (nl)
*nl = '\0';
} else {
VIR_FREE(serial);
ignore_value(VIR_STRDUP(serial, dev));
}
#ifdef WITH_UDEV
cleanup:
virCommandFree(cmd);
#endif
ignore_value(VIR_STRDUP(serial, dev));
return serial; return serial;
} }

View File

@ -1428,6 +1428,7 @@ int virStorageFileGetLVMKey(const char *path,
/* virStorageFileGetSCSIKey /* virStorageFileGetSCSIKey
* @path: Path to the SCSI device * @path: Path to the SCSI device
* @key: Unique key to be returned * @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 * Using a udev specific function, query the @path to get and return a
* unique @key for the caller to use. * unique @key for the caller to use.
@ -1440,7 +1441,8 @@ int virStorageFileGetLVMKey(const char *path,
*/ */
int int
virStorageFileGetSCSIKey(const char *path, virStorageFileGetSCSIKey(const char *path,
char **key) char **key,
bool ignoreError ATTRIBUTE_UNUSED)
{ {
int status; int status;
virCommandPtr cmd = virCommandNewArgList("/lib/udev/scsi_id", virCommandPtr cmd = virCommandNewArgList("/lib/udev/scsi_id",
@ -1480,9 +1482,11 @@ virStorageFileGetSCSIKey(const char *path,
} }
#else #else
int virStorageFileGetSCSIKey(const char *path, 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; return -1;
} }
#endif #endif

View File

@ -390,7 +390,8 @@ bool virStorageIsRelative(const char *backing);
int virStorageFileGetLVMKey(const char *path, int virStorageFileGetLVMKey(const char *path,
char **key); char **key);
int virStorageFileGetSCSIKey(const char *path, int virStorageFileGetSCSIKey(const char *path,
char **key); char **key,
bool ignoreError);
void virStorageAuthDefFree(virStorageAuthDefPtr def); void virStorageAuthDefFree(virStorageAuthDefPtr def);
virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src); virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);