Skip to content

Commit d343fce

Browse files
neilbrownLinus Torvalds
authored andcommitted
[PATCH] knfsd: Allow lockd to drop replies as appropriate
It is possible for the ->fopen callback from lockd into nfsd to find that an answer cannot be given straight away (an upcall is needed) and so the request has to be 'dropped', to be retried later. That error status is not currently propagated back. So: Change nlm_fopen to return nlm error codes (rather than a private protocol) and define a new nlm_drop_reply code. Cause nlm_drop_reply to cause the rpc request to get rpc_drop_reply when this error comes back. Cause svc_process to drop a request which returns a status of rpc_drop_reply. [akpm@osdl.org: fix warning storm] Cc: Marc Eshel <eshel@almaden.ibm.com> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 4481d10 commit d343fce

9 files changed

Lines changed: 41 additions & 26 deletions

File tree

‎fs/lockd/svc4proc.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
9696

9797
/* Obtain client and file */
9898
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
99-
return rpc_success;
99+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
100100

101101
/* Now check for conflicting locks */
102102
resp->status = nlmsvc_testlock(file, &argp->lock, &resp->lock);
@@ -126,7 +126,7 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
126126

127127
/* Obtain client and file */
128128
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
129-
return rpc_success;
129+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
130130

131131
#if 0
132132
/* If supplied state doesn't match current state, we assume it's
@@ -169,7 +169,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
169169

170170
/* Obtain client and file */
171171
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
172-
return rpc_success;
172+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
173173

174174
/* Try to cancel request. */
175175
resp->status = nlmsvc_cancel_blocked(file, &argp->lock);
@@ -202,7 +202,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
202202

203203
/* Obtain client and file */
204204
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
205-
return rpc_success;
205+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
206206

207207
/* Now try to remove the lock */
208208
resp->status = nlmsvc_unlock(file, &argp->lock);
@@ -339,7 +339,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
339339

340340
/* Obtain client and file */
341341
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
342-
return rpc_success;
342+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
343343

344344
/* Now try to create the share */
345345
resp->status = nlmsvc_share_file(host, file, argp);
@@ -372,7 +372,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
372372

373373
/* Obtain client and file */
374374
if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
375-
return rpc_success;
375+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
376376

377377
/* Now try to lock the file */
378378
resp->status = nlmsvc_unshare_file(host, file, argp);

‎fs/lockd/svcproc.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
5959
struct nlm_host *host = NULL;
6060
struct nlm_file *file = NULL;
6161
struct nlm_lock *lock = &argp->lock;
62-
u32 error;
62+
u32 error = 0;
6363

6464
/* nfsd callbacks must have been installed for this procedure */
6565
if (!nlmsvc_ops)
@@ -88,6 +88,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
8888
no_locks:
8989
if (host)
9090
nlm_release_host(host);
91+
if (error)
92+
return error;
9193
return nlm_lck_denied_nolocks;
9294
}
9395

@@ -122,7 +124,7 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
122124

123125
/* Obtain client and file */
124126
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
125-
return rpc_success;
127+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
126128

127129
/* Now check for conflicting locks */
128130
resp->status = cast_status(nlmsvc_testlock(file, &argp->lock, &resp->lock));
@@ -153,7 +155,7 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
153155

154156
/* Obtain client and file */
155157
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
156-
return rpc_success;
158+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
157159

158160
#if 0
159161
/* If supplied state doesn't match current state, we assume it's
@@ -196,7 +198,7 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
196198

197199
/* Obtain client and file */
198200
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
199-
return rpc_success;
201+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
200202

201203
/* Try to cancel request. */
202204
resp->status = cast_status(nlmsvc_cancel_blocked(file, &argp->lock));
@@ -229,7 +231,7 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
229231

230232
/* Obtain client and file */
231233
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
232-
return rpc_success;
234+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
233235

234236
/* Now try to remove the lock */
235237
resp->status = cast_status(nlmsvc_unlock(file, &argp->lock));
@@ -368,7 +370,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
368370

369371
/* Obtain client and file */
370372
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
371-
return rpc_success;
373+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
372374

373375
/* Now try to create the share */
374376
resp->status = cast_status(nlmsvc_share_file(host, file, argp));
@@ -401,7 +403,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
401403

402404
/* Obtain client and file */
403405
if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
404-
return rpc_success;
406+
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
405407

406408
/* Now try to unshare the file */
407409
resp->status = cast_status(nlmsvc_unshare_file(host, file, argp));

‎fs/lockd/svcsubs.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,
135135

136136
out_free:
137137
kfree(file);
138-
#ifdef CONFIG_LOCKD_V4
139-
if (nfserr == 1)
140-
nfserr = nlm4_stale_fh;
141-
else
142-
#endif
143-
nfserr = nlm_lck_denied;
144138
goto out_unlock;
145139
}
146140

‎fs/nfsd/lockd.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
3939
fh_put(&fh);
4040
rqstp->rq_client = NULL;
4141
exp_readunlock();
42-
/* nlm and nfsd don't share error codes.
43-
* we invent: 0 = no error
44-
* 1 = stale file handle
45-
* 2 = other error
42+
/* We return nlm error codes as nlm doesn't know
43+
* about nfsd, but nfsd does know about nlm..
4644
*/
4745
switch (nfserr) {
4846
case nfs_ok:
4947
return 0;
48+
case nfserr_dropit:
49+
return nlm_drop_reply;
50+
#ifdef CONFIG_LOCKD_V4
5051
case nfserr_stale:
51-
return 1;
52+
return nlm4_stale_fh;
53+
#endif
5254
default:
53-
return 2;
55+
return nlm_lck_denied;
5456
}
5557
}
5658

‎include/linux/lockd/bind.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#define LINUX_LOCKD_BIND_H
1111

1212
#include <linux/lockd/nlm.h>
13+
/* need xdr-encoded error codes too, so... */
14+
#include <linux/lockd/xdr.h>
15+
#ifdef CONFIG_LOCKD_V4
16+
#include <linux/lockd/xdr4.h>
17+
#endif
1318

1419
/* Dummy declarations */
1520
struct svc_rqst;

‎include/linux/lockd/xdr.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/nfs.h>
1414
#include <linux/sunrpc/xdr.h>
1515

16+
struct svc_rqst;
17+
1618
#define NLM_MAXCOOKIELEN 32
1719
#define NLM_MAXSTRLEN 1024
1820

@@ -22,6 +24,8 @@
2224
#define nlm_lck_blocked __constant_htonl(NLM_LCK_BLOCKED)
2325
#define nlm_lck_denied_grace_period __constant_htonl(NLM_LCK_DENIED_GRACE_PERIOD)
2426

27+
#define nlm_drop_reply __constant_htonl(30000)
28+
2529
/* Lock info passed via NLM */
2630
struct nlm_lock {
2731
char * caller;

‎include/linux/sunrpc/msg_prot.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ enum rpc_accept_stat {
5656
RPC_PROG_MISMATCH = 2,
5757
RPC_PROC_UNAVAIL = 3,
5858
RPC_GARBAGE_ARGS = 4,
59-
RPC_SYSTEM_ERR = 5
59+
RPC_SYSTEM_ERR = 5,
60+
/* internal use only */
61+
RPC_DROP_REPLY = 60000,
6062
};
6163

6264
enum rpc_reject_stat {

‎include/linux/sunrpc/xdr.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct xdr_buf {
7474
#define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
7575
#define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
7676
#define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
77+
#define rpc_drop_reply __constant_htonl(RPC_DROP_REPLY)
7778

7879
#define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
7980
#define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)

‎net/sunrpc/svc.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,11 @@ svc_process(struct svc_rqst *rqstp)
828828
*statp = procp->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);
829829

830830
/* Encode reply */
831+
if (*statp == rpc_drop_reply) {
832+
if (procp->pc_release)
833+
procp->pc_release(rqstp, NULL, rqstp->rq_resp);
834+
goto dropit;
835+
}
831836
if (*statp == rpc_success && (xdr = procp->pc_encode)
832837
&& !xdr(rqstp, resv->iov_base+resv->iov_len, rqstp->rq_resp)) {
833838
dprintk("svc: failed to encode reply\n");

0 commit comments

Comments
 (0)