1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 Copyright © 2010 Maarten Lankhorst
11 typedef struct Swap Swap
;
13 typedef enum SwapExecCommand
{
16 _SWAP_EXEC_COMMAND_MAX
,
17 _SWAP_EXEC_COMMAND_INVALID
= -EINVAL
,
20 typedef enum SwapResult
{
22 SWAP_FAILURE_RESOURCES
,
24 SWAP_FAILURE_EXIT_CODE
,
26 SWAP_FAILURE_CORE_DUMP
,
27 SWAP_FAILURE_START_LIMIT_HIT
,
29 _SWAP_RESULT_INVALID
= -EINVAL
,
32 typedef struct SwapParameters
{
44 /* If the device has already shown up, this is the device
45 * node, which might be different from what, due to
49 SwapParameters parameters_proc_swaps
;
50 SwapParameters parameters_fragment
;
52 bool from_proc_swaps
:1;
55 /* Used while looking for swaps that vanished or got added
56 * from/to /proc/swaps */
58 bool just_activated
:1;
61 SwapResult clean_result
;
65 ExecCommand exec_command
[_SWAP_EXEC_COMMAND_MAX
];
66 ExecContext exec_context
;
67 KillContext kill_context
;
68 CGroupContext cgroup_context
;
70 ExecSharedRuntime
*exec_runtime
;
71 DynamicCreds dynamic_creds
;
73 SwapState state
, deserialized_state
;
75 ExecCommand
* control_command
;
76 SwapExecCommand control_command_id
;
79 sd_event_source
*timer_event_source
;
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. */
85 LIST_FIELDS(struct Swap
, same_devnode
);
88 extern const UnitVTable swap_vtable
;
90 int swap_process_device_new(Manager
*m
, sd_device
*dev
);
91 int swap_process_device_remove(Manager
*m
, sd_device
*dev
);
93 const char* swap_exec_command_to_string(SwapExecCommand i
) _const_
;
94 SwapExecCommand
swap_exec_command_from_string(const char *s
) _pure_
;
96 const char* swap_result_to_string(SwapResult i
) _const_
;
97 SwapResult
swap_result_from_string(const char *s
) _pure_
;
99 DEFINE_CAST(SWAP
, Swap
);