2014-11-11 09:59:17 +01:00
|
|
|
From 9a0ccdc7cc51262e98fa9345393aa45fd9bba9cb Mon Sep 17 00:00:00 2001
|
2014-05-06 13:39:23 +02:00
|
|
|
From: David Sterba <dsterba@suse.cz>
|
|
|
|
Date: Wed, 23 Apr 2014 18:47:52 +0200
|
2014-11-11 09:59:17 +01:00
|
|
|
Subject: [PATCH 09/42] btrfs-progs: add original 'df' and rename 'disk_usage'
|
2014-05-06 13:39:23 +02:00
|
|
|
to 'usage'
|
|
|
|
|
|
|
|
Add back the original output of the 'btrfs fi df' command for backward
|
|
|
|
compatibility. The rich output is moved from 'disk_usage' to 'usage'.
|
|
|
|
|
|
|
|
Agreed in http://www.spinics.net/lists/linux-btrfs/msg31698.html
|
|
|
|
|
|
|
|
Signed-off-by: David Sterba <dsterba@suse.cz>
|
|
|
|
---
|
|
|
|
cmds-fi-disk_usage.c | 85 ++++++++++------------------------------------------
|
|
|
|
cmds-fi-disk_usage.h | 7 ++---
|
2014-11-11 09:59:17 +01:00
|
|
|
cmds-filesystem.c | 16 ++++------
|
|
|
|
3 files changed, 24 insertions(+), 84 deletions(-)
|
2014-05-06 13:39:23 +02:00
|
|
|
|
2014-11-29 08:39:46 +01:00
|
|
|
Index: btrfs-progs-v3.17.1/cmds-fi-disk_usage.c
|
|
|
|
===================================================================
|
|
|
|
--- btrfs-progs-v3.17.1.orig/cmds-fi-disk_usage.c
|
|
|
|
+++ btrfs-progs-v3.17.1/cmds-fi-disk_usage.c
|
|
|
|
@@ -328,6 +328,8 @@ static struct btrfs_ioctl_space_args *lo
|
2014-05-06 13:39:23 +02:00
|
|
|
return sargs;
|
|
|
|
}
|
|
|
|
|
|
|
|
+/* Not used, keep for later */
|
|
|
|
+#if 0
|
|
|
|
/*
|
|
|
|
* This function computes the space occuped by a *single* RAID5/RAID6 chunk.
|
|
|
|
* The computation is performed on the basis of the number of stripes
|
|
|
|
@@ -465,62 +467,7 @@ exit:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
-
|
|
|
|
-const char * const cmd_filesystem_df_usage[] = {
|
|
|
|
- "btrfs filesystem df [-b] <path> [<path>..]",
|
|
|
|
- "Show space usage information for a mount point(s).",
|
|
|
|
- "",
|
|
|
|
- "-b\tSet byte as unit",
|
|
|
|
- NULL
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-int cmd_filesystem_df(int argc, char **argv)
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
- int flags = DF_HUMAN_UNIT;
|
|
|
|
- int i, more_than_one = 0;
|
|
|
|
-
|
|
|
|
- optind = 1;
|
|
|
|
- while (1) {
|
|
|
|
- char c = getopt(argc, argv, "b");
|
|
|
|
- if (c < 0)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- switch (c) {
|
|
|
|
- case 'b':
|
|
|
|
- flags &= ~DF_HUMAN_UNIT;
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- usage(cmd_filesystem_df_usage);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (check_argc_min(argc - optind, 1))
|
|
|
|
- usage(cmd_filesystem_df_usage);
|
|
|
|
-
|
|
|
|
- for (i = optind; i < argc ; i++) {
|
|
|
|
- int r, fd;
|
|
|
|
- DIR *dirstream = NULL;
|
|
|
|
- if (more_than_one)
|
|
|
|
- printf("\n");
|
|
|
|
-
|
|
|
|
- fd = open_file_or_dir(argv[i], &dirstream);
|
|
|
|
- if (fd < 0) {
|
|
|
|
- fprintf(stderr, "ERROR: can't access to '%s'\n",
|
|
|
|
- argv[1]);
|
|
|
|
- return 12;
|
|
|
|
- }
|
|
|
|
- r = _cmd_disk_free(fd, argv[i], flags);
|
|
|
|
- close_file_or_dir(fd, dirstream);
|
|
|
|
-
|
|
|
|
- if (r)
|
|
|
|
- return r;
|
|
|
|
- more_than_one = 1;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to sort the disk_info structure
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -612,10 +559,10 @@ static u64 calc_chunk_size(struct chunk_
|
2014-05-06 13:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
- * This function print the results of the command btrfs fi disk-usage
|
|
|
|
+ * This function print the results of the command "btrfs fi usage"
|
|
|
|
* in tabular format
|
|
|
|
*/
|
|
|
|
-static void _cmd_filesystem_disk_usage_tabular(int mode,
|
|
|
|
+static void _cmd_filesystem_usage_tabular(int mode,
|
|
|
|
struct btrfs_ioctl_space_args *sargs,
|
|
|
|
struct chunk_info *chunks_info_ptr,
|
|
|
|
int chunks_info_count,
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -795,10 +742,10 @@ static void print_chunk_disks(u64 chunk_
|
2014-05-06 13:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
- * This function print the results of the command btrfs fi disk-usage
|
|
|
|
+ * This function print the results of the command "btrfs fi usage"
|
|
|
|
* in linear format
|
|
|
|
*/
|
|
|
|
-static void _cmd_filesystem_disk_usage_linear(int mode,
|
|
|
|
+static void _cmd_filesystem_usage_linear(int mode,
|
|
|
|
struct btrfs_ioctl_space_args *sargs,
|
|
|
|
struct chunk_info *info_ptr,
|
|
|
|
int info_count,
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -839,7 +786,7 @@ static void _cmd_filesystem_disk_usage_l
|
2014-05-06 13:39:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
-static int _cmd_filesystem_disk_usage(int fd, char *path, int mode, int tabular)
|
|
|
|
+static int _cmd_filesystem_usage(int fd, char *path, int mode, int tabular)
|
|
|
|
{
|
|
|
|
struct btrfs_ioctl_space_args *sargs = 0;
|
|
|
|
int info_count = 0;
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -860,11 +807,11 @@ static int _cmd_filesystem_disk_usage(in
|
2014-05-06 13:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tabular)
|
|
|
|
- _cmd_filesystem_disk_usage_tabular(mode, sargs,
|
|
|
|
+ _cmd_filesystem_usage_tabular(mode, sargs,
|
|
|
|
info_ptr, info_count,
|
|
|
|
disks_info_ptr, disks_info_count);
|
|
|
|
else
|
|
|
|
- _cmd_filesystem_disk_usage_linear(mode, sargs,
|
|
|
|
+ _cmd_filesystem_usage_linear(mode, sargs,
|
|
|
|
info_ptr, info_count,
|
|
|
|
disks_info_ptr, disks_info_count);
|
|
|
|
|
|
|
|
@@ -880,8 +827,8 @@ exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
-const char * const cmd_filesystem_disk_usage_usage[] = {
|
|
|
|
- "btrfs filesystem disk-usage [-b][-t] <path> [<path>..]",
|
|
|
|
+const char * const cmd_filesystem_usage_usage[] = {
|
|
|
|
+ "btrfs filesystem usage [-b][-t] <path> [<path>..]",
|
|
|
|
"Show in which disk the chunks are allocated.",
|
|
|
|
"",
|
|
|
|
"-b\tSet byte as unit",
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -889,7 +836,7 @@ const char * const cmd_filesystem_disk_u
|
2014-05-06 13:39:23 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
-int cmd_filesystem_disk_usage(int argc, char **argv)
|
|
|
|
+int cmd_filesystem_usage(int argc, char **argv)
|
|
|
|
{
|
|
|
|
|
|
|
|
int flags = DF_HUMAN_UNIT;
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -909,12 +856,12 @@ int cmd_filesystem_disk_usage(int argc,
|
2014-05-06 13:39:23 +02:00
|
|
|
tabular = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
- usage(cmd_filesystem_disk_usage_usage);
|
|
|
|
+ usage(cmd_filesystem_usage_usage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_argc_min(argc - optind, 1))
|
|
|
|
- usage(cmd_filesystem_disk_usage_usage);
|
|
|
|
+ usage(cmd_filesystem_usage_usage);
|
|
|
|
|
|
|
|
for (i = optind; i < argc ; i++) {
|
|
|
|
int r, fd;
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -928,7 +875,7 @@ int cmd_filesystem_disk_usage(int argc,
|
2014-05-06 13:39:23 +02:00
|
|
|
argv[1]);
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
- r = _cmd_filesystem_disk_usage(fd, argv[i], flags, tabular);
|
|
|
|
+ r = _cmd_filesystem_usage(fd, argv[i], flags, tabular);
|
|
|
|
close_file_or_dir(fd, dirstream);
|
|
|
|
|
|
|
|
if (r)
|
2014-11-29 08:39:46 +01:00
|
|
|
Index: btrfs-progs-v3.17.1/cmds-fi-disk_usage.h
|
|
|
|
===================================================================
|
|
|
|
--- btrfs-progs-v3.17.1.orig/cmds-fi-disk_usage.h
|
|
|
|
+++ btrfs-progs-v3.17.1/cmds-fi-disk_usage.h
|
2014-05-06 13:39:23 +02:00
|
|
|
@@ -19,11 +19,8 @@
|
|
|
|
#ifndef __CMDS_FI_DISK_USAGE__
|
|
|
|
#define __CMDS_FI_DISK_USAGE__
|
|
|
|
|
|
|
|
-extern const char * const cmd_filesystem_df_usage[];
|
|
|
|
-int cmd_filesystem_df(int argc, char **argv);
|
|
|
|
-
|
|
|
|
-extern const char * const cmd_filesystem_disk_usage_usage[];
|
|
|
|
-int cmd_filesystem_disk_usage(int argc, char **argv);
|
|
|
|
+extern const char * const cmd_filesystem_usage_usage[];
|
|
|
|
+int cmd_filesystem_usage(int argc, char **argv);
|
|
|
|
|
|
|
|
extern const char * const cmd_device_disk_usage_usage[];
|
|
|
|
int cmd_device_disk_usage(int argc, char **argv);
|
2014-11-29 08:39:46 +01:00
|
|
|
Index: btrfs-progs-v3.17.1/cmds-filesystem.c
|
|
|
|
===================================================================
|
|
|
|
--- btrfs-progs-v3.17.1.orig/cmds-filesystem.c
|
|
|
|
+++ btrfs-progs-v3.17.1/cmds-filesystem.c
|
|
|
|
@@ -122,8 +122,7 @@ static const char * const filesystem_cmd
|
2014-05-06 13:39:23 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-11-11 09:59:17 +01:00
|
|
|
-#if 0
|
|
|
|
-static const char * const cmd_df_usage[] = {
|
2014-05-06 13:39:23 +02:00
|
|
|
+static const char * const cmd_filesystem_df_usage[] = {
|
2014-11-11 09:59:17 +01:00
|
|
|
"btrfs filesystem df [options] <path>",
|
|
|
|
"Show space usage information for a mount point",
|
|
|
|
"-b|--raw raw numbers in bytes",
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -137,7 +136,6 @@ static const char * const cmd_df_usage[]
|
|
|
|
"-t|--tbytes show sizes in TiB, or TB with --si",
|
2014-11-11 09:59:17 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
-#endif
|
|
|
|
|
2014-05-06 13:39:23 +02:00
|
|
|
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
|
|
|
{
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -187,7 +185,6 @@ static int get_df(int fd, struct btrfs_i
|
2014-05-06 13:39:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-11 09:59:17 +01:00
|
|
|
-#if 0
|
|
|
|
static void print_df(struct btrfs_ioctl_space_args *sargs, unsigned unit_mode)
|
|
|
|
{
|
|
|
|
u64 i;
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -202,7 +199,7 @@ static void print_df(struct btrfs_ioctl_
|
2014-11-11 09:59:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-static int cmd_df(int argc, char **argv)
|
2014-05-06 13:39:23 +02:00
|
|
|
+static int cmd_filesystem_df(int argc, char **argv)
|
2014-11-11 09:59:17 +01:00
|
|
|
{
|
|
|
|
struct btrfs_ioctl_space_args *sargs = NULL;
|
|
|
|
int ret;
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -255,12 +252,12 @@ static int cmd_df(int argc, char **argv)
|
2014-11-11 09:59:17 +01:00
|
|
|
units_set_mode(&unit_mode, UNITS_BINARY);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
- usage(cmd_df_usage);
|
|
|
|
+ usage(cmd_filesystem_df_usage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-29 08:39:46 +01:00
|
|
|
if (check_argc_exact(argc, optind + 1))
|
2014-11-11 09:59:17 +01:00
|
|
|
- usage(cmd_df_usage);
|
|
|
|
+ usage(cmd_filesystem_df_usage);
|
|
|
|
|
|
|
|
path = argv[optind];
|
|
|
|
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -281,7 +278,6 @@ static int cmd_df(int argc, char **argv)
|
2014-11-11 09:59:17 +01:00
|
|
|
close_file_or_dir(fd, dirstream);
|
|
|
|
return !!ret;
|
|
|
|
}
|
|
|
|
-#endif
|
|
|
|
|
2014-05-06 13:39:23 +02:00
|
|
|
static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label,
|
|
|
|
char *search)
|
2014-11-29 08:39:46 +01:00
|
|
|
@@ -1287,8 +1283,8 @@ const struct cmd_group filesystem_cmd_gr
|
2014-05-06 13:39:23 +02:00
|
|
|
{ "balance", cmd_balance, NULL, &balance_cmd_group, 1 },
|
|
|
|
{ "resize", cmd_resize, cmd_resize_usage, NULL, 0 },
|
|
|
|
{ "label", cmd_label, cmd_label_usage, NULL, 0 },
|
|
|
|
- { "disk-usage", cmd_filesystem_disk_usage,
|
|
|
|
- cmd_filesystem_disk_usage_usage, NULL, 0 },
|
|
|
|
+ { "usage", cmd_filesystem_usage,
|
|
|
|
+ cmd_filesystem_usage_usage, NULL, 0 },
|
|
|
|
|
|
|
|
NULL_CMD_STRUCT
|
|
|
|
}
|