1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
9 Copyright 2010 Maarten Lankhorst
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
14 (at your option) any later version.
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 typedef struct Swap Swap;
30 typedef enum SwapState {
32 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
33 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
36 SWAP_ACTIVATING_SIGTERM,
37 SWAP_ACTIVATING_SIGKILL,
38 SWAP_DEACTIVATING_SIGTERM,
39 SWAP_DEACTIVATING_SIGKILL,
42 _SWAP_STATE_INVALID = -1
45 typedef enum SwapExecCommand {
48 _SWAP_EXEC_COMMAND_MAX,
49 _SWAP_EXEC_COMMAND_INVALID = -1
52 typedef enum SwapResult {
54 SWAP_FAILURE_RESOURCES,
56 SWAP_FAILURE_EXIT_CODE,
58 SWAP_FAILURE_CORE_DUMP,
60 _SWAP_RESULT_INVALID = -1
63 typedef struct SwapParameters {
74 /* If the device has already shown up, this is the device
75 * node, which might be different from what, due to
79 SwapParameters parameters_proc_swaps;
80 SwapParameters parameters_fragment;
82 bool from_proc_swaps:1;
85 /* Used while looking for swaps that vanished or got added
86 * from/to /proc/swaps */
88 bool just_activated:1;
94 ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
95 ExecContext exec_context;
96 KillContext kill_context;
97 CGroupContext cgroup_context;
99 ExecRuntime *exec_runtime;
101 SwapState state, deserialized_state;
103 ExecCommand* control_command;
104 SwapExecCommand control_command_id;
107 sd_event_source *timer_event_source;
109 /* In order to be able to distinguish dependencies on
110 different device nodes we might end up creating multiple
111 devices for the same swap. We chain them up here. */
113 LIST_FIELDS(struct Swap, same_devnode);
116 extern const UnitVTable swap_vtable;
118 int swap_process_device_new(Manager *m, struct udev_device *dev);
119 int swap_process_device_remove(Manager *m, struct udev_device *dev);
121 const char* swap_state_to_string(SwapState i) _const_;
122 SwapState swap_state_from_string(const char *s) _pure_;
124 const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
125 SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
127 const char* swap_result_to_string(SwapResult i) _const_;
128 SwapResult swap_result_from_string(const char *s) _pure_;