From: Robert Love <robert.w.love@intel.com>
To: linux-scsi@vger.kernel.org
Cc: Neil Horman <nhorman@tuxdriver.com>
Subject: [PATCH 03/16] libfcoe: Save some memory and optimize name lookups
Date: Wed, 12 Dec 2012 15:22:19 -0800 [thread overview]
Message-ID: <20121212232219.13084.99143.stgit@fritz> (raw)
In-Reply-To: <20121212232203.13084.3630.stgit@fritz>
Instead of creating a structure with an enum and a pointer
to a string, simply allocate an array of strings and use
the enum values for the indicies.
This means that we do not need to iterate through the list
of entries when looking up a string name by its enum key.
This will also help with a latter patch that will add
more fcoe_sysfs attributes that will also use the
fcoe_enum_name_search macro. One attribute will also do
a reverse lookup which requires less code when the
enum-to-string mappings are organized as this patch makes
them to be.
Signed-off-by: Robert Love <robert.w.love@intel.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
---
drivers/scsi/fcoe/fcoe_sysfs.c | 44 +++++++++++++++-------------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 5e75168..5a74a47 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -210,25 +210,23 @@ static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \
#define fcoe_enum_name_search(title, table_type, table) \
static const char *get_fcoe_##title##_name(enum table_type table_key) \
{ \
- int i; \
- char *name = NULL; \
- \
- for (i = 0; i < ARRAY_SIZE(table); i++) { \
- if (table[i].value == table_key) { \
- name = table[i].name; \
- break; \
- } \
- } \
- return name; \
+ if (table_key >= ARRAY_SIZE(table)) \
+ return NULL; \
+ return table[table_key]; \
}
-static struct {
- enum fcf_state value;
- char *name;
-} fcf_state_names[] = {
- { FCOE_FCF_STATE_UNKNOWN, "Unknown" },
- { FCOE_FCF_STATE_DISCONNECTED, "Disconnected" },
- { FCOE_FCF_STATE_CONNECTED, "Connected" },
+static char *fip_conn_type_names[] = {
+ [ FIP_CONN_TYPE_UNKNOWN ] = "Unknown",
+ [ FIP_CONN_TYPE_FABRIC ] = "Fabric",
+ [ FIP_CONN_TYPE_VN2VN ] = "VN2VN",
+};
+fcoe_enum_name_search(ctlr_mode, fip_conn_type, fip_conn_type_names)
+#define FCOE_CTLR_MODE_MAX_NAMELEN 50
+
+static char *fcf_state_names[] = {
+ [ FCOE_FCF_STATE_UNKNOWN ] = "Unknown",
+ [ FCOE_FCF_STATE_DISCONNECTED ] = "Disconnected",
+ [ FCOE_FCF_STATE_CONNECTED ] = "Connected",
};
fcoe_enum_name_search(fcf_state, fcf_state, fcf_state_names)
#define FCOE_FCF_STATE_MAX_NAMELEN 50
@@ -246,17 +244,7 @@ static ssize_t show_fcf_state(struct device *dev,
}
static FCOE_DEVICE_ATTR(fcf, state, S_IRUGO, show_fcf_state, NULL);
-static struct {
- enum fip_conn_type value;
- char *name;
-} fip_conn_type_names[] = {
- { FIP_CONN_TYPE_UNKNOWN, "Unknown" },
- { FIP_CONN_TYPE_FABRIC, "Fabric" },
- { FIP_CONN_TYPE_VN2VN, "VN2VN" },
-};
-fcoe_enum_name_search(ctlr_mode, fip_conn_type, fip_conn_type_names)
-#define FCOE_CTLR_MODE_MAX_NAMELEN 50
-
+#define FCOE_MAX_MODENAME_LEN 20
static ssize_t show_ctlr_mode(struct device *dev,
struct device_attribute *attr,
char *buf)
next prev parent reply other threads:[~2012-12-12 23:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-12 23:22 [PATCH 00/16] libfc, libfcoe and fcoe updates for 3.8 Robert Love
2012-12-12 23:22 ` [PATCH 01/16] libfc: fix REC handling Robert Love
2012-12-12 23:22 ` [PATCH 02/16] Documentation: Add missing devices/ to devices path Robert Love
2012-12-12 23:22 ` Robert Love [this message]
2012-12-13 7:54 ` [PATCH 03/16] libfcoe: Save some memory and optimize name lookups Bart Van Assche
2012-12-14 18:36 ` Love, Robert W
2012-12-14 22:02 ` [PATCH v2] " Robert Love
2012-12-17 14:26 ` Neil Horman
2012-12-12 23:22 ` [PATCH 04/16] libfcoe: Add fcoe_sysfs debug logging level Robert Love
2012-12-12 23:22 ` [PATCH 05/16] libfcoe, fcoe, bnx2fc: Add new fcoe control interface Robert Love
2012-12-16 19:50 ` Bhanu Prakash Gollapudi
2012-12-12 23:22 ` [PATCH 06/16] fcoe: Use the fcoe_sysfs " Robert Love
2012-12-12 23:22 ` [PATCH 07/16] bnx2fc: " Robert Love
2012-12-12 23:22 ` [PATCH 08/16] libfc, libfcoe, fcoe: Convert debug_logging macros to pr_info Robert Love
2012-12-12 23:22 ` [PATCH 09/16] fcoe: prep work to start consolidate the usage of fcoe_netdev Robert Love
2012-12-12 23:22 ` [PATCH 10/16] fcoe: add support to the get_netdev() for fcoe_interface Robert Love
2012-12-12 23:23 ` [PATCH 11/16] libfcoe, fcoe: move fcoe_link_speed_update() to libfcoe and export it Robert Love
2012-12-12 23:23 ` [PATCH 12/16] libfcoe, fcoe: consolidate the fcoe_ctlr_get_lesb/fcoe_get_lesb Robert Love
2012-12-12 23:23 ` [PATCH 13/16] bnx2fc: add support to get_netdev for bnx2f_interface Robert Love
2012-12-12 23:23 ` [PATCH 14/16] bnx2fc: use fcoe_link_speed_update() from the exported symbol in libfcoe Robert Love
2012-12-12 23:23 ` [PATCH 15/16] bnx2fc: use fcoe_get_lesb/fcoe_ctlr_get_lesb() directly from libfcoe Robert Love
2012-12-12 23:23 ` [PATCH 16/16] debris left by "[SCSI] libfcoe: Remove mutex_trylock/restart_syscall checks" Robert Love
2012-12-16 19:56 ` [PATCH 00/16] libfc, libfcoe and fcoe updates for 3.8 Bhanu Prakash Gollapudi
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=20121212232219.13084.99143.stgit@fritz \
--to=robert.w.love@intel.com \
--cc=linux-scsi@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
/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;
as well as URLs for NNTP newsgroup(s).