-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sysroot: Add concept of deployment "pinning" 📌 #1464
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,6 +399,37 @@ _ostree_admin_os_init() { | |
return 0 | ||
} | ||
|
||
_ostree_admin_pin() { | ||
local boolean_options=" | ||
$main_boolean_options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't grasp bash completion, I don't care too much about it myself at least for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There has to be someone out there who has implemented actually generating this stuff from the cli |
||
" | ||
|
||
local options_with_args=" | ||
--sysroot | ||
" | ||
|
||
local options_with_args_glob=$( __ostree_to_extglob "$options_with_args" ) | ||
|
||
case "$prev" in | ||
--sysroot) | ||
__ostree_compreply_dirs_only | ||
return 0 | ||
;; | ||
$options_with_args_glob ) | ||
return 0 | ||
;; | ||
esac | ||
|
||
case "$cur" in | ||
-*) | ||
local all_options="$boolean_options $options_with_args" | ||
__ostree_compreply_all_options | ||
;; | ||
esac | ||
|
||
return 0 | ||
} | ||
|
||
_ostree_admin_set_origin() { | ||
local boolean_options=" | ||
$main_boolean_options | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version='1.0'?> <!--*-nxml-*--> | ||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | ||
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | ||
|
||
<!-- | ||
Copyright 2018 Red Hat | ||
|
||
SPDX-License-Identifier: LGPL-2.0+ | ||
|
||
This library 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 License, 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. | ||
--> | ||
|
||
<refentry id="ostree"> | ||
|
||
<refentryinfo> | ||
<title>ostree admin pin</title> | ||
<productname>OSTree</productname> | ||
|
||
<authorgroup> | ||
<author> | ||
<contrib>Developer</contrib> | ||
<firstname>Colin</firstname> | ||
<surname>Walters</surname> | ||
<email>[email protected]</email> | ||
</author> | ||
</authorgroup> | ||
</refentryinfo> | ||
|
||
<refmeta> | ||
<refentrytitle>ostree admin pin</refentrytitle> | ||
<manvolnum>1</manvolnum> | ||
</refmeta> | ||
|
||
<refnamediv> | ||
<refname>ostree-admin-pin</refname> | ||
<refpurpose>Explicitly retain deployment at a given index</refpurpose> | ||
</refnamediv> | ||
|
||
<refsynopsisdiv> | ||
<cmdsynopsis> | ||
<command>ostree admin pin</command> <arg choice="req">INDEX</arg> | ||
</cmdsynopsis> | ||
</refsynopsisdiv> | ||
|
||
<refsect1> | ||
<title>Description</title> | ||
|
||
<para> | ||
Ensures the deployment at <literal>INDEX</literal>, will not be garbage | ||
collected by default. This is termed "pinning". If the | ||
<literal>-u</literal> option is provided, undoes a pinning operation. | ||
</para> | ||
</refsect1> | ||
|
||
<refsect1> | ||
<title>Options</title> | ||
|
||
<variablelist> | ||
<varlistentry> | ||
<term><option>--unpin</option>,<option>-u</option></term> | ||
|
||
<listitem><para> | ||
Undoes a pinning operation. | ||
</para></listitem> | ||
</varlistentry> | ||
</variablelist> | ||
</refsect1> | ||
|
||
</refentry> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1572,12 +1572,14 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, | |
|
||
/* Retain deployment if: | ||
* - we're explicitly asked to, or | ||
* - it's pinned | ||
* - the deployment is for another osname, or | ||
* - we're keeping pending deployments and this is a pending deployment, or | ||
* - this is the merge or boot deployment, or | ||
* - we're keeping rollback deployments and this is a rollback deployment | ||
*/ | ||
if (retain | ||
|| ostree_deployment_is_pinned (deployment) | ||
|| !osname_matches | ||
|| (retain_pending && !passed_crossover) | ||
|| (is_booted || is_merge) | ||
|
@@ -1832,3 +1834,45 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, | |
|
||
return TRUE; | ||
} | ||
|
||
/** | ||
* ostree_sysroot_deployment_set_pinned: | ||
* @self: Sysroot | ||
* @deployment: A deployment | ||
* @is_pinned: Whether or not deployment will be automatically GC'd | ||
* @error: Error | ||
* | ||
* By default, deployments may be subject to garbage collection. Typical uses of | ||
* libostree only retain at most 2 deployments. If @is_pinned is `TRUE`, a | ||
* metadata bit will be set causing libostree to avoid automatic GC of the | ||
* deployment. However, this is really an "advisory" note; it's still possible | ||
* for e.g. older versions of libostree unaware of pinning to GC the deployment. | ||
* | ||
* This function does nothing and returns successfully if the deployment | ||
* is already in the desired pinning state. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* | ||
* Since: 2018.3 | ||
*/ | ||
gboolean | ||
ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, | ||
OstreeDeployment *deployment, | ||
gboolean is_pinned, | ||
GError **error) | ||
{ | ||
const gboolean current_pin = ostree_deployment_is_pinned (deployment); | ||
if (is_pinned == current_pin) | ||
return TRUE; | ||
|
||
g_autoptr(OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused here. Why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the sysroot array should be immutable. That actually reveals a bug, we need to bump the mtime so e.g. rpm-ostree will do a reload. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh got it, that makes sense. |
||
GKeyFile *origin_clone = ostree_deployment_get_origin (deployment_clone); | ||
|
||
if (is_pinned) | ||
g_key_file_set_boolean (origin_clone, OSTREE_ORIGIN_TRANSIENT_GROUP, "pinned", TRUE); | ||
else | ||
g_key_file_remove_key (origin_clone, OSTREE_ORIGIN_TRANSIENT_GROUP, "pinned", NULL); | ||
|
||
if (!ostree_sysroot_write_origin_file (self, deployment, origin_clone, NULL, error)) | ||
return FALSE; | ||
|
||
return TRUE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2018 Colin Walters <[email protected]> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library 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 License, 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 <stdlib.h> | ||
|
||
#include "ot-main.h" | ||
#include "ot-admin-builtins.h" | ||
#include "ot-admin-functions.h" | ||
#include "ostree.h" | ||
#include "otutil.h" | ||
|
||
/* ATTENTION: | ||
* Please remember to update the bash-completion script (bash/ostree) and | ||
* man page (man/ostree-admin-pin.xml) when changing the option list. | ||
*/ | ||
|
||
static gboolean opt_unpin; | ||
|
||
static GOptionEntry options[] = { | ||
{ "unpin", 'u', 0, G_OPTION_ARG_NONE, &opt_unpin, "Unset pin", NULL }, | ||
{ NULL } | ||
}; | ||
|
||
gboolean | ||
ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) | ||
{ | ||
g_autoptr(GOptionContext) context = g_option_context_new ("INDEX"); | ||
g_autoptr(OstreeSysroot) sysroot = NULL; | ||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv, | ||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, | ||
invocation, &sysroot, cancellable, error)) | ||
return FALSE; | ||
|
||
if (argc < 2) | ||
{ | ||
ot_util_usage_error (context, "INDEX must be specified", error); | ||
return FALSE; | ||
} | ||
|
||
const char *deploy_index_str = argv[1]; | ||
const int deploy_index = atoi (deploy_index_str); | ||
|
||
g_autoptr(OstreeDeployment) target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); | ||
if (!target_deployment) | ||
return FALSE; | ||
|
||
|
||
gboolean current_pin = ostree_deployment_is_pinned (target_deployment); | ||
const gboolean desired_pin = !opt_unpin; | ||
if (current_pin == desired_pin) | ||
g_print ("Deployment is already %s\n", current_pin ? "pinned" : "unpinned"); | ||
else | ||
{ | ||
if (!ostree_sysroot_deployment_set_pinned (sysroot, target_deployment, desired_pin, error)) | ||
return FALSE; | ||
g_print ("Deployment is now %s\n", desired_pin ? "pinned" : "unpinned"); | ||
} | ||
|
||
return TRUE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, we also need a
pin
entry in_ostree_admin()
.