]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/swap.h
core: undo the dependency inversion between unit.h and all unit types
[thirdparty/systemd.git] / src / core / swap.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
07b0b134
ML
3
4/***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8 Copyright 2010 Maarten Lankhorst
07b0b134
ML
9***/
10
07630cea 11#include "libudev.h"
57b7a260 12#include "unit.h"
9670d583 13
07b0b134
ML
14typedef struct Swap Swap;
15
e04aad61
LP
16typedef enum SwapExecCommand {
17 SWAP_EXEC_ACTIVATE,
18 SWAP_EXEC_DEACTIVATE,
19 _SWAP_EXEC_COMMAND_MAX,
20 _SWAP_EXEC_COMMAND_INVALID = -1
21} SwapExecCommand;
22
e1770af8
LP
23typedef 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,
07299350 30 SWAP_FAILURE_START_LIMIT_HIT,
e1770af8
LP
31 _SWAP_RESULT_MAX,
32 _SWAP_RESULT_INVALID = -1
33} SwapResult;
34
5bcb0f2b
LP
35typedef struct SwapParameters {
36 char *what;
47cb901e 37 char *options;
5bcb0f2b 38 int priority;
5bcb0f2b
LP
39} SwapParameters;
40
07b0b134 41struct Swap {
ac155bb8 42 Unit meta;
07b0b134 43
e04aad61
LP
44 char *what;
45
9670d583
LP
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
4e85aff4
LP
51 SwapParameters parameters_proc_swaps;
52 SwapParameters parameters_fragment;
07b0b134 53
4e85aff4
LP
54 bool from_proc_swaps:1;
55 bool from_fragment:1;
e04aad61 56
e04aad61
LP
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
e1770af8
LP
62 SwapResult result;
63
e04aad61
LP
64 usec_t timeout_usec;
65
66 ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
67 ExecContext exec_context;
4819ff03 68 KillContext kill_context;
4ad49000 69 CGroupContext cgroup_context;
e04aad61 70
613b411c 71 ExecRuntime *exec_runtime;
29206d46 72 DynamicCreds dynamic_creds;
613b411c 73
e04aad61
LP
74 SwapState state, deserialized_state;
75
76 ExecCommand* control_command;
77 SwapExecCommand control_command_id;
78 pid_t control_pid;
79
718db961 80 sd_event_source *timer_event_source;
e04aad61 81
35b8ca3a 82 /* In order to be able to distinguish dependencies on
e04aad61
LP
83 different device nodes we might end up creating multiple
84 devices for the same swap. We chain them up here. */
85
9670d583 86 LIST_FIELDS(struct Swap, same_devnode);
07b0b134
ML
87};
88
89extern const UnitVTable swap_vtable;
90
628c89cc
LP
91int swap_process_device_new(Manager *m, struct udev_device *dev);
92int swap_process_device_remove(Manager *m, struct udev_device *dev);
9670d583 93
44a6b1b6
ZJS
94const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
95SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
07b0b134 96
44a6b1b6
ZJS
97const char* swap_result_to_string(SwapResult i) _const_;
98SwapResult swap_result_from_string(const char *s) _pure_;
57b7a260
FS
99
100DEFINE_CAST(SWAP, Swap);