Skip to contentSkip to conversation

ndctl: Use max_available_extent for namespace

PATCH In review Keith Busch 3 participants 6 messages Jul 24, 2018 – Aug 3, 2018 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ndctl: Use max_available_extent for namespace

The available_size attribute returns all the unused regions, but a memory namespace has to use contiguous free regions. This patch uses the max_available_extent attribute, which reports the largest capacity that can be created when determining what size to allocate.

If the attribute is available, this patch will also report the max available extent in the region list output.

---
v3 -> v4:

Moved the symbol to the appropriate version section of the symbols script.

Report the max available extent in the region list if the attribute exists.

 ndctl/lib/libndctl.c   | 33 +++++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/list.c           |  9 +++++++++
 ndctl/namespace.c      |  4 +++-
 5 files changed, 48 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +33 -0
index 969e4aa..e911ea2 100644
@@ -2107,6 +2107,39 @@ NDCTL_EXPORT unsigned long long ndctl_region_get_available_size(
 	return strtoull(buf, NULL, 0);
 }
 
+NDCTL_EXPORT unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region)
+{
+	unsigned int nstype = ndctl_region_get_nstype(region);
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+
+	switch (nstype) {
+	case ND_DEVICE_NAMESPACE_PMEM:
+	case ND_DEVICE_NAMESPACE_BLK:
+		break;
+	default:
+		return 0;
+	}
+
+	if (snprintf(path, len,
+		     "%s/max_available_extent", region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return ULLONG_MAX;
+	}
+
+	/* fall back to legacy behavior if max extents is not exported */
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
+		dbg(ctx, "max extents attribute not exported on older kernels\n");
+		return ULLONG_MAX;
+	}
+
+	return strtoull(buf, NULL, 0);
+}
+
 NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct ndctl_region *region)
 {
 	return region->range_index;
ndctl/lib/libndctl.sym +1 -0
index 9b36960..2bc312d 100644
@@ -375,4 +375,5 @@ global:
 	ndctl_dimm_get_flags;
 	ndctl_dimm_get_event_flags;
 	ndctl_dimm_is_flag_supported;
+	ndctl_region_get_max_available_extent;
 } LIBNDCTL_16;
ndctl/libndctl.h +2 -0
index 6a6bb0d..a146502 100644
@@ -350,6 +350,8 @@ unsigned int ndctl_region_get_interleave_ways(struct ndctl_region *region);
 unsigned int ndctl_region_get_mappings(struct ndctl_region *region);
 unsigned long long ndctl_region_get_size(struct ndctl_region *region);
 unsigned long long ndctl_region_get_available_size(struct ndctl_region *region);
+unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region);
 unsigned int ndctl_region_get_range_index(struct ndctl_region *region);
 unsigned int ndctl_region_get_type(struct ndctl_region *region);
 struct ndctl_namespace *ndctl_region_get_namespace_seed(
ndctl/list.c +9 -0
index a06edc9..82e88bb 100644
@@ -72,6 +72,7 @@ static struct json_object *region_to_json(struct ndctl_region *region,
 	struct ndctl_interleave_set *iset;
 	struct ndctl_mapping *mapping;
 	unsigned int bb_count = 0;
+	unsigned long long extent;
 	enum ndctl_persistence_domain pd;
 	int numa;
 
@@ -94,6 +95,14 @@ static struct json_object *region_to_json(struct ndctl_region *region,
 		goto err;
 	json_object_object_add(jregion, "available_size", jobj);
 
+	extent = ndctl_region_get_max_available_extent(region);
+	if (extent != ULLONG_MAX) {
+		jobj = util_json_object_size(extent, flags);
+		if (!jobj)
+			goto err;
+		json_object_object_add(jregion, "max_available_extent", jobj);
+	}
+
 	switch (ndctl_region_get_type(region)) {
 	case ND_DEVICE_REGION_PMEM:
 		jobj = json_object_new_string("pmem");
ndctl/namespace.c +3 -1
index fe86d82..cfe0559 100644
@@ -764,7 +764,9 @@ static int namespace_create(struct ndctl_region *region)
 		return -EAGAIN;
 	}
 
-	available = ndctl_region_get_available_size(region);
+	available = ndctl_region_get_max_available_extent(region);
+	if (available == ULLONG_MAX)
+		available = ndctl_region_get_available_size(region);
 	if (!available || p.size > available) {
 		debug("%s: insufficient capacity size: %llx avail: %llx\n",
 			devname, p.size, available);
Signature · 6 lines
2.14.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Tested-by on v4 1/1
#1 lore raw

Hi Keith,

I tested your patch with the following test script. The result is good to me.

Please feel free to add:

Test script:
---
#!/bin/bash -Ex

NDCTL=./ndctl/ndctl

modprobe nfit_test
region=$($NDCTL list -b nfit_test.0 -R -t pmem | jq -r .[].dev | head -1)

available_sz=$($NDCTL list -r $region | jq -r .[].available_size) size=$(( available_sz/4 ))

NS1=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS2=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS3=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)

$NDCTL disable-namespace $NS2
$NDCTL destroy-namespace $NS2

$NDCTL list -r $region

$NDCTL create-namespace -r $region -t pmem
ret=$?

$NDCTL disable-region all
modprobe -r nfit_test

exit $ret
---

Thanks,
Masa

Quoted 125 lines · Keith Busch

The available_size attribute returns all the unused regions, but a memory namespace has to use contiguous free regions. This patch uses the max_available_extent attribute, which reports the largest capacity that can be created when determining what size to allocate.

If the attribute is available, this patch will also report the max available extent in the region list output.

---
v3 -> v4:

Moved the symbol to the appropriate version section of the symbols script.

Report the max available extent in the region list if the attribute exists.

 ndctl/lib/libndctl.c   | 33 +++++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/list.c           |  9 +++++++++
 ndctl/namespace.c      |  4 +++-
 5 files changed, 48 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +33 -0
index 969e4aa..e911ea2 100644
@@ -2107,6 +2107,39 @@ NDCTL_EXPORT unsigned long long ndctl_region_get_available_size(
 	return strtoull(buf, NULL, 0);
 }
 
+NDCTL_EXPORT unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region)
+{
+	unsigned int nstype = ndctl_region_get_nstype(region);
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+
+	switch (nstype) {
+	case ND_DEVICE_NAMESPACE_PMEM:
+	case ND_DEVICE_NAMESPACE_BLK:
+		break;
+	default:
+		return 0;
+	}
+
+	if (snprintf(path, len,
+		     "%s/max_available_extent", region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return ULLONG_MAX;
+	}
+
+	/* fall back to legacy behavior if max extents is not exported */
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
+		dbg(ctx, "max extents attribute not exported on older kernels\n");
+		return ULLONG_MAX;
+	}
+
+	return strtoull(buf, NULL, 0);
+}
+
 NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct ndctl_region *region)
 {
 	return region->range_index;
ndctl/lib/libndctl.sym +1 -0
index 9b36960..2bc312d 100644
@@ -375,4 +375,5 @@ global:
 	ndctl_dimm_get_flags;
 	ndctl_dimm_get_event_flags;
 	ndctl_dimm_is_flag_supported;
+	ndctl_region_get_max_available_extent;
 } LIBNDCTL_16;
ndctl/libndctl.h +2 -0
index 6a6bb0d..a146502 100644
@@ -350,6 +350,8 @@ unsigned int ndctl_region_get_interleave_ways(struct ndctl_region *region);
 unsigned int ndctl_region_get_mappings(struct ndctl_region *region);
 unsigned long long ndctl_region_get_size(struct ndctl_region *region);
 unsigned long long ndctl_region_get_available_size(struct ndctl_region *region);
+unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region);
 unsigned int ndctl_region_get_range_index(struct ndctl_region *region);
 unsigned int ndctl_region_get_type(struct ndctl_region *region);
 struct ndctl_namespace *ndctl_region_get_namespace_seed(
ndctl/list.c +9 -0
index a06edc9..82e88bb 100644
@@ -72,6 +72,7 @@ static struct json_object *region_to_json(struct ndctl_region *region,
 	struct ndctl_interleave_set *iset;
 	struct ndctl_mapping *mapping;
 	unsigned int bb_count = 0;
+	unsigned long long extent;
 	enum ndctl_persistence_domain pd;
 	int numa;
 
@@ -94,6 +95,14 @@ static struct json_object *region_to_json(struct ndctl_region *region,
 		goto err;
 	json_object_object_add(jregion, "available_size", jobj);
 
+	extent = ndctl_region_get_max_available_extent(region);
+	if (extent != ULLONG_MAX) {
+		jobj = util_json_object_size(extent, flags);
+		if (!jobj)
+			goto err;
+		json_object_object_add(jregion, "max_available_extent", jobj);
+	}
+
 	switch (ndctl_region_get_type(region)) {
 	case ND_DEVICE_REGION_PMEM:
 		jobj = json_object_new_string("pmem");
ndctl/namespace.c +0 -0
index fe86d82..cfe0559 100644

ndctl/namespace.c static int namespace_create(struct ndctl_region *region) · line 772

Quoted 10 lines
ndctl/namespace.c +3 -1
@@ -764,7 +764,9 @@ static int namespace_create(struct ndctl_region *region)
 		return -EAGAIN;
 	}
 
-	available = ndctl_region_get_available_size(region);
+	available = ndctl_region_get_max_available_extent(region);
+	if (available == ULLONG_MAX)
+		available = ndctl_region_get_available_size(region);
 	if (!available || p.size > available) {
 		debug("%s: insufficient capacity size: %llx avail: %llx\n",
 			devname, p.size, available);

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#2 lore raw
Quoted 34 lines · Masayoshi Mizuma

Hi Keith,

I tested your patch with the following test script. The result is good to me.

Please feel free to add:

Test script:
---
#!/bin/bash -Ex

NDCTL=./ndctl/ndctl

modprobe nfit_test
region=$($NDCTL list -b nfit_test.0 -R -t pmem | jq -r .[].dev | head -1)

available_sz=$($NDCTL list -r $region | jq -r .[].available_size) size=$(( available_sz/4 ))

NS1=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS2=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS3=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)

$NDCTL disable-namespace $NS2
$NDCTL destroy-namespace $NS2

$NDCTL list -r $region

Quoted 7 lines

$NDCTL create-namespace -r $region -t pmem
ret=$?

$NDCTL disable-region all
modprobe -r nfit_test

exit $ret

Hi Masa,

Thanks for the testing, I will add the Tested-by.

If you also wanted to package up this script as a unit test, I'd be happy to include it. Would be gated on KVER=4.19

Thanks,
-Vishal

Quoted 152 lines

---

Thanks,
Masa

Quoted 146 lines · Keith Busch

The available_size attribute returns all the unused regions, but a memory namespace has to use contiguous free regions. This patch uses the
max_available_extent attribute, which reports the largest capacity that
can be created when determining what size to allocate.

If the attribute is available, this patch will also report the max available extent in the region list output.

---
v3 -> v4:

Moved the symbol to the appropriate version section of the
symbols
script.

Report the max available extent in the region list if the
attribute
exists.

 ndctl/lib/libndctl.c   | 33 +++++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/list.c           |  9 +++++++++
 ndctl/namespace.c      |  4 +++-
 5 files changed, 48 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +0 -0
index 969e4aa..e911ea2 100644
@@ -2107,6 +2107,39 @@ NDCTL_EXPORT unsigned long long

ndctl_region_get_available_size(

ndctl/lib/libndctl.c +1 -0
 	return strtoull(buf, NULL, 0);
 }
 
+NDCTL_EXPORT unsigned long long

ndctl_region_get_max_available_extent(

ndctl/lib/libndctl.c +18 -0
+		struct ndctl_region *region)
+{
+	unsigned int nstype = ndctl_region_get_nstype(region);
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+
+	switch (nstype) {
+	case ND_DEVICE_NAMESPACE_PMEM:
+	case ND_DEVICE_NAMESPACE_BLK:
+		break;
+	default:
+		return 0;
+	}
+
+	if (snprintf(path, len,
+		     "%s/max_available_extent", region-
Quoted 1 line

region_path) >= len) {

ndctl/lib/libndctl.c +6 -0
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return ULLONG_MAX;
+	}
+
+	/* fall back to legacy behavior if max extents is not

exported */

ndctl/lib/libndctl.c +2 -0
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
+		dbg(ctx, "max extents attribute not exported on

older kernels\n");

ndctl/lib/libndctl.c +6 -0
+		return ULLONG_MAX;
+	}
+
+	return strtoull(buf, NULL, 0);
+}
+
 NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct

ndctl_region *region)
{

ndctl/lib/libndctl.c +0 -0
 	return region->range_index;
ndctl/lib/libndctl.sym +1 -0
index 9b36960..2bc312d 100644
@@ -375,4 +375,5 @@ global:
 	ndctl_dimm_get_flags;
 	ndctl_dimm_get_event_flags;
 	ndctl_dimm_is_flag_supported;
+	ndctl_region_get_max_available_extent;
 } LIBNDCTL_16;
ndctl/libndctl.h +0 -0
index 6a6bb0d..a146502 100644
@@ -350,6 +350,8 @@ unsigned int
 ndctl_region_get_interleave_ways(struct ndctl_region *region);
 unsigned int ndctl_region_get_mappings(struct ndctl_region
 *region);
 unsigned long long ndctl_region_get_size(struct ndctl_region
 *region);
 unsigned long long ndctl_region_get_available_size(struct

ndctl_region *region);

ndctl/libndctl.h +2 -0
+unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region);
 unsigned int ndctl_region_get_range_index(struct ndctl_region

*region);
unsigned int ndctl_region_get_type(struct ndctl_region *region); struct ndctl_namespace *ndctl_region_get_namespace_seed(

ndctl/list.c +9 -0
index a06edc9..82e88bb 100644
@@ -72,6 +72,7 @@ static struct json_object *region_to_json(struct
 ndctl_region *region,
 	struct ndctl_interleave_set *iset;
 	struct ndctl_mapping *mapping;
 	unsigned int bb_count = 0;
+	unsigned long long extent;
 	enum ndctl_persistence_domain pd;
 	int numa;
@@ -94,6 +95,14 @@ static struct json_object *region_to_json(struct
 ndctl_region *region,
 		goto err;
 	json_object_object_add(jregion, "available_size", jobj);
 
+	extent = ndctl_region_get_max_available_extent(region);
+	if (extent != ULLONG_MAX) {
+		jobj = util_json_object_size(extent, flags);
+		if (!jobj)
+			goto err;
+		json_object_object_add(jregion,
 "max_available_extent", jobj);
+	}
+
 	switch (ndctl_region_get_type(region)) {
ndctl/list.c +0 -0
 	case ND_DEVICE_REGION_PMEM:
 		jobj = json_object_new_string("pmem");
ndctl/namespace.c +0 -0
index fe86d82..cfe0559 100644
@@ -764,7 +764,9 @@ static int namespace_create(struct ndctl_region
 *region)
 		return -EAGAIN;
 	}
 
Quoted 10 lines
Quoted 10 lines
ndctl/namespace.c +3 -1
-	available = ndctl_region_get_available_size(region);
+	available = ndctl_region_get_max_available_extent(region);
+	if (available == ULLONG_MAX)
+		available =
 ndctl_region_get_available_size(region);
 	if (!available || p.size > available) {

debug("%s: insufficient capacity size: %llx avail:
%llx\n",
devname, p.size, available);

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

Hi Vishal,

Quoted 42 lines · Vishal L
Quoted 40 lines · Masayoshi Mizuma

Hi Keith,

I tested your patch with the following test script. The result is good to me.

Please feel free to add:

Test script:
---
#!/bin/bash -Ex

NDCTL=./ndctl/ndctl

modprobe nfit_test
region=$($NDCTL list -b nfit_test.0 -R -t pmem | jq -r .[].dev | head -1)

available_sz=$($NDCTL list -r $region | jq -r .[].available_size) size=$(( available_sz/4 ))

NS1=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS2=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
NS3=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)

$NDCTL disable-namespace $NS2
$NDCTL destroy-namespace $NS2

$NDCTL list -r $region

$NDCTL create-namespace -r $region -t pmem
ret=$?

$NDCTL disable-region all
modprobe -r nfit_test

Quoted 8 lines
Quoted 1 line

exit $ret

Hi Masa,

Thanks for the testing, I will add the Tested-by.

If you also wanted to package up this script as a unit test, I'd be happy to include it. Would be gated on KVER=4.19

Sounds great :-)
Here is the patch for unit test:

--------
From: Masayoshi Mizuma <[email protected]>
Date: Thu, 2 Aug 2018 16:20:45 -0400
Subject: [PATCH] ndctl, test: add a new unit test for max_available_extent
namespace

Add a new unit test to test max_available_extent namespace. This function is implemented by the following patches.

kernel side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016731.html
    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016732.html

ndctl side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/017176.html
---
 test/Makefile.am                |  3 ++-
 test/max_available_extent_ns.sh | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 test/max_available_extent_ns.sh
test/Makefile.am +2 -1
index 8c55056..9af2464 100644
@@ -22,7 +22,8 @@ TESTS =\
 	firmware-update.sh \
 	ack-shutdown-count-set \
 	rescan-partitions.sh \
-	monitor.sh
+	monitor.sh \
+	max_available_extent_ns.sh
 
 check_PROGRAMS =\
 	libndctl \
test/max_available_extent_ns.sh new file +43 -0

43 lines not on this page · raw message

Signature · 9 lines
2.18.0

Thanks,
Masa

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#4 lore raw

Hi Vishal,

On 08/02/2018 04:42 PM, Masayoshi Mizuma wrote:
...

Quoted 63 lines
Quoted 2 lines

If you also wanted to package up this script as a unit test, I'd be happy to include it. Would be gated on KVER=4.19

Sounds great :-)
Here is the patch for unit test:

--------
From: Masayoshi Mizuma <[email protected]>
Date: Thu, 2 Aug 2018 16:20:45 -0400
Subject: [PATCH] ndctl, test: add a new unit test for max_available_extent
namespace

Add a new unit test to test max_available_extent namespace. This function is implemented by the following patches.

kernel side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016731.html
    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016732.html

ndctl side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/017176.html
---
 test/Makefile.am                |  3 ++-
 test/max_available_extent_ns.sh | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 test/max_available_extent_ns.sh
test/Makefile.am +2 -1
index 8c55056..9af2464 100644
@@ -22,7 +22,8 @@ TESTS =\
 	firmware-update.sh \
 	ack-shutdown-count-set \
 	rescan-partitions.sh \
-	monitor.sh
+	monitor.sh \
+	max_available_extent_ns.sh
 
 check_PROGRAMS =\
 	libndctl \
test/max_available_extent_ns.sh new file +14 -0
new file mode 100755
index 0000000..4a44625
@@ -0,0 +1,43 @@
+#!/bin/bash -Ex
+
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2018, FUJITSU LIMITED. All rights reserved.
+
+rc=77
+
+. ./common
+
+trap 'err $LINENO' ERR
+
+check_min_kver "4.19" || do_skip "kernel $KVER may not support max_available_size"
+
+init()

test/max_available_extent_ns.sh line 23

Quoted 10 lines
test/max_available_extent_ns.sh new file +9 -0
+{
+	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
+	$NDCTL zero-labels -b $NFIT_TEST_BUS0 all
+	$NDCTL enable-region -b $NFIT_TEST_BUS0 all
+}
+
+do_test()
+{
 
+	region=$($NDCTL list -b nfit_test.0 -R -t pmem | jq -r .[].dev | head -1)

nfit_test.0 here should be changed to $NFIT_TEST_BUS0. Please let me know if I should send the v2 patch.

Thanks!
Masa

Quoted 11 lines
test/max_available_extent_ns.sh new file +10 -0
+
+	available_sz=$($NDCTL list -r $region | jq -r .[].available_size)
+	size=$(( available_sz/4 ))
+
+	NS1=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+	NS2=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+	NS3=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+
+	$NDCTL disable-namespace $NS2
+	$NDCTL destroy-namespace $NS2

test/max_available_extent_ns.sh line 43

Quoted 10 lines
test/max_available_extent_ns.sh new file +10 -0
+
+	$NDCTL create-namespace -r $region -t pmem
+}
+
+modprobe nfit_test
+rc=1
+init
+do_test
+_cleanup
+exit 0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#5 lore raw
Quoted 71 lines · Masayoshi Mizuma

Hi Vishal,

On 08/02/2018 04:42 PM, Masayoshi Mizuma wrote:
...

Quoted 67 lines
Quoted 2 lines

If you also wanted to package up this script as a unit test, I'd be happy to include it. Would be gated on KVER=4.19

Sounds great :-)
Here is the patch for unit test:

--------
From: Masayoshi Mizuma <[email protected]>
Date: Thu, 2 Aug 2018 16:20:45 -0400
Subject: [PATCH] ndctl, test: add a new unit test for max_available_extent
namespace

Add a new unit test to test max_available_extent namespace. This function is implemented by the following patches.

kernel side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016731.html
    https://lists.01.org/pipermail/linux-nvdimm/2018-July/016732.html

ndctl side:

    https://lists.01.org/pipermail/linux-nvdimm/2018-July/017176.html
---
 test/Makefile.am                |  3 ++-
 test/max_available_extent_ns.sh | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 test/max_available_extent_ns.sh
test/Makefile.am +2 -1
index 8c55056..9af2464 100644
@@ -22,7 +22,8 @@ TESTS =\
 	firmware-update.sh \
 	ack-shutdown-count-set \
 	rescan-partitions.sh \
-	monitor.sh
+	monitor.sh \
+	max_available_extent_ns.sh
 
 check_PROGRAMS =\
 	libndctl \
test/max_available_extent_ns.sh new file +18 -0
new file mode 100755
index 0000000..4a44625
@@ -0,0 +1,43 @@
+#!/bin/bash -Ex
+
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2018, FUJITSU LIMITED. All rights reserved.
+
+rc=77
+
+. ./common
+
+trap 'err $LINENO' ERR
+
+check_min_kver "4.19" || do_skip "kernel $KVER may not support max_available_size"
+
+init()
+{
+	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
+	$NDCTL zero-labels -b $NFIT_TEST_BUS0 all
+	$NDCTL enable-region -b $NFIT_TEST_BUS0 all
Quoted 8 lines

test/max_available_extent_ns.sh line 23

Quoted 5 lines
test/max_available_extent_ns.sh new file +5 -0
+}
+
+do_test()
+{
+	region=$($NDCTL list -b nfit_test.0 -R -t pmem | jq -r .[].dev | head -1)

nfit_test.0 here should be changed to $NFIT_TEST_BUS0. Please let me know if I should send the v2 patch.

Ah yes good catch. I hadn't gotten around to applying it yet, so yeah please send a v2

Thanks,
-Vishal

Quoted 17 lines

Thanks!
Masa

Quoted 13 lines
test/max_available_extent_ns.sh new file +13 -0
+
+	available_sz=$($NDCTL list -r $region | jq -r .[].available_size)
+	size=$(( available_sz/4 ))
+
+	NS1=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+	NS2=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+	NS3=$($NDCTL create-namespace -r $region -t pmem -s $size | jq -r .dev)
+
+	$NDCTL disable-namespace $NS2
+	$NDCTL destroy-namespace $NS2
+
+	$NDCTL create-namespace -r $region -t pmem
+}
Quoted 8 lines

test/max_available_extent_ns.sh line 43

Quoted 8 lines
test/max_available_extent_ns.sh new file +7 -0
+
+modprobe nfit_test
+rc=1
+init
+do_test
+_cleanup
+exit 0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm