diff mbox series

[ndctl,1/2] ndctl/region: Support ndctl_region_{get, set}_align()

Message ID 158042415512.3946705.18330231517256727320.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show
Series ndctl: Cross-arch compatible namespace alignment | expand

Commit Message

Dan Williams Jan. 30, 2020, 10:42 p.m. UTC
Add support for the new kernel facility to set space alignment
constraints at the region level. Update the unit tests to bypass the
default 16MiB alignment constraint. Add the new parameter to the default
region listing given how central it is to understanding the valid values
for "create-namespace --size=...".

Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl.c   |   35 +++++++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |    2 ++
 ndctl/libndctl.h       |    2 ++
 ndctl/list.c           |    5 +++++
 test/blk_namespaces.c  |    1 +
 test/dpa-alloc.c       |   10 ++++++++--
 test/dsm-fail.c        |    5 ++++-
 test/libndctl.c        |   10 ++++++++--
 test/parent-uuid.c     |    1 +
 9 files changed, 66 insertions(+), 5 deletions(-)

Comments

Jeff Moyer Feb. 19, 2020, 6:03 p.m. UTC | #1
Dan Williams <dan.j.williams@intel.com> writes:

>  
> +NDCTL_EXPORT unsigned long ndctl_region_get_align(struct ndctl_region *region)
> +{
> +	return region->align;
> +}
> +
> +NDCTL_EXPORT int ndctl_region_set_align(struct ndctl_region *region,
> +		unsigned long align)
> +{
> +	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
> +	char *path = region->region_buf;
> +	int len = region->buf_len, rc;
> +	char buf[SYSFS_ATTR_SIZE];
> +
> +	if (snprintf(path, len, "%s/align", region->region_path) >= len) {
> +		err(ctx, "%s: buffer too small!\n",
> +				ndctl_region_get_devname(region));
> +		return -ENXIO;
> +	}
> +
> +	sprintf(buf, "%#lx\n", align);
> +	rc = sysfs_write_attr(ctx, path, buf);
> +	if (rc < 0)
> +		return rc;
> +
> +	region->align = align;
> +	return 0;
> +}
> +

Missing doctext.  Specifically, there should be a big, fat warning
against changing the region alignment.

-Jeff
Dan Williams Feb. 25, 2020, 11:23 p.m. UTC | #2
On Wed, Feb 19, 2020 at 10:04 AM Jeff Moyer <jmoyer@redhat.com> wrote:
>
> Dan Williams <dan.j.williams@intel.com> writes:
>
> >
> > +NDCTL_EXPORT unsigned long ndctl_region_get_align(struct ndctl_region *region)
> > +{
> > +     return region->align;
> > +}
> > +
> > +NDCTL_EXPORT int ndctl_region_set_align(struct ndctl_region *region,
> > +             unsigned long align)
> > +{
> > +     struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
> > +     char *path = region->region_buf;
> > +     int len = region->buf_len, rc;
> > +     char buf[SYSFS_ATTR_SIZE];
> > +
> > +     if (snprintf(path, len, "%s/align", region->region_path) >= len) {
> > +             err(ctx, "%s: buffer too small!\n",
> > +                             ndctl_region_get_devname(region));
> > +             return -ENXIO;
> > +     }
> > +
> > +     sprintf(buf, "%#lx\n", align);
> > +     rc = sysfs_write_attr(ctx, path, buf);
> > +     if (rc < 0)
> > +             return rc;
> > +
> > +     region->align = align;
> > +     return 0;
> > +}
> > +
>
> Missing doctext.  Specifically, there should be a big, fat warning
> against changing the region alignment.

I don't mind adding one, but is this the right place to document an
API warning? If the audience is future ndctl developers that should be
warned to keep the status quo of not plumbing this capability into
"create-namespace" that's one message. If it's to stop other libndctl
application developers, they'll likely never see this source file.

As it stands there is
Dan Williams Feb. 26, 2020, 5:49 p.m. UTC | #3
On Tue, Feb 25, 2020 at 3:23 PM Dan Williams <dan.j.williams@intel.com> wrote:
>
> On Wed, Feb 19, 2020 at 10:04 AM Jeff Moyer <jmoyer@redhat.com> wrote:
> >
> > Dan Williams <dan.j.williams@intel.com> writes:
> >
> > >
> > > +NDCTL_EXPORT unsigned long ndctl_region_get_align(struct ndctl_region *region)
> > > +{
> > > +     return region->align;
> > > +}
> > > +
> > > +NDCTL_EXPORT int ndctl_region_set_align(struct ndctl_region *region,
> > > +             unsigned long align)
> > > +{
> > > +     struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
> > > +     char *path = region->region_buf;
> > > +     int len = region->buf_len, rc;
> > > +     char buf[SYSFS_ATTR_SIZE];
> > > +
> > > +     if (snprintf(path, len, "%s/align", region->region_path) >= len) {
> > > +             err(ctx, "%s: buffer too small!\n",
> > > +                             ndctl_region_get_devname(region));
> > > +             return -ENXIO;
> > > +     }
> > > +
> > > +     sprintf(buf, "%#lx\n", align);
> > > +     rc = sysfs_write_attr(ctx, path, buf);
> > > +     if (rc < 0)
> > > +             return rc;
> > > +
> > > +     region->align = align;
> > > +     return 0;
> > > +}
> > > +
> >
> > Missing doctext.  Specifically, there should be a big, fat warning
> > against changing the region alignment.
>
> I don't mind adding one, but is this the right place to document an
> API warning? If the audience is future ndctl developers that should be
> warned to keep the status quo of not plumbing this capability into
> "create-namespace" that's one message. If it's to stop other libndctl
> application developers, they'll likely never see this source file.
>
> As it stands there is

Whoops, meant to delete this before sending...
Jeff Moyer Feb. 26, 2020, 9:52 p.m. UTC | #4
Dan Williams <dan.j.williams@intel.com> writes:

>> Missing doctext.  Specifically, there should be a big, fat warning
>> against changing the region alignment.
>
> I don't mind adding one, but is this the right place to document an
> API warning? If the audience is future ndctl developers that should be
> warned to keep the status quo of not plumbing this capability into
> "create-namespace" that's one message. If it's to stop other libndctl
> application developers, they'll likely never see this source file.

I meant to target users of the library (not ndctl developers).  I
thought that was the reason for the doctext on exported interfaces.  No?

I admit, I don't know how users of libndctl figure *anything* out about
how to use it.  :)

-Jeff
Dan Williams Feb. 26, 2020, 10:20 p.m. UTC | #5
On Wed, Feb 26, 2020 at 1:52 PM Jeff Moyer <jmoyer@redhat.com> wrote:
>
> Dan Williams <dan.j.williams@intel.com> writes:
>
> >> Missing doctext.  Specifically, there should be a big, fat warning
> >> against changing the region alignment.
> >
> > I don't mind adding one, but is this the right place to document an
> > API warning? If the audience is future ndctl developers that should be
> > warned to keep the status quo of not plumbing this capability into
> > "create-namespace" that's one message. If it's to stop other libndctl
> > application developers, they'll likely never see this source file.
>
> I meant to target users of the library (not ndctl developers).  I
> thought that was the reason for the doctext on exported interfaces.  No?
>
> I admit, I don't know how users of libndctl figure *anything* out about
> how to use it.  :)
>

Right, that's why I was confused about what you were asking. We
haven't yet formalized a library documentation system, which is bad.
I'll add kernel-doc for this function, and add an item to the backlog
to figure out how to build library-documentation from those
annotations. The developer's guide to date has unfortunately been "go
review how ndctl uses it".
Jeff Moyer Feb. 26, 2020, 10:44 p.m. UTC | #6
Dan Williams <dan.j.williams@intel.com> writes:

> On Wed, Feb 26, 2020 at 1:52 PM Jeff Moyer <jmoyer@redhat.com> wrote:
>>
>> Dan Williams <dan.j.williams@intel.com> writes:
>>
>> >> Missing doctext.  Specifically, there should be a big, fat warning
>> >> against changing the region alignment.
>> >
>> > I don't mind adding one, but is this the right place to document an
>> > API warning? If the audience is future ndctl developers that should be
>> > warned to keep the status quo of not plumbing this capability into
>> > "create-namespace" that's one message. If it's to stop other libndctl
>> > application developers, they'll likely never see this source file.
>>
>> I meant to target users of the library (not ndctl developers).  I
>> thought that was the reason for the doctext on exported interfaces.  No?
>>
>> I admit, I don't know how users of libndctl figure *anything* out about
>> how to use it.  :)
>>
>
> Right, that's why I was confused about what you were asking. We
> haven't yet formalized a library documentation system, which is bad.
> I'll add kernel-doc for this function, and add an item to the backlog
> to figure out how to build library-documentation from those
> annotations. The developer's guide to date has unfortunately been "go
> review how ndctl uses it".

OK, thanks a lot!

-Jeff
diff mbox series

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 469815a8f04b..1046db2bc1af 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -150,6 +150,7 @@  struct ndctl_region {
 	struct kmod_module *module;
 	struct ndctl_bus *bus;
 	int id, num_mappings, nstype, range_index, ro;
+	unsigned long align;
 	int mappings_init;
 	int namespaces_init;
 	int btts_init;
@@ -1109,6 +1110,34 @@  NDCTL_EXPORT int ndctl_region_set_ro(struct ndctl_region *region, int ro)
 	return ro;
 }
 
+NDCTL_EXPORT unsigned long ndctl_region_get_align(struct ndctl_region *region)
+{
+	return region->align;
+}
+
+NDCTL_EXPORT int ndctl_region_set_align(struct ndctl_region *region,
+		unsigned long align)
+{
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len, rc;
+	char buf[SYSFS_ATTR_SIZE];
+
+	if (snprintf(path, len, "%s/align", region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return -ENXIO;
+	}
+
+	sprintf(buf, "%#lx\n", align);
+	rc = sysfs_write_attr(ctx, path, buf);
+	if (rc < 0)
+		return rc;
+
+	region->align = align;
+	return 0;
+}
+
 NDCTL_EXPORT unsigned long long ndctl_region_get_resource(struct ndctl_region *region)
 {
 	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
@@ -2158,6 +2187,12 @@  static void *add_region(void *parent, int id, const char *region_base)
 	else
 		region->target_node = -1;
 
+	sprintf(path, "%s/align", region_base);
+	if (sysfs_read_attr(ctx, path, buf) == 0)
+		region->align = strtoul(buf, NULL, 0);
+	else
+		region->align = ULONG_MAX;
+
 	if (region_set_type(region, path) < 0)
 		goto err_read;
 
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index bf049af1393a..ac575a23d035 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -428,4 +428,6 @@  LIBNDCTL_23 {
 	ndctl_namespace_is_configuration_idle;
 	ndctl_namespace_get_target_node;
 	ndctl_region_get_target_node;
+	ndctl_region_get_align;
+	ndctl_region_set_align;
 } LIBNDCTL_22;
diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
index 208240b20aee..076c34583b7d 100644
--- a/ndctl/libndctl.h
+++ b/ndctl/libndctl.h
@@ -372,6 +372,8 @@  struct ndctl_namespace *ndctl_region_get_namespace_seed(
 		struct ndctl_region *region);
 int ndctl_region_get_ro(struct ndctl_region *region);
 int ndctl_region_set_ro(struct ndctl_region *region, int ro);
+unsigned long ndctl_region_get_align(struct ndctl_region *region);
+int ndctl_region_set_align(struct ndctl_region *region, unsigned long align);
 unsigned long long ndctl_region_get_resource(struct ndctl_region *region);
 struct ndctl_btt *ndctl_region_get_btt_seed(struct ndctl_region *region);
 struct ndctl_pfn *ndctl_region_get_pfn_seed(struct ndctl_region *region);
diff --git a/ndctl/list.c b/ndctl/list.c
index 125a9fe34cb8..3d3ca40d56fe 100644
--- a/ndctl/list.c
+++ b/ndctl/list.c
@@ -95,6 +95,11 @@  static struct json_object *region_to_json(struct ndctl_region *region,
 		goto err;
 	json_object_object_add(jregion, "size", jobj);
 
+	jobj = util_json_object_size(ndctl_region_get_align(region), flags);
+	if (!jobj)
+		goto err;
+	json_object_object_add(jregion, "align", jobj);
+
 	jobj = util_json_object_size(ndctl_region_get_available_size(region),
 			flags);
 	if (!jobj)
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index b587ab93fbb8..437fcad0a8f5 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -54,6 +54,7 @@  static struct ndctl_namespace *create_blk_namespace(int region_fraction,
 	unsigned long long size;
 	uuid_t uuid;
 
+	ndctl_region_set_align(region, sysconf(_SC_PAGESIZE));
 	ndctl_namespace_foreach(region, ndns)
 		if (ndctl_namespace_get_size(ndns) == 0) {
 			seed_ns = ndns;
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 9a9c6b64c504..b757b9ad9c2c 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -58,15 +58,21 @@  static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
 	if (!bus)
 		return -ENXIO;
-	ndctl_region_foreach(bus, region)
+	ndctl_region_foreach(bus, region) {
 		ndctl_region_disable_invalidate(region);
+		ndctl_region_set_align(region, sysconf(_SC_PAGESIZE)
+				* ndctl_region_get_interleave_ways(region));
+	}
 
 	/* init nfit_test.0 */
 	bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER0);
 	if (!bus)
 		return -ENXIO;
-	ndctl_region_foreach(bus, region)
+	ndctl_region_foreach(bus, region) {
 		ndctl_region_disable_invalidate(region);
+		ndctl_region_set_align(region, sysconf(_SC_PAGESIZE)
+				* ndctl_region_get_interleave_ways(region));
+	}
 
 	ndctl_dimm_foreach(bus, dimm) {
 		rc = ndctl_dimm_zero_labels(dimm);
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index 6e812aec008f..b2c51db4aa3a 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -48,8 +48,11 @@  static int reset_bus(struct ndctl_bus *bus)
 	}
 
 	/* set regions back to their default state */
-	ndctl_region_foreach(bus, region)
+	ndctl_region_foreach(bus, region) {
 		ndctl_region_enable(region);
+		ndctl_region_set_align(region, sysconf(_SC_PAGESIZE)
+				* ndctl_region_get_interleave_ways(region));
+	}
 	return 0;
 }
 
diff --git a/test/libndctl.c b/test/libndctl.c
index 02bb9ccaa465..9ad8f87b92dc 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2622,9 +2622,15 @@  static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		}
 	}
 
-	/* set regions back to their default state */
-	ndctl_region_foreach(bus, region)
+	/*
+	 * Enable regions and adjust the space-align to drop the default
+	 * alignment constraints
+	 */
+	ndctl_region_foreach(bus, region) {
 		ndctl_region_enable(region);
+		ndctl_region_set_align(region, sysconf(_SC_PAGESIZE)
+				* ndctl_region_get_interleave_ways(region));
+	}
 
 	/* pfn and dax tests require vmalloc-enabled nfit_test */
 	if (ndctl_test_attempt(test, KERNEL_VERSION(4, 8, 0))) {
diff --git a/test/parent-uuid.c b/test/parent-uuid.c
index 3a63f7244e21..f41ca2c7bd75 100644
--- a/test/parent-uuid.c
+++ b/test/parent-uuid.c
@@ -61,6 +61,7 @@  static struct ndctl_namespace *create_blk_namespace(int region_fraction,
 	struct ndctl_namespace *ndns, *seed_ns = NULL;
 	unsigned long long size;
 
+	ndctl_region_set_align(region, sysconf(_SC_PAGESIZE));
 	ndctl_namespace_foreach(region, ndns)
 		if (ndctl_namespace_get_size(ndns) == 0) {
 			seed_ns = ndns;