2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* linux/fs/nfs/delegation.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Trond Myklebust
|
|
|
|
*
|
|
|
|
* NFS file delegation management
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/completion.h>
|
2006-01-03 01:55:24 -07:00
|
|
|
#include <linux/kthread.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
#include <linux/nfs4.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include <linux/nfs_xdr.h>
|
|
|
|
|
2005-06-22 11:16:21 -06:00
|
|
|
#include "nfs4_fs.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "delegation.h"
|
2006-08-22 18:06:10 -06:00
|
|
|
#include "internal.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-08-06 10:18:34 -06:00
|
|
|
static void nfs_free_delegation(struct nfs_delegation *delegation)
|
|
|
|
{
|
2011-01-27 12:55:39 -07:00
|
|
|
if (delegation->cred) {
|
|
|
|
put_rpccred(delegation->cred);
|
|
|
|
delegation->cred = NULL;
|
|
|
|
}
|
2011-05-01 07:21:54 -06:00
|
|
|
kfree_rcu(delegation, rcu);
|
2007-07-06 13:12:04 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_mark_delegation_referenced - set delegation's REFERENCED flag
|
|
|
|
* @delegation: delegation to process
|
|
|
|
*
|
|
|
|
*/
|
2008-12-23 13:21:52 -07:00
|
|
|
void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
|
|
|
|
{
|
|
|
|
set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_have_delegation - check if inode has a delegation
|
|
|
|
* @inode: inode to check
|
|
|
|
* @flags: delegation types to check for
|
|
|
|
*
|
|
|
|
* Returns one if inode has the indicated delegation, otherwise zero.
|
|
|
|
*/
|
2008-12-23 13:21:53 -07:00
|
|
|
int nfs_have_delegation(struct inode *inode, fmode_t flags)
|
2008-12-23 13:21:52 -07:00
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
flags &= FMODE_READ|FMODE_WRITE;
|
|
|
|
rcu_read_lock();
|
|
|
|
delegation = rcu_dereference(NFS_I(inode)->delegation);
|
|
|
|
if (delegation != NULL && (delegation->type & flags) == flags) {
|
|
|
|
nfs_mark_delegation_referenced(delegation);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-04 13:38:11 -07:00
|
|
|
static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state)
|
|
|
|
{
|
|
|
|
struct inode *inode = state->inode;
|
|
|
|
struct file_lock *fl;
|
2009-06-17 14:22:58 -06:00
|
|
|
int status = 0;
|
2005-11-04 13:38:11 -07:00
|
|
|
|
2009-06-17 14:23:00 -06:00
|
|
|
if (inode->i_flock == NULL)
|
|
|
|
goto out;
|
|
|
|
|
2010-09-18 07:09:31 -06:00
|
|
|
/* Protect inode->i_flock using the file locks lock */
|
|
|
|
lock_flocks();
|
2008-02-20 14:03:05 -07:00
|
|
|
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
|
2005-11-04 13:38:11 -07:00
|
|
|
if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
|
|
|
|
continue;
|
2007-08-10 15:44:32 -06:00
|
|
|
if (nfs_file_open_context(fl->fl_file) != ctx)
|
2005-11-04 13:38:11 -07:00
|
|
|
continue;
|
2010-09-18 07:09:31 -06:00
|
|
|
unlock_flocks();
|
2005-11-04 13:38:11 -07:00
|
|
|
status = nfs4_lock_delegation_recall(state, fl);
|
2009-06-17 14:22:58 -06:00
|
|
|
if (status < 0)
|
2009-06-17 14:23:00 -06:00
|
|
|
goto out;
|
2010-09-18 07:09:31 -06:00
|
|
|
lock_flocks();
|
2005-11-04 13:38:11 -07:00
|
|
|
}
|
2010-09-18 07:09:31 -06:00
|
|
|
unlock_flocks();
|
2009-06-17 14:23:00 -06:00
|
|
|
out:
|
2005-11-04 13:38:11 -07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-12-03 06:10:17 -07:00
|
|
|
static int nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
struct nfs_open_context *ctx;
|
|
|
|
struct nfs4_state *state;
|
2005-11-04 13:38:11 -07:00
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
again:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
list_for_each_entry(ctx, &nfsi->open_files, list) {
|
|
|
|
state = ctx->state;
|
|
|
|
if (state == NULL)
|
|
|
|
continue;
|
|
|
|
if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
|
|
|
|
continue;
|
2007-07-05 12:55:18 -06:00
|
|
|
if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0)
|
|
|
|
continue;
|
2005-04-16 16:20:36 -06:00
|
|
|
get_nfs_open_context(ctx);
|
|
|
|
spin_unlock(&inode->i_lock);
|
2007-07-06 13:10:43 -06:00
|
|
|
err = nfs4_open_delegation_recall(ctx, state, stateid);
|
2005-11-04 13:38:11 -07:00
|
|
|
if (err >= 0)
|
|
|
|
err = nfs_delegation_claim_locks(ctx, state);
|
2005-04-16 16:20:36 -06:00
|
|
|
put_nfs_open_context(ctx);
|
2005-11-04 13:38:11 -07:00
|
|
|
if (err != 0)
|
2009-12-03 06:10:17 -07:00
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
spin_unlock(&inode->i_lock);
|
2009-12-03 06:10:17 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_inode_reclaim_delegation - process a delegation reclaim request
|
|
|
|
* @inode: inode to process
|
|
|
|
* @cred: credential to use for request
|
|
|
|
* @res: new delegation state from server
|
|
|
|
*
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2010-12-23 18:33:04 -07:00
|
|
|
void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
|
|
|
|
struct nfs_openres *res)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2010-05-01 10:36:18 -06:00
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
struct rpc_cred *oldcred = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-05-01 10:36:18 -06:00
|
|
|
rcu_read_lock();
|
|
|
|
delegation = rcu_dereference(NFS_I(inode)->delegation);
|
|
|
|
if (delegation != NULL) {
|
|
|
|
spin_lock(&delegation->lock);
|
|
|
|
if (delegation->inode != NULL) {
|
|
|
|
memcpy(delegation->stateid.data, res->delegation.data,
|
|
|
|
sizeof(delegation->stateid.data));
|
|
|
|
delegation->type = res->delegation_type;
|
|
|
|
delegation->maxsize = res->maxsize;
|
|
|
|
oldcred = delegation->cred;
|
|
|
|
delegation->cred = get_rpccred(cred);
|
|
|
|
clear_bit(NFS_DELEGATION_NEED_RECLAIM,
|
|
|
|
&delegation->flags);
|
|
|
|
NFS_I(inode)->delegation_state = delegation->type;
|
|
|
|
spin_unlock(&delegation->lock);
|
|
|
|
put_rpccred(oldcred);
|
|
|
|
rcu_read_unlock();
|
|
|
|
} else {
|
|
|
|
/* We appear to have raced with a delegation return. */
|
|
|
|
spin_unlock(&delegation->lock);
|
|
|
|
rcu_read_unlock();
|
|
|
|
nfs_inode_set_delegation(inode, cred, res);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-01-25 14:38:18 -07:00
|
|
|
static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid, issync);
|
|
|
|
nfs_free_delegation(delegation);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-12-23 13:21:39 -07:00
|
|
|
static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation)
|
|
|
|
{
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
|
|
|
|
spin_lock(&delegation->lock);
|
|
|
|
if (delegation->inode != NULL)
|
|
|
|
inode = igrab(delegation->inode);
|
|
|
|
spin_unlock(&delegation->lock);
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:32:54 -07:00
|
|
|
static struct nfs_delegation *
|
|
|
|
nfs_detach_delegation_locked(struct nfs_inode *nfsi,
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server)
|
2008-01-25 14:38:18 -07:00
|
|
|
{
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
struct nfs_delegation *delegation =
|
|
|
|
rcu_dereference_protected(nfsi->delegation,
|
2010-12-23 18:33:04 -07:00
|
|
|
lockdep_is_held(&server->nfs_client->cl_lock));
|
2008-01-25 14:38:18 -07:00
|
|
|
|
|
|
|
if (delegation == NULL)
|
|
|
|
goto nomatch;
|
2010-12-23 18:32:54 -07:00
|
|
|
|
2008-12-23 13:21:38 -07:00
|
|
|
spin_lock(&delegation->lock);
|
2008-01-25 14:38:18 -07:00
|
|
|
list_del_rcu(&delegation->super_list);
|
2008-12-23 13:21:39 -07:00
|
|
|
delegation->inode = NULL;
|
2008-01-25 14:38:18 -07:00
|
|
|
nfsi->delegation_state = 0;
|
|
|
|
rcu_assign_pointer(nfsi->delegation, NULL);
|
2008-12-23 13:21:38 -07:00
|
|
|
spin_unlock(&delegation->lock);
|
2008-01-25 14:38:18 -07:00
|
|
|
return delegation;
|
|
|
|
nomatch:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:32:54 -07:00
|
|
|
static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi,
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server)
|
2010-12-23 18:32:54 -07:00
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_client *clp = server->nfs_client;
|
2010-12-23 18:32:54 -07:00
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
|
|
|
spin_lock(&clp->cl_lock);
|
2010-12-23 18:33:04 -07:00
|
|
|
delegation = nfs_detach_delegation_locked(nfsi, server);
|
2010-12-23 18:32:54 -07:00
|
|
|
spin_unlock(&clp->cl_lock);
|
|
|
|
return delegation;
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_inode_set_delegation - set up a delegation on an inode
|
|
|
|
* @inode: inode to which delegation applies
|
|
|
|
* @cred: cred to use for subsequent delegation processing
|
|
|
|
* @res: new delegation state from server
|
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno value.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
|
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct nfs_client *clp = server->nfs_client;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
struct nfs_delegation *delegation, *old_delegation;
|
2008-01-25 14:38:18 -07:00
|
|
|
struct nfs_delegation *freeme = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
int status = 0;
|
|
|
|
|
2010-05-13 10:51:01 -06:00
|
|
|
delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (delegation == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
memcpy(delegation->stateid.data, res->delegation.data,
|
|
|
|
sizeof(delegation->stateid.data));
|
|
|
|
delegation->type = res->delegation_type;
|
|
|
|
delegation->maxsize = res->maxsize;
|
2011-10-17 17:08:46 -06:00
|
|
|
delegation->change_attr = inode->i_version;
|
2005-04-16 16:20:36 -06:00
|
|
|
delegation->cred = get_rpccred(cred);
|
|
|
|
delegation->inode = inode;
|
2008-12-23 13:21:52 -07:00
|
|
|
delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
|
2008-12-23 13:21:38 -07:00
|
|
|
spin_lock_init(&delegation->lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
spin_lock(&clp->cl_lock);
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
old_delegation = rcu_dereference_protected(nfsi->delegation,
|
2010-12-23 18:33:04 -07:00
|
|
|
lockdep_is_held(&clp->cl_lock));
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
if (old_delegation != NULL) {
|
|
|
|
if (memcmp(&delegation->stateid, &old_delegation->stateid,
|
|
|
|
sizeof(old_delegation->stateid)) == 0 &&
|
|
|
|
delegation->type == old_delegation->type) {
|
2008-01-25 14:38:18 -07:00
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2008-01-25 14:38:18 -07:00
|
|
|
/*
|
|
|
|
* Deal with broken servers that hand out two
|
|
|
|
* delegations for the same file.
|
|
|
|
*/
|
|
|
|
dfprintk(FILE, "%s: server %s handed out "
|
|
|
|
"a duplicate delegation!\n",
|
2008-05-02 14:42:44 -06:00
|
|
|
__func__, clp->cl_hostname);
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
if (delegation->type <= old_delegation->type) {
|
2008-01-25 14:38:18 -07:00
|
|
|
freeme = delegation;
|
|
|
|
delegation = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-12-23 18:33:04 -07:00
|
|
|
freeme = nfs_detach_delegation_locked(nfsi, server);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2010-12-23 18:33:04 -07:00
|
|
|
list_add_rcu(&delegation->super_list, &server->delegations);
|
2008-01-25 14:38:18 -07:00
|
|
|
nfsi->delegation_state = delegation->type;
|
|
|
|
rcu_assign_pointer(nfsi->delegation, delegation);
|
|
|
|
delegation = NULL;
|
2007-07-03 14:10:55 -06:00
|
|
|
|
|
|
|
/* Ensure we revalidate the attributes and page cache! */
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
|
2008-01-25 14:38:18 -07:00
|
|
|
out:
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_unlock(&clp->cl_lock);
|
2007-10-18 17:59:20 -06:00
|
|
|
if (delegation != NULL)
|
|
|
|
nfs_free_delegation(delegation);
|
2008-01-25 14:38:18 -07:00
|
|
|
if (freeme != NULL)
|
|
|
|
nfs_do_return_delegation(inode, freeme, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic procedure for returning a delegation to the server
|
|
|
|
*/
|
2009-12-03 06:10:17 -07:00
|
|
|
static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
2009-12-03 06:10:17 -07:00
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-06-17 14:23:00 -06:00
|
|
|
/*
|
|
|
|
* Guard against new delegated open/lock/unlock calls and against
|
|
|
|
* state recovery
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
down_write(&nfsi->rwsem);
|
2009-12-03 06:10:17 -07:00
|
|
|
err = nfs_delegation_claim_opens(inode, &delegation->stateid);
|
2005-04-16 16:20:36 -06:00
|
|
|
up_write(&nfsi->rwsem);
|
2009-12-03 06:10:17 -07:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-12-03 06:10:17 -07:00
|
|
|
err = nfs_do_return_delegation(inode, delegation, issync);
|
|
|
|
out:
|
|
|
|
return err;
|
2007-07-05 12:55:18 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_client_return_marked_delegations - return previously marked delegations
|
|
|
|
* @clp: nfs_client to process
|
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno value.
|
2008-12-23 13:21:46 -07:00
|
|
|
*/
|
2009-12-03 06:10:17 -07:00
|
|
|
int nfs_client_return_marked_delegations(struct nfs_client *clp)
|
2008-12-23 13:21:46 -07:00
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server;
|
2008-12-23 13:21:46 -07:00
|
|
|
struct inode *inode;
|
2009-12-03 06:10:17 -07:00
|
|
|
int err = 0;
|
2008-12-23 13:21:46 -07:00
|
|
|
|
|
|
|
restart:
|
|
|
|
rcu_read_lock();
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
|
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations,
|
|
|
|
super_list) {
|
|
|
|
if (!test_and_clear_bit(NFS_DELEGATION_RETURN,
|
|
|
|
&delegation->flags))
|
|
|
|
continue;
|
|
|
|
inode = nfs_delegation_grab_inode(delegation);
|
|
|
|
if (inode == NULL)
|
|
|
|
continue;
|
|
|
|
delegation = nfs_detach_delegation(NFS_I(inode),
|
|
|
|
server);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (delegation != NULL) {
|
|
|
|
filemap_flush(inode->i_mapping);
|
|
|
|
err = __nfs_inode_return_delegation(inode,
|
|
|
|
delegation, 0);
|
|
|
|
}
|
|
|
|
iput(inode);
|
|
|
|
if (!err)
|
|
|
|
goto restart;
|
|
|
|
set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
|
|
|
|
return err;
|
2009-12-03 06:10:17 -07:00
|
|
|
}
|
2008-12-23 13:21:46 -07:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2009-12-03 06:10:17 -07:00
|
|
|
return 0;
|
2008-12-23 13:21:46 -07:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens
|
|
|
|
* @inode: inode to process
|
|
|
|
*
|
|
|
|
* Does not protect against delegation reclaims, therefore really only safe
|
|
|
|
* to be called from nfs4_clear_inode().
|
2008-01-24 16:14:34 -07:00
|
|
|
*/
|
|
|
|
void nfs_inode_return_delegation_noreclaim(struct inode *inode)
|
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2008-01-24 16:14:34 -07:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
if (rcu_access_pointer(nfsi->delegation) != NULL) {
|
2010-12-23 18:33:04 -07:00
|
|
|
delegation = nfs_detach_delegation(nfsi, server);
|
2008-01-24 16:14:34 -07:00
|
|
|
if (delegation != NULL)
|
|
|
|
nfs_do_return_delegation(inode, delegation, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_inode_return_delegation - synchronously return a delegation
|
|
|
|
* @inode: inode to process
|
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno value.
|
|
|
|
*/
|
2007-07-05 12:55:18 -06:00
|
|
|
int nfs_inode_return_delegation(struct inode *inode)
|
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2007-07-05 12:55:18 -06:00
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
int err = 0;
|
|
|
|
|
NFS: Fix RCU issues in the NFSv4 delegation code
Fix a number of RCU issues in the NFSv4 delegation code.
(1) delegation->cred doesn't need to be RCU protected as it's essentially an
invariant refcounted structure.
By the time we get to nfs_free_delegation(), the delegation is being
released, so no one else should be attempting to use the saved
credentials, and they can be cleared.
However, since the list of delegations could still be under traversal at
this point by such as nfs_client_return_marked_delegations(), the cred
should be released in nfs_do_free_delegation() rather than in
nfs_free_delegation(). Simply using rcu_assign_pointer() to clear it is
insufficient as that doesn't stop the cred from being destroyed, and nor
does calling put_rpccred() after call_rcu(), given that the latter is
asynchronous.
(2) nfs_detach_delegation_locked() and nfs_inode_set_delegation() should use
rcu_derefence_protected() because they can only be called if
nfs_client::cl_lock is held, and that guards against anyone changing
nfsi->delegation under it. Furthermore, the barrier imposed by
rcu_dereference() is superfluous, given that the spin_lock() is also a
barrier.
(3) nfs_detach_delegation_locked() is now passed a pointer to the nfs_client
struct so that it can issue lockdep advice based on clp->cl_lock for (2).
(4) nfs_inode_return_delegation_noreclaim() and nfs_inode_return_delegation()
should use rcu_access_pointer() outside the spinlocked region as they
merely examine the pointer and don't follow it, thus rendering unnecessary
the need to impose a partial ordering over the one item of interest.
These result in an RCU warning like the following:
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
fs/nfs/delegation.c:332 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by mount.nfs4/2281:
#0: (&type->s_umount_key#34){+.+...}, at: [<ffffffff810b25b4>] deactivate_super+0x60/0x80
#1: (iprune_sem){+.+...}, at: [<ffffffff810c332a>] invalidate_inodes+0x39/0x13a
stack backtrace:
Pid: 2281, comm: mount.nfs4 Not tainted 2.6.34-rc1-cachefs #110
Call Trace:
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4591>] nfs_inode_return_delegation_noreclaim+0x5b/0xa0 [nfs]
[<ffffffffa0095d63>] nfs4_clear_inode+0x11/0x1e [nfs]
[<ffffffff810c2d92>] clear_inode+0x9e/0xf8
[<ffffffff810c3028>] dispose_list+0x67/0x10e
[<ffffffff810c340d>] invalidate_inodes+0x11c/0x13a
[<ffffffff810b1dc1>] generic_shutdown_super+0x42/0xf4
[<ffffffff810b1ebe>] kill_anon_super+0x11/0x4f
[<ffffffffa009893c>] nfs4_kill_super+0x3f/0x72 [nfs]
[<ffffffff810b25bc>] deactivate_super+0x68/0x80
[<ffffffff810c6744>] mntput_no_expire+0xbb/0xf8
[<ffffffff810c681b>] release_mounts+0x9a/0xb0
[<ffffffff810c689b>] put_mnt_ns+0x6a/0x79
[<ffffffffa00983a1>] nfs_follow_remote_path+0x5a/0x146 [nfs]
[<ffffffffa0098334>] ? nfs_do_root_mount+0x82/0x95 [nfs]
[<ffffffffa00985a9>] nfs4_try_mount+0x75/0xaf [nfs]
[<ffffffffa0098874>] nfs4_get_sb+0x291/0x31a [nfs]
[<ffffffff810b2059>] vfs_kern_mount+0xb8/0x177
[<ffffffff810b2176>] do_kern_mount+0x48/0xe8
[<ffffffff810c810b>] do_mount+0x782/0x7f9
[<ffffffff810c8205>] sys_mount+0x83/0xbe
[<ffffffff81001eeb>] system_call_fastpath+0x16/0x1b
Also on:
fs/nfs/delegation.c:215 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b4223>] nfs_inode_set_delegation+0xfe/0x219 [nfs]
[<ffffffffa00a9c6f>] nfs4_opendata_to_nfs4_state+0x2c2/0x30d [nfs]
[<ffffffffa00aa15d>] nfs4_do_open+0x2a6/0x3a6 [nfs]
...
And:
fs/nfs/delegation.c:40 invoked rcu_dereference_check() without protection!
[<ffffffff8105149f>] lockdep_rcu_dereference+0xaa/0xb2
[<ffffffffa00b3bef>] nfs_free_delegation+0x3d/0x6e [nfs]
[<ffffffffa00b3e71>] nfs_do_return_delegation+0x26/0x30 [nfs]
[<ffffffffa00b406a>] __nfs_inode_return_delegation+0x1ef/0x1fe [nfs]
[<ffffffffa00b448a>] nfs_client_return_marked_delegations+0xc9/0x124 [nfs]
...
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2010-05-01 10:37:18 -06:00
|
|
|
if (rcu_access_pointer(nfsi->delegation) != NULL) {
|
2010-12-23 18:33:04 -07:00
|
|
|
delegation = nfs_detach_delegation(nfsi, server);
|
2009-12-03 06:10:17 -07:00
|
|
|
if (delegation != NULL) {
|
2010-07-31 12:29:06 -06:00
|
|
|
nfs_wb_all(inode);
|
2009-12-03 06:10:17 -07:00
|
|
|
err = __nfs_inode_return_delegation(inode, delegation, 1);
|
|
|
|
}
|
2007-07-05 12:55:18 -06:00
|
|
|
}
|
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2011-07-25 13:37:29 -06:00
|
|
|
static void nfs_mark_return_delegation(struct nfs_server *server,
|
|
|
|
struct nfs_delegation *delegation)
|
2008-12-23 13:21:51 -07:00
|
|
|
{
|
|
|
|
set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
|
2011-07-25 13:37:29 -06:00
|
|
|
set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
|
2008-12-23 13:21:51 -07:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_super_return_all_delegations - return delegations for one superblock
|
|
|
|
* @sb: sb to process
|
|
|
|
*
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2008-12-23 13:21:46 -07:00
|
|
|
void nfs_super_return_all_delegations(struct super_block *sb)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server = NFS_SB(sb);
|
|
|
|
struct nfs_client *clp = server->nfs_client;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
|
|
|
if (clp == NULL)
|
|
|
|
return;
|
2010-12-23 18:33:04 -07:00
|
|
|
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_lock();
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
|
2008-12-23 13:21:39 -07:00
|
|
|
spin_lock(&delegation->lock);
|
2010-12-23 18:33:04 -07:00
|
|
|
set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
|
2008-12-23 13:21:39 -07:00
|
|
|
spin_unlock(&delegation->lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_unlock();
|
2010-12-23 18:33:04 -07:00
|
|
|
|
2009-12-03 06:10:17 -07:00
|
|
|
if (nfs_client_return_marked_delegations(clp) != 0)
|
|
|
|
nfs4_schedule_state_manager(clp);
|
2008-12-23 13:21:46 -07:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
static void nfs_mark_return_all_delegation_types(struct nfs_server *server,
|
|
|
|
fmode_t flags)
|
2008-12-23 13:21:46 -07:00
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
|
2009-12-05 11:20:52 -07:00
|
|
|
if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE))
|
|
|
|
continue;
|
|
|
|
if (delegation->type & flags)
|
2011-07-25 13:37:29 -06:00
|
|
|
nfs_mark_return_delegation(server, delegation);
|
2008-12-23 13:21:47 -07:00
|
|
|
}
|
2010-12-23 18:33:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp,
|
|
|
|
fmode_t flags)
|
|
|
|
{
|
|
|
|
struct nfs_server *server;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
|
|
|
|
nfs_mark_return_all_delegation_types(server, flags);
|
2008-12-23 13:21:46 -07:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-12-05 11:20:52 -07:00
|
|
|
static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
nfs_client_mark_return_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
|
|
|
|
}
|
|
|
|
|
2008-12-23 13:21:50 -07:00
|
|
|
static void nfs_delegation_run_state_manager(struct nfs_client *clp)
|
2006-01-03 01:55:24 -07:00
|
|
|
{
|
2008-12-23 13:21:50 -07:00
|
|
|
if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
|
|
|
|
nfs4_schedule_state_manager(clp);
|
2006-01-03 01:55:24 -07:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_expire_all_delegation_types
|
|
|
|
* @clp: client to process
|
|
|
|
* @flags: delegation types to expire
|
|
|
|
*
|
|
|
|
*/
|
2009-12-05 11:27:02 -07:00
|
|
|
void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags)
|
2006-01-03 01:55:24 -07:00
|
|
|
{
|
2009-12-05 11:20:52 -07:00
|
|
|
nfs_client_mark_return_all_delegation_types(clp, flags);
|
2008-12-23 13:21:50 -07:00
|
|
|
nfs_delegation_run_state_manager(clp);
|
2006-01-03 01:55:24 -07:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_expire_all_delegations
|
|
|
|
* @clp: client to process
|
|
|
|
*
|
|
|
|
*/
|
2009-12-05 11:20:52 -07:00
|
|
|
void nfs_expire_all_delegations(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
|
|
|
|
* @clp: client to process
|
|
|
|
*
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2006-08-22 18:06:08 -06:00
|
|
|
void nfs_handle_cb_pathdown(struct nfs_client *clp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (clp == NULL)
|
|
|
|
return;
|
2008-12-23 13:21:47 -07:00
|
|
|
nfs_client_mark_return_all_delegations(clp);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
|
2008-12-23 13:21:52 -07:00
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
|
2008-12-23 13:21:52 -07:00
|
|
|
if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
|
|
|
|
continue;
|
2011-07-25 13:37:29 -06:00
|
|
|
nfs_mark_return_delegation(server, delegation);
|
2008-12-23 13:21:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_expire_unreferenced_delegations - Eliminate unused delegations
|
|
|
|
* @clp: nfs_client to process
|
|
|
|
*
|
|
|
|
*/
|
2008-12-23 13:21:52 -07:00
|
|
|
void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
|
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
|
|
|
|
nfs_mark_return_unreferenced_delegations(server);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
2008-12-23 13:21:52 -07:00
|
|
|
nfs_delegation_run_state_manager(clp);
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_async_inode_return_delegation - asynchronously return a delegation
|
|
|
|
* @inode: inode to process
|
|
|
|
* @stateid: state ID information from CB_RECALL arguments
|
|
|
|
*
|
|
|
|
* Returns zero on success, or a negative errno value.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2010-12-23 18:33:04 -07:00
|
|
|
int nfs_async_inode_return_delegation(struct inode *inode,
|
|
|
|
const nfs4_stateid *stateid)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-07-25 13:37:29 -06:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct nfs_client *clp = server->nfs_client;
|
2008-12-23 13:21:51 -07:00
|
|
|
struct nfs_delegation *delegation;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-12-23 13:21:51 -07:00
|
|
|
rcu_read_lock();
|
|
|
|
delegation = rcu_dereference(NFS_I(inode)->delegation);
|
2009-12-05 11:48:55 -07:00
|
|
|
|
2010-06-16 07:52:27 -06:00
|
|
|
if (!clp->cl_mvops->validate_stateid(delegation, stateid)) {
|
2008-12-23 13:21:51 -07:00
|
|
|
rcu_read_unlock();
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2011-07-25 13:37:29 -06:00
|
|
|
nfs_mark_return_delegation(server, delegation);
|
2008-12-23 13:21:51 -07:00
|
|
|
rcu_read_unlock();
|
2010-12-23 18:33:04 -07:00
|
|
|
|
2008-12-23 13:21:51 -07:00
|
|
|
nfs_delegation_run_state_manager(clp);
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
static struct inode *
|
|
|
|
nfs_delegation_find_inode_server(struct nfs_server *server,
|
|
|
|
const struct nfs_fh *fhandle)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
struct inode *res = NULL;
|
2010-12-23 18:33:04 -07:00
|
|
|
|
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
|
2008-12-23 13:21:39 -07:00
|
|
|
spin_lock(&delegation->lock);
|
|
|
|
if (delegation->inode != NULL &&
|
|
|
|
nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
res = igrab(delegation->inode);
|
|
|
|
}
|
2008-12-23 13:21:39 -07:00
|
|
|
spin_unlock(&delegation->lock);
|
|
|
|
if (res != NULL)
|
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2010-12-23 18:33:04 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_delegation_find_inode - retrieve the inode associated with a delegation
|
|
|
|
* @clp: client state handle
|
|
|
|
* @fhandle: filehandle from a delegation recall
|
|
|
|
*
|
|
|
|
* Returns pointer to inode matching "fhandle," or NULL if a matching inode
|
|
|
|
* cannot be found.
|
|
|
|
*/
|
|
|
|
struct inode *nfs_delegation_find_inode(struct nfs_client *clp,
|
|
|
|
const struct nfs_fh *fhandle)
|
|
|
|
{
|
|
|
|
struct nfs_server *server;
|
|
|
|
struct inode *res = NULL;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
|
|
|
|
res = nfs_delegation_find_inode_server(server, fhandle);
|
|
|
|
if (res != NULL)
|
|
|
|
break;
|
|
|
|
}
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
|
|
|
|
{
|
|
|
|
struct nfs_delegation *delegation;
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations, super_list)
|
|
|
|
set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed
|
|
|
|
* @clp: nfs_client to process
|
|
|
|
*
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2006-08-22 18:06:08 -06:00
|
|
|
void nfs_delegation_mark_reclaim(struct nfs_client *clp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server;
|
|
|
|
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_lock();
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
|
|
|
|
nfs_delegation_mark_reclaim_server(server);
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done
|
|
|
|
* @clp: nfs_client to process
|
|
|
|
*
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2006-08-22 18:06:08 -06:00
|
|
|
void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-07-06 13:12:04 -06:00
|
|
|
struct nfs_delegation *delegation;
|
2010-12-23 18:33:04 -07:00
|
|
|
struct nfs_server *server;
|
2008-12-23 13:21:39 -07:00
|
|
|
struct inode *inode;
|
2010-12-23 18:33:04 -07:00
|
|
|
|
2007-07-06 13:12:04 -06:00
|
|
|
restart:
|
|
|
|
rcu_read_lock();
|
2010-12-23 18:33:04 -07:00
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
|
|
|
|
list_for_each_entry_rcu(delegation, &server->delegations,
|
|
|
|
super_list) {
|
|
|
|
if (test_bit(NFS_DELEGATION_NEED_RECLAIM,
|
|
|
|
&delegation->flags) == 0)
|
|
|
|
continue;
|
|
|
|
inode = nfs_delegation_grab_inode(delegation);
|
|
|
|
if (inode == NULL)
|
|
|
|
continue;
|
|
|
|
delegation = nfs_detach_delegation(NFS_I(inode),
|
|
|
|
server);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (delegation != NULL)
|
|
|
|
nfs_free_delegation(delegation);
|
|
|
|
iput(inode);
|
|
|
|
goto restart;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-03-20 11:44:46 -07:00
|
|
|
|
2010-12-23 18:33:04 -07:00
|
|
|
/**
|
|
|
|
* nfs_delegations_present - check for existence of delegations
|
|
|
|
* @clp: client state handle
|
|
|
|
*
|
|
|
|
* Returns one if there are any nfs_delegation structures attached
|
|
|
|
* to this nfs_client.
|
|
|
|
*/
|
|
|
|
int nfs_delegations_present(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs_server *server;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
|
|
|
|
if (!list_empty(&server->delegations)) {
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs4_copy_delegation_stateid - Copy inode's state ID information
|
|
|
|
* @dst: stateid data structure to fill in
|
|
|
|
* @inode: inode to check
|
|
|
|
*
|
|
|
|
* Returns one and fills in "dst->data" * if inode had a delegation,
|
|
|
|
* otherwise zero is returned.
|
|
|
|
*/
|
2006-03-20 11:44:46 -07:00
|
|
|
int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
|
|
|
|
{
|
|
|
|
struct nfs_inode *nfsi = NFS_I(inode);
|
|
|
|
struct nfs_delegation *delegation;
|
2007-07-06 13:12:04 -06:00
|
|
|
int ret = 0;
|
2006-03-20 11:44:46 -07:00
|
|
|
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_lock();
|
|
|
|
delegation = rcu_dereference(nfsi->delegation);
|
2006-03-20 11:44:46 -07:00
|
|
|
if (delegation != NULL) {
|
|
|
|
memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
|
2007-07-06 13:12:04 -06:00
|
|
|
ret = 1;
|
2006-03-20 11:44:46 -07:00
|
|
|
}
|
2007-07-06 13:12:04 -06:00
|
|
|
rcu_read_unlock();
|
|
|
|
return ret;
|
2006-03-20 11:44:46 -07:00
|
|
|
}
|