Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=3bec63db55463365110d00721ed60a31e4614cb6
Commit:     3bec63db55463365110d00721ed60a31e4614cb6
Parent:     edc05fc1c24ba49dae585da1b2a22686f0b221f0
Author:     Trond Myklebust <[EMAIL PROTECTED]>
AuthorDate: Sun Jun 17 16:02:44 2007 -0400
Committer:  Trond Myklebust <[EMAIL PROTECTED]>
CommitDate: Tue Jul 10 23:40:27 2007 -0400

    NFS: Convert struct nfs_open_context to use a kref
    
    Signed-off-by: Trond Myklebust <[EMAIL PROTECTED]>
---
 fs/nfs/inode.c         |   40 +++++++++++++++++++++++-----------------
 include/linux/nfs_fs.h |    3 ++-
 2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index e7d2bba..01fc8ab 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -461,7 +461,6 @@ static struct nfs_open_context 
*alloc_nfs_open_context(struct vfsmount *mnt, str
 
        ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
        if (ctx != NULL) {
-               atomic_set(&ctx->count, 1);
                ctx->path.dentry = dget(dentry);
                ctx->path.mnt = mntget(mnt);
                ctx->cred = get_rpccred(cred);
@@ -469,6 +468,7 @@ static struct nfs_open_context 
*alloc_nfs_open_context(struct vfsmount *mnt, str
                ctx->lockowner = current->files;
                ctx->error = 0;
                ctx->dir_cookie = 0;
+               kref_init(&ctx->kref);
        }
        return ctx;
 }
@@ -476,27 +476,33 @@ static struct nfs_open_context 
*alloc_nfs_open_context(struct vfsmount *mnt, str
 struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
 {
        if (ctx != NULL)
-               atomic_inc(&ctx->count);
+               kref_get(&ctx->kref);
        return ctx;
 }
 
-void put_nfs_open_context(struct nfs_open_context *ctx)
+static void nfs_free_open_context(struct kref *kref)
 {
-       if (atomic_dec_and_test(&ctx->count)) {
-               if (!list_empty(&ctx->list)) {
-                       struct inode *inode = ctx->path.dentry->d_inode;
-                       spin_lock(&inode->i_lock);
-                       list_del(&ctx->list);
-                       spin_unlock(&inode->i_lock);
-               }
-               if (ctx->state != NULL)
-                       nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
-               if (ctx->cred != NULL)
-                       put_rpccred(ctx->cred);
-               dput(ctx->path.dentry);
-               mntput(ctx->path.mnt);
-               kfree(ctx);
+       struct nfs_open_context *ctx = container_of(kref,
+                       struct nfs_open_context, kref);
+
+       if (!list_empty(&ctx->list)) {
+               struct inode *inode = ctx->path.dentry->d_inode;
+               spin_lock(&inode->i_lock);
+               list_del(&ctx->list);
+               spin_unlock(&inode->i_lock);
        }
+       if (ctx->state != NULL)
+               nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
+       if (ctx->cred != NULL)
+               put_rpccred(ctx->cred);
+       dput(ctx->path.dentry);
+       mntput(ctx->path.mnt);
+       kfree(ctx);
+}
+
+void put_nfs_open_context(struct nfs_open_context *ctx)
+{
+       kref_put(&ctx->kref, nfs_free_open_context);
 }
 
 /*
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 750708c..bf24151 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -30,6 +30,7 @@
 #ifdef __KERNEL__
 
 #include <linux/in.h>
+#include <linux/kref.h>
 #include <linux/mm.h>
 #include <linux/namei.h>
 #include <linux/pagemap.h>
@@ -70,7 +71,7 @@ struct nfs_access_entry {
 
 struct nfs4_state;
 struct nfs_open_context {
-       atomic_t count;
+       struct kref kref;
        struct path path;
        struct rpc_cred *cred;
        struct nfs4_state *state;
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to