Added parameters to select a kernel through the release version and path to binary.
When setting kernel release version, the module search will be done in
/lib/modules/<release>/kernel . Also, by default, after setting the kernel release
version the default kernel image path will be /boot/vmlinuz-<release>
The two default to the running configuration: /lib/modules/`uname -r`/kernel
and /boot/vmlinuz-`uname -r`
kver didn't seem suggestive enough; I used kernrelease and kernpath. To be changed if
necessary.
Also removed utsname inclusion wherever it wasn't used at all anymore
diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 7087459..3f7c5d7 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
-#include <sys/utsname.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
@@ -116,7 +115,6 @@ static void gvir_sandbox_builder_machine_finalize(GObject *object)
static gchar *gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig *config,
- const gchar *kver,
GError **error)
{
GVirSandboxConfigInitrd *initrd = gvir_sandbox_config_initrd_new();
@@ -124,7 +122,7 @@ static gchar *gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig
*config,
gchar *targetfile = g_strdup_printf("/tmp/libvirt-sandbox-initrd-XXXXXX");
int fd = -1;
- gvir_sandbox_config_initrd_set_kver(initrd, kver);
+ gvir_sandbox_config_initrd_set_kver(initrd,
gvir_sandbox_config_get_kernrelease(config));
gvir_sandbox_config_initrd_set_init(initrd, LIBEXECDIR
"/libvirt-sandbox-init-qemu");
gvir_sandbox_config_initrd_add_module(initrd, "fscache.ko");
@@ -341,19 +340,16 @@ static gboolean
gvir_sandbox_builder_machine_construct_os(GVirSandboxBuilder *bu
gchar *kernel = NULL;
gchar *initrd = NULL;
gchar *cmdline = NULL;
- struct utsname uts;
GVirConfigDomainOs *os;
if (!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_machine_parent_class)->
construct_os(builder, config, configdir, cleaner, domain, error))
return FALSE;
- uname(&uts);
-
- if (!(initrd = gvir_sandbox_builder_machine_mkinitrd(config, uts.release, error)))
+ if (!(initrd = gvir_sandbox_builder_machine_mkinitrd(config, error)))
return FALSE;
- kernel = g_strdup_printf("/boot/vmlinuz-%s", uts.release);
+ kernel = g_strdup(gvir_sandbox_config_get_kernpath(config));
cmdline = gvir_sandbox_builder_machine_cmdline(config);
gvir_sandbox_cleaner_add_rmfile_post_start(cleaner,
diff --git a/libvirt-sandbox/libvirt-sandbox-config-initrd.c
b/libvirt-sandbox/libvirt-sandbox-config-initrd.c
index 327e0bf..5c75fce 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-initrd.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-initrd.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
-#include <sys/utsname.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
@@ -161,12 +160,8 @@ static void
gvir_sandbox_config_initrd_class_init(GVirSandboxConfigInitrdClass *
static void gvir_sandbox_config_initrd_init(GVirSandboxConfigInitrd *config)
{
GVirSandboxConfigInitrdPrivate *priv = config->priv;
- struct utsname uts;
priv = config->priv = GVIR_SANDBOX_CONFIG_INITRD_GET_PRIVATE(config);
-
priv->init = g_strdup(LIBEXECDIR "/libvirt-sandbox-init-qemu");
- uname(&uts);
- priv->kver = g_strdup(uts.release);
}
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-address.c
b/libvirt-sandbox/libvirt-sandbox-config-network-address.c
index ad91f77..959bf94 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-network-address.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-address.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
-#include <sys/utsname.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-route.c
b/libvirt-sandbox/libvirt-sandbox-config-network-route.c
index 7962352..6c473d0 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-network-route.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-route.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
-#include <sys/utsname.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network.c
b/libvirt-sandbox/libvirt-sandbox-config-network.c
index 5668274..6440642 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-network.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-network.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
-#include <sys/utsname.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c
b/libvirt-sandbox/libvirt-sandbox-config.c
index 2b0a9be..b9cda3d 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -46,6 +46,8 @@ struct _GVirSandboxConfigPrivate
gchar *name;
gchar *root;
gchar *arch;
+ gchar *kernrelease;
+ gchar *kernpath;
gboolean shell;
guint uid;
@@ -72,6 +74,8 @@ enum {
PROP_ROOT,
PROP_ARCH,
PROP_SHELL,
+ PROP_KERNRELEASE,
+ PROP_KERNPATH,
PROP_UID,
PROP_GID,
@@ -123,6 +127,14 @@ static void gvir_sandbox_config_get_property(GObject *object,
g_value_set_string(value, priv->arch);
break;
+ case PROP_KERNRELEASE:
+ g_value_set_string(value, priv->kernrelease);
+ break;
+
+ case PROP_KERNPATH:
+ g_value_set_string(value, priv->kernpath);
+ break;
+
case PROP_SHELL:
g_value_set_boolean(value, priv->shell);
break;
@@ -181,6 +193,16 @@ static void gvir_sandbox_config_set_property(GObject *object,
priv->arch = g_value_dup_string(value);
break;
+ case PROP_KERNRELEASE:
+ g_free(priv->kernrelease);
+ priv->kernrelease = g_value_dup_string(value);
+ break;
+
+ case PROP_KERNPATH:
+ g_free(priv->kernpath);
+ priv->kernpath = g_value_dup_string(value);
+ break;
+
case PROP_SHELL:
priv->shell = g_value_get_boolean(value);
break;
@@ -239,6 +261,8 @@ static void gvir_sandbox_config_finalize(GObject *object)
g_free(priv->name);
g_free(priv->root);
g_free(priv->arch);
+ g_free(priv->kernrelease);
+ g_free(priv->kernpath);
g_free(priv->secLabel);
G_OBJECT_CLASS(gvir_sandbox_config_parent_class)->finalize(object);
@@ -291,6 +315,28 @@ 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_KERNRELEASE,
+ g_param_spec_string("kernrelease",
+ "Kernrelease",
+ "The kernel release
version",
+ 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_KERNPATH,
+ g_param_spec_string("kernpath",
+ "Kernpath",
+ "The kernel image
path",
+ 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",
@@ -388,6 +434,8 @@ static void gvir_sandbox_config_init(GVirSandboxConfig *config)
priv->name = g_strdup("sandbox");
priv->root = g_strdup("/");
priv->arch = g_strdup(uts.machine);
+ priv->kernrelease = g_strdup(uts.release);
+ priv->kernpath = g_strdup_printf("/boot/vmlinuz-%s",
priv->kernrelease);
priv->secLabel = g_strdup("system_u:system_r:svirt_t:s0:c0.c1023");
priv->uid = geteuid();
@@ -474,6 +522,70 @@ const gchar *gvir_sandbox_config_get_arch(GVirSandboxConfig *config)
/**
+ * gvir_sandbox_config_set_kernrelease:
+ * @config: (transfer none): the sandbox config
+ * @kernrelease: (transfer none): the host directory
+ *
+ * Set the kernel release version to use in the sandbox. If none is provided,
+ * it will default to matching the current running kernel.
+ * Also sets the default kernel path as /boot/vmlinuz-<release>
+ */
+void gvir_sandbox_config_set_kernrelease(GVirSandboxConfig *config, const gchar
*kernrelease)
+{
+ GVirSandboxConfigPrivate *priv = config->priv;
+ g_free(priv->kernrelease);
+ priv->kernrelease = g_strdup(kernrelease);
+ gvir_sandbox_config_set_kernpath(config,
g_strdup_printf("/boot/vmlinuz-%s", priv->kernrelease));
+
+}
+
+
+/**
+ * gvir_sandbox_config_get_kernrelease:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox kernel release version
+ *
+ * Returns: (transfer none): the current kernel release version
+ */
+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
+ * @kernpath: (transfer none): the host directory
+ *
+ * Set the kernel image path to use in the sandbox. If none is provided,
+ * it will default to matching /boot/vmlinuz-<kernel release>.
+ */
+
+void gvir_sandbox_config_set_kernpath(GVirSandboxConfig *config, const gchar *kernpath)
+{
+ GVirSandboxConfigPrivate *priv = config->priv;
+ g_free(priv->kernpath);
+ priv->kernpath = g_strdup(kernpath);
+}
+
+
+/**
+ * gvir_sandbox_config_get_kernpath:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox kernel image path
+ *
+ * Returns: (transfer none): the current kernel image path
+ */
+const gchar *gvir_sandbox_config_get_kernpath(GVirSandboxConfig *config)
+{
+ GVirSandboxConfigPrivate *priv = config->priv;
+ return priv->kernpath;
+}
+
+
+/**
* gvir_sandbox_config_set_shell:
* @config: (transfer none): the sandbox config
* @shell: (transfer none): true if the container should have a shell
@@ -1531,6 +1643,14 @@ static gboolean gvir_sandbox_config_load_config(GVirSandboxConfig
*config,
g_free(priv->arch);
priv->arch = str;
}
+ if ((str = g_key_file_get_string(file, "core", "kernrelease",
NULL)) != NULL) {
+ g_free(priv->kernrelease);
+ priv->kernrelease = str;
+ }
+ if ((str = g_key_file_get_string(file, "core", "kernpath", NULL))
!= NULL) {
+ g_free(priv->kernpath);
+ priv->kernpath = str;
+ }
b = g_key_file_get_boolean(file, "core", "shell", &e);
if (e) {
g_error_free(e);
@@ -1748,6 +1868,8 @@ static void gvir_sandbox_config_save_config(GVirSandboxConfig
*config,
g_key_file_set_string(file, "core", "name", priv->name);
g_key_file_set_string(file, "core", "root", priv->root);
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_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 3902e40..a6c8ae8 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -76,6 +76,12 @@ const gchar *gvir_sandbox_config_get_root(GVirSandboxConfig *config);
void gvir_sandbox_config_set_arch(GVirSandboxConfig *config, const gchar *arch);
const gchar *gvir_sandbox_config_get_arch(GVirSandboxConfig *config);
+void gvir_sandbox_config_set_kernrelease(GVirSandboxConfig *config, const gchar
*kernrelease);
+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_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 16cd2ff..424fd98 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -94,6 +94,8 @@ LIBVIRT_SANDBOX_0.0.1 {
gvir_sandbox_config_set_root;
gvir_sandbox_config_set_shell;
gvir_sandbox_config_set_arch;
+gvir_sandbox_config_set_kernrelease;
+gvir_sandbox_config_set_kernpath;
gvir_sandbox_config_set_userid;
gvir_sandbox_config_set_groupid;
gvir_sandbox_config_set_username;