misc (mostly callback) patches for 2.6.31
Subsystems (2)
I intend to submit the following for 2.6.31, mainly concerned with moving the nfsv4 callbacks to asynchronous rpc's. Currently we create a new kthread for each callback. But there's no real reason they need a real thread, and I'm assuming an rpc task will be lighter-weight. This should also keep the callbacks from outliving the nfsd module (though that could probably be solved some other way).
Next I'd like to improve the decision about when to declare the callback channel down, and implement the callback-parameter-changing case of setclientid (and the corresponding 4.1 case). For the latter I'm currently stuck trying to decide how to do the locking necessary to prevent races between destruction of the old rpc client and lease-breaking code about to launch a new rpc task using the old rpc client.
--b.
PATCH 1/1 nfsd4: rename callback struct to cb_conn
From: J. Bruce Fields <[email protected]>
I want to use the name for a struct that actually does represent a single callback.
(Actually, I've never been sure it helps to a separate struct for the callback information. Some day maybe those fields could just be dumped into struct nfs4_client. I don't know.)
--- fs/nfsd/nfs4callback.c | 16 ++++++++-------- fs/nfsd/nfs4state.c | 22 +++++++++++----------- include/linux/nfsd/state.h | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-)
fs/nfsd/nfs4callback.c +8 -8
@@ -369,7 +369,7 @@ static int max_cb_time(void)int setup_callback_client (struct nfs4_client *clp) {struct sockaddr_in addr; -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;struct rpc_timeout timeparms = { .to_initval =max_cb_time (), .to_retries =0 ,
@@ -422,7 +422,7 @@ static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata)if (task->tk_status)warn_no_callback_path (clp, task->tk_status);else -atomic_set (&clp->cl_callback.cb_set,1 ); +atomic_set (&clp->cl_cb_conn.cb_set,1 );put_nfs4_client (clp); }
@@ -430,7 +430,7 @@ static const struct rpc_call_ops nfsd4_cb_probe_ops = { .rpc_call_done = nfsd4_cb_probe_done, }; -static struct rpc_cred *lookup_cb_cred (struct nfs4_callback *cb) +static struct rpc_cred *lookup_cb_cred (struct nfs4_cb_conn *cb) {struct auth_cred acred = { .machine_cred =1
@@ -448,7 +448,7 @@ static struct rpc_cred *lookup_cb_cred(struct nfs4_callback *cb)void do_probe_callback (struct nfs4_client *clp) { -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL ], .rpc_argp = clp,
@@ -480,7 +480,7 @@ nfsd4_probe_callback(struct nfs4_client *clp) {int status; -BUG_ON (atomic_read (&clp->cl_callback.cb_set)); +BUG_ON (atomic_read (&clp->cl_cb_conn.cb_set)); status =setup_callback_client (clp);if (status) {
@@ -501,12 +501,12 @@ void nfsd4_cb_recall(struct nfs4_delegation *dp) {struct nfs4_client *clp = dp->dl_client; -struct rpc_clnt *clnt = clp->cl_callback.cb_client; +struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;struct nfs4_cb_recall *cbr = &dp->dl_recall;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL ], .rpc_argp = cbr, - .rpc_cred = clp->cl_callback.cb_cred + .rpc_cred = clp->cl_cb_conn.cb_cred };int retries =1 ;int status =0 ;
@@ -519,7 +519,7 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)switch (status) {case -EIO :/* Network partition? */ -atomic_set (&clp->cl_callback.cb_set,0 ); +atomic_set (&clp->cl_cb_conn.cb_set,0 );case -EBADHANDLE :case -NFS4ERR_BAD_STATEID :/* Race: client probably got cb_recall
fs/nfsd/nfs4state.c +11 -11
@@ -182,7 +182,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f {struct nfs4_delegation *dp;struct nfs4_file *fp = stp->st_file; -struct nfs4_callback *cb = &stp->st_stateowner->so_client->cl_callback; +struct nfs4_cb_conn *cb = &stp->st_stateowner->so_client->cl_cb_conn;dprintk ("NFSD alloc_init_deleg\n" );if (fp->fi_had_conflict)
@@ -633,19 +633,19 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)static void shutdown_callback_client (struct nfs4_client *clp) { -struct rpc_clnt *clnt = clp->cl_callback.cb_client; +struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;if (clnt) {/* * Callback threads take a reference on the client, so there * should be no outstanding callbacks at this point. */ - clp->cl_callback.cb_client =NULL ; + clp->cl_cb_conn.cb_client =NULL ;rpc_shutdown_client (clnt); } -if (clp->cl_callback.cb_cred) { -put_rpccred (clp->cl_callback.cb_cred); - clp->cl_callback.cb_cred =NULL ; +if (clp->cl_cb_conn.cb_cred) { +put_rpccred (clp->cl_cb_conn.cb_cred); + clp->cl_cb_conn.cb_cred =NULL ; } }
@@ -719,7 +719,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir)return NULL ;memcpy (clp->cl_recdir, recdir,HEXDIR_LEN );atomic_set (&clp->cl_count,1 ); -atomic_set (&clp->cl_callback.cb_set,0 ); +atomic_set (&clp->cl_cb_conn.cb_set,0 );INIT_LIST_HEAD (&clp->cl_idhash);INIT_LIST_HEAD (&clp->cl_strhash);INIT_LIST_HEAD (&clp->cl_openowners);
@@ -971,7 +971,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsignestatic void gen_callback (struct nfs4_client *clp,struct nfsd4_setclientid *se) { -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;/* Currently, we only support tcp for the callback channel */ if ((se->se_callback_netid_len !=3 ) ||memcmp ((char *)se->se_callback_netid_val,"tcp" ,3 ))
@@ -1691,7 +1691,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,else {/* XXX: We just turn off callbacks until we can handle * change request correctly. */ -atomic_set (&conf->cl_callback.cb_set,0 ); +atomic_set (&conf->cl_cb_conn.cb_set,0 );expire_client (unconf); status = nfs_ok;
@@ -2425,7 +2425,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta {struct nfs4_delegation *dp;struct nfs4_stateowner *sop = stp->st_stateowner; -struct nfs4_callback *cb = &sop->so_client->cl_callback; +struct nfs4_cb_conn *cb = &sop->so_client->cl_cb_conn;struct file_lock fl, *flp = &fl;int status, flag =0 ;
@@ -2617,7 +2617,7 @@ nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,renew_client (clp); status = nfserr_cb_path_down;if (!list_empty (&clp->cl_delegations) - && !atomic_read (&clp->cl_callback.cb_set)) + && !atomic_read (&clp->cl_cb_conn.cb_set)) goto out; status = nfs_ok; out:
include/linux/nfsd/state.h +2 -2
@@ -88,7 +88,7 @@ struct nfs4_delegation {#define dl_fh dl_recall.cbr_fh/* client delegation callback info */ -struct nfs4_callback { +struct nfs4_cb_conn {/* SETCLIENTID info */ u32 cb_addr;unsigned short cb_port;
@@ -186,7 +186,7 @@ struct nfs4_client {struct svc_cred cl_cred;/* setclientid principal */ clientid_t cl_clientid;/* generated by server */ nfs4_verifier cl_confirm;/* generated by server */ -struct nfs4_callback cl_callback;/* callback info */ +struct nfs4_cb_conn cl_cb_conn;/* callback info */ atomic_t cl_count;/* ref count */ u32 cl_firststate;/* recovery dir creation */
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd: quiet compile warning
From: J. Bruce Fields <[email protected]>
Stephen Rothwell said:
"Today's linux-next build (powerpc ppc64_defconfig) produced this new warning:
fs/nfsd/nfs4state.c: In function 'EXPIRED_STATEID':fs/nfsd/nfs4state.c:2757: warning: comparison of distinct pointer types lacks a cast
Caused by commit 78155ed75f470710f2aecb3e75e3d97107ba8374 ("nfsd4:
distinguish expired from stale stateids")."
--- fs/nfsd/nfs4state.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfsd/nfs4state.c +1 -1
@@ -2754,7 +2754,7 @@ EXPIRED_STATEID(stateid_t *stateid) {if (time_before ((unsigned long )boot_time, ((unsigned long )stateid->si_boot)) && -time_before ((stateid->si_boot + lease_time),get_seconds ())) { +time_before ((unsigned long )(stateid->si_boot + lease_time),get_seconds ())) {dprintk ("NFSD: expired stateid (%08x/%08x/%08x/%08x)!\n" , stateid->si_boot, stateid->si_stateownerid, stateid->si_fileid, stateid->si_generation);
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: setclientid_confirm callback-change fixes
From: J. Bruce Fields <[email protected]>
This setclientid_confirm case should allow the client to change callbacks, but it currently has a dummy implementation that just turns off callbacks completely. That dummy implementation isn't completely correct either, though:
- There's no need to remove any client recovery directory in this case.
- New clientid confirm verifiers should be generated (and returned) in setclientid; there's no need to generate a new one here.
--- fs/nfsd/nfs4state.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +0 -2
@@ -1688,8 +1688,6 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,/* XXX: We just turn off callbacks until we can handle * change request correctly. */ atomic_set (&conf->cl_callback.cb_set,0 ); -gen_confirm (conf); -nfsd4_remove_clid_dir (unconf);expire_client (unconf); status = nfs_ok;
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: set shorter timeout
From: J. Bruce Fields <[email protected]>
We tried to do something overly complicated with the callback rpc timeouts here. And they're wrong--the result is that by the time a single callback times out, it's already too late to tell the client (using the cb_path_down return to RENEW) that the callback is down.
Use a much shorter, simpler timeout.
--- fs/nfsd/nfs4callback.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
fs/nfsd/nfs4callback.c +7 -4
@@ -358,6 +358,11 @@ static struct rpc_program cb_program = { .pipe_dir_name = "/nfsd4_cb", }; +static int max_cb_time (void ) +{ +return max (NFSD_LEASE_TIME /10 , (time_t )1 ) *HZ ; +} +/* Reference counting, callback cleanup, etc., all look racy as heck. * And why is cb_set an atomic? */
@@ -366,10 +371,8 @@ static struct rpc_clnt *setup_callback_client(struct nfs4_client *clp)struct sockaddr_in addr;struct nfs4_callback *cb = &clp->cl_callback;struct rpc_timeout timeparms = { - .to_initval = (NFSD_LEASE_TIME /4 ) *HZ , - .to_retries =5 , - .to_maxval = (NFSD_LEASE_TIME /2 ) *HZ , - .to_exponential =1 , + .to_initval =max_cb_time (), + .to_retries =0 , };struct rpc_create_args args = { .protocol =IPPROTO_TCP ,
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: set cb_client inside setup_callback_client
From: J. Bruce Fields <[email protected]>
This is just a minor code simplification.
--- fs/nfsd/nfs4callback.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)
fs/nfsd/nfs4callback.c +12 -14
@@ -366,7 +366,7 @@ static int max_cb_time(void)/* Reference counting, callback cleanup, etc., all look racy as heck. * And why is cb_set an atomic? */ -static struct rpc_clnt *setup_callback_client (struct nfs4_client *clp) +int setup_callback_client (struct nfs4_client *clp) {struct sockaddr_in addr;struct nfs4_callback *cb = &clp->cl_callback;
@@ -389,7 +389,7 @@ static struct rpc_clnt *setup_callback_client(struct nfs4_client *clp)struct rpc_clnt *client;if (!clp->cl_principal && (clp->cl_flavor >=RPC_AUTH_GSS_KRB5 )) -return ERR_PTR (-EINVAL ); +return -EINVAL ;/* Initialize address */ memset (&addr,0 ,sizeof (addr));
@@ -399,10 +399,13 @@ static struct rpc_clnt *setup_callback_client(struct nfs4_client *clp)/* Create RPC client */ client =rpc_create (&args); -if (IS_ERR (client)) +if (IS_ERR (client)) {dprintk ("NFSD: couldn't create callback client: %ld\n" ,PTR_ERR (client)); -return client; +return PTR_ERR (client); + } + cb->cb_client = client; +return 0 ; }
@@ -414,28 +417,23 @@ static int do_probe_callback(void *data) .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], .rpc_argp = clp, }; -struct rpc_clnt *client;int status; - client =setup_callback_client (clp); -if (IS_ERR (client)) { - status =PTR_ERR (client); -dprintk ("NFSD: couldn't create callback client: %d\n" , - status); + status =setup_callback_client (clp); +if (status) goto out_err; - } - status =rpc_call_sync (client, &msg,RPC_TASK_SOFT ); + status =rpc_call_sync (cb->cb_client, &msg,RPC_TASK_SOFT );if (status) goto out_release_client; - cb->cb_client = client;atomic_set (&cb->cb_set,1 );put_nfs4_client (clp);return 0 ; out_release_client: -rpc_shutdown_client (client); +rpc_shutdown_client (cb->cb_client); + cb->cb_client =NULL ; out_err:dprintk ("NFSD: warning: no callback path to client %.*s: error %d\n" , (int )clp->cl_name.len, clp->cl_name.data, status);
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: create rpc callback client from server thread
From: J. Bruce Fields <[email protected]>
The code is a little simpler, and it should be easier to avoid races, if we just do all rpc client creation/destruction from nfsd or laundromat threads and do only the rpc calls themselves asynchronously. The rpc creation doesn't involve any significant waiting (it doesn't call the client, for example), so there's no reason not to do this.
Also don't bother destroying the client on failure of the rpc null probe. We may want to retry the probe later anyway.
--- fs/nfsd/nfs4callback.c | 31 ++++++++++++++++--------------- 1 files changed, 16 insertions(+), 15 deletions(-)
fs/nfsd/nfs4callback.c +16 -15
@@ -409,6 +409,12 @@ int setup_callback_client(struct nfs4_client *clp) } +static void warn_no_callback_path (struct nfs4_client *clp,int reason) +{ +dprintk ("NFSD: warning: no callback path to client %.*s: error %d\n" , + (int )clp->cl_name.len, clp->cl_name.data, reason); +} +static int do_probe_callback (void *data) {struct nfs4_client *clp = data;
@@ -419,24 +425,12 @@ static int do_probe_callback(void *data) };int status; - status =setup_callback_client (clp); -if (status) - goto out_err; - status =rpc_call_sync (cb->cb_client, &msg,RPC_TASK_SOFT ); -if (status) - goto out_release_client; +warn_no_callback_path (clp, status); +else +atomic_set (&cb->cb_set,1 ); -atomic_set (&cb->cb_set,1 ); -put_nfs4_client (clp); -return 0 ; -out_release_client: -rpc_shutdown_client (cb->cb_client); - cb->cb_client =NULL ; -out_err: -dprintk ("NFSD: warning: no callback path to client %.*s: error %d\n" , - (int )clp->cl_name.len, clp->cl_name.data, status);put_nfs4_client (clp);return 0 ; }
@@ -448,9 +442,16 @@ void nfsd4_probe_callback(struct nfs4_client *clp) {struct task_struct *t; +int status;BUG_ON (atomic_read (&clp->cl_callback.cb_set)); + status =setup_callback_client (clp); +if (status) { +warn_no_callback_path (clp, status); +return ; + } +/* the task holds a reference to the nfs4_client struct */ atomic_inc (&clp->cl_count);
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: lookup up callback cred only once
From: J. Bruce Fields <[email protected]>
Lookup the callback cred once and then use it for all subsequent callbacks.
--- fs/nfsd/nfs4callback.c | 26 ++++++++++++++++++++++++++ fs/nfsd/nfs4state.c | 4 ++++ include/linux/nfsd/state.h | 1 + 3 files changed, 31 insertions(+), 0 deletions(-)
fs/nfsd/nfs4callback.c +26 -0
@@ -415,6 +415,22 @@ static void warn_no_callback_path(struct nfs4_client *clp, int reason) (int)clp->cl_name.len, clp->cl_name.data, reason); } +static struct rpc_cred *lookup_cb_cred (struct nfs4_callback *cb) +{ +struct auth_cred acred = { + .machine_cred =1 + }; + +/* +* Note in the gss case this doesn't actually have to wait for a +* gss upcall (or any calls to the client); this just creates a +* non-uptodate cred which the rpc state machine will fill in with +* a refresh_upcall later. +*/ +return rpcauth_lookup_credcache (cb->cb_client->cl_auth, &acred, +RPCAUTH_LOOKUP_NEW ); +} +static int do_probe_callback (void *data) {struct nfs4_client *clp = data;
@@ -423,9 +439,18 @@ static int do_probe_callback(void *data) .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], .rpc_argp = clp, }; +struct rpc_cred *cred;int status; + cred =lookup_cb_cred (cb); +if (IS_ERR (cred)) { + status =PTR_ERR (cred); + goto out; + } + cb->cb_cred = cred; + msg.rpc_cred = cb->cb_cred; status =rpc_call_sync (cb->cb_client, &msg,RPC_TASK_SOFT ); +out:if (status)warn_no_callback_path (clp, status);else
@@ -475,6 +500,7 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL ], .rpc_argp = cbr, + .rpc_cred = clp->cl_callback.cb_cred };int retries =1 ;int status =0 ;
fs/nfsd/nfs4state.c +4 -0
@@ -643,6 +643,10 @@ shutdown_callback_client(struct nfs4_client *clp) clp->cl_callback.cb_client =NULL ;rpc_shutdown_client (clnt); } +if (clp->cl_callback.cb_cred) { +put_rpccred (clp->cl_callback.cb_cred); + clp->cl_callback.cb_cred =NULL ; + } } static inline void
include/linux/nfsd/state.h +1 -0
@@ -97,6 +97,7 @@ struct nfs4_callback {/* RPC client info */ atomic_t cb_set;/* successful CB_NULL call */ struct rpc_clnt * cb_client; +struct rpc_cred * cb_cred; };/* Maximum number of slots per session. 128 is useful for long haul TCP */
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: replace callback thread by asynchronous rpc
From: J. Bruce Fields <[email protected]>
We don't really need a synchronous rpc, and moving to an asynchronous rpc allows us to do without this extra kthread.
--- fs/nfsd/nfs4callback.c | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-)
fs/nfsd/nfs4callback.c +22 -16
@@ -415,6 +415,21 @@ static void warn_no_callback_path(struct nfs4_client *clp, int reason) (int)clp->cl_name.len, clp->cl_name.data, reason); } +static void nfsd4_cb_probe_done (struct rpc_task *task,void *calldata) +{ +struct nfs4_client *clp = calldata; + +if (task->tk_status) +warn_no_callback_path (clp, task->tk_status); +else +atomic_set (&clp->cl_callback.cb_set,1 ); +put_nfs4_client (clp); +} + +static const struct rpc_call_ops nfsd4_cb_probe_ops = { + .rpc_call_done = nfsd4_cb_probe_done, +}; +static struct rpc_cred *lookup_cb_cred (struct nfs4_callback *cb) {struct auth_cred acred = {
@@ -431,9 +446,8 @@ static struct rpc_cred *lookup_cb_cred(struct nfs4_callback *cb) RPCAUTH_LOOKUP_NEW); } -static int do_probe_callback (void *data) +void do_probe_callback (struct nfs4_client *clp) { -struct nfs4_client *clp = data;struct nfs4_callback *cb = &clp->cl_callback;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL ],
@@ -449,15 +463,13 @@ static int do_probe_callback(void *data) } cb->cb_cred = cred; msg.rpc_cred = cb->cb_cred; - status =rpc_call_sync (cb->cb_client, &msg,RPC_TASK_SOFT ); + status =rpc_call_async (cb->cb_client, &msg,RPC_TASK_SOFT , + &nfsd4_cb_probe_ops, (void *)clp); out: -if (status) +if (status) {warn_no_callback_path (clp, status); -else -atomic_set (&cb->cb_set,1 ); - -put_nfs4_client (clp); -return 0 ; +put_nfs4_client (clp); + } }/*
@@ -466,7 +478,6 @@ out:void nfsd4_probe_callback (struct nfs4_client *clp) { -struct task_struct *t;int status;BUG_ON (atomic_read (&clp->cl_callback.cb_set));
@@ -480,12 +491,7 @@ nfsd4_probe_callback(struct nfs4_client *clp)/* the task holds a reference to the nfs4_client struct */ atomic_inc (&clp->cl_count); - t =kthread_run (do_probe_callback, clp,"nfs4_cb_probe" ); - -if (IS_ERR (t)) -atomic_dec (&clp->cl_count); - -return ; +do_probe_callback (clp); }/*
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: rename callback struct to cb_conn
From: J. Bruce Fields <[email protected]>
I want to use the name for a struct that actually does represent a single callback.
(Actually, I've never been sure it helps to a separate struct for the callback information. Some day maybe those fields could just be dumped into struct nfs4_client. I don't know.)
--- fs/nfsd/nfs4callback.c | 16 ++++++++-------- fs/nfsd/nfs4state.c | 22 +++++++++++----------- include/linux/nfsd/state.h | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-)
fs/nfsd/nfs4callback.c +8 -8
@@ -369,7 +369,7 @@ static int max_cb_time(void)int setup_callback_client (struct nfs4_client *clp) {struct sockaddr_in addr; -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;struct rpc_timeout timeparms = { .to_initval =max_cb_time (), .to_retries =0 ,
@@ -422,7 +422,7 @@ static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata)if (task->tk_status)warn_no_callback_path (clp, task->tk_status);else -atomic_set (&clp->cl_callback.cb_set,1 ); +atomic_set (&clp->cl_cb_conn.cb_set,1 );put_nfs4_client (clp); }
@@ -430,7 +430,7 @@ static const struct rpc_call_ops nfsd4_cb_probe_ops = { .rpc_call_done = nfsd4_cb_probe_done, }; -static struct rpc_cred *lookup_cb_cred (struct nfs4_callback *cb) +static struct rpc_cred *lookup_cb_cred (struct nfs4_cb_conn *cb) {struct auth_cred acred = { .machine_cred =1
@@ -448,7 +448,7 @@ static struct rpc_cred *lookup_cb_cred(struct nfs4_callback *cb)void do_probe_callback (struct nfs4_client *clp) { -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL ], .rpc_argp = clp,
@@ -480,7 +480,7 @@ nfsd4_probe_callback(struct nfs4_client *clp) {int status; -BUG_ON (atomic_read (&clp->cl_callback.cb_set)); +BUG_ON (atomic_read (&clp->cl_cb_conn.cb_set)); status =setup_callback_client (clp);if (status) {
@@ -501,12 +501,12 @@ void nfsd4_cb_recall(struct nfs4_delegation *dp) {struct nfs4_client *clp = dp->dl_client; -struct rpc_clnt *clnt = clp->cl_callback.cb_client; +struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;struct nfs4_cb_recall *cbr = &dp->dl_recall;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL ], .rpc_argp = cbr, - .rpc_cred = clp->cl_callback.cb_cred + .rpc_cred = clp->cl_cb_conn.cb_cred };int retries =1 ;int status =0 ;
@@ -519,7 +519,7 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)switch (status) {case -EIO :/* Network partition? */ -atomic_set (&clp->cl_callback.cb_set,0 ); +atomic_set (&clp->cl_cb_conn.cb_set,0 );case -EBADHANDLE :case -NFS4ERR_BAD_STATEID :/* Race: client probably got cb_recall
fs/nfsd/nfs4state.c +11 -11
@@ -182,7 +182,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f {struct nfs4_delegation *dp;struct nfs4_file *fp = stp->st_file; -struct nfs4_callback *cb = &stp->st_stateowner->so_client->cl_callback; +struct nfs4_cb_conn *cb = &stp->st_stateowner->so_client->cl_cb_conn;dprintk ("NFSD alloc_init_deleg\n" );if (fp->fi_had_conflict)
@@ -633,19 +633,19 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)static void shutdown_callback_client (struct nfs4_client *clp) { -struct rpc_clnt *clnt = clp->cl_callback.cb_client; +struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;if (clnt) {/* * Callback threads take a reference on the client, so there * should be no outstanding callbacks at this point. */ - clp->cl_callback.cb_client =NULL ; + clp->cl_cb_conn.cb_client =NULL ;rpc_shutdown_client (clnt); } -if (clp->cl_callback.cb_cred) { -put_rpccred (clp->cl_callback.cb_cred); - clp->cl_callback.cb_cred =NULL ; +if (clp->cl_cb_conn.cb_cred) { +put_rpccred (clp->cl_cb_conn.cb_cred); + clp->cl_cb_conn.cb_cred =NULL ; } }
@@ -719,7 +719,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir)return NULL ;memcpy (clp->cl_recdir, recdir,HEXDIR_LEN );atomic_set (&clp->cl_count,1 ); -atomic_set (&clp->cl_callback.cb_set,0 ); +atomic_set (&clp->cl_cb_conn.cb_set,0 );INIT_LIST_HEAD (&clp->cl_idhash);INIT_LIST_HEAD (&clp->cl_strhash);INIT_LIST_HEAD (&clp->cl_openowners);
@@ -971,7 +971,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsignestatic void gen_callback (struct nfs4_client *clp,struct nfsd4_setclientid *se) { -struct nfs4_callback *cb = &clp->cl_callback; +struct nfs4_cb_conn *cb = &clp->cl_cb_conn;/* Currently, we only support tcp for the callback channel */ if ((se->se_callback_netid_len !=3 ) ||memcmp ((char *)se->se_callback_netid_val,"tcp" ,3 ))
@@ -1691,7 +1691,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,else {/* XXX: We just turn off callbacks until we can handle * change request correctly. */ -atomic_set (&conf->cl_callback.cb_set,0 ); +atomic_set (&conf->cl_cb_conn.cb_set,0 );expire_client (unconf); status = nfs_ok;
@@ -2425,7 +2425,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta {struct nfs4_delegation *dp;struct nfs4_stateowner *sop = stp->st_stateowner; -struct nfs4_callback *cb = &sop->so_client->cl_callback; +struct nfs4_cb_conn *cb = &sop->so_client->cl_cb_conn;struct file_lock fl, *flp = &fl;int status, flag =0 ;
@@ -2617,7 +2617,7 @@ nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,renew_client (clp); status = nfserr_cb_path_down;if (!list_empty (&clp->cl_delegations) - && !atomic_read (&clp->cl_callback.cb_set)) + && !atomic_read (&clp->cl_cb_conn.cb_set)) goto out; status = nfs_ok; out:
include/linux/nfsd/state.h +2 -2
@@ -88,7 +88,7 @@ struct nfs4_delegation {#define dl_fh dl_recall.cbr_fh/* client delegation callback info */ -struct nfs4_callback { +struct nfs4_cb_conn {/* SETCLIENTID info */ u32 cb_addr;unsigned short cb_port;
@@ -186,7 +186,7 @@ struct nfs4_client {struct svc_cred cl_cred;/* setclientid principal */ clientid_t cl_clientid;/* generated by server */ nfs4_verifier cl_confirm;/* generated by server */ -struct nfs4_callback cl_callback;/* callback info */ +struct nfs4_cb_conn cl_cb_conn;/* callback info */ atomic_t cl_count;/* ref count */ u32 cl_firststate;/* recovery dir creation */
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: eliminate struct nfs4_cb_recall
From: J. Bruce Fields <[email protected]>
The nfs4_cb_recall struct is used only in nfs4_delegation, so its pointer to the containing delegation is unnecessary--we could just use container_of().
But there's no real reason to have this a separate struct at all--just move these fields to nfs4_delegation.
--- fs/nfsd/nfs4callback.c | 24 +++++++++++------------- fs/nfsd/nfs4state.c | 5 ++--- include/linux/nfsd/state.h | 18 +++++------------- 3 files changed, 18 insertions(+), 29 deletions(-)
fs/nfsd/nfs4callback.c +11 -13
@@ -215,18 +215,18 @@ encode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr) }static int -encode_cb_recall (struct xdr_stream *xdr,struct nfs4_cb_recall *cb_rec) +encode_cb_recall (struct xdr_stream *xdr,struct nfs4_delegation *dp) {__be32 *p; -int len = cb_rec->cbr_fh.fh_size; +int len = dp->dl_fh.fh_size; -RESERVE_SPACE (12 +sizeof (cb_rec->cbr_stateid) + len); +RESERVE_SPACE (12 +sizeof (dp->dl_stateid) + len);WRITE32 (OP_CB_RECALL ); -WRITE32 (cb_rec->cbr_stateid.si_generation); -WRITEMEM (&cb_rec->cbr_stateid.si_opaque,sizeof (stateid_opaque_t)); -WRITE32 (cb_rec->cbr_trunc); +WRITE32 (dp->dl_stateid.si_generation); +WRITEMEM (&dp->dl_stateid.si_opaque,sizeof (stateid_opaque_t)); +WRITE32 (dp->dl_trunc);WRITE32 (len); -WRITEMEM (&cb_rec->cbr_fh.fh_base, len); +WRITEMEM (&dp->dl_fh.fh_base, len);return 0 ; }
@@ -241,11 +241,11 @@ nfs4_xdr_enc_cb_null(struct rpc_rqst *req, __be32 *p) }static int -nfs4_xdr_enc_cb_recall (struct rpc_rqst *req,__be32 *p,struct nfs4_cb_recall *args) +nfs4_xdr_enc_cb_recall (struct rpc_rqst *req,__be32 *p,struct nfs4_delegation *args) {struct xdr_stream xdr;struct nfs4_cb_compound_hdr hdr = { - .ident = args->cbr_ident, + .ident = args->dl_ident, .nops =1 , };
@@ -502,17 +502,15 @@ nfsd4_cb_recall(struct nfs4_delegation *dp) {struct nfs4_client *clp = dp->dl_client;struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client; -struct nfs4_cb_recall *cbr = &dp->dl_recall;struct rpc_message msg = { .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL ], - .rpc_argp = cbr, + .rpc_argp = dp, .rpc_cred = clp->cl_cb_conn.cb_cred };int retries =1 ;int status =0 ; - cbr->cbr_trunc =0 ;/* XXX need to implement truncate optimization */ - cbr->cbr_dp = dp; + dp->dl_trunc =0 ;/* XXX need to implement truncate optimization */ status =rpc_call_sync (clnt, &msg,RPC_TASK_SOFT );while (retries--) {
fs/nfsd/nfs4state.c +2 -3
@@ -203,9 +203,8 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fget_file (stp->st_vfs_file); dp->dl_vfs_file = stp->st_vfs_file; dp->dl_type = type; - dp->dl_recall.cbr_dp =NULL ; - dp->dl_recall.cbr_ident = cb->cb_ident; - dp->dl_recall.cbr_trunc =0 ; + dp->dl_ident = cb->cb_ident; + dp->dl_trunc =0 ; dp->dl_stateid.si_boot =get_seconds (); dp->dl_stateid.si_stateownerid = current_delegid++; dp->dl_stateid.si_fileid =0 ;
include/linux/nfsd/state.h +5 -13
@@ -61,15 +61,6 @@ typedef struct {#define si_stateownerid si_opaque.so_stateownerid#define si_fileid si_opaque.so_fileid - -struct nfs4_cb_recall { -u32 cbr_ident; -int cbr_trunc; -stateid_t cbr_stateid; -struct knfsd_fh cbr_fh; -struct nfs4_delegation *cbr_dp; -}; -struct nfs4_delegation {struct list_head dl_perfile;struct list_head dl_perclnt;
@@ -81,12 +72,13 @@ struct nfs4_delegation {struct file *dl_vfs_file;u32 dl_type;time_t dl_time; -struct nfs4_cb_recall dl_recall; +/* For recall: */ +u32 dl_ident; +int dl_trunc; +stateid_t dl_stateid; +struct knfsd_fh dl_fh; }; -#define dl_stateid dl_recall.cbr_stateid -#define dl_fh dl_recall.cbr_fh -/* client delegation callback info */ struct nfs4_cb_conn {/* SETCLIENTID info */
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: remove unused dl_trunc
From: J. Bruce Fields <[email protected]>
There's no point in keeping this field around--it's always zero.
(Background: the protocol allows you to tell the client that the file is about to be truncated, as an optimization to save the client from writing back dirty pages that will just be discarded. We don't implement this hint. If we do some day, adding this field back in will be the least of the work involved.)
--- fs/nfsd/nfs4callback.c | 4 +--- fs/nfsd/nfs4state.c | 1 - include/linux/nfsd/state.h | 1 - 3 files changed, 1 insertions(+), 5 deletions(-)
fs/nfsd/nfs4callback.c +1 -3
@@ -224,7 +224,7 @@ encode_cb_recall(struct xdr_stream *xdr, struct nfs4_delegation *dp)WRITE32 (OP_CB_RECALL );WRITE32 (dp->dl_stateid.si_generation);WRITEMEM (&dp->dl_stateid.si_opaque,sizeof (stateid_opaque_t)); -WRITE32 (dp->dl_trunc); +WRITE32 (0 );/* truncate optimization not implemented */ WRITE32 (len);WRITEMEM (&dp->dl_fh.fh_base, len);return 0 ;
@@ -510,8 +510,6 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)int retries =1 ;int status =0 ; - dp->dl_trunc =0 ;/* XXX need to implement truncate optimization */ - status =rpc_call_sync (clnt, &msg,RPC_TASK_SOFT );while (retries--) {switch (status) {
fs/nfsd/nfs4state.c +0 -1
@@ -204,7 +204,6 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f dp->dl_vfs_file = stp->st_vfs_file; dp->dl_type = type; dp->dl_ident = cb->cb_ident; - dp->dl_trunc =0 ; dp->dl_stateid.si_boot =get_seconds (); dp->dl_stateid.si_stateownerid = current_delegid++; dp->dl_stateid.si_fileid =0 ;
include/linux/nfsd/state.h +0 -1
@@ -74,7 +74,6 @@ struct nfs4_delegation {time_t dl_time;/* For recall: */ u32 dl_ident; -int dl_trunc;stateid_t dl_stateid;struct knfsd_fh dl_fh; };
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: track recall retries in nfs4_delegation
From: J. Bruce Fields <[email protected]>
Move this out of a local variable into the nfs4_delegation object in preparation for making this an async rpc call (at which point we'll need any state like this in a common object that's preserved across function calls).
--- fs/nfsd/nfs4callback.c | 4 ++-- include/linux/nfsd/state.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
fs/nfsd/nfs4callback.c +2 -2
@@ -507,11 +507,11 @@ nfsd4_cb_recall(struct nfs4_delegation *dp) .rpc_argp = dp, .rpc_cred = clp->cl_cb_conn.cb_cred }; -int retries =1 ;int status =0 ; + dp->dl_retries =1 ; status =rpc_call_sync (clnt, &msg,RPC_TASK_SOFT ); -while (retries--) { +while (dp->dl_retries--) {switch (status) {case -EIO :/* Network partition? */
include/linux/nfsd/state.h +1 -0
@@ -76,6 +76,7 @@ struct nfs4_delegation {u32 dl_ident;stateid_t dl_stateid;struct knfsd_fh dl_fh; +int dl_retries; };/* client delegation callback info */
Signature · 1 line
1.6.0.4
PATCH 1/1 nfsd4: make recall callback an asynchronous rpc
From: J. Bruce Fields <[email protected]>
As with the probe, this removes the need for another kthread.
--- fs/nfsd/nfs4callback.c | 74 +++++++++++++++++++++++++++++++---------------- fs/nfsd/nfs4state.c | 28 ++---------------- 2 files changed, 52 insertions(+), 50 deletions(-)
fs/nfsd/nfs4callback.c +49 -25
@@ -494,6 +494,49 @@ nfsd4_probe_callback(struct nfs4_client *clp)do_probe_callback (clp); } +static void nfsd4_cb_recall_done (struct rpc_task *task,void *calldata) +{ +struct nfs4_delegation *dp = calldata; +struct nfs4_client *clp = dp->dl_client; + +switch (task->tk_status) { +case -EIO : +/* Network partition? */ +atomic_set (&clp->cl_cb_conn.cb_set,0 ); +warn_no_callback_path (clp, task->tk_status); +case -EBADHANDLE : +case -NFS4ERR_BAD_STATEID : +/* Race: client probably got cb_recall +* before open reply granting delegation */ +break ; +default : +/* success, or error we can't handle */ +return ; + } +if (dp->dl_retries--) { +rpc_delay (task,2 *HZ ); + task->tk_status =0 ; +rpc_restart_call (task); + }else { +atomic_set (&clp->cl_cb_conn.cb_set,0 ); +warn_no_callback_path (clp, task->tk_status); + } +} + +static void nfsd4_cb_recall_release (void *calldata) +{ +struct nfs4_delegation *dp = calldata; +struct nfs4_client *clp = dp->dl_client; + +nfs4_put_delegation (dp); +put_nfs4_client (clp); +} + +static const struct rpc_call_ops nfsd4_cb_recall_ops = { + .rpc_call_done = nfsd4_cb_recall_done, + .rpc_release = nfsd4_cb_recall_release, +}; +/* * called with dp->dl_count inc'ed. */
@@ -507,32 +550,13 @@ nfsd4_cb_recall(struct nfs4_delegation *dp) .rpc_argp = dp, .rpc_cred = clp->cl_cb_conn.cb_cred }; -int status =0 ; +int status; dp->dl_retries =1 ; - status =rpc_call_sync (clnt, &msg,RPC_TASK_SOFT ); -while (dp->dl_retries--) { -switch (status) { -case -EIO : -/* Network partition? */ -atomic_set (&clp->cl_cb_conn.cb_set,0 ); -case -EBADHANDLE : -case -NFS4ERR_BAD_STATEID : -/* Race: client probably got cb_recall -* before open reply granting delegation */ -break ; -default : - goto out_put_cred; - } -ssleep (2 ); - status =rpc_call_sync (clnt, &msg,RPC_TASK_SOFT ); + status =rpc_call_async (clnt, &msg,RPC_TASK_SOFT , + &nfsd4_cb_recall_ops, dp); +if (status) { +put_nfs4_client (clp); +nfs4_put_delegation (dp); } -out_put_cred: -/* -* Success or failure, now we're either waiting for lease expiration -* or deleg_return. -*/ -put_nfs4_client (clp); -nfs4_put_delegation (dp); -return ; }
fs/nfsd/nfs4state.c +3 -25
@@ -2060,19 +2060,6 @@ nfs4_file_downgrade(struct file *filp, unsigned int share_access) }/* -* Recall a delegation -*/ -static int -do_recall (void *__dp) -{ -struct nfs4_delegation *dp = __dp; - - dp->dl_file->fi_had_conflict = true; -nfsd4_cb_recall (dp); -return 0 ; -} - -/* * Spawn a thread to perform a recall on the delegation represented * by the lease (file_lock) *
@@ -2083,8 +2070,7 @@ do_recall(void *__dp)static void nfsd_break_deleg_cb (struct file_lock *fl) { -struct nfs4_delegation *dp= (struct nfs4_delegation *)fl->fl_owner; -struct task_struct *t; +struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;dprintk ("NFSD nfsd_break_deleg_cb: dp %p fl %p\n" ,dp,fl);if (!dp)
@@ -2112,16 +2098,8 @@ void nfsd_break_deleg_cb(struct file_lock *fl)*/ fl->fl_break_time =0 ; - t =kthread_run (do_recall, dp,"%s" ,"nfs4_cb_recall" ); -if (IS_ERR (t)) { -struct nfs4_client *clp = dp->dl_client; - -printk (KERN_INFO "NFSD: Callback thread failed for " -"for client (clientid %08x/%08x)\n" , - clp->cl_clientid.cl_boot, clp->cl_clientid.cl_id); -put_nfs4_client (dp->dl_client); -nfs4_put_delegation (dp); - } + dp->dl_file->fi_had_conflict = true; +nfsd4_cb_recall (dp); }/*
Signature · 1 line
1.6.0.4