bcddb9
From 4b841d996f9e1181e6a0614eb0bc9a35d5f7c372 Mon Sep 17 00:00:00 2001
bcddb9
Message-Id: <4b841d996f9e1181e6a0614eb0bc9a35d5f7c372@dist-git>
bcddb9
From: John Ferlan <jferlan@redhat.com>
bcddb9
Date: Tue, 12 Mar 2019 13:55:57 -0400
bcddb9
Subject: [PATCH] storage: Rework virStorageBackendSCSISerial
bcddb9
MIME-Version: 1.0
bcddb9
Content-Type: text/plain; charset=UTF-8
bcddb9
Content-Transfer-Encoding: 8bit
bcddb9
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1687715 (7.6.z)
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1657468 (7.7.0)
bcddb9
bcddb9
Alter the code to use the virStorageFileGetSCSIKey helper
bcddb9
to fetch the unique key for the SCSI disk. Alter the logic
bcddb9
to follow the former code which would return a duplicate
bcddb9
of @dev when either the virCommandRun succeeded, but returned
bcddb9
an empty string or when WITH_UDEV was not true.
bcddb9
bcddb9
Signed-off-by: John Ferlan <jferlan@redhat.com>
bcddb9
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
bcddb9
Reviewed-by: Ján Tomko <jtomko@redhat.com>
bcddb9
(cherry picked from commit 8bf89dc83729aaa0388f89e972a4847fd1e267c6)
bcddb9
bcddb9
Managed conflict in src/locking/lock_driver_lockd.c as a result of
bcddb9
commit e9e904b3b70533982954ab39ccb81122e8dad338 which changed from
bcddb9
using "goto error" to using "goto cleanup" by using the error label.
bcddb9
bcddb9
Signed-off-by: John Ferlan <jferlan@redhat.com>
bcddb9
Message-Id: <20190312175559.13583-3-jferlan@redhat.com>
bcddb9
Reviewed-by: Ján Tomko <jtomko@redhat.com>
bcddb9
---
bcddb9
 src/locking/lock_driver_lockd.c |  2 +-
bcddb9
 src/storage/storage_util.c      | 33 +++++++--------------------------
bcddb9
 src/util/virstoragefile.c       | 10 +++++++---
bcddb9
 src/util/virstoragefile.h       |  3 ++-
bcddb9
 4 files changed, 17 insertions(+), 31 deletions(-)
bcddb9
bcddb9
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
bcddb9
index 957a963a7b..1b9341ceba 100644
bcddb9
--- a/src/locking/lock_driver_lockd.c
bcddb9
+++ b/src/locking/lock_driver_lockd.c
bcddb9
@@ -517,7 +517,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
bcddb9
         if (STRPREFIX(name, "/dev") &&
bcddb9
             driver->scsiLockSpaceDir) {
bcddb9
             VIR_DEBUG("Trying to find an SCSI ID for %s", name);
bcddb9
-            if (virStorageFileGetSCSIKey(name, &newName) < 0)
bcddb9
+            if (virStorageFileGetSCSIKey(name, &newName, false) < 0)
bcddb9
                 goto error;
bcddb9
 
bcddb9
             if (newName) {
bcddb9
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
bcddb9
index 5dc22d3182..d1659c0c8d 100644
bcddb9
--- a/src/storage/storage_util.c
bcddb9
+++ b/src/storage/storage_util.c
bcddb9
@@ -3696,36 +3696,17 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
bcddb9
 static char *
bcddb9
 virStorageBackendSCSISerial(const char *dev)
bcddb9
 {
bcddb9
+    int rc;
bcddb9
     char *serial = NULL;
bcddb9
-#ifdef WITH_UDEV
bcddb9
-    virCommandPtr cmd = virCommandNewArgList(
bcddb9
-        "/lib/udev/scsi_id",
bcddb9
-        "--replace-whitespace",
bcddb9
-        "--whitelisted",
bcddb9
-        "--device", dev,
bcddb9
-        NULL
bcddb9
-        );
bcddb9
 
bcddb9
-    /* Run the program and capture its output */
bcddb9
-    virCommandSetOutputBuffer(cmd, &serial);
bcddb9
-    if (virCommandRun(cmd, NULL) < 0)
bcddb9
-        goto cleanup;
bcddb9
-#endif
bcddb9
+    rc = virStorageFileGetSCSIKey(dev, &serial, true);
bcddb9
+    if (rc == 0 && serial)
bcddb9
+        return serial;
bcddb9
 
bcddb9
-    if (serial && STRNEQ(serial, "")) {
bcddb9
-        char *nl = strchr(serial, '\n');
bcddb9
-        if (nl)
bcddb9
-            *nl = '\0';
bcddb9
-    } else {
bcddb9
-        VIR_FREE(serial);
bcddb9
-        ignore_value(VIR_STRDUP(serial, dev));
bcddb9
-    }
bcddb9
-
bcddb9
-#ifdef WITH_UDEV
bcddb9
- cleanup:
bcddb9
-    virCommandFree(cmd);
bcddb9
-#endif
bcddb9
+    if (rc == -2)
bcddb9
+        return NULL;
bcddb9
 
bcddb9
+    ignore_value(VIR_STRDUP(serial, dev));
bcddb9
     return serial;
bcddb9
 }
bcddb9
 
bcddb9
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
bcddb9
index ed7266619d..56d38b467e 100644
bcddb9
--- a/src/util/virstoragefile.c
bcddb9
+++ b/src/util/virstoragefile.c
bcddb9
@@ -1438,6 +1438,7 @@ int virStorageFileGetLVMKey(const char *path,
bcddb9
 /* virStorageFileGetSCSIKey
bcddb9
  * @path: Path to the SCSI device
bcddb9
  * @key: Unique key to be returned
bcddb9
+ * @ignoreError: Used to not report ENOSYS
bcddb9
  *
bcddb9
  * Using a udev specific function, query the @path to get and return a
bcddb9
  * unique @key for the caller to use.
bcddb9
@@ -1450,7 +1451,8 @@ int virStorageFileGetLVMKey(const char *path,
bcddb9
  */
bcddb9
 int
bcddb9
 virStorageFileGetSCSIKey(const char *path,
bcddb9
-                         char **key)
bcddb9
+                         char **key,
bcddb9
+                         bool ignoreError ATTRIBUTE_UNUSED)
bcddb9
 {
bcddb9
     int status;
bcddb9
     virCommandPtr cmd = virCommandNewArgList(
bcddb9
@@ -1491,9 +1493,11 @@ virStorageFileGetSCSIKey(const char *path,
bcddb9
 }
bcddb9
 #else
bcddb9
 int virStorageFileGetSCSIKey(const char *path,
bcddb9
-                             char **key ATTRIBUTE_UNUSED)
bcddb9
+                             char **key ATTRIBUTE_UNUSED,
bcddb9
+                             bool ignoreError)
bcddb9
 {
bcddb9
-    virReportSystemError(ENOSYS, _("Unable to get SCSI key for %s"), path);
bcddb9
+    if (!ignoreError)
bcddb9
+        virReportSystemError(ENOSYS, _("Unable to get SCSI key for %s"), path);
bcddb9
     return -1;
bcddb9
 }
bcddb9
 #endif
bcddb9
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
bcddb9
index 991098e6c6..bbb0b8b3c1 100644
bcddb9
--- a/src/util/virstoragefile.h
bcddb9
+++ b/src/util/virstoragefile.h
bcddb9
@@ -384,7 +384,8 @@ bool virStorageIsRelative(const char *backing);
bcddb9
 int virStorageFileGetLVMKey(const char *path,
bcddb9
                             char **key);
bcddb9
 int virStorageFileGetSCSIKey(const char *path,
bcddb9
-                             char **key);
bcddb9
+                             char **key,
bcddb9
+                             bool ignoreError);
bcddb9
 
bcddb9
 void virStorageAuthDefFree(virStorageAuthDefPtr def);
bcddb9
 virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);
bcddb9
-- 
bcddb9
2.21.0
bcddb9