All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 03/14] libnvdimm, namespace: refactor uuid_show() into a namespace_to_uuid() helper
Date: Fri, 07 Oct 2016 09:38:57 -0700	[thread overview]
Message-ID: <147585833727.22349.4151646734474522098.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <147585832067.22349.6376523541984122050.stgit@dwillia2-desk3.amr.corp.intel.com>

The ability to translate a generic struct device pointer into a
namespace uuid is a useful utility as we go to unify the blk and pmem
label scanning paths.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/nvdimm/namespace_devs.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 9f4188c78120..0e62f46755e7 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1032,22 +1032,27 @@ static ssize_t size_show(struct device *dev,
 }
 static DEVICE_ATTR(size, S_IRUGO, size_show, size_store);
 
-static ssize_t uuid_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
+static u8 *namespace_to_uuid(struct device *dev)
 {
-	u8 *uuid;
-
 	if (is_namespace_pmem(dev)) {
 		struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);
 
-		uuid = nspm->uuid;
+		return nspm->uuid;
 	} else if (is_namespace_blk(dev)) {
 		struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);
 
-		uuid = nsblk->uuid;
+		return nsblk->uuid;
 	} else
-		return -ENXIO;
+		return ERR_PTR(-ENXIO);
+}
+
+static ssize_t uuid_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	u8 *uuid = namespace_to_uuid(dev);
 
+	if (IS_ERR(uuid))
+		return PTR_ERR(uuid);
 	if (uuid)
 		return sprintf(buf, "%pUb\n", uuid);
 	return sprintf(buf, "\n");

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

WARNING: multiple messages have this Message-ID (diff)
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@ml01.01.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 03/14] libnvdimm, namespace: refactor uuid_show() into a namespace_to_uuid() helper
Date: Fri, 07 Oct 2016 09:38:57 -0700	[thread overview]
Message-ID: <147585833727.22349.4151646734474522098.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <147585832067.22349.6376523541984122050.stgit@dwillia2-desk3.amr.corp.intel.com>

The ability to translate a generic struct device pointer into a
namespace uuid is a useful utility as we go to unify the blk and pmem
label scanning paths.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/nvdimm/namespace_devs.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 9f4188c78120..0e62f46755e7 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1032,22 +1032,27 @@ static ssize_t size_show(struct device *dev,
 }
 static DEVICE_ATTR(size, S_IRUGO, size_show, size_store);
 
-static ssize_t uuid_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
+static u8 *namespace_to_uuid(struct device *dev)
 {
-	u8 *uuid;
-
 	if (is_namespace_pmem(dev)) {
 		struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);
 
-		uuid = nspm->uuid;
+		return nspm->uuid;
 	} else if (is_namespace_blk(dev)) {
 		struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);
 
-		uuid = nsblk->uuid;
+		return nsblk->uuid;
 	} else
-		return -ENXIO;
+		return ERR_PTR(-ENXIO);
+}
+
+static ssize_t uuid_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	u8 *uuid = namespace_to_uuid(dev);
 
+	if (IS_ERR(uuid))
+		return PTR_ERR(uuid);
 	if (uuid)
 		return sprintf(buf, "%pUb\n", uuid);
 	return sprintf(buf, "\n");

  parent reply	other threads:[~2016-10-07 16:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-07 16:38 [PATCH 00/14] libnvdimm: support sub-divisions of pmem for 4.9 Dan Williams
2016-10-07 16:38 ` Dan Williams
2016-10-07 16:38 ` [PATCH 01/14] libnvdimm, region: move region-mapping input-paramters to nd_mapping_desc Dan Williams
2016-10-07 16:38   ` Dan Williams
2016-10-07 16:38 ` [PATCH 02/14] libnvdimm, label: convert label tracking to a linked list Dan Williams
2016-10-07 16:38   ` Dan Williams
2016-10-07 16:38 ` Dan Williams [this message]
2016-10-07 16:38   ` [PATCH 03/14] libnvdimm, namespace: refactor uuid_show() into a namespace_to_uuid() helper Dan Williams
2016-10-07 16:39 ` [PATCH 04/14] libnvdimm, namespace: unify blk and pmem label scanning Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 05/14] tools/testing/nvdimm: support for sub-dividing a pmem region Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 06/14] libnvdimm, namespace: allow multiple pmem-namespaces per region at scan time Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 07/14] libnvdimm, namespace: sort namespaces by dpa at init Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 08/14] libnvdimm, region: update nd_region_available_dpa() for multi-pmem support Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 09/14] libnvdimm, namespace: expand pmem device naming scheme for multi-pmem Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 10/14] libnvdimm, namespace: update label implementation " Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 11/14] libnvdimm, namespace: enable allocation of multiple pmem namespaces Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 12/14] libnvdimm, namespace: filter out of range labels in scan_labels() Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 13/14] libnvdimm, namespace: lift single pmem limit " Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 16:39 ` [PATCH 14/14] libnvdimm, namespace: allow creation of multiple pmem-namespaces per region Dan Williams
2016-10-07 16:39   ` Dan Williams
2016-10-07 18:19 ` [PATCH 00/14] libnvdimm: support sub-divisions of pmem for 4.9 Linda Knippers
2016-10-07 18:19   ` Linda Knippers
2016-10-07 19:52   ` Dan Williams
2016-10-07 19:52     ` Dan Williams
2016-10-07 21:42     ` Linda Knippers
2016-10-07 21:42       ` Linda Knippers
2016-10-07 23:38       ` Dan Williams
2016-10-07 23:38         ` 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=147585833727.22349.4151646734474522098.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --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.