]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/nfs/dir.c
NFS: Remove BKL from NFS lookup code
[linux-2.6-omap-h63xx.git] / fs / nfs / dir.c
index f288b3ecab4afad46334d311ac301f7a2e1e1fa4..60da7550133c58a491baa83ad0aba7c8247dd523 100644 (file)
@@ -133,13 +133,14 @@ nfs_opendir(struct inode *inode, struct file *filp)
 {
        int res;
 
-       dfprintk(VFS, "NFS: opendir(%s/%ld)\n",
-                       inode->i_sb->s_id, inode->i_ino);
+       dfprintk(FILE, "NFS: open dir(%s/%s)\n",
+                       filp->f_path.dentry->d_parent->d_name.name,
+                       filp->f_path.dentry->d_name.name);
+
+       nfs_inc_stats(inode, NFSIOS_VFSOPEN);
 
-       lock_kernel();
        /* Call generic open code in order to cache credentials */
        res = nfs_open(inode, filp);
-       unlock_kernel();
        return res;
 }
 
@@ -180,7 +181,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
        int             error;
 
        dfprintk(DIRCACHE, "NFS: %s: reading cookie %Lu into page %lu\n",
-                       __FUNCTION__, (long long)desc->entry->cookie,
+                       __func__, (long long)desc->entry->cookie,
                        page->index);
 
  again:
@@ -204,7 +205,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
         * Note: assumes we have exclusive access to this mapping either
         *       through inode->i_mutex or some other mechanism.
         */
-       if (page->index == 0 && invalidate_inode_pages2_range(inode->i_mapping, PAGE_CACHE_SIZE, -1) < 0) {
+       if (invalidate_inode_pages2_range(inode->i_mapping, page->index + 1, -1) < 0) {
                /* Should never happen */
                nfs_zap_mapping(inode, inode->i_mapping);
        }
@@ -256,7 +257,7 @@ int find_dirent(nfs_readdir_descriptor_t *desc)
 
        while((status = dir_decode(desc)) == 0) {
                dfprintk(DIRCACHE, "NFS: %s: examining cookie %Lu\n",
-                               __FUNCTION__, (unsigned long long)entry->cookie);
+                               __func__, (unsigned long long)entry->cookie);
                if (entry->prev_cookie == *desc->dir_cookie)
                        break;
                if (loop_count++ > 200) {
@@ -315,7 +316,7 @@ int find_dirent_page(nfs_readdir_descriptor_t *desc)
        int             status;
 
        dfprintk(DIRCACHE, "NFS: %s: searching page %ld for target %Lu\n",
-                       __FUNCTION__, desc->page_index,
+                       __func__, desc->page_index,
                        (long long) *desc->dir_cookie);
 
        /* If we find the page in the page_cache, we cannot be sure
@@ -339,7 +340,7 @@ int find_dirent_page(nfs_readdir_descriptor_t *desc)
        if (status < 0)
                dir_page_release(desc);
  out:
-       dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __FUNCTION__, status);
+       dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, status);
        return status;
 }
 
@@ -380,7 +381,7 @@ int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
                }
        }
 
-       dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __FUNCTION__, res);
+       dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, res);
        return res;
 }
 
@@ -506,7 +507,7 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
        desc->entry->eof = 0;
  out:
        dfprintk(DIRCACHE, "NFS: %s: returns %d\n",
-                       __FUNCTION__, status);
+                       __func__, status);
        return status;
  out_release:
        dir_page_release(desc);
@@ -528,7 +529,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        struct nfs_fattr fattr;
        long            res;
 
-       dfprintk(VFS, "NFS: readdir(%s/%s) starting at cookie %Lu\n",
+       dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
                        dentry->d_parent->d_name.name, dentry->d_name.name,
                        (long long)filp->f_pos);
        nfs_inc_stats(inode, NFSIOS_VFSGETDENTS);
@@ -595,7 +596,7 @@ out:
        unlock_kernel();
        if (res > 0)
                res = 0;
-       dfprintk(VFS, "NFS: readdir(%s/%s) returns %ld\n",
+       dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n",
                        dentry->d_parent->d_name.name, dentry->d_name.name,
                        res);
        return res;
@@ -603,7 +604,15 @@ out:
 
 static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
 {
-       mutex_lock(&filp->f_path.dentry->d_inode->i_mutex);
+       struct dentry *dentry = filp->f_path.dentry;
+       struct inode *inode = dentry->d_inode;
+
+       dfprintk(FILE, "NFS: llseek dir(%s/%s, %lld, %d)\n",
+                       dentry->d_parent->d_name.name,
+                       dentry->d_name.name,
+                       offset, origin);
+
+       mutex_lock(&inode->i_mutex);
        switch (origin) {
                case 1:
                        offset += filp->f_pos;
@@ -619,7 +628,7 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
                nfs_file_open_context(filp)->dir_cookie = 0;
        }
 out:
-       mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex);
+       mutex_unlock(&inode->i_mutex);
        return offset;
 }
 
@@ -629,10 +638,11 @@ out:
  */
 static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync)
 {
-       dfprintk(VFS, "NFS: fsync_dir(%s/%s) datasync %d\n",
+       dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n",
                        dentry->d_parent->d_name.name, dentry->d_name.name,
                        datasync);
 
+       nfs_inc_stats(dentry->d_inode, NFSIOS_VFSFSYNC);
        return 0;
 }
 
@@ -767,7 +777,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
        struct nfs_fattr fattr;
 
        parent = dget_parent(dentry);
-       lock_kernel();
        dir = parent->d_inode;
        nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
        inode = dentry->d_inode;
@@ -780,7 +789,7 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
 
        if (is_bad_inode(inode)) {
                dfprintk(LOOKUPCACHE, "%s: %s/%s has dud inode\n",
-                               __FUNCTION__, dentry->d_parent->d_name.name,
+                               __func__, dentry->d_parent->d_name.name,
                                dentry->d_name.name);
                goto out_bad;
        }
@@ -805,10 +814,9 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
 
        nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
  out_valid:
-       unlock_kernel();
        dput(parent);
        dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n",
-                       __FUNCTION__, dentry->d_parent->d_name.name,
+                       __func__, dentry->d_parent->d_name.name,
                        dentry->d_name.name);
        return 1;
 out_zap_parent:
@@ -824,10 +832,9 @@ out_zap_parent:
                shrink_dcache_parent(dentry);
        }
        d_drop(dentry);
-       unlock_kernel();
        dput(parent);
        dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
-                       __FUNCTION__, dentry->d_parent->d_name.name,
+                       __func__, dentry->d_parent->d_name.name,
                        dentry->d_name.name);
        return 0;
 }
@@ -858,6 +865,14 @@ static int nfs_dentry_delete(struct dentry *dentry)
 
 }
 
+static void nfs_drop_nlink(struct inode *inode)
+{
+       spin_lock(&inode->i_lock);
+       if (inode->i_nlink > 0)
+               drop_nlink(inode);
+       spin_unlock(&inode->i_lock);
+}
+
 /*
  * Called when the dentry loses inode.
  * We use it to clean up silly-renamed files.
@@ -903,8 +918,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
        res = ERR_PTR(-ENOMEM);
        dentry->d_op = NFS_PROTO(dir)->dentry_ops;
 
-       lock_kernel();
-
        /*
         * If we're doing an exclusive create, optimize away the lookup
         * but don't hash the dentry.
@@ -912,7 +925,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
        if (nfs_is_exclusive_create(dir, nd)) {
                d_instantiate(dentry, NULL);
                res = NULL;
-               goto out_unlock;
+               goto out;
        }
 
        parent = dentry->d_parent;
@@ -940,8 +953,6 @@ no_entry:
        nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
 out_unblock_sillyrename:
        nfs_unblock_sillyrename(parent);
-out_unlock:
-       unlock_kernel();
 out:
        return res;
 }
@@ -999,9 +1010,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
        }
 
        /* Open the file on the server */
-       lock_kernel();
        res = nfs4_atomic_open(dir, dentry, nd);
-       unlock_kernel();
        if (IS_ERR(res)) {
                error = PTR_ERR(res);
                switch (error) {
@@ -1063,9 +1072,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
         * operations that change the directory. We therefore save the
         * change attribute *before* we do the RPC call.
         */
-       lock_kernel();
        ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
-       unlock_kernel();
 out:
        dput(parent);
        if (!ret)
@@ -1218,14 +1225,11 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
        if ((nd->flags & LOOKUP_CREATE) != 0)
                open_flags = nd->intent.open.flags;
 
-       lock_kernel();
        error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
        if (error != 0)
                goto out_err;
-       unlock_kernel();
        return 0;
 out_err:
-       unlock_kernel();
        d_drop(dentry);
        return error;
 }
@@ -1248,14 +1252,11 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
        attr.ia_mode = mode;
        attr.ia_valid = ATTR_MODE;
 
-       lock_kernel();
        status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev);
        if (status != 0)
                goto out_err;
-       unlock_kernel();
        return 0;
 out_err:
-       unlock_kernel();
        d_drop(dentry);
        return status;
 }
@@ -1274,15 +1275,12 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        attr.ia_valid = ATTR_MODE;
        attr.ia_mode = mode | S_IFDIR;
 
-       lock_kernel();
        error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr);
        if (error != 0)
                goto out_err;
-       unlock_kernel();
        return 0;
 out_err:
        d_drop(dentry);
-       unlock_kernel();
        return error;
 }
 
@@ -1408,7 +1406,7 @@ static int nfs_safe_remove(struct dentry *dentry)
                error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
                /* The VFS may want to delete this inode */
                if (error == 0)
-                       drop_nlink(inode);
+                       nfs_drop_nlink(inode);
                nfs_mark_for_revalidate(inode);
        } else
                error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
@@ -1544,14 +1542,12 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
                old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
                dentry->d_parent->d_name.name, dentry->d_name.name);
 
-       lock_kernel();
        d_drop(dentry);
        error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
        if (error == 0) {
                atomic_inc(&inode->i_count);
                d_add(dentry, inode);
        }
-       unlock_kernel();
        return error;
 }
 
@@ -1635,7 +1631,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        /* dentry still busy? */
                        goto out;
        } else
-               drop_nlink(new_inode);
+               nfs_drop_nlink(new_inode);
 
 go_ahead:
        /*
@@ -1962,8 +1958,6 @@ int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
        }
 
 force_lookup:
-       lock_kernel();
-
        if (!NFS_PROTO(inode)->access)
                goto out_notsup;
 
@@ -1973,7 +1967,6 @@ force_lookup:
                put_rpccred(cred);
        } else
                res = PTR_ERR(cred);
-       unlock_kernel();
 out:
        dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n",
                inode->i_sb->s_id, inode->i_ino, mask, res);
@@ -1982,7 +1975,6 @@ out_notsup:
        res = nfs_revalidate_inode(NFS_SERVER(inode), inode);
        if (res == 0)
                res = generic_permission(inode, mask, NULL);
-       unlock_kernel();
        goto out;
 }