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 17, 2017
1 parent c2fb2bb commit ad0b69c
Show file tree
Hide file tree
Showing 21 changed files with 936 additions and 40 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
3 changes: 3 additions & 0 deletions Makefile-decls.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ gsettings_SCHEMAS =
# git.mk
GITIGNOREFILES =

# This initializes some more variables
include $(top_srcdir)/buildutil/glib-tap.mk

# This is a special facility to chain together hooks easily
INSTALL_DATA_HOOKS =
install-data-hook: $(INSTALL_DATA_HOOKS)
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: 0 additions & 2 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include $(top_srcdir)/buildutil/glib-tap.mk

BASE_TESTS_ENVIRONMENT = \
builddir=$(abs_builddir) \
topsrcdir=$(abs_top_srcdir) \
Expand Down
2 changes: 1 addition & 1 deletion libglnx
Submodule libglnx updated from abd37a to c83ec7
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;
}
31 changes: 29 additions & 2 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 @@ -263,7 +266,31 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
print_kv ("BaseCommit", max_key_len, base_checksum);
is_locally_assembled = TRUE;
}
print_kv ("Commit", max_key_len, checksum);
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;
if (!(live_inprogress || live_replaced))
{
print_kv ("Commit", max_key_len, checksum);
}
else
{
print_kv ("BootedCommit", max_key_len, checksum);

if (live_inprogress)
{
g_print ("%s%s", red_prefix, bold_prefix);
print_kv ("InterruptedLiveCommit", max_key_len, live_inprogress);
g_print ("%s%s", bold_suffix, red_suffix);
}
if (live_replaced)
{
g_print ("%s%s", red_prefix, bold_prefix);
print_kv ("LiveCommit", max_key_len, live_replaced);
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 @@ -215,6 +215,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
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 @@ -235,6 +239,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
Loading

0 comments on commit ad0b69c

Please sign in to comment.