]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/swap.h
Merge pull request #1425 from kaysievers/wip
[thirdparty/systemd.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 #include <libudev.h>
26
27 typedef struct Swap Swap;
28
29 typedef enum SwapExecCommand {
30 SWAP_EXEC_ACTIVATE,
31 SWAP_EXEC_DEACTIVATE,
32 _SWAP_EXEC_COMMAND_MAX,
33 _SWAP_EXEC_COMMAND_INVALID = -1
34 } SwapExecCommand;
35
36 typedef enum SwapResult {
37 SWAP_SUCCESS,
38 SWAP_FAILURE_RESOURCES,
39 SWAP_FAILURE_TIMEOUT,
40 SWAP_FAILURE_EXIT_CODE,
41 SWAP_FAILURE_SIGNAL,
42 SWAP_FAILURE_CORE_DUMP,
43 _SWAP_RESULT_MAX,
44 _SWAP_RESULT_INVALID = -1
45 } SwapResult;
46
47 typedef struct SwapParameters {
48 char *what;
49 char *options;
50 int priority;
51 } SwapParameters;
52
53 struct Swap {
54 Unit meta;
55
56 char *what;
57
58 /* If the device has already shown up, this is the device
59 * node, which might be different from what, due to
60 * symlinks */
61 char *devnode;
62
63 SwapParameters parameters_proc_swaps;
64 SwapParameters parameters_fragment;
65
66 bool from_proc_swaps:1;
67 bool from_fragment:1;
68
69 /* Used while looking for swaps that vanished or got added
70 * from/to /proc/swaps */
71 bool is_active:1;
72 bool just_activated:1;
73
74 bool reset_cpu_usage:1;
75
76 SwapResult result;
77
78 usec_t timeout_usec;
79
80 ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
81 ExecContext exec_context;
82 KillContext kill_context;
83 CGroupContext cgroup_context;
84
85 ExecRuntime *exec_runtime;
86
87 SwapState state, deserialized_state;
88
89 ExecCommand* control_command;
90 SwapExecCommand control_command_id;
91 pid_t control_pid;
92
93 sd_event_source *timer_event_source;
94
95 /* In order to be able to distinguish dependencies on
96 different device nodes we might end up creating multiple
97 devices for the same swap. We chain them up here. */
98
99 LIST_FIELDS(struct Swap, same_devnode);
100 };
101
102 extern const UnitVTable swap_vtable;
103
104 int swap_process_device_new(Manager *m, struct udev_device *dev);
105 int swap_process_device_remove(Manager *m, struct udev_device *dev);
106
107 const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
108 SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
109
110 const char* swap_result_to_string(SwapResult i) _const_;
111 SwapResult swap_result_from_string(const char *s) _pure_;