From: Richard W.M. Jones Date: Mon, 29 Jun 2009 19:24:47 +0000 (+0100) Subject: Generated code for the 'mkswap*' commands. X-Git-Tag: 1.0.55~46 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=da8ddb2745c3d53c36e3ad7f09836a4c27a4d3e6;p=libguestfs.git Generated code for the 'mkswap*' commands. --- diff --git a/capitests/tests.c b/capitests/tests.c index 455c20e..f1a450b 100644 --- a/capitests/tests.c +++ b/capitests/tests.c @@ -156,6 +156,215 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_mount_loop\" has no tests\n"); } +static int test_mkswap_U_0_skip (void) +{ + const char *str; + + str = getenv ("TEST_ONLY"); + if (str) + return strstr (str, "mkswap_U") == NULL; + str = getenv ("SKIP_TEST_MKSWAP_U_0"); + if (str && strcmp (str, "1") == 0) return 1; + str = getenv ("SKIP_TEST_MKSWAP_U"); + if (str && strcmp (str, "1") == 0) return 1; + return 0; +} + +static int test_mkswap_U_0 (void) +{ + if (test_mkswap_U_0_skip ()) { + printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_U_0"); + return 0; + } + + /* InitNone|InitEmpty for test_mkswap_U_0 */ + { + char device[] = "/dev/sda"; + int r; + suppress_error = 0; + r = guestfs_blockdev_setrw (g, device); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestRun for mkswap_U (0) */ + { + char device[] = "/dev/sda"; + char lines_0[] = ","; + char *lines[] = { + lines_0, + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, device, 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + char uuid[] = "a3a61220-882b-4f61-89f4-cf24dcc7297d"; + char device[] = "/dev/sda1"; + int r; + suppress_error = 0; + r = guestfs_mkswap_U (g, uuid, device); + if (r == -1) + return -1; + } + return 0; +} + +static int test_mkswap_L_0_skip (void) +{ + const char *str; + + str = getenv ("TEST_ONLY"); + if (str) + return strstr (str, "mkswap_L") == NULL; + str = getenv ("SKIP_TEST_MKSWAP_L_0"); + if (str && strcmp (str, "1") == 0) return 1; + str = getenv ("SKIP_TEST_MKSWAP_L"); + if (str && strcmp (str, "1") == 0) return 1; + return 0; +} + +static int test_mkswap_L_0 (void) +{ + if (test_mkswap_L_0_skip ()) { + printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_L_0"); + return 0; + } + + /* InitNone|InitEmpty for test_mkswap_L_0 */ + { + char device[] = "/dev/sda"; + int r; + suppress_error = 0; + r = guestfs_blockdev_setrw (g, device); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestRun for mkswap_L (0) */ + { + char device[] = "/dev/sda"; + char lines_0[] = ","; + char *lines[] = { + lines_0, + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, device, 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + char label[] = "hello"; + char device[] = "/dev/sda1"; + int r; + suppress_error = 0; + r = guestfs_mkswap_L (g, label, device); + if (r == -1) + return -1; + } + return 0; +} + +static int test_mkswap_0_skip (void) +{ + const char *str; + + str = getenv ("TEST_ONLY"); + if (str) + return strstr (str, "mkswap") == NULL; + str = getenv ("SKIP_TEST_MKSWAP_0"); + if (str && strcmp (str, "1") == 0) return 1; + str = getenv ("SKIP_TEST_MKSWAP"); + if (str && strcmp (str, "1") == 0) return 1; + return 0; +} + +static int test_mkswap_0 (void) +{ + if (test_mkswap_0_skip ()) { + printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_0"); + return 0; + } + + /* InitNone|InitEmpty for test_mkswap_0 */ + { + char device[] = "/dev/sda"; + int r; + suppress_error = 0; + r = guestfs_blockdev_setrw (g, device); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestRun for mkswap (0) */ + { + char device[] = "/dev/sda"; + char lines_0[] = ","; + char *lines[] = { + lines_0, + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, device, 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + char device[] = "/dev/sda1"; + int r; + suppress_error = 0; + r = guestfs_mkswap (g, device); + if (r == -1) + return -1; + } + return 0; +} + static int test_initrd_list_0_skip (void) { const char *str; @@ -18764,9 +18973,27 @@ int main (int argc, char *argv[]) /* Cancel previous alarm. */ alarm (0); - nr_tests = 166; + nr_tests = 169; test_num++; + printf ("%3d/%3d test_mkswap_U_0\n", test_num, nr_tests); + if (test_mkswap_U_0 () == -1) { + printf ("test_mkswap_U_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mkswap_L_0\n", test_num, nr_tests); + if (test_mkswap_L_0 () == -1) { + printf ("test_mkswap_L_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mkswap_0\n", test_num, nr_tests); + if (test_mkswap_0 () == -1) { + printf ("test_mkswap_0 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_initrd_list_0\n", test_num, nr_tests); if (test_initrd_list_0 () == -1) { printf ("test_initrd_list_0 FAILED\n"); diff --git a/daemon/actions.h b/daemon/actions.h index 1d412dc..3f8b7a8 100644 --- a/daemon/actions.h +++ b/daemon/actions.h @@ -150,3 +150,6 @@ extern char *do_df_h (void); extern int64_t do_du (char *path); extern char **do_initrd_list (char *path); extern int do_mount_loop (char *file, char *mountpoint); +extern int do_mkswap (char *device); +extern int do_mkswap_L (char *label, char *device); +extern int do_mkswap_U (char *uuid, char *device); diff --git a/daemon/stubs.c b/daemon/stubs.c index 6d7cb0e..48f16c2 100644 --- a/daemon/stubs.c +++ b/daemon/stubs.c @@ -3259,6 +3259,82 @@ done: xdr_free ((xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args); } +static void mkswap_stub (XDR *xdr_in) +{ + int r; + struct guestfs_mkswap_args args; + char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_mkswap_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap"); + return; + } + device = args.device; + + r = do_mkswap (device); + if (r == -1) + /* do_mkswap has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_mkswap_args, (char *) &args); +} + +static void mkswap_L_stub (XDR *xdr_in) +{ + int r; + struct guestfs_mkswap_L_args args; + char *label; + char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_mkswap_L_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap_L"); + return; + } + label = args.label; + device = args.device; + + r = do_mkswap_L (label, device); + if (r == -1) + /* do_mkswap_L has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_mkswap_L_args, (char *) &args); +} + +static void mkswap_U_stub (XDR *xdr_in) +{ + int r; + struct guestfs_mkswap_U_args args; + char *uuid; + char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_mkswap_U_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap_U"); + return; + } + uuid = args.uuid; + device = args.device; + + r = do_mkswap_U (uuid, device); + if (r == -1) + /* do_mkswap_U has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_mkswap_U_args, (char *) &args); +} + void dispatch_incoming_message (XDR *xdr_in) { switch (proc_nr) { @@ -3649,6 +3725,15 @@ void dispatch_incoming_message (XDR *xdr_in) case GUESTFS_PROC_MOUNT_LOOP: mount_loop_stub (xdr_in); break; + case GUESTFS_PROC_MKSWAP: + mkswap_stub (xdr_in); + break; + case GUESTFS_PROC_MKSWAP_L: + mkswap_L_stub (xdr_in); + break; + case GUESTFS_PROC_MKSWAP_U: + mkswap_U_stub (xdr_in); + break; default: reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr); } diff --git a/fish/cmds.c b/fish/cmds.c index c9c0515..a23fe2d 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -116,6 +116,9 @@ void list_commands (void) printf ("%-20s %s\n", "mkdir-p", "create a directory and parents"); printf ("%-20s %s\n", "mkdtemp", "create a temporary directory"); printf ("%-20s %s\n", "mkfs", "make a filesystem"); + printf ("%-20s %s\n", "mkswap", "create a swap partition"); + printf ("%-20s %s\n", "mkswap-L", "create a swap partition with a label"); + printf ("%-20s %s\n", "mkswap-U", "create a swap partition with an explicit UUID"); printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem"); printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device"); printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options"); @@ -636,6 +639,15 @@ void display_command (const char *cmd) if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0) pod2text ("mount-loop - mount a file using the loop device", " mount-loop \n\nThis command lets you mount C (a filesystem image\nin a file) on a mount point. It is entirely equivalent to\nthe command C."); else + if (strcasecmp (cmd, "mkswap") == 0) + pod2text ("mkswap - create a swap partition", " mkswap \n\nCreate a swap partition on C."); + else + if (strcasecmp (cmd, "mkswap_L") == 0 || strcasecmp (cmd, "mkswap-L") == 0) + pod2text ("mkswap-L - create a swap partition with a label", " mkswap-L