[libvirt] [sandbox 1/6] Pass debug and verbose values to init

Cédric Bosdonnat posted 6 patches 7 years, 5 months ago
There is a newer version of this series
[libvirt] [sandbox 1/6] Pass debug and verbose values to init
Posted by Cédric Bosdonnat 7 years, 5 months ago
libvirt-sandbox-init-common is expecting -d and -v parameters to
set it in debug or verbose mode... but those will never be passed
by the launcher program.

Writing the core.debug and core.verbose parameters in the sandbox
configuration makes those values actually usable from the init.
---
 bin/virt-sandbox.c                            |  3 ++
 libvirt-sandbox/libvirt-sandbox-config.c      | 75 +++++++++++++++++++++++++++
 libvirt-sandbox/libvirt-sandbox-config.h      |  6 +++
 libvirt-sandbox/libvirt-sandbox-init-common.c |  3 ++
 libvirt-sandbox/libvirt-sandbox.sym           |  4 ++
 5 files changed, 91 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 3058013..6032562 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -273,6 +273,9 @@ int main(int argc, char **argv) {
     if (shell)
         gvir_sandbox_config_set_shell(cfg, TRUE);
 
+    gvir_sandbox_config_set_debug(cfg, debug);
+    gvir_sandbox_config_set_verbose(cfg, verbose);
+
     if (isatty(STDIN_FILENO))
         gvir_sandbox_config_interactive_set_tty(icfg, TRUE);
 
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/libvirt-sandbox-config.c
index 8709736..73a0fa4 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -68,6 +68,9 @@ struct _GVirSandboxConfigPrivate
 
     gchar *secLabel;
     gboolean secDynamic;
+
+    gboolean debug;
+    gboolean verbose;
 };
 
 G_DEFINE_ABSTRACT_TYPE(GVirSandboxConfig, gvir_sandbox_config, G_TYPE_OBJECT);
@@ -1926,6 +1929,59 @@ gboolean gvir_sandbox_config_set_security_opts(GVirSandboxConfig *config,
     return ret;
 }
 
+/**
+ * gvir_sandbox_config_set_debug:
+ * @config: (transfer none): the sandbox config
+ * @debug: true if the container init should print debugging messages
+ *
+ * Set whether the container init should print debugging messages.
+ */
+void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean debug)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    priv->debug = debug;
+}
+
+/**
+ * gvir_sandbox_config_get_debug:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox debug flag
+ *
+ * Returns: the debug flag
+ */
+gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    return priv->debug;
+}
+
+/**
+ * gvir_sandbox_config_set_verbose:
+ * @config: (transfer none): the sandbox config
+ * @verbose: true if the container init should be verbose
+ *
+ * Set whether the container init should be verbose.
+ */
+void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean verbose)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    priv->verbose = verbose;
+}
+
+/**
+ * gvir_sandbox_config_get_verbose:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox verbose flag
+ *
+ * Returns: the verbose flag
+ */
+gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    return priv->verbose;
+}
 
 static GVirSandboxConfigMount *gvir_sandbox_config_load_config_mount(GKeyFile *file,
                                                                      guint i,
@@ -2415,6 +2471,22 @@ static gboolean gvir_sandbox_config_load_config(GVirSandboxConfig *config,
         priv->secDynamic = b;
     }
 
+    b = g_key_file_get_boolean(file, "core", "debug", &e);
+    if (e) {
+        g_error_free(e);
+        e = NULL;
+    } else {
+        priv->debug = b;
+    }
+
+    b = g_key_file_get_boolean(file, "core", "verbose", &e);
+    if (e) {
+        g_error_free(e);
+        e = NULL;
+    } else {
+        priv->verbose = b;
+    }
+
     ret = TRUE;
  cleanup:
     return ret;
@@ -2677,6 +2749,9 @@ static void gvir_sandbox_config_save_config(GVirSandboxConfig *config,
     if (priv->secLabel)
         g_key_file_set_string(file, "security", "label", priv->secLabel);
     g_key_file_set_boolean(file, "security", "dynamic", priv->secDynamic);
+
+    g_key_file_set_boolean(file, "core", "debug", priv->debug);
+    g_key_file_set_boolean(file, "core", "verbose", priv->verbose);
 }
 
 
diff --git a/libvirt-sandbox/libvirt-sandbox-config.h b/libvirt-sandbox/libvirt-sandbox-config.h
index e5e53f7..8950e25 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -180,6 +180,12 @@ gboolean gvir_sandbox_config_set_security_opts(GVirSandboxConfig *config,
                                                const gchar *optstr,
                                                GError**error);
 
+void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean debug);
+gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config);
+
+void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean verbose);
+gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config);
+
 gchar **gvir_sandbox_config_get_command(GVirSandboxConfig *config);
 
 G_END_DECLS
diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 7ea63cf..240ca83 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -1442,6 +1442,9 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
+    debug = gvir_sandbox_config_get_debug(config);
+    verbose = gvir_sandbox_config_get_verbose(config);
+
     setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin/:/usr/sbin", 1);
     unsetenv("LD_LIBRARY_PATH");
 
diff --git a/libvirt-sandbox/libvirt-sandbox.sym b/libvirt-sandbox/libvirt-sandbox.sym
index b7c5921..1bead3e 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -120,6 +120,8 @@ LIBVIRT_SANDBOX_0.6.0 {
 	gvir_sandbox_config_get_userid;
 	gvir_sandbox_config_get_username;
 	gvir_sandbox_config_get_uuid;
+	gvir_sandbox_config_get_debug;
+	gvir_sandbox_config_get_verbose;
 	gvir_sandbox_config_find_mount;
 	gvir_sandbox_config_has_networks;
 	gvir_sandbox_config_has_mounts;
@@ -143,6 +145,8 @@ LIBVIRT_SANDBOX_0.6.0 {
 	gvir_sandbox_config_set_security_label;
 	gvir_sandbox_config_set_security_opts;
 	gvir_sandbox_config_set_uuid;
+	gvir_sandbox_config_set_debug;
+	gvir_sandbox_config_set_verbose;
 
 	gvir_sandbox_config_initrd_add_module;
 	gvir_sandbox_config_initrd_get_init;
-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [sandbox 1/6] Pass debug and verbose values to init
Posted by Daniel P. Berrange 7 years, 5 months ago
On Tue, Dec 05, 2017 at 10:53:17AM +0100, Cédric Bosdonnat wrote:
> libvirt-sandbox-init-common is expecting -d and -v parameters to
> set it in debug or verbose mode... but those will never be passed
> by the launcher program.

Hmm, libvirt-sandbox-init-{qemu,lxc} both know how to pass -d
to init-common.  If either of the virt specific init programs
are in debug mode (as indicated by the word "debug" in kernel
command line or equiv), then they pass -d to init-common.

You're right that there's no way to pass -v though.

Also, it might be useful to run init-common in debug mode
without the virt specific init being in debug mode, to avoid
drowning in debug.

> 
> Writing the core.debug and core.verbose parameters in the sandbox
> configuration makes those values actually usable from the init.
> ---
>  bin/virt-sandbox.c                            |  3 ++
>  libvirt-sandbox/libvirt-sandbox-config.c      | 75 +++++++++++++++++++++++++++
>  libvirt-sandbox/libvirt-sandbox-config.h      |  6 +++
>  libvirt-sandbox/libvirt-sandbox-init-common.c |  3 ++
>  libvirt-sandbox/libvirt-sandbox.sym           |  4 ++
>  5 files changed, 91 insertions(+)

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>

if the commit message is fixed


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [sandbox 1/6] Pass debug and verbose values to init
Posted by Cedric Bosdonnat 7 years, 5 months ago
On Tue, 2017-12-05 at 16:52 +0000, Daniel P. Berrange wrote:
> On Tue, Dec 05, 2017 at 10:53:17AM +0100, Cédric Bosdonnat wrote:
> > libvirt-sandbox-init-common is expecting -d and -v parameters to
> > set it in debug or verbose mode... but those will never be passed
> > by the launcher program.
> 
> Hmm, libvirt-sandbox-init-{qemu,lxc} both know how to pass -d
> to init-common.  If either of the virt specific init programs
> are in debug mode (as indicated by the word "debug" in kernel
> command line or equiv), then they pass -d to init-common.

Hum, then I should surely revise that commit to remove the debug-related
code. Instead I should change the init-{lxc,qemu} to actually pass
the debug flag to init-common.

> You're right that there's no way to pass -v though.
> 
> Also, it might be useful to run init-common in debug mode
> without the virt specific init being in debug mode, to avoid
> drowning in debug.

Hum, then keeping the debug-related flag I introduced could help,
but then I'll need to rename it to make it more explicit. Or maybe
I should change the debug parameter to take a level value:
 0: all (default)
 1: only the init-common

In which case the user-exposed options should be expanded to use these.

I'll push the other commits, but not this one.

--
Cedric

> > 
> > Writing the core.debug and core.verbose parameters in the sandbox
> > configuration makes those values actually usable from the init.
> > ---
> >  bin/virt-sandbox.c                            |  3 ++
> >  libvirt-sandbox/libvirt-sandbox-config.c      | 75 +++++++++++++++++++++++++++
> >  libvirt-sandbox/libvirt-sandbox-config.h      |  6 +++
> >  libvirt-sandbox/libvirt-sandbox-init-common.c |  3 ++
> >  libvirt-sandbox/libvirt-sandbox.sym           |  4 ++
> >  5 files changed, 91 insertions(+)
> 
> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> 
> if the commit message is fixed
> 
> 
> Regards,
> Daniel

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [sandbox 1/6] Pass debug and verbose values to init
Posted by Daniel P. Berrange 7 years, 5 months ago
On Wed, Dec 06, 2017 at 01:56:23PM +0100, Cedric Bosdonnat wrote:
> On Tue, 2017-12-05 at 16:52 +0000, Daniel P. Berrange wrote:
> > On Tue, Dec 05, 2017 at 10:53:17AM +0100, Cédric Bosdonnat wrote:
> > > libvirt-sandbox-init-common is expecting -d and -v parameters to
> > > set it in debug or verbose mode... but those will never be passed
> > > by the launcher program.
> > 
> > Hmm, libvirt-sandbox-init-{qemu,lxc} both know how to pass -d
> > to init-common.  If either of the virt specific init programs
> > are in debug mode (as indicated by the word "debug" in kernel
> > command line or equiv), then they pass -d to init-common.
> 
> Hum, then I should surely revise that commit to remove the debug-related
> code. Instead I should change the init-{lxc,qemu} to actually pass
> the debug flag to init-common.
> 
> > You're right that there's no way to pass -v though.
> > 
> > Also, it might be useful to run init-common in debug mode
> > without the virt specific init being in debug mode, to avoid
> > drowning in debug.
> 
> Hum, then keeping the debug-related flag I introduced could help,
> but then I'll need to rename it to make it more explicit. Or maybe
> I should change the debug parameter to take a level value:
>  0: all (default)
>  1: only the init-common

I'm not a fan of adding  args to --debug flags. I think what you
have here already is good enough, just with commit message changed
to be more accurate

> 
> In which case the user-exposed options should be expanded to use these.
> 
> I'll push the other commits, but not this one.
> 
> --
> Cedric
> 
> > > 
> > > Writing the core.debug and core.verbose parameters in the sandbox
> > > configuration makes those values actually usable from the init.
> > > ---
> > >  bin/virt-sandbox.c                            |  3 ++
> > >  libvirt-sandbox/libvirt-sandbox-config.c      | 75 +++++++++++++++++++++++++++
> > >  libvirt-sandbox/libvirt-sandbox-config.h      |  6 +++
> > >  libvirt-sandbox/libvirt-sandbox-init-common.c |  3 ++
> > >  libvirt-sandbox/libvirt-sandbox.sym           |  4 ++
> > >  5 files changed, 91 insertions(+)
> > 
> > Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> > 
> > if the commit message is fixed

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list