All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: "Verma, Vishal L" <vishal.l.verma@intel.com>
Cc: "linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Subject: Re: [PATCH v3 6/6] ndctl: Add supported_alignments to the JSON output
Date: Tue, 29 Jan 2019 11:43:30 -0800	[thread overview]
Message-ID: <CAPcyv4it4KaUHw0BXsRNsc2M84zLVD=gxY1RaCnq0BhM7K9-0w@mail.gmail.com> (raw)
In-Reply-To: <18cf9fb70675d39ecde5cee456e0e87471047d08.camel@intel.com>

On Tue, Jan 29, 2019 at 11:28 AM Verma, Vishal L
<vishal.l.verma@intel.com> wrote:
>
>
> On Wed, 2019-01-30 at 01:40 +1100, Oliver wrote:
> > On Wed, Jan 16, 2019 at 8:49 PM Oliver O'Halloran <oohall@gmail.com> wrote:
> > > Add the list of supported alignemnts to PFN and DAX namespaces. Also add the
> > > list of supported sector sizes to BTT namespaces.
> > >
> > > Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
> > > ---
> > > Not sure the namespace JSON blob are the best place to put these. The
> > > region might be better, but slightly less accessable to users.
> > > ---
> > >  util/json.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
> > >  1 file changed, 47 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/util/json.c b/util/json.c
> > > index 77c96fb53c27..6c66033bd312 100644
> > > --- a/util/json.c
> > > +++ b/util/json.c
> > > @@ -303,6 +303,38 @@ struct json_object *util_daxctl_devs_to_list(struct daxctl_region *region,
> > >         return jdevs;
> > >  }
> > >
> > > +#define _SZ(get_max, get_elem, type) \
> > > +static struct json_object *type##_build_size_array(struct type *arg)   \
> > > +{                                                              \
> > > +       struct json_object *arr = json_object_new_array();      \
> > > +       int i;                                                  \
> > > +                                                               \
> > > +       if (!arr)                                               \
> > > +               return NULL;                                    \
> > > +                                                               \
> > > +       for (i = 0; i < get_max(arg); i++) {                    \
> > > +               struct json_object *jobj;                       \
> > > +               int64_t align;                                  \
> > > +                                                               \
> > > +               align = get_elem(arg, i);                       \
> > > +               jobj = json_object_new_int64(align);            \
> > > +               if (!jobj)                                      \
> > > +                       goto err;                               \
> > > +               json_object_array_add(arr, jobj);               \
> > > +       }                                                       \
> > > +                                                               \
> > > +       return arr;                                             \
> > > +err:                                                           \
> > > +       json_object_put(arr);                                   \
> > > +       return NULL;                                            \
> > > +}
> > > +#define SZ(type, kind) _SZ(ndctl_##type##_get_num_##kind##s, \
> > > +                          ndctl_##type##_get_supported_##kind, ndctl_##type)
> > > +SZ(pfn, alignment)
> > > +SZ(dax, alignment)
> > > +SZ(btt, sector_size)
> > > +//SZ(namespace, sector_size)
> > > +
> > >  struct json_object *util_daxctl_region_to_json(struct daxctl_region *region,
> > >                 const char *ident, unsigned long flags)
> > >  {
> > > @@ -739,7 +771,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
> > >  {
> > >         struct json_object *jndns = json_object_new_object();
> > >         enum ndctl_pfn_loc loc = NDCTL_PFN_LOC_NONE;
> > > -       struct json_object *jobj, *jbbs = NULL;
> > > +       struct json_object *jobj, *jbbs = NULL, *size_array = NULL;
> > >         const char *locations[] = {
> > >                 [NDCTL_PFN_LOC_NONE] = "none",
> > >                 [NDCTL_PFN_LOC_RAM] = "mem",
> > > @@ -749,6 +781,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
> > >         unsigned int sector_size = UINT_MAX;
> > >         enum ndctl_namespace_mode mode;
> > >         const char *bdev = NULL, *name;
> > > +       const char *size_array_name;
> > >         unsigned int bb_count = 0;
> > >         struct ndctl_btt *btt;
> > >         struct ndctl_pfn *pfn;
> > > @@ -936,6 +969,19 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
> > >                         json_object_object_add(jndns, "numa_node", jobj);
> > >         }
> > >
> > > +       if (pfn) {
> > > +               size_array_name = "supported_alignments";
> > > +               size_array = ndctl_pfn_build_size_array(pfn);
> > > +       } else if (dax) {
> > > +               size_array_name = "supported_alignments";
> > > +               size_array = ndctl_dax_build_size_array(dax);
> > > +       } else if (btt) {
> > > +               size_array_name = "supported sector sizes";
> > > +               size_array = ndctl_btt_build_size_array(btt);
> > > +       }
> > > +       if (size_array)
> > > +               json_object_object_add(jndns, size_array_name, size_array);
> >
> > So apparently I forgot to run the `make check` on v3 because this
> > completely breaks the unit tests.
> >
> > The problem is that the tests rely on a sed script to parse the JSON
> > blob into shell variables. That works when the JSON blob only contains
> > scalars (and strings with no spaces), but it chokes when confronted
> > with a JSON array. I can't think of any simple ways to fix it other
> > than using a real JSON parser (jq?). Should I drop this patch for now?
> > I don't mind doing a real fix if you don't mind waiting a bit longer
> > :)
>
> I think we should just fix the tests to properly parse json - we use jq
> in several other places, and if something that didn't use jq breaks the
> hackier sed/eval stuff, we should just take the chance to fix that in
> the test. If this is a larger piece of work, I'm happy to defer it to
> the next release. The other semi-related question might be, should we
> always show the supported alignments array, or should hide it under one
> or more -v verbosity levels. How often would a user need to know these?
> If the array is now shown at the default non-verbose level, then maybe
> the parsing problem goes away until a future time :)
>

Yeah, if gating this property on UTIL_JSON_VERBOSE fixes the unit test
that seems like the fastest way forward for now.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  reply	other threads:[~2019-01-29 19:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16  9:49 [PATCH v3 1/6] libndctl: Use the supported_alignment attribute Oliver O'Halloran
2019-01-16  9:49 ` [PATCH v3 2/6] ndctl/namespace: Check for seed namespaces earlier Oliver O'Halloran
2019-01-16  9:49 ` [PATCH v3 3/6] ndctl/namespace: Use seed alignment as the default Oliver O'Halloran
2019-01-16  9:49 ` [PATCH v3 4/6] ndctl/namespace: Validate alignment from the {pfn|dax} seed Oliver O'Halloran
2019-01-16  9:49 ` [PATCH v3 5/6] ndctl: Add alignment to the namespace JSON output Oliver O'Halloran
2019-01-16  9:49 ` [PATCH v3 6/6] ndctl: Add supported_alignments to the " Oliver O'Halloran
2019-01-29 14:40   ` Oliver
2019-01-29 19:28     ` Verma, Vishal L
2019-01-29 19:43       ` Dan Williams [this message]
2019-01-23 19:32 ` [PATCH v3 1/6] libndctl: Use the supported_alignment attribute Verma, Vishal L
2019-01-28 23:11   ` Oliver
2019-01-28 23:15     ` Verma, Vishal L
2019-01-28 23:20       ` Oliver
2019-01-28 23:22         ` Verma, Vishal L

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='CAPcyv4it4KaUHw0BXsRNsc2M84zLVD=gxY1RaCnq0BhM7K9-0w@mail.gmail.com' \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.