[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



On Tue, Jul 26, 2016 at 05:41:26PM +0200, Pino Toscano wrote:
> 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.

Can we move the lvmetad start up to another function?  Either that or
change the name of the copy_lvm function to more accurately reflect
what it does now.

Rich.

>  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
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs redhat com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]