New API: lvm_scan, deprecate vgscan (RHBZ#1602353).

The old vgscan API literally ran vgscan.  When we switched to using
lvmetad (in commit dd162d2cd5) 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]
This commit is contained in:
Richard W.M. Jones
2018-07-18 14:27:20 +01:00
parent 16e64b8988
commit 55dfcb2211
7 changed files with 61 additions and 21 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)." };
]

View File

@@ -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." };
]

View File

@@ -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

View File

@@ -1 +1 @@
505
506