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