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") &&
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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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);