[PATCH 015 of 19] knfsd: make nlmclnt_next_cookie SMP safe

From: NeilBrown
Date: Fri Sep 01 2006 - 00:40:44 EST



From: Olaf Kirch <okir@xxxxxxx>

The way we incremented the NLM cookie in nlmclnt_next_cookie
was not thread safe. This patch changes the counter to an
atomic_t

Signed-off-by: Olaf Kirch <okir@xxxxxxx>
Signed-off-by: Neil Brown <neilb@xxxxxxx>

### Diffstat output
./fs/lockd/clntproc.c | 10 +++++-----
./include/linux/lockd/lockd.h | 1 +
2 files changed, 6 insertions(+), 5 deletions(-)

diff .prev/fs/lockd/clntproc.c ./fs/lockd/clntproc.c
--- .prev/fs/lockd/clntproc.c 2006-09-01 12:11:03.000000000 +1000
+++ ./fs/lockd/clntproc.c 2006-09-01 12:17:03.000000000 +1000
@@ -36,14 +36,14 @@ static const struct rpc_call_ops nlmclnt
/*
* Cookie counter for NLM requests
*/
-static u32 nlm_cookie = 0x1234;
+static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);

-static inline void nlmclnt_next_cookie(struct nlm_cookie *c)
+void nlmclnt_next_cookie(struct nlm_cookie *c)
{
- memcpy(c->data, &nlm_cookie, 4);
- memset(c->data+4, 0, 4);
+ u32 cookie = atomic_inc_return(&nlm_cookie);
+
+ memcpy(c->data, &cookie, 4);
c->len=4;
- nlm_cookie++;
}

static struct nlm_lockowner *nlm_get_lockowner(struct nlm_lockowner *lockowner)

diff .prev/include/linux/lockd/lockd.h ./include/linux/lockd/lockd.h
--- .prev/include/linux/lockd/lockd.h 2006-09-01 12:16:06.000000000 +1000
+++ ./include/linux/lockd/lockd.h 2006-09-01 12:17:03.000000000 +1000
@@ -157,6 +157,7 @@ int nlmclnt_block(struct nlm_wait *bl
u32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *);
void nlmclnt_recovery(struct nlm_host *);
int nlmclnt_reclaim(struct nlm_host *, struct file_lock *);
+void nlmclnt_next_cookie(struct nlm_cookie *);

/*
* Host cache
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/