* [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description
@ 2008-02-13 19:09 Yi Zou
2008-02-13 19:09 ` [PATCH 1/4] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Yi Zou @ 2008-02-13 19:09 UTC (permalink / raw)
To: linux-scsi; +Cc: devel
The following series remove use of all sa_hash_xxx in hash table operations
for fc_local_port, fc_remote_port, and fc_sess. sa_hash_kern.c and sa_hash.h
are removed. All abstraction using sa_hash_xxx are removed and replaced by
using hlist_head, hlist_node directly. Hash functions are in their own module
now for fc_remote_port and fc_sess.
For fc_local_port, the hash is completely removed since there is always going
to be just one fc_local_port per openfc/fcoe. For fc_remote_port, the hash by
wwpn is removed with hash by remote port FCID already there. Hash entry
counters are removed as they are used only in debugging/printting routines.
All debugging/testing functions, e.g. hash table iterate, print, are removed
as well.
Note that fc_virt_fab struct is still the place holder for the hash tables,
which eventually will be in fcs_state struct once fc_virt_fab is merged with
the fcs_state struct.
---
Yi Zou (4):
[FCoE] 4. remove sa_hash_kern.c/sa_hash.h
[FCoE] 3. remove hash table for fc_local_port
[FCoE] 2. hash for fc_sess: do not use sa_hash_xxx
[FCoE] 1. hash for fc_remote_port: do not use sa_hash_xxx
drivers/scsi/ofc/include/fc_local_port.h | 6
drivers/scsi/ofc/include/fc_remote_port.h | 4
drivers/scsi/ofc/include/fc_sess.h | 3
drivers/scsi/ofc/include/sa_hash.h | 65 -----
drivers/scsi/ofc/libfc/fc_exch.c | 1
drivers/scsi/ofc/libfc/fc_local_port.c | 85 -------
drivers/scsi/ofc/libfc/fc_local_port_impl.h | 4
drivers/scsi/ofc/libfc/fc_remote_port.c | 325 ++++++++++++---------------
drivers/scsi/ofc/libfc/fc_sess.c | 214 +++++++++++-------
drivers/scsi/ofc/libfc/fc_sess_impl.h | 3
drivers/scsi/ofc/libfc/fc_virt_fab.c | 5
drivers/scsi/ofc/libfc/fc_virt_fab_impl.h | 10 -
drivers/scsi/ofc/libsa/Makefile | 4
drivers/scsi/ofc/libsa/sa_hash_kern.c | 141 ------------
14 files changed, 298 insertions(+), 572 deletions(-)
delete mode 100644 drivers/scsi/ofc/include/sa_hash.h
delete mode 100644 drivers/scsi/ofc/libsa/sa_hash_kern.c
--
Yi Zou <yi.zou@intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx
2008-02-13 19:09 [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description Yi Zou
@ 2008-02-13 19:09 ` Yi Zou
2008-02-13 19:09 ` [PATCH 2/4] [FCoE] hash for fc_sess: " Yi Zou
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yi Zou @ 2008-02-13 19:09 UTC (permalink / raw)
To: linux-scsi; +Cc: devel
This patch removes using sa_hash_xxx and sticks to hlist_head and hlist_node
struct for hashing the fc_remote_port, removing abstractions of sa_hash
struct. The hash by world wide port name is redundant and thus removed. Also,
all debugging rouintes are removed. The hash entry counter is removed as well
as it is used only in debugging routines.
1. Added hash by fcid functions for fc_remote_port
2. Removed hash table by rport wwpn from fc_virt_fab struct
3. Removed fc_remote_port hash table entry counters
4. Removed debug iterate/print rouintes
5. Removed references to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/fc_remote_port.h | 4
drivers/scsi/ofc/libfc/fc_remote_port.c | 325 +++++++++++++----------------
drivers/scsi/ofc/libfc/fc_virt_fab_impl.h | 3
3 files changed, 146 insertions(+), 186 deletions(-)
diff --git a/drivers/scsi/ofc/include/fc_remote_port.h b/drivers/scsi/ofc/include/fc_remote_port.h
index 07b20fb..4cac26b 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,7 @@ 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;
/*
* 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..b7114f8 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,72 +35,138 @@
#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)
+
+/**
+ * fc_remote_port_fid_match - the compare function by fcid
+ * @fid: fcid as the input for match-up
+ * @rp: the ptr to the remote port to be matched
+ */
+static inline int fc_remote_port_fid_match(fc_fid_t fid,
+ const struct fc_remote_port *rp)
+{
+ return fid == rp->rp_fid;
+}
-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);
+/**
+ * fc_remote_port_fid_hash - hash remote port by fcid
+ * @fid: the fc id used as the hash key
+ *
+ * this hash returns the rport fc id masked off by hash size-1.
+ */
+static inline uint32_t fc_remote_port_fid_hash(fc_fid_t fid)
+{
+ return fid & FC_HASH_RPORT_MASK;
+}
-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_bucket - returns the bucket in the hash table
+ * @vf: ptr to the virtual fabric struct
+ * @fid: the fc id used as the hash key
+ */
+static inline struct hlist_head *fc_remote_port_fid_bucket(
+ const struct fc_virt_fab *vf, fc_fid_t fid)
+{
+ return &vf->vf_rport_by_fid[fc_remote_port_fid_hash(fid)];
+}
-#ifdef FC_REMOTE_PORT_BY_WWPN
-/*
- * Declare hash table type for lookup by WWPN.
+/**
+ * fc_remote_port_fid_hash_lookup - lookup a remote port by fcid
+ * @vf: ptr to the virtual fabric struct
+ * @fid: the fc id used as the hash key
+ *
+ * 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 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 inline struct fc_remote_port *fc_remote_port_fid_hash_lookup(
+ const struct fc_virt_fab *vf, fc_fid_t fid)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_remote_port *rp;
-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 */
+ head = fc_remote_port_fid_bucket(vf, 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;
+}
-int fc_remote_port_table_create(struct fc_virt_fab *vp)
+/**
+ * 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);
+}
- INIT_LIST_HEAD(&vp->vf_remote_ports);
-
- vp->vf_rport_by_fid = sa_hash_create(&fc_remote_port_hash_by_fid,
- FC_REMOTE_PORT_HASH_SIZE);
+/**
+ * fc_remote_port_fid_hash_insert - insert the remote port into fcid hash
+ * @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 struct fc_remote_port *rp)
+{
+ struct hlist_head *head;
- if (!vp->vf_rport_by_fid)
- return -1;
+ head = fc_remote_port_fid_bucket(rp->rp_vf, rp->rp_fid);
+ hlist_add_head_rcu((struct hlist_node *)&rp->rp_fid_hash_link, head);
+}
-#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);
+/**
+ * fc_remote_port_table_create - allocate the memory for hash table
+ * also initializes the list haed and hlist head.
+ * @vf: ptr to the virtual fabric struct
+ */
+int fc_remote_port_table_create(struct fc_virt_fab *vf)
+{
+ int size;
+ int loop;
- if (!vp->vf_rport_by_wwpn) {
- sa_hash_destroy(vp->vf_rport_by_fid);
+ INIT_LIST_HEAD(&vf->vf_remote_ports);
+ size = sizeof(struct hlist_head) * FC_HASH_RPORT_BUCKETS;
+ vf->vf_rport_by_fid = sa_malloc(size);
+ if (!vf->vf_rport_by_fid)
return -1;
- }
-#endif /* FC_REMOTE_PORT_BY_WWPN */
+ for (loop = 0; loop < FC_HASH_RPORT_BUCKETS; loop++)
+ INIT_HLIST_HEAD(&vf->vf_rport_by_fid[loop]);
return 0;
}
-void fc_remote_port_table_destroy(struct fc_virt_fab *vp)
+/**
+ * fc_remote_port_table_destroy - release the memory allocated for hash table
+ * @vf: ptr to the virtual fabric struct
+ */
+void fc_remote_port_table_destroy(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;
-
-#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 */
+ WARN_ON(!list_empty(&vf->vf_remote_ports));
+ INIT_LIST_HEAD(&vf->vf_remote_ports);
+ if (vf->vf_rport_by_fid) {
+ sa_free(vf->vf_rport_by_fid);
+ vf->vf_rport_by_fid = NULL;
+ }
}
-struct fc_remote_port *fc_remote_port_create(struct fc_virt_fab *vp,
+/**
+ * fc_remote_port_create - create a remote port.
+ * @vf: 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 *vf,
fc_wwn_t port_name)
{
struct fc_remote_port *rp;
@@ -109,7 +174,7 @@ struct fc_remote_port *fc_remote_port_create(struct fc_virt_fab *vp,
rp = sa_malloc(sizeof(*rp));
if (rp) {
memset(rp, 0, sizeof(*rp));
- rp->rp_vf = vp;
+ rp->rp_vf = vf;
atomic_set(&rp->rp_refcnt, 1);
rp->rp_events = sa_event_list_alloc();
@@ -118,43 +183,26 @@ struct fc_remote_port *fc_remote_port_create(struct fc_virt_fab *vp,
sa_free(rp);
rp = NULL;
} else {
- list_add_tail(&rp->rp_list, &vp->vf_remote_ports);
+ list_add_tail(&rp->rp_list, &vf->vf_remote_ports);
fc_remote_port_set_name(rp, port_name, 0);
}
}
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.
+ * @vf: 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,
+struct fc_remote_port *fc_remote_port_lookup_create(struct fc_virt_fab *vf,
fc_fid_t fid,
fc_wwn_t wwpn,
fc_wwn_t wwnn)
@@ -162,19 +210,15 @@ struct fc_remote_port *fc_remote_port_lookup_create(struct fc_virt_fab *vp,
struct fc_remote_port *rp;
rp = NULL;
- fc_virt_fab_lock(vp);
+ fc_virt_fab_lock(vf);
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 */
+ rp = fc_remote_port_fid_hash_lookup(vf, fid);
if (!rp) {
- fc_virt_fab_unlock(vp);
- rp = fc_remote_port_create(vp, wwpn);
+ fc_virt_fab_unlock(vf);
+ rp = fc_remote_port_create(vf, wwpn); /* create and hold */
} else {
fc_remote_port_hold(rp);
- fc_virt_fab_unlock(vp);
+ fc_virt_fab_unlock(vf);
}
if (rp) {
if (fid && rp->rp_fid != fid)
@@ -185,57 +229,14 @@ struct fc_remote_port *fc_remote_port_lookup_create(struct fc_virt_fab *vp,
return rp;
}
-#ifdef FC_REMOTE_PORT_DEBUG
-/*
- * Debug remote port print.
- */
-static void fc_remote_port_print(void *rp_arg, void *msg_arg)
-{
- struct fc_remote_port *rp = rp_arg;
-
- OFC_DBG("%s rp %6x wwpn %16llx %p",
- (char *)msg_arg, rp->rp_fid, rp->rp_port_wwn, rp);
-}
-
-/*
- * Debug print of remote ports from hash.
- */
-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, "");
-}
-#endif /* FC_REMOTE_PORT_DEBUG */
-
/*
* Set remote port's port and node names.
*/
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;
-
- 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);
- }
-#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);
-#endif /* FC_REMOTE_PORT_BY_WWPN */
}
/*
@@ -243,48 +244,38 @@ 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;
+ struct fc_virt_fab *vf;
if (fid != rp->rp_fid) {
- vp = rp->rp_vf;
- fc_virt_fab_lock(vp);
+ vf = rp->rp_vf;
+ fc_virt_fab_lock(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(vf, 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(rp);
+ fc_virt_fab_unlock(vf);
}
}
static void fc_remote_port_delete(struct fc_remote_port *rp)
{
struct fc_remote_port *found;
- struct fc_virt_fab *vp;
+ struct fc_virt_fab *vf;
- vp = rp->rp_vf;
- fc_virt_fab_lock(vp);
+ vf = rp->rp_vf;
+ fc_virt_fab_lock(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(vf, 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);
- WARN_ON(found != rp);
- }
-#endif /* FC_REMOTE_PORT_BY_WWPN */
list_del(&rp->rp_list);
- fc_virt_fab_unlock(vp);
+ fc_virt_fab_unlock(vf);
sa_event_list_free(rp->rp_events);
sa_free(rp);
}
@@ -299,31 +290,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 */
diff --git a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
index e19714a..115b650 100644
--- a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
@@ -23,8 +23,7 @@
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 hlist_head *vf_rport_by_fid; /* remote ports by FCID */
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 */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] [FCoE] hash for fc_sess: do not use sa_hash_xxx
2008-02-13 19:09 [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description Yi Zou
2008-02-13 19:09 ` [PATCH 1/4] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
@ 2008-02-13 19:09 ` Yi Zou
2008-02-13 19:10 ` [PATCH 3/4] [FCoE] remove hash table for fc_local_port Yi Zou
2008-02-13 19:10 ` [PATCH 4/4] [FCoE] remove sa_hash_kern.c/sa_hash.h Yi Zou
3 siblings, 0 replies; 5+ messages in thread
From: Yi Zou @ 2008-02-13 19:09 UTC (permalink / raw)
To: linux-scsi; +Cc: devel
This patch removes using sa_hash_xxx and sticks to hlist_head and hlist_node
struct for hashing the fc_sess struct, removing the use of the sa_hash struct.
Also, the hash entry counter is removed as it's only used for debugging.
1. Added hash table funcs for fc_sess
2. Removed the fc_sess hash table entry counter
3. Removed refrences to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/fc_sess.h | 3
drivers/scsi/ofc/libfc/fc_sess.c | 214 +++++++++++++++++++----------
drivers/scsi/ofc/libfc/fc_sess_impl.h | 3
drivers/scsi/ofc/libfc/fc_virt_fab_impl.h | 2
4 files changed, 143 insertions(+), 79 deletions(-)
diff --git a/drivers/scsi/ofc/include/fc_sess.h b/drivers/scsi/ofc/include/fc_sess.h
index d0b4f73..eb79d20 100644
--- a/drivers/scsi/ofc/include/fc_sess.h
+++ b/drivers/scsi/ofc/include/fc_sess.h
@@ -81,6 +81,9 @@ 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 struct fc_virt_fab *vf,
+ uint64_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..1e3e3cc 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,136 @@ 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);
+
+/*
+ * 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)
+
+/**
+ * fc_sess_hash_match - session hash table match functio
+ * @key: the key for match up compare
+ * @sess: the ptr to the fc_sess structure
+ */
+static inline int fc_sess_hash_match(uint64_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 key used to do the hash
+ */
+static inline uint32_t fc_sess_hash(uint64_t key)
+{
+ return ((uint32_t) ((key >> 20) ^ key)) & FC_HASH_SESS_MASK;
+}
+
+/**
+ * fc_sess_hash_bucket - returns the bucket in the fid hash table
+ * @vf: the ptr to the virtual fabric struct
+ * @key: the key for match up compare
+ */
+static inline struct hlist_head *fc_sess_hash_bucket(
+ const struct fc_virt_fab *vf, uint64_t key)
+{
+ return &vf->vf_sess_by_fids[fc_sess_hash(key)];
+}
+
+
+/**
+ * fc_sess_hash_delete - remove the give session from the hash table
+ * @vf: the ptr to the virtual fabric struct
+ * @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(struct fc_virt_fab *vf,
+ const struct fc_sess *sess)
+{
+ hlist_del_rcu((struct hlist_node *)&sess->fs_hash_link);
+}
+
+/**
+ * fc_sess_hash_insert - session hash table match functio
+ * @vf: the ptr to the virtual fabric struct
+ * @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(struct fc_virt_fab *vf,
+ uint64_t key, const struct fc_sess *sess)
+{
+ struct hlist_head *head;
+
+ head = fc_sess_hash_bucket(vf, key);
+ hlist_add_head_rcu((struct hlist_node *)&sess->fs_hash_link, head);
+}
+
+/**
+ * fc_sess_hash_lookup - Lookup the session hash table by key.
+ * @vf: the ptr to the virtual fabric struct
+ * @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.
+ */
+struct fc_sess *fc_sess_hash_lookup(const struct fc_virt_fab *vf, uint64_t key)
+{
+ struct hlist_node *node;
+ struct hlist_head *head;
+ struct fc_sess *sess;
+
+ head = fc_sess_hash_bucket(vf, 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_table_create - allocate memory for the hash table
+ * @vf: ptr to the virtual fabric
+ *
+ * Allocates the memory for hash table. initalize the list head
+ * as well as the hash link list head.
+ */
+int fc_sess_table_create(struct fc_virt_fab *vf)
+{
+ int loop;
+ int size;
+
+ size = sizeof(struct hlist_head) * FC_HASH_SESS_BUCKETS;
+ vf->vf_sess_by_fids = (struct hlist_head *)sa_malloc(size);
+ if (!vf->vf_sess_by_fids)
+ return -1;
+ for (loop = 0; loop < FC_HASH_SESS_BUCKETS; loop++)
+ INIT_HLIST_HEAD(&vf->vf_sess_by_fids[loop]);
+ return 0;
+}
+
+/**
+ * fc_sess_table_destroy - release the allocated memory
+ * @vf: ptr to the virtual fabric
+ *
+ * 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);
+ if (vf->vf_sess_by_fids) {
+ sa_free(vf->vf_sess_by_fids);
+ vf->vf_sess_by_fids = NULL;
+ }
+ synchronize_rcu();
+}
/*
* Lock session.
@@ -170,20 +285,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.
*
@@ -232,30 +333,6 @@ static void fc_sess_iterate(struct fc_virt_fab *vf,
fc_virt_fab_unlock(vf);
}
-static void fc_sess_debug_print(void *sess_arg, void *arg)
-{
- struct fc_sess *sess = sess_arg;
-
- OFC_DBG("fid %6.6x did %6.6x ref %d\n", sess->fs_local_fid,
- sess->fs_remote_fid, atomic_read(&sess->fs_refcnt));
-
-}
-
-/*
- * 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 +391,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(vp, key);
if (found) {
fc_sess_hold(found);
fc_virt_fab_unlock(vp);
@@ -324,7 +401,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(vp, key, sess);
list_add_tail(&sess->fs_list, &lp->fl_sess_list);
fc_virt_fab_unlock(vp);
}
@@ -366,9 +443,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(vp, key);
WARN_ON(found != sess);
+ fc_sess_hash_delete(vp, found);
list_del(&sess->fs_list); /* under vf_lock */
fc_virt_fab_unlock(vp);
@@ -453,12 +530,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(vp, key);
WARN_ON(found != sess);
+ fc_sess_hash_delete(vp, found);
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(vp, key, sess);
}
fc_sess_enter_init(sess);
fc_sess_unlock_send(sess);
@@ -1387,21 +1464,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 +1487,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(vp, 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..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>
@@ -61,7 +60,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() */
diff --git a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
index 115b650..af7f9cb 100644
--- a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
@@ -25,7 +25,7 @@ struct fc_virt_fab {
struct list_head vf_remote_ports; /* remote ports */
struct hlist_head *vf_rport_by_fid; /* remote ports by FCID */
struct sa_hash *vf_lport_by_fid; /* local ports by FCID */
- struct sa_hash *vf_sess_by_fids; /* sessions by FCID pairs */
+ struct hlist_head *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] 5+ messages in thread
* [PATCH 3/4] [FCoE] remove hash table for fc_local_port
2008-02-13 19:09 [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description Yi Zou
2008-02-13 19:09 ` [PATCH 1/4] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
2008-02-13 19:09 ` [PATCH 2/4] [FCoE] hash for fc_sess: " Yi Zou
@ 2008-02-13 19:10 ` Yi Zou
2008-02-13 19:10 ` [PATCH 4/4] [FCoE] remove sa_hash_kern.c/sa_hash.h Yi Zou
3 siblings, 0 replies; 5+ messages in thread
From: Yi Zou @ 2008-02-13 19:10 UTC (permalink / raw)
To: linux-scsi; +Cc: devel
This patch removes hash table for fc_local_port. The fc_local_port is always
created per openfc/fcoe instance, no need to have the hash table. This also
removes any use or references to sa_hash_xxx, as well as the abstraction of
the sa_hash struct.
1. Removed local port hash by fid from struct fc_virt_fab
2. Remmoed local port hash functions from fc_local_port.c
3. Removed fl_hash_link from struct fc_local_port
4. Removed local port hash table create/destroy from fc_virt_fab.c
5. Removed all references to sa_hash_xxx
Signed-off-by: Yi Zou <yi.zou@intel.com>
---
drivers/scsi/ofc/include/fc_local_port.h | 6 --
drivers/scsi/ofc/libfc/fc_local_port.c | 85 ++-------------------------
drivers/scsi/ofc/libfc/fc_local_port_impl.h | 4 -
drivers/scsi/ofc/libfc/fc_virt_fab.c | 5 --
drivers/scsi/ofc/libfc/fc_virt_fab_impl.h | 7 +-
5 files changed, 9 insertions(+), 98 deletions(-)
diff --git a/drivers/scsi/ofc/include/fc_local_port.h b/drivers/scsi/ofc/include/fc_local_port.h
index 0781a8d..37edb94 100644
--- a/drivers/scsi/ofc/include/fc_local_port.h
+++ b/drivers/scsi/ofc/include/fc_local_port.h
@@ -99,12 +99,6 @@ u_int fc_local_port_get_payload_size(struct fc_els_flogi *, u_int maxval);
int fc_local_port_test_ready(struct fc_local_port *);
/*
- * Initialize local port lookups in virtual fabric.
- */
-int fc_local_port_table_create(struct fc_virt_fab *);
-void fc_local_port_table_destroy(struct fc_virt_fab *);
-
-/*
* For debugging and /sys only - return state name.
*/
const char *fc_local_port_state(struct fc_local_port *lp);
diff --git a/drivers/scsi/ofc/libfc/fc_local_port.c b/drivers/scsi/ofc/libfc/fc_local_port.c
index 5f28f4a..73c419c 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,7 @@ 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);
+
static inline void fc_local_port_enter_state(struct fc_local_port *lp,
enum fc_local_port_state state)
{
@@ -225,20 +225,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 +828,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.
*/
@@ -927,27 +890,15 @@ 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);
- if (lp->fl_fid) {
- found = sa_hash_lookup_delete(vf->vf_lport_by_fid,
- &lp->fl_fid);
- WARN_ON(found != lp);
- }
- WARN_ON(sa_hash_lookup(vf->vf_lport_by_fid, &fid));
+ spin_lock_bh(&lp->fl_lock);
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);
+ spin_unlock_bh(&lp->fl_lock);
+ fc_sess_reset_list(lp->fl_vf, &lp->fl_sess_list);
}
}
@@ -1015,21 +966,9 @@ 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);
- if (lp->fl_fid) {
- found = sa_hash_lookup_delete(vf->vf_lport_by_fid, &lp->fl_fid);
- WARN_ON(found != lp);
- lp->fl_fid = 0;
- }
- list_del(&lp->fl_list);
- fc_virt_fab_unlock(vf);
sa_event_list_free(lp->fl_events);
sa_free(lp);
}
@@ -1551,7 +1490,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(lp->fl_vf, key);
if (!sess) {
rcu_read_unlock();
fc_exch_recv_req(mp, fp, lp->fl_max_payload,
@@ -1603,20 +1542,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..725402e 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;
@@ -47,7 +46,7 @@ enum fc_local_port_state {
*
* Locking notes:
* Most of these fields are protected by fl_lock, with the exception that;
- * fl_list, fl_hash_link, fl_sess_list, are protected by the virtual fabric
+ * fl_list, fl_sess_list, are protected by the virtual fabric
* lock. The event list is protected by a lock in the sa_event facility.
* The refcnt is atomic, and release doesn't acquire fl_lock, just vf_lock.
*/
@@ -82,7 +81,6 @@ 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 timer_list fl_timer; /* timer for state events */
/*
diff --git a/drivers/scsi/ofc/libfc/fc_virt_fab.c b/drivers/scsi/ofc/libfc/fc_virt_fab.c
index dd84628..6972e92 100644
--- a/drivers/scsi/ofc/libfc/fc_virt_fab.c
+++ b/drivers/scsi/ofc/libfc/fc_virt_fab.c
@@ -63,12 +63,8 @@ struct fc_virt_fab *fc_virt_fab_alloc(u_int tag, enum fc_class class,
goto out_sp;
if (fc_remote_port_table_create(vp))
goto out_rp;
- if (fc_local_port_table_create(vp))
- goto out_lp;
return vp;
-out_lp:
- fc_remote_port_table_destroy(vp);
out_rp:
fc_sess_table_destroy(vp);
out_sp:
@@ -83,7 +79,6 @@ void fc_virt_fab_free(struct fc_virt_fab *vp)
{
fc_sess_table_destroy(vp);
fc_remote_port_table_destroy(vp);
- fc_local_port_table_destroy(vp);
if (vp->vf_exch_mgr)
fc_exch_mgr_free(vp->vf_exch_mgr);
sa_free(vp);
diff --git a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
index af7f9cb..51fe626 100644
--- a/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
+++ b/drivers/scsi/ofc/libfc/fc_virt_fab_impl.h
@@ -21,14 +21,13 @@
#define _LIBFC_FC_VIRT_FAB_IMPL_H_
struct fc_virt_fab {
- uint vf_tag; /* virtual fabric tag (or zero) */
+ uint32_t vf_tag; /* virtual fabric tag (or zero) */
+ spinlock_t vf_lock; /* lock for all tables and lists */
struct list_head vf_remote_ports; /* remote ports */
+ struct list_head vf_local_ports; /* list of local ports */
struct hlist_head *vf_rport_by_fid; /* remote ports by FCID */
- struct sa_hash *vf_lport_by_fid; /* local ports by FCID */
struct hlist_head *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] 5+ messages in thread
* [PATCH 4/4] [FCoE] remove sa_hash_kern.c/sa_hash.h
2008-02-13 19:09 [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description Yi Zou
` (2 preceding siblings ...)
2008-02-13 19:10 ` [PATCH 3/4] [FCoE] remove hash table for fc_local_port Yi Zou
@ 2008-02-13 19:10 ` Yi Zou
3 siblings, 0 replies; 5+ messages in thread
From: Yi Zou @ 2008-02-13 19:10 UTC (permalink / raw)
To: linux-scsi; +Cc: devel
This patch removes using sa_hash_kern.c and sa_hash.h files. All references
to the sa_hash.h are also removed.
1. Removed libsa/sa_hash_kern.c
2. Removed include/sa_hash.h
3. Removed all references to sa_hash_xxx
4. Updated 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/libsa/Makefile | 4 -
drivers/scsi/ofc/libsa/sa_hash_kern.c | 141 ---------------------------------
4 files changed, 1 insertions(+), 210 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/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] 5+ messages in thread
end of thread, other threads:[~2008-02-13 19:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-13 19:09 [PATCH 0/4] [FCoE] Remove sa_hash_xxx:series short description Yi Zou
2008-02-13 19:09 ` [PATCH 1/4] [FCoE] hash for fc_remote_port: do not use sa_hash_xxx Yi Zou
2008-02-13 19:09 ` [PATCH 2/4] [FCoE] hash for fc_sess: " Yi Zou
2008-02-13 19:10 ` [PATCH 3/4] [FCoE] remove hash table for fc_local_port Yi Zou
2008-02-13 19:10 ` [PATCH 4/4] [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).