Skip to content

btrfs-progs: device usage: implement json format output - #1151

Open
jelly wants to merge 1 commit into
kdave:develfrom
jelly:device-usage-json
Open

btrfs-progs: device usage: implement json format output#1151
jelly wants to merge 1 commit into
kdave:develfrom
jelly:device-usage-json

Conversation

@jelly

@jelly jelly commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Implements JSON formatted output for the device usage command.


Tested on a single nvme btrfs filesystem and raid 1:

[jelle@homeserver ~]$ sudo ./btrfs --format json device usage  /mnt/disk /
{
  "__header": {
    "version": "1"
  },
  "device-usage": [
    {
      "device": "/dev/sda",
      "devid": 1,
      "device_size": 20000588955648,
      "device_slack": 0,
      "chunks": [
        {
          "type": "Data",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 12590696628224
        },
        {
          "type": "Metadata",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 16106127360
        },
        {
          "type": "System",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 8388608
        }
      ],
      "unallocated": 7393777811456
    },
    {
      "device": "/dev/sdb",
      "devid": 2,
      "device_size": 20000588955648,
      "device_slack": 0,
      "chunks": [
        {
          "type": "Data",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 12590696628224
        },
        {
          "type": "Metadata",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 16106127360
        },
        {
          "type": "System",
          "profile": "RAID1",
          "num_stripes": 2,
          "size": 8388608
        }
      ],
      "unallocated": 7393777811456
    },
    {
      "device": "/dev/nvme0n1p2",
      "devid": 1,
      "device_size": 999627103744,
      "device_slack": 3584,
      "chunks": [
        {
          "type": "Data",
          "profile": "single",
          "num_stripes": 1,
          "size": 312467259392
        },
        {
          "type": "Metadata",
          "profile": "DUP",
          "num_stripes": 2,
          "size": 6442450944
        },
        {
          "type": "System",
          "profile": "DUP",
          "num_stripes": 2,
          "size": 134217728
        }
      ],
      "unallocated": 680583172096
    }
  ]
}

Implements JSON formatted output for the `device usage` command.

Signed-off-by: Jelle van der Waa <jvanderwaa@redhat.com>
@jelly

jelly commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Note to self, should update Documentation/dev/dev-json.rst as well.

Comment thread cmds/filesystem-usage.c
if (json) {
fmt_print_end_group(fctx, "chunks");
if (chunkinfos->length > 0)
fmt_print(fctx, "unallocated", devinfo->size - allocated);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have decided to not report 0, similar to how zone_unusable is handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant