[Libguestfs] [PATCH 2/5] daemon: lvm-filter: start lvmetad better

Pino Toscano ptoscano at redhat.com
Tue Jul 26 15:41:26 UTC 2016


Currently lvmetad is started in init, and thus using the system
(= appliance) configuration of lvm.  Later on, in the daemon, a local
copy of the lvm configuration is setup, and set it for use using the
LVM_SYSTEM_DIR environment variable: this means only the programmes
executed by the daemon will use the local lvm configuration, and not
lvmetad.

Thus manually start lvmetad from the daemon, right after having setup
the local lvm configuration, and still without failing if it cannot be
executed.

Additionally, since lvmetad now respects the right configuration, make
sure to update its cache when rescanning the VGs by passing --cache to
vgscan.
---
 appliance/init      |  1 -
 daemon/lvm-filter.c | 13 ++++++++++++-
 daemon/lvm.c        |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/appliance/init b/appliance/init
index 3816dfd..d440007 100755
--- a/appliance/init
+++ b/appliance/init
@@ -131,7 +131,6 @@ mdadm -As --auto=yes --run
 
 # Scan for LVM.
 modprobe dm_mod ||:
-lvmetad ||:
 
 lvm vgchange -aay --sysinit
 
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index 8629aab..2add95a 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -39,6 +39,7 @@
 GUESTFSD_EXT_CMD(str_lvm, lvm);
 GUESTFSD_EXT_CMD(str_cp, cp);
 GUESTFSD_EXT_CMD(str_rm, rm);
+GUESTFSD_EXT_CMD(str_lvmetad, lvmetad);
 
 /* This runs during daemon start up and creates a complete copy of
  * /etc/lvm so that we can modify it as we desire.  We set
@@ -97,6 +98,16 @@ copy_lvm (void)
   snprintf (env, sizeof env, "%s/lvm", lvm_system_dir);
   setenv ("LVM_SYSTEM_DIR", env, 1);
 
+  /* Try to run lvmetad, without failing if it couldn't. */
+  snprintf (cmd, sizeof cmd, "%s", str_lvmetad);
+  if (verbose)
+    printf ("%s\n", cmd);
+  r = system (cmd);
+  if (r == -1)
+    perror ("system/lvmetad");
+  else if (!WIFEXITED (r) || WEXITSTATUS (r) != 0)
+    fprintf (stderr, "warning: lvmetad command failed\n");
+
   /* Set a handler to remove the temporary directory at exit. */
   atexit (rm_lvm_system_dir);
 }
@@ -247,7 +258,7 @@ rescan (void)
   unlink (lvm_cache);
 
   CLEANUP_FREE char *err = NULL;
-  int r = command (NULL, &err, str_lvm, "vgscan", NULL);
+  int r = command (NULL, &err, str_lvm, "vgscan", "--cache", NULL);
   if (r == -1) {
     reply_with_error ("vgscan: %s", err);
     return -1;
diff --git a/daemon/lvm.c b/daemon/lvm.c
index d4909ad..e21f7c1 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -794,7 +794,7 @@ do_vgscan (void)
   int r;
 
   r = command (NULL, &err,
-               str_lvm, "vgscan", NULL);
+               str_lvm, "vgscan", "--cache", NULL);
   if (r == -1) {
     reply_with_error ("%s", err);
     return -1;
-- 
2.7.4




More information about the Libguestfs mailing list