Commit d2b6b4c8 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'nfsd-5.3' of git://linux-nfs.org/~bfields/linux

Pull nfsd updates from Bruce Fields:
 "Highlights:

   - Add a new /proc/fs/nfsd/clients/ directory which exposes some
     long-requested information about NFSv4 clients (like open files)
     and allows forced revocation of client state.

   - Replace the global duplicate reply cache by a cache per network
     namespace; previously, a request in one network namespace could
     incorrectly match an entry from another, though we haven't seen
     this in production. This is the last remaining container bug that
     I'm aware of; at this point you should be able to run separate
     nfsd's in each network namespace, each with their own set of
     exports, and everything should work.

   - Cleanup and modify lock code to show the pid of lockd as the owner
     of NLM locks. This is the correct version of the bugfix originally
     attempted in b8eee0e9 ("lockd: Show pid of lockd for remote
     locks")"

* tag 'nfsd-5.3' of git://linux-nfs.org/~bfields/linux: (34 commits)
  nfsd: Make __get_nfsdfs_client() static
  nfsd: Make two functions static
  nfsd: Fix misuse of strlcpy
  sunrpc/cache: remove the exporting of cache_seq_next
  nfsd: decode implementation id
  nfsd: create xdr_netobj_dup helper
  nfsd: allow forced expiration of NFSv4 clients
  nfsd: create get_nfsdfs_clp helper
  nfsd4: show layout stateids
  nfsd: show lock and deleg stateids
  nfsd4: add file to display list of client's opens
  nfsd: add more information to client info file
  nfsd: escape high characters in binary data
  nfsd: copy client's address including port number to cl_addr
  nfsd4: add a client info file
  nfsd: make client/ directory names small ints
  nfsd: add nfsd/clients directory
  nfsd4: use reference count to free client
  nfsd: rename cl_refcount
  nfsd: persist nfsd filesystem across mounts
  ...
parents 0248a8be b78fa45d
...@@ -361,8 +361,6 @@ so fl_release_private called on a lease should not block. ...@@ -361,8 +361,6 @@ so fl_release_private called on a lease should not block.
----------------------- lock_manager_operations --------------------------- ----------------------- lock_manager_operations ---------------------------
prototypes: prototypes:
int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
unsigned long (*lm_owner_key)(struct file_lock *);
void (*lm_notify)(struct file_lock *); /* unblock callback */ void (*lm_notify)(struct file_lock *); /* unblock callback */
int (*lm_grant)(struct file_lock *, struct file_lock *, int); int (*lm_grant)(struct file_lock *, struct file_lock *, int);
void (*lm_break)(struct file_lock *); /* break_lease callback */ void (*lm_break)(struct file_lock *); /* break_lease callback */
...@@ -371,23 +369,11 @@ prototypes: ...@@ -371,23 +369,11 @@ prototypes:
locking rules: locking rules:
inode->i_lock blocked_lock_lock may block inode->i_lock blocked_lock_lock may block
lm_compare_owner: yes[1] maybe no
lm_owner_key yes[1] yes no
lm_notify: yes yes no lm_notify: yes yes no
lm_grant: no no no lm_grant: no no no
lm_break: yes no no lm_break: yes no no
lm_change yes no no lm_change yes no no
[1]: ->lm_compare_owner and ->lm_owner_key are generally called with
*an* inode->i_lock held. It may not be the i_lock of the inode
associated with either file_lock argument! This is the case with deadlock
detection, since the code has to chase down the owners of locks that may
be entirely unrelated to the one on which the lock is being acquired.
For deadlock detection however, the blocked_lock_lock is also held. The
fact that these locks are held ensures that the file_locks do not
disappear out from under you while doing the comparison or generating an
owner key.
--------------------------- buffer_head ----------------------------------- --------------------------- buffer_head -----------------------------------
prototypes: prototypes:
void (*b_end_io)(struct buffer_head *bh, int uptodate); void (*b_end_io)(struct buffer_head *bh, int uptodate);
......
...@@ -47,13 +47,14 @@ void nlmclnt_next_cookie(struct nlm_cookie *c) ...@@ -47,13 +47,14 @@ void nlmclnt_next_cookie(struct nlm_cookie *c)
c->len=4; c->len=4;
} }
static struct nlm_lockowner *nlm_get_lockowner(struct nlm_lockowner *lockowner) static struct nlm_lockowner *
nlmclnt_get_lockowner(struct nlm_lockowner *lockowner)
{ {
refcount_inc(&lockowner->count); refcount_inc(&lockowner->count);
return lockowner; return lockowner;
} }
static void nlm_put_lockowner(struct nlm_lockowner *lockowner) static void nlmclnt_put_lockowner(struct nlm_lockowner *lockowner)
{ {
if (!refcount_dec_and_lock(&lockowner->count, &lockowner->host->h_lock)) if (!refcount_dec_and_lock(&lockowner->count, &lockowner->host->h_lock))
return; return;
...@@ -82,28 +83,28 @@ static inline uint32_t __nlm_alloc_pid(struct nlm_host *host) ...@@ -82,28 +83,28 @@ static inline uint32_t __nlm_alloc_pid(struct nlm_host *host)
return res; return res;
} }
static struct nlm_lockowner *__nlm_find_lockowner(struct nlm_host *host, fl_owner_t owner) static struct nlm_lockowner *__nlmclnt_find_lockowner(struct nlm_host *host, fl_owner_t owner)
{ {
struct nlm_lockowner *lockowner; struct nlm_lockowner *lockowner;
list_for_each_entry(lockowner, &host->h_lockowners, list) { list_for_each_entry(lockowner, &host->h_lockowners, list) {
if (lockowner->owner != owner) if (lockowner->owner != owner)
continue; continue;
return nlm_get_lockowner(lockowner); return nlmclnt_get_lockowner(lockowner);
} }
return NULL; return NULL;
} }
static struct nlm_lockowner *nlm_find_lockowner(struct nlm_host *host, fl_owner_t owner) static struct nlm_lockowner *nlmclnt_find_lockowner(struct nlm_host *host, fl_owner_t owner)
{ {
struct nlm_lockowner *res, *new = NULL; struct nlm_lockowner *res, *new = NULL;
spin_lock(&host->h_lock); spin_lock(&host->h_lock);
res = __nlm_find_lockowner(host, owner); res = __nlmclnt_find_lockowner(host, owner);
if (res == NULL) { if (res == NULL) {
spin_unlock(&host->h_lock); spin_unlock(&host->h_lock);
new = kmalloc(sizeof(*new), GFP_KERNEL); new = kmalloc(sizeof(*new), GFP_KERNEL);
spin_lock(&host->h_lock); spin_lock(&host->h_lock);
res = __nlm_find_lockowner(host, owner); res = __nlmclnt_find_lockowner(host, owner);
if (res == NULL && new != NULL) { if (res == NULL && new != NULL) {
res = new; res = new;
refcount_set(&new->count, 1); refcount_set(&new->count, 1);
...@@ -457,7 +458,7 @@ static void nlmclnt_locks_copy_lock(struct file_lock *new, struct file_lock *fl) ...@@ -457,7 +458,7 @@ static void nlmclnt_locks_copy_lock(struct file_lock *new, struct file_lock *fl)
{ {
spin_lock(&fl->fl_u.nfs_fl.owner->host->h_lock); spin_lock(&fl->fl_u.nfs_fl.owner->host->h_lock);
new->fl_u.nfs_fl.state = fl->fl_u.nfs_fl.state; new->fl_u.nfs_fl.state = fl->fl_u.nfs_fl.state;
new->fl_u.nfs_fl.owner = nlm_get_lockowner(fl->fl_u.nfs_fl.owner); new->fl_u.nfs_fl.owner = nlmclnt_get_lockowner(fl->fl_u.nfs_fl.owner);
list_add_tail(&new->fl_u.nfs_fl.list, &fl->fl_u.nfs_fl.owner->host->h_granted); list_add_tail(&new->fl_u.nfs_fl.list, &fl->fl_u.nfs_fl.owner->host->h_granted);
spin_unlock(&fl->fl_u.nfs_fl.owner->host->h_lock); spin_unlock(&fl->fl_u.nfs_fl.owner->host->h_lock);
} }
...@@ -467,7 +468,7 @@ static void nlmclnt_locks_release_private(struct file_lock *fl) ...@@ -467,7 +468,7 @@ static void nlmclnt_locks_release_private(struct file_lock *fl)
spin_lock(&fl->fl_u.nfs_fl.owner->host->h_lock); spin_lock(&fl->fl_u.nfs_fl.owner->host->h_lock);
list_del(&fl->fl_u.nfs_fl.list); list_del(&fl->fl_u.nfs_fl.list);
spin_unlock(&fl->fl_u.nfs_fl.owner->host->h_lock); spin_unlock(&fl->fl_u.nfs_fl.owner->host->h_lock);
nlm_put_lockowner(fl->fl_u.nfs_fl.owner); nlmclnt_put_lockowner(fl->fl_u.nfs_fl.owner);
} }
static const struct file_lock_operations nlmclnt_lock_ops = { static const struct file_lock_operations nlmclnt_lock_ops = {
...@@ -478,7 +479,7 @@ static const struct file_lock_operations nlmclnt_lock_ops = { ...@@ -478,7 +479,7 @@ static const struct file_lock_operations nlmclnt_lock_ops = {
static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host) static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host)
{ {
fl->fl_u.nfs_fl.state = 0; fl->fl_u.nfs_fl.state = 0;
fl->fl_u.nfs_fl.owner = nlm_find_lockowner(host, fl->fl_owner); fl->fl_u.nfs_fl.owner = nlmclnt_find_lockowner(host, fl->fl_owner);
INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list); INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list);
fl->fl_ops = &nlmclnt_lock_ops; fl->fl_ops = &nlmclnt_lock_ops;
} }
......
...@@ -46,8 +46,14 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, ...@@ -46,8 +46,14 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
/* Set up the missing parts of the file_lock structure */ /* Set up the missing parts of the file_lock structure */
lock->fl.fl_file = file->f_file; lock->fl.fl_file = file->f_file;
lock->fl.fl_owner = (fl_owner_t) host; lock->fl.fl_pid = current->tgid;
lock->fl.fl_lmops = &nlmsvc_lock_operations; lock->fl.fl_lmops = &nlmsvc_lock_operations;
nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid);
if (!lock->fl.fl_owner) {
/* lockowner allocation has failed */
nlmsvc_release_host(host);
return nlm_lck_denied_nolocks;
}
} }
return 0; return 0;
...@@ -94,6 +100,7 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -94,6 +100,7 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp)
else else
dprintk("lockd: TEST4 status %d\n", ntohl(resp->status)); dprintk("lockd: TEST4 status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rc; return rc;
...@@ -142,6 +149,7 @@ __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -142,6 +149,7 @@ __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp)
else else
dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); dprintk("lockd: LOCK status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rc; return rc;
...@@ -178,6 +186,7 @@ __nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -178,6 +186,7 @@ __nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp)
resp->status = nlmsvc_cancel_blocked(SVC_NET(rqstp), file, &argp->lock); resp->status = nlmsvc_cancel_blocked(SVC_NET(rqstp), file, &argp->lock);
dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -217,6 +226,7 @@ __nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -217,6 +226,7 @@ __nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp)
resp->status = nlmsvc_unlock(SVC_NET(rqstp), file, &argp->lock); resp->status = nlmsvc_unlock(SVC_NET(rqstp), file, &argp->lock);
dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -365,6 +375,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp) ...@@ -365,6 +375,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp)
resp->status = nlmsvc_share_file(host, file, argp); resp->status = nlmsvc_share_file(host, file, argp);
dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); dprintk("lockd: SHARE status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -399,6 +410,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp) ...@@ -399,6 +410,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp)
resp->status = nlmsvc_unshare_file(host, file, argp); resp->status = nlmsvc_unshare_file(host, file, argp);
dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
......
...@@ -332,6 +332,93 @@ void nlmsvc_traverse_blocks(struct nlm_host *host, ...@@ -332,6 +332,93 @@ void nlmsvc_traverse_blocks(struct nlm_host *host,
mutex_unlock(&file->f_mutex); mutex_unlock(&file->f_mutex);
} }
static struct nlm_lockowner *
nlmsvc_get_lockowner(struct nlm_lockowner *lockowner)
{
refcount_inc(&lockowner->count);
return lockowner;
}
static void nlmsvc_put_lockowner(struct nlm_lockowner *lockowner)
{
if (!refcount_dec_and_lock(&lockowner->count, &lockowner->host->h_lock))
return;
list_del(&lockowner->list);
spin_unlock(&lockowner->host->h_lock);
nlmsvc_release_host(lockowner->host);
kfree(lockowner);
}
static struct nlm_lockowner *__nlmsvc_find_lockowner(struct nlm_host *host, pid_t pid)
{
struct nlm_lockowner *lockowner;
list_for_each_entry(lockowner, &host->h_lockowners, list) {
if (lockowner->pid != pid)
continue;
return nlmsvc_get_lockowner(lockowner);
}
return NULL;
}
static struct nlm_lockowner *nlmsvc_find_lockowner(struct nlm_host *host, pid_t pid)
{
struct nlm_lockowner *res, *new = NULL;
spin_lock(&host->h_lock);
res = __nlmsvc_find_lockowner(host, pid);
if (res == NULL) {
spin_unlock(&host->h_lock);
new = kmalloc(sizeof(*res), GFP_KERNEL);
spin_lock(&host->h_lock);
res = __nlmsvc_find_lockowner(host, pid);
if (res == NULL && new != NULL) {
res = new;
/* fs/locks.c will manage the refcount through lock_ops */
refcount_set(&new->count, 1);
new->pid = pid;
new->host = nlm_get_host(host);
list_add(&new->list, &host->h_lockowners);
new = NULL;
}
}
spin_unlock(&host->h_lock);
kfree(new);
return res;
}
void
nlmsvc_release_lockowner(struct nlm_lock *lock)
{
if (lock->fl.fl_owner)
nlmsvc_put_lockowner(lock->fl.fl_owner);
}
static void nlmsvc_locks_copy_lock(struct file_lock *new, struct file_lock *fl)
{
struct nlm_lockowner *nlm_lo = (struct nlm_lockowner *)fl->fl_owner;
new->fl_owner = nlmsvc_get_lockowner(nlm_lo);
}
static void nlmsvc_locks_release_private(struct file_lock *fl)
{
nlmsvc_put_lockowner((struct nlm_lockowner *)fl->fl_owner);
}
static const struct file_lock_operations nlmsvc_lock_ops = {
.fl_copy_lock = nlmsvc_locks_copy_lock,
.fl_release_private = nlmsvc_locks_release_private,
};
void nlmsvc_locks_init_private(struct file_lock *fl, struct nlm_host *host,
pid_t pid)
{
fl->fl_owner = nlmsvc_find_lockowner(host, pid);
if (fl->fl_owner != NULL)
fl->fl_ops = &nlmsvc_lock_ops;
}
/* /*
* Initialize arguments for GRANTED call. The nlm_rqst structure * Initialize arguments for GRANTED call. The nlm_rqst structure
* has been cleared already. * has been cleared already.
...@@ -345,7 +432,7 @@ static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock) ...@@ -345,7 +432,7 @@ static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock)
/* set default data area */ /* set default data area */
call->a_args.lock.oh.data = call->a_owner; call->a_args.lock.oh.data = call->a_owner;
call->a_args.lock.svid = lock->fl.fl_pid; call->a_args.lock.svid = ((struct nlm_lockowner *)lock->fl.fl_owner)->pid;
if (lock->oh.len > NLMCLNT_OHSIZE) { if (lock->oh.len > NLMCLNT_OHSIZE) {
void *data = kmalloc(lock->oh.len, GFP_KERNEL); void *data = kmalloc(lock->oh.len, GFP_KERNEL);
...@@ -509,6 +596,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -509,6 +596,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
{ {
int error; int error;
__be32 ret; __be32 ret;
struct nlm_lockowner *test_owner;
dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n", dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
locks_inode(file->f_file)->i_sb->s_id, locks_inode(file->f_file)->i_sb->s_id,
...@@ -522,6 +610,9 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -522,6 +610,9 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
goto out; goto out;
} }
/* If there's a conflicting lock, remember to clean up the test lock */
test_owner = (struct nlm_lockowner *)lock->fl.fl_owner;
error = vfs_test_lock(file->f_file, &lock->fl); error = vfs_test_lock(file->f_file, &lock->fl);
if (error) { if (error) {
/* We can't currently deal with deferred test requests */ /* We can't currently deal with deferred test requests */
...@@ -543,11 +634,16 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -543,11 +634,16 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
conflock->caller = "somehost"; /* FIXME */ conflock->caller = "somehost"; /* FIXME */
conflock->len = strlen(conflock->caller); conflock->len = strlen(conflock->caller);
conflock->oh.len = 0; /* don't return OH info */ conflock->oh.len = 0; /* don't return OH info */
conflock->svid = lock->fl.fl_pid; conflock->svid = ((struct nlm_lockowner *)lock->fl.fl_owner)->pid;
conflock->fl.fl_type = lock->fl.fl_type; conflock->fl.fl_type = lock->fl.fl_type;
conflock->fl.fl_start = lock->fl.fl_start; conflock->fl.fl_start = lock->fl.fl_start;
conflock->fl.fl_end = lock->fl.fl_end; conflock->fl.fl_end = lock->fl.fl_end;
locks_release_private(&lock->fl); locks_release_private(&lock->fl);
/* Clean up the test lock */
lock->fl.fl_owner = NULL;
nlmsvc_put_lockowner(test_owner);
ret = nlm_lck_denied; ret = nlm_lck_denied;
out: out:
return ret; return ret;
...@@ -692,25 +788,7 @@ nlmsvc_notify_blocked(struct file_lock *fl) ...@@ -692,25 +788,7 @@ nlmsvc_notify_blocked(struct file_lock *fl)
printk(KERN_WARNING "lockd: notification for unknown block!\n"); printk(KERN_WARNING "lockd: notification for unknown block!\n");
} }
static int nlmsvc_same_owner(struct file_lock *fl1, struct file_lock *fl2)
{
return fl1->fl_owner == fl2->fl_owner && fl1->fl_pid == fl2->fl_pid;
}
/*
* Since NLM uses two "keys" for tracking locks, we need to hash them down
* to one for the blocked_hash. Here, we're just xor'ing the host address
* with the pid in order to create a key value for picking a hash bucket.
*/
static unsigned long
nlmsvc_owner_key(struct file_lock *fl)
{
return (unsigned long)fl->fl_owner ^ (unsigned long)fl->fl_pid;
}
const struct lock_manager_operations nlmsvc_lock_operations = { const struct lock_manager_operations nlmsvc_lock_operations = {
.lm_compare_owner = nlmsvc_same_owner,
.lm_owner_key = nlmsvc_owner_key,
.lm_notify = nlmsvc_notify_blocked, .lm_notify = nlmsvc_notify_blocked,
.lm_grant = nlmsvc_grant_deferred, .lm_grant = nlmsvc_grant_deferred,
}; };
......
...@@ -76,8 +76,14 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, ...@@ -76,8 +76,14 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
/* Set up the missing parts of the file_lock structure */ /* Set up the missing parts of the file_lock structure */
lock->fl.fl_file = file->f_file; lock->fl.fl_file = file->f_file;
lock->fl.fl_owner = (fl_owner_t) host; lock->fl.fl_pid = current->tgid;
lock->fl.fl_lmops = &nlmsvc_lock_operations; lock->fl.fl_lmops = &nlmsvc_lock_operations;
nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid);
if (!lock->fl.fl_owner) {
/* lockowner allocation has failed */
nlmsvc_release_host(host);
return nlm_lck_denied_nolocks;
}
} }
return 0; return 0;
...@@ -125,6 +131,7 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -125,6 +131,7 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp)
dprintk("lockd: TEST status %d vers %d\n", dprintk("lockd: TEST status %d vers %d\n",
ntohl(resp->status), rqstp->rq_vers); ntohl(resp->status), rqstp->rq_vers);
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rc; return rc;
...@@ -173,6 +180,7 @@ __nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -173,6 +180,7 @@ __nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp)
else else
dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); dprintk("lockd: LOCK status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rc; return rc;
...@@ -210,6 +218,7 @@ __nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -210,6 +218,7 @@ __nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp)
resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock)); resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock));
dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -250,6 +259,7 @@ __nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp) ...@@ -250,6 +259,7 @@ __nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp)
resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock)); resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock));
dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -408,6 +418,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp) ...@@ -408,6 +418,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp)
resp->status = cast_status(nlmsvc_share_file(host, file, argp)); resp->status = cast_status(nlmsvc_share_file(host, file, argp));
dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); dprintk("lockd: SHARE status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
...@@ -442,6 +453,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp) ...@@ -442,6 +453,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp)
resp->status = cast_status(nlmsvc_unshare_file(host, file, argp)); resp->status = cast_status(nlmsvc_unshare_file(host, file, argp));
dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status));
nlmsvc_release_lockowner(&argp->lock);
nlmsvc_release_host(host); nlmsvc_release_host(host);
nlm_release_file(file); nlm_release_file(file);
return rpc_success; return rpc_success;
......
...@@ -180,7 +180,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, ...@@ -180,7 +180,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
/* update current lock count */ /* update current lock count */
file->f_locks++; file->f_locks++;
lockhost = (struct nlm_host *) fl->fl_owner; lockhost = ((struct nlm_lockowner *)fl->fl_owner)->host;
if (match(lockhost, host)) { if (match(lockhost, host)) {
struct file_lock lock = *fl; struct file_lock lock = *fl;
......
...@@ -126,8 +126,6 @@ nlm_decode_lock(__be32 *p, struct nlm_lock *lock) ...@@ -126,8 +126,6 @@ nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
lock->svid = ntohl(*p++); lock->svid = ntohl(*p++);
locks_init_lock(fl); locks_init_lock(fl);
fl->fl_owner = current->files;
fl->fl_pid = (pid_t)lock->svid;
fl->fl_flags = FL_POSIX; fl->fl_flags = FL_POSIX;
fl->fl_type = F_RDLCK; /* as good as anything else */ fl->fl_type = F_RDLCK; /* as good as anything else */
start = ntohl(*p++); start = ntohl(*p++);
...@@ -269,7 +267,6 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p) ...@@ -269,7 +267,6 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
memset(lock, 0, sizeof(*lock)); memset(lock, 0, sizeof(*lock));
locks_init_lock(&lock->fl); locks_init_lock(&lock->fl);
lock->svid = ~(u32) 0; lock->svid = ~(u32) 0;
lock->fl.fl_pid = (pid_t)lock->svid;
if (!(p = nlm_decode_cookie(p, &argp->cookie)) if (!(p = nlm_decode_cookie(p, &argp->cookie))
|| !(p = xdr_decode_string_inplace(p, &lock->caller, || !(p = xdr_decode_string_inplace(p, &lock->caller,
......
...@@ -118,8 +118,6 @@ nlm4_decode_lock(__be32 *p, struct nlm_lock *lock) ...@@ -118,8 +118,6 @@ nlm4_decode_lock(__be32 *p, struct nlm_lock *lock)
lock->svid = ntohl(*p++); lock->svid = ntohl(*p++);
locks_init_lock(fl); locks_init_lock(fl);
fl->fl_owner = current->files;
fl->fl_pid = (pid_t)lock->svid;
fl->fl_flags = FL_POSIX; fl->fl_flags = FL_POSIX;
fl->fl_type = F_RDLCK; /* as good as anything else */ fl->fl_type = F_RDLCK; /* as good as anything else */
p = xdr_decode_hyper(p, &start); p = xdr_decode_hyper(p, &start);
...@@ -266,7 +264,6 @@ nlm4svc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p) ...@@ -266,7 +264,6 @@ nlm4svc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
memset(lock, 0, sizeof(*lock)); memset(lock, 0, sizeof(*lock));
locks_init_lock(&lock->fl); locks_init_lock(&lock->fl);
lock->svid = ~(u32) 0; lock->svid = ~(u32) 0;
lock->fl.fl_pid = (pid_t)lock->svid;
if (!(p = nlm4_decode_cookie(p, &argp->cookie)) if (!(p = nlm4_decode_cookie(p, &argp->cookie))
|| !(p = xdr_decode_string_inplace(p, &lock->caller, || !(p = xdr_decode_string_inplace(p, &lock->caller,
......
...@@ -658,9 +658,6 @@ static inline int locks_overlap(struct file_lock *fl1, struct file_lock *fl2) ...@@ -658,9 +658,6 @@ static inline int locks_overlap(struct file_lock *fl1, struct file_lock *fl2)
*/ */
static int posix_same_owner(struct file_lock *fl1, struct file_lock *fl2) static int posix_same_owner(struct file_lock *fl1, struct file_lock *fl2)
{ {
if (fl1->fl_lmops && fl1->fl_lmops->lm_compare_owner)
return fl2->fl_lmops == fl1->fl_lmops &&
fl1->fl_lmops->lm_compare_owner(fl1, fl2);
return fl1->fl_owner == fl2->fl_owner; return fl1->fl_owner == fl2->fl_owner;
} }
...@@ -701,8 +698,6 @@ static void locks_delete_global_locks(struct file_lock *fl) ...@@ -701,8 +698,6 @@ static void locks_delete_global_locks(struct file_lock *fl)
static unsigned long static unsigned long
posix_owner_key(struct file_lock *fl) posix_owner_key(struct file_lock *fl)
{ {
if (fl->fl_lmops && fl->fl_lmops->lm_owner_key)
return fl->fl_lmops->lm_owner_key(fl);
return (unsigned long)fl->fl_owner; return (unsigned long)fl->fl_owner;
} }
......
...@@ -121,15 +121,13 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, ...@@ -121,15 +121,13 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp,
{ {
loff_t new_size = lcp->lc_last_wr + 1; loff_t new_size = lcp->lc_last_wr + 1;
struct iattr iattr = { .ia_valid = 0 }; struct iattr iattr = { .ia_valid = 0 };
struct timespec ts;
int error; int error;
ts = timespec64_to_timespec(inode->i_mtime);
if (lcp->lc_mtime.tv_nsec == UTIME_NOW || if (lcp->lc_mtime.tv_nsec == UTIME_NOW ||
timespec_compare(&lcp->lc_mtime, &ts) < 0) timespec64_compare(&lcp->lc_mtime, &inode->i_mtime) < 0)
lcp->lc_mtime = timespec64_to_timespec(current_time(inode)); lcp->lc_mtime = current_time(inode);
iattr.ia_valid |= ATTR_ATIME | ATTR_CTIME | ATTR_MTIME; iattr.ia_valid |= ATTR_ATIME | ATTR_CTIME | ATTR_MTIME;
iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = timespec_to_timespec64(lcp->lc_mtime); iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime;
if (new_size > i_size_read(inode)) { if (new_size > i_size_read(inode)) {
iattr.ia_valid |= ATTR_SIZE; iattr.ia_valid |= ATTR_SIZE;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define NFSCACHE_H #define NFSCACHE_H
#include <linux/sunrpc/svc.h> #include <linux/sunrpc/svc.h>
#include "netns.h"
/* /*
* Representation of a reply cache entry. * Representation of a reply cache entry.
...@@ -77,8 +78,8 @@ enum { ...@@ -77,8 +78,8 @@ enum {
/* Checksum this amount of the request */ /* Checksum this amount of the request */
#define RC_CSUMLEN (256U) #define RC_CSUMLEN (256U)
int nfsd_reply_cache_init(void); int nfsd_reply_cache_init(struct nfsd_net *);
void nfsd_reply_cache_shutdown(void); void nfsd_reply_cache_shutdown(struct nfsd_net *);
int nfsd_cache_lookup(struct svc_rqst *); int nfsd_cache_lookup(struct svc_rqst *);
void nfsd_cache_update(struct svc_rqst *, int, __be32 *); void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
int nfsd_reply_cache_stats_open(struct inode *, struct file *); int nfsd_reply_cache_stats_open(struct inode *, struct file *);
......
...@@ -42,6 +42,11 @@ struct nfsd_net { ...@@ -42,6 +42,11 @@ struct nfsd_net {
bool grace_ended; bool grace_ended;
time_t boot_time; time_t boot_time;
/* internal mount of the "nfsd" pseudofilesystem: */
struct vfsmount *nfsd_mnt;
struct dentry *nfsd_client_dir;
/* /*
* reclaim_str_hashtbl[] holds known client info from previous reset/reboot * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
* used in reboot/reset lease grace period processing * used in reboot/reset lease grace period processing
...@@ -106,6 +111,7 @@ struct nfsd_net { ...@@ -106,6 +111,7 @@ struct nfsd_net {
*/ */
unsigned int max_connections; unsigned int max_connections;
u32 clientid_base;
u32 clientid_counter; u32 clientid_counter;
u32 clverifier_counter; u32 clverifier_counter;
...@@ -127,6 +133,44 @@ struct nfsd_net { ...@@ -127,6 +133,44 @@ struct nfsd_net {
*/ */
bool *nfsd_versions; bool *nfsd_versions;
bool *nfsd4_minorversions; bool *nfsd4_minorversions;
/*
* Duplicate reply cache
*/
struct nfsd_drc_bucket *drc_hashtbl;
struct kmem_cache *drc_slab;
/* max number of entries allowed in the cache */
unsigned int max_drc_entries;
/* number of significant bits in the hash value */
unsigned int maskbits;
unsigned int drc_hashsize;
/*
* Stats and other tracking of on the duplicate reply cache.
* These fields and the "rc" fields in nfsdstats are modified
* with only the per-bucket cache lock, which isn't really safe
* and should be fixed if we want the statistics to be
* completely accurate.
*/
/* total number of entries */
atomic_t num_drc_entries;
/* cache misses due only to checksum comparison failures */
unsigned int payload_misses;
/* amount of memory (in bytes) currently consumed by the DRC */
unsigned int drc_mem_usage;
/* longest hash chain seen */
unsigned int longest_chain;
/* size of cache when we saw the longest hash chain */
unsigned int longest_chain_cachesize;
struct shrinker nfsd_reply_cache_shrinker;
}; };
/* Simple check to find out if a given net was properly initialized */ /* Simple check to find out if a given net was properly initialized */
......
...@@ -83,7 +83,7 @@ ent_init(struct cache_head *cnew, struct cache_head *citm) ...@@ -83,7 +83,7 @@ ent_init(struct cache_head *cnew, struct cache_head *citm)
new->type = itm->type; new->type = itm->type;
strlcpy(new->name, itm->name, sizeof(new->name)); strlcpy(new->name, itm->name, sizeof(new->name));
strlcpy(new->authname, itm->authname, sizeof(new->name)); strlcpy(new->authname, itm->authname, sizeof(new->authname));
} }
static void static void
......
This diff is collapsed.
...@@ -269,19 +269,13 @@ static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) ...@@ -269,19 +269,13 @@ static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
return ret; return ret;
} }
/*
* We require the high 32 bits of 'seconds' to be 0, and
* we ignore all 32 bits of 'nseconds'.
*/
static __be32 static __be32
nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec *tv) nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv)
{ {
DECODE_HEAD; DECODE_HEAD;
u64 sec;
READ_BUF(12); READ_BUF(12);
p = xdr_decode_hyper(p, &sec); p = xdr_decode_hyper(p, &tv->tv_sec);
tv->tv_sec = sec;
tv->tv_nsec = be32_to_cpup(p++); tv->tv_nsec = be32_to_cpup(p++);
if (tv->tv_nsec >= (u32)1000000000) if (tv->tv_nsec >= (u32)1000000000)
return nfserr_inval; return nfserr_inval;
...@@ -320,7 +314,6 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, ...@@ -320,7 +314,6 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
struct iattr *iattr, struct nfs4_acl **acl, struct iattr *iattr, struct nfs4_acl **acl,
struct xdr_netobj *label, int *umask) struct xdr_netobj *label, int *umask)
{ {
struct timespec ts;
int expected_len, len = 0; int expected_len, len = 0;
u32 dummy32; u32 dummy32;
char *buf; char *buf;
...@@ -422,8 +415,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, ...@@ -422,8 +415,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
switch (dummy32) { switch (dummy32) {
case NFS4_SET_TO_CLIENT_TIME: case NFS4_SET_TO_CLIENT_TIME:
len += 12; len += 12;
status = nfsd4_decode_time(argp, &ts); status = nfsd4_decode_time(argp, &iattr->ia_atime);
iattr->ia_atime = timespec_to_timespec64(ts);
if (status) if (status)
return status; return status;
iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
...@@ -442,8 +434,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, ...@@ -442,8 +434,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
switch (dummy32) { switch (dummy32) {
case NFS4_SET_TO_CLIENT_TIME: case NFS4_SET_TO_CLIENT_TIME:
len += 12; len += 12;
status = nfsd4_decode_time(argp, &ts); status = nfsd4_decode_time(argp, &iattr->ia_mtime);
iattr->ia_mtime = timespec_to_timespec64(ts);
if (status) if (status)
return status; return status;
iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
...@@ -1398,7 +1389,6 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, ...@@ -1398,7 +1389,6 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
goto xdr_error; goto xdr_error;
} }
/* Ignore Implementation ID */
READ_BUF(4); /* nfs_impl_id4 array length */ READ_BUF(4); /* nfs_impl_id4 array length */
dummy = be32_to_cpup(p++); dummy = be32_to_cpup(p++);
...@@ -1406,21 +1396,19 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, ...@@ -1406,21 +1396,19 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
goto xdr_error; goto xdr_error;
if (dummy == 1) { if (dummy == 1) {
/* nii_domain */ status = nfsd4_decode_opaque(argp, &exid->nii_domain);
READ_BUF(4); if (status)
dummy = be32_to_cpup(p++); goto xdr_error;
READ_BUF(dummy);
p += XDR_QUADLEN(dummy);
/* nii_name */ /* nii_name */
READ_BUF(4); status = nfsd4_decode_opaque(argp, &exid->nii_name);
dummy = be32_to_cpup(p++); if (status)
READ_BUF(dummy); goto xdr_error;
p += XDR_QUADLEN(dummy);
/* nii_date */ /* nii_date */
READ_BUF(12); status = nfsd4_decode_time(argp, &exid->nii_time);
p += 3; if (status)
goto xdr_error;
} }
DECODE_TAIL; DECODE_TAIL;
} }
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/sunrpc/gss_krb5_enctypes.h> #include <linux/sunrpc/gss_krb5_enctypes.h>
#include <linux/sunrpc/rpc_pipe_fs.h> #include <linux/sunrpc/rpc_pipe_fs.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/fsnotify.h>
#include "idmap.h" #include "idmap.h"
#include "nfsd.h" #include "nfsd.h"
...@@ -53,6 +54,7 @@ enum { ...@@ -53,6 +54,7 @@ enum {
NFSD_RecoveryDir, NFSD_RecoveryDir,
NFSD_V4EndGrace, NFSD_V4EndGrace,
#endif #endif
NFSD_MaxReserved
}; };
/* /*
...@@ -1147,8 +1149,201 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) ...@@ -1147,8 +1149,201 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size)
* populating the filesystem. * populating the filesystem.
*/ */
/* Basically copying rpc_get_inode. */
static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode)
{
struct inode *inode = new_inode(sb);
if (!inode)
return NULL;
/* Following advice from simple_fill_super documentation: */
inode->i_ino = iunique(sb, NFSD_MaxReserved);
inode->i_mode = mode;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
switch (mode & S_IFMT) {
case S_IFDIR:
inode->i_fop = &simple_dir_operations;
inode->i_op = &simple_dir_inode_operations;
inc_nlink(inode);
default:
break;
}
return inode;
}
static int __nfsd_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
struct inode *inode;
inode = nfsd_get_inode(dir->i_sb, mode);
if (!inode)
return -ENOMEM;
d_add(dentry, inode);
inc_nlink(dir);
fsnotify_mkdir(dir, dentry);
return 0;
}
static struct dentry *nfsd_mkdir(struct dentry *parent, struct nfsdfs_client *ncl, char *name)
{
struct inode *dir = parent->d_inode;
struct dentry *dentry;
int ret = -ENOMEM;
inode_lock(dir);
dentry = d_alloc_name(parent, name);
if (!dentry)
goto out_err;
ret = __nfsd_mkdir(d_inode(parent), dentry, S_IFDIR | 0600);
if (ret)
goto out_err;
if (ncl) {
d_inode(dentry)->i_private = ncl;
kref_get(&ncl->cl_ref);
}
out:
inode_unlock(dir);
return dentry;
out_err:
dentry = ERR_PTR(ret);
goto out;
}
static void clear_ncl(struct inode *inode)
{
struct nfsdfs_client *ncl = inode->i_private;
inode->i_private = NULL;
synchronize_rcu();
kref_put(&ncl->cl_ref, ncl->cl_release);
}
static struct nfsdfs_client *__get_nfsdfs_client(struct inode *inode)
{
struct nfsdfs_client *nc = inode->i_private;
if (nc)
kref_get(&nc->cl_ref);
return nc;
}
struct nfsdfs_client *get_nfsdfs_client(struct inode *inode)
{
struct nfsdfs_client *nc;
rcu_read_lock();
nc = __get_nfsdfs_client(inode);
rcu_read_unlock();
return nc;
}
/* from __rpc_unlink */
static void nfsdfs_remove_file(struct inode *dir, struct dentry *dentry)
{
int ret;
clear_ncl(d_inode(dentry));
dget(dentry);
ret = simple_unlink(dir, dentry);
d_delete(dentry);
dput(dentry);
WARN_ON_ONCE(ret);
}
static void nfsdfs_remove_files(struct dentry *root)
{
struct dentry *dentry, *tmp;
list_for_each_entry_safe(dentry, tmp, &root->d_subdirs, d_child) {
if (!simple_positive(dentry)) {
WARN_ON_ONCE(1); /* I think this can't happen? */
continue;
}
nfsdfs_remove_file(d_inode(root), dentry);
}
}
/* XXX: cut'n'paste from simple_fill_super; figure out if we could share
* code instead. */
static int nfsdfs_create_files(struct dentry *root,
const struct tree_descr *files)
{
struct inode *dir = d_inode(root);
struct inode *inode;
struct dentry *dentry;
int i;
inode_lock(dir);
for (i = 0; files->name && files->name[0]; i++, files++) {
if (!files->name)
continue;
dentry = d_alloc_name(root, files->name);
if (!dentry)
goto out;
inode = nfsd_get_inode(d_inode(root)->i_sb,
S_IFREG | files->mode);
if (!inode) {
dput(dentry);
goto out;
}
inode->i_fop = files->ops;
inode->i_private = __get_nfsdfs_client(dir);
d_add(dentry, inode);
fsnotify_create(dir, dentry);
}
inode_unlock(dir);
return 0;
out:
nfsdfs_remove_files(root);
inode_unlock(dir);
return -ENOMEM;
}
/* on success, returns positive number unique to that client. */
struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
struct nfsdfs_client *ncl, u32 id,
const struct tree_descr *files)
{
struct dentry *dentry;
char name[11];
int ret;
sprintf(name, "%u", id);
dentry = nfsd_mkdir(nn->nfsd_client_dir, ncl, name);
if (IS_ERR(dentry)) /* XXX: tossing errors? */
return NULL;
ret = nfsdfs_create_files(dentry, files);
if (ret) {
nfsd_client_rmdir(dentry);
return NULL;
}
return dentry;
}
/* Taken from __rpc_rmdir: */
void nfsd_client_rmdir(struct dentry *dentry)
{
struct inode *dir = d_inode(dentry->d_parent);
struct inode *inode = d_inode(dentry);
int ret;
inode_lock(dir);
nfsdfs_remove_files(dentry);
clear_ncl(inode);
dget(dentry);
ret = simple_rmdir(dir, dentry);
WARN_ON_ONCE(ret);
d_delete(dentry);
inode_unlock(dir);
}
static int nfsd_fill_super(struct super_block * sb, void * data, int silent) static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
{ {
struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
nfsd_net_id);
struct dentry *dentry;
int ret;
static const struct tree_descr nfsd_files[] = { static const struct tree_descr nfsd_files[] = {
[NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO}, [NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO},
[NFSD_Export_features] = {"export_features", [NFSD_Export_features] = {"export_features",
...@@ -1178,7 +1373,15 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent) ...@@ -1178,7 +1373,15 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
/* last one */ {""} /* last one */ {""}
}; };
get_net(sb->s_fs_info); get_net(sb->s_fs_info);
return simple_fill_super(sb, 0x6e667364, nfsd_files); ret = simple_fill_super(sb, 0x6e667364, nfsd_files);
if (ret)
return ret;
dentry = nfsd_mkdir(sb->s_root, NULL, "clients");
if (IS_ERR(dentry))
return PTR_ERR(dentry);
nn->nfsd_client_dir = dentry;
return 0;
} }
static struct dentry *nfsd_mount(struct file_system_type *fs_type, static struct dentry *nfsd_mount(struct file_system_type *fs_type,
...@@ -1232,6 +1435,7 @@ unsigned int nfsd_net_id; ...@@ -1232,6 +1435,7 @@ unsigned int nfsd_net_id;
static __net_init int nfsd_init_net(struct net *net) static __net_init int nfsd_init_net(struct net *net)
{ {
int retval; int retval;
struct vfsmount *mnt;
struct nfsd_net *nn = net_generic(net, nfsd_net_id); struct nfsd_net *nn = net_generic(net, nfsd_net_id);
retval = nfsd_export_init(net); retval = nfsd_export_init(net);
...@@ -1242,18 +1446,33 @@ static __net_init int nfsd_init_net(struct net *net) ...@@ -1242,18 +1446,33 @@ static __net_init int nfsd_init_net(struct net *net)
goto out_idmap_error; goto out_idmap_error;
nn->nfsd_versions = NULL; nn->nfsd_versions = NULL;
nn->nfsd4_minorversions = NULL; nn->nfsd4_minorversions = NULL;
retval = nfsd_reply_cache_init(nn);
if (retval)
goto out_drc_error;
nn->nfsd4_lease = 90; /* default lease time */ nn->nfsd4_lease = 90; /* default lease time */
nn->nfsd4_grace = 90; nn->nfsd4_grace = 90;
nn->somebody_reclaimed = false; nn->somebody_reclaimed = false;
nn->track_reclaim_completes = false; nn->track_reclaim_completes = false;
nn->clverifier_counter = prandom_u32(); nn->clverifier_counter = prandom_u32();
nn->clientid_counter = prandom_u32(); nn->clientid_base = prandom_u32();
nn->clientid_counter = nn->clientid_base + 1;
nn->s2s_cp_cl_id = nn->clientid_counter++; nn->s2s_cp_cl_id = nn->clientid_counter++;
atomic_set(&nn->ntf_refcnt, 0); atomic_set(&nn->ntf_refcnt, 0);
init_waitqueue_head(&nn->ntf_wq); init_waitqueue_head(&nn->ntf_wq);
mnt = vfs_kern_mount(&nfsd_fs_type, SB_KERNMOUNT, "nfsd", NULL);
if (IS_ERR(mnt)) {
retval = PTR_ERR(mnt);
goto out_mount_err;
}
nn->nfsd_mnt = mnt;
return 0; return 0;
out_mount_err:
nfsd_reply_cache_shutdown(nn);
out_drc_error:
nfsd_idmap_shutdown(net);
out_idmap_error: out_idmap_error:
nfsd_export_shutdown(net); nfsd_export_shutdown(net);
out_export_error: out_export_error:
...@@ -1262,6 +1481,10 @@ static __net_init int nfsd_init_net(struct net *net) ...@@ -1262,6 +1481,10 @@ static __net_init int nfsd_init_net(struct net *net)
static __net_exit void nfsd_exit_net(struct net *net) static __net_exit void nfsd_exit_net(struct net *net)
{ {
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
mntput(nn->nfsd_mnt);
nfsd_reply_cache_shutdown(nn);
nfsd_idmap_shutdown(net); nfsd_idmap_shutdown(net);
nfsd_export_shutdown(net); nfsd_export_shutdown(net);
nfsd_netns_free_versions(net_generic(net, nfsd_net_id)); nfsd_netns_free_versions(net_generic(net, nfsd_net_id));
...@@ -1295,9 +1518,6 @@ static int __init init_nfsd(void) ...@@ -1295,9 +1518,6 @@ static int __init init_nfsd(void)
if (retval) if (retval)
goto out_exit_pnfs; goto out_exit_pnfs;
nfsd_stat_init(); /* Statistics */ nfsd_stat_init(); /* Statistics */
retval = nfsd_reply_cache_init();
if (retval)
goto out_free_stat;
nfsd_lockd_init(); /* lockd->nfsd callbacks */ nfsd_lockd_init(); /* lockd->nfsd callbacks */
retval = create_proc_exports_entry(); retval = create_proc_exports_entry();
if (retval) if (retval)
...@@ -1311,8 +1531,6 @@ static int __init init_nfsd(void) ...@@ -1311,8 +1531,6 @@ static int __init init_nfsd(void)
remove_proc_entry("fs/nfs", NULL); remove_proc_entry("fs/nfs", NULL);
out_free_lockd: out_free_lockd:
nfsd_lockd_shutdown(); nfsd_lockd_shutdown();
nfsd_reply_cache_shutdown();
out_free_stat:
nfsd_stat_shutdown(); nfsd_stat_shutdown();
nfsd_fault_inject_cleanup(); nfsd_fault_inject_cleanup();
out_exit_pnfs: out_exit_pnfs:
...@@ -1328,7 +1546,6 @@ static int __init init_nfsd(void) ...@@ -1328,7 +1546,6 @@ static int __init init_nfsd(void)
static void __exit exit_nfsd(void) static void __exit exit_nfsd(void)
{ {
nfsd_reply_cache_shutdown();
remove_proc_entry("fs/nfs/exports", NULL); remove_proc_entry("fs/nfs/exports", NULL);
remove_proc_entry("fs/nfs", NULL); remove_proc_entry("fs/nfs", NULL);
nfsd_stat_shutdown(); nfsd_stat_shutdown();
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <uapi/linux/nfsd/debug.h> #include <uapi/linux/nfsd/debug.h>
#include "netns.h"
#include "stats.h" #include "stats.h"
#include "export.h" #include "export.h"
...@@ -86,6 +87,16 @@ int nfsd_pool_stats_release(struct inode *, struct file *); ...@@ -86,6 +87,16 @@ int nfsd_pool_stats_release(struct inode *, struct file *);
void nfsd_destroy(struct net *net); void nfsd_destroy(struct net *net);
struct nfsdfs_client {
struct kref cl_ref;
void (*cl_release)(struct kref *kref);
};
struct nfsdfs_client *get_nfsdfs_client(struct inode *);
struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
struct nfsdfs_client *ncl, u32 id, const struct tree_descr *);
void nfsd_client_rmdir(struct dentry *dentry);
#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
#ifdef CONFIG_NFSD_V2_ACL #ifdef CONFIG_NFSD_V2_ACL
extern const struct svc_version nfsd_acl_version2; extern const struct svc_version nfsd_acl_version2;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <linux/sunrpc/svc_xprt.h> #include <linux/sunrpc/svc_xprt.h>
#include "nfsfh.h" #include "nfsfh.h"
#include "nfsd.h"
typedef struct { typedef struct {
u32 cl_boot; u32 cl_boot;
...@@ -316,6 +317,10 @@ struct nfs4_client { ...@@ -316,6 +317,10 @@ struct nfs4_client {
clientid_t cl_clientid; /* generated by server */ clientid_t cl_clientid; /* generated by server */
nfs4_verifier cl_confirm; /* generated by server */ nfs4_verifier cl_confirm; /* generated by server */
u32 cl_minorversion; u32 cl_minorversion;
/* NFSv4.1 client implementation id: */
struct xdr_netobj cl_nii_domain;
struct xdr_netobj cl_nii_name;
struct timespec cl_nii_time;
/* for v4.0 and v4.1 callbacks: */ /* for v4.0 and v4.1 callbacks: */
struct nfs4_cb_conn cl_cb_conn; struct nfs4_cb_conn cl_cb_conn;
...@@ -347,9 +352,13 @@ struct nfs4_client { ...@@ -347,9 +352,13 @@ struct nfs4_client {
struct nfsd4_clid_slot cl_cs_slot; /* create_session slot */ struct nfsd4_clid_slot cl_cs_slot; /* create_session slot */
u32 cl_exchange_flags; u32 cl_exchange_flags;
/* number of rpc's in progress over an associated session: */ /* number of rpc's in progress over an associated session: */
atomic_t cl_refcount; atomic_t cl_rpc_users;
struct nfsdfs_client cl_nfsdfs;
struct nfs4_op_map cl_spo_must_allow; struct nfs4_op_map cl_spo_must_allow;
/* debugging info directory under nfsd/clients/ : */
struct dentry *cl_nfsd_dentry;
/* for nfs41 callbacks */ /* for nfs41 callbacks */
/* We currently support a single back channel with a single slot */ /* We currently support a single back channel with a single slot */
unsigned long cl_cb_slot_busy; unsigned long cl_cb_slot_busy;
......
...@@ -404,7 +404,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap, ...@@ -404,7 +404,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
/* /*
* If utimes(2) and friends are called with times not NULL, we should * If utimes(2) and friends are called with times not NULL, we should
* not set NFSD_MAY_WRITE bit. Otherwise fh_verify->nfsd_permission * not set NFSD_MAY_WRITE bit. Otherwise fh_verify->nfsd_permission
* will return EACCESS, when the caller's effective UID does not match * will return EACCES, when the caller's effective UID does not match
* the owner of the file, and the caller is not privileged. In this * the owner of the file, and the caller is not privileged. In this
* situation, we should return EPERM(notify_change will return this). * situation, we should return EPERM(notify_change will return this).
*/ */
......
...@@ -410,6 +410,9 @@ struct nfsd4_exchange_id { ...@@ -410,6 +410,9 @@ struct nfsd4_exchange_id {
int spa_how; int spa_how;
u32 spo_must_enforce[3]; u32 spo_must_enforce[3];
u32 spo_must_allow[3]; u32 spo_must_allow[3];
struct xdr_netobj nii_domain;
struct xdr_netobj nii_name;
struct timespec64 nii_time;
}; };
struct nfsd4_sequence { struct nfsd4_sequence {
...@@ -472,7 +475,7 @@ struct nfsd4_layoutcommit { ...@@ -472,7 +475,7 @@ struct nfsd4_layoutcommit {
u32 lc_reclaim; /* request */ u32 lc_reclaim; /* request */
u32 lc_newoffset; /* request */ u32 lc_newoffset; /* request */
u64 lc_last_wr; /* request */ u64 lc_last_wr; /* request */
struct timespec lc_mtime; /* request */ struct timespec64 lc_mtime; /* request */
u32 lc_layout_type; /* request */ u32 lc_layout_type; /* request */
u32 lc_up_len; /* layout length */ u32 lc_up_len; /* layout length */
void *lc_up_layout; /* decoded by callback */ void *lc_up_layout; /* decoded by callback */
......
...@@ -384,6 +384,17 @@ void seq_escape(struct seq_file *m, const char *s, const char *esc) ...@@ -384,6 +384,17 @@ void seq_escape(struct seq_file *m, const char *s, const char *esc)
} }
EXPORT_SYMBOL(seq_escape); EXPORT_SYMBOL(seq_escape);
void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz)
{
char *buf;
size_t size = seq_get_buf(m, &buf);
int ret;
ret = string_escape_mem_ascii(src, isz, buf, size);
seq_commit(m, ret < size ? ret : -1);
}
EXPORT_SYMBOL(seq_escape_mem_ascii);
void seq_vprintf(struct seq_file *m, const char *f, va_list args) void seq_vprintf(struct seq_file *m, const char *f, va_list args)
{ {
int len; int len;
......
...@@ -1019,8 +1019,6 @@ struct file_lock_operations { ...@@ -1019,8 +1019,6 @@ struct file_lock_operations {
}; };
struct lock_manager_operations { struct lock_manager_operations {
int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
unsigned long (*lm_owner_key)(struct file_lock *);
fl_owner_t (*lm_get_owner)(fl_owner_t); fl_owner_t (*lm_get_owner)(fl_owner_t);
void (*lm_put_owner)(fl_owner_t); void (*lm_put_owner)(fl_owner_t);
void (*lm_notify)(struct file_lock *); /* unblock callback */ void (*lm_notify)(struct file_lock *); /* unblock callback */
......
...@@ -282,6 +282,7 @@ void nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *, ...@@ -282,6 +282,7 @@ void nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
nlm_host_match_fn_t match); nlm_host_match_fn_t match);
void nlmsvc_grant_reply(struct nlm_cookie *, __be32); void nlmsvc_grant_reply(struct nlm_cookie *, __be32);
void nlmsvc_release_call(struct nlm_rqst *); void nlmsvc_release_call(struct nlm_rqst *);
void nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t);
/* /*
* File handling for the server personality * File handling for the server personality
...@@ -289,6 +290,7 @@ void nlmsvc_release_call(struct nlm_rqst *); ...@@ -289,6 +290,7 @@ void nlmsvc_release_call(struct nlm_rqst *);
__be32 nlm_lookup_file(struct svc_rqst *, struct nlm_file **, __be32 nlm_lookup_file(struct svc_rqst *, struct nlm_file **,
struct nfs_fh *); struct nfs_fh *);
void nlm_release_file(struct nlm_file *); void nlm_release_file(struct nlm_file *);
void nlmsvc_release_lockowner(struct nlm_lock *);
void nlmsvc_mark_resources(struct net *); void nlmsvc_mark_resources(struct net *);
void nlmsvc_free_host_resources(struct nlm_host *); void nlmsvc_free_host_resources(struct nlm_host *);
void nlmsvc_invalidate_all(void); void nlmsvc_invalidate_all(void);
......
...@@ -127,6 +127,7 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter, ...@@ -127,6 +127,7 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter,
unsigned long long v, unsigned int width); unsigned long long v, unsigned int width);
void seq_escape(struct seq_file *m, const char *s, const char *esc); void seq_escape(struct seq_file *m, const char *s, const char *esc);
void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz);
void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
int rowsize, int groupsize, const void *buf, size_t len, int rowsize, int groupsize, const void *buf, size_t len,
......
...@@ -54,6 +54,9 @@ static inline int string_unescape_any_inplace(char *buf) ...@@ -54,6 +54,9 @@ static inline int string_unescape_any_inplace(char *buf)
int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
unsigned int flags, const char *only); unsigned int flags, const char *only);
int string_escape_mem_ascii(const char *src, size_t isz, char *dst,
size_t osz);
static inline int string_escape_mem_any_np(const char *src, size_t isz, static inline int string_escape_mem_any_np(const char *src, size_t isz,
char *dst, size_t osz, const char *only) char *dst, size_t osz, const char *only)
{ {
......
...@@ -164,6 +164,13 @@ xdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len) ...@@ -164,6 +164,13 @@ xdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len)
return p + XDR_QUADLEN(len); return p + XDR_QUADLEN(len);
} }
static inline void xdr_netobj_dup(struct xdr_netobj *dst,
struct xdr_netobj *src, gfp_t gfp_mask)
{
dst->data = kmemdup(src->data, src->len, gfp_mask);
dst->len = src->len;
}
/* /*
* Adjust kvec to reflect end of xdr'ed data (RPC client XDR) * Adjust kvec to reflect end of xdr'ed data (RPC client XDR)
*/ */
......
...@@ -540,6 +540,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, ...@@ -540,6 +540,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
} }
EXPORT_SYMBOL(string_escape_mem); EXPORT_SYMBOL(string_escape_mem);
int string_escape_mem_ascii(const char *src, size_t isz, char *dst,
size_t osz)
{
char *p = dst;
char *end = p + osz;
while (isz--) {
unsigned char c = *src++;
if (!isprint(c) || !isascii(c) || c == '"' || c == '\\')
escape_hex(c, &p, end);
else
escape_passthrough(c, &p, end);
}
return p - dst;
}
EXPORT_SYMBOL(string_escape_mem_ascii);
/* /*
* Return an allocated string that has been escaped of special characters * Return an allocated string that has been escaped of special characters
* and double quotes, making it safe to log in quotes. * and double quotes, making it safe to log in quotes.
......
...@@ -1375,7 +1375,6 @@ static void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) ...@@ -1375,7 +1375,6 @@ static void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos)
hlist_first_rcu(&cd->hash_table[hash])), hlist_first_rcu(&cd->hash_table[hash])),
struct cache_head, cache_list); struct cache_head, cache_list);
} }
EXPORT_SYMBOL_GPL(cache_seq_next);
void *cache_seq_start_rcu(struct seq_file *m, loff_t *pos) void *cache_seq_start_rcu(struct seq_file *m, loff_t *pos)
__acquires(RCU) __acquires(RCU)
......
...@@ -35,7 +35,7 @@ static void svc_delete_xprt(struct svc_xprt *xprt); ...@@ -35,7 +35,7 @@ static void svc_delete_xprt(struct svc_xprt *xprt);
/* apparently the "standard" is that clients close /* apparently the "standard" is that clients close
* idle connections after 5 minutes, servers after * idle connections after 5 minutes, servers after
* 6 minutes * 6 minutes
* http://www.connectathon.org/talks96/nfstcp.pdf * http://nfsv4bat.org/Documents/ConnectAThon/1996/nfstcp.pdf
*/ */
static int svc_conn_age_period = 6*60; static int svc_conn_age_period = 6*60;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment