On Mon, Mar 19, 2018 at 4:45 PM, Dave Jiang <dave.ji...@intel.com> wrote:
> Adding helper functions to iterate through sysfs region persistence domain
> attribute. The region will display the domain with the most persistence for 
> the
> region.  The bus will display the domain attribute with the least persistence
> amongst all the regions. ndctl_bus_get_persistence_domain() and
> ndctl_region_get_persistence_domain are exported. ndctl list will also display
> the region persistence domain as well.
>
> Signed-off-by: Dave Jiang <dave.ji...@intel.com>
> ---
> v2:
> - Simplied scanning of persistence domain from Ross's comments.
>
>  ndctl/lib/libndctl.c   |   87 
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  ndctl/lib/libndctl.sym |    2 +
>  ndctl/lib/private.h    |    1 +
>  ndctl/libndctl.h       |   10 ++++++
>  ndctl/list.c           |   16 +++++++++
>  5 files changed, 116 insertions(+)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index a165e697..8f4e1745 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -180,6 +180,7 @@ struct ndctl_region {
>         } iset;
>         FILE *badblocks;
>         struct badblock bb;
> +       enum ndctl_persistence persistence_domain;
>  };
>
>  /**
> @@ -755,6 +756,7 @@ static void *add_bus(void *parent, int id, const char 
> *ctl_base)
>         list_head_init(&bus->regions);
>         bus->ctx = ctx;
>         bus->id = id;
> +       bus->persistence_domain = PERSISTENCE_UNKNOWN;
>
>         sprintf(path, "%s/dev", ctl_base);
>         if (sysfs_read_attr(ctx, path, buf) < 0
> @@ -916,6 +918,17 @@ NDCTL_EXPORT struct ndctl_bus 
> *ndctl_bus_get_by_provider(struct ndctl_ctx *ctx,
>         return NULL;
>  }
>
> +NDCTL_EXPORT unsigned int
> +ndctl_bus_get_persistence_domain(struct ndctl_bus *bus)
> +{
> +       struct ndctl_region *region;
> +
> +       /* iterate through region to get the region persistence domain */
> +       ndctl_region_foreach(bus, region) {}
> +
> +       return bus->persistence_domain;

There's no need to add this property to the 'struct ndctl_bus' object.
Just do the aggregation live in the ndctl_region_foreach() loop that
you already have.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to