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: coreos#639
  • Loading branch information
cgwalters committed Mar 22, 2017
1 parent 7be6141 commit 9068e75
Show file tree
Hide file tree
Showing 17 changed files with 891 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Makefile-daemon.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -49,6 +50,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
101 changes: 101 additions & 0 deletions src/app/rpmostree-builtin-livefs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* -*- 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)
{
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,
invocation,
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;
}
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 @@ -221,6 +221,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
16 changes: 15 additions & 1 deletion 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 @@ -157,7 +158,8 @@ variant_add_commit_details (GVariantDict *dict,
}

GVariant *
rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
const char *booted_id,
OstreeRepo *repo,
GError **error)
Expand All @@ -178,6 +180,8 @@ rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
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 @@ -247,6 +251,16 @@ rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
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
5 changes: 3 additions & 2 deletions src/daemon/rpmostreed-deployment-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ OstreeDeployment *

GVariant * rpmostreed_deployment_generate_blank_variant (void);

GVariant * rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
GVariant * rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
const char *booted_id,
OstreeRepo *repo,
GError **error);
GError **error);

GVariant * rpmostreed_commit_generate_cached_details_variant (OstreeDeployment *deployment,
OstreeRepo *repo,
Expand Down
77 changes: 73 additions & 4 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,73 @@ 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 ();
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_live_fs (interface, invocation, client_address);
}

return TRUE;
}

static gboolean
os_handle_get_cached_rebase_rpm_diff (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -1195,7 +1262,7 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
booted = ostree_sysroot_get_booted_deployment (ot_sysroot);
if (booted && g_strcmp0 (ostree_deployment_get_osname (booted), name) == 0)
{
booted_variant = rpmostreed_deployment_generate_variant (booted, booted_id, ot_repo, error);
booted_variant = rpmostreed_deployment_generate_variant (ot_sysroot, booted, booted_id, ot_repo, error);
if (!booted_variant)
return FALSE;
booted_id = rpmostreed_deployment_generate_id (booted);
Expand All @@ -1206,7 +1273,8 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
{
if (g_strcmp0 (ostree_deployment_get_osname (deployments->pdata[i]), name) == 0)
{
default_variant = rpmostreed_deployment_generate_variant (deployments->pdata[i],
default_variant = rpmostreed_deployment_generate_variant (ot_sysroot,
deployments->pdata[i],
booted_id,
ot_repo, error);
if (default_variant == NULL)
Expand All @@ -1220,8 +1288,8 @@ 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 (deployments->pdata[rollback_index], booted_id,
ot_repo, error);
rollback_variant = rpmostreed_deployment_generate_variant (ot_sysroot, deployments->pdata[rollback_index], booted_id,
ot_repo, error);
if (!rollback_variant)
return FALSE;
}
Expand Down Expand Up @@ -1283,6 +1351,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 9068e75

Please sign in to comment.