提交 8bf89dc8 编写于 作者: J John Ferlan

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: NJohn Ferlan <jferlan@redhat.com>
ACKed-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 9b86bbcc
...@@ -531,7 +531,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, ...@@ -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) {
......
...@@ -3778,36 +3778,17 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool) ...@@ -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 */
virCommandSetOutputBuffer(cmd, &serial);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
#endif
if (serial && STRNEQ(serial, "")) { rc = virStorageFileGetSCSIKey(dev, &serial, true);
char *nl = strchr(serial, '\n'); if (rc == 0 && serial)
if (nl) return serial;
*nl = '\0';
} else {
VIR_FREE(serial);
ignore_value(VIR_STRDUP(serial, dev));
}
#ifdef WITH_UDEV if (rc == -2)
cleanup: return NULL;
virCommandFree(cmd);
#endif
ignore_value(VIR_STRDUP(serial, dev));
return serial; return serial;
} }
......
...@@ -1428,6 +1428,7 @@ int virStorageFileGetLVMKey(const char *path, ...@@ -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, ...@@ -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, ...@@ -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
......
...@@ -390,7 +390,8 @@ bool virStorageIsRelative(const char *backing); ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册