ndctl: Use max_available_extent for namespaces
PATCH v2 1/1 ndctl: Use max_available_extent for namespaces
The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.
If this is used on a kernel that predates the new attribute, ndctl will fall back to the previous behavior using available_size. While that may still fail, it is more likely to succeed than returning a hard-coded value.
---
v1 -> v2:
Appropriate subject-prefex for ndctl.
Added the fallback to the previous behavior if the attribute is not found, and noted this behavior in the changelog.
ndctl/lib/libndctl.c | 31 +++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 2 ++ ndctl/namespace.c | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +31 -0
@@ -2025,6 +2025,37 @@ 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 ) +return ndctl_region_get_available_size (region); + +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
@@ -123,6 +123,7 @@ global: ndctl_region_get_mappings; ndctl_region_get_size; ndctl_region_get_available_size; + ndctl_region_get_max_available_extent; ndctl_region_get_type; ndctl_region_get_namespace_seed; ndctl_region_get_btt_seed;
ndctl/libndctl.h +2 -0
@@ -338,6 +338,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/namespace.c +1 -1
@@ -764,7 +764,7 @@ 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 || p.size > available) {debug ("%s: insufficient capacity size: %llx avail: %llx\n" , devname, p.size, available);
Signature · 6 lines
2.14.3 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 61 lines · Keith Busch
The
available_sizeattribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.If this is used on a kernel that predates the new attribute, ndctl will fall back to the previous behavior using
available_size. While that may still fail, it is more likely to succeed than returning a hard-coded value.Signed-off-by Keith Busch <[email protected]>---
v1 -> v2:Appropriate subject-prefex for ndctl.
Added the fallback to the previous behavior if the attribute is not found, and noted this behavior in the changelog.
ndctl/lib/libndctl.c | 31 +++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 2 ++ ndctl/namespace.c | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-)ndctl/lib/libndctl.c +0
-0@@ -2025,6 +2025,37 @@ NDCTL_EXPORT unsigned long longndctl_region_get_available_size(
ndctl/lib/libndctl.c +19
-0return 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) {
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 NDCTL_EXPORT unsigned long long ndctl_region_get_available_size( · line 2054
Quoted 2 lines
ndctl/lib/libndctl.c +2
-0+if (sysfs_read_attr (ctx, path, buf) <0 ) +return ndctl_region_get_available_size (region);
Instead of silently falling back to the legacy behavior, perhaps we should print a dbg() warning here so that the user can be prompted to update their kernel.
Quoted 48 lines
ndctl/lib/libndctl.c +4
-0+ +return strtoull (buf,NULL ,0 ); +} + NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct
ndctl_region*region)
{ndctl/lib/libndctl.c +0
-0return region->range_index;ndctl/lib/libndctl.sym +1
-0@@ -123,6 +123,7 @@ global: ndctl_region_get_mappings; ndctl_region_get_size; ndctl_region_get_available_size; + ndctl_region_get_max_available_extent; ndctl_region_get_type; ndctl_region_get_namespace_seed; ndctl_region_get_btt_seed;ndctl/libndctl.h +2
-0@@ -338,6 +338,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); structndctl_namespace*ndctl_region_get_namespace_seed(ndctl/namespace.c +1
-1@@ -764,7 +764,7 @@ 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 || p.size > available) { debug("%s: insufficient capacity size: %llx avail:
Quoted 2 lines
%llx\n",
devname, p.size, available);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm