]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/swap.h
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / core / swap.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2010 Maarten Lankhorst
6 ***/
7
8 #include "libudev.h"
9 #include "unit.h"
10
11 typedef struct Swap Swap;
12
13 typedef enum SwapExecCommand {
14 SWAP_EXEC_ACTIVATE,
15 SWAP_EXEC_DEACTIVATE,
16 _SWAP_EXEC_COMMAND_MAX,
17 _SWAP_EXEC_COMMAND_INVALID = -1
18 } SwapExecCommand;
19
20 typedef enum SwapResult {
21 SWAP_SUCCESS,
22 SWAP_FAILURE_RESOURCES,
23 SWAP_FAILURE_TIMEOUT,
24 SWAP_FAILURE_EXIT_CODE,
25 SWAP_FAILURE_SIGNAL,
26 SWAP_FAILURE_CORE_DUMP,
27 SWAP_FAILURE_START_LIMIT_HIT,
28 _SWAP_RESULT_MAX,
29 _SWAP_RESULT_INVALID = -1
30 } SwapResult;
31
32 typedef struct SwapParameters {
33 char *what;
34 char *options;
35 int priority;
36 } SwapParameters;
37
38 struct Swap {
39 Unit meta;
40
41 char *what;
42
43 /* If the device has already shown up, this is the device
44 * node, which might be different from what, due to
45 * symlinks */
46 char *devnode;
47
48 SwapParameters parameters_proc_swaps;
49 SwapParameters parameters_fragment;
50
51 bool from_proc_swaps:1;
52 bool from_fragment:1;
53
54 /* Used while looking for swaps that vanished or got added
55 * from/to /proc/swaps */
56 bool is_active:1;
57 bool just_activated:1;
58
59 SwapResult result;
60
61 usec_t timeout_usec;
62
63 ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
64 ExecContext exec_context;
65 KillContext kill_context;
66 CGroupContext cgroup_context;
67
68 ExecRuntime *exec_runtime;
69 DynamicCreds dynamic_creds;
70
71 SwapState state, deserialized_state;
72
73 ExecCommand* control_command;
74 SwapExecCommand control_command_id;
75 pid_t control_pid;
76
77 sd_event_source *timer_event_source;
78
79 /* In order to be able to distinguish dependencies on
80 different device nodes we might end up creating multiple
81 devices for the same swap. We chain them up here. */
82
83 LIST_FIELDS(struct Swap, same_devnode);
84 };
85
86 extern const UnitVTable swap_vtable;
87
88 int swap_process_device_new(Manager *m, struct udev_device *dev);
89 int swap_process_device_remove(Manager *m, struct udev_device *dev);
90
91 const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
92 SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
93
94 const char* swap_result_to_string(SwapResult i) _const_;
95 SwapResult swap_result_from_string(const char *s) _pure_;
96
97 DEFINE_CAST(SWAP, Swap);