Pino Toscano
2018-Apr-12 14:10 UTC
[Libguestfs] [PATCH 0/2] Support for expanding f2fs partitions
Hi, this small patch series exposes one of the utility in f2fs-tools, and use it to expand f2fs partitions in virt-resize. Thanks, Pino Toscano (2): New API: f2fs_expand resize: expand f2fs partitions daemon/Makefile.am | 1 + daemon/f2fs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ generator/actions_core.ml | 9 +++++++++ generator/proc_nr.ml | 1 + lib/MAX_PROC_NR | 2 +- resize/resize.ml | 12 ++++++++++-- 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 daemon/f2fs.c -- 2.14.3
Expose the resize.f2fs utility from f2fs-tools, to expand a f2fs filesystem. --- daemon/Makefile.am | 1 + daemon/f2fs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ generator/actions_core.ml | 9 +++++++++ generator/proc_nr.ml | 1 + lib/MAX_PROC_NR | 2 +- 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 daemon/f2fs.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index ba5d8deed..5df41fd79 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -113,6 +113,7 @@ guestfsd_SOURCES = \ du.c \ echo-daemon.c \ ext2.c \ + f2fs.c \ fallocate.c \ file.c \ fill.c \ diff --git a/daemon/f2fs.c b/daemon/f2fs.c new file mode 100644 index 000000000..74108a3b1 --- /dev/null +++ b/daemon/f2fs.c @@ -0,0 +1,49 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2018 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "daemon.h" +#include "actions.h" +#include "optgroups.h" + +int +optgroup_f2fs_available (void) +{ + return prog_exists ("resize.f2fs"); +} + +int +do_f2fs_expand (const char *device) +{ + CLEANUP_FREE char *err = NULL; + int r; + + r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, + "resize.f2fs", device, NULL); + if (r == -1) { + reply_with_error ("%s", err); + return -1; + } + + return 0; +} diff --git a/generator/actions_core.ml b/generator/actions_core.ml index 544cb6ea7..394576398 100644 --- a/generator/actions_core.ml +++ b/generator/actions_core.ml @@ -9708,4 +9708,13 @@ When growing a partition you will want to grow the filesystem afterwards, but when shrinking, you need to shrink the filesystem before the partition." }; + { defaults with + name = "f2fs_expand"; added = (1, 39, 3); + style = RErr, [String (Device, "device")], []; + optional = Some "f2fs"; + shortdesc = "expand a f2fs filesystem"; + longdesc = "\ +This expands a f2fs filesystem to match the size of the underlying +device." }; + ] diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml index 9e16ab14a..ca73aa361 100644 --- a/generator/proc_nr.ml +++ b/generator/proc_nr.ml @@ -512,6 +512,7 @@ let proc_nr = [ 502, "inspect_get_drive_mappings"; 503, "part_set_gpt_attributes"; 504, "part_get_gpt_attributes"; +505, "f2fs_expand"; ] (* End of list. If adding a new entry, add it at the end of the list diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR index 3091e8eea..f573e999a 100644 --- a/lib/MAX_PROC_NR +++ b/lib/MAX_PROC_NR @@ -1 +1 @@ -504 +505 -- 2.14.3
Pino Toscano
2018-Apr-12 14:10 UTC
[Libguestfs] [PATCH 2/2] resize: expand f2fs partitions
Use resize.f2fs (via f2fs_expand) to expand f2fs filesystems, if available. --- resize/resize.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 1a21e4dff..8e4bb1b16 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -136,7 +136,7 @@ let debug_logvol lv type expand_content_method | PVResize | Resize2fs | NTFSResize | BtrfsFilesystemResize | XFSGrowFS - | Mkswap + | Mkswap | ResizeF2fs let string_of_expand_content_method = function | PVResize -> s_"pvresize" @@ -145,6 +145,7 @@ let string_of_expand_content_method = function | BtrfsFilesystemResize -> s_"btrfs-filesystem-resize" | XFSGrowFS -> s_"xfs_growfs" | Mkswap -> s_"mkswap" + | ResizeF2fs -> s_"resize.f2fs" type unknown_filesystems_mode | UnknownFsIgnore @@ -295,6 +296,8 @@ read the man page virt-resize(1). printf "btrfs\n"; if g#feature_available [| "xfs" |] then printf "xfs\n"; + if g#feature_available [| "f2fs" |] then + printf "f2fs\n"; exit 0 ); @@ -331,10 +334,11 @@ read the man page virt-resize(1). lv_expands, machine_readable, ntfsresize_force, output_format, resizes, resizes_force, shrink, sparse, unknown_fs_mode in - (* Default to true, since NTFS/btrfs/XFS support are usually available. *) + (* Default to true, since NTFS/btrfs/XFS/f2fs support are usually available. *) let ntfs_available = ref true in let btrfs_available = ref true in let xfs_available = ref true in + let f2fs_available = ref true in (* Add a drive to an handle using the elements of the URI, * and few additional parameters. @@ -364,6 +368,7 @@ read the man page virt-resize(1). ntfs_available := g#feature_available [|"ntfsprogs"; "ntfs3g"|]; btrfs_available := g#feature_available [|"btrfs"|]; xfs_available := g#feature_available [|"xfs"|]; + f2fs_available := g#feature_available [|"f2fs"|]; g in @@ -585,6 +590,7 @@ read the man page virt-resize(1). | ContentFS (("ntfs"), _) when !ntfs_available -> true | ContentFS (("btrfs"), _) when !btrfs_available -> true | ContentFS (("xfs"), _) when !xfs_available -> true + | ContentFS (("f2fs"), _) when !f2fs_available -> true | ContentFS _ -> false | ContentExtendedPartition -> false | ContentSwap -> true @@ -600,6 +606,7 @@ read the man page virt-resize(1). | ContentFS (("ntfs"), _) when !ntfs_available -> NTFSResize | ContentFS (("btrfs"), _) when !btrfs_available -> BtrfsFilesystemResize | ContentFS (("xfs"), _) when !xfs_available -> XFSGrowFS + | ContentFS (("f2fs"), _) when !f2fs_available -> ResizeF2fs | ContentFS _ -> assert false | ContentExtendedPartition -> assert false | ContentSwap -> Mkswap @@ -1368,6 +1375,7 @@ read the man page virt-resize(1). if new_uuid <> orig_uuid then warning (f_"UUID in swap partition %s changed from ‘%s’ to ‘%s’") target orig_uuid new_uuid; + | ResizeF2fs -> g#f2fs_expand target in (* Expand partition content as required. *) -- 2.14.3
Pino Toscano
2018-Apr-12 14:25 UTC
[Libguestfs] [PATCH v2 2/2] resize: expand f2fs partitions
Use resize.f2fs (via f2fs_expand) to expand f2fs filesystems, if available. --- resize/resize.ml | 12 ++++++++++-- resize/virt-resize.pod | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 1a21e4dff..8e4bb1b16 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -136,7 +136,7 @@ let debug_logvol lv type expand_content_method | PVResize | Resize2fs | NTFSResize | BtrfsFilesystemResize | XFSGrowFS - | Mkswap + | Mkswap | ResizeF2fs let string_of_expand_content_method = function | PVResize -> s_"pvresize" @@ -145,6 +145,7 @@ let string_of_expand_content_method = function | BtrfsFilesystemResize -> s_"btrfs-filesystem-resize" | XFSGrowFS -> s_"xfs_growfs" | Mkswap -> s_"mkswap" + | ResizeF2fs -> s_"resize.f2fs" type unknown_filesystems_mode | UnknownFsIgnore @@ -295,6 +296,8 @@ read the man page virt-resize(1). printf "btrfs\n"; if g#feature_available [| "xfs" |] then printf "xfs\n"; + if g#feature_available [| "f2fs" |] then + printf "f2fs\n"; exit 0 ); @@ -331,10 +334,11 @@ read the man page virt-resize(1). lv_expands, machine_readable, ntfsresize_force, output_format, resizes, resizes_force, shrink, sparse, unknown_fs_mode in - (* Default to true, since NTFS/btrfs/XFS support are usually available. *) + (* Default to true, since NTFS/btrfs/XFS/f2fs support are usually available. *) let ntfs_available = ref true in let btrfs_available = ref true in let xfs_available = ref true in + let f2fs_available = ref true in (* Add a drive to an handle using the elements of the URI, * and few additional parameters. @@ -364,6 +368,7 @@ read the man page virt-resize(1). ntfs_available := g#feature_available [|"ntfsprogs"; "ntfs3g"|]; btrfs_available := g#feature_available [|"btrfs"|]; xfs_available := g#feature_available [|"xfs"|]; + f2fs_available := g#feature_available [|"f2fs"|]; g in @@ -585,6 +590,7 @@ read the man page virt-resize(1). | ContentFS (("ntfs"), _) when !ntfs_available -> true | ContentFS (("btrfs"), _) when !btrfs_available -> true | ContentFS (("xfs"), _) when !xfs_available -> true + | ContentFS (("f2fs"), _) when !f2fs_available -> true | ContentFS _ -> false | ContentExtendedPartition -> false | ContentSwap -> true @@ -600,6 +606,7 @@ read the man page virt-resize(1). | ContentFS (("ntfs"), _) when !ntfs_available -> NTFSResize | ContentFS (("btrfs"), _) when !btrfs_available -> BtrfsFilesystemResize | ContentFS (("xfs"), _) when !xfs_available -> XFSGrowFS + | ContentFS (("f2fs"), _) when !f2fs_available -> ResizeF2fs | ContentFS _ -> assert false | ContentExtendedPartition -> assert false | ContentSwap -> Mkswap @@ -1368,6 +1375,7 @@ read the man page virt-resize(1). if new_uuid <> orig_uuid then warning (f_"UUID in swap partition %s changed from ‘%s’ to ‘%s’") target orig_uuid new_uuid; + | ResizeF2fs -> g#f2fs_expand target in (* Expand partition content as required. *) diff --git a/resize/virt-resize.pod b/resize/virt-resize.pod index f6aeb5706..720318c4d 100644 --- a/resize/virt-resize.pod +++ b/resize/virt-resize.pod @@ -156,7 +156,8 @@ 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<pvresize(8)>, -L<resize2fs(8)>, L<ntfsresize(8)>, L<btrfs(8)> or L<xfs_growfs(8)>. +L<resize2fs(8)>, L<ntfsresize(8)>, L<btrfs(8)>, L<xfs_growfs(8)>, +or L<resize.f2fs(8)>. However virt-resize does not know how to resize some filesystems, so you would have to online resize them after booting the guest. @@ -407,6 +408,10 @@ Please note that libguestfs I<destroys> the existing swap content by recreating it with C<mkswap>, so this should not be used when the guest is suspended. +=item * + +f2fs filesystems, if libguestfs was compiled with support for f2fs. + =back Note that you cannot use I<--expand> and I<--shrink> together. @@ -775,7 +780,7 @@ This may be due to either of the following: There corresponding filesystem is not available in libguestfs, because there is no proper package in the host with utilities for it. -This is usually the case for C<btrfs>, C<ntfs>, and C<xfs> +This is usually the case for C<btrfs>, C<ntfs>, C<xfs>, and C<f2fs> filesystems. Check the results of: @@ -842,6 +847,7 @@ L<resize2fs(8)>, L<ntfsresize(8)>, L<btrfs(8)>, L<xfs_growfs(8)>, +L<resize.f2fs(8)>, L<virsh(1)>, L<parted(8)>, L<truncate(1)>, -- 2.14.3
Richard W.M. Jones
2018-Apr-16 09:55 UTC
Re: [Libguestfs] [PATCH v2 2/2] resize: expand f2fs partitions
ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Apparently Analagous Threads
- [PATCH v2 2/2] resize: expand f2fs partitions
- [PATCH 1/2] daemon: allow to change the labels of swap partitions
- [PATCH 0/2] Small improvements to f2fs support
- [PATCH 2/2] resize: shrink/expand swap partitions
- [PATCH 0/2] resize: Split out the command line parsing into Cmdline