daemon: lvm-filter: start lvmetad better

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.
This commit is contained in:
Pino Toscano
2016-07-26 17:12:38 +02:00
parent 5ce19cec4c
commit 2c4f154b91
5 changed files with 24 additions and 4 deletions

View File

@@ -131,7 +131,6 @@ mdadm -As --auto=yes --run
# Scan for LVM.
modprobe dm_mod ||:
lvmetad ||:
lvm vgchange -aay --sysinit

View File

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

View File

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

View File

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

View File

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