public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
To: roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	hal-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org,
	Ira Weiny <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: [PATCH 1/6] ib/mad: Add function to support format specifiers for node description
Date: Thu, 30 Oct 2014 19:50:16 -0400	[thread overview]
Message-ID: <1414713021-12175-2-git-send-email-ira.weiny@intel.com> (raw)
In-Reply-To: <1414713021-12175-1-git-send-email-ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

From: Ira Weiny <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

ib_build_node_desc - prints src node description into dest while mapping format
specifiers

Specifiers supported:
%h system hostname
%d device name

Define a default Node Description format to be "%h %d"

Original work done by Mike Heinz.

The function signature is generic to support some devices which are not
processing an ib_smp object when calling this function.

Reviewed-by: John Fleck <john.fleck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Michael Heinz <michael.william.heinz-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Ira Weiny <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

---
 drivers/infiniband/core/mad.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/rdma/ib_mad.h         | 17 +++++++++++++++++
 include/rdma/ib_verbs.h       |  6 ++++--
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 74c30f4..a7ed0ada 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -39,7 +39,9 @@
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/utsname.h>
 #include <rdma/ib_cache.h>
+#include <rdma/ib_smi.h>
 
 #include "mad_priv.h"
 #include "mad_rmpp.h"
@@ -996,6 +998,42 @@ int ib_get_mad_data_offset(u8 mgmt_class)
 }
 EXPORT_SYMBOL(ib_get_mad_data_offset);
 
+void ib_build_node_desc(char *dest, char *src, int dest_len,
+			struct ib_device *dev)
+{
+	char *end = dest + dest_len-1;
+	char *field;
+
+	while (*src && (dest < end)) {
+		if (*src != '%') {
+			*dest++ = *src++;
+		} else {
+			src++;
+			switch (*src) {
+			case 'h':
+				field = init_utsname()->nodename;
+				src++;
+				while (*field && (*field != '.') && (dest < end))
+					*dest++ = *field++;
+			break;
+			case 'd':
+				field = dev->name;
+				src++;
+				while (*field && (dest < end))
+					*dest++ = *field++;
+				break;
+			default:
+				src++;
+			}
+		}
+	}
+	if (dest < end)
+		*dest = 0;
+	else
+		*end = 0;
+}
+EXPORT_SYMBOL(ib_build_node_desc);
+
 int ib_is_mad_class_rmpp(u8 mgmt_class)
 {
 	if ((mgmt_class == IB_MGMT_CLASS_SUBN_ADM) ||
diff --git a/include/rdma/ib_mad.h b/include/rdma/ib_mad.h
index 9bb99e9..975642e 100644
--- a/include/rdma/ib_mad.h
+++ b/include/rdma/ib_mad.h
@@ -677,4 +677,21 @@ void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
  */
 int ib_mad_kernel_rmpp_agent(struct ib_mad_agent *agent);
 
+#define IB_DEFAULT_ND_FORMAT "%h %d"
+/**
+ * ib_build_node_desc - prints src node description into dest while mapping
+ * format specifiers
+ *
+ * Specifiers supported:
+ * %h system hostname
+ * %d device name
+ *
+ * @dest: destination buffer
+ * @src: source buffer
+ * @dest_len: destination buffer length
+ * @dev: ib_device
+ */
+void ib_build_node_desc(char *dest, char *src, int dest_len,
+			struct ib_device *dev);
+
 #endif /* IB_MAD_H */
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 470a011..f3ec6de 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -55,6 +55,8 @@
 
 extern struct workqueue_struct *ib_wq;
 
+#define IB_DEVICE_DESC_MAX 64
+
 union ib_gid {
 	u8	raw[16];
 	struct {
@@ -351,7 +353,7 @@ enum ib_device_modify_flags {
 
 struct ib_device_modify {
 	u64	sys_image_guid;
-	char	node_desc[64];
+	char	node_desc[IB_DEVICE_DESC_MAX];
 };
 
 enum ib_port_modify_flags {
@@ -1625,7 +1627,7 @@ struct ib_device {
 	u64			     uverbs_cmd_mask;
 	u64			     uverbs_ex_cmd_mask;
 
-	char			     node_desc[64];
+	char			     node_desc[IB_DEVICE_DESC_MAX];
 	__be64			     node_guid;
 	u32			     local_dma_lkey;
 	u8                           node_type;
-- 
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-10-30 23:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 23:50 [PATCH 0/6] Make Node Description default to "<hostname> <device>" ira.weiny-ral2JQCrhuEAvxtiuMwx3w
     [not found] ` <1414713021-12175-1-git-send-email-ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-30 23:50   ` ira.weiny-ral2JQCrhuEAvxtiuMwx3w [this message]
2014-10-30 23:50   ` [PATCH 2/6] ib/ipath: change default node description processing ira.weiny-ral2JQCrhuEAvxtiuMwx3w
2014-10-30 23:50   ` [PATCH 3/6] ib/mlx4: " ira.weiny-ral2JQCrhuEAvxtiuMwx3w
     [not found]     ` <1414713021-12175-4-git-send-email-ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-11-07 12:17       ` Hal Rosenstock
2014-10-30 23:50   ` [PATCH 4/6] ib/mthca: " ira.weiny-ral2JQCrhuEAvxtiuMwx3w
     [not found]     ` <1414713021-12175-5-git-send-email-ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-11-07 12:17       ` Hal Rosenstock
2014-10-30 23:50   ` [PATCH 5/6] ib/qib: " ira.weiny-ral2JQCrhuEAvxtiuMwx3w
2014-10-30 23:50   ` [PATCH 6/6] ib/mlx5: " ira.weiny-ral2JQCrhuEAvxtiuMwx3w
     [not found]     ` <1414713021-12175-7-git-send-email-ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-11-07 12:17       ` Hal Rosenstock

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=1414713021-12175-2-git-send-email-ira.weiny@intel.com \
    --to=ira.weiny-ral2jqcrhueavxtiumwx3w@public.gmane.org \
    --cc=hal-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox