From: Richard W.M. Jones Date: Thu, 14 Jul 2011 10:39:11 +0000 (+0100) Subject: resize: Add btrfs support to virt-resize (RHBZ#721275). X-Git-Tag: 1.11.17~2 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=f2d816573ffba9c5a2022ac5b3b6514eaf02d0f7;p=libguestfs.git resize: Add btrfs support to virt-resize (RHBZ#721275). --- diff --git a/resize/resize.ml b/resize/resize.ml index 8e7057c..d4455eb 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -144,8 +144,9 @@ read the man page virt-resize(1). lv_expands, ntfsresize_force, output_format, quiet, resizes, resizes_force, shrink -(* Default to true, since NTFS support is usually available. *) +(* Default to true, since NTFS and btrfs support are usually available. *) let ntfs_available = ref true +let btrfs_available = ref true (* Add in and out disks to the handle and launch. *) let connect_both_disks () = @@ -163,6 +164,7 @@ let connect_both_disks () = (* Update features available in the daemon. *) ntfs_available := feature_available g [|"ntfsprogs"; "ntfs3g"|]; + btrfs_available := feature_available g [|"btrfs"|]; g @@ -373,12 +375,14 @@ let lvs = (* These functions tell us if we know how to expand the content of * a particular partition or LV, and what method to use. *) -type expand_content_method = PVResize | Resize2fs | NTFSResize +type expand_content_method = + | PVResize | Resize2fs | NTFSResize | BtrfsFilesystemResize let string_of_expand_content_method = function | PVResize -> "pvresize" | Resize2fs -> "resize2fs" | NTFSResize -> "ntfsresize" + | BtrfsFilesystemResize -> "btrfs-filesystem-resize" let can_expand_content = if expand_content then @@ -387,6 +391,7 @@ let can_expand_content = | ContentPV _ -> true | ContentFS (("ext2"|"ext3"|"ext4"), _) -> true | ContentFS (("ntfs"), _) when !ntfs_available -> true + | ContentFS (("btrfs"), _) when !btrfs_available -> true | ContentFS (_, _) -> false else fun _ -> false @@ -398,6 +403,7 @@ let expand_content_method = | ContentPV _ -> PVResize | ContentFS (("ext2"|"ext3"|"ext4"), _) -> Resize2fs | ContentFS (("ntfs"), _) when !ntfs_available -> NTFSResize + | ContentFS (("btrfs"), _) when !btrfs_available -> BtrfsFilesystemResize | ContentFS (_, _) -> assert false else fun _ -> assert false @@ -920,6 +926,14 @@ let () = g#e2fsck_f target; g#resize2fs target | NTFSResize -> g#ntfsresize_opts ~force:ntfsresize_force target + | BtrfsFilesystemResize -> + (* Complicated ... Btrfs forces us to mount the filesystem + * in order to resize it. + *) + assert (Array.length (g#mounts ()) = 0); + g#mount_options "" target "/"; + g#btrfs_filesystem_resize "/"; + g#umount "/" in (* Expand partition content as required. *) diff --git a/resize/virt-resize.pod b/resize/virt-resize.pod index 6a93e46..a071110 100644 --- a/resize/virt-resize.pod +++ b/resize/virt-resize.pod @@ -133,9 +133,9 @@ to fill the rest of the available space: If the expanded partition in the image contains a filesystem or LVM PV, then if virt-resize knows how, it will resize the contents, the equivalent of calling a command such as L, -L or L. However virt-resize does not -know how to resize some filesystems, so you would have to online -resize them after booting the guest. +L, L or L. However virt-resize +does not know how to resize some filesystems, so you would have to +online resize them after booting the guest. Other options are covered below. @@ -274,6 +274,10 @@ LVM PVs (physical volumes). virt-resize does not usually resize anything inside the PV, but see the I<--LV-expand> option. The user could also resize LVs as desired after boot. +=item * + +Btrfs filesystems, if libguestfs was compiled with support for btrfs. + =back Note that you cannot use I<--expand> and I<--shrink> together. @@ -530,6 +534,7 @@ L, L, L, L, +L, L, L, L,