From: Richard Jones Date: Mon, 18 May 2009 19:22:36 +0000 (+0100) Subject: Add: lvresize, resize2fs commands. X-Git-Tag: 1.0.27~10 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0695593702b8612b500ff0b3bf800e5934f9b56e;p=libguestfs.git Add: lvresize, resize2fs commands. --- diff --git a/daemon/ext2.c b/daemon/ext2.c index 99c12f0..639ae5d 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -234,3 +234,22 @@ do_get_e2uuid (const char *device) free (out); return p; /* caller frees */ } + +int +do_resize2fs (const char *device) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + r = command (NULL, &err, "/sbin/resize2fs", device, NULL); + if (r == -1) { + reply_with_error ("resize2fs: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/daemon/lvm.c b/daemon/lvm.c index 63a3e7e..40377f1 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -240,6 +240,30 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes) return 0; } +int +do_lvresize (const char *logvol, int mbytes) +{ + char *err; + int r; + char size[64]; + + IS_DEVICE (logvol, -1); + + snprintf (size, sizeof size, "%d", mbytes); + + r = command (NULL, &err, + "/sbin/lvm", "lvresize", + "-L", size, logvol, NULL); + if (r == -1) { + reply_with_error ("lvresize: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + /* Super-dangerous command used for testing. It removes all * LVs, VGs and PVs permanently. */ diff --git a/src/generator.ml b/src/generator.ml index 5717f9b..8ebfafb 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -136,8 +136,7 @@ can easily destroy all your data>." * the virtual machine and block devices are reused between tests. * So don't try testing kill_subprocess :-x * - * Between each test we blockdev-setrw, umount-all, lvm-remove-all - * (except InitNone). + * Between each test we blockdev-setrw, umount-all, lvm-remove-all. * * If the appliance is running an older Linux kernel (eg. RHEL 5) then * devices are named /dev/hda etc. To cope with this, the test suite @@ -2096,6 +2095,33 @@ This command is the same as running C Note that if C is an empty list then B volume groups are activated or deactivated."); + ("lvresize", (RErr, [String "device"; Int "mbytes"]), 105, [], + [InitNone, Always, TestOutput ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; + ["lvcreate"; "LV"; "VG"; "10"]; + ["mkfs"; "ext2"; "/dev/VG/LV"]; + ["mount"; "/dev/VG/LV"; "/"]; + ["write_file"; "/new"; "test content"; "0"]; + ["umount"; "/"]; + ["lvresize"; "/dev/VG/LV"; "20"]; + ["resize2fs"; "/dev/VG/LV"]; + ["mount"; "/dev/VG/LV"; "/"]; + ["cat"; "/new"]], "test content")], + "resize an LVM logical volume", + "\ +This resizes (expands or shrinks) an existing LVM logical +volume to C. When reducing, data in the reduced part +is lost."); + + ("resize2fs", (RErr, [String "device"]), 106, [], + [], (* lvresize tests this *) + "resize an ext2/ext3 filesystem", + "\ +This resizes an ext2 or ext3 filesystem to match the size of +the underlying device."); + ] let all_functions = non_daemon_functions @ daemon_functions @@ -3816,15 +3842,15 @@ and generate_one_test name i (init, prereq, test) = and generate_one_test_body name i test_name init test = (match init with - | InitNone -> () + | InitNone | InitEmpty -> - pr " /* InitEmpty for %s (%d) */\n" name i; + pr " /* InitNone|InitEmpty for %s */\n" test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"]; ["lvm_remove_all"]] | InitBasicFS -> - pr " /* InitBasicFS for %s (%d): create ext2 on /dev/sda1 */\n" name i; + pr " /* InitBasicFS for %s: create ext2 on /dev/sda1 */\n" test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"]; @@ -3833,8 +3859,8 @@ and generate_one_test_body name i test_name init test = ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]] | InitBasicFSonLVM -> - pr " /* InitBasicFSonLVM for %s (%d): create ext2 on /dev/VG/LV */\n" - name i; + pr " /* InitBasicFSonLVM for %s: create ext2 on /dev/VG/LV */\n" + test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"];