ndctl icon indicating copy to clipboard operation
ndctl copied to clipboard

JSON output consistency

Open etsaur4 opened this issue 6 years ago • 0 comments

There is some output consistency that makes programming/scripting harder. It's has to do with array names.

As a result this simple jq script ".dimm[].dev" won't work all the time. ndctl list -RD | jq ".dimms[].dev"

  • pass if there are regions
  • fail if there are no regions

Example without an array name: - Notice no "dimms" name for array. We explicitly assume the array is associated with DIMMS $ ndctl list --dimms [ { "dev":"nmem1", "id":"8089-a2-1839-000004c8", "handle":257, "phys_id":68, "security":"disabled" }, { "dev":"nmem3", "id":"8089-a2-1835-00001d6e", "handle":4353, "phys_id":82, "security":"disabled" }, { "dev":"nmem0", "id":"8089-a2-1835-00001a21", "handle":1, "phys_id":61, "security":"disabled" }, { "dev":"nmem2", "id":"8089-a2-1835-00001d8d", "handle":4097, "phys_id":75, "security":"disabled" } ]

Example with an array name: - notice dimms and regions label $ ndctl list --dimms --regions { "dimms":[ { "dev":"nmem1", "id":"8089-a2-1839-000004c8", "handle":257, "phys_id":68, "security":"disabled" }, { "dev":"nmem3", "id":"8089-a2-1835-00001d6e", "handle":4353, "phys_id":82, "security":"disabled" }, { "dev":"nmem0", "id":"8089-a2-1835-00001a21", "handle":1, "phys_id":61, "security":"disabled" }, { "dev":"nmem2", "id":"8089-a2-1835-00001d8d", "handle":4097, "phys_id":75, "security":"disabled" } ], "regions":[ { "dev":"region1", "size":135291469824, "available_size":0, "max_available_extent":0, "type":"pmem", "mappings":[ { "dimm":"nmem1", "offset":268435456, "length":135291469824, "position":0 } ], "persistence_domain":"memory_controller" }, { "dev":"region3", "size":135291469824, "available_size":0, "max_available_extent":0, "type":"pmem", "mappings":[ { "dimm":"nmem3", "offset":268435456, "length":135291469824, "position":0 } ], "persistence_domain":"memory_controller" }, { "dev":"region0", "size":135291469824, "available_size":135257915392, "max_available_extent":134200950784, "type":"pmem", "iset_id":2945594469756602914, "mappings":[ { "dimm":"nmem0", "offset":268435456, "length":135291469824, "position":0 } ], "persistence_domain":"memory_controller" }, { "dev":"region2", "size":135291469824, "available_size":0, "max_available_extent":0, "type":"pmem", "mappings":[ { "dimm":"nmem2", "offset":268435456, "length":135291469824, "position":0 } ], "persistence_domain":"memory_controller" } ] }

Example where coding can get extra confused: - notice no dimms and/or regions label $ ndctl disable-region all disabled 4 regions $ ndctl list --dimms --regions [ { "dev":"nmem1", "id":"8089-a2-1839-000004c8", "handle":257, "phys_id":68, "security":"disabled" }, { "dev":"nmem3", "id":"8089-a2-1835-00001d6e", "handle":4353, "phys_id":82, "security":"disabled" }, { "dev":"nmem0", "id":"8089-a2-1835-00001a21", "handle":1, "phys_id":61, "security":"disabled" }, { "dev":"nmem2", "id":"8089-a2-1835-00001d8d", "handle":4097, "phys_id":75, "security":"disabled" } ]

etsaur4 avatar Mar 27 '19 18:03 etsaur4