]>
Commit | Line | Data |
---|---|---|
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 | #include <libudev.h> | |
26 | ||
27 | typedef struct Swap Swap; | |
28 | ||
29 | #include "unit.h" | |
30 | ||
31 | typedef enum SwapState { | |
32 | SWAP_DEAD, | |
33 | SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */ | |
34 | SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */ | |
35 | SWAP_ACTIVE, | |
36 | SWAP_DEACTIVATING, | |
37 | SWAP_ACTIVATING_SIGTERM, | |
38 | SWAP_ACTIVATING_SIGKILL, | |
39 | SWAP_DEACTIVATING_SIGTERM, | |
40 | SWAP_DEACTIVATING_SIGKILL, | |
41 | SWAP_FAILED, | |
42 | _SWAP_STATE_MAX, | |
43 | _SWAP_STATE_INVALID = -1 | |
44 | } SwapState; | |
45 | ||
46 | typedef enum SwapExecCommand { | |
47 | SWAP_EXEC_ACTIVATE, | |
48 | SWAP_EXEC_DEACTIVATE, | |
49 | _SWAP_EXEC_COMMAND_MAX, | |
50 | _SWAP_EXEC_COMMAND_INVALID = -1 | |
51 | } SwapExecCommand; | |
52 | ||
53 | typedef enum SwapResult { | |
54 | SWAP_SUCCESS, | |
55 | SWAP_FAILURE_RESOURCES, | |
56 | SWAP_FAILURE_TIMEOUT, | |
57 | SWAP_FAILURE_EXIT_CODE, | |
58 | SWAP_FAILURE_SIGNAL, | |
59 | SWAP_FAILURE_CORE_DUMP, | |
60 | _SWAP_RESULT_MAX, | |
61 | _SWAP_RESULT_INVALID = -1 | |
62 | } SwapResult; | |
63 | ||
64 | typedef struct SwapParameters { | |
65 | char *what; | |
66 | char *options; | |
67 | int priority; | |
68 | bool noauto:1; | |
69 | bool nofail:1; | |
70 | } SwapParameters; | |
71 | ||
72 | struct Swap { | |
73 | Unit meta; | |
74 | ||
75 | char *what; | |
76 | ||
77 | /* If the device has already shown up, this is the device | |
78 | * node, which might be different from what, due to | |
79 | * symlinks */ | |
80 | char *devnode; | |
81 | ||
82 | SwapParameters parameters_proc_swaps; | |
83 | SwapParameters parameters_fragment; | |
84 | ||
85 | bool from_proc_swaps:1; | |
86 | bool from_fragment:1; | |
87 | ||
88 | /* Used while looking for swaps that vanished or got added | |
89 | * from/to /proc/swaps */ | |
90 | bool is_active:1; | |
91 | bool just_activated:1; | |
92 | ||
93 | SwapResult result; | |
94 | ||
95 | usec_t timeout_usec; | |
96 | ||
97 | ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX]; | |
98 | ExecContext exec_context; | |
99 | KillContext kill_context; | |
100 | CGroupContext cgroup_context; | |
101 | ||
102 | ExecRuntime *exec_runtime; | |
103 | ||
104 | SwapState state, deserialized_state; | |
105 | ||
106 | ExecCommand* control_command; | |
107 | SwapExecCommand control_command_id; | |
108 | pid_t control_pid; | |
109 | ||
110 | sd_event_source *timer_event_source; | |
111 | ||
112 | /* In order to be able to distinguish dependencies on | |
113 | different device nodes we might end up creating multiple | |
114 | devices for the same swap. We chain them up here. */ | |
115 | ||
116 | LIST_FIELDS(struct Swap, same_devnode); | |
117 | }; | |
118 | ||
119 | extern const UnitVTable swap_vtable; | |
120 | ||
121 | int swap_process_new_device(Manager *m, struct udev_device *dev); | |
122 | int swap_process_removed_device(Manager *m, struct udev_device *dev); | |
123 | ||
124 | const char* swap_state_to_string(SwapState i) _const_; | |
125 | SwapState swap_state_from_string(const char *s) _pure_; | |
126 | ||
127 | const char* swap_exec_command_to_string(SwapExecCommand i) _const_; | |
128 | SwapExecCommand swap_exec_command_from_string(const char *s) _pure_; | |
129 | ||
130 | const char* swap_result_to_string(SwapResult i) _const_; | |
131 | SwapResult swap_result_from_string(const char *s) _pure_; |