chiark / gitweb /
use #pragma once instead of foo*foo #define guards
[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,
32         SWAP_ACTIVE,
33         SWAP_DEACTIVATING,
34         SWAP_ACTIVATING_SIGTERM,
35         SWAP_ACTIVATING_SIGKILL,
36         SWAP_DEACTIVATING_SIGTERM,
37         SWAP_DEACTIVATING_SIGKILL,
38         SWAP_FAILED,
39         _SWAP_STATE_MAX,
40         _SWAP_STATE_INVALID = -1
41 } SwapState;
42
43 typedef enum SwapExecCommand {
44         SWAP_EXEC_ACTIVATE,
45         SWAP_EXEC_DEACTIVATE,
46         _SWAP_EXEC_COMMAND_MAX,
47         _SWAP_EXEC_COMMAND_INVALID = -1
48 } SwapExecCommand;
49
50 typedef struct SwapParameters {
51         char *what;
52         int priority;
53         bool noauto:1;
54         bool nofail:1;
55 } SwapParameters;
56
57 typedef enum SwapResult {
58         SWAP_SUCCESS,
59         SWAP_FAILURE_RESOURCES,
60         SWAP_FAILURE_TIMEOUT,
61         SWAP_FAILURE_EXIT_CODE,
62         SWAP_FAILURE_SIGNAL,
63         SWAP_FAILURE_CORE_DUMP,
64         _SWAP_RESULT_MAX,
65         _SWAP_RESULT_INVALID = -1
66 } SwapResult;
67
68 struct Swap {
69         Unit meta;
70
71         char *what;
72
73         SwapParameters parameters_proc_swaps;
74         SwapParameters parameters_fragment;
75
76         bool from_proc_swaps:1;
77         bool from_fragment:1;
78
79         /* Used while looking for swaps that vanished or got added
80          * from/to /proc/swaps */
81         bool is_active:1;
82         bool just_activated:1;
83
84         SwapResult result;
85
86         usec_t timeout_usec;
87
88         ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
89         ExecContext exec_context;
90
91         SwapState state, deserialized_state;
92
93         ExecCommand* control_command;
94         SwapExecCommand control_command_id;
95         pid_t control_pid;
96
97         Watch timer_watch;
98
99         /* In order to be able to distinguish dependencies on
100         different device nodes we might end up creating multiple
101         devices for the same swap. We chain them up here. */
102
103         LIST_FIELDS(struct Swap, same_proc_swaps);
104 };
105
106 extern const UnitVTable swap_vtable;
107
108 int swap_add_one_mount_link(Swap *s, Mount *m);
109
110 int swap_dispatch_reload(Manager *m);
111 int swap_fd_event(Manager *m, int events);
112
113 const char* swap_state_to_string(SwapState i);
114 SwapState swap_state_from_string(const char *s);
115
116 const char* swap_exec_command_to_string(SwapExecCommand i);
117 SwapExecCommand swap_exec_command_from_string(const char *s);
118
119 const char* swap_result_to_string(SwapResult i);
120 SwapResult swap_result_from_string(const char *s);