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

Pino Toscano ptoscano at redhat.com
Tue Jul 26 16:42:59 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/daemon.h     |  1 +
 daemon/guestfsd.c   |  4 +++-
 daemon/lvm-filter.c | 20 +++++++++++++++++++-
 daemon/lvm.c        |  2 +-
 5 files changed, 24 insertions(+), 4 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/daemon.h b/daemon/daemon.h
index 7716981..9fb0472 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -189,6 +189,7 @@ extern int lv_canonical (const char *device, char **ret);
 
 /*-- in lvm-filter.c --*/
 extern void copy_lvm (void);
+extern void start_lvmetad (void);
 
 /*-- in zero.c --*/
 extern void wipe_device_before_mkfs (const char *device);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index bd3f7de..b343d7e 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -274,8 +274,10 @@ main (int argc, char *argv[])
   /* Make a private copy of /etc/lvm so we can change the config (see
    * daemon/lvm-filter.c).
    */
-  if (!test_mode)
+  if (!test_mode) {
     copy_lvm ();
+    start_lvmetad ();
+  }
 
   /* Connect to virtio-serial channel. */
   if (!channel)
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index 8629aab..d53d64b 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
@@ -101,6 +102,23 @@ copy_lvm (void)
   atexit (rm_lvm_system_dir);
 }
 
+/* Try to run lvmetad, without failing if it couldn't. */
+void
+start_lvmetad (void)
+{
+  char cmd[64];
+  int r;
+
+  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");
+}
+
 static void
 rm_lvm_system_dir (void)
 {
@@ -247,7 +265,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