daemon: Make vg_scan and lvm_scan no-ops if no LVM feature

If the LVM ("lvm2") feature is not available, these calls would fail.
Really they ought to be part of the "lvm2" optgroup which would cause
the generator to call reply_with_unavailable_feature and generate the
correct ENOTSUP error.  When vgscan was originally added in 2010 it
was not added to the optgroup, and when lvm_scan was later added in
2018 and deprecating vgscan, the same mistake was copied.

Before this commit they will try to run the lvm pvscan command which
will fail returning some other error (instead of ENOTSUP).

Fix this by turning the calls into no-ops if the LVM feature is not
available, since scanning for LVM objects when there is no LVM can be
safely turned into a no-op.

See also
https://listman.redhat.com/archives/libguestfs/2022-September/thread.html#29908

Also this updates the common module to pick up a related fix:

  commit 4b4a5b84647b1496d034bcdff910930ca5f5c486
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Fri Sep 23 15:18:43 2022 +0100

    options: Don't attempt to scan LVs if "lvm2" feature is not available

Reported-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Fixes: 55dfcb2211 ("New API: lvm_scan, deprecate vgscan")
Fixes: 9752039e52 ("New API: vgscan")
This commit is contained in:
Richard W.M. Jones
2022-09-26 08:50:47 +01:00
parent 57d1812091
commit c2dd84b263
2 changed files with 8 additions and 1 deletions

2
common

Submodule common updated: 9d40590852...4b4a5b8464

View File

@@ -651,6 +651,13 @@ do_lvm_scan (int activate)
const char *argv[MAX_ARGS];
size_t i = 0;
/* Historically this call was never added to the "lvm2" optgroup.
* Rather than changing that and have the small risk of breaking
* callers, just make it into a no-op if LVM is not available.
*/
if (optgroup_lvm2_available () == 0)
return 0;
ADD_ARG (argv, i, "lvm");
ADD_ARG (argv, i, "pvscan");
ADD_ARG (argv, i, "--cache");