btrfs-progs: fi df: extended information about profile types

There's more information available in sysfs
(/sys/fs/btrfs/FSID/allocation) that we can print in 'fi df'. This is
still meant for debugging or deeper analysis of the filesystem, the
values need to be correctly interpreted with respect to the profiles,
persistence and other conditonal features.

The extended output is not printed by default and for now is behind the
verbosity options:

$ btrfs -vv fi df /mnt
Data, single: total=47.06GiB, used=25.32GiB
System, DUP: total=32.00MiB, used=16.00KiB
Metadata, DUP: total=1.44GiB, used=961.20MiB
GlobalReserve, single: total=125.62MiB, used=0.00B
Data:
  bg_reclaim_threshold                   0%
  bytes_may_use                     8.00KiB
  bytes_pinned                        0.00B
  bytes_readonly                   64.00KiB
  bytes_reserved                      0.00B
  bytes_used                       25.32GiB
  bytes_zone_unusable                 0.00B
  chunk_size                       10.00GiB
  disk_total                       47.06GiB
  disk_used                        25.32GiB
  total_bytes                      47.06GiB
Metadata:
  bg_reclaim_threshold                   0%
  bytes_may_use                   126.62MiB
  bytes_pinned                        0.00B
  bytes_readonly                      0.00B
  bytes_reserved                      0.00B
  bytes_used                      961.20MiB
  bytes_zone_unusable                 0.00B
  chunk_size                      256.00MiB
  disk_total                        2.88GiB
  disk_used                         1.88GiB
  total_bytes                       1.44GiB
System:
  bg_reclaim_threshold                   0%
  bytes_may_use                       0.00B
  bytes_pinned                        0.00B
  bytes_readonly                      0.00B
  bytes_reserved                      0.00B
  bytes_used                       16.00KiB
  bytes_zone_unusable                 0.00B
  chunk_size                       32.00MiB
  disk_total                       64.00MiB
  disk_used                        32.00KiB
  total_bytes                      32.00MiB

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-06-13 18:09:57 +02:00 committed by Qu Wenruo
parent 85b896472b
commit 4c4e6f1053

View file

@ -31,6 +31,7 @@
#include <limits.h>
#include <dirent.h>
#include <stdbool.h>
#include <ctype.h>
#include <uuid/uuid.h>
#include "libbtrfsutil/btrfsutil.h"
#include "kernel-lib/list.h"
@ -53,6 +54,7 @@
#include "common/device-utils.h"
#include "common/open-utils.h"
#include "common/parse-utils.h"
#include "common/sysfs-utils.h"
#include "common/string-utils.h"
#include "common/filesystem-utils.h"
#include "common/format-output.h"
@ -81,6 +83,41 @@ static const char * const cmd_filesystem_df_usage[] = {
NULL
};
static void print_df_by_type(int fd, unsigned int unit_mode) {
static const char *files[] = {
"bg_reclaim_threshold",
"bytes_may_use",
"bytes_pinned",
"bytes_readonly",
"bytes_reserved",
"bytes_used",
"bytes_zone_unusable",
"chunk_size",
"disk_total",
"disk_used",
"total_bytes",
};
char path[PATH_MAX] = { 0 };
const char *types[] = { "data", "metadata", "mixed", "system" };
u64 tmp;
int ret;
for (int ti = 0; ti < ARRAY_SIZE(types); ti++) {
for (int i = 0; i < ARRAY_SIZE(files); i++) {
path_cat3_out(path, "allocation", types[ti], files[i]);
ret = sysfs_read_fsid_file_u64(fd, path, &tmp);
if (ret < 0)
continue;
if (i == 0)
pr_verbose(LOG_INFO, "%c%s:\n", toupper(types[ti][0]), types[ti] + 1);
if (strcmp(files[i], "bg_reclaim_threshold") == 0)
pr_verbose(LOG_INFO, " %-24s %14llu%%\n", files[i], tmp);
else
pr_verbose(LOG_INFO, " %-24s %16s\n", files[i], pretty_size_mode(tmp, unit_mode));
}
}
}
static void print_df_text(int fd, struct btrfs_ioctl_space_args *sargs, unsigned unit_mode)
{
u64 i;
@ -100,6 +137,7 @@ static void print_df_text(int fd, struct btrfs_ioctl_space_args *sargs, unsigned
(ok ? ", zone_unusable=" : ""),
(ok ? pretty_size_mode(unusable, unit_mode) : ""));
}
print_df_by_type(fd, unit_mode);
}
static const struct rowspec filesystem_df_rowspec[] = {