On Wed, Oct 14, 2015 at 06:13:29PM +0300, Maxim Perevedentsev
wrote:> Added support for getting ext2/3/4 filesystem minimum size.
> This is needed primarily for shrinking images.
>
> Difference to v1: added test, style fixes.
>
> ---
> daemon/ext2.c | 35 +++++++++++++++++++++++++++++++++++
> generator/actions.ml | 14 ++++++++++++++
> src/MAX_PROC_NR | 2 +-
> 3 files changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/daemon/ext2.c b/daemon/ext2.c
> index ebaf0f0..0cd6a66 100644
> --- a/daemon/ext2.c
> +++ b/daemon/ext2.c
> @@ -279,6 +279,41 @@ do_resize2fs_M (const char *device)
> return 0;
> }
>
> +int64_t
> +do_resize2fs_P (const char *device)
> +{
> + CLEANUP_FREE char *err = NULL, *out = NULL;
> + CLEANUP_FREE_STRING_LIST char **lines = NULL;
> + int r;
> + size_t i;
> + char *p;
> + int64_t ret;
> + const char *pattern = "Estimated minimum size of the filesystem:
";
> +
> + r = command (&out, &err, str_resize2fs, "-P", device,
NULL);
> + if (r == -1) {
> + reply_with_error ("%s", err);
> + return -1;
> + }
> +
> + lines = split_lines (out);
> + if (lines == NULL)
> + return -1;
> +
> + for (i = 0; lines[i] != NULL; ++i) {
> + if (verbose)
> + fprintf (stderr, "resize2fs_P: lines[%zu] =
\"%s\"\n", i, lines[i]);
> +
> + if ((p = strstr (lines[i], pattern))) {
> + if (sscanf (p + strlen(pattern), "%" SCNd64, &ret) !=
1)
> + return -1;
> + return ret;
> + }
> + }
> +
> + return -1;
> +}
> +
> /* Takes optional arguments, consult optargs_bitmask. */
> int
> do_e2fsck (const char *device,
> diff --git a/generator/actions.ml b/generator/actions.ml
> index a76b466..78de100 100644
> --- a/generator/actions.ml
> +++ b/generator/actions.ml
> @@ -12751,6 +12751,20 @@ Only some filesystem types support setting UUIDs.
>
> To read the UUID on a filesystem, call C<guestfs_vfs_uuid>." };
>
> + { defaults with
> + name = "resize2fs_P"; added = (1, 31, 17);
> + style = RInt64 "sizeinblocks", [Device "device"],
[];
> + proc_nr = Some 457;
> + tests = [
> + InitBasicFS, Always, TestRun (
> + [["resize2fs_P"; "/dev/sda1"]]), [];
> + ];
> + shortdesc = "get minimum filesystem size in blocks";
> + longdesc = "\
> +Get the minimum filesystem size in blocks.
> +
> +See also L<resize2fs(8)>." };
> +
> ]
>
> (* Non-API meta-commands available only in guestfish.
> diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
> index 8d38505..de2a00c 100644
> --- a/src/MAX_PROC_NR
> +++ b/src/MAX_PROC_NR
> @@ -1 +1 @@
> -456
> +457
> --
ACK. I made some minor adjustments to the 'longdesc' field,
and will push it soon.
Thanks,
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top