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: #639
  • Loading branch information
cgwalters committed Mar 2, 2017
1 parent 7fd474f commit 188d224
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 27 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 <walters@verbum.org>
*
* 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
5 changes: 5 additions & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
<arg type="s" name="transaction_address" direction="out"/>
</method>

<method name="LiveFs">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="s" name="transaction_address" direction="out"/>
</method>

</interface>

<interface name="org.projectatomic.rpmostree1.Transaction">
Expand Down
27 changes: 1 addition & 26 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,6 @@ parse_origin_deployment (RpmOstreeSysrootUpgrader *self,
return TRUE;
}

/* This is like ostree_sysroot_get_merge_deployment() except we explicitly
* ignore the magical "booted" behavior. For rpm-ostree we're trying something
* different now where we are a bit more stateful and pick up changes from the
* pending root. This allows users to chain operations together naturally.
*/
static OstreeDeployment *
get_origin_merge_deployment (OstreeSysroot *self,
const char *osname)
{
g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (self);
guint i;

for (i = 0; i < deployments->len; i++)
{
OstreeDeployment *deployment = deployments->pdata[i];

if (strcmp (ostree_deployment_get_osname (deployment), osname) != 0)
continue;

return g_object_ref (deployment);
}

return NULL;
}

static gboolean
rpmostree_sysroot_upgrader_initable_init (GInitable *initable,
GCancellable *cancellable,
Expand Down Expand Up @@ -169,7 +144,7 @@ rpmostree_sysroot_upgrader_initable_init (GInitable *initable,
goto out;

self->cfg_merge_deployment = ostree_sysroot_get_merge_deployment (self->sysroot, self->osname);
self->origin_merge_deployment = get_origin_merge_deployment (self->sysroot, self->osname);
self->origin_merge_deployment = rpmostreed_get_origin_merge_deployment (self->sysroot, self->osname);
if (self->cfg_merge_deployment == NULL || self->origin_merge_deployment == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
Expand Down
69 changes: 69 additions & 0 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,74 @@ 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,
GVariant *arg_options)
{
RpmostreedOS *self = RPMOSTREED_OS (interface);
glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
g_autoptr(GVariantDict) dict = NULL;
GError *local_error = NULL;

transaction = merge_compatible_txn (self, invocation);
if (transaction)
goto out;

if (!rpmostreed_sysroot_load_state (rpmostreed_sysroot_get (),
cancellable,
&ot_sysroot,
NULL,
&local_error))
goto out;

transaction = rpmostreed_transaction_new_livefs (invocation,
ot_sysroot,
livefs_flags_from_options (arg_options),
cancellable,
&local_error);
if (transaction == NULL)
goto out;

rpmostreed_transaction_monitor_add (self->transaction_monitor, transaction);

out:
if (local_error != NULL)
{
g_dbus_method_invocation_take_error (invocation, local_error);
}
else
{
const char *client_address;
client_address = rpmostreed_transaction_get_client_address (transaction);
rpmostree_os_complete_pkg_change (interface, invocation, client_address);
}

return TRUE;
}

static gboolean
os_handle_get_cached_rebase_rpm_diff (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -1264,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 188d224

Please sign in to comment.