diff mbox

[ndctl,v2,08/10] ndctl: refresh region type after init_labels

Message ID 150405910100.22171.16178052413106856140.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 4b80bddf3987
Headers show

Commit Message

Dan Williams Aug. 30, 2017, 2:11 a.m. UTC
Given that init_labels can change a region from hosting namespaces with
an 'nstype' of ND_DEVICE_NAMESPACE_IO to ND_DEVICE_NAMESPACE_PMEM,
arrange for ndctl_dimm_init_labels() to trigger the region to refresh
these attributes when it is next enabled.

Reported-by: Ryon Jensen <ryon.jensen@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/dimm.c     |   12 ++++++++++++
 ndctl/lib/libndctl.c |   11 +++++++++++
 ndctl/lib/private.h  |    2 ++
 3 files changed, 25 insertions(+)
diff mbox

Patch

diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c
index 0fd8d9e30b93..49cf7cb9be6f 100644
--- a/ndctl/lib/dimm.c
+++ b/ndctl/lib/dimm.c
@@ -422,8 +422,10 @@  static int write_label_index(struct ndctl_dimm *dimm,
 NDCTL_EXPORT int ndctl_dimm_init_labels(struct ndctl_dimm *dimm,
 		enum ndctl_namespace_version v)
 {
+	struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm);
 	struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm);
 	struct nvdimm_data *ndd = &dimm->ndd;
+	struct ndctl_region *region;
 	int i;
 
 	if (!ndd->cmd_read) {
@@ -432,6 +434,16 @@  NDCTL_EXPORT int ndctl_dimm_init_labels(struct ndctl_dimm *dimm,
 		return -EINVAL;
 	}
 
+	ndctl_region_foreach(bus, region) {
+		struct ndctl_dimm *match;
+
+		ndctl_dimm_foreach_in_region(region, match)
+			if (match == dimm) {
+				region_flag_refresh(region);
+				break;
+			}
+	}
+
 	for (i = 0; i < 2; i++) {
 		int rc;
 
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 9c65646ac3e9..f52ecfe9d142 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -152,6 +152,7 @@  struct ndctl_region {
 	int btts_init;
 	int pfns_init;
 	int daxs_init;
+	int refresh_type;
 	unsigned long long size;
 	char *region_path;
 	char *region_buf;
@@ -2400,10 +2401,20 @@  NDCTL_EXPORT int ndctl_region_enable(struct ndctl_region *region)
 		return -ENXIO;
 	}
 
+	if (region->refresh_type) {
+		region->refresh_type = 0;
+		region_set_type(region, region->region_buf);
+	}
+
 	dbg(ctx, "%s: enabled\n", devname);
 	return 0;
 }
 
+void region_flag_refresh(struct ndctl_region *region)
+{
+	region->refresh_type = 1;
+}
+
 NDCTL_EXPORT void ndctl_region_cleanup(struct ndctl_region *region)
 {
 	free_stale_namespaces(region);
diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h
index 808e77da07ca..cfea5f75fcde 100644
--- a/ndctl/lib/private.h
+++ b/ndctl/lib/private.h
@@ -101,6 +101,8 @@  struct ndctl_dimm {
 	int format[0];
 };
 
+void region_flag_refresh(struct ndctl_region *region);
+
 /**
  * struct ndctl_ctx - library user context to find "nd" instances
  *