summaryrefslogtreecommitdiffstats
path: root/daemon/swap.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-08-28 04:00:52 -0400
committerRichard W.M. Jones <rjones@redhat.com>2012-08-28 04:44:05 -0400
commitf23a5c468e959f86df89e2a4e8aa9160eca532f8 (patch)
tree9af42fe1783d6c550f0764bb9df84d6a6e730341 /daemon/swap.c
parentc2ac512f12cc87d27d04f69cb70b2c5e4c4a9bc5 (diff)
downloadlibguestfs-f23a5c468e959f86df89e2a4e8aa9160eca532f8.tar.gz
libguestfs-f23a5c468e959f86df89e2a4e8aa9160eca532f8.tar.xz
libguestfs-f23a5c468e959f86df89e2a4e8aa9160eca532f8.zip
Modified API: mkswap now takes optional arguments.
Add optional label and uuid arguments, and deprecate mkswap-L and mkswap-U. This also adds a call to udev_settle after creating the swap device. This is an attempt to workaround the following problem seen in Koji and Rawhide: libguestfs: trace: mkswap_L "swapit" "/dev/sda1" libguestfs: send_to_daemon: 72 bytes: 00 00 00 44 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 83 | 00 00 00 00 | ... guestfsd: main_loop: proc 210 (part_disk) took 2.28 seconds guestfsd: main_loop: new request, len 0x44 mkswap -f -L swapit /dev/sda1 libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 83 | 00 00 00 01 | 00 12 37 cf | ... libguestfs: trace: mkswap_L = 0 libguestfs: trace: swapon_label "swapit" libguestfs: send_to_daemon: 56 bytes: 00 00 00 34 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 ae | 00 00 00 00 | ... guestfsd: main_loop: proc 131 (mkswap_L) took 0.77 seconds guestfsd: main_loop: new request, len 0x34 swapon -L swapit swapon: cannot find the device for swapit guestfsd: error: swapit: swapon: cannot find the device for swapit libguestfs: recv_from_daemon: 100 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 ae | 00 00 00 01 | 00 12 37 d0 | ... libguestfs: trace: swapon_label = -1 (error) swapon_label: swapit: swapon: cannot find the device for swapit test_swapon_label_0 FAILED
Diffstat (limited to 'daemon/swap.c')
-rw-r--r--daemon/swap.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/daemon/swap.c b/daemon/swap.c
index 51dbbe48..8f1b59de 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -56,56 +56,71 @@ optgroup_linuxfsuuid_available (void)
return av;
}
-static int
-mkswap (const char *device, const char *flag, const char *value)
+/* Takes optional arguments, consult optargs_bitmask. */
+int
+do_mkswap (const char *device, const char *label, const char *uuid)
{
- char *err;
+ const size_t MAX_ARGS = 64;
+ const char *argv[MAX_ARGS];
+ size_t i = 0;
int r;
+ char *err;
- if (!flag)
- r = command (NULL, &err, "mkswap", "-f", device, NULL);
- else
- r = command (NULL, &err, "mkswap", "-f", flag, value, device, NULL);
+ ADD_ARG (argv, i, "mkswap");
+ ADD_ARG (argv, i, "-f");
+
+ if (optargs_bitmask & GUESTFS_MKSWAP_LABEL_BITMASK) {
+ if (strlen (label) > SWAP_LABEL_MAX) {
+ reply_with_error ("%s: Linux swap labels are limited to %d bytes",
+ label, SWAP_LABEL_MAX);
+ return -1;
+ }
+
+ ADD_ARG (argv, i, "-L");
+ ADD_ARG (argv, i, label);
+ }
+ if (optargs_bitmask & GUESTFS_MKSWAP_UUID_BITMASK) {
+ ADD_ARG (argv, i, "-U");
+ ADD_ARG (argv, i, uuid);
+ }
+
+ ADD_ARG (argv, i, device);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (NULL, &err, argv);
if (r == -1) {
- reply_with_error ("%s", err);
+ reply_with_error ("%s: %s", device, err);
free (err);
return -1;
}
free (err);
- return 0;
-}
+ udev_settle ();
-int
-do_mkswap (const char *device)
-{
- return mkswap (device, NULL, NULL);
+ return 0;
}
int
do_mkswap_L (const char *label, const char *device)
{
- if (strlen (label) > SWAP_LABEL_MAX) {
- reply_with_error ("%s: Linux swap labels are limited to %d bytes",
- label, SWAP_LABEL_MAX);
- return -1;
- }
-
- return mkswap (device, "-L", label);
+ optargs_bitmask = GUESTFS_MKSWAP_LABEL_BITMASK;
+ return do_mkswap (device, label, NULL);
}
int
do_mkswap_U (const char *uuid, const char *device)
{
- return mkswap (device, "-U", uuid);
+ optargs_bitmask = GUESTFS_MKSWAP_UUID_BITMASK;
+ return do_mkswap (device, NULL, uuid);
}
int
do_mkswap_file (const char *path)
{
char *buf;
+ char *err;
int r;
buf = sysroot_path (path);
@@ -114,8 +129,17 @@ do_mkswap_file (const char *path)
return -1;
}
- r = mkswap (buf, NULL, NULL);
+ r = command (NULL, &err, "mkswap", "-f", buf, NULL);
free (buf);
+
+ if (r == -1) {
+ reply_with_error ("%s: %s", path, err);
+ free (err);
+ return -1;
+ }
+
+ free (err);
+
return r;
}