]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
07b0b134 ML |
3 | |
4 | /*** | |
96b2fb93 | 5 | Copyright © 2010 Maarten Lankhorst |
07b0b134 ML |
6 | ***/ |
7 | ||
4366e598 | 8 | #include "sd-device.h" |
57b7a260 | 9 | #include "unit.h" |
9670d583 | 10 | |
07b0b134 ML |
11 | typedef struct Swap Swap; |
12 | ||
e04aad61 LP |
13 | typedef enum SwapExecCommand { |
14 | SWAP_EXEC_ACTIVATE, | |
15 | SWAP_EXEC_DEACTIVATE, | |
16 | _SWAP_EXEC_COMMAND_MAX, | |
2d93c20e | 17 | _SWAP_EXEC_COMMAND_INVALID = -EINVAL, |
e04aad61 LP |
18 | } SwapExecCommand; |
19 | ||
e1770af8 LP |
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, | |
07299350 | 27 | SWAP_FAILURE_START_LIMIT_HIT, |
e1770af8 | 28 | _SWAP_RESULT_MAX, |
2d93c20e | 29 | _SWAP_RESULT_INVALID = -EINVAL, |
e1770af8 LP |
30 | } SwapResult; |
31 | ||
5bcb0f2b LP |
32 | typedef struct SwapParameters { |
33 | char *what; | |
47cb901e | 34 | char *options; |
5bcb0f2b | 35 | int priority; |
7477451b | 36 | bool priority_set; |
5bcb0f2b LP |
37 | } SwapParameters; |
38 | ||
07b0b134 | 39 | struct Swap { |
ac155bb8 | 40 | Unit meta; |
07b0b134 | 41 | |
e04aad61 LP |
42 | char *what; |
43 | ||
9670d583 LP |
44 | /* If the device has already shown up, this is the device |
45 | * node, which might be different from what, due to | |
46 | * symlinks */ | |
47 | char *devnode; | |
48 | ||
4e85aff4 LP |
49 | SwapParameters parameters_proc_swaps; |
50 | SwapParameters parameters_fragment; | |
07b0b134 | 51 | |
4e85aff4 LP |
52 | bool from_proc_swaps:1; |
53 | bool from_fragment:1; | |
e04aad61 | 54 | |
e04aad61 LP |
55 | /* Used while looking for swaps that vanished or got added |
56 | * from/to /proc/swaps */ | |
57 | bool is_active:1; | |
58 | bool just_activated:1; | |
59 | ||
e1770af8 | 60 | SwapResult result; |
a8b689b7 | 61 | SwapResult clean_result; |
e1770af8 | 62 | |
e04aad61 LP |
63 | usec_t timeout_usec; |
64 | ||
65 | ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX]; | |
66 | ExecContext exec_context; | |
4819ff03 | 67 | KillContext kill_context; |
4ad49000 | 68 | CGroupContext cgroup_context; |
e04aad61 | 69 | |
e76506b7 | 70 | ExecSharedRuntime *exec_runtime; |
29206d46 | 71 | DynamicCreds dynamic_creds; |
613b411c | 72 | |
e04aad61 LP |
73 | SwapState state, deserialized_state; |
74 | ||
75 | ExecCommand* control_command; | |
76 | SwapExecCommand control_command_id; | |
77 | pid_t control_pid; | |
78 | ||
718db961 | 79 | sd_event_source *timer_event_source; |
e04aad61 | 80 | |
35b8ca3a | 81 | /* In order to be able to distinguish dependencies on |
e04aad61 LP |
82 | different device nodes we might end up creating multiple |
83 | devices for the same swap. We chain them up here. */ | |
84 | ||
9670d583 | 85 | LIST_FIELDS(struct Swap, same_devnode); |
07b0b134 ML |
86 | }; |
87 | ||
88 | extern const UnitVTable swap_vtable; | |
89 | ||
4366e598 YW |
90 | int swap_process_device_new(Manager *m, sd_device *dev); |
91 | int swap_process_device_remove(Manager *m, sd_device *dev); | |
9670d583 | 92 | |
44a6b1b6 ZJS |
93 | const char* swap_exec_command_to_string(SwapExecCommand i) _const_; |
94 | SwapExecCommand swap_exec_command_from_string(const char *s) _pure_; | |
07b0b134 | 95 | |
44a6b1b6 ZJS |
96 | const char* swap_result_to_string(SwapResult i) _const_; |
97 | SwapResult swap_result_from_string(const char *s) _pure_; | |
57b7a260 FS |
98 | |
99 | DEFINE_CAST(SWAP, Swap); |