1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 Copyright © 2010 Maarten Lankhorst
13 typedef struct Swap Swap
;
15 typedef enum SwapExecCommand
{
18 _SWAP_EXEC_COMMAND_MAX
,
19 _SWAP_EXEC_COMMAND_INVALID
= -EINVAL
,
22 typedef enum SwapResult
{
24 SWAP_FAILURE_RESOURCES
,
26 SWAP_FAILURE_EXIT_CODE
,
28 SWAP_FAILURE_CORE_DUMP
,
29 SWAP_FAILURE_START_LIMIT_HIT
,
31 _SWAP_RESULT_INVALID
= -EINVAL
,
34 typedef struct SwapParameters
{
46 /* If the device has already shown up, this is the device
47 * node, which might be different from what, due to
51 SwapParameters parameters_proc_swaps
;
52 SwapParameters parameters_fragment
;
54 bool from_proc_swaps
:1;
57 /* Used while looking for swaps that vanished or got added
58 * from/to /proc/swaps */
60 bool just_activated
:1;
63 SwapResult clean_result
;
67 ExecCommand exec_command
[_SWAP_EXEC_COMMAND_MAX
];
68 ExecContext exec_context
;
69 KillContext kill_context
;
70 CGroupContext cgroup_context
;
72 ExecRuntime
*exec_runtime
;
74 SwapState state
, deserialized_state
;
76 ExecCommand
* control_command
;
77 SwapExecCommand control_command_id
;
80 sd_event_source
*timer_event_source
;
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. */
86 LIST_FIELDS(struct Swap
, same_devnode
);
89 extern const UnitVTable swap_vtable
;
91 int swap_process_device_new(Manager
*m
, sd_device
*dev
);
92 int swap_process_device_remove(Manager
*m
, sd_device
*dev
);
94 const char* swap_exec_command_to_string(SwapExecCommand i
) _const_
;
95 SwapExecCommand
swap_exec_command_from_string(const char *s
) _pure_
;
97 const char* swap_result_to_string(SwapResult i
) _const_
;
98 SwapResult
swap_result_from_string(const char *s
) _pure_
;
100 DEFINE_CAST(SWAP
, Swap
);