1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

Remove snapshot unit type

Snapshots were never useful or used for anything. Many systemd
developers that I spoke to at systemd.conf2015, didn't even know they
existed, so it is fairly safe to assume that this type can be deleted
without harm.

The fundamental problem with snapshots is that the state of the system
is dynamic, devices come and go, users log in and out, timers fire...
and restoring all units to some state from the past would "undo"
those changes, which isn't really possible.

Tested by creating a snapshot, running the new binary, and checking
that the transition did not cause errors, and the snapshot is gone,
and snapshots cannot be created anymore.

New systemctl says:
Unknown operation snapshot.
Old systemctl says:
Failed to create snapshot: Support for snapshots has been removed.

IgnoreOnSnaphost settings are warned about and ignored:
Support for option IgnoreOnSnapshot= has been removed and it is ignored

http://lists.freedesktop.org/archives/systemd-devel/2015-November/034872.html
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2015-11-08 14:12:54 +01:00
parent e3c4a681db
commit 36b4a7ba55
27 changed files with 11 additions and 814 deletions

View File

@ -136,7 +136,6 @@ MANPAGES += \
man/systemd.scope.5 \
man/systemd.service.5 \
man/systemd.slice.5 \
man/systemd.snapshot.5 \
man/systemd.socket.5 \
man/systemd.special.7 \
man/systemd.swap.5 \
@ -2413,7 +2412,6 @@ EXTRA_DIST += \
man/systemd.scope.xml \
man/systemd.service.xml \
man/systemd.slice.xml \
man/systemd.snapshot.xml \
man/systemd.socket.xml \
man/systemd.special.xml \
man/systemd.swap.xml \

View File

@ -1138,8 +1138,6 @@ libcore_la_SOURCES = \
src/core/bus-policy.h \
src/core/target.c \
src/core/target.h \
src/core/snapshot.c \
src/core/snapshot.h \
src/core/device.c \
src/core/device.h \
src/core/mount.c \
@ -1178,8 +1176,6 @@ libcore_la_SOURCES = \
src/core/dbus-busname.h \
src/core/dbus-target.c \
src/core/dbus-target.h \
src/core/dbus-snapshot.c \
src/core/dbus-snapshot.h \
src/core/dbus-device.c \
src/core/dbus-device.h \
src/core/dbus-mount.c \

View File

@ -1341,46 +1341,6 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
</variablelist>
</refsect2>
<refsect2>
<title>Snapshot Commands</title>
<variablelist>
<varlistentry>
<term><command>snapshot <optional><replaceable>NAME</replaceable></optional></command></term>
<listitem>
<para>Create a snapshot. If a snapshot name is specified,
the new snapshot will be named after it. If none is
specified, an automatic snapshot name is generated. In
either case, the snapshot name used is printed to standard
output, unless <option>--quiet</option> is specified.
</para>
<para>A snapshot refers to a saved state of the systemd
manager. It is implemented itself as a unit that is
generated dynamically with this command and has dependencies
on all units active at the time. At a later time, the user
may return to this state by using the
<command>isolate</command> command on the snapshot unit.
</para>
<para>Snapshots are only useful for saving and restoring
which units are running or are stopped, they do not
save/restore any other state. Snapshots are dynamic and lost
on reboot.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>delete <replaceable>PATTERN</replaceable>...</command></term>
<listitem>
<para>Remove a snapshot previously created with
<command>snapshot</command>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Environment Commands</title>

View File

@ -1,83 +0,0 @@
<?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">
<!--
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd 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.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
-->
<refentry id="systemd.snapshot">
<refentryinfo>
<title>systemd.snapshot</title>
<productname>systemd</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Lennart</firstname>
<surname>Poettering</surname>
<email>lennart@poettering.net</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>systemd.snapshot</refentrytitle>
<manvolnum>5</manvolnum>
</refmeta>
<refnamediv>
<refname>systemd.snapshot</refname>
<refpurpose>Snapshot unit configuration</refpurpose>
</refnamediv>
<refsynopsisdiv>
<para><filename><replaceable>snapshot</replaceable>.snapshot</filename></para>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>Snapshot units are not configured via unit configuration
files. Nonetheless they are named similar to filenames. A unit
whose name ends in <literal>.snapshot</literal> refers to a
dynamic snapshot of the systemd runtime state.</para>
<para>Snapshots are not configured on disk but created dynamically
via <command>systemctl snapshot</command> (see
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
for details) or an equivalent command. When created, they will
automatically get dependencies on the currently activated units.
They act as saved runtime state of the systemd manager. Later on,
the user may choose to return to the saved state via
<command>systemctl isolate</command>. They are useful to roll back
to a defined state after temporarily starting/stopping services or
similar.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>

View File

@ -60,7 +60,6 @@
<filename><replaceable>target</replaceable>.target</filename>,
<filename><replaceable>path</replaceable>.path</filename>,
<filename><replaceable>timer</replaceable>.timer</filename>,
<filename><replaceable>snapshot</replaceable>.snapshot</filename>,
<filename><replaceable>slice</replaceable>.slice</filename>,
<filename><replaceable>scope</replaceable>.scope</filename></para>
@ -90,7 +89,7 @@
swap file or partition, a start-up target, a watched file system
path, a timer controlled and supervised by
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
a temporary system state snapshot, a resource management slice or
a resource management slice or
a group of externally created processes. The syntax is inspired by
<ulink
url="http://standards.freedesktop.org/desktop-entry-spec/latest/">XDG
@ -115,8 +114,7 @@
<citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.path</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.snapshot</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
<citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
<citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
@ -651,16 +649,6 @@
<option>false</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>IgnoreOnSnapshot=</varname></term>
<listitem><para>Takes a boolean argument. If
<option>true</option>, this unit will not be included in
snapshots. Defaults to <option>true</option> for device and
snapshot units, <option>false</option> for the
others.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>StopWhenUnneeded=</varname></term>
@ -1431,7 +1419,6 @@ PrivateTmp=yes</programlisting>
<citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.path</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.snapshot</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>,

View File

@ -318,12 +318,6 @@
boot-up. See
<citerefentry><refentrytitle>systemd.automount</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para></listitem>
<listitem><para>Snapshot units can be used to temporarily save
the state of the set of systemd units, which later may be
restored by activating the saved snapshot unit. For more
information, see
<citerefentry><refentrytitle>systemd.snapshot</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para></listitem>
<listitem><para>Timer units are useful for triggering activation
of other units based on timers. You may find details in
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para></listitem>

View File

@ -6,7 +6,6 @@ src/core/dbus-mount.c
src/core/dbus-path.c
src/core/dbus-service.c
src/core/dbus-slice.c
src/core/dbus-snapshot.c
src/core/dbus-socket.c
src/core/dbus-swap.c
src/core/dbus-target.c

View File

@ -174,14 +174,12 @@ _systemctl () {
[TARGET_AND_UNITS]='add-wants add-requires'
[MASKED_UNITS]='unmask'
[JOBS]='cancel'
[SNAPSHOTS]='delete'
[ENVS]='set-environment unset-environment'
[STANDALONE]='daemon-reexec daemon-reload default
emergency exit halt hibernate hybrid-sleep kexec list-jobs
list-sockets list-timers list-units list-unit-files poweroff
reboot rescue show-environment suspend get-default
is-system-running'
[NAME]='snapshot'
[FILE]='link switch-root'
[TARGETS]='set-default'
)
@ -259,16 +257,12 @@ _systemctl () {
fi
compopt -o filenames
elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
comps=''
elif __contains_word "$verb" ${VERBS[JOBS]}; then
comps=$( __systemctl $mode list-jobs | { while read -r a b; do echo " $a"; done; } )
elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
comps=$( __systemctl $mode list-units --type snapshot --full --all \
| { while read -r a b; do echo " $a"; done; } )
elif __contains_word "$verb" ${VERBS[ENVS]}; then
comps=$( __systemctl $mode show-environment \
| while read -r line; do echo " ${line%%=*}=";done )

View File

@ -5,5 +5,5 @@ _sd_unit_files() {
files=( '*:files:->files' )
_description files expl 'unit file'
_files "$expl[@]" -g '*.(automount|busname|device|mount|path|service|snapshot|socket|swap|target|timer)'
_files "$expl[@]" -g '*.(automount|busname|device|mount|path|service|socket|swap|target|timer)'
}

View File

@ -43,8 +43,6 @@
"is-enabled:Check whether unit files are enabled"
"list-jobs:List jobs"
"cancel:Cancel all, one, or more jobs"
"snapshot:Create a snapshot"
"delete:Remove one or more snapshots"
"show-environment:Dump environment"
"set-environment:Set one or more environment variables"
"unset-environment:Unset one or more environment variables"
@ -268,14 +266,6 @@ done
_message "no jobs found"
}
# Completion functions for SNAPSHOTS
(( $+functions[_systemctl_delete] )) || _systemctl_delete()
{
_wanted systemd-snapshots expl snapshot \
compadd "$@" - ${${(f)"$(__systemctl list-units --type snapshot --all)"}%% *} ||
_message "no snapshots found"
}
# Completion functions for TARGETS
(( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
{
@ -310,7 +300,6 @@ done
# [STANDALONE]='daemon-reexec daemon-reload default
# emergency exit halt kexec list-jobs list-units
# list-unit-files poweroff reboot rescue show-environment'
# [NAME]='snapshot'
_systemctl_caching_policy()
{

View File

@ -597,7 +597,6 @@ const char* unit_dbus_interface_from_type(UnitType t) {
[UNIT_SOCKET] = "org.freedesktop.systemd1.Socket",
[UNIT_BUSNAME] = "org.freedesktop.systemd1.BusName",
[UNIT_TARGET] = "org.freedesktop.systemd1.Target",
[UNIT_SNAPSHOT] = "org.freedesktop.systemd1.Snapshot",
[UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
[UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
[UNIT_AUTOMOUNT] = "org.freedesktop.systemd1.Automount",
@ -819,7 +818,6 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
[UNIT_SOCKET] = "socket",
[UNIT_BUSNAME] = "busname",
[UNIT_TARGET] = "target",
[UNIT_SNAPSHOT] = "snapshot",
[UNIT_DEVICE] = "device",
[UNIT_MOUNT] = "mount",
[UNIT_AUTOMOUNT] = "automount",
@ -950,13 +948,6 @@ static const char* const slice_state_table[_SLICE_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(slice_state, SliceState);
static const char* const snapshot_state_table[_SNAPSHOT_STATE_MAX] = {
[SNAPSHOT_DEAD] = "dead",
[SNAPSHOT_ACTIVE] = "active"
};
DEFINE_STRING_TABLE_LOOKUP(snapshot_state, SnapshotState);
static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = "dead",
[SOCKET_START_PRE] = "start-pre",

View File

@ -32,7 +32,6 @@ typedef enum UnitType {
UNIT_SOCKET,
UNIT_BUSNAME,
UNIT_TARGET,
UNIT_SNAPSHOT,
UNIT_DEVICE,
UNIT_MOUNT,
UNIT_AUTOMOUNT,
@ -165,13 +164,6 @@ typedef enum SliceState {
_SLICE_STATE_INVALID = -1
} SliceState;
typedef enum SnapshotState {
SNAPSHOT_DEAD,
SNAPSHOT_ACTIVE,
_SNAPSHOT_STATE_MAX,
_SNAPSHOT_STATE_INVALID = -1
} SnapshotState;
typedef enum SocketState {
SOCKET_DEAD,
SOCKET_START_PRE,
@ -366,9 +358,6 @@ ServiceState service_state_from_string(const char *s) _pure_;
const char* slice_state_to_string(SliceState i) _const_;
SliceState slice_state_from_string(const char *s) _pure_;
const char* snapshot_state_to_string(SnapshotState i) _const_;
SnapshotState snapshot_state_from_string(const char *s) _pure_;
const char* socket_state_to_string(SocketState i) _const_;
SocketState socket_state_from_string(const char *s) _pure_;

View File

@ -31,7 +31,6 @@
#include "dbus-execute.h"
#include "dbus-job.h"
#include "dbus-manager.h"
#include "dbus-snapshot.h"
#include "dbus-unit.h"
#include "dbus.h"
#include "env-util.h"
@ -1101,66 +1100,8 @@ static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *er
return sd_bus_reply_method_return(message, "s", dump);
}
static int method_create_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
const char *name;
int cleanup;
Snapshot *s = NULL;
int r;
assert(message);
assert(m);
r = mac_selinux_access_check(message, "start", error);
if (r < 0)
return r;
r = sd_bus_message_read(message, "sb", &name, &cleanup);
if (r < 0)
return r;
if (isempty(name))
name = NULL;
r = bus_verify_manage_units_async(m, message, error);
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
r = snapshot_create(m, name, cleanup, error, &s);
if (r < 0)
return r;
path = unit_dbus_path(UNIT(s));
if (!path)
return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
static int method_remove_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Unit *u;
int r;
assert(message);
assert(m);
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
return r;
u = manager_get_unit(m, name);
if (!u)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
if (u->type != UNIT_SNAPSHOT)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
return bus_snapshot_method_remove(message, u, error);
static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed.");
}
static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@ -2042,8 +1983,8 @@ const sd_bus_vtable bus_manager_vtable[] = {
SD_BUS_METHOD("Subscribe", NULL, NULL, method_subscribe, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Unsubscribe", NULL, NULL, method_unsubscribe, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Dump", NULL, "s", method_dump, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_create_snapshot, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_remove_snapshot, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("CreateSnapshot", "sb", "o", method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("RemoveSnapshot", "s", NULL, method_refuse_snapshot, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Reload", NULL, NULL, method_reload, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Reexecute", NULL, NULL, method_reexecute, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Exit", NULL, NULL, method_exit, 0),

View File

@ -1,55 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd 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.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "selinux-access.h"
#include "unit.h"
#include "dbus.h"
#include "snapshot.h"
#include "dbus-snapshot.h"
int bus_snapshot_method_remove(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Snapshot *s = userdata;
int r;
assert(message);
assert(s);
r = mac_selinux_unit_access_check(UNIT(s), message, "stop", error);
if (r < 0)
return r;
r = bus_verify_manage_units_async(UNIT(s)->manager, message, error);
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
snapshot_remove(s);
return sd_bus_reply_method_return(message, NULL);
}
const sd_bus_vtable bus_snapshot_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Cleanup", "b", bus_property_get_bool, offsetof(Snapshot, cleanup), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD("Remove", NULL, NULL, bus_snapshot_method_remove, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};

View File

@ -1,28 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#pragma once
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd 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.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-bus.h"
extern const sd_bus_vtable bus_snapshot_vtable[];
int bus_snapshot_method_remove(sd_bus_message *message, void *userdata, sd_bus_error *error);

View File

@ -671,7 +671,6 @@ const sd_bus_vtable bus_unit_vtable[] = {
SD_BUS_PROPERTY("DefaultDependencies", "b", bus_property_get_bool, offsetof(Unit, default_dependencies), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("OnFailureJobMode", "s", property_get_job_mode, offsetof(Unit, on_failure_job_mode), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("IgnoreOnIsolate", "b", bus_property_get_bool, offsetof(Unit, ignore_on_isolate), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("IgnoreOnSnapshot", "b", bus_property_get_bool, offsetof(Unit, ignore_on_snapshot), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("NeedDaemonReload", "b", property_get_need_daemon_reload, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("JobTimeoutUSec", "t", bus_property_get_usec, offsetof(Unit, job_timeout), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("JobTimeoutAction", "s", property_get_failure_action, offsetof(Unit, job_timeout_action), SD_BUS_VTABLE_PROPERTY_CONST),

View File

@ -117,7 +117,6 @@ static void device_init(Unit *u) {
u->job_timeout = u->manager->default_timeout_start_usec;
u->ignore_on_isolate = true;
u->ignore_on_snapshot = true;
}
static void device_done(Unit *u) {

View File

@ -158,7 +158,7 @@ Unit.DefaultDependencies, config_parse_bool, 0,
Unit.OnFailureJobMode, config_parse_job_mode, 0, offsetof(Unit, on_failure_job_mode)
Unit.OnFailureIsolate, config_parse_job_mode_isolate, 0, offsetof(Unit, on_failure_job_mode)
Unit.IgnoreOnIsolate, config_parse_bool, 0, offsetof(Unit, ignore_on_isolate)
Unit.IgnoreOnSnapshot, config_parse_bool, 0, offsetof(Unit, ignore_on_snapshot)
Unit.IgnoreOnSnapshot, config_parse_warn_compat, DISABLED_LEGACY, 0
Unit.JobTimeoutSec, config_parse_sec, 0, offsetof(Unit, job_timeout)
Unit.JobTimeoutAction, config_parse_failure_action, 0, offsetof(Unit, job_timeout_action)
Unit.JobTimeoutRebootArgument, config_parse_string, 0, offsetof(Unit, job_timeout_reboot_arg)

View File

@ -141,8 +141,6 @@ struct Manager {
sd_event_source *jobs_in_progress_event_source;
unsigned n_snapshots;
LookupPaths lookup_paths;
Set *unit_path_cache;

View File

@ -54,7 +54,6 @@ static void scope_init(Unit *u) {
s->timeout_stop_usec = u->manager->default_timeout_stop_usec;
UNIT(s)->ignore_on_isolate = true;
UNIT(s)->ignore_on_snapshot = true;
}
static void scope_done(Unit *u) {

View File

@ -2365,14 +2365,6 @@ static bool service_check_gc(Unit *u) {
return false;
}
_pure_ static bool service_check_snapshot(Unit *u) {
Service *s = SERVICE(u);
assert(s);
return s->socket_fd < 0;
}
static int service_retry_pid_file(Service *s) {
int r;
@ -3294,7 +3286,6 @@ const UnitVTable service_vtable = {
.sub_state_to_string = service_sub_state_to_string,
.check_gc = service_check_gc,
.check_snapshot = service_check_snapshot,
.sigchld_event = service_sigchld_event,

View File

@ -1,303 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd 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.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "dbus-snapshot.h"
#include "parse-util.h"
#include "parse-util.h"
#include "snapshot.h"
#include "string-util.h"
#include "unit-name.h"
#include "unit.h"
static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = {
[SNAPSHOT_DEAD] = UNIT_INACTIVE,
[SNAPSHOT_ACTIVE] = UNIT_ACTIVE
};
static void snapshot_init(Unit *u) {
Snapshot *s = SNAPSHOT(u);
assert(s);
assert(UNIT(s)->load_state == UNIT_STUB);
UNIT(s)->ignore_on_isolate = true;
UNIT(s)->ignore_on_snapshot = true;
UNIT(s)->allow_isolate = true;
}
static void snapshot_set_state(Snapshot *s, SnapshotState state) {
SnapshotState old_state;
assert(s);
old_state = s->state;
s->state = state;
if (state != old_state)
log_unit_debug(UNIT(s), "Changed %s -> %s", snapshot_state_to_string(old_state), snapshot_state_to_string(state));
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
}
static int snapshot_load(Unit *u) {
Snapshot *s = SNAPSHOT(u);
assert(u);
assert(u->load_state == UNIT_STUB);
/* Make sure that only snapshots created via snapshot_create()
* can be loaded */
if (!u->transient && UNIT(s)->manager->n_reloading <= 0)
return -ENOENT;
u->load_state = UNIT_LOADED;
return 0;
}
static int snapshot_coldplug(Unit *u) {
Snapshot *s = SNAPSHOT(u);
assert(s);
assert(s->state == SNAPSHOT_DEAD);
if (s->deserialized_state != s->state)
snapshot_set_state(s, s->deserialized_state);
return 0;
}
static void snapshot_dump(Unit *u, FILE *f, const char *prefix) {
Snapshot *s = SNAPSHOT(u);
assert(s);
assert(f);
fprintf(f,
"%sSnapshot State: %s\n"
"%sClean Up: %s\n",
prefix, snapshot_state_to_string(s->state),
prefix, yes_no(s->cleanup));
}
static int snapshot_start(Unit *u) {
Snapshot *s = SNAPSHOT(u);
assert(s);
assert(s->state == SNAPSHOT_DEAD);
snapshot_set_state(s, SNAPSHOT_ACTIVE);
if (s->cleanup)
unit_add_to_cleanup_queue(u);
return 1;
}
static int snapshot_stop(Unit *u) {
Snapshot *s = SNAPSHOT(u);
assert(s);
assert(s->state == SNAPSHOT_ACTIVE);
snapshot_set_state(s, SNAPSHOT_DEAD);
return 1;
}
static int snapshot_serialize(Unit *u, FILE *f, FDSet *fds) {
Snapshot *s = SNAPSHOT(u);
Unit *other;
Iterator i;
assert(s);
assert(f);
assert(fds);
unit_serialize_item(u, f, "state", snapshot_state_to_string(s->state));
unit_serialize_item(u, f, "cleanup", yes_no(s->cleanup));
SET_FOREACH(other, u->dependencies[UNIT_WANTS], i)
unit_serialize_item(u, f, "wants", other->id);
return 0;
}
static int snapshot_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
Snapshot *s = SNAPSHOT(u);
int r;
assert(u);
assert(key);
assert(value);
assert(fds);
if (streq(key, "state")) {
SnapshotState state;
state = snapshot_state_from_string(value);
if (state < 0)
log_unit_debug(u, "Failed to parse state value: %s", value);
else
s->deserialized_state = state;
} else if (streq(key, "cleanup")) {
r = parse_boolean(value);
if (r < 0)
log_unit_debug(u, "Failed to parse cleanup value: %s", value);
else
s->cleanup = r;
} else if (streq(key, "wants")) {
r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, value, NULL, true);
if (r < 0)
return r;
} else
log_unit_debug(u, "Unknown serialization key: %s", key);
return 0;
}
_pure_ static UnitActiveState snapshot_active_state(Unit *u) {
assert(u);
return state_translation_table[SNAPSHOT(u)->state];
}
_pure_ static const char *snapshot_sub_state_to_string(Unit *u) {
assert(u);
return snapshot_state_to_string(SNAPSHOT(u)->state);
}
int snapshot_create(Manager *m, const char *name, bool cleanup, sd_bus_error *e, Snapshot **_s) {
_cleanup_free_ char *n = NULL;
Unit *other, *u = NULL;
Iterator i;
int r;
const char *k;
assert(m);
assert(_s);
if (name) {
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Unit name %s is not valid.", name);
if (!endswith(name, ".snapshot"))
return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Unit name %s lacks snapshot suffix.", name);
if (manager_get_unit(m, name))
return sd_bus_error_setf(e, BUS_ERROR_UNIT_EXISTS, "Snapshot %s exists already.", name);
} else {
for (;;) {
if (asprintf(&n, "snapshot-%u.snapshot", ++ m->n_snapshots) < 0)
return -ENOMEM;
if (!manager_get_unit(m, n)) {
name = n;
break;
}
n = mfree(n);
}
}
r = manager_load_unit_prepare(m, name, NULL, e, &u);
if (r < 0)
goto fail;
u->transient = true;
manager_dispatch_load_queue(m);
assert(u->load_state == UNIT_LOADED);
HASHMAP_FOREACH_KEY(other, k, m->units, i) {
if (other->ignore_on_snapshot ||
other->transient)
continue;
if (k != other->id)
continue;
if (UNIT_VTABLE(other)->check_snapshot)
if (!UNIT_VTABLE(other)->check_snapshot(other))
continue;
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
continue;
r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_WANTS, other, true);
if (r < 0)
goto fail;
}
SNAPSHOT(u)->cleanup = cleanup;
*_s = SNAPSHOT(u);
log_unit_info(u, "Created snapshot.");
return 0;
fail:
if (u)
unit_add_to_cleanup_queue(u);
return r;
}
void snapshot_remove(Snapshot *s) {
assert(s);
log_unit_info(UNIT(s), "Removing snapshot.");
unit_add_to_cleanup_queue(UNIT(s));
}
const UnitVTable snapshot_vtable = {
.object_size = sizeof(Snapshot),
.no_alias = true,
.no_instances = true,
.no_gc = true,
.init = snapshot_init,
.load = snapshot_load,
.coldplug = snapshot_coldplug,
.dump = snapshot_dump,
.start = snapshot_start,
.stop = snapshot_stop,
.serialize = snapshot_serialize,
.deserialize_item = snapshot_deserialize_item,
.active_state = snapshot_active_state,
.sub_state_to_string = snapshot_sub_state_to_string,
.bus_vtable = bus_snapshot_vtable
};

View File

@ -1,39 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#pragma once
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd 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.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
typedef struct Snapshot Snapshot;
#include "unit.h"
struct Snapshot {
Unit meta;
SnapshotState state, deserialized_state;
bool cleanup;
};
extern const UnitVTable snapshot_vtable;
int snapshot_create(Manager *m, const char *name, bool cleanup, sd_bus_error *e, Snapshot **s);
void snapshot_remove(Snapshot *s);

View File

@ -63,7 +63,6 @@ const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
[UNIT_SOCKET] = &socket_vtable,
[UNIT_BUSNAME] = &busname_vtable,
[UNIT_TARGET] = &target_vtable,
[UNIT_SNAPSHOT] = &snapshot_vtable,
[UNIT_DEVICE] = &device_vtable,
[UNIT_MOUNT] = &mount_vtable,
[UNIT_AUTOMOUNT] = &automount_vtable,
@ -998,15 +997,13 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
"%s\tRefuseManualStop: %s\n"
"%s\tDefaultDependencies: %s\n"
"%s\tOnFailureJobMode: %s\n"
"%s\tIgnoreOnIsolate: %s\n"
"%s\tIgnoreOnSnapshot: %s\n",
"%s\tIgnoreOnIsolate: %s\n",
prefix, yes_no(u->stop_when_unneeded),
prefix, yes_no(u->refuse_manual_start),
prefix, yes_no(u->refuse_manual_stop),
prefix, yes_no(u->default_dependencies),
prefix, job_mode_to_string(u->on_failure_job_mode),
prefix, yes_no(u->ignore_on_isolate),
prefix, yes_no(u->ignore_on_snapshot));
prefix, yes_no(u->ignore_on_isolate));
if (UNIT_VTABLE(u)->dump)
UNIT_VTABLE(u)->dump(u, f, prefix2);

View File

@ -203,9 +203,6 @@ struct Unit {
/* Ignore this unit when isolating */
bool ignore_on_isolate;
/* Ignore this unit when snapshotting */
bool ignore_on_snapshot;
/* Did the last condition check succeed? */
bool condition_result;
bool assert_result;
@ -248,7 +245,6 @@ typedef enum UnitSetPropertiesMode {
#include "socket.h"
#include "busname.h"
#include "target.h"
#include "snapshot.h"
#include "device.h"
#include "automount.h"
#include "swap.h"
@ -343,9 +339,6 @@ struct UnitVTable {
* shall release its runtime resources */
void (*release_resources)(Unit *u);
/* Return true when this unit is suitable for snapshotting */
bool (*check_snapshot)(Unit *u);
/* Invoked on every child that died */
void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
@ -443,7 +436,6 @@ DEFINE_CAST(SERVICE, Service);
DEFINE_CAST(SOCKET, Socket);
DEFINE_CAST(BUSNAME, BusName);
DEFINE_CAST(TARGET, Target);
DEFINE_CAST(SNAPSHOT, Snapshot);
DEFINE_CAST(DEVICE, Device);
DEFINE_CAST(MOUNT, Mount);
DEFINE_CAST(AUTOMOUNT, Automount);

View File

@ -4905,102 +4905,6 @@ static int set_property(int argc, char *argv[], void *userdata) {
return 0;
}
static int snapshot(int argc, char *argv[], void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_free_ char *n = NULL, *id = NULL;
const char *path;
sd_bus *bus;
int r;
polkit_agent_open_if_enabled();
if (argc > 1) {
r = unit_name_mangle_with_suffix(argv[1], UNIT_NAME_NOGLOB, ".snapshot", &n);
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
} else {
n = strdup("");
if (!n)
return log_oom();
}
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"CreateSnapshot",
&error,
&reply,
"sb", n, false);
if (r < 0)
return log_error_errno(r, "Failed to create snapshot: %s", bus_error_message(&error, r));
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
return bus_log_parse_error(r);
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
"Id",
&error,
&id);
if (r < 0)
return log_error_errno(r, "Failed to get ID of snapshot: %s", bus_error_message(&error, r));
if (!arg_quiet)
puts(id);
return 0;
}
static int delete_snapshot(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
sd_bus *bus;
char **name;
int r;
polkit_agent_open_if_enabled();
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;
r = expand_names(bus, strv_skip(argv, 1), ".snapshot", &names);
if (r < 0)
return log_error_errno(r, "Failed to expand names: %m");
STRV_FOREACH(name, names) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
int q;
q = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"RemoveSnapshot",
&error,
NULL,
"s", *name);
if (q < 0) {
log_error_errno(q, "Failed to remove snapshot %s: %s", *name, bus_error_message(&error, q));
if (r == 0)
r = q;
}
}
return r;
}
static int daemon_reload(int argc, char *argv[], void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
const char *method;
@ -6381,9 +6285,6 @@ static void systemctl_help(void) {
"Job Commands:\n"
" list-jobs [PATTERN...] List jobs\n"
" cancel [JOB...] Cancel all, one, or more jobs\n\n"
"Snapshot Commands:\n"
" snapshot [NAME] Create a snapshot\n"
" delete NAME... Remove one or more snapshots\n\n"
"Environment Commands:\n"
" show-environment Dump environment\n"
" set-environment NAME=VALUE... Set one or more environment variables\n"
@ -6525,11 +6426,6 @@ static void help_states(void) {
for (i = 0; i < _SLICE_STATE_MAX; i++)
puts(slice_state_to_string(i));
if (!arg_no_legend)
puts("\nAvailable snapshot unit substates:");
for (i = 0; i < _SNAPSHOT_STATE_MAX; i++)
puts(snapshot_state_to_string(i));
if (!arg_no_legend)
puts("\nAvailable socket unit substates:");
for (i = 0; i < _SOCKET_STATE_MAX; i++)
@ -7460,8 +7356,6 @@ static int systemctl_main(int argc, char *argv[]) {
{ "cat", 2, VERB_ANY, 0, cat },
{ "status", VERB_ANY, VERB_ANY, 0, show },
{ "help", VERB_ANY, VERB_ANY, 0, show },
{ "snapshot", VERB_ANY, 2, 0, snapshot },
{ "delete", 2, VERB_ANY, 0, delete_snapshot },
{ "daemon-reload", VERB_ANY, 1, 0, daemon_reload },
{ "daemon-reexec", VERB_ANY, 1, 0, daemon_reload },
{ "show-environment", VERB_ANY, 1, 0, show_environment },

View File

@ -39,7 +39,6 @@
#include "scope.h"
#include "service.h"
#include "slice.h"
#include "snapshot.h"
#include "socket-util.h"
#include "socket.h"
#include "swap.h"
@ -98,7 +97,6 @@ int main(int argc, char **argv) {
test_table(service_state, SERVICE_STATE);
test_table(service_type, SERVICE_TYPE);
test_table(slice_state, SLICE_STATE);
test_table(snapshot_state, SNAPSHOT_STATE);
test_table(socket_address_bind_ipv6_only, SOCKET_ADDRESS_BIND_IPV6_ONLY);
test_table(socket_exec_command, SOCKET_EXEC_COMMAND);
test_table(socket_result, SOCKET_RESULT);