Commit b4454fe1 authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Remove requirement for machine creds for the "renew" operation

 In RFC3530, the RENEW operation is allowed to use either

 the same principal, RPC security flavour and (if RPCSEC_GSS), the same
  mechanism and service that was used for SETCLIENTID_CONFIRM

 OR

 Any principal, RPC security flavour and service combination that
 currently has an OPEN file on the server.

 Choose the latter since that doesn't require us to keep credentials for
 the same principal for the entire duration of the mount.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 58d9714a
...@@ -213,8 +213,8 @@ extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t); ...@@ -213,8 +213,8 @@ extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
extern int nfs4_map_errors(int err); extern int nfs4_map_errors(int err);
extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short); extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
extern int nfs4_proc_setclientid_confirm(struct nfs4_client *); extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
extern int nfs4_proc_async_renew(struct nfs4_client *); extern int nfs4_proc_async_renew(struct nfs4_client *, struct rpc_cred *);
extern int nfs4_proc_renew(struct nfs4_client *); extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *);
extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state); extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
...@@ -240,6 +240,7 @@ extern struct nfs4_client *nfs4_get_client(struct in_addr *); ...@@ -240,6 +240,7 @@ extern struct nfs4_client *nfs4_get_client(struct in_addr *);
extern void nfs4_put_client(struct nfs4_client *clp); extern void nfs4_put_client(struct nfs4_client *clp);
extern int nfs4_init_client(struct nfs4_client *clp); extern int nfs4_init_client(struct nfs4_client *clp);
extern struct nfs4_client *nfs4_find_client(struct in_addr *); extern struct nfs4_client *nfs4_find_client(struct in_addr *);
struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp);
extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *); extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *); extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
......
...@@ -850,9 +850,14 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -850,9 +850,14 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
int open_flags = flags & (FMODE_READ|FMODE_WRITE); int open_flags = flags & (FMODE_READ|FMODE_WRITE);
int err; int err;
err = -ENOMEM;
if (!(sp = nfs4_get_state_owner(server, cred))) {
dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
return err;
}
err = nfs4_recover_expired_lease(server); err = nfs4_recover_expired_lease(server);
if (err != 0) if (err != 0)
return err; goto out_put_state_owner;
/* Protect against reboot recovery - NOTE ORDER! */ /* Protect against reboot recovery - NOTE ORDER! */
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
/* Protect against delegation recall */ /* Protect against delegation recall */
...@@ -862,10 +867,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -862,10 +867,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
if (delegation == NULL || (delegation->type & open_flags) != open_flags) if (delegation == NULL || (delegation->type & open_flags) != open_flags)
goto out_err; goto out_err;
err = -ENOMEM; err = -ENOMEM;
if (!(sp = nfs4_get_state_owner(server, cred))) {
dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
goto out_err;
}
state = nfs4_get_open_state(inode, sp); state = nfs4_get_open_state(inode, sp);
if (state == NULL) if (state == NULL)
goto out_err; goto out_err;
...@@ -877,13 +878,13 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -877,13 +878,13 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
goto out_ok; goto out_ok;
} else if (state->state != 0) } else if (state->state != 0)
goto out_err; goto out_put_open_state;
lock_kernel(); lock_kernel();
err = _nfs4_do_access(inode, cred, open_flags); err = _nfs4_do_access(inode, cred, open_flags);
unlock_kernel(); unlock_kernel();
if (err != 0) if (err != 0)
goto out_err; goto out_put_open_state;
set_bit(NFS_DELEGATED_STATE, &state->flags); set_bit(NFS_DELEGATED_STATE, &state->flags);
update_open_stateid(state, &delegation->stateid, open_flags); update_open_stateid(state, &delegation->stateid, open_flags);
out_ok: out_ok:
...@@ -891,17 +892,16 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -891,17 +892,16 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
up_read(&nfsi->rwsem); up_read(&nfsi->rwsem);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
*res = state; *res = state;
return 0; return 0;
out_put_open_state:
nfs4_put_open_state(state);
out_err: out_err:
if (sp != NULL) {
if (state != NULL)
nfs4_put_open_state(state);
nfs4_put_state_owner(sp);
}
up_read(&nfsi->rwsem); up_read(&nfsi->rwsem);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
if (err != -EACCES) if (err != -EACCES)
nfs_inode_return_delegation(inode); nfs_inode_return_delegation(inode);
out_put_state_owner:
nfs4_put_state_owner(sp);
return err; return err;
} }
...@@ -941,7 +941,7 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st ...@@ -941,7 +941,7 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
} }
status = nfs4_recover_expired_lease(server); status = nfs4_recover_expired_lease(server);
if (status != 0) if (status != 0)
goto out_err; goto err_put_state_owner;
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
status = -ENOMEM; status = -ENOMEM;
opendata = nfs4_opendata_alloc(dentry, sp, flags, sattr); opendata = nfs4_opendata_alloc(dentry, sp, flags, sattr);
...@@ -2518,26 +2518,24 @@ static const struct rpc_call_ops nfs4_renew_ops = { ...@@ -2518,26 +2518,24 @@ static const struct rpc_call_ops nfs4_renew_ops = {
.rpc_call_done = nfs4_renew_done, .rpc_call_done = nfs4_renew_done,
}; };
int int nfs4_proc_async_renew(struct nfs4_client *clp, struct rpc_cred *cred)
nfs4_proc_async_renew(struct nfs4_client *clp)
{ {
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
.rpc_argp = clp, .rpc_argp = clp,
.rpc_cred = clp->cl_cred, .rpc_cred = cred,
}; };
return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
&nfs4_renew_ops, (void *)jiffies); &nfs4_renew_ops, (void *)jiffies);
} }
int int nfs4_proc_renew(struct nfs4_client *clp, struct rpc_cred *cred)
nfs4_proc_renew(struct nfs4_client *clp)
{ {
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
.rpc_argp = clp, .rpc_argp = clp,
.rpc_cred = clp->cl_cred, .rpc_cred = cred,
}; };
unsigned long now = jiffies; unsigned long now = jiffies;
int status; int status;
......
...@@ -62,6 +62,7 @@ void ...@@ -62,6 +62,7 @@ void
nfs4_renew_state(void *data) nfs4_renew_state(void *data)
{ {
struct nfs4_client *clp = (struct nfs4_client *)data; struct nfs4_client *clp = (struct nfs4_client *)data;
struct rpc_cred *cred;
long lease, timeout; long lease, timeout;
unsigned long last, now; unsigned long last, now;
...@@ -77,7 +78,8 @@ nfs4_renew_state(void *data) ...@@ -77,7 +78,8 @@ nfs4_renew_state(void *data)
timeout = (2 * lease) / 3 + (long)last - (long)now; timeout = (2 * lease) / 3 + (long)last - (long)now;
/* Are we close to a lease timeout? */ /* Are we close to a lease timeout? */
if (time_after(now, last + lease/3)) { if (time_after(now, last + lease/3)) {
if (list_empty(&clp->cl_state_owners)) { cred = nfs4_get_renew_cred(clp);
if (cred == NULL) {
set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
nfs_expire_all_delegations(clp); nfs_expire_all_delegations(clp);
...@@ -85,7 +87,8 @@ nfs4_renew_state(void *data) ...@@ -85,7 +87,8 @@ nfs4_renew_state(void *data)
} }
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
/* Queue an asynchronous RENEW. */ /* Queue an asynchronous RENEW. */
nfs4_proc_async_renew(clp); nfs4_proc_async_renew(clp, cred);
put_rpccred(cred);
timeout = (2 * lease) / 3; timeout = (2 * lease) / 3;
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
} else } else
......
...@@ -232,6 +232,20 @@ nfs4_client_grab_unused(struct nfs4_client *clp, struct rpc_cred *cred) ...@@ -232,6 +232,20 @@ nfs4_client_grab_unused(struct nfs4_client *clp, struct rpc_cred *cred)
return sp; return sp;
} }
struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp)
{
struct nfs4_state_owner *sp;
struct rpc_cred *cred = NULL;
list_for_each_entry(sp, &clp->cl_state_owners, so_list) {
if (list_empty(&sp->so_states))
continue;
cred = get_rpccred(sp->so_cred);
break;
}
return cred;
}
static struct nfs4_state_owner * static struct nfs4_state_owner *
nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred) nfs4_find_state_owner(struct nfs4_client *clp, struct rpc_cred *cred)
{ {
...@@ -899,7 +913,7 @@ static int reclaimer(void *ptr) ...@@ -899,7 +913,7 @@ static int reclaimer(void *ptr)
if (list_empty(&clp->cl_superblocks)) if (list_empty(&clp->cl_superblocks))
goto out; goto out;
restart_loop: restart_loop:
status = nfs4_proc_renew(clp); status = nfs4_proc_renew(clp, clp->cl_cred);
switch (status) { switch (status) {
case 0: case 0:
case -NFS4ERR_CB_PATH_DOWN: case -NFS4ERR_CB_PATH_DOWN:
......
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