]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: stop hardcoding LVM tool paths
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 29 Apr 2025 10:47:27 +0000 (11:47 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 2 May 2025 08:31:28 +0000 (09:31 +0100)
Change the meson rules to always enable the LVM driver if on a
Linux host, unless the meson options say not to.

The virCommand APIs will return suitable runtime errors if the
tools are not installed.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
meson.build
src/locking/lock_driver_lockd.c
src/storage/storage_backend_logical.c

index 4991868449fcae38fc6405cdfb39a4ad54d06b46..bb0436e0720ee3d955535b44ca5980038c841390 100644 (file)
@@ -1826,32 +1826,12 @@ if conf.has('WITH_LIBVIRTD')
     error('Need libiscsi for iscsi-direct storage driver')
   endif
 
-  if not get_option('storage_lvm').disabled()
+  if not get_option('storage_lvm').disabled() and host_machine.system() == 'linux'
     lvm_enable = true
-    lvm_progs = [
-      'pvcreate', 'vgcreate', 'lvcreate',
-      'pvremove', 'vgremove', 'lvremove',
-      'lvchange', 'vgchange', 'vgscan',
-      'pvs', 'vgs', 'lvs',
-    ]
-    foreach name : lvm_progs
-      set_variable(
-        '@0@_prog'.format(name),
-        find_program(name, required: get_option('storage_lvm'), dirs: libvirt_sbin_path)
-      )
-      if not get_variable('@0@_prog'.format(name)).found()
-        lvm_enable = false
-      endif
-    endforeach
-
-    if lvm_enable
-      use_storage = true
-      conf.set('WITH_STORAGE_LVM', 1)
-
-      foreach name : lvm_progs
-        conf.set_quoted(name.to_upper(), get_variable('@0@_prog'.format(name)).full_path())
-      endforeach
-    endif
+    use_storage = true
+    conf.set('WITH_STORAGE_LVM', 1)
+  elif get_option('storage_lvm').enabled()
+    error('Linux host needed for LVM storage driver')
   endif
 
   if not get_option('storage_mpath').disabled() and host_machine.system() == 'linux' and devmapper_dep.found()
index 0b6c72047750e65c716b8c27900fc1f4c433e8af..a3bb285eecbc8673309aea90cb7d154d445162bc 100644 (file)
@@ -433,7 +433,7 @@ static int virLockManagerLockDaemonNew(virLockManager *lock,
 }
 
 
-#ifdef LVS
+#ifdef __linux__
 static int
 virLockManagerGetLVMKey(const char *path,
                         char **key)
@@ -446,7 +446,7 @@ virLockManagerGetLVMKey(const char *path,
     int ret = -1;
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = virCommandNewArgList(LVS, "--noheadings",
+    cmd = virCommandNewArgList("lvs", "--noheadings",
                                "--unbuffered", "--nosuffix",
                                "--options", "uuid", path,
                                NULL
index 6acbc37f18d0ae6da77a5b98e7715a8510580e02..51e93378206747da2eb66fb85df29c92525bc45c 100644 (file)
@@ -49,7 +49,7 @@ virStorageBackendLogicalSetActive(virStoragePoolObj *pool,
     g_autoptr(virCommand) cmd = NULL;
     int ret;
 
-    cmd = virStorageBackendLogicalChangeCmd(VGCHANGE, def, on);
+    cmd = virStorageBackendLogicalChangeCmd("vgchange", def, on);
 
     virObjectUnlock(pool);
     ret = virCommandRun(cmd, NULL);
@@ -70,7 +70,7 @@ virStorageBackendLogicalRemoveDevice(const char *path)
 {
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = virCommandNewArgList(PVREMOVE, path, NULL);
+    cmd = virCommandNewArgList("pvremove", path, NULL);
     if (virCommandRun(cmd, NULL) < 0)
         VIR_INFO("Failed to pvremove logical device '%s'", path);
 }
@@ -100,7 +100,7 @@ virStorageBackendLogicalInitializeDevice(const char *path)
      * Initialize the physical volume because vgcreate is not
      * clever enough todo this for us :-(
      */
-    pvcmd = virCommandNewArgList(PVCREATE, path, NULL);
+    pvcmd = virCommandNewArgList("pvcreate", path, NULL);
     return virCommandRun(pvcmd, NULL);
 }
 
@@ -380,7 +380,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObj *pool,
     };
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = virCommandNewArgList(LVS,
+    cmd = virCommandNewArgList("lvs",
                                "--separator", "#",
                                "--noheadings",
                                "--units", "b",
@@ -483,11 +483,11 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceList *sourceList)
      * that might be hanging around, so if this fails for some reason, the
      * worst that happens is that scanning doesn't pick everything up
      */
-    vgcmd = virCommandNew(VGSCAN);
+    vgcmd = virCommandNew("vgscan");
     if (virCommandRun(vgcmd, NULL) < 0)
         VIR_WARN("Failure when running vgscan to refresh physical volumes");
 
-    pvcmd = virCommandNewArgList(PVS,
+    pvcmd = virCommandNewArgList("pvs",
                                  "--noheadings",
                                  "-o", "pv_name,vg_name",
                                  NULL, NULL);
@@ -658,7 +658,7 @@ virStorageBackendLogicalBuildPool(virStoragePoolObj *pool,
                              VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
                              cleanup);
 
-    vgcmd = virCommandNewArgList(VGCREATE, def->source.name, NULL);
+    vgcmd = virCommandNewArgList("vgcreate", def->source.name, NULL);
 
     for (i = 0; i < def->source.ndevice; i++) {
         const char *path = def->source.devices[i].path;
@@ -720,7 +720,7 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObj *pool)
     if (virStorageBackendLogicalFindLVs(pool, NULL) < 0)
         return -1;
 
-    cmd = virCommandNewArgList(VGS,
+    cmd = virCommandNewArgList("vgs",
                                "--separator", ":",
                                "--noheadings",
                                "--units", "b",
@@ -769,7 +769,7 @@ virStorageBackendLogicalDeletePool(virStoragePoolObj *pool,
     virCheckFlags(0, -1);
 
     /* first remove the volume group */
-    cmd = virCommandNewArgList(VGREMOVE,
+    cmd = virCommandNewArgList("vgremove",
                                "-f", def->source.name,
                                NULL);
     if (virCommandRun(cmd, NULL) < 0)
@@ -795,8 +795,8 @@ virStorageBackendLogicalDeleteVol(virStoragePoolObj *pool G_GNUC_UNUSED,
 
     virWaitForDevices();
 
-    lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", vol->target.path, NULL);
-    lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", vol->target.path, NULL);
+    lvchange_cmd = virCommandNewArgList("lvchange", "-aln", vol->target.path, NULL);
+    lvremove_cmd = virCommandNewArgList("lvremove", "-f", vol->target.path, NULL);
 
     if (virCommandRun(lvremove_cmd, NULL) < 0) {
         if (virCommandRun(lvchange_cmd, NULL) < 0) {
@@ -825,7 +825,7 @@ virStorageBackendLogicalLVCreate(virStorageVolDef *vol,
         return -1;
     }
 
-    cmd = virCommandNewArgList(LVCREATE,
+    cmd = virCommandNewArgList("lvcreate",
                                "--name", vol->name,
                                NULL);
     virCommandAddArg(cmd, "-L");