]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: move virStorageFileGetLVMKey to locking
authorPavel Hrdina <phrdina@redhat.com>
Fri, 4 Dec 2020 05:52:18 +0000 (06:52 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 6 Jan 2021 12:15:17 +0000 (13:15 +0100)
The function doesn't take virStorageSource as argument and has nothing
in common with virStorageSource or storage file.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/libvirt_private.syms
src/locking/lock_driver_lockd.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index b8fedc82d568ed50534a236408adf768423cb730..78d4e5ab30c2c5d2f6c707cf7f6776352a6c8d8c 100644 (file)
@@ -3135,7 +3135,6 @@ virStorageFileFeatureTypeToString;
 virStorageFileFormatTypeFromString;
 virStorageFileFormatTypeToString;
 virStorageFileGetBackingStoreStr;
-virStorageFileGetLVMKey;
 virStorageFileGetMetadata;
 virStorageFileGetMetadataFromBuf;
 virStorageFileGetMetadataFromFD;
index 15d9e5f076587beafc7e8c1a4ede6446e3e402b3..d459c1668c5325404d393ccb6fb1c207ae147f59 100644 (file)
@@ -24,6 +24,7 @@
 #include "lock_driver.h"
 #include "virconf.h"
 #include "viralloc.h"
+#include "vircommand.h"
 #include "vircrypto.h"
 #include "virlog.h"
 #include "viruuid.h"
@@ -455,6 +456,71 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock,
 }
 
 
+#ifdef LVS
+static int
+virLockManagerGetLVMKey(const char *path,
+                        char **key)
+{
+    /*
+     *  # lvs --noheadings --unbuffered --nosuffix --options "uuid" LVNAME
+     *    06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky
+     */
+    int status;
+    int ret = -1;
+    g_autoptr(virCommand) cmd = NULL;
+
+    cmd = virCommandNewArgList(LVS, "--noheadings",
+                               "--unbuffered", "--nosuffix",
+                               "--options", "uuid", path,
+                               NULL
+                               );
+    *key = NULL;
+
+    /* Run the program and capture its output */
+    virCommandSetOutputBuffer(cmd, key);
+    if (virCommandRun(cmd, &status) < 0)
+        goto cleanup;
+
+    /* Explicitly check status == 0, rather than passing NULL
+     * to virCommandRun because we don't want to raise an actual
+     * error in this scenario, just return a NULL key.
+     */
+
+    if (status == 0 && *key) {
+        char *nl;
+        char *tmp = *key;
+
+        /* Find first non-space character */
+        while (*tmp && g_ascii_isspace(*tmp))
+            tmp++;
+        /* Kill leading spaces */
+        if (tmp != *key)
+            memmove(*key, tmp, strlen(tmp)+1);
+
+        /* Kill trailing newline */
+        if ((nl = strchr(*key, '\n')))
+            *nl = '\0';
+    }
+
+    ret = 0;
+
+ cleanup:
+    if (*key && STREQ(*key, ""))
+        VIR_FREE(*key);
+
+    return ret;
+}
+#else
+static int
+virLockManagerGetLVMKey(const char *path,
+                        char **key G_GNUC_UNUSED)
+{
+    virReportSystemError(ENOSYS, _("Unable to get LVM key for %s"), path);
+    return -1;
+}
+#endif
+
+
 static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
                                                unsigned int type,
                                                const char *name,
@@ -494,7 +560,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
         if (STRPREFIX(name, "/dev") &&
             driver->lvmLockSpaceDir) {
             VIR_DEBUG("Trying to find an LVM UUID for %s", name);
-            if (virStorageFileGetLVMKey(name, &newName) < 0)
+            if (virLockManagerGetLVMKey(name, &newName) < 0)
                 goto cleanup;
 
             if (newName) {
index 119342d29641e14430c5503a9eb02e22d043502e..bc342cabe3b6cf33dc04b236dfbcde65046bad8f 100644 (file)
@@ -1251,68 +1251,6 @@ int virStorageFileIsClusterFS(const char *path)
                                  VIR_FILE_SHFS_CEPH);
 }
 
-#ifdef LVS
-int virStorageFileGetLVMKey(const char *path,
-                            char **key)
-{
-    /*
-     *  # lvs --noheadings --unbuffered --nosuffix --options "uuid" LVNAME
-     *    06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky
-     */
-    int status;
-    int ret = -1;
-    g_autoptr(virCommand) cmd = NULL;
-
-    cmd = virCommandNewArgList(LVS, "--noheadings",
-                               "--unbuffered", "--nosuffix",
-                               "--options", "uuid", path,
-                               NULL
-                               );
-    *key = NULL;
-
-    /* Run the program and capture its output */
-    virCommandSetOutputBuffer(cmd, key);
-    if (virCommandRun(cmd, &status) < 0)
-        goto cleanup;
-
-    /* Explicitly check status == 0, rather than passing NULL
-     * to virCommandRun because we don't want to raise an actual
-     * error in this scenario, just return a NULL key.
-     */
-
-    if (status == 0 && *key) {
-        char *nl;
-        char *tmp = *key;
-
-        /* Find first non-space character */
-        while (*tmp && g_ascii_isspace(*tmp))
-            tmp++;
-        /* Kill leading spaces */
-        if (tmp != *key)
-            memmove(*key, tmp, strlen(tmp)+1);
-
-        /* Kill trailing newline */
-        if ((nl = strchr(*key, '\n')))
-            *nl = '\0';
-    }
-
-    ret = 0;
-
- cleanup:
-    if (*key && STREQ(*key, ""))
-        VIR_FREE(*key);
-
-    return ret;
-}
-#else
-int virStorageFileGetLVMKey(const char *path,
-                            char **key G_GNUC_UNUSED)
-{
-    virReportSystemError(ENOSYS, _("Unable to get LVM key for %s"), path);
-    return -1;
-}
-#endif
-
 #ifdef WITH_UDEV
 /* virStorageFileGetSCSIKey
  * @path: Path to the SCSI device
index cc9bd4875f21b0c30f2efd9983714c39c21bcef6..31feb22f26a167a9b38e6fbed203f208c461e299 100644 (file)
@@ -428,8 +428,6 @@ int virStorageFileIsClusterFS(const char *path);
 bool virStorageIsFile(const char *path);
 bool virStorageIsRelative(const char *backing);
 
-int virStorageFileGetLVMKey(const char *path,
-                            char **key);
 int virStorageFileGetSCSIKey(const char *path,
                              char **key,
                              bool ignoreError);