Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: linux-btrfs@vger.kernel.org
Subject: RFC: btrfs-progs json formatting
Date: Tue, 25 Jun 2019 18:09:44 +0200	[thread overview]
Message-ID: <20190625160944.GP8917@twin.jikos.cz> (raw)

Hi,

I'd like to get some feedback on the json output, the overall structure
of the information and naming.

Code: git://github.com/kdave/btrfs-progs.git preview-json

The one example command that supports it is

 $ ./btrfs --format json subvolume show /mnt

The test tests/cli-tests/011-* can demonstrate the capabilities.  The
json formatter and example use are in the top commits, otherwise the
branch contains lot of unrelated changes.

Example output:

{
  "__header": {
    "version": "1"
  },
  "subvolume-show": {
    "path": "subv2",
    "name": "subv2",
    "uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
    "parent_uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
    "received_uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
    "otime": "2019-06-25 17:15:28 +0200",
    "subvolume_id": "256",
    "generation": "6",
    "parent_id": "5",
    "toplevel_id": "5",
    "flags": "-",
    "snapshots": [
    ],
    "quota-group": {
      "qgroupid": "0/256",
      "qgroup-limit-referenced": "-",
      "qgroup-limit-exclusive": "-",
      "qgroup-usage-referenced": "16.00KiB",
      "qgroup-usage-exclusive": "16.00KiB"
    }
  }
}

The current proposal:

- the toplevel group contains 2 maps, one is some generic header, to
  identify version of the format or the version of progs that produces
  it or whatever could be useful and I did not think of it

- the 2nd map is named according to the command that generated the
  output, this is to be able to merge outputs from several commands, or
  to somehow define the contents of the map

Compare that to a simple unnamed group with bunch of values:

{
  "path": "subv2",
  "name": "subv2",
  "uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
  "parent_uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
  "received_uuid": "9178604e-e961-ef40-a5f0-2c109126b209",
  "otime": "2019-06-25 17:15:28 +0200",
  "subvolume_id": "256",
  "generation": "6",
  "parent_id": "5",
  "toplevel_id": "5",
  "flags": "-",
  "snapshots": [
  ],
  "quota-group": {
    "qgroupid": "0/256",
    "qgroup-limit-referenced": "-",
    "qgroup-limit-exclusive": "-",
    "qgroup-usage-referenced": "16.00KiB",
    "qgroup-usage-exclusive": "16.00KiB"
  }
}

That's a bit shorter but makes validation harder. I assume that the
output would be accessed programatically like (python pseudo-code)

---
rawjson = output_of_command("btrfs --format json subvolume show /mnt")
json = Json.from_string(rawjson)

if json["subvolume-show"]["flags"] != "-":
  print("Subvolume %s has flags", json["subvolume-show"]["name"])
---

so the latter is subset of the former, without one map reference.

Once the json format is settled, more commands can be easily converted.

             reply	other threads:[~2019-06-25 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 16:09 David Sterba [this message]
2019-06-25 18:07 ` RFC: btrfs-progs json formatting Hans van Kranenburg
2019-06-26 16:47   ` David Sterba
2019-06-27  8:45     ` Hans van Kranenburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190625160944.GP8917@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox