]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/swap.h
core: expose consumed CPU time per unit
[thirdparty/systemd.git] / src / core / swap.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
07b0b134 2
c2f1db8f 3#pragma once
07b0b134
ML
4
5/***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9 Copyright 2010 Maarten Lankhorst
10
11 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
07b0b134
ML
14 (at your option) any later version.
15
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 19 Lesser General Public License for more details.
07b0b134 20
5430f7f2 21 You should have received a copy of the GNU Lesser General Public License
07b0b134
ML
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23***/
24
9670d583
LP
25#include <libudev.h>
26
07b0b134
ML
27typedef struct Swap Swap;
28
07b0b134
ML
29
30typedef enum SwapState {
31 SWAP_DEAD,
5bcb0f2b
LP
32 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
33 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
07b0b134 34 SWAP_ACTIVE,
e04aad61
LP
35 SWAP_DEACTIVATING,
36 SWAP_ACTIVATING_SIGTERM,
37 SWAP_ACTIVATING_SIGKILL,
38 SWAP_DEACTIVATING_SIGTERM,
39 SWAP_DEACTIVATING_SIGKILL,
fdf20a31 40 SWAP_FAILED,
07b0b134
ML
41 _SWAP_STATE_MAX,
42 _SWAP_STATE_INVALID = -1
43} SwapState;
44
e04aad61
LP
45typedef enum SwapExecCommand {
46 SWAP_EXEC_ACTIVATE,
47 SWAP_EXEC_DEACTIVATE,
48 _SWAP_EXEC_COMMAND_MAX,
49 _SWAP_EXEC_COMMAND_INVALID = -1
50} SwapExecCommand;
51
e1770af8
LP
52typedef enum SwapResult {
53 SWAP_SUCCESS,
54 SWAP_FAILURE_RESOURCES,
55 SWAP_FAILURE_TIMEOUT,
56 SWAP_FAILURE_EXIT_CODE,
57 SWAP_FAILURE_SIGNAL,
58 SWAP_FAILURE_CORE_DUMP,
59 _SWAP_RESULT_MAX,
60 _SWAP_RESULT_INVALID = -1
61} SwapResult;
62
5bcb0f2b
LP
63typedef struct SwapParameters {
64 char *what;
47cb901e 65 char *options;
5bcb0f2b 66 int priority;
5bcb0f2b
LP
67} SwapParameters;
68
07b0b134 69struct Swap {
ac155bb8 70 Unit meta;
07b0b134 71
e04aad61
LP
72 char *what;
73
9670d583
LP
74 /* If the device has already shown up, this is the device
75 * node, which might be different from what, due to
76 * symlinks */
77 char *devnode;
78
4e85aff4
LP
79 SwapParameters parameters_proc_swaps;
80 SwapParameters parameters_fragment;
07b0b134 81
4e85aff4
LP
82 bool from_proc_swaps:1;
83 bool from_fragment:1;
e04aad61 84
e04aad61
LP
85 /* Used while looking for swaps that vanished or got added
86 * from/to /proc/swaps */
87 bool is_active:1;
88 bool just_activated:1;
89
5ad096b3
LP
90 bool reset_cpu_usage:1;
91
e1770af8
LP
92 SwapResult result;
93
e04aad61
LP
94 usec_t timeout_usec;
95
96 ExecCommand exec_command[_SWAP_EXEC_COMMAND_MAX];
97 ExecContext exec_context;
4819ff03 98 KillContext kill_context;
4ad49000 99 CGroupContext cgroup_context;
e04aad61 100
613b411c
LP
101 ExecRuntime *exec_runtime;
102
e04aad61
LP
103 SwapState state, deserialized_state;
104
105 ExecCommand* control_command;
106 SwapExecCommand control_command_id;
107 pid_t control_pid;
108
718db961 109 sd_event_source *timer_event_source;
e04aad61 110
35b8ca3a 111 /* In order to be able to distinguish dependencies on
e04aad61
LP
112 different device nodes we might end up creating multiple
113 devices for the same swap. We chain them up here. */
114
9670d583 115 LIST_FIELDS(struct Swap, same_devnode);
07b0b134
ML
116};
117
118extern const UnitVTable swap_vtable;
119
628c89cc
LP
120int swap_process_device_new(Manager *m, struct udev_device *dev);
121int swap_process_device_remove(Manager *m, struct udev_device *dev);
9670d583 122
44a6b1b6
ZJS
123const char* swap_state_to_string(SwapState i) _const_;
124SwapState swap_state_from_string(const char *s) _pure_;
07b0b134 125
44a6b1b6
ZJS
126const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
127SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
07b0b134 128
44a6b1b6
ZJS
129const char* swap_result_to_string(SwapResult i) _const_;
130SwapResult swap_result_from_string(const char *s) _pure_;