Debian Codegraph @

src/core/swap.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /***
5 Copyright © 2010 Maarten Lankhorst
6 ***/
7
8 #include "cgroup.h"
9 #include "core-forward.h"
10 #include "execute.h"
11 #include "pidref.h"
12 #include "unit.h"
13
14 typedef enum SwapExecCommand {
15 SWAP_EXEC_ACTIVATE,
16 SWAP_EXEC_DEACTIVATE,
17 _SWAP_EXEC_COMMAND_MAX,
18 _SWAP_EXEC_COMMAND_INVALID = -EINVAL,
19 } SwapExecCommand;
20
21 typedef enum SwapResult {
22 SWAP_SUCCESS,
23 SWAP_FAILURE_RESOURCES,
24 SWAP_FAILURE_TIMEOUT,
25 SWAP_FAILURE_EXIT_CODE,
26 SWAP_FAILURE_SIGNAL,
27 SWAP_FAILURE_CORE_DUMP,
28 SWAP_FAILURE_START_LIMIT_HIT,
29 _SWAP_RESULT_MAX,
30 _SWAP_RESULT_INVALID = -EINVAL,
31 } SwapResult;
32
33 typedef struct SwapParameters {
34 char *what;
35 char *options;
36 int priority;
37 bool priority_set;
38 } SwapParameters;
39
40 typedef 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 SwapResult clean_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 CGroupRuntime *cgroup_runtime;
73
74 SwapState state, deserialized_state;
75
76 ExecCommand* control_command;
77 SwapExecCommand control_command_id;
78 PidRef 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 } Swap;
88
89 extern const UnitVTable swap_vtable;
90
91 int swap_process_device_new(Manager *m, sd_device *dev);
92 int swap_process_device_remove(Manager *m, sd_device *dev);
93
94 int swap_get_priority(const Swap *s);
95 const char* swap_get_options(const Swap *s);
96
97 DECLARE_STRING_TABLE_LOOKUP(swap_exec_command, SwapExecCommand);
98
99 DECLARE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
100
101 DEFINE_CAST(SWAP, Swap);