]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/swap.c
b61eab3e7e889a12fd17c3709e379b40c3aefa8c
[thirdparty/systemd.git] / src / core / swap.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2010 Lennart Poettering
6 ***/
7
8 #include <errno.h>
9 #include <sys/epoll.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12
13 #include "libudev.h"
14
15 #include "alloc-util.h"
16 #include "dbus-swap.h"
17 #include "device.h"
18 #include "escape.h"
19 #include "exit-status.h"
20 #include "fd-util.h"
21 #include "format-util.h"
22 #include "fstab-util.h"
23 #include "parse-util.h"
24 #include "path-util.h"
25 #include "process-util.h"
26 #include "special.h"
27 #include "string-table.h"
28 #include "string-util.h"
29 #include "swap.h"
30 #include "udev-util.h"
31 #include "unit-name.h"
32 #include "unit.h"
33 #include "virt.h"
34
35 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
36 [SWAP_DEAD] = UNIT_INACTIVE,
37 [SWAP_ACTIVATING] = UNIT_ACTIVATING,
38 [SWAP_ACTIVATING_DONE] = UNIT_ACTIVE,
39 [SWAP_ACTIVE] = UNIT_ACTIVE,
40 [SWAP_DEACTIVATING] = UNIT_DEACTIVATING,
41 [SWAP_DEACTIVATING_SIGTERM] = UNIT_DEACTIVATING,
42 [SWAP_DEACTIVATING_SIGKILL] = UNIT_DEACTIVATING,
43 [SWAP_FAILED] = UNIT_FAILED
44 };
45
46 static int swap_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
47 static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
48
49 static bool SWAP_STATE_WITH_PROCESS(SwapState state) {
50 return IN_SET(state,
51 SWAP_ACTIVATING,
52 SWAP_ACTIVATING_DONE,
53 SWAP_DEACTIVATING,
54 SWAP_DEACTIVATING_SIGTERM,
55 SWAP_DEACTIVATING_SIGKILL);
56 }
57
58 static void swap_unset_proc_swaps(Swap *s) {
59 assert(s);
60
61 if (!s->from_proc_swaps)
62 return;
63
64 s->parameters_proc_swaps.what = mfree(s->parameters_proc_swaps.what);
65
66 s->from_proc_swaps = false;
67 }
68
69 static int swap_set_devnode(Swap *s, const char *devnode) {
70 Hashmap *swaps;
71 Swap *first;
72 int r;
73
74 assert(s);
75
76 r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, &path_hash_ops);
77 if (r < 0)
78 return r;
79
80 swaps = UNIT(s)->manager->swaps_by_devnode;
81
82 if (s->devnode) {
83 first = hashmap_get(swaps, s->devnode);
84
85 LIST_REMOVE(same_devnode, first, s);
86 if (first)
87 hashmap_replace(swaps, first->devnode, first);
88 else
89 hashmap_remove(swaps, s->devnode);
90
91 s->devnode = mfree(s->devnode);
92 }
93
94 if (devnode) {
95 s->devnode = strdup(devnode);
96 if (!s->devnode)
97 return -ENOMEM;
98
99 first = hashmap_get(swaps, s->devnode);
100 LIST_PREPEND(same_devnode, first, s);
101
102 return hashmap_replace(swaps, first->devnode, first);
103 }
104
105 return 0;
106 }
107
108 static void swap_init(Unit *u) {
109 Swap *s = SWAP(u);
110
111 assert(s);
112 assert(UNIT(s)->load_state == UNIT_STUB);
113
114 s->timeout_usec = u->manager->default_timeout_start_usec;
115
116 s->exec_context.std_output = u->manager->default_std_output;
117 s->exec_context.std_error = u->manager->default_std_error;
118
119 s->parameters_proc_swaps.priority = s->parameters_fragment.priority = -1;
120
121 s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
122
123 u->ignore_on_isolate = true;
124 }
125
126 static void swap_unwatch_control_pid(Swap *s) {
127 assert(s);
128
129 if (s->control_pid <= 0)
130 return;
131
132 unit_unwatch_pid(UNIT(s), s->control_pid);
133 s->control_pid = 0;
134 }
135
136 static void swap_done(Unit *u) {
137 Swap *s = SWAP(u);
138
139 assert(s);
140
141 swap_unset_proc_swaps(s);
142 swap_set_devnode(s, NULL);
143
144 s->what = mfree(s->what);
145 s->parameters_fragment.what = mfree(s->parameters_fragment.what);
146 s->parameters_fragment.options = mfree(s->parameters_fragment.options);
147
148 s->exec_runtime = exec_runtime_unref(s->exec_runtime, false);
149 exec_command_done_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX);
150 s->control_command = NULL;
151
152 dynamic_creds_unref(&s->dynamic_creds);
153
154 swap_unwatch_control_pid(s);
155
156 s->timer_event_source = sd_event_source_unref(s->timer_event_source);
157 }
158
159 static int swap_arm_timer(Swap *s, usec_t usec) {
160 int r;
161
162 assert(s);
163
164 if (s->timer_event_source) {
165 r = sd_event_source_set_time(s->timer_event_source, usec);
166 if (r < 0)
167 return r;
168
169 return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
170 }
171
172 if (usec == USEC_INFINITY)
173 return 0;
174
175 r = sd_event_add_time(
176 UNIT(s)->manager->event,
177 &s->timer_event_source,
178 CLOCK_MONOTONIC,
179 usec, 0,
180 swap_dispatch_timer, s);
181 if (r < 0)
182 return r;
183
184 (void) sd_event_source_set_description(s->timer_event_source, "swap-timer");
185
186 return 0;
187 }
188
189 static int swap_add_device_dependencies(Swap *s) {
190 assert(s);
191
192 if (!s->what)
193 return 0;
194
195 if (!s->from_fragment)
196 return 0;
197
198 if (is_device_path(s->what))
199 return unit_add_node_dependency(UNIT(s), s->what, MANAGER_IS_SYSTEM(UNIT(s)->manager), UNIT_BINDS_TO, UNIT_DEPENDENCY_FILE);
200 else
201 /* File based swap devices need to be ordered after
202 * systemd-remount-fs.service, since they might need a
203 * writable file system. */
204 return unit_add_dependency_by_name(UNIT(s), UNIT_AFTER, SPECIAL_REMOUNT_FS_SERVICE, NULL, true, UNIT_DEPENDENCY_FILE);
205 }
206
207 static int swap_add_default_dependencies(Swap *s) {
208 int r;
209
210 assert(s);
211
212 if (!UNIT(s)->default_dependencies)
213 return 0;
214
215 if (!MANAGER_IS_SYSTEM(UNIT(s)->manager))
216 return 0;
217
218 if (detect_container() > 0)
219 return 0;
220
221 /* swap units generated for the swap dev links are missing the
222 * ordering dep against the swap target. */
223 r = unit_add_dependency_by_name(UNIT(s), UNIT_BEFORE, SPECIAL_SWAP_TARGET, NULL, true, UNIT_DEPENDENCY_DEFAULT);
224 if (r < 0)
225 return r;
226
227 return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true, UNIT_DEPENDENCY_DEFAULT);
228 }
229
230 static int swap_verify(Swap *s) {
231 _cleanup_free_ char *e = NULL;
232 int r;
233
234 if (UNIT(s)->load_state != UNIT_LOADED)
235 return 0;
236
237 r = unit_name_from_path(s->what, ".swap", &e);
238 if (r < 0)
239 return log_unit_error_errno(UNIT(s), r, "Failed to generate unit name from path: %m");
240
241 if (!unit_has_name(UNIT(s), e)) {
242 log_unit_error(UNIT(s), "Value of What= and unit name do not match, not loading.");
243 return -ENOEXEC;
244 }
245
246 if (s->exec_context.pam_name && s->kill_context.kill_mode != KILL_CONTROL_GROUP) {
247 log_unit_error(UNIT(s), "Unit has PAM enabled. Kill mode must be set to 'control-group'. Refusing to load.");
248 return -ENOEXEC;
249 }
250
251 return 0;
252 }
253
254 static int swap_load_devnode(Swap *s) {
255 _cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
256 struct stat st;
257 const char *p;
258 int r;
259
260 assert(s);
261
262 if (stat(s->what, &st) < 0 || !S_ISBLK(st.st_mode))
263 return 0;
264
265 r = udev_device_new_from_stat_rdev(UNIT(s)->manager->udev, &st, &d);
266 if (r < 0) {
267 log_unit_full(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
268 "Failed to allocate udev device for swap %s: %m", s->what);
269 return 0;
270 }
271
272 p = udev_device_get_devnode(d);
273 if (!p)
274 return 0;
275
276 return swap_set_devnode(s, p);
277 }
278
279 static int swap_load(Unit *u) {
280 int r;
281 Swap *s = SWAP(u);
282
283 assert(s);
284 assert(u->load_state == UNIT_STUB);
285
286 /* Load a .swap file */
287 if (SWAP(u)->from_proc_swaps)
288 r = unit_load_fragment_and_dropin_optional(u);
289 else
290 r = unit_load_fragment_and_dropin(u);
291 if (r < 0)
292 return r;
293
294 if (u->load_state == UNIT_LOADED) {
295
296 if (UNIT(s)->fragment_path)
297 s->from_fragment = true;
298
299 if (!s->what) {
300 if (s->parameters_fragment.what)
301 s->what = strdup(s->parameters_fragment.what);
302 else if (s->parameters_proc_swaps.what)
303 s->what = strdup(s->parameters_proc_swaps.what);
304 else {
305 r = unit_name_to_path(u->id, &s->what);
306 if (r < 0)
307 return r;
308 }
309
310 if (!s->what)
311 return -ENOMEM;
312 }
313
314 path_simplify(s->what, false);
315
316 if (!UNIT(s)->description) {
317 r = unit_set_description(u, s->what);
318 if (r < 0)
319 return r;
320 }
321
322 r = unit_require_mounts_for(UNIT(s), s->what, UNIT_DEPENDENCY_IMPLICIT);
323 if (r < 0)
324 return r;
325
326 r = swap_add_device_dependencies(s);
327 if (r < 0)
328 return r;
329
330 r = swap_load_devnode(s);
331 if (r < 0)
332 return r;
333
334 r = unit_patch_contexts(u);
335 if (r < 0)
336 return r;
337
338 r = unit_add_exec_dependencies(u, &s->exec_context);
339 if (r < 0)
340 return r;
341
342 r = unit_set_default_slice(u);
343 if (r < 0)
344 return r;
345
346 r = swap_add_default_dependencies(s);
347 if (r < 0)
348 return r;
349 }
350
351 return swap_verify(s);
352 }
353
354 static int swap_setup_unit(
355 Manager *m,
356 const char *what,
357 const char *what_proc_swaps,
358 int priority,
359 bool set_flags) {
360
361 _cleanup_free_ char *e = NULL;
362 bool delete = false;
363 Unit *u = NULL;
364 int r;
365 SwapParameters *p;
366
367 assert(m);
368 assert(what);
369 assert(what_proc_swaps);
370
371 r = unit_name_from_path(what, ".swap", &e);
372 if (r < 0)
373 return log_unit_error_errno(u, r, "Failed to generate unit name from path: %m");
374
375 u = manager_get_unit(m, e);
376
377 if (u &&
378 SWAP(u)->from_proc_swaps &&
379 !path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps)) {
380 log_error("Swap %s appeared twice with different device paths %s and %s", e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps);
381 return -EEXIST;
382 }
383
384 if (!u) {
385 delete = true;
386
387 r = unit_new_for_name(m, sizeof(Swap), e, &u);
388 if (r < 0)
389 goto fail;
390
391 SWAP(u)->what = strdup(what);
392 if (!SWAP(u)->what) {
393 r = -ENOMEM;
394 goto fail;
395 }
396
397 unit_add_to_load_queue(u);
398 } else
399 delete = false;
400
401 p = &SWAP(u)->parameters_proc_swaps;
402
403 if (!p->what) {
404 p->what = strdup(what_proc_swaps);
405 if (!p->what) {
406 r = -ENOMEM;
407 goto fail;
408 }
409 }
410
411 if (set_flags) {
412 SWAP(u)->is_active = true;
413 SWAP(u)->just_activated = !SWAP(u)->from_proc_swaps;
414 }
415
416 SWAP(u)->from_proc_swaps = true;
417
418 p->priority = priority;
419
420 unit_add_to_dbus_queue(u);
421 return 0;
422
423 fail:
424 log_unit_warning_errno(u, r, "Failed to load swap unit: %m");
425
426 if (delete)
427 unit_free(u);
428
429 return r;
430 }
431
432 static int swap_process_new(Manager *m, const char *device, int prio, bool set_flags) {
433 _cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
434 struct udev_list_entry *item = NULL, *first = NULL;
435 const char *dn;
436 struct stat st;
437 int r;
438
439 assert(m);
440
441 r = swap_setup_unit(m, device, device, prio, set_flags);
442 if (r < 0)
443 return r;
444
445 /* If this is a block device, then let's add duplicates for
446 * all other names of this block device */
447 if (stat(device, &st) < 0 || !S_ISBLK(st.st_mode))
448 return 0;
449
450 r = udev_device_new_from_stat_rdev(m->udev, &st, &d);
451 if (r < 0) {
452 log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
453 "Failed to allocate udev device for swap %s: %m", device);
454 return 0;
455 }
456
457 /* Add the main device node */
458 dn = udev_device_get_devnode(d);
459 if (dn && !streq(dn, device))
460 swap_setup_unit(m, dn, device, prio, set_flags);
461
462 /* Add additional units for all symlinks */
463 first = udev_device_get_devlinks_list_entry(d);
464 udev_list_entry_foreach(item, first) {
465 const char *p;
466
467 /* Don't bother with the /dev/block links */
468 p = udev_list_entry_get_name(item);
469
470 if (streq(p, device))
471 continue;
472
473 if (path_startswith(p, "/dev/block/"))
474 continue;
475
476 if (stat(p, &st) >= 0)
477 if (!S_ISBLK(st.st_mode) ||
478 st.st_rdev != udev_device_get_devnum(d))
479 continue;
480
481 swap_setup_unit(m, p, device, prio, set_flags);
482 }
483
484 return r;
485 }
486
487 static void swap_set_state(Swap *s, SwapState state) {
488 SwapState old_state;
489 Swap *other;
490
491 assert(s);
492
493 old_state = s->state;
494 s->state = state;
495
496 if (!SWAP_STATE_WITH_PROCESS(state)) {
497 s->timer_event_source = sd_event_source_unref(s->timer_event_source);
498 swap_unwatch_control_pid(s);
499 s->control_command = NULL;
500 s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
501 }
502
503 if (state != old_state)
504 log_unit_debug(UNIT(s), "Changed %s -> %s", swap_state_to_string(old_state), swap_state_to_string(state));
505
506 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
507
508 /* If there other units for the same device node have a job
509 queued it might be worth checking again if it is runnable
510 now. This is necessary, since swap_start() refuses
511 operation with EAGAIN if there's already another job for
512 the same device node queued. */
513 LIST_FOREACH_OTHERS(same_devnode, other, s)
514 if (UNIT(other)->job)
515 job_add_to_run_queue(UNIT(other)->job);
516 }
517
518 static int swap_coldplug(Unit *u) {
519 Swap *s = SWAP(u);
520 SwapState new_state = SWAP_DEAD;
521 int r;
522
523 assert(s);
524 assert(s->state == SWAP_DEAD);
525
526 if (s->deserialized_state != s->state)
527 new_state = s->deserialized_state;
528 else if (s->from_proc_swaps)
529 new_state = SWAP_ACTIVE;
530
531 if (new_state == s->state)
532 return 0;
533
534 if (s->control_pid > 0 &&
535 pid_is_unwaited(s->control_pid) &&
536 SWAP_STATE_WITH_PROCESS(new_state)) {
537
538 r = unit_watch_pid(UNIT(s), s->control_pid);
539 if (r < 0)
540 return r;
541
542 r = swap_arm_timer(s, usec_add(u->state_change_timestamp.monotonic, s->timeout_usec));
543 if (r < 0)
544 return r;
545 }
546
547 if (!IN_SET(new_state, SWAP_DEAD, SWAP_FAILED)) {
548 (void) unit_setup_dynamic_creds(u);
549 (void) unit_setup_exec_runtime(u);
550 }
551
552 swap_set_state(s, new_state);
553 return 0;
554 }
555
556 static void swap_dump(Unit *u, FILE *f, const char *prefix) {
557 char buf[FORMAT_TIMESPAN_MAX];
558 Swap *s = SWAP(u);
559 SwapParameters *p;
560
561 assert(s);
562 assert(f);
563
564 if (s->from_proc_swaps)
565 p = &s->parameters_proc_swaps;
566 else if (s->from_fragment)
567 p = &s->parameters_fragment;
568 else
569 p = NULL;
570
571 fprintf(f,
572 "%sSwap State: %s\n"
573 "%sResult: %s\n"
574 "%sWhat: %s\n"
575 "%sFrom /proc/swaps: %s\n"
576 "%sFrom fragment: %s\n",
577 prefix, swap_state_to_string(s->state),
578 prefix, swap_result_to_string(s->result),
579 prefix, s->what,
580 prefix, yes_no(s->from_proc_swaps),
581 prefix, yes_no(s->from_fragment));
582
583 if (s->devnode)
584 fprintf(f, "%sDevice Node: %s\n", prefix, s->devnode);
585
586 if (p)
587 fprintf(f,
588 "%sPriority: %i\n"
589 "%sOptions: %s\n",
590 prefix, p->priority,
591 prefix, strempty(p->options));
592
593 fprintf(f,
594 "%sTimeoutSec: %s\n",
595 prefix, format_timespan(buf, sizeof(buf), s->timeout_usec, USEC_PER_SEC));
596
597 if (s->control_pid > 0)
598 fprintf(f,
599 "%sControl PID: "PID_FMT"\n",
600 prefix, s->control_pid);
601
602 exec_context_dump(&s->exec_context, f, prefix);
603 kill_context_dump(&s->kill_context, f, prefix);
604 cgroup_context_dump(&s->cgroup_context, f, prefix);
605 }
606
607 static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) {
608
609 ExecParameters exec_params = {
610 .flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
611 .stdin_fd = -1,
612 .stdout_fd = -1,
613 .stderr_fd = -1,
614 };
615 pid_t pid;
616 int r;
617
618 assert(s);
619 assert(c);
620 assert(_pid);
621
622 r = unit_prepare_exec(UNIT(s));
623 if (r < 0)
624 return r;
625
626 r = swap_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_usec));
627 if (r < 0)
628 goto fail;
629
630 unit_set_exec_params(UNIT(s), &exec_params);
631
632 r = exec_spawn(UNIT(s),
633 c,
634 &s->exec_context,
635 &exec_params,
636 s->exec_runtime,
637 &s->dynamic_creds,
638 &pid);
639 if (r < 0)
640 goto fail;
641
642 r = unit_watch_pid(UNIT(s), pid);
643 if (r < 0)
644 /* FIXME: we need to do something here */
645 goto fail;
646
647 *_pid = pid;
648
649 return 0;
650
651 fail:
652 s->timer_event_source = sd_event_source_unref(s->timer_event_source);
653
654 return r;
655 }
656
657 static void swap_enter_dead(Swap *s, SwapResult f) {
658 assert(s);
659
660 if (s->result == SWAP_SUCCESS)
661 s->result = f;
662
663 if (s->result != SWAP_SUCCESS)
664 log_unit_warning(UNIT(s), "Failed with result '%s'.", swap_result_to_string(s->result));
665
666 swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
667
668 s->exec_runtime = exec_runtime_unref(s->exec_runtime, true);
669
670 exec_context_destroy_runtime_directory(&s->exec_context, UNIT(s)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
671
672 unit_unref_uid_gid(UNIT(s), true);
673
674 dynamic_creds_destroy(&s->dynamic_creds);
675 }
676
677 static void swap_enter_active(Swap *s, SwapResult f) {
678 assert(s);
679
680 if (s->result == SWAP_SUCCESS)
681 s->result = f;
682
683 swap_set_state(s, SWAP_ACTIVE);
684 }
685
686 static void swap_enter_dead_or_active(Swap *s, SwapResult f) {
687 assert(s);
688
689 if (s->from_proc_swaps)
690 swap_enter_active(s, f);
691 else
692 swap_enter_dead(s, f);
693 }
694
695 static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) {
696 int r;
697 KillOperation kop;
698
699 assert(s);
700
701 if (s->result == SWAP_SUCCESS)
702 s->result = f;
703
704 if (state == SWAP_DEACTIVATING_SIGTERM)
705 kop = KILL_TERMINATE;
706 else
707 kop = KILL_KILL;
708
709 r = unit_kill_context(UNIT(s), &s->kill_context, kop, -1, s->control_pid, false);
710 if (r < 0)
711 goto fail;
712
713 if (r > 0) {
714 r = swap_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_usec));
715 if (r < 0)
716 goto fail;
717
718 swap_set_state(s, state);
719 } else if (state == SWAP_DEACTIVATING_SIGTERM && s->kill_context.send_sigkill)
720 swap_enter_signal(s, SWAP_DEACTIVATING_SIGKILL, SWAP_SUCCESS);
721 else
722 swap_enter_dead_or_active(s, SWAP_SUCCESS);
723
724 return;
725
726 fail:
727 log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
728 swap_enter_dead_or_active(s, SWAP_FAILURE_RESOURCES);
729 }
730
731 static void swap_enter_activating(Swap *s) {
732 _cleanup_free_ char *opts = NULL;
733 int r;
734
735 assert(s);
736
737 unit_warn_leftover_processes(UNIT(s));
738
739 s->control_command_id = SWAP_EXEC_ACTIVATE;
740 s->control_command = s->exec_command + SWAP_EXEC_ACTIVATE;
741
742 if (s->from_fragment) {
743 int priority = -1;
744
745 r = fstab_find_pri(s->parameters_fragment.options, &priority);
746 if (r < 0)
747 log_warning_errno(r, "Failed to parse swap priority \"%s\", ignoring: %m", s->parameters_fragment.options);
748 else if (r == 1 && s->parameters_fragment.priority >= 0)
749 log_warning("Duplicate swap priority configuration by Priority and Options fields.");
750
751 if (r <= 0 && s->parameters_fragment.priority >= 0) {
752 if (s->parameters_fragment.options)
753 r = asprintf(&opts, "%s,pri=%i", s->parameters_fragment.options, s->parameters_fragment.priority);
754 else
755 r = asprintf(&opts, "pri=%i", s->parameters_fragment.priority);
756 if (r < 0)
757 goto fail;
758 }
759 }
760
761 r = exec_command_set(s->control_command, "/sbin/swapon", NULL);
762 if (r < 0)
763 goto fail;
764
765 if (s->parameters_fragment.options || opts) {
766 r = exec_command_append(s->control_command, "-o",
767 opts ? : s->parameters_fragment.options, NULL);
768 if (r < 0)
769 goto fail;
770 }
771
772 r = exec_command_append(s->control_command, s->what, NULL);
773 if (r < 0)
774 goto fail;
775
776 swap_unwatch_control_pid(s);
777
778 r = swap_spawn(s, s->control_command, &s->control_pid);
779 if (r < 0)
780 goto fail;
781
782 swap_set_state(s, SWAP_ACTIVATING);
783
784 return;
785
786 fail:
787 log_unit_warning_errno(UNIT(s), r, "Failed to run 'swapon' task: %m");
788 swap_enter_dead_or_active(s, SWAP_FAILURE_RESOURCES);
789 }
790
791 static void swap_enter_deactivating(Swap *s) {
792 int r;
793
794 assert(s);
795
796 s->control_command_id = SWAP_EXEC_DEACTIVATE;
797 s->control_command = s->exec_command + SWAP_EXEC_DEACTIVATE;
798
799 r = exec_command_set(s->control_command,
800 "/sbin/swapoff",
801 s->what,
802 NULL);
803 if (r < 0)
804 goto fail;
805
806 swap_unwatch_control_pid(s);
807
808 r = swap_spawn(s, s->control_command, &s->control_pid);
809 if (r < 0)
810 goto fail;
811
812 swap_set_state(s, SWAP_DEACTIVATING);
813
814 return;
815
816 fail:
817 log_unit_warning_errno(UNIT(s), r, "Failed to run 'swapoff' task: %m");
818 swap_enter_dead_or_active(s, SWAP_FAILURE_RESOURCES);
819 }
820
821 static int swap_start(Unit *u) {
822 Swap *s = SWAP(u), *other;
823 int r;
824
825 assert(s);
826
827 /* We cannot fulfill this request right now, try again later please! */
828 if (IN_SET(s->state,
829 SWAP_DEACTIVATING,
830 SWAP_DEACTIVATING_SIGTERM,
831 SWAP_DEACTIVATING_SIGKILL))
832 return -EAGAIN;
833
834 /* Already on it! */
835 if (s->state == SWAP_ACTIVATING)
836 return 0;
837
838 assert(IN_SET(s->state, SWAP_DEAD, SWAP_FAILED));
839
840 if (detect_container() > 0)
841 return -EPERM;
842
843 /* If there's a job for another swap unit for the same node
844 * running, then let's not dispatch this one for now, and wait
845 * until that other job has finished. */
846 LIST_FOREACH_OTHERS(same_devnode, other, s)
847 if (UNIT(other)->job && UNIT(other)->job->state == JOB_RUNNING)
848 return -EAGAIN;
849
850 r = unit_start_limit_test(u);
851 if (r < 0) {
852 swap_enter_dead(s, SWAP_FAILURE_START_LIMIT_HIT);
853 return r;
854 }
855
856 r = unit_acquire_invocation_id(u);
857 if (r < 0)
858 return r;
859
860 s->result = SWAP_SUCCESS;
861
862 u->reset_accounting = true;
863
864 swap_enter_activating(s);
865 return 1;
866 }
867
868 static int swap_stop(Unit *u) {
869 Swap *s = SWAP(u);
870
871 assert(s);
872
873 switch (s->state) {
874
875 case SWAP_DEACTIVATING:
876 case SWAP_DEACTIVATING_SIGTERM:
877 case SWAP_DEACTIVATING_SIGKILL:
878 /* Already on it */
879 return 0;
880
881 case SWAP_ACTIVATING:
882 case SWAP_ACTIVATING_DONE:
883 /* There's a control process pending, directly enter kill mode */
884 swap_enter_signal(s, SWAP_DEACTIVATING_SIGTERM, SWAP_SUCCESS);
885 return 0;
886
887 case SWAP_ACTIVE:
888 if (detect_container() > 0)
889 return -EPERM;
890
891 swap_enter_deactivating(s);
892 return 1;
893
894 default:
895 assert_not_reached("Unexpected state.");
896 }
897 }
898
899 static int swap_serialize(Unit *u, FILE *f, FDSet *fds) {
900 Swap *s = SWAP(u);
901
902 assert(s);
903 assert(f);
904 assert(fds);
905
906 unit_serialize_item(u, f, "state", swap_state_to_string(s->state));
907 unit_serialize_item(u, f, "result", swap_result_to_string(s->result));
908
909 if (s->control_pid > 0)
910 unit_serialize_item_format(u, f, "control-pid", PID_FMT, s->control_pid);
911
912 if (s->control_command_id >= 0)
913 unit_serialize_item(u, f, "control-command", swap_exec_command_to_string(s->control_command_id));
914
915 return 0;
916 }
917
918 static int swap_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
919 Swap *s = SWAP(u);
920
921 assert(s);
922 assert(fds);
923
924 if (streq(key, "state")) {
925 SwapState state;
926
927 state = swap_state_from_string(value);
928 if (state < 0)
929 log_unit_debug(u, "Failed to parse state value: %s", value);
930 else
931 s->deserialized_state = state;
932 } else if (streq(key, "result")) {
933 SwapResult f;
934
935 f = swap_result_from_string(value);
936 if (f < 0)
937 log_unit_debug(u, "Failed to parse result value: %s", value);
938 else if (f != SWAP_SUCCESS)
939 s->result = f;
940 } else if (streq(key, "control-pid")) {
941 pid_t pid;
942
943 if (parse_pid(value, &pid) < 0)
944 log_unit_debug(u, "Failed to parse control-pid value: %s", value);
945 else
946 s->control_pid = pid;
947
948 } else if (streq(key, "control-command")) {
949 SwapExecCommand id;
950
951 id = swap_exec_command_from_string(value);
952 if (id < 0)
953 log_unit_debug(u, "Failed to parse exec-command value: %s", value);
954 else {
955 s->control_command_id = id;
956 s->control_command = s->exec_command + id;
957 }
958 } else
959 log_unit_debug(u, "Unknown serialization key: %s", key);
960
961 return 0;
962 }
963
964 _pure_ static UnitActiveState swap_active_state(Unit *u) {
965 assert(u);
966
967 return state_translation_table[SWAP(u)->state];
968 }
969
970 _pure_ static const char *swap_sub_state_to_string(Unit *u) {
971 assert(u);
972
973 return swap_state_to_string(SWAP(u)->state);
974 }
975
976 _pure_ static bool swap_may_gc(Unit *u) {
977 Swap *s = SWAP(u);
978
979 assert(s);
980
981 if (s->from_proc_swaps)
982 return false;
983
984 return true;
985 }
986
987 static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
988 Swap *s = SWAP(u);
989 SwapResult f;
990
991 assert(s);
992 assert(pid >= 0);
993
994 if (pid != s->control_pid)
995 return;
996
997 s->control_pid = 0;
998
999 if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
1000 f = SWAP_SUCCESS;
1001 else if (code == CLD_EXITED)
1002 f = SWAP_FAILURE_EXIT_CODE;
1003 else if (code == CLD_KILLED)
1004 f = SWAP_FAILURE_SIGNAL;
1005 else if (code == CLD_DUMPED)
1006 f = SWAP_FAILURE_CORE_DUMP;
1007 else
1008 assert_not_reached("Unknown code");
1009
1010 if (s->result == SWAP_SUCCESS)
1011 s->result = f;
1012
1013 if (s->control_command) {
1014 exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
1015
1016 s->control_command = NULL;
1017 s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
1018 }
1019
1020 log_unit_full(u, f == SWAP_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0,
1021 "Swap process exited, code=%s status=%i", sigchld_code_to_string(code), status);
1022
1023 switch (s->state) {
1024
1025 case SWAP_ACTIVATING:
1026 case SWAP_ACTIVATING_DONE:
1027
1028 if (f == SWAP_SUCCESS || s->from_proc_swaps)
1029 swap_enter_active(s, f);
1030 else
1031 swap_enter_dead(s, f);
1032 break;
1033
1034 case SWAP_DEACTIVATING:
1035 case SWAP_DEACTIVATING_SIGKILL:
1036 case SWAP_DEACTIVATING_SIGTERM:
1037
1038 swap_enter_dead_or_active(s, f);
1039 break;
1040
1041 default:
1042 assert_not_reached("Uh, control process died at wrong time.");
1043 }
1044
1045 /* Notify clients about changed exit status */
1046 unit_add_to_dbus_queue(u);
1047 }
1048
1049 static int swap_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) {
1050 Swap *s = SWAP(userdata);
1051
1052 assert(s);
1053 assert(s->timer_event_source == source);
1054
1055 switch (s->state) {
1056
1057 case SWAP_ACTIVATING:
1058 case SWAP_ACTIVATING_DONE:
1059 log_unit_warning(UNIT(s), "Activation timed out. Stopping.");
1060 swap_enter_signal(s, SWAP_DEACTIVATING_SIGTERM, SWAP_FAILURE_TIMEOUT);
1061 break;
1062
1063 case SWAP_DEACTIVATING:
1064 log_unit_warning(UNIT(s), "Deactivation timed out. Stopping.");
1065 swap_enter_signal(s, SWAP_DEACTIVATING_SIGTERM, SWAP_FAILURE_TIMEOUT);
1066 break;
1067
1068 case SWAP_DEACTIVATING_SIGTERM:
1069 if (s->kill_context.send_sigkill) {
1070 log_unit_warning(UNIT(s), "Swap process timed out. Killing.");
1071 swap_enter_signal(s, SWAP_DEACTIVATING_SIGKILL, SWAP_FAILURE_TIMEOUT);
1072 } else {
1073 log_unit_warning(UNIT(s), "Swap process timed out. Skipping SIGKILL. Ignoring.");
1074 swap_enter_dead_or_active(s, SWAP_FAILURE_TIMEOUT);
1075 }
1076 break;
1077
1078 case SWAP_DEACTIVATING_SIGKILL:
1079 log_unit_warning(UNIT(s), "Swap process still around after SIGKILL. Ignoring.");
1080 swap_enter_dead_or_active(s, SWAP_FAILURE_TIMEOUT);
1081 break;
1082
1083 default:
1084 assert_not_reached("Timeout at wrong time.");
1085 }
1086
1087 return 0;
1088 }
1089
1090 static int swap_load_proc_swaps(Manager *m, bool set_flags) {
1091 unsigned i;
1092 int r = 0;
1093
1094 assert(m);
1095
1096 rewind(m->proc_swaps);
1097
1098 (void) fscanf(m->proc_swaps, "%*s %*s %*s %*s %*s\n");
1099
1100 for (i = 1;; i++) {
1101 _cleanup_free_ char *dev = NULL, *d = NULL;
1102 int prio = 0, k;
1103
1104 k = fscanf(m->proc_swaps,
1105 "%ms " /* device/file */
1106 "%*s " /* type of swap */
1107 "%*s " /* swap size */
1108 "%*s " /* used */
1109 "%i\n", /* priority */
1110 &dev, &prio);
1111 if (k != 2) {
1112 if (k == EOF)
1113 break;
1114
1115 log_warning("Failed to parse /proc/swaps:%u.", i);
1116 continue;
1117 }
1118
1119 if (cunescape(dev, UNESCAPE_RELAX, &d) < 0)
1120 return log_oom();
1121
1122 device_found_node(m, d, DEVICE_FOUND_SWAP, DEVICE_FOUND_SWAP);
1123
1124 k = swap_process_new(m, d, prio, set_flags);
1125 if (k < 0)
1126 r = k;
1127 }
1128
1129 return r;
1130 }
1131
1132 static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
1133 Manager *m = userdata;
1134 Unit *u;
1135 int r;
1136
1137 assert(m);
1138 assert(revents & EPOLLPRI);
1139
1140 r = swap_load_proc_swaps(m, true);
1141 if (r < 0) {
1142 log_error_errno(r, "Failed to reread /proc/swaps: %m");
1143
1144 /* Reset flags, just in case, for late calls */
1145 LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
1146 Swap *swap = SWAP(u);
1147
1148 swap->is_active = swap->just_activated = false;
1149 }
1150
1151 return 0;
1152 }
1153
1154 manager_dispatch_load_queue(m);
1155
1156 LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_SWAP]) {
1157 Swap *swap = SWAP(u);
1158
1159 if (!swap->is_active) {
1160 /* This has just been deactivated */
1161
1162 swap_unset_proc_swaps(swap);
1163
1164 switch (swap->state) {
1165
1166 case SWAP_ACTIVE:
1167 swap_enter_dead(swap, SWAP_SUCCESS);
1168 break;
1169
1170 default:
1171 /* Fire again */
1172 swap_set_state(swap, swap->state);
1173 break;
1174 }
1175
1176 if (swap->what)
1177 device_found_node(m, swap->what, 0, DEVICE_FOUND_SWAP);
1178
1179 } else if (swap->just_activated) {
1180
1181 /* New swap entry */
1182
1183 switch (swap->state) {
1184
1185 case SWAP_DEAD:
1186 case SWAP_FAILED:
1187 (void) unit_acquire_invocation_id(UNIT(swap));
1188 swap_enter_active(swap, SWAP_SUCCESS);
1189 break;
1190
1191 case SWAP_ACTIVATING:
1192 swap_set_state(swap, SWAP_ACTIVATING_DONE);
1193 break;
1194
1195 default:
1196 /* Nothing really changed, but let's
1197 * issue an notification call
1198 * nonetheless, in case somebody is
1199 * waiting for this. */
1200 swap_set_state(swap, swap->state);
1201 break;
1202 }
1203 }
1204
1205 /* Reset the flags for later calls */
1206 swap->is_active = swap->just_activated = false;
1207 }
1208
1209 return 1;
1210 }
1211
1212 static Unit *swap_following(Unit *u) {
1213 Swap *s = SWAP(u);
1214 Swap *other, *first = NULL;
1215
1216 assert(s);
1217
1218 /* If the user configured the swap through /etc/fstab or
1219 * a device unit, follow that. */
1220
1221 if (s->from_fragment)
1222 return NULL;
1223
1224 LIST_FOREACH_OTHERS(same_devnode, other, s)
1225 if (other->from_fragment)
1226 return UNIT(other);
1227
1228 /* Otherwise, make everybody follow the unit that's named after
1229 * the swap device in the kernel */
1230
1231 if (streq_ptr(s->what, s->devnode))
1232 return NULL;
1233
1234 LIST_FOREACH_AFTER(same_devnode, other, s)
1235 if (streq_ptr(other->what, other->devnode))
1236 return UNIT(other);
1237
1238 LIST_FOREACH_BEFORE(same_devnode, other, s) {
1239 if (streq_ptr(other->what, other->devnode))
1240 return UNIT(other);
1241
1242 first = other;
1243 }
1244
1245 /* Fall back to the first on the list */
1246 return UNIT(first);
1247 }
1248
1249 static int swap_following_set(Unit *u, Set **_set) {
1250 Swap *s = SWAP(u), *other;
1251 _cleanup_set_free_ Set *set = NULL;
1252 int r;
1253
1254 assert(s);
1255 assert(_set);
1256
1257 if (LIST_JUST_US(same_devnode, s)) {
1258 *_set = NULL;
1259 return 0;
1260 }
1261
1262 set = set_new(NULL);
1263 if (!set)
1264 return -ENOMEM;
1265
1266 LIST_FOREACH_OTHERS(same_devnode, other, s) {
1267 r = set_put(set, other);
1268 if (r < 0)
1269 return r;
1270 }
1271
1272 *_set = TAKE_PTR(set);
1273 return 1;
1274 }
1275
1276 static void swap_shutdown(Manager *m) {
1277 assert(m);
1278
1279 m->swap_event_source = sd_event_source_unref(m->swap_event_source);
1280 m->proc_swaps = safe_fclose(m->proc_swaps);
1281 m->swaps_by_devnode = hashmap_free(m->swaps_by_devnode);
1282 }
1283
1284 static void swap_enumerate(Manager *m) {
1285 int r;
1286
1287 assert(m);
1288
1289 if (!m->proc_swaps) {
1290 m->proc_swaps = fopen("/proc/swaps", "re");
1291 if (!m->proc_swaps) {
1292 if (errno == ENOENT)
1293 log_debug_errno(errno, "Not swap enabled, skipping enumeration.");
1294 else
1295 log_warning_errno(errno, "Failed to open /proc/swaps, ignoring: %m");
1296
1297 return;
1298 }
1299
1300 r = sd_event_add_io(m->event, &m->swap_event_source, fileno(m->proc_swaps), EPOLLPRI, swap_dispatch_io, m);
1301 if (r < 0) {
1302 log_error_errno(r, "Failed to watch /proc/swaps: %m");
1303 goto fail;
1304 }
1305
1306 /* Dispatch this before we dispatch SIGCHLD, so that
1307 * we always get the events from /proc/swaps before
1308 * the SIGCHLD of /sbin/swapon. */
1309 r = sd_event_source_set_priority(m->swap_event_source, SD_EVENT_PRIORITY_NORMAL-10);
1310 if (r < 0) {
1311 log_error_errno(r, "Failed to change /proc/swaps priority: %m");
1312 goto fail;
1313 }
1314
1315 (void) sd_event_source_set_description(m->swap_event_source, "swap-proc");
1316 }
1317
1318 r = swap_load_proc_swaps(m, false);
1319 if (r < 0)
1320 goto fail;
1321
1322 return;
1323
1324 fail:
1325 swap_shutdown(m);
1326 }
1327
1328 int swap_process_device_new(Manager *m, struct udev_device *dev) {
1329 struct udev_list_entry *item = NULL, *first = NULL;
1330 _cleanup_free_ char *e = NULL;
1331 const char *dn;
1332 Unit *u;
1333 int r = 0;
1334
1335 assert(m);
1336 assert(dev);
1337
1338 dn = udev_device_get_devnode(dev);
1339 if (!dn)
1340 return 0;
1341
1342 r = unit_name_from_path(dn, ".swap", &e);
1343 if (r < 0)
1344 return r;
1345
1346 u = manager_get_unit(m, e);
1347 if (u)
1348 r = swap_set_devnode(SWAP(u), dn);
1349
1350 first = udev_device_get_devlinks_list_entry(dev);
1351 udev_list_entry_foreach(item, first) {
1352 _cleanup_free_ char *n = NULL;
1353 int q;
1354
1355 q = unit_name_from_path(udev_list_entry_get_name(item), ".swap", &n);
1356 if (q < 0)
1357 return q;
1358
1359 u = manager_get_unit(m, n);
1360 if (u) {
1361 q = swap_set_devnode(SWAP(u), dn);
1362 if (q < 0)
1363 r = q;
1364 }
1365 }
1366
1367 return r;
1368 }
1369
1370 int swap_process_device_remove(Manager *m, struct udev_device *dev) {
1371 const char *dn;
1372 int r = 0;
1373 Swap *s;
1374
1375 dn = udev_device_get_devnode(dev);
1376 if (!dn)
1377 return 0;
1378
1379 while ((s = hashmap_get(m->swaps_by_devnode, dn))) {
1380 int q;
1381
1382 q = swap_set_devnode(s, NULL);
1383 if (q < 0)
1384 r = q;
1385 }
1386
1387 return r;
1388 }
1389
1390 static void swap_reset_failed(Unit *u) {
1391 Swap *s = SWAP(u);
1392
1393 assert(s);
1394
1395 if (s->state == SWAP_FAILED)
1396 swap_set_state(s, SWAP_DEAD);
1397
1398 s->result = SWAP_SUCCESS;
1399 }
1400
1401 static int swap_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
1402 return unit_kill_common(u, who, signo, -1, SWAP(u)->control_pid, error);
1403 }
1404
1405 static int swap_get_timeout(Unit *u, usec_t *timeout) {
1406 Swap *s = SWAP(u);
1407 usec_t t;
1408 int r;
1409
1410 if (!s->timer_event_source)
1411 return 0;
1412
1413 r = sd_event_source_get_time(s->timer_event_source, &t);
1414 if (r < 0)
1415 return r;
1416 if (t == USEC_INFINITY)
1417 return 0;
1418
1419 *timeout = t;
1420 return 1;
1421 }
1422
1423 static bool swap_supported(void) {
1424 static int supported = -1;
1425
1426 /* If swap support is not available in the kernel, or we are
1427 * running in a container we don't support swap units, and any
1428 * attempts to starting one should fail immediately. */
1429
1430 if (supported < 0)
1431 supported =
1432 access("/proc/swaps", F_OK) >= 0 &&
1433 detect_container() <= 0;
1434
1435 return supported;
1436 }
1437
1438 static int swap_control_pid(Unit *u) {
1439 Swap *s = SWAP(u);
1440
1441 assert(s);
1442
1443 return s->control_pid;
1444 }
1445
1446 static const char* const swap_exec_command_table[_SWAP_EXEC_COMMAND_MAX] = {
1447 [SWAP_EXEC_ACTIVATE] = "ExecActivate",
1448 [SWAP_EXEC_DEACTIVATE] = "ExecDeactivate",
1449 };
1450
1451 DEFINE_STRING_TABLE_LOOKUP(swap_exec_command, SwapExecCommand);
1452
1453 static const char* const swap_result_table[_SWAP_RESULT_MAX] = {
1454 [SWAP_SUCCESS] = "success",
1455 [SWAP_FAILURE_RESOURCES] = "resources",
1456 [SWAP_FAILURE_TIMEOUT] = "timeout",
1457 [SWAP_FAILURE_EXIT_CODE] = "exit-code",
1458 [SWAP_FAILURE_SIGNAL] = "signal",
1459 [SWAP_FAILURE_CORE_DUMP] = "core-dump",
1460 [SWAP_FAILURE_START_LIMIT_HIT] = "start-limit-hit",
1461 };
1462
1463 DEFINE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
1464
1465 const UnitVTable swap_vtable = {
1466 .object_size = sizeof(Swap),
1467 .exec_context_offset = offsetof(Swap, exec_context),
1468 .cgroup_context_offset = offsetof(Swap, cgroup_context),
1469 .kill_context_offset = offsetof(Swap, kill_context),
1470 .exec_runtime_offset = offsetof(Swap, exec_runtime),
1471 .dynamic_creds_offset = offsetof(Swap, dynamic_creds),
1472
1473 .sections =
1474 "Unit\0"
1475 "Swap\0"
1476 "Install\0",
1477 .private_section = "Swap",
1478
1479 .init = swap_init,
1480 .load = swap_load,
1481 .done = swap_done,
1482
1483 .coldplug = swap_coldplug,
1484
1485 .dump = swap_dump,
1486
1487 .start = swap_start,
1488 .stop = swap_stop,
1489
1490 .kill = swap_kill,
1491
1492 .get_timeout = swap_get_timeout,
1493
1494 .serialize = swap_serialize,
1495 .deserialize_item = swap_deserialize_item,
1496
1497 .active_state = swap_active_state,
1498 .sub_state_to_string = swap_sub_state_to_string,
1499
1500 .may_gc = swap_may_gc,
1501
1502 .sigchld_event = swap_sigchld_event,
1503
1504 .reset_failed = swap_reset_failed,
1505
1506 .control_pid = swap_control_pid,
1507
1508 .bus_vtable = bus_swap_vtable,
1509 .bus_set_property = bus_swap_set_property,
1510 .bus_commit_properties = bus_swap_commit_properties,
1511
1512 .following = swap_following,
1513 .following_set = swap_following_set,
1514
1515 .enumerate = swap_enumerate,
1516 .shutdown = swap_shutdown,
1517 .supported = swap_supported,
1518
1519 .status_message_formats = {
1520 .starting_stopping = {
1521 [0] = "Activating swap %s...",
1522 [1] = "Deactivating swap %s...",
1523 },
1524 .finished_start_job = {
1525 [JOB_DONE] = "Activated swap %s.",
1526 [JOB_FAILED] = "Failed to activate swap %s.",
1527 [JOB_TIMEOUT] = "Timed out activating swap %s.",
1528 },
1529 .finished_stop_job = {
1530 [JOB_DONE] = "Deactivated swap %s.",
1531 [JOB_FAILED] = "Failed deactivating swap %s.",
1532 [JOB_TIMEOUT] = "Timed out deactivating swap %s.",
1533 },
1534 },
1535 };