[Libguestfs] [PATCH v2 3/4] New API: lvm_scan, deprecate vgscan (RHBZ#1602353).

Richard W.M. Jones rjones at redhat.com
Wed Jul 25 11:45:37 UTC 2018


The old vgscan API literally ran vgscan.  When we switched to using
lvmetad (in commit dd162d2cd56a2ecf4bcd40a7f463940eaac875b8) this
stopped working because lvmetad now ignores plain *scan commands
without the --cache option.

We documented that vgscan would rescan PVs, VGs and LVs, but without
activating them.

I have introduced a new API (lvm_scan) which scans or rescans PVs, VGs
and LVs.  It has an optional activate parameter allowing activation of
any new LVs that are found.

With lvmetad this nicely maps to the single command:

 pvscan --cache [--activate ay]
---
 common/options/decrypt.c             |  4 +--
 daemon/lvm.c                         | 22 ++++++++++++++--
 format/format.c                      |  2 +-
 generator/actions_core.ml            | 38 ++++++++++++++++++----------
 generator/actions_core_deprecated.ml | 13 ++++++++++
 generator/proc_nr.ml                 |  1 +
 lib/MAX_PROC_NR                      |  2 +-
 7 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/common/options/decrypt.c b/common/options/decrypt.c
index d6e041db6..b9113073c 100644
--- a/common/options/decrypt.c
+++ b/common/options/decrypt.c
@@ -94,9 +94,7 @@ inspect_do_decrypt (guestfs_h *g)
   }
 
   if (need_rescan) {
-    if (guestfs_vgscan (g) == -1)
-      exit (EXIT_FAILURE);
-    if (guestfs_vg_activate_all (g, 1) == -1)
+    if (guestfs_lvm_scan (g, 1) == -1)
       exit (EXIT_FAILURE);
   }
 }
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 709a1e73b..4fe2c24e4 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -32,6 +32,8 @@
 #include "actions.h"
 #include "optgroups.h"
 
+#define MAX_ARGS 64
+
 int
 optgroup_lvm2_available (void)
 {
@@ -637,12 +639,28 @@ do_vglvuuids (const char *vgname)
 
 int
 do_vgscan (void)
+{
+  return do_lvm_scan (0);
+}
+
+int
+do_lvm_scan (int activate)
 {
   CLEANUP_FREE char *err = NULL;
   int r;
+  const char *argv[MAX_ARGS];
+  size_t i = 0;
 
-  r = command (NULL, &err,
-               "lvm", "vgscan", "--cache", NULL);
+  ADD_ARG (argv, i, "lvm");
+  ADD_ARG (argv, i, "pvscan");
+  ADD_ARG (argv, i, "--cache");
+  if (activate) {
+    ADD_ARG (argv, i, "--activate");
+    ADD_ARG (argv, i, "ay");
+  }
+  ADD_ARG (argv, i, NULL);
+
+  r = commandv (NULL, &err, (const char * const *) argv);
   if (r == -1) {
     reply_with_error ("%s", err);
     return -1;
diff --git a/format/format.c b/format/format.c
index 57f74669c..5453fc7e1 100644
--- a/format/format.c
+++ b/format/format.c
@@ -466,7 +466,7 @@ do_rescan (char **devices)
       errors++;
   }
 
-  if (guestfs_vgscan (g) == -1)
+  if (guestfs_lvm_scan (g, 1) == -1)
     errors++;
 
   guestfs_pop_error_handler (g);
diff --git a/generator/actions_core.ml b/generator/actions_core.ml
index 5fb49a14d..f237a3c8b 100644
--- a/generator/actions_core.ml
+++ b/generator/actions_core.ml
@@ -5245,18 +5245,6 @@ If blocks are already zero, then this command avoids writing
 zeroes.  This prevents the underlying device from becoming non-sparse
 or growing unnecessarily." };
 
-  { defaults with
-    name = "vgscan"; added = (1, 3, 2);
-    style = RErr, [], [];
-    tests = [
-      InitEmpty, Always, TestRun (
-        [["vgscan"]]), []
-    ];
-    shortdesc = "rescan for LVM physical volumes, volume groups and logical volumes";
-    longdesc = "\
-This rescans all block devices and rebuilds the list of LVM
-physical volumes, volume groups and logical volumes." };
-
   { defaults with
     name = "part_del"; added = (1, 3, 2);
     style = RErr, [String (Device, "device"); Int "partnum"], [];
@@ -5660,8 +5648,8 @@ Reads and writes to this block device are decrypted from and
 encrypted to the underlying C<device> respectively.
 
 If this block device contains LVM volume groups, then
-calling C<guestfs_vgscan> followed by C<guestfs_vg_activate_all>
-will make them visible.
+calling C<guestfs_lvm_scan> with the C<activate>
+parameter C<true> will make them visible.
 
 Use C<guestfs_list_dm_devices> to list all device mapper
 devices." };
@@ -9718,4 +9706,26 @@ before the partition." };
 This expands a f2fs filesystem to match the size of the underlying
 device." };
 
+  { defaults with
+    name = "lvm_scan"; added = (1, 39, 8);
+    style = RErr, [Bool "activate"], [];
+    tests = [
+      InitEmpty, Always, TestRun (
+        [["lvm_scan"; "true"]]), []
+    ];
+    shortdesc = "scan for LVM physical volumes, volume groups and logical volumes";
+    longdesc = "\
+This scans all block devices and rebuilds the list of LVM
+physical volumes, volume groups and logical volumes.
+
+If the C<activate> parameter is C<true> then newly found
+volume groups and logical volumes are activated, meaning
+the LV F</dev/VG/LV> devices become visible.
+
+When a libguestfs handle is launched it scans for existing
+devices, so you do not normally need to use this API.  However
+it is useful when you have added a new device or deleted an
+existing device (such as when the C<guestfs_luks_open> API
+is used)." };
+
 ]
diff --git a/generator/actions_core_deprecated.ml b/generator/actions_core_deprecated.ml
index 9a58b1df3..fafb9adad 100644
--- a/generator/actions_core_deprecated.ml
+++ b/generator/actions_core_deprecated.ml
@@ -834,4 +834,17 @@ is not large enough." };
 This command is the same as C<guestfs_ntfsresize> except that it
 allows you to specify the new size (in bytes) explicitly." };
 
+  { defaults with
+    name = "vgscan"; added = (1, 3, 2);
+    style = RErr, [], [];
+    deprecated_by = Replaced_by "lvm_scan";
+    tests = [
+      InitEmpty, Always, TestRun (
+        [["vgscan"]]), []
+    ];
+    shortdesc = "rescan for LVM physical volumes, volume groups and logical volumes";
+    longdesc = "\
+This rescans all block devices and rebuilds the list of LVM
+physical volumes, volume groups and logical volumes." };
+
 ]
diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml
index ca73aa361..2adf8a32f 100644
--- a/generator/proc_nr.ml
+++ b/generator/proc_nr.ml
@@ -513,6 +513,7 @@ let proc_nr = [
 503, "part_set_gpt_attributes";
 504, "part_get_gpt_attributes";
 505, "f2fs_expand";
+506, "lvm_scan";
 ]
 
 (* End of list.  If adding a new entry, add it at the end of the list
diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR
index f573e999a..80e3e6eab 100644
--- a/lib/MAX_PROC_NR
+++ b/lib/MAX_PROC_NR
@@ -1 +1 @@
-505
+506
-- 
2.18.0




More information about the Libguestfs mailing list