* [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel
@ 2008-02-07 8:21 Yi Zou
2008-02-07 8:21 ` [PATCH 2/6] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
The current build for openfc will fail as it only builds as module.
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/openfc/Makefile | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/ofc/openfc/Makefile b/drivers/scsi/ofc/openfc/Makefile
index 00606a2..9309266 100644
--- a/drivers/scsi/ofc/openfc/Makefile
+++ b/drivers/scsi/ofc/openfc/Makefile
@@ -9,7 +9,10 @@ openfc-y := \
openfc_if.o \
openfc_ioctl.o \
openfc_pkt.o \
- openfc_scsi.o \
- ../libfc/libfc.o \
- ../libsa/libsa.o \
- ../libcrc/libcrc.o
+ openfc_scsi.o
+
+ifeq ($(CONFIG_OFC),m)
+ openfc-y += ../libfc/libfc.o \
+ ../libsa/libsa.o \
+ ../libcrc/libcrc.o
+endif
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/6] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
@ 2008-02-07 8:21 ` Yi Zou
2008-02-07 8:21 ` [PATCH 3/6] [FCoE] hash for fc_sess: " Yi Zou
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
1. Add hash table/funcs for fc_remote_port
2. Remove association with vf_rport_by_fid in fc_virt_fab
3. Remove association with vf_rport_by_wwpn in fc_virt_fab
4. Remove references to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/fc_remote_port.h | 5
drivers/scsi/ofc/libfc/fc_remote_port.c | 387 +++++++++++++++++++----------
2 files changed, 254 insertions(+), 138 deletions(-)
diff --git a/drivers/scsi/ofc/include/fc_remote_port.h b/drivers/scsi/ofc/include/fc_remote_port.h
index 07b20fb..a2d294f 100644
--- a/drivers/scsi/ofc/include/fc_remote_port.h
+++ b/drivers/scsi/ofc/include/fc_remote_port.h
@@ -21,7 +21,6 @@
#define _LIBFC_REMOTE_PORT_H_
#include "sa_kernel.h"
-#include "sa_hash.h"
/*
* Fibre Channel Remote Ports.
@@ -46,8 +45,8 @@ struct fc_remote_port {
void *rp_client_priv; /* HBA driver private data */
void *rp_fcs_priv; /* FCS driver private data */
struct sa_event_list *rp_events; /* event list */
- struct sa_hash_link rp_fid_hash_link;
- struct sa_hash_link rp_wwpn_hash_link;
+ struct hlist_node rp_fid_hash_link;
+ struct hlist_node rp_wwpn_hash_link;
/*
* For now, there's just one session per remote port.
diff --git a/drivers/scsi/ofc/libfc/fc_remote_port.c b/drivers/scsi/ofc/libfc/fc_remote_port.c
index b0061f5..9d48e8e 100644
--- a/drivers/scsi/ofc/libfc/fc_remote_port.c
+++ b/drivers/scsi/ofc/libfc/fc_remote_port.c
@@ -27,7 +27,6 @@
#include "sa_kernel.h"
#undef LIST_HEAD
#include "sa_event.h"
-#include "sa_hash.h"
#include "ofc_dbg.h"
#include "fc_types.h"
@@ -36,71 +35,246 @@
#include "fc_virt_fab_impl.h"
/*
- * Declare hash table type for lookup by FCID.
+ * Hash table size for remote port
*/
-#define FC_REMOTE_PORT_HASH_SIZE 32 /* XXX smallish for now */
+#define FC_HASH_RPORT_SHIFT 3
+#define FC_HASH_RPORT_BUCKETS (1UL << FC_HASH_RPORT_SHIFT)
+#define FC_HASH_RPORT_MASK (FC_HASH_RPORT_BUCKETS - 1)
-static int fc_remote_port_fid_match(sa_hash_key_t, void *);
-static u_int32_t fc_remote_port_fid_hash(sa_hash_key_t);
+static u_int32_t rport_fid_entries;
+static struct hlist_head rport_fid_hash[FC_HASH_RPORT_BUCKETS];
-static struct sa_hash_type fc_remote_port_hash_by_fid = {
- .st_link_offset = offsetof(struct fc_remote_port, rp_fid_hash_link),
- .st_match = fc_remote_port_fid_match,
- .st_hash = fc_remote_port_fid_hash,
-};
+/**
+ * fc_remote_port_fid_match - the compare function by fcid
+ * @fid: the ptr to fcid as the input
+ * @rp: the ptr to the remote port to be matched
+ */
+static inline int fc_remote_port_fid_match(const fc_fid_t *fid,
+ const struct fc_remote_port *rp)
+{
+ return *fid == rp->rp_fid;
+}
-#ifdef FC_REMOTE_PORT_BY_WWPN
-/*
- * Declare hash table type for lookup by WWPN.
+/**
+ * fc_remote_port_fid_hash - hash remote port by fcid
+ * @fid: the ptr to fcid as the input
+ *
+ * this hash currently does nothing but return directly
*/
-static int fc_remote_port_wwpn_match(sa_hash_key_t, void *);
-static u_int32_t fc_remote_port_wwpn_hash(sa_hash_key_t);
-
-static struct sa_hash_type fc_remote_port_hash_by_wwpn = {
- .st_link_offset = offsetof(struct fc_remote_port, rp_wwpn_hash_link),
- .st_match = fc_remote_port_wwpn_match,
- .st_hash = fc_remote_port_wwpn_hash,
-};
-#endif /* FC_REMOTE_PORT_BY_WWPN */
+static inline u_int32_t fc_remote_port_fid_hash(const fc_fid_t *fid)
+{
+ return (*fid) & FC_HASH_RPORT_MASK;
+}
-int fc_remote_port_table_create(struct fc_virt_fab *vp)
+/**
+ * fc_remote_port_fid_hash_lookup - lookup a remote port by fcid
+ * @fid: the ptr to the fc id as key for lookup
+ *
+ * the caller should should acquire appropriate lock before calling.
+ * use rcu_read_lock/unlock for read, use fc_virt_fab_lock/unlock
+ * for write.
+ */
+static inline struct fc_remote_port *fc_remote_port_fid_hash_lookup(
+ const fc_fid_t *fid)
{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_remote_port *rp;
- INIT_LIST_HEAD(&vp->vf_remote_ports);
+ head = &rport_fid_hash[fc_remote_port_fid_hash(fid)];
+ hlist_for_each_entry_rcu(rp, node, head, rp_fid_hash_link)
+ if (fc_remote_port_fid_match(fid, rp))
+ return rp;
+ return NULL;
+}
- vp->vf_rport_by_fid = sa_hash_create(&fc_remote_port_hash_by_fid,
- FC_REMOTE_PORT_HASH_SIZE);
+/**
+ * fc_remote_port_fid_hash_delete - delete the remote port from the fcid hash
+ * @rp: the ptr to the remote port to be deleted
+ *
+ * caller should acquire the lock before calling. use fc_virt_fab_lock/unlock.
+ */
+static inline void fc_remote_port_fid_hash_delete(
+ const struct fc_remote_port *rp)
+{
+ hlist_del_rcu((struct hlist_node *)&rp->rp_fid_hash_link);
+ rport_fid_entries--;
+}
- if (!vp->vf_rport_by_fid)
- return -1;
+/**
+ * fc_remote_port_fid_hash_insert - insert the remote port into fcid hash
+ * @fid: the ptr to the fc id as key
+ * @rp: the ptr to the remote port to be inserted
+ *
+ * caller should acquire the lock before calling. use fc_virt_fab_lock/unlock.
+ */
+static inline void fc_remote_port_fid_hash_insert(const fc_fid_t *fid,
+ const struct fc_remote_port *rp)
+{
+ struct hlist_head *head;
+
+ head = &rport_fid_hash[fc_remote_port_fid_hash(fid)];
+ hlist_add_head_rcu((struct hlist_node *)&rp->rp_fid_hash_link, head);
+ rport_fid_entries++;
+}
#ifdef FC_REMOTE_PORT_BY_WWPN
- vp->vf_rport_by_wwpn = sa_hash_create(&fc_remote_port_hash_by_wwpn,
- FC_REMOTE_PORT_HASH_SIZE);
+static u_int32_t rport_wwpn_entries;
+static struct hlist_head rport_hash_wwn[FC_HASH_RPORT_BUCKETS];
+
+/**
+ * fc_remote_port_wwpn_match - the compare function by port wwn
+ * @wwn: the ptr to wwn as the input
+ * @rp: the ptr to the remote port to be matched
+ */
+static inline int fc_remote_port_wwpn_match(const fc_wwn_t *wwn,
+ struct fc_remote_port *rp)
+{
+ return *wwn == rp->rp_port_wwn;
+}
+
+/**
+ * fc_remote_port_wwpn_match - the compare function by port wwn
+ * @wwn: the ptr to wwn as the input
+ * @rp: the ptr to the remote port to be matched
+ */
+static inline u_int32_t fc_remote_port_wwpn_hash(const fc_wwn_t *wwn)
+{
+ return ((u_int32_t) (((*wwn) >> 32) | (*wwn))) & FC_HASH_RPORT_MASK;
+}
+
+/**
+ * fc_remote_port_wwpn_hash_lookup - look up the remote port from wwpn hash
+ * @wwn: the ptr to the wwn as key
+ * @rp: the ptr to the remote port to be inserted
+ *
+ * the caller should should acquire appropriate lock before calling.
+ * use rcu_read_lock/unlock for read, use fc_virt_fab_lock/unlock
+ * for write.
+ */
+static inline struct fc_remote_port *fc_remote_port_wwpn_hash_lookup(
+ const fc_wwn_t *wwn)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_remote_port *rp;
+
+ head = &rport_wwn_hash[fc_remote_port_wwpn_hash(wwn)];
+ hlist_for_each_entry_rcu(rp, node, head, rp_wwpn_hash_link)
+ if (fc_remote_port_wwpn_match(wwn, rp))
+ return rp;
+ return NULL;
+}
- if (!vp->vf_rport_by_wwpn) {
- sa_hash_destroy(vp->vf_rport_by_fid);
- return -1;
+/**
+ * fc_remote_port_wwpn_hash_delete - delete the remote port from port wwn hash
+ * @wwn: the ptr to the wwn as key
+ * @rp: the ptr to the remote port to be deleted
+ *
+ * the caller should acquire the lock by fc_virt_fab_lock/unlock
+ * before calling.
+ */
+static inline void fc_remote_port_wwpn_hash_delete(const fc_wwn_t *wwn,
+ const struct fc_remote_port *rp)
+{
+ struct hlist_head *head;
+
+ head = &rport_wwn_hash[fc_remote_port_wwpn_hash(wwn)];
+ hlist_del_rcu((struct hlist_node *)&rp->rp_wwpn_hash_link);
+ rport_wwpn_entries--;
+}
+
+/**
+ * fc_remote_port_wwpn_hash_insert - insert the remote port into port wwn hash
+ * @wwn: the ptr to the wwn as key
+ * @rp: the ptr to the remote port to be inserted
+ *
+ * the caller should acquire the lock by fc_virt_fab_lock/unlock
+ * before calling.
+ */
+static inline void fc_remote_port_wwpn_hash_insert(const fc_wwn_t *wwn,
+ const struct fc_remote_port *rp)
+{
+ struct hlist_head *head;
+
+ head = &rport_wwn_hash[fc_remote_port_wwpn_hash(wwn)];
+ hlist_add_head_rcu(&rp->rp_wwpn_hash_link, head);
+ rport_wwpn_entries++;
+}
+
+#ifdef FC_REMOTE_PORT_DEBUG
+/**
+ * fc_remote_port_wwpn_hash_iterate - iterate all items in all buckets
+ * @callback: callback function for iterator
+ * @arg: the arg to be passed to callback as the 2nd arg
+ *
+ * this function uses RCU lock so the caller should not acquire lock
+ * before calling. The callback should not acuqire the same lock either.
+ */
+static void fc_remote_port_wwpn_hash_iterate(
+ void (*callback) (void *ep, void *arg), void *arg)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_remote_port *rp;
+ int loop;
+
+ rcu_read_lock();
+ for (loop = 0; lopp < FC_HASH_RPORT_BUCKETS; loop++) {
+ hlist_for_each_entry_rcu(rp, node, head, rp_wwpn_hash_link) {
+ (*callback) (rp, arg);
+ count++;
+ }
}
+ rcu_read_unlock();
+ if (count != rport_wwpn_entries)
+ OFC_DBG("rport_wwpn_entries %d != count %d",
+ rport_wwpn_entries, count);
+ BUG_ON(count != rport_wwpn_entries);
+}
+#endif /* FC_REMOTE_PORT_DEBUG */
#endif /* FC_REMOTE_PORT_BY_WWPN */
- return 0;
+
+/**
+ * fc_remote_port_hash_init - initialize the hash table hlist iterate
+ */
+static void fc_remote_port_hash_init(void)
+{
+ int loop;
+ for (loop = 0; loop < FC_HASH_RPORT_BUCKETS; loop++) {
+ INIT_HLIST_HEAD(&rport_fid_hash[loop]);
+#ifdef FC_REMOTE_PORT_BY_WWPN
+ INIT_HLIST_HEAD(&rport_wwpn_hash[loop]);
+#endif
+ }
+ rport_fid_entries = 0;
+#ifdef FC_REMOTE_PORT_BY_WWPN
+ rport_wwpn_entries = 0;
+#endif
}
-void fc_remote_port_table_destroy(struct fc_virt_fab *vp)
+int fc_remote_port_table_create(struct fc_virt_fab *vf)
{
- WARN_ON(!list_empty(&vp->vf_remote_ports));
- INIT_LIST_HEAD(&vp->vf_remote_ports);
- if (vp->vf_rport_by_fid)
- sa_hash_destroy(vp->vf_rport_by_fid);
- vp->vf_rport_by_fid = NULL;
+ INIT_LIST_HEAD(&vf->vf_remote_ports);
+ fc_remote_port_hash_init();
+ return 0;
+}
-#ifdef FC_REMOTE_PORT_BY_WWPN
- if (vp->vf_rport_by_wwpn)
- sa_hash_destroy(vp->vf_rport_by_wwpn);
- vp->vf_rport_by_wwpn = NULL;
-#endif /* FC_REMOTE_PORT_BY_WWPN */
+void fc_remote_port_table_destroy(struct fc_virt_fab *vf)
+{
+ WARN_ON(!list_empty(&vf->vf_remote_ports));
+ INIT_LIST_HEAD(&vf->vf_remote_ports);
+ fc_remote_port_hash_init();
}
+/**
+ * fc_remote_port_create - create a remote port.
+ * @vp: ptr to virtual fabric structure
+ * @port_name: world wide port name for the remote port
+ *
+ * create a new remote port struct and assign the virtual
+ * fabric to it. also the world wide port name.
+ */
struct fc_remote_port *fc_remote_port_create(struct fc_virt_fab *vp,
fc_wwn_t port_name)
{
@@ -125,35 +299,18 @@ struct fc_remote_port *fc_remote_port_create(struct fc_virt_fab *vp,
return rp;
}
-/*
- * Find remote port by FCID or by WWPN.
+/**
+ * fc_remote_port_lookup_create - lookup by FCID or by WWPN, if not found then
+ * create it accordingly.
+ * @vp: ptr to virtual fabric structure
+ * @fid: fc id for the remote port
+ * @wwpn: world wide port name for the remote port
+ * @wwnn: world wide node name for the remote port
+ *
* The first lookup is by FCID, if that is non-zero. If that lookup fails,
* a second lookup by WWPN (if that is non-zero) is performed.
* Returns with the remote port held, or with NULL if the lookups fail.
*/
-struct fc_remote_port *fc_remote_port_lookup(struct fc_virt_fab *vp,
- fc_fid_t fid, fc_wwn_t wwpn)
-{
- struct fc_remote_port *rp;
-
- rp = NULL;
- fc_virt_fab_lock(vp);
- if (fid)
- rp = sa_hash_lookup(vp->vf_rport_by_fid, &fid);
-#ifdef FC_REMOTE_PORT_BY_WWPN
- if (!rp && wwpn)
- rp = sa_hash_lookup(vp->vf_rport_by_wwpn, &wwpn);
-#endif /* FC_REMOTE_PORT_BY_WWPN */
- if (rp)
- fc_remote_port_hold(rp);
- fc_virt_fab_unlock(vp);
- return rp;
-}
-
-/*
- * Find remote port by FCID or by WWPN. Create it if not found.
- * Returns with the remote port held.
- */
struct fc_remote_port *fc_remote_port_lookup_create(struct fc_virt_fab *vp,
fc_fid_t fid,
fc_wwn_t wwpn,
@@ -164,14 +321,14 @@ struct fc_remote_port *fc_remote_port_lookup_create(struct fc_virt_fab *vp,
rp = NULL;
fc_virt_fab_lock(vp);
if (fid)
- rp = sa_hash_lookup(vp->vf_rport_by_fid, &fid);
+ rp = fc_remote_port_fid_hash_lookup(&fid);
#ifdef FC_REMOTE_PORT_BY_WWPN
if (!rp && wwpn)
- rp = sa_hash_lookup(vp->vf_rport_by_wwpn, &wwpn);
+ rp = fc_remote_port_wwpn_hash_lookup(&wwpn);
#endif /* FC_REMOTE_PORT_BY_WWPN */
if (!rp) {
fc_virt_fab_unlock(vp);
- rp = fc_remote_port_create(vp, wwpn);
+ rp = fc_remote_port_create(vp, wwpn); /* create and hold */
} else {
fc_remote_port_hold(rp);
fc_virt_fab_unlock(vp);
@@ -204,7 +361,9 @@ static void fc_remote_port_list(struct fc_virt_fab *vp, char *msg,
struct fc_remote_port *rp)
{
OFC_DBG("%s rp %6x %16llx %p", msg, rp->rp_fid, rp->rp_port_wwn, rp);
- sa_hash_iterate(vp->vf_rport_by_wwpn, fc_remote_port_print, "");
+#ifdef FC_REMOTE_PORT_BY_WWPN
+ fc_remote_port_wwpn_hash_iterate(fc_remote_port_print, "");
+#endif
}
#endif /* FC_REMOTE_PORT_DEBUG */
@@ -215,26 +374,19 @@ void fc_remote_port_set_name(struct fc_remote_port *rp, fc_wwn_t wwpn,
fc_wwn_t wwnn)
{
#ifdef FC_REMOTE_PORT_BY_WWPN
- struct fc_remote_port *found_rp;
- struct fc_virt_fab *vp;
- fc_wwn_t old_name;
+ struct fc_remote_port *found;
- vp = rp->rp_vf;
- fc_virt_fab_lock(vp);
- old_name = rp->rp_port_wwn;
- if (old_name) {
- found_rp = sa_hash_lookup_delete(vp->vf_rport_by_wwpn,
- &old_name);
- WARN_ON(!found_rp);
- WARN_ON(found_rp != rp);
+ if (rp->rp_port_wwn) {
+ found = fc_remote_port_wwpn_hash_lookup(&rp->rp_port_wwn);
+ WARN_ON(found != rp);
+ fc_remote_port_wwpn_hash_delete(found);
}
#endif /* FC_REMOTE_PORT_BY_WWPN */
rp->rp_node_wwn = wwnn;
rp->rp_port_wwn = wwpn;
#ifdef FC_REMOTE_PORT_BY_WWPN
if (wwpn != 0)
- sa_hash_insert(vp->vf_rport_by_wwpn, &wwpn, rp);
- fc_virt_fab_unlock(vp);
+ fc_remote_port_wwpn_hash_insert(&wwpn, rp);
#endif /* FC_REMOTE_PORT_BY_WWPN */
}
@@ -243,48 +395,41 @@ void fc_remote_port_set_name(struct fc_remote_port *rp, fc_wwn_t wwpn,
*/
void fc_remote_port_set_fid(struct fc_remote_port *rp, fc_fid_t fid)
{
- struct fc_remote_port *found_rp;
- struct fc_virt_fab *vp;
+ struct fc_remote_port *found;
if (fid != rp->rp_fid) {
- vp = rp->rp_vf;
- fc_virt_fab_lock(vp);
+ fc_virt_fab_lock(rp->rp_vf);
if (rp->rp_fid != 0) {
- found_rp = sa_hash_lookup_delete(vp->vf_rport_by_fid,
- &rp->rp_fid);
- WARN_ON(!found_rp);
- WARN_ON(found_rp != rp);
+ found = fc_remote_port_fid_hash_lookup(&rp->rp_fid);
+ WARN_ON(found != rp);
+ fc_remote_port_fid_hash_delete(found);
}
rp->rp_fid = fid;
if (fid)
- sa_hash_insert(vp->vf_rport_by_fid, &fid, rp);
- fc_virt_fab_unlock(vp);
+ fc_remote_port_fid_hash_insert(&fid, rp);
+ fc_virt_fab_unlock(rp->rp_vf);
}
}
static void fc_remote_port_delete(struct fc_remote_port *rp)
{
struct fc_remote_port *found;
- struct fc_virt_fab *vp;
- vp = rp->rp_vf;
- fc_virt_fab_lock(vp);
+ fc_virt_fab_lock(rp->rp_vf);
if (rp->rp_fid != 0) {
- found = sa_hash_lookup_delete(rp->rp_vf->vf_rport_by_fid,
- &rp->rp_fid);
- WARN_ON(!found);
+ found = fc_remote_port_fid_hash_lookup(&rp->rp_fid);
WARN_ON(found != rp);
+ fc_remote_port_fid_hash_delete(found);
}
#ifdef FC_REMOTE_PORT_BY_WWPN
if (rp->rp_port_wwn) {
- found = sa_hash_lookup_delete(rp->rp_vf->vf_rport_by_wwpn,
- &rp->rp_port_wwn);
- WARN_ON(!found);
+ found = fc_remote_port_wwpn_hash_lookup(&rp->rp_port_wwn);
WARN_ON(found != rp);
+ fc_remote_port_wwpn_hash_delete(found);
}
#endif /* FC_REMOTE_PORT_BY_WWPN */
list_del(&rp->rp_list);
- fc_virt_fab_unlock(vp);
+ fc_virt_fab_unlock(rp->rp_vf);
sa_event_list_free(rp->rp_events);
sa_free(rp);
}
@@ -299,31 +444,3 @@ void fc_remote_port_release(struct fc_remote_port *rp)
if (atomic_dec_and_test(&rp->rp_refcnt))
fc_remote_port_delete(rp);
}
-
-static int fc_remote_port_fid_match(sa_hash_key_t key, void *rp_arg)
-{
- struct fc_remote_port *rp = rp_arg;
-
- return *(fc_fid_t *) key == rp->rp_fid;
-}
-
-static u_int32_t fc_remote_port_fid_hash(sa_hash_key_t key)
-{
- return *(fc_fid_t *) key;
-}
-
-#ifdef FC_REMOTE_PORT_BY_WWPN
-static int fc_remote_port_wwpn_match(sa_hash_key_t key, void *rp_arg)
-{
- struct fc_remote_port *rp = rp_arg;
-
- return *(fc_wwn_t *) key == rp->rp_port_wwn;
-}
-
-static u_int32_t fc_remote_port_wwpn_hash(sa_hash_key_t key)
-{
- fc_wwn_t wwn = *(fc_wwn_t *) key;
-
- return (u_int32_t) ((wwn >> 32) | wwn);
-}
-#endif /* FC_REMOTE_PORT_BY_WWPN */
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/6] [FCoE] hash for fc_sess: do not use sa_hash_xxx
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
2008-02-07 8:21 ` [PATCH 2/6] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
@ 2008-02-07 8:21 ` Yi Zou
2008-02-07 8:21 ` [PATCH 4/6] [FCoE] hash for fc_local_port: " Yi Zou
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
1. Add hash table/funcs for fc_sess
2. Remove association with vf_sess_by_fids in fc_virt_fab
4. Remove refrences to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/fc_sess.h | 2
drivers/scsi/ofc/libfc/fc_sess.c | 226 +++++++++++++++++++++++----------
drivers/scsi/ofc/libfc/fc_sess_impl.h | 2
3 files changed, 162 insertions(+), 68 deletions(-)
diff --git a/drivers/scsi/ofc/include/fc_sess.h b/drivers/scsi/ofc/include/fc_sess.h
index d0b4f73..5684a18 100644
--- a/drivers/scsi/ofc/include/fc_sess.h
+++ b/drivers/scsi/ofc/include/fc_sess.h
@@ -81,6 +81,8 @@ static inline u_int64_t fc_sess_key(fc_fid_t local, fc_fid_t remote)
int fc_sess_table_create(struct fc_virt_fab *);
void fc_sess_table_destroy(struct fc_virt_fab *);
+struct fc_sess *fc_sess_hash_lookup(const u_int64_t *key);
+
/*
* Lookup or create a new session.
*/
diff --git a/drivers/scsi/ofc/libfc/fc_sess.c b/drivers/scsi/ofc/libfc/fc_sess.c
index 1eb3bc3..4e4acfd 100644
--- a/drivers/scsi/ofc/libfc/fc_sess.c
+++ b/drivers/scsi/ofc/libfc/fc_sess.c
@@ -32,7 +32,6 @@
#include "ofc_dbg.h"
#include "sa_event.h"
-#include "sa_hash.h"
#include "fc_fs.h"
#include "fc_els.h"
@@ -64,20 +63,6 @@
static int fc_sess_debug;
/*
- * Declare hash type for lookup of session by local and remote FCID.
- */
-#define FC_SESS_HASH_SIZE 32 /* XXX increase later */
-
-static int fc_sess_match(const sa_hash_key_t, void *);
-static u_int32_t fc_sess_hash(const sa_hash_key_t);
-
-static struct sa_hash_type fc_sess_hash_type = {
- .st_link_offset = offsetof(struct fc_sess, fs_hash_link),
- .st_match = fc_sess_match,
- .st_hash = fc_sess_hash,
-};
-
-/*
* static functions.
*/
static void fc_sess_enter_init(struct fc_sess *);
@@ -99,6 +84,157 @@ static void fc_sess_recv_logo_req(struct fc_sess *,
struct fc_seq *, struct fc_frame *);
static void fc_sess_delete(struct fc_sess *, void *);
static void fc_sess_timeout(unsigned long);
+static void fc_sess_iterate(struct fc_virt_fab *vf,
+ void (*func) (struct fc_sess *, void *), void *arg);
+
+static void fc_sess_debug_print(void *sess_arg, void *arg);
+
+/*
+ * Hash table size for session
+ */
+#define FC_HASH_SESS_SHIFT 5
+#define FC_HASH_SESS_BUCKETS (1UL << FC_HASH_SESS_SHIFT)
+#define FC_HASH_SESS_MASK (FC_HASH_SESS_BUCKETS - 1)
+
+static u_int32_t sess_hash_entries;
+static struct hlist_head sess_hash_table[FC_HASH_SESS_BUCKETS];
+
+/**
+ * fc_sess_hash_match - session hash table match functio
+ * @key: the ptr to the key for match up compare
+ * @sess: the ptr to the fc_sess structure
+ */
+static inline int fc_sess_hash_match(const u_int64_t *key,
+ struct fc_sess *sess)
+{
+ return *key == fc_sess_key(sess->fs_local_fid, sess->fs_remote_fid);
+}
+
+/**
+ * fc_sess_hash - session hash table hash functio
+ * @key: the ptr to the key doing the hash
+ */
+static inline u_int32_t fc_sess_hash(const u_int64_t *key)
+{
+ return ((u_int32_t) (((*key) >> 20) ^ (*key))) & FC_HASH_SESS_MASK;
+}
+
+/**
+ * fc_sess_hash_delete - remove the give session from the hash table
+ * @key: the ptr to the key for match up compare
+ * @sess: the ptr to the fc_sess structure
+ *
+ * caller should aquire the lock before calling. use vf_lock.
+ */
+static inline void fc_sess_hash_delete(const struct fc_sess *sess,
+ struct fc_virt_fab *vf)
+{
+ hlist_del_rcu((struct hlist_node *)&sess->fs_hash_link);
+ sess_hash_entries--;
+}
+
+/**
+ * fc_sess_hash_insert - session hash table match functio
+ * @key: the ptr to the key for match up compare
+ * @sess: the ptr to the fc_sess structure
+ *
+ * caller should aquire the lock before calling. use vf_lock.
+ */
+static inline void fc_sess_hash_insert(const u_int64_t *key,
+ const struct fc_sess *sess,
+ struct fc_virt_fab *vf)
+{
+ struct hlist_head *head;
+
+ head = &sess_hash_table[fc_sess_hash(key)];
+ hlist_add_head_rcu((struct hlist_node *)&sess->fs_hash_link, head);
+ sess_hash_entries++;
+}
+
+/**
+ * fc_sess_hash_lookup - Lookup the session hash table by key.
+ * @key: ptr to the key to hash bucket
+ *
+ * the caller should acquire either RCU lock for read or spinlock
+ * e.g., vf_lock, for write before calling.
+ */
+inline struct fc_sess *fc_sess_hash_lookup(const u_int64_t *key)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_sess *sess;
+
+ head = &sess_hash_table[fc_sess_hash(key)];
+ hlist_for_each_entry_rcu(sess, node, head, fs_hash_link)
+ if (fc_sess_hash_match(key, sess))
+ return sess;
+ return NULL;
+}
+
+/**
+ * fc_sess_hash_iterate - iterate all items in all buckets of hash table
+ * @callback: callback function for iterator
+ * @arg: the arg to be passed to callback as the 2nd arg
+ *
+ * this function uses RCU lock so the caller should not acquire lock
+ * before calling. The callback should not acuqire the same lock either.
+ */
+static void fc_sess_hash_iterate(
+ void (*callback) (void *ep, void *arg), void *arg)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_sess *sess;
+ int loop;
+ int count = 0;
+
+ rcu_read_lock();
+ for (loop = 0; loop < FC_HASH_SESS_BUCKETS; loop++) {
+ head = &sess_hash_table[loop];
+ hlist_for_each_entry_rcu(sess, node, head, fs_hash_link) {
+ (*callback) (sess, arg);
+ count++;
+ }
+ }
+ rcu_read_unlock();
+ if (count != sess_hash_entries)
+ OFC_DBG("sess_hash_entries %d != count %d",
+ sess_hash_entries, count);
+ BUG_ON(count != sess_hash_entries);
+}
+
+
+/**
+ * fc_sess_hash_init - initialize the the list heads
+ */
+static void fc_sess_hash_init(void)
+{
+ int loop;
+ for (loop = 0; loop < FC_HASH_SESS_BUCKETS; loop++)
+ INIT_HLIST_HEAD(&sess_hash_table[loop]);
+ sess_hash_entries = 0;
+}
+
+/*
+ * Create hash lookup table for sessions.
+ */
+int fc_sess_table_create(struct fc_virt_fab *vf)
+{
+ fc_sess_hash_init();
+ return 0;
+}
+
+/*
+ * Remove all sessions in a virtual fabric.
+ * This takes care of freeing memory for incoming sessions.
+ */
+void fc_sess_table_destroy(struct fc_virt_fab *vf)
+{
+ fc_sess_iterate(vf, fc_sess_delete, NULL);
+ fc_sess_hash_iterate(fc_sess_debug_print, NULL);
+ fc_sess_hash_init();
+ synchronize_rcu();
+}
/*
* Lock session.
@@ -170,20 +306,6 @@ static void fc_sess_state_enter(struct fc_sess *sess, enum fc_sess_state new)
}
/*
- * Create hash lookup table for sessions.
- */
-int fc_sess_table_create(struct fc_virt_fab *vf)
-{
- struct sa_hash *tp;
-
- tp = sa_hash_create(&fc_sess_hash_type, FC_SESS_HASH_SIZE);
- if (!tp)
- return -1;
- vf->vf_sess_by_fids = tp;
- return 0;
-}
-
-/*
* Call a function for all sessions on the fabric.
* The vf_lock must not be held during the callback.
*
@@ -242,21 +364,6 @@ static void fc_sess_debug_print(void *sess_arg, void *arg)
}
/*
- * Remove all sessions in a virtual fabric.
- * This takes care of freeing memory for incoming sessions.
- */
-void fc_sess_table_destroy(struct fc_virt_fab *vf)
-{
- fc_sess_iterate(vf, fc_sess_delete, NULL);
- fc_virt_fab_lock(vf);
- sa_hash_iterate(vf->vf_sess_by_fids, fc_sess_debug_print, NULL);
- sa_hash_destroy(vf->vf_sess_by_fids);
- vf->vf_sess_by_fids = NULL;
- fc_virt_fab_unlock(vf);
- synchronize_rcu();
-}
-
-/*
* Create session.
* If the session already exists, find and hold it.
*/
@@ -314,7 +421,7 @@ struct fc_sess *fc_sess_create(struct fc_local_port *lp,
*/
key = fc_sess_key(lp->fl_fid, rp->rp_fid);
fc_virt_fab_lock(vp);
- found = sa_hash_lookup(vp->vf_sess_by_fids, &key);
+ found = fc_sess_hash_lookup(&key);
if (found) {
fc_sess_hold(found);
fc_virt_fab_unlock(vp);
@@ -324,7 +431,7 @@ struct fc_sess *fc_sess_create(struct fc_local_port *lp,
} else {
fc_remote_port_hold(rp);
fc_local_port_hold(lp);
- sa_hash_insert(vp->vf_sess_by_fids, &key, sess);
+ fc_sess_hash_insert(&key, sess, vp);
list_add_tail(&sess->fs_list, &lp->fl_sess_list);
fc_virt_fab_unlock(vp);
}
@@ -366,9 +473,9 @@ static void fc_sess_delete(struct fc_sess *sess, void *arg)
key = fc_sess_key(sess->fs_local_fid, sess->fs_remote_fid);
fc_virt_fab_lock(vp);
- found = sa_hash_lookup_delete(vp->vf_sess_by_fids, &key);
- WARN_ON(!found);
+ found = fc_sess_hash_lookup(&key);
WARN_ON(found != sess);
+ fc_sess_hash_delete(found, vp);
list_del(&sess->fs_list); /* under vf_lock */
fc_virt_fab_unlock(vp);
@@ -453,12 +560,12 @@ void fc_sess_reset(struct fc_sess *sess)
if (lp->fl_fid != sess->fs_local_fid) {
key = fc_sess_key(sess->fs_local_fid, sess->fs_remote_fid);
vp = lp->fl_vf;
- found = sa_hash_lookup_delete(vp->vf_sess_by_fids, &key);
- WARN_ON(!found);
+ found = fc_sess_hash_lookup(&key);
WARN_ON(found != sess);
+ fc_sess_hash_delete(found, vp);
sess->fs_local_fid = lp->fl_fid;
key = fc_sess_key(sess->fs_local_fid, sess->fs_remote_fid);
- sa_hash_insert(vp->vf_sess_by_fids, &key, sess);
+ fc_sess_hash_insert(&key, sess, vp);
}
fc_sess_enter_init(sess);
fc_sess_unlock_send(sess);
@@ -1387,21 +1494,6 @@ static void fc_sess_recv_logo_req(struct fc_sess *sess, struct fc_seq *sp,
fc_frame_free(fp);
}
-static int fc_sess_match(sa_hash_key_t key, void *sess_arg)
-{
- struct fc_sess *sess = sess_arg;
-
- return *(u_int64_t *) key ==
- fc_sess_key(sess->fs_local_fid, sess->fs_remote_fid);
-}
-
-static u_int32_t fc_sess_hash(sa_hash_key_t keyp)
-{
- u_int64_t key = *(u_int64_t *) keyp;
-
- return (u_int32_t) ((key >> 20) ^ key);
-}
-
/*
* Lookup or create a new session.
* Returns with the session held.
@@ -1425,7 +1517,7 @@ struct fc_sess *fc_sess_lookup_create(struct fc_local_port *lp,
*/
key = fc_sess_key(lp->fl_fid, fid);
rcu_read_lock();
- sess = sa_hash_lookup(vp->vf_sess_by_fids, &key);
+ sess = fc_sess_hash_lookup(&key);
/*
* Create new session if we didn't find one.
diff --git a/drivers/scsi/ofc/libfc/fc_sess_impl.h b/drivers/scsi/ofc/libfc/fc_sess_impl.h
index d844cba..c600186 100644
--- a/drivers/scsi/ofc/libfc/fc_sess_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_sess_impl.h
@@ -61,7 +61,7 @@ struct fc_sess {
uint8_t fs_plogi_held : 1; /* sess held by remote login */
struct sa_event_list *fs_events; /* event list */
enum fc_event fs_last_event; /* last reported event to clients */
- struct sa_hash_link fs_hash_link; /* link in hash by port pair */
+ struct hlist_node fs_hash_link; /* link in hash by port pair */
struct fc_lun_disc *fs_lun_disc; /* active LUN discovery if any */
spinlock_t fs_lock; /* lock on state changes */
struct rcu_head fs_rcu; /* element for call_rcu() */
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/6] [FCoE] hash for fc_local_port: do not use sa_hash_xxx
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
2008-02-07 8:21 ` [PATCH 2/6] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
2008-02-07 8:21 ` [PATCH 3/6] [FCoE] hash for fc_sess: " Yi Zou
@ 2008-02-07 8:21 ` Yi Zou
2008-02-07 8:21 ` [PATCH 5/6] [FCoE] remove hash tables from fc_virt_fab Yi Zou
2008-02-07 8:21 ` [PATCH 6/6] [FCoE] remove sa_hash_kern.c/sa_hash.h Yi Zou
4 siblings, 0 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
1. Add hash table/funcs for fc_local_port
2. Remove association with vf_lport_by_fid in fc_virt_fab
3. Remove references to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/libfc/fc_local_port.c | 184 +++++++++++++++++----------
drivers/scsi/ofc/libfc/fc_local_port_impl.h | 3
2 files changed, 117 insertions(+), 70 deletions(-)
diff --git a/drivers/scsi/ofc/libfc/fc_local_port.c b/drivers/scsi/ofc/libfc/fc_local_port.c
index 5f28f4a..2a3c256 100644
--- a/drivers/scsi/ofc/libfc/fc_local_port.c
+++ b/drivers/scsi/ofc/libfc/fc_local_port.c
@@ -28,7 +28,6 @@
#include "net_types.h"
#include "ofc_dbg.h"
#include "sa_event.h"
-#include "sa_hash.h"
#include "fc_fs.h"
#include "fc_gs.h"
@@ -92,6 +91,109 @@ static void fc_local_port_port_event(int, void *);
static void fc_local_port_set_fid_int(struct fc_local_port *, fc_fid_t);
static void fc_local_port_gid_pn_error(enum fc_event, void *arg);
+/*
+ * Hash table size for local port
+ */
+#define FC_HASH_LPORT_SHIFT 3
+#define FC_HASH_LPORT_BUCKETS (1UL << FC_HASH_LPORT_SHIFT)
+#define FC_HASH_LPORT_MASK (FC_HASH_LPORT_BUCKETS - 1)
+
+static u_int32_t lport_hash_entries;
+static struct hlist_head lport_hash_table[FC_HASH_LPORT_BUCKETS];
+
+/**
+ * fc_local_port_match - the compare function for hash lookup
+ * @fid: the ptr to fcid as the input
+ * @lp: the ptr to the local port to be matched
+ */
+static inline int fc_local_port_match(const fc_fid_t *fid,
+ const struct fc_local_port *lp)
+{
+ return *fid == lp->fl_fid;
+}
+
+/**
+ * fc_local_port_hash - a simple hash function of fcid
+ * @fid: the ptr to a given fcid
+ */
+static inline u_int32_t fc_local_port_hash(const fc_fid_t *fid)
+{
+ return (((*fid) >> 8) ^ (*fid)) & FC_HASH_LPORT_MASK;
+}
+
+/**
+ * fc_local_port_hash_lookup - lookup the hash table
+ * @fid: the ptr to a given fcid as key
+ *
+ * caller should acquire the lock appropriately, use RCU lock if
+ * no write, otherwise use spinlock such as vf_lock before calling.
+ */
+static inline struct fc_local_port *fc_local_port_hash_lookup(
+ const fc_fid_t *fid)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_local_port *lp;
+
+ head = &lport_hash_table[fc_local_port_hash(fid)];
+ hlist_for_each_entry_rcu(lp, node, head, fl_hash_link)
+ if (fc_local_port_match(fid, lp))
+ return lp;
+ return NULL;
+}
+
+/**
+ * fc_local_port_hash_delete - remove the local port from the hash table
+ * @lp: the ptr to the local port to be removed
+ *
+ * caller should acquire the lock before calling, e.g. vf_lock.
+ */
+static inline void fc_local_port_hash_delete(const struct fc_local_port *lp)
+{
+ hlist_del_rcu((struct hlist_node *)&lp->fl_hash_link);
+ lport_hash_entries--;
+}
+
+/**
+ * fc_local_port_hash_insert - remove the local port from the hash table
+ * @lp: the ptr to the local port to be removed
+ *
+ * caller should acquire the lock before calling, e.g. vf_lock.
+ */
+static inline void fc_local_port_hash_insert(const struct fc_local_port *lp)
+{
+ struct hlist_head *head;
+
+ head = &lport_hash_table[fc_local_port_hash(&lp->fl_fid)];
+ hlist_add_head_rcu((struct hlist_node *)&lp->fl_hash_link, head);
+ lport_hash_entries++;
+}
+
+/**
+ * fc_local_port_hash_init - initalize the hlist_head for each bucket
+ */
+static void fc_local_port_hash_init(void)
+{
+ int loop;
+ for (loop = 0; loop < FC_HASH_LPORT_BUCKETS; loop++)
+ INIT_HLIST_HEAD(&lport_hash_table[loop]);
+ lport_hash_entries = 0;
+}
+
+int fc_local_port_table_create(struct fc_virt_fab *vf)
+{
+ fc_local_port_hash_init();
+ INIT_LIST_HEAD(&vf->vf_local_ports);
+ return 0;
+}
+
+void fc_local_port_table_destroy(struct fc_virt_fab *vf)
+{
+ WARN_ON(!list_empty(&vf->vf_local_ports));
+ fc_local_port_hash_init();
+ INIT_LIST_HEAD(&vf->vf_local_ports);
+}
+
static inline void fc_local_port_enter_state(struct fc_local_port *lp,
enum fc_local_port_state state)
{
@@ -225,20 +327,6 @@ static void fc_local_port_retry(struct fc_local_port *lp)
}
/*
- * Declare hash table type for lookup by FCID.
- */
-#define FC_LOCAL_PORT_HASH_SIZE 8 /* smallish for now */
-
-static int fc_local_port_fid_match(sa_hash_key_t, void *);
-static u_int32_t fc_local_port_fid_hash(sa_hash_key_t);
-
-static struct sa_hash_type fc_local_port_hash_by_fid = {
- .st_link_offset = offsetof(struct fc_local_port, fl_hash_link),
- .st_match = fc_local_port_fid_match,
- .st_hash = fc_local_port_fid_hash,
-};
-
-/*
* Return max segment size for local port.
*/
static u_int fc_local_port_mfs(struct fc_local_port *lp)
@@ -842,29 +930,6 @@ static void fc_local_port_enter_logo(struct fc_local_port *lp)
fc_local_port_els_send(lp, sp, fp);
}
-int fc_local_port_table_create(struct fc_virt_fab *vp)
-{
- struct sa_hash *hp;
-
- WARN_ON(vp->vf_lport_by_fid);
-
- hp = sa_hash_create(&fc_local_port_hash_by_fid,
- FC_LOCAL_PORT_HASH_SIZE);
-
- if (!hp)
- return -1;
- vp->vf_lport_by_fid = hp;
- INIT_LIST_HEAD(&vp->vf_local_ports);
-
- return 0;
-}
-
-void fc_local_port_table_destroy(struct fc_virt_fab *vp)
-{
- WARN_ON(!list_empty(&vp->vf_local_ports));
- sa_hash_destroy(vp->vf_lport_by_fid);
-}
-
/*
* Create Local Port.
*/
@@ -928,26 +993,24 @@ err:
static void fc_local_port_set_fid_int(struct fc_local_port *lp, fc_fid_t fid)
{
struct fc_local_port *found;
- struct fc_virt_fab *vf;
- vf = lp->fl_vf;
if (lp->fl_fid != fid) {
if (fc_local_port_debug) {
OFC_DBG("changing local port fid from %x to %x",
lp->fl_fid, fid);
}
- fc_virt_fab_lock(vf);
+ fc_virt_fab_lock(lp->fl_vf);
if (lp->fl_fid) {
- found = sa_hash_lookup_delete(vf->vf_lport_by_fid,
- &lp->fl_fid);
+ found = fc_local_port_hash_lookup(&lp->fl_fid);
WARN_ON(found != lp);
+ fc_local_port_hash_delete(found);
}
- WARN_ON(sa_hash_lookup(vf->vf_lport_by_fid, &fid));
+ WARN_ON(fc_local_port_hash_lookup(&lp->fl_fid));
lp->fl_fid = fid;
- if (fid != 0)
- sa_hash_insert(vf->vf_lport_by_fid, &fid, lp);
- fc_virt_fab_unlock(vf);
- fc_sess_reset_list(vf, &lp->fl_sess_list);
+ if (lp->fl_fid != 0)
+ fc_local_port_hash_insert(lp);
+ fc_virt_fab_unlock(lp->fl_vf);
+ fc_sess_reset_list(lp->fl_vf, &lp->fl_sess_list);
}
}
@@ -1016,20 +1079,19 @@ struct fc_els_rnid_gen *fc_local_port_get_rnidp(struct fc_local_port *lp)
static void fc_local_port_delete(struct fc_local_port *lp)
{
struct fc_local_port *found;
- struct fc_virt_fab *vf;
if (fc_local_port_debug)
OFC_DBG("local port %6x delete", lp->fl_fid);
- vf = lp->fl_vf;
- fc_virt_fab_lock(vf);
+ fc_virt_fab_lock(lp->fl_vf);
if (lp->fl_fid) {
- found = sa_hash_lookup_delete(vf->vf_lport_by_fid, &lp->fl_fid);
+ found = fc_local_port_hash_lookup(&lp->fl_fid);
WARN_ON(found != lp);
+ fc_local_port_hash_delete(found);
lp->fl_fid = 0;
}
list_del(&lp->fl_list);
- fc_virt_fab_unlock(vf);
+ fc_virt_fab_unlock(lp->fl_vf);
sa_event_list_free(lp->fl_events);
sa_free(lp);
}
@@ -1551,7 +1613,7 @@ void fc_local_port_recv(struct fc_local_port *lp, struct fc_frame *fp)
d_id = net24_get(&fh->fh_d_id);
key = fc_sess_key(d_id, s_id);
rcu_read_lock();
- sess = sa_hash_lookup(lp->fl_vf->vf_sess_by_fids, &key);
+ sess = fc_sess_hash_lookup(&key);
if (!sess) {
rcu_read_unlock();
fc_exch_recv_req(mp, fp, lp->fl_max_payload,
@@ -1603,20 +1665,6 @@ static void fc_local_port_error(enum fc_event event, void *lp_arg)
fc_local_port_unlock_send(lp);
}
-static int fc_local_port_fid_match(const sa_hash_key_t key, void *lp_arg)
-{
- struct fc_local_port *lp = lp_arg;
-
- return *(fc_fid_t *) key == lp->fl_fid;
-}
-
-static u_int32_t fc_local_port_fid_hash(const sa_hash_key_t key)
-{
- fc_fid_t fid = *(fc_fid_t *) key;
-
- return (fid >> 8) ^ fid;
-}
-
/*
* Handle state change from the ingress/egress port.
*/
diff --git a/drivers/scsi/ofc/libfc/fc_local_port_impl.h b/drivers/scsi/ofc/libfc/fc_local_port_impl.h
index ce32176..3f26c90 100644
--- a/drivers/scsi/ofc/libfc/fc_local_port_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_local_port_impl.h
@@ -23,7 +23,6 @@
#include <linux/timer.h>
#include "fc_sess.h"
#include "fc_sess_impl.h"
-#include "sa_hash.h"
#include "fc_ns.h"
struct fc_els_rscn_page;
@@ -82,7 +81,7 @@ struct fc_local_port {
void *); /* callback for incoming PRLI */
void *fl_prli_cb_arg; /* arg for PRLI callback */
struct sa_event_list *fl_events; /* event list head */
- struct sa_hash_link fl_hash_link; /* hash list linkage */
+ struct hlist_node fl_hash_link; /* hash list linkage */
struct timer_list fl_timer; /* timer for state events */
/*
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/6] [FCoE] remove hash tables from fc_virt_fab
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
` (2 preceding siblings ...)
2008-02-07 8:21 ` [PATCH 4/6] [FCoE] hash for fc_local_port: " Yi Zou
@ 2008-02-07 8:21 ` Yi Zou
2008-02-07 8:21 ` [PATCH 6/6] [FCoE] remove sa_hash_kern.c/sa_hash.h Yi Zou
4 siblings, 0 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
Remove vf_rport_by_fid, vf_rport_by_wwn, vf_lport_by_fid, vf_sess_by_fids
in struct fc_virt_fab of fc_virt_fab_impl.h
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/libfc/fc_virt_fab_impl.h | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
index e19714a..51d4543 100644
--- a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
@@ -23,10 +23,6 @@
struct fc_virt_fab {
uint vf_tag; /* virtual fabric tag (or zero) */
struct list_head vf_remote_ports; /* remote ports */
- struct sa_hash *vf_rport_by_fid; /* remote ports by FCID */
- struct sa_hash *vf_rport_by_wwpn; /* remote ports by WWPN */
- struct sa_hash *vf_lport_by_fid; /* local ports by FCID */
- struct sa_hash *vf_sess_by_fids; /* sessions by FCID pairs */
struct list_head vf_local_ports; /* list of local ports */
struct fc_exch_mgr *vf_exch_mgr; /* exchange mgr for fabric */
spinlock_t vf_lock; /* lock for all tables and lists */
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6/6] [FCoE] remove sa_hash_kern.c/sa_hash.h
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
` (3 preceding siblings ...)
2008-02-07 8:21 ` [PATCH 5/6] [FCoE] remove hash tables from fc_virt_fab Yi Zou
@ 2008-02-07 8:21 ` Yi Zou
4 siblings, 0 replies; 6+ messages in thread
From: Yi Zou @ 2008-02-07 8:21 UTC (permalink / raw)
To: linux-scsi
1. Remove libsa/sa_hash_kern.c
2. Remove include/sa_hash.h
3. Remove all references to sa_hash_xxx
4. Update Makefile accordingly in libsa
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/sa_hash.h | 65 ---------------
drivers/scsi/ofc/libfc/fc_exch.c | 1
drivers/scsi/ofc/libfc/fc_sess_impl.h | 1
drivers/scsi/ofc/libsa/Makefile | 4 -
drivers/scsi/ofc/libsa/sa_hash_kern.c | 141 ---------------------------------
5 files changed, 1 insertions(+), 211 deletions(-)
delete mode 100644 drivers/scsi/ofc/include/sa_hash.h
delete mode 100644 drivers/scsi/ofc/libsa/sa_hash_kern.c
diff --git a/drivers/scsi/ofc/include/sa_hash.h b/drivers/scsi/ofc/include/sa_hash.h
deleted file mode 100644
index d4ee6be..0000000
--- a/drivers/scsi/ofc/include/sa_hash.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Maintained at www.Open-FCoE.org
- */
-
-#ifndef _LIBSA_HASH_H_
-#define _LIBSA_HASH_H_
-
-#include <linux/list.h>
-
-/*
- * Hash table facility.
- */
-struct sa_hash;
-
-/*
- * Hash key value.
- */
-typedef void * sa_hash_key_t; /* pointer hash key */
-typedef u_int32_t sa_hash_key32_t; /* fixed-size 32-bit hash key */
-
-struct sa_hash_type {
- u_int16_t st_link_offset; /* offset of linkage in the element */
- int (*st_match)(const sa_hash_key_t, void *elem);
- u_int32_t (*st_hash)(const sa_hash_key_t);
-};
-
-/*
- * Element linkage on the hash.
- * The collision list is circular.
- */
-#define sa_hash_link hlist_node
-
-struct sa_hash *sa_hash_create(const struct sa_hash_type *, u_int32_t size);
-
-void sa_hash_destroy(struct sa_hash *);
-
-void *sa_hash_lookup(struct sa_hash *, const sa_hash_key_t);
-
-void sa_hash_insert(struct sa_hash *, const sa_hash_key_t, void *elem);
-
-void sa_hash_insert_next(struct sa_hash *, sa_hash_key32_t *,
- sa_hash_key32_t min_key, sa_hash_key32_t max_key,
- void *elem);
-
-void *sa_hash_lookup_delete(struct sa_hash *, const sa_hash_key_t);
-
-void sa_hash_iterate(struct sa_hash *,
- void (*callback)(void *entry, void *arg), void *arg);
-
-#endif /* _LIBSA_HASH_H_ */
diff --git a/drivers/scsi/ofc/libfc/fc_exch.c b/drivers/scsi/ofc/libfc/fc_exch.c
index db67d98..1ceab9c 100644
--- a/drivers/scsi/ofc/libfc/fc_exch.c
+++ b/drivers/scsi/ofc/libfc/fc_exch.c
@@ -27,7 +27,6 @@
#include "sa_kernel.h"
#include "net_types.h"
#include "ofc_dbg.h"
-#include "sa_hash.h"
#include "fc_fcip.h"
#include "fc_fc2.h"
diff --git a/drivers/scsi/ofc/libfc/fc_sess_impl.h b/drivers/scsi/ofc/libfc/fc_sess_impl.h
index c600186..84befab 100644
--- a/drivers/scsi/ofc/libfc/fc_sess_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_sess_impl.h
@@ -22,7 +22,6 @@
#include <linux/timer.h>
#include "fc_exch.h"
-#include "sa_hash.h"
#include <linux/rcupdate.h>
diff --git a/drivers/scsi/ofc/libsa/Makefile b/drivers/scsi/ofc/libsa/Makefile
index 3453608..fa6da75 100644
--- a/drivers/scsi/ofc/libsa/Makefile
+++ b/drivers/scsi/ofc/libsa/Makefile
@@ -4,6 +4,4 @@ EXTRA_CFLAGS += -I$(OFC_DIR)/include
obj-y += libsa.o
-libsa-y := \
- sa_event.o \
- sa_hash_kern.o
+libsa-y := sa_event.o
diff --git a/drivers/scsi/ofc/libsa/sa_hash_kern.c b/drivers/scsi/ofc/libsa/sa_hash_kern.c
deleted file mode 100644
index f1103a5..0000000
--- a/drivers/scsi/ofc/libsa/sa_hash_kern.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Maintained at www.Open-FCoE.org
- */
-
-#include "sa_kernel.h"
-#include "ofc_dbg.h"
-#include "sa_hash.h"
-
-struct sa_hash {
- struct sa_hash_type sh_type;
- u_int32_t sh_mask; /* mask for the size of the table */
- u_int32_t sh_entries; /* number of entries now in the table */
- struct hlist_head sh_table[0]; /* table (will be allocated bigger) */
-};
-
-struct sa_hash_elem { /* stand-in for the real client element */
- struct hlist_node elem_node;
-};
-
-static inline struct hlist_head *sa_hash_bucket(struct sa_hash *hp,
- sa_hash_key_t key)
-{
- return &hp->sh_table[(*hp->sh_type.st_hash) (key) & hp->sh_mask];
-}
-
-struct sa_hash *sa_hash_create(const struct sa_hash_type *tp, uint32_t req_size)
-{
- struct sa_hash *hp;
- u_int32_t size;
- size_t len;
-
- /*
- * Pick power of 2 at least as big as size.
- */
- for (size = 4; size < (1UL << 31); size <<= 1)
- if (size >= req_size)
- break;
-
- len = sizeof(*hp) + size * sizeof(struct hlist_head);
- hp = sa_malloc(len);
- if (hp) {
- memset(hp, 0, len);
- hp->sh_type = *tp;
- hp->sh_mask = size - 1;
- }
- return hp;
-}
-
-void sa_hash_destroy(struct sa_hash *hp)
-{
- sa_free(hp);
-}
-
-void *sa_hash_lookup(struct sa_hash *hp, const sa_hash_key_t key)
-{
- struct sa_hash_elem *ep;
- struct hlist_node *np;
- struct hlist_head *hhp;
- void *rp = NULL;
-
- hhp = sa_hash_bucket(hp, key);
- hlist_for_each_entry_rcu(ep, np, hhp, elem_node) {
- rp = (void *)((char *)ep - hp->sh_type.st_link_offset);
- if ((*hp->sh_type.st_match) (key, rp))
- break;
- rp = NULL;
- }
- return rp;
-}
-
-void *sa_hash_lookup_delete(struct sa_hash *hp, const sa_hash_key_t key)
-{
- struct sa_hash_elem *ep;
- struct hlist_node *np;
- struct hlist_head *hhp;
- void *rp = NULL;
-
- hhp = sa_hash_bucket(hp, key);
- hlist_for_each_entry_rcu(ep, np, hhp, elem_node) {
- rp = (void *)((char *)ep - hp->sh_type.st_link_offset);
- if ((*hp->sh_type.st_match) (key, rp)) {
- hlist_del_rcu(np);
- hp->sh_entries--;
- break;
- }
- rp = NULL;
- }
- return (rp);
-}
-
-void sa_hash_insert(struct sa_hash *hp, const sa_hash_key_t key, void *ep)
-{
- struct hlist_head *hhp;
- struct hlist_node *lp; /* new link pointer */
-
- lp = (struct hlist_node *)((char *)ep + hp->sh_type.st_link_offset);
- hhp = sa_hash_bucket(hp, key);
- hlist_add_head_rcu(lp, hhp);
- hp->sh_entries++;
-}
-
-/*
- * Iterate through all hash entries.
- * For debugging. This can be slow.
- */
-void
-sa_hash_iterate(struct sa_hash *hp,
- void (*callback) (void *ep, void *arg), void *arg)
-{
- struct hlist_head *hhp;
- struct hlist_node *np;
- struct sa_hash_elem *ep;
- void *entry;
- int count = 0;
-
- for (hhp = hp->sh_table; hhp < &hp->sh_table[hp->sh_mask + 1]; hhp++) {
- hlist_for_each_entry_rcu(ep, np, hhp, elem_node) {
- entry = (void *)((char *)ep -
- hp->sh_type.st_link_offset);
- (*callback) (entry, arg);
- count++;
- }
- }
- if (count != hp->sh_entries)
- OFC_DBG("sh_entries %d != count %d", hp->sh_entries, count);
-}
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-02-07 8:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-07 8:21 [PATCH 1/6] [FCoE] Fix the openfc Makefile to build as included in kernel Yi Zou
2008-02-07 8:21 ` [PATCH 2/6] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
2008-02-07 8:21 ` [PATCH 3/6] [FCoE] hash for fc_sess: " Yi Zou
2008-02-07 8:21 ` [PATCH 4/6] [FCoE] hash for fc_local_port: " Yi Zou
2008-02-07 8:21 ` [PATCH 5/6] [FCoE] remove hash tables from fc_virt_fab Yi Zou
2008-02-07 8:21 ` [PATCH 6/6] [FCoE] remove sa_hash_kern.c/sa_hash.h Yi Zou
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).