diff mbox

[ndctl,4/6] ndctl: add per-context private data

Message ID 148143809712.11895.1329521496424418324.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams Dec. 11, 2016, 6:34 a.m. UTC
Allow an application to attach private data to the context. The initial
motivate is passing the ndctl_test instance into deeper leaf functions
of the unit test.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl-private.h |    1 +
 ndctl/lib/libndctl.c         |   10 ++++++++++
 ndctl/lib/libndctl.sym       |    2 ++
 ndctl/libndctl.h.in          |    2 ++
 4 files changed, 15 insertions(+)
diff mbox

Patch

diff --git a/ndctl/lib/libndctl-private.h b/ndctl/lib/libndctl-private.h
index 778dbb508ead..3e67db058f04 100644
--- a/ndctl/lib/libndctl-private.h
+++ b/ndctl/lib/libndctl-private.h
@@ -144,6 +144,7 @@  struct ndctl_ctx {
 	struct kmod_ctx *kmod_ctx;
 	struct daxctl_ctx *daxctl_ctx;
 	unsigned long timeout;
+	void *private_data;
 };
 
 /**
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ff74c483076e..ea3111eb6c93 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -434,6 +434,16 @@  NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx)
 	return rc;
 }
 
+NDCTL_EXPORT void ndctl_set_private_data(struct ndctl_ctx *ctx, void *data)
+{
+	ctx->private_data = data;
+}
+
+NDCTL_EXPORT void *ndctl_get_private_data(struct ndctl_ctx *ctx)
+{
+	return ctx->private_data;
+}
+
 NDCTL_EXPORT struct daxctl_ctx *ndctl_get_daxctl_ctx(struct ndctl_ctx *ctx)
 {
 	return ctx->daxctl_ctx;
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index 603c386cc2a1..506bf0d67aab 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -12,6 +12,8 @@  global:
 	ndctl_set_log_priority;
 	ndctl_new;
 	ndctl_get_daxctl_ctx;
+	ndctl_set_private_data;
+	ndctl_get_private_data;
 	ndctl_invalidate;
 local:
         *;
diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in
index 9d7219894ed7..d45111775525 100644
--- a/ndctl/libndctl.h.in
+++ b/ndctl/libndctl.h.in
@@ -77,6 +77,8 @@  struct ndctl_ctx;
 struct ndctl_ctx *ndctl_ref(struct ndctl_ctx *ctx);
 struct ndctl_ctx *ndctl_unref(struct ndctl_ctx *ctx);
 int ndctl_new(struct ndctl_ctx **ctx);
+void ndctl_set_private_data(struct ndctl_ctx *ctx, void *data);
+void *ndctl_get_private_data(struct ndctl_ctx *ctx);
 struct daxctl_ctx;
 struct daxctl_ctx *ndctl_get_daxctl_ctx(struct ndctl_ctx *ctx);
 void ndctl_invalidate(struct ndctl_ctx *ctx);