Skip to content

Commit

Permalink
WIP: livefs
Browse files Browse the repository at this point in the history
WIP due to missing tests and docs.

But I've been playing with this interactively, and it's at a useful place
already. The primary target here is supporting live addition of new packages,
while *also* allowing people to do completely arbitrary replacement if that's
what they want.

Depends:
  GNOME/libglnx#36
  ostreedev/ostree#714

Closes: coreos#639
  • Loading branch information
cgwalters committed Mar 2, 2017
1 parent 801b124 commit 8b42b6a
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 63 deletions.
1 change: 1 addition & 0 deletions Makefile-rpm-ostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rpm_ostree_SOURCES = src/app/main.c \
src/app/rpmostree-builtin-rebase.c \
src/app/rpmostree-builtin-cleanup.c \
src/app/rpmostree-builtin-initramfs.c \
src/app/rpmostree-builtin-livefs.c \
src/app/rpmostree-pkg-builtins.c \
src/app/rpmostree-builtin-status.c \
src/app/rpmostree-builtin-internals.c \
Expand Down
2 changes: 1 addition & 1 deletion libglnx
Submodule libglnx updated from abd37a to f25ed9
1 change: 1 addition & 0 deletions src/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static RpmOstreeCommand legacy_alias_commands[] = {
static RpmOstreeCommand experimental_commands[] = {
{ "internals", rpmostree_builtin_internals },
{ "container", rpmostree_builtin_container },
{ "livefs", rpmostree_builtin_livefs },
{ NULL }
};

Expand Down
100 changes: 100 additions & 0 deletions src/app/rpmostree-builtin-livefs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2017 Colin Walters <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the licence or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/

#include "config.h"

#include <string.h>
#include <glib-unix.h>

#include "rpmostree-builtins.h"
#include "rpmostree-libbuiltin.h"
#include "rpmostree-dbus-helpers.h"

#include <libglnx.h>

static gboolean opt_dry_run;
static gboolean opt_allow_replace;
static gboolean opt_accept_partial;

static GOptionEntry option_entries[] = {
{ "dry-run", 'n', 0, G_OPTION_ARG_NONE, &opt_dry_run, "Only perform analysis, do not make changes", NULL },
{ "allow-replace", 0, 0, G_OPTION_ARG_NONE, &opt_allow_replace, "Allow replacing existing files", NULL },
{ "accept-partial", 0, 0, G_OPTION_ARG_NONE, &opt_accept_partial, "Continue even on partial updates", NULL },
{ NULL }
};

static GVariant *
get_args_variant (void)
{
GVariantDict dict;

g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "dry-run", "b", opt_dry_run);
g_variant_dict_insert (&dict, "replace", "b", opt_allow_replace);
g_variant_dict_insert (&dict, "partial", "b", opt_accept_partial);

return g_variant_dict_end (&dict);
}

int
rpmostree_builtin_livefs (int argc,
char **argv,
GCancellable *cancellable,
GError **error)
{
int exit_status = EXIT_FAILURE;
g_autoptr(GOptionContext) context = g_option_context_new ("- Apply pending deployment changes to booted deployment");
glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
g_autofree char *transaction_address = NULL;

if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
cancellable,
&sysroot_proxy,
error))
goto out;

if (!rpmostree_load_os_proxy (sysroot_proxy, NULL,
cancellable, &os_proxy, error))
goto out;

if (!rpmostree_os_call_live_fs_sync (os_proxy,
get_args_variant (),
&transaction_address,
cancellable,
error))
goto out;

if (!rpmostree_transaction_get_response_sync (sysroot_proxy,
transaction_address,
cancellable,
error))
goto out;

exit_status = EXIT_SUCCESS;
out:
/* Does nothing if using the message bus. */
rpmostree_cleanup_peer ();

return exit_status;
}
1 change: 1 addition & 0 deletions src/app/rpmostree-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BUILTINPROTO(rebase);
BUILTINPROTO(cleanup);
BUILTINPROTO(rollback);
BUILTINPROTO(initramfs);
BUILTINPROTO(livefs);
BUILTINPROTO(status);
BUILTINPROTO(db);
BUILTINPROTO(internals);
Expand Down
41 changes: 26 additions & 15 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,26 @@ os_handle_cleanup (RPMOSTreeOS *interface,
return TRUE;
}

static RpmOstreeTransactionLiveFsFlags
livefs_flags_from_options (GVariant *options)
{
RpmOstreeTransactionLiveFsFlags ret = 0;
GVariantDict options_dict;
gboolean opt = FALSE;

g_variant_dict_init (&options_dict, options);
if (g_variant_dict_lookup (&options_dict, "dry-run", "b", &opt) && opt)
ret |= RPMOSTREE_TRANSACTION_LIVEFS_FLAG_DRY_RUN;
if (g_variant_dict_lookup (&options_dict, "replace", "b", &opt) && opt)
ret |= RPMOSTREE_TRANSACTION_LIVEFS_FLAG_ALLOW_REPLACE;
if (g_variant_dict_lookup (&options_dict, "partial", "b", &opt) && opt)
ret |= RPMOSTREE_TRANSACTION_LIVEFS_FLAG_IGNORE_NON_USR;

g_variant_dict_clear (&options_dict);

return ret;
}

static gboolean
os_handle_live_fs (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation,
Expand All @@ -888,8 +908,6 @@ os_handle_live_fs (RPMOSTreeOS *interface,
glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
g_autoptr(GVariantDict) dict = NULL;
const char *osname;
gboolean reboot = FALSE;
GError *local_error = NULL;

transaction = merge_compatible_txn (self, invocation);
Expand All @@ -903,19 +921,11 @@ os_handle_live_fs (RPMOSTreeOS *interface,
&local_error))
goto out;

osname = rpmostree_os_get_name (interface);

dict = g_variant_dict_new (arg_options);
g_variant_dict_lookup (dict, "reboot", "b", &reboot);

transaction = rpmostreed_transaction_new_initramfs_state (invocation,
ot_sysroot,
osname,
regenerate,
(char**)args,
reboot,
cancellable,
&local_error);
transaction = rpmostreed_transaction_new_livefs (invocation,
ot_sysroot,
livefs_flags_from_options (arg_options),
cancellable,
&local_error);
if (transaction == NULL)
goto out;

Expand Down Expand Up @@ -1322,6 +1332,7 @@ rpmostreed_os_iface_init (RPMOSTreeOSIface *iface)
iface->handle_pkg_change = os_handle_pkg_change;
iface->handle_set_initramfs_state = os_handle_set_initramfs_state;
iface->handle_cleanup = os_handle_cleanup;
iface->handle_live_fs = os_handle_live_fs;
iface->handle_get_cached_rebase_rpm_diff = os_handle_get_cached_rebase_rpm_diff;
iface->handle_download_rebase_rpm_diff = os_handle_download_rebase_rpm_diff;
iface->handle_get_cached_deploy_rpm_diff = os_handle_get_cached_deploy_rpm_diff;
Expand Down
Loading

0 comments on commit 8b42b6a

Please sign in to comment.