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