[pnfs] [PATCH 1/1] Changed the max_slots for the slot table from u32 to atomic_t

iyer at netapp.com iyer at netapp.com
Fri Mar 16 23:24:27 EDT 2007


From: Rahul Iyer<iyer at netapp.com>

This change enables us to read the variable atomically thus eliminating the
need for the spinlock.

Signed-off-by: Rahul Iyer<iyer at netapp.com>
---
 fs/nfs/nfs4proc.c              |   29 ++++++++++++++---------------
 include/linux/nfs41_sessions.h |    3 +--
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 89702cf..185f0c4 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -273,13 +273,10 @@ struct nfs4_slot *nfs4_find_slot(struct nfs4_channel *channel)
 	min_waiters = tbl->slots[0].nr_waiters;
 	target_slot = &tbl->slots[0];
 
-	spin_lock(&tbl->slot_tbl_lock);
-	/* Make a local copy of max slots so we don't need to hold it through
-	 * out. 
+	/* Make a local copy of max slots.
 	 * XXX Will need to revalidate this if slots are reclaimed
 	 */
-	max_slots = tbl->max_slots;
-	spin_unlock(&tbl->slot_tbl_lock);
+	max_slots = atomic_read(&tbl->max_slots);
 
 	do {
 		need_to_sleep = 1;
@@ -357,7 +354,7 @@ static int _nfs41_proc_setup_sequence(struct nfs4_session *session, struct nfs41
 	*/
        args->seqid = slot->seq_nr++;
        args->slotid = slot->slot_nr;
-       args->maxslots = session->fore_channel.slot_table.max_slots;
+       args->maxslots = atomic_read(&session->fore_channel.slot_table.max_slots);
       
        res->slot = slot;
 
@@ -3940,17 +3937,17 @@ int nfs4_init_slot_table(struct nfs4_channel *channel)
 	int i;
 	struct nfs4_slot_table *tbl;
 	struct nfs4_slot *slot;
-	
+
 	tbl = &channel->slot_table;
-	tbl->max_slots = channel->chan_attrs.max_reqs;
+	atomic_set(&tbl->max_slots, channel->chan_attrs.max_reqs);
 
-	tbl->slots = kzalloc(tbl->max_slots * sizeof(struct nfs4_slot), GFP_ATOMIC);
+	tbl->slots = kzalloc(channel->chan_attrs.max_reqs * 
+					sizeof(struct nfs4_slot), GFP_ATOMIC);
+	
 	if (!tbl->slots)
 		return -ENOMEM;
 
-	spin_lock_init(&tbl->slot_tbl_lock);
-
-	for (i = 0; i < tbl->max_slots; ++i) {
+	for (i = 0; i < channel->chan_attrs.max_reqs; ++i) {
 		slot = &tbl->slots[i];
 
 		slot->slot_nr = i;
@@ -3969,10 +3966,12 @@ void nfs4_destroy_slot_table(struct nfs4_channel *channel)
 	int i;
 	struct nfs4_slot *slot;
 	struct nfs4_slot_table *tbl;
-
-	tbl = &channel->slot_table;
+	u32 max_slots;
 	
-	for (i = 0; i < tbl->max_slots;++i) {
+	tbl = &channel->slot_table;
+	max_slots = atomic_read(&tbl->max_slots);
+
+	for (i = 0; i < max_slots;++i) {
 		slot = &tbl->slots[i];
 
 		BUG_ON(slot->nr_waiters);
diff --git a/include/linux/nfs41_sessions.h b/include/linux/nfs41_sessions.h
index 02f45db..352fae8 100644
--- a/include/linux/nfs41_sessions.h
+++ b/include/linux/nfs41_sessions.h
@@ -30,8 +30,7 @@ struct nfs4_slot {
 
 struct nfs4_slot_table {
 	struct nfs4_slot	*slots;
-	u32			max_slots;
-	spinlock_t		slot_tbl_lock;
+	atomic_t		max_slots;
 };
 
 struct nfs4_channel {
-- 
1.5.0.2


More information about the pNFS mailing list