[sandbox][PATCH] Add module directory prefix selection feature

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

 



Add module directory prefix selection feature

This is useful when running as a non-privileged user if we want to
boot a custom compiled kernel: we might not have rights to install in
/lib/modules/<kernel release> so when compiling the kernel we can use
"make modules_install INSTALL_MOD_PATH=/path" which installs in
/path/lib/modules/<kernel release>. By setting with
gvir_sandbox_config_set_moddirprefix(cfg, "/path") we can now achieve
just that.
 libvirt-sandbox/libvirt-sandbox-builder-initrd.c  |    3 +-
 libvirt-sandbox/libvirt-sandbox-builder-machine.c |    1 +
 libvirt-sandbox/libvirt-sandbox-config-initrd.c   |   50 ++++++++++++++++
 libvirt-sandbox/libvirt-sandbox-config-initrd.h   |    3 +
 libvirt-sandbox/libvirt-sandbox-config.c          |   63 +++++++++++++++++++++
 libvirt-sandbox/libvirt-sandbox-config.h          |    3 +
 libvirt-sandbox/libvirt-sandbox.sym               |    3 +
 7 files changed, 125 insertions(+), 1 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-initrd.c b/libvirt-sandbox/libvirt-sandbox-builder-initrd.c
index dd01c7a..0b13589 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-initrd.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-initrd.c
@@ -331,7 +331,8 @@ static GList *gvir_sandbox_builder_initrd_find_modules(GList *modnames,
                                                        GVirSandboxConfigInitrd *config,
                                                        GError **error)
 {
-    gchar *moddirpath = g_strdup_printf("/lib/modules/%s/kernel",
+    gchar *moddirpath = g_strdup_printf("%s/lib/modules/%s/kernel",
+                                        gvir_sandbox_config_initrd_get_moddirprefix(config),
                                         gvir_sandbox_config_initrd_get_kver(config));
     GFile *moddir = g_file_new_for_path(moddirpath);
 
diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 0e6514e..7fb6997 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -123,6 +123,7 @@ static gchar *gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig *config,
     int fd = -1;
 
     gvir_sandbox_config_initrd_set_kver(initrd, gvir_sandbox_config_get_kernrelease(config));
+    gvir_sandbox_config_initrd_set_moddirprefix(initrd, gvir_sandbox_config_get_moddirprefix(config));
     gvir_sandbox_config_initrd_set_init(initrd, LIBEXECDIR "/libvirt-sandbox-init-qemu");
 
     gvir_sandbox_config_initrd_add_module(initrd, "fscache.ko");
diff --git a/libvirt-sandbox/libvirt-sandbox-config-initrd.c b/libvirt-sandbox/libvirt-sandbox-config-initrd.c
index 5c75fce..77cc1f0 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-initrd.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-initrd.c
@@ -44,6 +44,7 @@ struct _GVirSandboxConfigInitrdPrivate
 {
     gchar *kver;
     gchar *init;
+    gchar *moddirprefix;
     GList *modules;
 };
 
@@ -53,6 +54,7 @@ G_DEFINE_TYPE(GVirSandboxConfigInitrd, gvir_sandbox_config_initrd, G_TYPE_OBJECT
 enum {
     PROP_0,
     PROP_KVER,
+    PROP_MODDIRPREFIX,
     PROP_INIT,
 };
 
@@ -76,6 +78,10 @@ static void gvir_sandbox_config_initrd_get_property(GObject *object,
         g_value_set_string(value, priv->kver);
         break;
 
+    case PROP_MODDIRPREFIX:
+        g_value_set_string(value, priv->moddirprefix);
+        break;
+
     case PROP_INIT:
         g_value_set_string(value, priv->init);
         break;
@@ -100,6 +106,11 @@ static void gvir_sandbox_config_initrd_set_property(GObject *object,
         priv->kver = g_value_dup_string(value);
         break;
 
+    case PROP_MODDIRPREFIX:
+        g_free(priv->moddirprefix);
+        priv->moddirprefix = g_value_dup_string(value);
+        break;
+
     case PROP_INIT:
         g_free(priv->init);
         priv->init = g_value_dup_string(value);
@@ -142,6 +153,17 @@ static void gvir_sandbox_config_initrd_class_init(GVirSandboxConfigInitrdClass *
                                                         G_PARAM_STATIC_NICK |
                                                         G_PARAM_STATIC_BLURB));
     g_object_class_install_property(object_class,
+                                    PROP_MODDIRPREFIX,
+                                    g_param_spec_string("moddirprefix",
+                                                        "Moddirprefix",
+                                                        "Module directory prefix",
+                                                        NULL,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE |
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB));
+    g_object_class_install_property(object_class,
                                     PROP_INIT,
                                     g_param_spec_string("init",
                                                         "Init",
@@ -209,6 +231,34 @@ const gchar *gvir_sandbox_config_initrd_get_kver(GVirSandboxConfigInitrd *config
     return priv->kver;
 }
 
+/**
+ * gvir_sandbox_config_initrd_set_moddirprefix:
+ * @config: (transfer none): the sandbox initrd config
+ * @moddirprefix: (transfer none): the prefix for kernel module directory
+ *
+ * Sets what prefix to use for looking up kernel modules to add to the initrd
+ */
+void gvir_sandbox_config_initrd_set_moddirprefix(GVirSandboxConfigInitrd *config, const gchar *moddirprefix)
+{
+    GVirSandboxConfigInitrdPrivate *priv = config->priv;
+    g_free(priv->moddirprefix);
+    priv->moddirprefix = g_strdup(moddirprefix);
+}
+
+/**
+ * gvir_sandbox_config_initrd_get_moddirprefix:
+ * @config: (transfer none): the sandbox module directory prefix
+ *
+ * Retrieves the current module directory prefix
+ *
+ * Returns: (transfer none): kernel module dir prefix
+ */
+const gchar *gvir_sandbox_config_initrd_get_moddirprefix(GVirSandboxConfigInitrd *config)
+{
+    GVirSandboxConfigInitrdPrivate *priv = config->priv;
+    return priv->moddirprefix;
+}
+
 
 /**
  * gvir_sandbox_config_initrd_set_init:
diff --git a/libvirt-sandbox/libvirt-sandbox-config-initrd.h b/libvirt-sandbox/libvirt-sandbox-config-initrd.h
index 6e09e62..131d98d 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-initrd.h
+++ b/libvirt-sandbox/libvirt-sandbox-config-initrd.h
@@ -64,6 +64,9 @@ GVirSandboxConfigInitrd *gvir_sandbox_config_initrd_new(void);
 void gvir_sandbox_config_initrd_set_kver(GVirSandboxConfigInitrd *config, const gchar *version);
 const gchar *gvir_sandbox_config_initrd_get_kver(GVirSandboxConfigInitrd *config);
 
+void gvir_sandbox_config_initrd_set_moddirprefix(GVirSandboxConfigInitrd *config, const gchar *moddirprefix);
+const gchar *gvir_sandbox_config_initrd_get_moddirprefix(GVirSandboxConfigInitrd *config);
+
 void gvir_sandbox_config_initrd_set_init(GVirSandboxConfigInitrd *config, const gchar *hostpath);
 const gchar *gvir_sandbox_config_initrd_get_init(GVirSandboxConfigInitrd *config);
 
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/libvirt-sandbox-config.c
index 7f6efea..597017c 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -48,6 +48,7 @@ struct _GVirSandboxConfigPrivate
     gchar *arch;
     gchar *kernrelease;
     gchar *kernpath;
+    gchar *moddirprefix;
     gboolean shell;
 
     guint uid;
@@ -76,6 +77,7 @@ enum {
     PROP_SHELL,
     PROP_KERNRELEASE,
     PROP_KERNPATH,
+    PROP_MODDIRPREFIX,
 
     PROP_UID,
     PROP_GID,
@@ -135,6 +137,10 @@ static void gvir_sandbox_config_get_property(GObject *object,
         g_value_set_string(value, priv->kernpath);
         break;
 
+    case PROP_MODDIRPREFIX:
+        g_value_set_string(value, priv->moddirprefix);
+        break;
+
     case PROP_SHELL:
         g_value_set_boolean(value, priv->shell);
         break;
@@ -203,6 +209,11 @@ static void gvir_sandbox_config_set_property(GObject *object,
         priv->kernpath = g_value_dup_string(value);
         break;
 
+    case PROP_MODDIRPREFIX:
+        g_free(priv->moddirprefix);
+        priv->moddirprefix = g_value_dup_string(value);
+        break;
+
     case PROP_SHELL:
         priv->shell = g_value_get_boolean(value);
         break;
@@ -263,6 +274,7 @@ static void gvir_sandbox_config_finalize(GObject *object)
     g_free(priv->arch);
     g_free(priv->kernrelease);
     g_free(priv->kernpath);
+    g_free(priv->moddirprefix);
     g_free(priv->secLabel);
 
     G_OBJECT_CLASS(gvir_sandbox_config_parent_class)->finalize(object);
@@ -337,6 +349,17 @@ static void gvir_sandbox_config_class_init(GVirSandboxConfigClass *klass)
                                                         G_PARAM_STATIC_NICK |
                                                         G_PARAM_STATIC_BLURB));
     g_object_class_install_property(object_class,
+                                    PROP_MODDIRPREFIX,
+                                    g_param_spec_string("moddirprefix",
+                                                        "Moddirprefix",
+                                                        "Module dir prefix",
+                                                        NULL,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE |
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB));
+    g_object_class_install_property(object_class,
                                     PROP_SHELL,
                                     g_param_spec_string("shell",
                                                         "SHELL",
@@ -436,6 +459,7 @@ static void gvir_sandbox_config_init(GVirSandboxConfig *config)
     priv->arch = g_strdup(uts.machine);
     priv->kernrelease = g_strdup(uts.release);
     priv->kernpath = g_strdup_printf("/boot/vmlinuz-%s", priv->kernrelease);
+    priv->moddirprefix = g_strdup_printf("/");
     priv->secLabel = g_strdup("system_u:system_r:svirt_t:s0:c0.c1023");
 
     priv->uid = geteuid();
@@ -553,6 +577,7 @@ const gchar *gvir_sandbox_config_get_kernrelease(GVirSandboxConfig *config)
     GVirSandboxConfigPrivate *priv = config->priv;
     return priv->kernrelease;
 }
+
 /**
  * gvir_sandbox_config_set_kernpath:
  * @config: (transfer none): the sandbox config
@@ -584,6 +609,39 @@ const gchar *gvir_sandbox_config_get_kernpath(GVirSandboxConfig *config)
     return priv->kernpath;
 }
 
+/**
+ * gvir_sandbox_config_set_moddirprefix:
+ * @config: (transfer none): the sandbox config
+ * @moddirprefix: (transfer none): the module prefix directory
+ *
+ * Set the kernel modules directory prefix. If none is provided,
+ * it will default to "/" such that modules will be looked up in
+ * /lib/modules/<kernel release>. If "/path" is given as argument
+ * modules will be searched in /path/lib/modules/<kernel release>
+ */
+
+void gvir_sandbox_config_set_moddirprefix(GVirSandboxConfig *config, const gchar *moddirprefix)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    g_free(priv->moddirprefix);
+    priv->moddirprefix = g_strdup(moddirprefix);
+}
+
+
+/**
+ * gvir_sandbox_config_get_moddirprefix:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox module prefix directory
+ *
+ * Returns: (transfer none): the current module prefix dir
+ */
+const gchar *gvir_sandbox_config_get_moddirprefix(GVirSandboxConfig *config)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    return priv->moddirprefix;
+}
+
 
 /**
  * gvir_sandbox_config_set_shell:
@@ -1651,6 +1709,10 @@ static gboolean gvir_sandbox_config_load_config(GVirSandboxConfig *config,
         g_free(priv->kernpath);
         priv->kernpath = str;
     }
+    if ((str = g_key_file_get_string(file, "core", "moddirprefix", NULL)) != NULL) {
+        g_free(priv->moddirprefix);
+        priv->moddirprefix = str;
+    }
     b = g_key_file_get_boolean(file, "core", "shell", &e);
     if (e) {
         g_error_free(e);
@@ -1870,6 +1932,7 @@ static void gvir_sandbox_config_save_config(GVirSandboxConfig *config,
     g_key_file_set_string(file, "core", "arch", priv->arch);
     g_key_file_set_string(file, "core", "kernrelease", priv->kernrelease);
     g_key_file_set_string(file, "core", "kernpath", priv->kernpath);
+    g_key_file_set_string(file, "core", "moddirprefix", priv->moddirprefix);
     g_key_file_set_boolean(file, "core", "shell", priv->shell);
 
     g_key_file_set_uint64(file, "identity", "uid", priv->uid);
diff --git a/libvirt-sandbox/libvirt-sandbox-config.h b/libvirt-sandbox/libvirt-sandbox-config.h
index a6c8ae8..0196d16 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -82,6 +82,9 @@ const gchar *gvir_sandbox_config_get_kernrelease(GVirSandboxConfig *config);
 void gvir_sandbox_config_set_kernpath(GVirSandboxConfig *config, const gchar *kernpath);
 const gchar *gvir_sandbox_config_get_kernpath(GVirSandboxConfig *config);
 
+void gvir_sandbox_config_set_moddirprefix(GVirSandboxConfig *config, const gchar *moddirprefix);
+const gchar *gvir_sandbox_config_get_moddirprefix(GVirSandboxConfig *config);
+
 void gvir_sandbox_config_set_shell(GVirSandboxConfig *config, gboolean shell);
 gboolean gvir_sandbox_config_get_shell(GVirSandboxConfig *config);
 
diff --git a/libvirt-sandbox/libvirt-sandbox.sym b/libvirt-sandbox/libvirt-sandbox.sym
index 424fd98..c048768 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -96,6 +96,7 @@ LIBVIRT_SANDBOX_0.0.1 {
 	gvir_sandbox_config_set_arch;
 	gvir_sandbox_config_set_kernrelease;
 	gvir_sandbox_config_set_kernpath;
+	gvir_sandbox_config_set_moddirprefix;
 	gvir_sandbox_config_set_userid;
 	gvir_sandbox_config_set_groupid;
 	gvir_sandbox_config_set_username;
@@ -107,11 +108,13 @@ LIBVIRT_SANDBOX_0.0.1 {
 	gvir_sandbox_config_initrd_add_module;
 	gvir_sandbox_config_initrd_get_init;
 	gvir_sandbox_config_initrd_get_kver;
+	gvir_sandbox_config_initrd_get_moddirprefix;
 	gvir_sandbox_config_initrd_get_modules;
 	gvir_sandbox_config_initrd_get_type;
 	gvir_sandbox_config_initrd_new;
 	gvir_sandbox_config_initrd_set_init;
 	gvir_sandbox_config_initrd_set_kver;
+	gvir_sandbox_config_initrd_set_moddirprefix;
 
 	gvir_sandbox_console_get_type;
 	gvir_sandbox_console_attach;
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]