Skip to content

Commit 1459ad5

Browse files
neilbrownchucklever
authored andcommitted
nfsd: Move error code mapping to per-version proc code.
There is code scattered around nfsd which chooses an error status based on the particular version of nfs being used. It is cleaner to have the version specific choices in version specific code. With this patch common code returns the most specific error code possible and the version specific code maps that if necessary. Both v2 (nfsproc.c) and v3 (nfs3proc.c) now have a "map_status()" function which is called to map the resp->status before each non-trivial nfsd_proc_* or nfsd3_proc_* function returns. NFS4ERR_SYMLINK and NFS4ERR_WRONG_TYPE introduce extra complications and are left for a later patch. Signed-off-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent ef7f6c4 commit 1459ad5

File tree

5 files changed

+78
-18
lines changed

5 files changed

+78
-18
lines changed

fs/nfsd/export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
11211121
return 0;
11221122

11231123
denied:
1124-
return rqstp->rq_vers < 4 ? nfserr_acces : nfserr_wrongsec;
1124+
return nfserr_wrongsec;
11251125
}
11261126

11271127
/*

fs/nfsd/nfs3proc.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ static int nfs3_ftypes[] = {
2828
S_IFIFO, /* NF3FIFO */
2929
};
3030

31+
static __be32 nfsd3_map_status(__be32 status)
32+
{
33+
switch (status) {
34+
case nfs_ok:
35+
break;
36+
case nfserr_nofilehandle:
37+
status = nfserr_badhandle;
38+
break;
39+
case nfserr_wrongsec:
40+
case nfserr_file_open:
41+
status = nfserr_acces;
42+
break;
43+
}
44+
return status;
45+
}
46+
3147
/*
3248
* NULL call.
3349
*/
@@ -57,6 +73,7 @@ nfsd3_proc_getattr(struct svc_rqst *rqstp)
5773

5874
resp->status = fh_getattr(&resp->fh, &resp->stat);
5975
out:
76+
resp->status = nfsd3_map_status(resp->status);
6077
return rpc_success;
6178
}
6279

@@ -80,6 +97,7 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)
8097
if (argp->check_guard)
8198
guardtime = &argp->guardtime;
8299
resp->status = nfsd_setattr(rqstp, &resp->fh, &attrs, guardtime);
100+
resp->status = nfsd3_map_status(resp->status);
83101
return rpc_success;
84102
}
85103

@@ -103,6 +121,7 @@ nfsd3_proc_lookup(struct svc_rqst *rqstp)
103121
resp->status = nfsd_lookup(rqstp, &resp->dirfh,
104122
argp->name, argp->len,
105123
&resp->fh);
124+
resp->status = nfsd3_map_status(resp->status);
106125
return rpc_success;
107126
}
108127

@@ -122,6 +141,7 @@ nfsd3_proc_access(struct svc_rqst *rqstp)
122141
fh_copy(&resp->fh, &argp->fh);
123142
resp->access = argp->access;
124143
resp->status = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
144+
resp->status = nfsd3_map_status(resp->status);
125145
return rpc_success;
126146
}
127147

@@ -142,6 +162,7 @@ nfsd3_proc_readlink(struct svc_rqst *rqstp)
142162
resp->pages = rqstp->rq_next_page++;
143163
resp->status = nfsd_readlink(rqstp, &resp->fh,
144164
page_address(*resp->pages), &resp->len);
165+
resp->status = nfsd3_map_status(resp->status);
145166
return rpc_success;
146167
}
147168

@@ -179,6 +200,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp)
179200
fh_copy(&resp->fh, &argp->fh);
180201
resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
181202
&resp->count, &resp->eof);
203+
resp->status = nfsd3_map_status(resp->status);
182204
return rpc_success;
183205
}
184206

@@ -212,6 +234,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
212234
rqstp->rq_vec, nvecs, &cnt,
213235
resp->committed, resp->verf);
214236
resp->count = cnt;
237+
resp->status = nfsd3_map_status(resp->status);
215238
return rpc_success;
216239
}
217240

@@ -359,6 +382,7 @@ nfsd3_proc_create(struct svc_rqst *rqstp)
359382
newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
360383

361384
resp->status = nfsd3_create_file(rqstp, dirfhp, newfhp, argp);
385+
resp->status = nfsd3_map_status(resp->status);
362386
return rpc_success;
363387
}
364388

@@ -384,6 +408,7 @@ nfsd3_proc_mkdir(struct svc_rqst *rqstp)
384408
fh_init(&resp->fh, NFS3_FHSIZE);
385409
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
386410
&attrs, S_IFDIR, 0, &resp->fh);
411+
resp->status = nfsd3_map_status(resp->status);
387412
return rpc_success;
388413
}
389414

@@ -424,6 +449,7 @@ nfsd3_proc_symlink(struct svc_rqst *rqstp)
424449
argp->flen, argp->tname, &attrs, &resp->fh);
425450
kfree(argp->tname);
426451
out:
452+
resp->status = nfsd3_map_status(resp->status);
427453
return rpc_success;
428454
}
429455

@@ -465,6 +491,7 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
465491
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
466492
&attrs, type, rdev, &resp->fh);
467493
out:
494+
resp->status = nfsd3_map_status(resp->status);
468495
return rpc_success;
469496
}
470497

@@ -486,6 +513,7 @@ nfsd3_proc_remove(struct svc_rqst *rqstp)
486513
fh_copy(&resp->fh, &argp->fh);
487514
resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
488515
argp->name, argp->len);
516+
resp->status = nfsd3_map_status(resp->status);
489517
return rpc_success;
490518
}
491519

@@ -506,6 +534,7 @@ nfsd3_proc_rmdir(struct svc_rqst *rqstp)
506534
fh_copy(&resp->fh, &argp->fh);
507535
resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
508536
argp->name, argp->len);
537+
resp->status = nfsd3_map_status(resp->status);
509538
return rpc_success;
510539
}
511540

@@ -528,6 +557,7 @@ nfsd3_proc_rename(struct svc_rqst *rqstp)
528557
fh_copy(&resp->tfh, &argp->tfh);
529558
resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
530559
&resp->tfh, argp->tname, argp->tlen);
560+
resp->status = nfsd3_map_status(resp->status);
531561
return rpc_success;
532562
}
533563

@@ -548,6 +578,7 @@ nfsd3_proc_link(struct svc_rqst *rqstp)
548578
fh_copy(&resp->tfh, &argp->tfh);
549579
resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
550580
&resp->fh);
581+
resp->status = nfsd3_map_status(resp->status);
551582
return rpc_success;
552583
}
553584

@@ -600,6 +631,7 @@ nfsd3_proc_readdir(struct svc_rqst *rqstp)
600631
/* Recycle only pages that were part of the reply */
601632
rqstp->rq_next_page = resp->xdr.page_ptr + 1;
602633

634+
resp->status = nfsd3_map_status(resp->status);
603635
return rpc_success;
604636
}
605637

@@ -644,6 +676,7 @@ nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
644676
rqstp->rq_next_page = resp->xdr.page_ptr + 1;
645677

646678
out:
679+
resp->status = nfsd3_map_status(resp->status);
647680
return rpc_success;
648681
}
649682

@@ -661,6 +694,7 @@ nfsd3_proc_fsstat(struct svc_rqst *rqstp)
661694

662695
resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
663696
fh_put(&argp->fh);
697+
resp->status = nfsd3_map_status(resp->status);
664698
return rpc_success;
665699
}
666700

@@ -704,6 +738,7 @@ nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
704738
}
705739

706740
fh_put(&argp->fh);
741+
resp->status = nfsd3_map_status(resp->status);
707742
return rpc_success;
708743
}
709744

@@ -746,6 +781,7 @@ nfsd3_proc_pathconf(struct svc_rqst *rqstp)
746781
}
747782

748783
fh_put(&argp->fh);
784+
resp->status = nfsd3_map_status(resp->status);
749785
return rpc_success;
750786
}
751787

@@ -773,6 +809,7 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)
773809
argp->count, resp->verf);
774810
nfsd_file_put(nf);
775811
out:
812+
resp->status = nfsd3_map_status(resp->status);
776813
return rpc_success;
777814
}
778815

fs/nfsd/nfsfh.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
154154
int len;
155155
__be32 error;
156156

157-
error = nfserr_stale;
158-
if (rqstp->rq_vers > 2)
159-
error = nfserr_badhandle;
160-
if (rqstp->rq_vers == 4 && fh->fh_size == 0)
157+
error = nfserr_badhandle;
158+
if (fh->fh_size == 0)
161159
return nfserr_nofilehandle;
162160

163161
if (fh->fh_version != 1)
@@ -231,9 +229,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
231229
/*
232230
* Look up the dentry using the NFS file handle.
233231
*/
234-
error = nfserr_stale;
235-
if (rqstp->rq_vers > 2)
236-
error = nfserr_badhandle;
232+
error = nfserr_badhandle;
237233

238234
fileid_type = fh->fh_fileid_type;
239235

fs/nfsd/nfsproc.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@
1313

1414
#define NFSDDBG_FACILITY NFSDDBG_PROC
1515

16+
static __be32 nfsd_map_status(__be32 status)
17+
{
18+
switch (status) {
19+
case nfs_ok:
20+
break;
21+
case nfserr_nofilehandle:
22+
case nfserr_badhandle:
23+
status = nfserr_stale;
24+
break;
25+
case nfserr_wrongsec:
26+
case nfserr_xdev:
27+
case nfserr_file_open:
28+
status = nfserr_acces;
29+
break;
30+
}
31+
return status;
32+
}
33+
1634
static __be32
1735
nfsd_proc_null(struct svc_rqst *rqstp)
1836
{
@@ -38,6 +56,7 @@ nfsd_proc_getattr(struct svc_rqst *rqstp)
3856
goto out;
3957
resp->status = fh_getattr(&resp->fh, &resp->stat);
4058
out:
59+
resp->status = nfsd_map_status(resp->status);
4160
return rpc_success;
4261
}
4362

@@ -109,6 +128,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp)
109128

110129
resp->status = fh_getattr(&resp->fh, &resp->stat);
111130
out:
131+
resp->status = nfsd_map_status(resp->status);
112132
return rpc_success;
113133
}
114134

@@ -143,6 +163,7 @@ nfsd_proc_lookup(struct svc_rqst *rqstp)
143163

144164
resp->status = fh_getattr(&resp->fh, &resp->stat);
145165
out:
166+
resp->status = nfsd_map_status(resp->status);
146167
return rpc_success;
147168
}
148169

@@ -164,6 +185,7 @@ nfsd_proc_readlink(struct svc_rqst *rqstp)
164185
page_address(resp->page), &resp->len);
165186

166187
fh_put(&argp->fh);
188+
resp->status = nfsd_map_status(resp->status);
167189
return rpc_success;
168190
}
169191

@@ -200,6 +222,7 @@ nfsd_proc_read(struct svc_rqst *rqstp)
200222
resp->status = fh_getattr(&resp->fh, &resp->stat);
201223
else if (resp->status == nfserr_jukebox)
202224
set_bit(RQ_DROPME, &rqstp->rq_flags);
225+
resp->status = nfsd_map_status(resp->status);
203226
return rpc_success;
204227
}
205228

@@ -235,6 +258,7 @@ nfsd_proc_write(struct svc_rqst *rqstp)
235258
resp->status = fh_getattr(&resp->fh, &resp->stat);
236259
else if (resp->status == nfserr_jukebox)
237260
set_bit(RQ_DROPME, &rqstp->rq_flags);
261+
resp->status = nfsd_map_status(resp->status);
238262
return rpc_success;
239263
}
240264

@@ -404,6 +428,7 @@ nfsd_proc_create(struct svc_rqst *rqstp)
404428
goto out;
405429
resp->status = fh_getattr(&resp->fh, &resp->stat);
406430
out:
431+
resp->status = nfsd_map_status(resp->status);
407432
return rpc_success;
408433
}
409434

@@ -420,6 +445,7 @@ nfsd_proc_remove(struct svc_rqst *rqstp)
420445
resp->status = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR,
421446
argp->name, argp->len);
422447
fh_put(&argp->fh);
448+
resp->status = nfsd_map_status(resp->status);
423449
return rpc_success;
424450
}
425451

@@ -438,6 +464,7 @@ nfsd_proc_rename(struct svc_rqst *rqstp)
438464
&argp->tfh, argp->tname, argp->tlen);
439465
fh_put(&argp->ffh);
440466
fh_put(&argp->tfh);
467+
resp->status = nfsd_map_status(resp->status);
441468
return rpc_success;
442469
}
443470

@@ -458,6 +485,7 @@ nfsd_proc_link(struct svc_rqst *rqstp)
458485
&argp->ffh);
459486
fh_put(&argp->ffh);
460487
fh_put(&argp->tfh);
488+
resp->status = nfsd_map_status(resp->status);
461489
return rpc_success;
462490
}
463491

@@ -496,6 +524,7 @@ nfsd_proc_symlink(struct svc_rqst *rqstp)
496524
fh_put(&argp->ffh);
497525
fh_put(&newfh);
498526
out:
527+
resp->status = nfsd_map_status(resp->status);
499528
return rpc_success;
500529
}
501530

@@ -529,6 +558,7 @@ nfsd_proc_mkdir(struct svc_rqst *rqstp)
529558

530559
resp->status = fh_getattr(&resp->fh, &resp->stat);
531560
out:
561+
resp->status = nfsd_map_status(resp->status);
532562
return rpc_success;
533563
}
534564

@@ -546,6 +576,7 @@ nfsd_proc_rmdir(struct svc_rqst *rqstp)
546576
resp->status = nfsd_unlink(rqstp, &argp->fh, S_IFDIR,
547577
argp->name, argp->len);
548578
fh_put(&argp->fh);
579+
resp->status = nfsd_map_status(resp->status);
549580
return rpc_success;
550581
}
551582

@@ -591,6 +622,7 @@ nfsd_proc_readdir(struct svc_rqst *rqstp)
591622
nfssvc_encode_nfscookie(resp, offset);
592623

593624
fh_put(&argp->fh);
625+
resp->status = nfsd_map_status(resp->status);
594626
return rpc_success;
595627
}
596628

@@ -608,6 +640,7 @@ nfsd_proc_statfs(struct svc_rqst *rqstp)
608640
resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
609641
NFSD_MAY_BYPASS_GSS_ON_ROOT);
610642
fh_put(&argp->fh);
643+
resp->status = nfsd_map_status(resp->status);
611644
return rpc_success;
612645
}
613646

0 commit comments

Comments
 (0)