summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-05-18 20:22:36 +0100
committerRichard Jones <rjones@redhat.com>2009-05-18 20:22:36 +0100
commit0695593702b8612b500ff0b3bf800e5934f9b56e (patch)
tree12873130bf81bb0ba4e409303c15b0ca82d20360
parent38797198d8f60b0a1793d7f228f69c757307ac3f (diff)
downloadlibguestfs-0695593702b8612b500ff0b3bf800e5934f9b56e.tar.gz
libguestfs-0695593702b8612b500ff0b3bf800e5934f9b56e.tar.xz
libguestfs-0695593702b8612b500ff0b3bf800e5934f9b56e.zip
Add: lvresize, resize2fs commands.
-rw-r--r--daemon/ext2.c19
-rw-r--r--daemon/lvm.c24
-rwxr-xr-xsrc/generator.ml40
3 files changed, 76 insertions, 7 deletions
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 99c12f09..639ae5dd 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 63a3e7e5..40377f10 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 5717f9b6..8ebfafbb 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<vgchange -a y|n volgroups...>
Note that if C<volgroups> is an empty list then B<all> 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<mbytes>. 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"];