Page MenuHomeFreeBSD

geom <class> list/status --libxo support
ClosedPublic

Authored by js on Dec 6 2022, 5:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Dec 12, 11:49 AM
Unknown Object (File)
Nov 26 2025, 1:23 AM
Unknown Object (File)
Nov 21 2025, 8:23 PM
Unknown Object (File)
Nov 20 2025, 8:54 AM
Unknown Object (File)
Nov 19 2025, 11:19 AM
Unknown Object (File)
Nov 16 2025, 10:24 AM
Unknown Object (File)
Nov 16 2025, 5:07 AM
Unknown Object (File)
Nov 13 2025, 7:57 AM

Details

Summary

I wanted to parse geom <xxx> list/status output as JSON in a Python script I'm working on and got somewhat disappointed when I found that there was no --libxo support for geom status and list sub commands. So I thought I could add it. I haven't really written anything in C for nearly 8 years so I'm somewhat rusty and it's my first time adding libxo support to something, so please do tell me how to improve this code if you have suggestions.

Some example outputs:

gpart status --libxo json,pretty

{
  "__version": "1",
  "status": [
    {
      "name": "ada0p1",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p2",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p3",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p4",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p5",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p6",
      "status": "    OK",
      "components": [
        {

        }
      ],
      "name": "ada0p7",
      "status": "    OK",
      "components": [
        {

        }
      ]
    }
  ]
}

geom multipath list --libxo json,pretty

{
  "__version": "1",
  "Geoms": [
    {
      "Name": "test",
      "Type": "MANUAL",
      "Mode": "Active/Active",
      "UUID": "(null)",
      "State": "OPTIMAL",
      "Providers": [
        {
          "Name": "multipath/test",
          "Mediasize": 1073741824,
          "Sectorsize": 512,
          "State": "OPTIMAL"
        }
      ],
      "Consumers": [
        {
          "Name": "zvol/zroot/test1",
          "Mediasize": 1073741824,
          "Sectorsize": 512,
          "Stripesize": 8192,
          "Stripesize": 0,
          "Mode": "r1w1e1",
          "State": "ACTIVE"
        },
        {
          "Name": "zvol/zroot/test2",
          "Mediasize": 1073741824,
          "Sectorsize": 512,
          "Stripesize": 8192,
          "Stripesize": 0,
          "Mode": "r1w1e1",
          "State": "ACTIVE"
        }
      ]
    }
  ]
}
Test Plan
  • Make sure output without --libxo looks the same as before
  • libxo makes valid JSON/XML/HTML output

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

js requested review of this revision.Dec 6 2022, 5:38 PM

I've never used libxo to closely review this, but I find it amusing that kernel produces XML for libgeom to parse for geom tool to be able to produce another XML (or JSON or whatever). :)

It would be helpful to have the context available which you can do by getting git to provide it using

git diff -U9999

I also have never used libxo, so am not able to provide feedback on its use here.

Updated diff to include context

@asomers @mckusick @trasz @mav, it seems like there isn't much interest in this patch, so we'll likely close this at the end of the year if there aren't new reviews by then

First, sorry for letting this languish. Though I have not dealt with libxo, I assume that you have ensured that this generates the output that you need. Structurally it is properly added to the geom utility. If there are no issues raised by the other reviewers by Monday October 13th, I will commit it.

This revision is now accepted and ready to land.Oct 7 2025, 9:31 PM

This patch seems to break several testcases in the sys/geom/class/multipath/misc test suite with this output:

===> sys/geom/class/multipath/misc:add
Result:     failed: ACTIVE !=  (ACTIVE != )

This patch seems to break several testcases in the sys/geom/class/multipath/misc test suite with this output:

===> sys/geom/class/multipath/misc:add
Result:     failed: ACTIVE !=  (ACTIVE != )

I'll take a look.

In D37615#1212734, @guest-jsollvander wrote:

This patch seems to break several testcases in the sys/geom/class/multipath/misc test suite with this output:

===> sys/geom/class/multipath/misc:add
Result:     failed: ACTIVE !=  (ACTIVE != )

I'll take a look.

If you can come up with a fix in the next 24 hours, I will wait to apply it. If you cannot do it in that time frame, let me know, and I will revert the commit until you can sort it out.

In D37615#1212734, @guest-jsollvander wrote:

This patch seems to break several testcases in the sys/geom/class/multipath/misc test suite with this output:

===> sys/geom/class/multipath/misc:add
Result:     failed: ACTIVE !=  (ACTIVE != )

I'll take a look.

If you can come up with a fix in the next 24 hours, I will wait to apply it. If you cannot do it in that time frame, let me know, and I will revert the commit until you can sort it out.

I have a fix, I'll open a new PR and tag you for review.

@guest-jsollvander Thanks for doing this!