All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 1/2] ndctl: provide a method to invalidate the bus list
Date: Wed, 23 Mar 2016 18:16:53 -0700	[thread overview]
Message-ID: <20160324011653.20651.27454.stgit@dwillia2-desk3.jf.intel.com> (raw)
In-Reply-To: <20160324011648.20651.33434.stgit@dwillia2-desk3.jf.intel.com>

Consider the following scenario:

    ndctl_new()
    ndctl_bus_foreach()
    <install a new nvdimm-bus provider>
    ndctl_bus_foreach()

...the second ndctl_bus_foreach() will not see any new buses because the
bus results are cached.  When the holder of the context knows that it
has invalidated the bus list it needs to call ndctl_invalidate() so that
subsequent ndctl_bus_foreach() scans are guaranteed to see new buses.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 lib/libndctl.c          |   22 ++++++++++++++++++----
 lib/libndctl.sym        |    1 +
 lib/ndctl/libndctl.h.in |    1 +
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/lib/libndctl.c b/lib/libndctl.c
index 6728508024b0..b628243df651 100644
--- a/lib/libndctl.c
+++ b/lib/libndctl.c
@@ -584,7 +584,7 @@ static void free_region(struct ndctl_region *region)
 	free(region);
 }
 
-static void free_bus(struct ndctl_bus *bus)
+static void free_bus(struct ndctl_bus *bus, struct list_head *head)
 {
 	struct ndctl_dimm *dimm, *_d;
 	struct ndctl_region *region, *_r;
@@ -598,7 +598,8 @@ static void free_bus(struct ndctl_bus *bus)
 	}
 	list_for_each_safe(&bus->regions, region, _r, list)
 		free_region(region);
-	list_del_from(&bus->ctx->busses, &bus->list);
+	if (head)
+		list_del_from(head, &bus->list);
 	free(bus->provider);
 	free(bus->bus_path);
 	free(bus->bus_buf);
@@ -611,7 +612,7 @@ static void free_context(struct ndctl_ctx *ctx)
 	struct ndctl_bus *bus, *_b;
 
 	list_for_each_safe(&ctx->busses, bus, _b, list)
-		free_bus(bus);
+		free_bus(bus, &ctx->busses);
 	free(ctx);
 }
 
@@ -869,9 +870,9 @@ static void parse_nfit_mem_flags(struct ndctl_dimm *dimm, char *flags)
 static int add_bus(void *parent, int id, const char *ctl_base)
 {
 	int rc = -ENOMEM;
-	struct ndctl_bus *bus;
 	char buf[SYSFS_ATTR_SIZE];
 	struct ndctl_ctx *ctx = parent;
+	struct ndctl_bus *bus, *bus_dup;
 	char *path = calloc(1, strlen(ctl_base) + 100);
 
 	if (!path)
@@ -928,6 +929,14 @@ static int add_bus(void *parent, int id, const char *ctl_base)
 		goto err_read;
 	bus->buf_len = strlen(bus->bus_path) + 50;
 
+	ndctl_bus_foreach(ctx, bus_dup)
+		if (strcmp(ndctl_bus_get_provider(bus_dup),
+					ndctl_bus_get_provider(bus)) == 0) {
+			free_bus(bus, NULL);
+			free(path);
+			return 1;
+		}
+
 	list_add(&ctx->busses, &bus->list);
 
 	rc = 0;
@@ -954,6 +963,11 @@ static void busses_init(struct ndctl_ctx *ctx)
 	device_parse(ctx, NULL, "/sys/class/nd", "ndctl", ctx, add_bus);
 }
 
+NDCTL_EXPORT void ndctl_invalidate(struct ndctl_ctx *ctx)
+{
+	ctx->busses_init = 0;
+}
+
 /**
  * ndctl_bus_get_first - retrieve first "nd bus" in the system
  * @ctx: context established by ndctl_new
diff --git a/lib/libndctl.sym b/lib/libndctl.sym
index 25d7b982ecb1..9df2b5a6e89d 100644
--- a/lib/libndctl.sym
+++ b/lib/libndctl.sym
@@ -11,6 +11,7 @@ global:
 	ndctl_unref;
 	ndctl_set_log_priority;
 	ndctl_new;
+	ndctl_invalidate;
 local:
         *;
 };
diff --git a/lib/ndctl/libndctl.h.in b/lib/ndctl/libndctl.h.in
index b16f26dae535..831f7822e91f 100644
--- a/lib/ndctl/libndctl.h.in
+++ b/lib/ndctl/libndctl.h.in
@@ -77,6 +77,7 @@ 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_invalidate(struct ndctl_ctx *ctx);
 void ndctl_set_log_fn(struct ndctl_ctx *ctx,
                   void (*log_fn)(struct ndctl_ctx *ctx,
                                  int priority, const char *file, int line, const char *fn,

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  reply	other threads:[~2016-03-24  1:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-24  1:16 [ndctl PATCH 0/2] fix the nfit_test fallback for 'ndctl bat' Dan Williams
2016-03-24  1:16 ` Dan Williams [this message]
2016-03-24 16:04   ` [ndctl PATCH 1/2] ndctl: provide a method to invalidate the bus list Ross Zwisler
2016-03-24 16:15     ` Dan Williams
2016-03-24  1:16 ` [ndctl PATCH 2/2] ndctl: don't skip bat tests if nfit_test not available Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160324011653.20651.27454.stgit@dwillia2-desk3.jf.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.