]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Rework virStorageBackendSCSISerial
authorJohn Ferlan <jferlan@redhat.com>
Tue, 15 Jan 2019 20:59:21 +0000 (15:59 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 1 Feb 2019 15:30:45 +0000 (10:30 -0500)
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>
src/locking/lock_driver_lockd.c
src/storage/storage_util.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 16fce551c36864b62ca16bd33281b3dca8c40774..4ffa92fc9b570704afc2303a431800de0877949e 100644 (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) {
index de6f8ec2bd0811466c6d13262ecec099293c1675..b5056bbb05ec8a4709fc2db34a6d07b24b1067b1 100644 (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
 
-    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, true);
+    if (rc == 0 && serial)
+        return serial;
 
-#ifdef WITH_UDEV
- cleanup:
-    virCommandFree(cmd);
-#endif
+    if (rc == -2)
+        return NULL;
 
+    ignore_value(VIR_STRDUP(serial, dev));
     return serial;
 }
 
index 2fc8ed840e996cbcb380673eee8eae732a7d43ab..a2f0670e508613a2b5bf88b8145a33947234106c 100644 (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
index 1d6161a2c77c6c17c9d85d087dbc09b0f1c18929..03837e9e58a9b60aa3dbf374d98002fbdee76830 100644 (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);