summaryrefslogtreecommitdiff
path: root/cmds-inspect.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-07-20 17:31:43 +0200
committerDavid Sterba <dsterba@suse.com>2015-08-31 19:25:08 +0200
commit5b1c5b88786297a8582c8ad211289a090f8e8435 (patch)
tree19634859381e6f2d7b1c74a10cdedec9790591be /cmds-inspect.c
parent934dd0e1f720b3c1feb06e8b5db519f6bb2565e8 (diff)
btrfs-progs: inspect: add command min-dev-size
Previously in 'filesystem resize get_min_size', now 'inspect-internal min-dev-size'. We'd like to avoid cluttering the 'resize' syntax further. The test has been updated to exercise the new option. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-inspect.c')
-rw-r--r--cmds-inspect.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c
index 05f1ccf..1823584 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -20,13 +20,14 @@
#include <stdint.h>
#include <sys/ioctl.h>
#include <errno.h>
+#include <getopt.h>
#include "kerncompat.h"
#include "ioctl.h"
#include "utils.h"
#include "ctree.h"
#include "send-utils.h"
-
+#include "disk-io.h"
#include "commands.h"
#include "btrfs-list.h"
@@ -481,7 +482,7 @@ static void adjust_dev_min_size(struct list_head *extents,
}
}
-static int get_min_size(int fd, DIR *dirstream, u64 devid)
+static int print_min_dev_size(int fd, u64 devid)
{
int ret = 1;
/*
@@ -572,13 +573,64 @@ static int get_min_size(int fd, DIR *dirstream, u64 devid)
printf("%llu bytes (%s)\n", min_size, pretty_size(min_size));
ret = 0;
out:
- close_file_or_dir(fd, dirstream);
free_dev_extent_list(&extents);
free_dev_extent_list(&holes);
return ret;
}
+static const char* const cmd_inspect_min_dev_size_usage[] = {
+ "btrfs inspect-internal min-dev-size [options] <path>",
+ "Get the minimum size the device can be shrunk to. The",
+ "device id 1 is used by default.",
+ "--id DEVID specify the device id to query",
+ NULL
+};
+
+static int cmd_inspect_min_dev_size(int argc, char **argv)
+{
+ int ret;
+ int fd = -1;
+ DIR *dirstream = NULL;
+ u64 devid = 1;
+
+ while (1) {
+ int c;
+ enum { GETOPT_VAL_DEVID = 256 };
+ static const struct option long_options[] = {
+ { "id", required_argument, NULL, GETOPT_VAL_DEVID },
+ {NULL, 0, NULL, 0}
+ };
+
+ c = getopt_long(argc, argv, "", long_options, NULL);
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case GETOPT_VAL_DEVID:
+ devid = arg_strtou64(optarg);
+ break;
+ default:
+ usage(cmd_inspect_min_dev_size_usage);
+ }
+ }
+ if (check_argc_exact(argc - optind, 1))
+ usage(cmd_inspect_min_dev_size_usage);
+
+ fd = open_file_or_dir(argv[optind], &dirstream);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind]);
+ ret = -ENOENT;
+ goto out;
+ }
+
+ ret = print_min_dev_size(fd, devid);
+out:
+ close_file_or_dir(fd, dirstream);
+
+ return !!ret;
+}
+
static const char inspect_cmd_group_info[] =
"query various internal information";
@@ -591,6 +643,8 @@ const struct cmd_group inspect_cmd_group = {
{ "subvolid-resolve", cmd_subvolid_resolve,
cmd_subvolid_resolve_usage, NULL, 0 },
{ "rootid", cmd_rootid, cmd_rootid_usage, NULL, 0 },
+ { "min-dev-size", cmd_inspect_min_dev_size,
+ cmd_inspect_min_dev_size_usage, NULL, 0 },
NULL_CMD_STRUCT
}
};