[ndctl,35/36] ndctl/lib/namespace: Fix resource retrieval after size change
diff mbox series

Message ID 158300779047.2141307.11160238427930235188.stgit@dwillia2-desk3.amr.corp.intel.com
State New
Headers show
Series
  • Multiple topics / backlog for v68
Related show

Commit Message

Dan Williams Feb. 29, 2020, 8:23 p.m. UTC
The namespaceX.Y/resource attribute returns -1 while the namespace does
not have capacity allocated. While it is valid after setting the size
the library has already cached the error value. Teach
ndctl_namespace_set_size() to refresh ->resource.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch
diff mbox series

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index a996bff66fb2..ee737cbbfe3e 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -4484,6 +4484,24 @@  static int namespace_set_size(struct ndctl_namespace *ndns,
 		return rc;
 
 	ndns->size = size;
+
+	/*
+	 * A size change event invalidates / establishes 'resource', try
+	 * to refresh it.
+	 */
+	if (snprintf(path, len, "%s/resource", ndns->ndns_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_namespace_get_devname(ndns));
+		ndns->resource = ULLONG_MAX;
+		return 0;
+	}
+
+	if (sysfs_read_attr(ctx, path, buf) < 0) {
+		ndns->resource = ULLONG_MAX;
+		return 0;
+	}
+
+	ndns->resource = strtoull(buf, NULL, 0);
 	return 0;
 }