diff mbox series

[ndctl,2/3] libdaxctl: add an API to check if a device is active

Message ID 20210331031229.384068-3-vishal.l.verma@intel.com (mailing list archive)
State New
Headers show
Series daxctl-device fixes | expand

Commit Message

Verma, Vishal L March 31, 2021, 3:12 a.m. UTC
Add an API to check whether a daxctl device is active in system-ram
mode. This would be used from libndctl during
ndctl_namespace_disable_safe(), so that we don't disable/destroy an
underlying namespace while the memory is active and online.

Reported-by: Chunye Xu <chunye.xu@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 daxctl/lib/libdaxctl.c   | 10 ++++++++++
 daxctl/libdaxctl.h       |  1 +
 daxctl/lib/libdaxctl.sym |  1 +
 3 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 879f7e6..860bd9c 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -1665,3 +1665,13 @@  DAXCTL_EXPORT int daxctl_dev_will_auto_online_memory(struct daxctl_dev *dev)
 	/* match both "online" and "online_movable" */
 	return !strncmp(buf, "online", 6);
 }
+
+DAXCTL_EXPORT int daxctl_dev_has_online_memory(struct daxctl_dev *dev)
+{
+	struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
+
+	if (mem)
+		return daxctl_memory_is_online(mem);
+	else
+		return 0;
+}
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index 30ab51a..683ae9c 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -72,6 +72,7 @@  int daxctl_dev_enable_devdax(struct daxctl_dev *dev);
 int daxctl_dev_enable_ram(struct daxctl_dev *dev);
 int daxctl_dev_get_target_node(struct daxctl_dev *dev);
 int daxctl_dev_will_auto_online_memory(struct daxctl_dev *dev);
+int daxctl_dev_has_online_memory(struct daxctl_dev *dev);
 
 struct daxctl_memory;
 struct daxctl_memory *daxctl_dev_get_memory(struct daxctl_dev *dev);
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index 892e393..a13e93d 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -95,4 +95,5 @@  global:
 LIBDAXCTL_9 {
 global:
 	daxctl_dev_will_auto_online_memory;
+	daxctl_dev_has_online_memory;
 } LIBDAXCTL_8;