chiark / gitweb /
swap: split state machine state ACTIVATING into two
[elogind.git] / src / core / swap.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9   Copyright 2010 Maarten Lankhorst
10
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.
15
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.
20
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/>.
23 ***/
24
25 typedef struct Swap Swap;
26
27 #include "unit.h"
28
29 typedef enum SwapState {
30         SWAP_DEAD,
31         SWAP_ACTIVATING,               /* /sbin/swapon is running, but the swap not yet enabled. */
32         SWAP_ACTIVATING_DONE,          /* /sbin/swapon is running, and the swap is done. */
33         SWAP_ACTIVE,
34         SWAP_DEACTIVATING,
35         SWAP_ACTIVATING_SIGTERM,
36         SWAP_ACTIVATING_SIGKILL,
37         SWAP_DEACTIVATING_SIGTERM,
38         SWAP_DEACTIVATING_SIGKILL,
39         SWAP_FAILED,
40         _SWAP_STATE_MAX,
41         _SWAP_STATE_INVALID = -1
42 } SwapState;
43
44 typedef enum SwapExecCommand {
45         SWAP_EXEC_ACTIVATE,
46         SWAP_EXEC_DEACTIVATE,
47         _SWAP_EXEC_COMMAND_MAX,
48         _SWAP_EXEC_COMMAND_INVALID = -1
49 } SwapExecCommand;
50
51 typedef enum SwapResult {
52         SWAP_SUCCESS,
53         SWAP_FAILURE_RESOURCES,
54         SWAP_FAILURE_TIMEOUT,
55         SWAP_FAILURE_EXIT_CODE,
56         SWAP_FAILURE_SIGNAL,
57         SWAP_FAILURE_CORE_DUMP,
58         _SWAP_RESULT_MAX,
59         _SWAP_RESULT_INVALID = -1
60 } SwapResult;
61
62 typedef struct SwapParameters {
63         char *what;
64         int priority;
65         bool noauto:1;
66         bool nofail:1;
67 } SwapParameters;
68
69 struct Swap {
70         Unit meta;
71
72         char *what;
73
74         SwapParameters parameters_proc_swaps;
75         SwapParameters parameters_fragment;
76
77         bool from_proc_swaps:1;
78         bool from_fragment:1;
79
80         /* Used while looking for swaps that vanished or got added
81          * from/to /proc/swaps */
82         bool is_active:1;
83         bool just_activated:1;
84
85         SwapResult result;
86
87         usec_t timeout_usec;
88
89         ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
90         ExecContext exec_context;
91         KillContext kill_context;
92         CGroupContext cgroup_context;
93
94         SwapState state, deserialized_state;
95
96         ExecCommand* control_command;
97         SwapExecCommand control_command_id;
98         pid_t control_pid;
99
100         sd_event_source *timer_event_source;
101
102         /* In order to be able to distinguish dependencies on
103         different device nodes we might end up creating multiple
104         devices for the same swap. We chain them up here. */
105
106         LIST_FIELDS(struct Swap, same_proc_swaps);
107 };
108
109 extern const UnitVTable swap_vtable;
110
111 const char* swap_state_to_string(SwapState i) _const_;
112 SwapState swap_state_from_string(const char *s) _pure_;
113
114 const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
115 SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
116
117 const char* swap_result_to_string(SwapResult i) _const_;
118 SwapResult swap_result_from_string(const char *s) _pure_;