2006-09-29 03:08:52

by NeilBrown

[permalink] [raw]
Subject: [PATCH 002 of 8] knfsd: lockd: fix refount on nsm.


If nlm_lookup_host finds what it is looking for
it exits with an extra reference on the matching
'nsm' structure.
So don't actually count the reference until we are
(fairly) sure it is going to be used.

Signed-off-by: Neil Brown <[email protected]>

### Diffstat output
./fs/lockd/host.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff .prev/fs/lockd/host.c ./fs/lockd/host.c
--- .prev/fs/lockd/host.c 2006-09-29 11:44:21.000000000 +1000
+++ ./fs/lockd/host.c 2006-09-29 11:55:15.000000000 +1000
@@ -103,8 +103,8 @@ nlm_lookup_host(int server, const struct
continue;

/* See if we have an NSM handle for this client */
- if (!nsm && (nsm = host->h_nsmhandle) != 0)
- atomic_inc(&nsm->sm_count);
+ if (!nsm)
+ nsm = host->h_nsmhandle;

if (host->h_proto != proto)
continue;
@@ -120,6 +120,8 @@ nlm_lookup_host(int server, const struct
nlm_get_host(host);
goto out;
}
+ if (nsm)
+ atomic_inc(&nsm->sm_count);

host = NULL;


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2006-09-29 06:02:05

by Olaf Kirch

[permalink] [raw]
Subject: Re: [PATCH 002 of 8] knfsd: lockd: fix refount on nsm.

On Fri, Sep 29, 2006 at 01:08:45PM +1000, NeilBrown wrote:
> If nlm_lookup_host finds what it is looking for
> it exits with an extra reference on the matching
> 'nsm' structure.
> So don't actually count the reference until we are
> (fairly) sure it is going to be used.
>
> Signed-off-by: Neil Brown <[email protected]>

Correct, even though I would have done it slightly differently. The if()
is not needed anymore, and there's another if (nsm) two lines down.

Olaf

fs/lockd/host.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

Index: build/fs/lockd/host.c
===================================================================
--- build.orig/fs/lockd/host.c
+++ build/fs/lockd/host.c
@@ -109,9 +109,9 @@ nlm_lookup_host(int server, const struct
if (!nlm_cmp_addr(&host->h_addr, sin))
continue;

- /* See if we have an NSM handle for this client */
- if (!nsm && (nsm = host->h_nsmhandle) != 0)
- atomic_inc(&nsm->sm_count);
+ /* Stash away the NSM handle in case we need
+ * to create a new host entry. */
+ nsm = host->h_nsmhandle;

if (host->h_proto != proto)
continue;
@@ -133,7 +133,9 @@ nlm_lookup_host(int server, const struct
/* Sadly, the host isn't in our hash table yet. See if
* we have an NSM handle for it. If not, create one.
*/
- if (!nsm && !(nsm = nsm_find(sin, hostname, hostname_len)))
+ if (nsm != NULL)
+ atomic_inc(&nsm->sm_count);
+ else if (!(nsm = nsm_find(sin, hostname, hostname_len)))
goto out;

if (!(host = (struct nlm_host *) kmalloc(sizeof(*host), GFP_KERNEL))) {

--
Olaf Kirch | --- o --- Nous sommes du soleil we love when we play
[email protected] | / | \ sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs