[ostree] admin: Allow specifying --boot-dir
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] admin: Allow specifying --boot-dir
- Date: Sat, 5 Jan 2013 00:32:49 +0000 (UTC)
commit 2db497fd3f982ff391e4cade8f5b27af4cd62f4a
Author: Colin Walters <walters verbum org>
Date: Wed Jan 2 22:44:06 2013 -0500
admin: Allow specifying --boot-dir
This is intended for use by QA tools that want to manipulate a
loopback-mounted disk image or the like.
src/ostree/ot-admin-builtin-deploy.c | 6 +++-
src/ostree/ot-admin-builtin-diff.c | 3 +-
src/ostree/ot-admin-builtin-init-fs.c | 2 +-
src/ostree/ot-admin-builtin-install.c | 3 +-
src/ostree/ot-admin-builtin-os-init.c | 3 +-
src/ostree/ot-admin-builtin-prune.c | 3 +-
src/ostree/ot-admin-builtin-pull-deploy.c | 3 +-
src/ostree/ot-admin-builtin-run-triggers.c | 2 +-
src/ostree/ot-admin-builtin-update-kernel.c | 28 ++++++++++++++++++--------
src/ostree/ot-admin-builtin-upgrade.c | 3 +-
src/ostree/ot-admin-builtins.h | 25 ++++++++++++++---------
src/ostree/ot-builtin-admin.c | 11 ++++++++-
12 files changed, 61 insertions(+), 31 deletions(-)
---
diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c
index 588b6a9..ffe9f28 100644
--- a/src/ostree/ot-admin-builtin-deploy.c
+++ b/src/ostree/ot-admin-builtin-deploy.c
@@ -30,6 +30,7 @@
typedef struct {
OstreeRepo *repo;
+ OtAdminBuiltinOpts *admin_opts;
GFile *ostree_dir;
char *osname;
GFile *osname_dir;
@@ -621,7 +622,7 @@ do_update_kernel (OtAdminDeploy *self,
}
gboolean
-ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
OtAdminDeploy self_data;
@@ -649,7 +650,8 @@ ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **erro
goto out;
}
- self->ostree_dir = g_object_ref (ostree_dir);
+ self->admin_opts = admin_opts;
+ self->ostree_dir = g_object_ref (admin_opts->ostree_dir);
if (!ot_admin_ensure_initialized (self->ostree_dir, cancellable, error))
goto out;
diff --git a/src/ostree/ot-admin-builtin-diff.c b/src/ostree/ot-admin-builtin-diff.c
index 64c2bcc..af2b288 100644
--- a/src/ostree/ot-admin-builtin-diff.c
+++ b/src/ostree/ot-admin-builtin-diff.c
@@ -33,11 +33,12 @@ static GOptionEntry options[] = {
};
gboolean
-ot_admin_builtin_diff (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
const char *osname;
+ GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *deployment = NULL;
ot_lobj GFile *deploy_parent = NULL;
diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c
index 52a4dcd..d8a5355 100644
--- a/src/ostree/ot-admin-builtin-init-fs.c
+++ b/src/ostree/ot-admin-builtin-init-fs.c
@@ -33,7 +33,7 @@ static GOptionEntry options[] = {
};
gboolean
-ot_admin_builtin_init_fs (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
diff --git a/src/ostree/ot-admin-builtin-install.c b/src/ostree/ot-admin-builtin-install.c
index 7e0cb45..5ec8ff7 100644
--- a/src/ostree/ot-admin-builtin-install.c
+++ b/src/ostree/ot-admin-builtin-install.c
@@ -62,7 +62,7 @@ on_keyfile_retrieved (GObject *obj,
}
gboolean
-ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
OtAdminBuiltinInstall self_data;
OtAdminBuiltinInstall *self = &self_data;
@@ -70,6 +70,7 @@ ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **err
gboolean ret = FALSE;
const char *keyfile_arg = NULL;
const char *treename_arg = NULL;
+ GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *osdir = NULL;
ot_lobj GFile *dest_osconfig_path = NULL;
diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c
index 3cd38aa..123e085 100644
--- a/src/ostree/ot-admin-builtin-os-init.c
+++ b/src/ostree/ot-admin-builtin-os-init.c
@@ -33,11 +33,12 @@ static GOptionEntry options[] = {
};
gboolean
-ot_admin_builtin_os_init (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
const char *osname = NULL;
+ GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *dir = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL;
diff --git a/src/ostree/ot-admin-builtin-prune.c b/src/ostree/ot-admin-builtin-prune.c
index d2b2cc5..f53229c 100644
--- a/src/ostree/ot-admin-builtin-prune.c
+++ b/src/ostree/ot-admin-builtin-prune.c
@@ -98,12 +98,13 @@ list_deployments (GFile *from_dir,
}
gboolean
-ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_prune (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
guint i;
const char *osname;
+ GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *current_deployment = NULL;
diff --git a/src/ostree/ot-admin-builtin-pull-deploy.c b/src/ostree/ot-admin-builtin-pull-deploy.c
index 47c675d..1333f41 100644
--- a/src/ostree/ot-admin-builtin-pull-deploy.c
+++ b/src/ostree/ot-admin-builtin-pull-deploy.c
@@ -51,11 +51,12 @@ parse_deploy_name_from_path (GFile *osdir,
}
gboolean
-ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
const char *osname;
+ GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *current_deployment = NULL;
ot_lfree char *deploy_name = NULL;
diff --git a/src/ostree/ot-admin-builtin-run-triggers.c b/src/ostree/ot-admin-builtin-run-triggers.c
index 7c146cd..9adbf0f 100644
--- a/src/ostree/ot-admin-builtin-run-triggers.c
+++ b/src/ostree/ot-admin-builtin-run-triggers.c
@@ -35,7 +35,7 @@ static GOptionEntry options[] = {
};
gboolean
-ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_run_triggers (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
diff --git a/src/ostree/ot-admin-builtin-update-kernel.c b/src/ostree/ot-admin-builtin-update-kernel.c
index 1fd9ac7..b43c74e 100644
--- a/src/ostree/ot-admin-builtin-update-kernel.c
+++ b/src/ostree/ot-admin-builtin-update-kernel.c
@@ -29,7 +29,9 @@
#include <sys/utsname.h>
typedef struct {
+ OtAdminBuiltinOpts *admin_opts;
GFile *ostree_dir;
+ GFile *boot_ostree_dir;
const char *deploy_path;
GFile *kernel_path;
char *release;
@@ -122,7 +124,6 @@ setup_kernel (OtAdminUpdateKernel *self,
ot_lobj GFile *deploy_path = NULL;
ot_lobj GFile *deploy_boot_path = NULL;
ot_lobj GFile *src_kernel_path = NULL;
- ot_lobj GFile *host_boot = NULL;
ot_lfree char *prefix = NULL;
const char *release = NULL;
const char *kernel_name = NULL;
@@ -140,8 +141,7 @@ setup_kernel (OtAdminUpdateKernel *self,
goto out;
}
- host_boot = g_file_new_for_path ("/boot/ostree");
- if (!gs_file_ensure_directory (host_boot, TRUE, cancellable, error))
+ if (!gs_file_ensure_directory (self->boot_ostree_dir, TRUE, cancellable, error))
goto out;
kernel_name = gs_file_get_basename_cached (src_kernel_path);
@@ -155,7 +155,7 @@ setup_kernel (OtAdminUpdateKernel *self,
self->release = g_strdup (release + 1);
prefix = g_strndup (kernel_name, release - kernel_name);
- self->kernel_path = ot_gfile_get_child_strconcat (host_boot, prefix, "-", self->release, NULL);
+ self->kernel_path = ot_gfile_get_child_strconcat (self->boot_ostree_dir, prefix, "-", self->release, NULL);
if (!g_file_copy (src_kernel_path, self->kernel_path,
G_FILE_COPY_OVERWRITE | G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NOFOLLOW_SYMLINKS,
@@ -183,7 +183,7 @@ update_initramfs (OtAdminUpdateKernel *self,
initramfs_name = g_strconcat ("initramfs-", self->release, ".img", NULL);
- initramfs_file = ot_gfile_from_build_path ("/boot", "ostree", initramfs_name, NULL);
+ initramfs_file = g_file_get_child (self->boot_ostree_dir, initramfs_name);
if (!g_file_query_exists (initramfs_file, NULL))
{
gs_unref_ptrarray GPtrArray *mkinitramfs_args = NULL;
@@ -324,7 +324,7 @@ get_kernel_path_from_release (OtAdminUpdateKernel *self,
/* TODO - replace this with grubby code */
name = g_strconcat ("vmlinuz-", release, NULL);
- possible_path = ot_gfile_from_build_path ("/boot", name, NULL);
+ possible_path = g_file_get_child (self->admin_opts->boot_dir, name);
if (!g_file_query_exists (possible_path, cancellable))
g_clear_object (&possible_path);
@@ -340,7 +340,7 @@ update_grub (OtAdminUpdateKernel *self,
GError **error)
{
gboolean ret = FALSE;
- ot_lobj GFile *grub_path = g_file_new_for_path ("/boot/grub/grub.conf");
+ ot_lobj GFile *grub_path = g_file_resolve_relative_path (self->admin_opts->boot_dir, "grub/grub.conf");
if (g_file_query_exists (grub_path, cancellable))
{
@@ -353,7 +353,9 @@ update_grub (OtAdminUpdateKernel *self,
{
ot_lfree char *add_kernel_arg = NULL;
ot_lfree char *initramfs_arg = NULL;
+ ot_lfree char *initramfs_name = NULL;
ot_lobj GFile *kernel_path = NULL;
+ ot_lobj GFile *initramfs_path = NULL;
if (!self->kernel_path)
{
@@ -371,8 +373,11 @@ update_grub (OtAdminUpdateKernel *self,
else
kernel_path = g_object_ref (self->kernel_path);
+ initramfs_name = g_strconcat ("initramfs-", self->release, ".img", NULL);
+ initramfs_path = g_file_get_child (self->boot_ostree_dir, initramfs_name);
+
add_kernel_arg = g_strconcat ("--add-kernel=", gs_file_get_path_cached (kernel_path), NULL);
- initramfs_arg = g_strconcat ("--initrd=", "/boot/ostree/initramfs-", self->release, ".img", NULL);
+ initramfs_arg = g_strconcat ("--initrd=", gs_file_get_path_cached (initramfs_path), NULL);
g_print ("Adding OSTree grub entry...\n");
if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
@@ -395,17 +400,20 @@ update_grub (OtAdminUpdateKernel *self,
}
gboolean
-ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_update_kernel (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
OtAdminUpdateKernel self_data;
OtAdminUpdateKernel *self = &self_data;
+ GFile *ostree_dir = admin_opts->ostree_dir;
gboolean ret = FALSE;
struct utsname utsname;
GCancellable *cancellable = NULL;
memset (self, 0, sizeof (*self));
+ self->admin_opts = admin_opts;
+
context = g_option_context_new ("OSNAME DEPLOY_PATH - Update kernel and regenerate initial ramfs");
g_option_context_add_main_entries (context, options, NULL);
@@ -446,6 +454,7 @@ ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError
}
self->ostree_dir = g_object_ref (ostree_dir);
+ self->boot_ostree_dir = g_file_get_child (admin_opts->boot_dir, "ostree");
if (opt_host_kernel)
{
@@ -471,6 +480,7 @@ ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError
ret = TRUE;
out:
g_clear_object (&self->ostree_dir);
+ g_clear_object (&self->boot_ostree_dir);
g_clear_object (&self->kernel_path);
g_free (self->release);
if (context)
diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c
index 635ae1f..dc28657 100644
--- a/src/ostree/ot-admin-builtin-upgrade.c
+++ b/src/ostree/ot-admin-builtin-upgrade.c
@@ -35,10 +35,11 @@ static GOptionEntry options[] = {
};
gboolean
-ot_admin_builtin_upgrade (int argc, char **argv, GFile *ostree_dir, GError **error)
+ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
+ GFile *ostree_dir = admin_opts->ostree_dir;
const char *osname = NULL;
gs_free char *ostree_dir_arg = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL;
diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h
index d6decd4..5fbdacd 100644
--- a/src/ostree/ot-admin-builtins.h
+++ b/src/ostree/ot-admin-builtins.h
@@ -27,16 +27,21 @@
G_BEGIN_DECLS
-gboolean ot_admin_builtin_os_init (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_init_fs (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_diff (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError **error);
-gboolean ot_admin_builtin_upgrade (int argc, char **argv, GFile *ostree_dir, GError **error);
+typedef struct {
+ GFile *ostree_dir;
+ GFile *boot_dir;
+} OtAdminBuiltinOpts;
+
+gboolean ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_prune (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_run_triggers (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_update_kernel (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
+gboolean ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
G_END_DECLS
diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c
index 831e80c..1f23647 100644
--- a/src/ostree/ot-builtin-admin.c
+++ b/src/ostree/ot-builtin-admin.c
@@ -31,15 +31,17 @@
#include <glib/gi18n.h>
static char *opt_ostree_dir = "/ostree";
+static char *opt_boot_dir = "/boot";
static GOptionEntry options[] = {
{ "ostree-dir", 0, 0, G_OPTION_ARG_STRING, &opt_ostree_dir, "Path to OSTree root directory (default: /ostree)", NULL },
+ { "boot-dir", 0, 0, G_OPTION_ARG_STRING, &opt_boot_dir, "Path to system boot directory (default: /boot)", NULL },
{ NULL }
};
typedef struct {
const char *name;
- gboolean (*fn) (int argc, char **argv, GFile *ostree_dir, GError **error);
+ gboolean (*fn) (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
} OstreeAdminCommand;
static OstreeAdminCommand admin_subcommands[] = {
@@ -65,8 +67,10 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GError **error)
const char *subcommand_name;
OstreeAdminCommand *subcommand;
int subcmd_argc;
+ OtAdminBuiltinOpts admin_opts;
char **subcmd_argv = NULL;
ot_lobj GFile *ostree_dir = NULL;
+ ot_lobj GFile *boot_dir = NULL;
context = g_option_context_new ("[OPTIONS] SUBCOMMAND - Run an administrative subcommand");
@@ -113,10 +117,13 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GError **error)
}
ostree_dir = g_file_new_for_path (opt_ostree_dir);
+ boot_dir = g_file_new_for_path (opt_boot_dir);
ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv);
- if (!subcommand->fn (subcmd_argc, subcmd_argv, ostree_dir, error))
+ admin_opts.ostree_dir = ostree_dir;
+ admin_opts.boot_dir = boot_dir;
+ if (!subcommand->fn (subcmd_argc, subcmd_argv, &admin_opts, error))
goto out;
ret = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]