summaryrefslogtreecommitdiff
path: root/cmds-filesystem.c
diff options
context:
space:
mode:
authorZach Brown <zab@redhat.com>2013-07-09 13:24:43 -0700
committerDavid Sterba <dsterba@suse.cz>2013-08-09 14:32:33 +0200
commit876e3f9380d373ba76f9b6d4c08ff84327956abf (patch)
treea5cf9f31f77249dadbd35b57f9a0025876db2e27 /cmds-filesystem.c
parent8e6b7ce746d668d7f2c2b6e0b2075dccf55df01a (diff)
btrfs-progs: per-thread, per-call pretty buffer
We don't need callers to manage string storage for each pretty_sizes() call. We can use a macro to have per-thread and per-call static storage so that pretty_sizes() can be used as many times as needed in printf() arguments without requiring a bunch of supporting variables. This lets us have a natural interface at the cost of requiring __thread and TLS from gcc and a small amount of static storage. This seems better than the current code or doing something with illegible format specifier macros. Signed-off-by: Zach Brown <zab@redhat.com> Acked-by: Wang Shilong <wangs.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r--cmds-filesystem.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index f41a72ab..222e4582 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -111,8 +111,6 @@ static int cmd_df(int argc, char **argv)
for (i = 0; i < sargs->total_spaces; i++) {
char description[80];
- char *total_bytes;
- char *used_bytes;
int written = 0;
u64 flags = sargs->spaces[i].flags;
@@ -155,10 +153,9 @@ static int cmd_df(int argc, char **argv)
written += 7;
}
- total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
- used_bytes = pretty_sizes(sargs->spaces[i].used_bytes);
- printf("%s: total=%s, used=%s\n", description, total_bytes,
- used_bytes);
+ printf("%s: total=%s, used=%s\n", description,
+ pretty_size(sargs->spaces[i].total_bytes),
+ pretty_size(sargs->spaces[i].used_bytes));
}
close(fd);
free(sargs);
@@ -192,7 +189,6 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
char uuidbuf[37];
struct list_head *cur;
struct btrfs_device *device;
- char *super_bytes_used;
u64 devs_found = 0;
u64 total;
@@ -204,25 +200,20 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
else
printf("Label: none ");
- super_bytes_used = pretty_sizes(device->super_bytes_used);
total = device->total_devs;
printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
- (unsigned long long)total, super_bytes_used);
-
- free(super_bytes_used);
+ (unsigned long long)total,
+ pretty_size(device->super_bytes_used));
list_for_each(cur, &fs_devices->devices) {
- char *total_bytes;
- char *bytes_used;
device = list_entry(cur, struct btrfs_device, dev_list);
- total_bytes = pretty_sizes(device->total_bytes);
- bytes_used = pretty_sizes(device->bytes_used);
+
printf("\tdevid %4llu size %s used %s path %s\n",
(unsigned long long)device->devid,
- total_bytes, bytes_used, device->name);
- free(total_bytes);
- free(bytes_used);
+ pretty_size(device->total_bytes),
+ pretty_size(device->bytes_used), device->name);
+
devs_found++;
}
if (devs_found < total) {