Skip to content

Commit

Permalink
WIP: livefs
Browse files Browse the repository at this point in the history
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 27, 2017
1 parent 1b8f03d commit b0f5d7a
Show file tree
Hide file tree
Showing 16 changed files with 978 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Makefile-daemon.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ librpmostreed_la_SOURCES = \
src/daemon/rpmostreed-transaction-monitor.c \
src/daemon/rpmostreed-transaction-types.h \
src/daemon/rpmostreed-transaction-types.c \
src/daemon/rpmostreed-transaction-livefs.c \
src/daemon/rpmostree-package-variants.h \
src/daemon/rpmostree-package-variants.c \
src/daemon/rpmostreed-os.h \
Expand All @@ -54,6 +55,7 @@ librpmostreed_la_CFLAGS = \
$(AM_CFLAGS) \
$(PKGDEP_RPMOSTREE_CFLAGS) \
-DG_LOG_DOMAIN=\"rpm-ostreed\" \
-D_RPMOSTREE_EXTERN= \
-I$(srcdir)/src/daemon \
-I$(srcdir)/src/lib \
-I$(srcdir)/src/libpriv \
Expand Down
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-ex.c \
Expand Down
2 changes: 2 additions & 0 deletions src/app/rpmostree-builtin-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "rpmostree-rpm-util.h"

static RpmOstreeCommand ex_subcommands[] = {
{ "livefs", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_ex_builtin_livefs },
{ "unpack", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_ex_builtin_unpack },
{ "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
Expand Down
98 changes: 98 additions & 0 deletions src/app/rpmostree-builtin-livefs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* -*- 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-ex-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_ex_builtin_livefs (int argc,
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
_cleanup_peer_ GPid peer_pid = 0;
glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
g_autoptr(GOptionContext) context = g_option_context_new ("- Apply pending deployment changes to booted deployment");
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
invocation,
cancellable,
&sysroot_proxy,
&peer_pid,
error))
return EXIT_FAILURE;

glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
glnx_unref_object RPMOSTreeOSExperimental *osexperimental_proxy = NULL;
if (!rpmostree_load_os_proxies (sysroot_proxy, NULL,
cancellable, &os_proxy,
&osexperimental_proxy, error))
return EXIT_FAILURE;

g_autofree char *transaction_address = NULL;
if (!rpmostree_osexperimental_call_live_fs_sync (osexperimental_proxy,
get_args_variant (),
&transaction_address,
cancellable,
error))
return EXIT_FAILURE;

if (!rpmostree_transaction_get_response_sync (sysroot_proxy,
transaction_address,
cancellable,
error))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}
42 changes: 39 additions & 3 deletions src/app/rpmostree-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,16 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
const gchar *checksum;
const gchar *version_string;
const gchar *unlocked;
const gchar *live_inprogress;
const gchar *live_replaced;
gboolean gpg_enabled;
gboolean regenerate_initramfs;
guint64 t = 0;
int serial;
gboolean is_booted;
const gboolean was_first = first;
const guint max_key_len = strlen ("PendingBaseVersion");
/* Add the long keys here */
const guint max_key_len = MAX (strlen ("PendingBaseVersion"), strlen ("InterruptedLiveCommit"));
g_autoptr(GVariant) signatures = NULL;
g_autofree char *timestamp_string = NULL;

Expand Down Expand Up @@ -265,10 +268,43 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
print_kv ("Timestamp", max_key_len, timestamp_string);
}

if (!g_variant_dict_lookup (dict, "live-inprogress", "&s", &live_inprogress))
live_inprogress = NULL;
if (!g_variant_dict_lookup (dict, "live-replaced", "&s", &live_replaced))
live_replaced = NULL;
const gboolean have_live_changes = live_inprogress || live_replaced;

if (is_locally_assembled)
print_kv ("BaseCommit", max_key_len, base_checksum);
{
if (have_live_changes)
print_kv ("BootedBaseCommit", max_key_len, base_checksum);
else
print_kv ("BaseCommit", max_key_len, base_checksum);
}
else
print_kv ("Commit", max_key_len, checksum);
{
if (have_live_changes)
print_kv ("BootedCommit", max_key_len, checksum);
else
print_kv ("Commit", max_key_len, checksum);
}

if (live_inprogress)
{
if (is_booted)
g_print ("%s%s", red_prefix, bold_prefix);
print_kv ("InterruptedLiveCommit", max_key_len, live_inprogress);
if (is_booted)
g_print ("%s%s", bold_suffix, red_suffix);
}
if (live_replaced)
{
if (is_booted)
g_print ("%s%s", red_prefix, bold_prefix);
print_kv ("LiveCommit", max_key_len, live_replaced);
if (is_booted)
g_print ("%s%s", bold_suffix, red_suffix);
}

/* Show any difference between the baseref vs head, but only for the
booted commit, and only if there isn't a pending deployment. Otherwise
Expand Down
9 changes: 8 additions & 1 deletion src/app/rpmostree-ex-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@

G_BEGIN_DECLS

gboolean rpmostree_ex_builtin_unpack (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error);
#define BUILTINPROTO(name) gboolean rpmostree_ex_builtin_ ## name (int argc, char **argv, \
RpmOstreeCommandInvocation *invocation, \
GCancellable *cancellable, GError **error)

BUILTINPROTO(unpack);
BUILTINPROTO(livefs);

#undef BUILTINPROTO

G_END_DECLS

5 changes: 5 additions & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
<arg type="s" name="result" 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
13 changes: 13 additions & 0 deletions src/daemon/rpmostreed-deployment-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "rpmostreed-deployment-utils.h"
#include "rpmostree-origin.h"
#include "rpmostree-util.h"
#include "rpmostreed-utils.h"

#include <libglnx.h>

Expand Down Expand Up @@ -179,6 +180,8 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
gint serial = ostree_deployment_get_deployserial (deployment);
gboolean gpg_enabled = FALSE;
gboolean is_layered = FALSE;
g_autofree char *live_inprogress = NULL;
g_autofree char *live_replaced = NULL;
g_auto(GStrv) layered_pkgs = NULL;

if (!ostree_repo_load_variant (repo,
Expand Down Expand Up @@ -248,6 +251,16 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
variant_add_commit_details (&dict, "pending-base-", pending_base_commit);
}

if (!rpmostreed_deployment_get_live_status (sysroot, deployment, -1,
&live_inprogress, &live_replaced,
error))
return NULL;

if (live_inprogress)
g_variant_dict_insert (&dict, "live-inprogress", "s", live_inprogress);
if (live_replaced)
g_variant_dict_insert (&dict, "live-replaced", "s", live_replaced);

g_variant_dict_insert (&dict, "origin", "s", refspec);

g_autofree char **requested_pkgs =
Expand Down
84 changes: 84 additions & 0 deletions src/daemon/rpmostreed-os-experimental.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ G_DEFINE_TYPE_WITH_CODE (RpmostreedOSExperimental,
rpmostreed_osexperimental_iface_init)
);

static RpmostreedTransaction *
merge_compatible_txn (RpmostreedOSExperimental *self,
GDBusMethodInvocation *invocation)
{
glnx_unref_object RpmostreedTransaction *transaction = NULL;

/* If a compatible transaction is in progress, share its bus address. */
transaction = rpmostreed_transaction_monitor_ref_active_transaction (self->transaction_monitor);
if (transaction != NULL)
{
if (rpmostreed_transaction_is_compatible (transaction, invocation))
return g_steal_pointer (&transaction);
}

return NULL;
}

/* ---------------------------------------------------------------------------------------------------- */

static void
Expand Down Expand Up @@ -119,11 +136,78 @@ osexperimental_handle_moo (RPMOSTreeOSExperimental *interface,
rpmostree_osexperimental_complete_moo (interface, invocation, result);
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
osexperimental_handle_live_fs (RPMOSTreeOSExperimental *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_options)
{
RpmostreedOSExperimental *self = RPMOSTREED_OSEXPERIMENTAL (interface);
glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
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_osexperimental_complete_live_fs (interface, invocation, client_address);
}

return TRUE;
}

static void
rpmostreed_osexperimental_iface_init (RPMOSTreeOSExperimentalIface *iface)
{
iface->handle_moo = osexperimental_handle_moo;
iface->handle_live_fs = osexperimental_handle_live_fs;
}

/* ---------------------------------------------------------------------------------------------------- */
Expand Down
3 changes: 1 addition & 2 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,7 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
rollback_index = rpmostreed_rollback_deployment_index (name, ot_sysroot, NULL);
if (rollback_index >= 0)
{
rollback_variant = rpmostreed_deployment_generate_variant (ot_sysroot,
deployments->pdata[rollback_index], booted_id,
rollback_variant = rpmostreed_deployment_generate_variant (ot_sysroot, deployments->pdata[rollback_index], booted_id,
ot_repo, error);
if (!rollback_variant)
return FALSE;
Expand Down
Loading

0 comments on commit b0f5d7a

Please sign in to comment.