From 77b2275dfcebce16ceea17ddf77a7f9d0a41c082 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 31 Jul 2009 11:55:38 +0100 Subject: [PATCH] New commands: swapon-*, swapoff-*, mkswap-file. swapon-device swapoff-device swapon-file swapoff-file swapon-label swapoff-label swapon-uuid swapoff-uuid mkswap-file --- TODO | 5 -- capitests/Makefile.am | 1 + daemon/swap.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++- src/MAX_PROC_NR | 2 +- src/generator.ml | 96 ++++++++++++++++++++++++++++++++++++- 5 files changed, 225 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 0326ad9..28b884f 100644 --- a/TODO +++ b/TODO @@ -172,11 +172,6 @@ Ideas for extra commands pivot_root fts(3) / ftw(3) -Swap space ----------- - -Allow swap space from the guest to be used. Is it a good idea? - Other initrd-* commands ----------------------- diff --git a/capitests/Makefile.am b/capitests/Makefile.am index bb931e6..71928ec 100644 --- a/capitests/Makefile.am +++ b/capitests/Makefile.am @@ -35,6 +35,7 @@ TESTS_ENVIRONMENT = \ SKIP_TEST_NTFS_3G_PROBE=$(shell test -x ../initramfs/bin/ntfs-3g.probe || echo 1) \ SKIP_TEST_CHECKSUM_8=$(shell if test `find ../initramfs -name squashfs.ko | wc -l` -eq 0; then echo 1; fi) \ SKIP_TEST_MKSWAP_U=$(shell r=1; if test -x ../initramfs/sbin/mkswap; then if ../initramfs/sbin/mkswap --help 2>&1 | grep -sq -- -U; then r=0; fi; fi; echo $$r) \ + SKIP_TEST_SWAPON_UUID=$$SKIP_TEST_MKSWAP_U \ SKIP_TEST_SCRUB_FILE=$(shell test -x ../initramfs/usr/bin/scrub || echo 1) \ SKIP_TEST_SCRUB_DEVICE=$(shell test -x ../initramfs/usr/bin/scrub || echo 1) \ $(VG) diff --git a/daemon/swap.c b/daemon/swap.c index faed7f6..db93e57 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -33,8 +33,6 @@ mkswap (char *device, const char *flag, const char *value) char *err; int r; - IS_DEVICE (device, -1); - if (!flag) r = command (NULL, &err, "/sbin/mkswap", device, NULL); else @@ -54,17 +52,145 @@ mkswap (char *device, const char *flag, const char *value) int do_mkswap (char *device) { + IS_DEVICE (device, -1); + return mkswap (device, NULL, NULL); } int do_mkswap_L (char *label, char *device) { + IS_DEVICE (device, -1); + return mkswap (device, "-L", label); } int do_mkswap_U (char *uuid, char *device) { + IS_DEVICE (device, -1); + return mkswap (device, "-U", uuid); } + +int +do_mkswap_file (char *path) +{ + char *buf; + int r; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + buf = sysroot_path (path); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + + r = mkswap (buf, NULL, NULL); + free (buf); + return r; +} + +static int +swaponoff (const char *cmd, const char *flag, const char *value) +{ + char *err; + int r; + + if (!flag) + r = command (NULL, &err, cmd, value, NULL); + else + r = command (NULL, &err, cmd, flag, value, NULL); + + if (r == -1) { + reply_with_error ("%s: %s: %s", cmd, value, err); + free (err); + return -1; + } + + free (err); + + return 0; +} + +int +do_swapon_device (char *device) +{ + IS_DEVICE (device, -1); + + return swaponoff ("/sbin/swapon", NULL, device); +} + +int +do_swapoff_device (char *device) +{ + IS_DEVICE (device, -1); + + return swaponoff ("/sbin/swapoff", NULL, device); +} + +int +do_swapon_file (char *path) +{ + char *buf; + int r; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + buf = sysroot_path (path); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + + r = swaponoff ("/sbin/swapon", NULL, buf); + free (buf); + return r; +} + +int +do_swapoff_file (char *path) +{ + char *buf; + int r; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + buf = sysroot_path (path); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + + r = swaponoff ("/sbin/swapoff", NULL, buf); + free (buf); + return r; +} + +int +do_swapon_label (char *label) +{ + return swaponoff ("/sbin/swapon", "-L", label); +} + +int +do_swapoff_label (char *label) +{ + return swaponoff ("/sbin/swapoff", "-L", label); +} + +int +do_swapon_uuid (char *uuid) +{ + return swaponoff ("/sbin/swapon", "-U", uuid); +} + +int +do_swapoff_uuid (char *uuid) +{ + return swaponoff ("/sbin/swapoff", "-U", uuid); +} diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index fb402ef..f84d24e 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -169 +178 diff --git a/src/generator.ml b/src/generator.ml index e30f5eb..b0b3f06 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2757,7 +2757,11 @@ Create a swap partition on C."); ["mkswap_L"; "hello"; "/dev/sda1"]])], "create a swap partition with a label", "\ -Create a swap partition on C with label C