nfs3proc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*
  2. * Process version 3 NFS requests.
  3. *
  4. * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
  5. */
  6. #include <linux/fs.h>
  7. #include <linux/ext2_fs.h>
  8. #include <linux/magic.h>
  9. #include "cache.h"
  10. #include "xdr3.h"
  11. #include "vfs.h"
  12. #define NFSDDBG_FACILITY NFSDDBG_PROC
  13. #define RETURN_STATUS(st) { resp->status = (st); return (st); }
  14. static int nfs3_ftypes[] = {
  15. 0, /* NF3NON */
  16. S_IFREG, /* NF3REG */
  17. S_IFDIR, /* NF3DIR */
  18. S_IFBLK, /* NF3BLK */
  19. S_IFCHR, /* NF3CHR */
  20. S_IFLNK, /* NF3LNK */
  21. S_IFSOCK, /* NF3SOCK */
  22. S_IFIFO, /* NF3FIFO */
  23. };
  24. /*
  25. * NULL call.
  26. */
  27. static __be32
  28. nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  29. {
  30. return nfs_ok;
  31. }
  32. /*
  33. * Get a file's attributes
  34. */
  35. static __be32
  36. nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp,
  37. struct nfsd3_attrstat *resp)
  38. {
  39. __be32 nfserr;
  40. dprintk("nfsd: GETATTR(3) %s\n",
  41. SVCFH_fmt(&argp->fh));
  42. fh_copy(&resp->fh, &argp->fh);
  43. nfserr = fh_verify(rqstp, &resp->fh, 0,
  44. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  45. if (nfserr)
  46. RETURN_STATUS(nfserr);
  47. nfserr = fh_getattr(&resp->fh, &resp->stat);
  48. RETURN_STATUS(nfserr);
  49. }
  50. /*
  51. * Set a file's attributes
  52. */
  53. static __be32
  54. nfsd3_proc_setattr(struct svc_rqst *rqstp, struct nfsd3_sattrargs *argp,
  55. struct nfsd3_attrstat *resp)
  56. {
  57. __be32 nfserr;
  58. dprintk("nfsd: SETATTR(3) %s\n",
  59. SVCFH_fmt(&argp->fh));
  60. fh_copy(&resp->fh, &argp->fh);
  61. nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
  62. argp->check_guard, argp->guardtime);
  63. RETURN_STATUS(nfserr);
  64. }
  65. /*
  66. * Look up a path name component
  67. */
  68. static __be32
  69. nfsd3_proc_lookup(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
  70. struct nfsd3_diropres *resp)
  71. {
  72. __be32 nfserr;
  73. dprintk("nfsd: LOOKUP(3) %s %.*s\n",
  74. SVCFH_fmt(&argp->fh),
  75. argp->len,
  76. argp->name);
  77. fh_copy(&resp->dirfh, &argp->fh);
  78. fh_init(&resp->fh, NFS3_FHSIZE);
  79. nfserr = nfsd_lookup(rqstp, &resp->dirfh,
  80. argp->name,
  81. argp->len,
  82. &resp->fh);
  83. RETURN_STATUS(nfserr);
  84. }
  85. /*
  86. * Check file access
  87. */
  88. static __be32
  89. nfsd3_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
  90. struct nfsd3_accessres *resp)
  91. {
  92. __be32 nfserr;
  93. dprintk("nfsd: ACCESS(3) %s 0x%x\n",
  94. SVCFH_fmt(&argp->fh),
  95. argp->access);
  96. fh_copy(&resp->fh, &argp->fh);
  97. resp->access = argp->access;
  98. nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
  99. RETURN_STATUS(nfserr);
  100. }
  101. /*
  102. * Read a symlink.
  103. */
  104. static __be32
  105. nfsd3_proc_readlink(struct svc_rqst *rqstp, struct nfsd3_readlinkargs *argp,
  106. struct nfsd3_readlinkres *resp)
  107. {
  108. __be32 nfserr;
  109. dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
  110. /* Read the symlink. */
  111. fh_copy(&resp->fh, &argp->fh);
  112. resp->len = NFS3_MAXPATHLEN;
  113. nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
  114. RETURN_STATUS(nfserr);
  115. }
  116. /*
  117. * Read a portion of a file.
  118. */
  119. static __be32
  120. nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
  121. struct nfsd3_readres *resp)
  122. {
  123. __be32 nfserr;
  124. u32 max_blocksize = svc_max_payload(rqstp);
  125. unsigned long cnt = min(argp->count, max_blocksize);
  126. dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
  127. SVCFH_fmt(&argp->fh),
  128. (unsigned long) argp->count,
  129. (unsigned long long) argp->offset);
  130. /* Obtain buffer pointer for payload.
  131. * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
  132. * + 1 (xdr opaque byte count) = 26
  133. */
  134. resp->count = cnt;
  135. svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
  136. fh_copy(&resp->fh, &argp->fh);
  137. nfserr = nfsd_read(rqstp, &resp->fh,
  138. argp->offset,
  139. rqstp->rq_vec, argp->vlen,
  140. &resp->count);
  141. if (nfserr == 0) {
  142. struct inode *inode = d_inode(resp->fh.fh_dentry);
  143. resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset,
  144. inode->i_size);
  145. }
  146. RETURN_STATUS(nfserr);
  147. }
  148. /*
  149. * Write data to a file
  150. */
  151. static __be32
  152. nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp,
  153. struct nfsd3_writeres *resp)
  154. {
  155. __be32 nfserr;
  156. unsigned long cnt = argp->len;
  157. dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
  158. SVCFH_fmt(&argp->fh),
  159. argp->len,
  160. (unsigned long long) argp->offset,
  161. argp->stable? " stable" : "");
  162. fh_copy(&resp->fh, &argp->fh);
  163. resp->committed = argp->stable;
  164. nfserr = nfsd_write(rqstp, &resp->fh, NULL,
  165. argp->offset,
  166. rqstp->rq_vec, argp->vlen,
  167. &cnt,
  168. &resp->committed);
  169. resp->count = cnt;
  170. RETURN_STATUS(nfserr);
  171. }
  172. /*
  173. * With NFSv3, CREATE processing is a lot easier than with NFSv2.
  174. * At least in theory; we'll see how it fares in practice when the
  175. * first reports about SunOS compatibility problems start to pour in...
  176. */
  177. static __be32
  178. nfsd3_proc_create(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
  179. struct nfsd3_diropres *resp)
  180. {
  181. svc_fh *dirfhp, *newfhp = NULL;
  182. struct iattr *attr;
  183. __be32 nfserr;
  184. dprintk("nfsd: CREATE(3) %s %.*s\n",
  185. SVCFH_fmt(&argp->fh),
  186. argp->len,
  187. argp->name);
  188. dirfhp = fh_copy(&resp->dirfh, &argp->fh);
  189. newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
  190. attr = &argp->attrs;
  191. /* Unfudge the mode bits */
  192. attr->ia_mode &= ~S_IFMT;
  193. if (!(attr->ia_valid & ATTR_MODE)) {
  194. attr->ia_valid |= ATTR_MODE;
  195. attr->ia_mode = S_IFREG;
  196. } else {
  197. attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
  198. }
  199. /* Now create the file and set attributes */
  200. nfserr = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
  201. attr, newfhp,
  202. argp->createmode, (u32 *)argp->verf, NULL, NULL);
  203. RETURN_STATUS(nfserr);
  204. }
  205. /*
  206. * Make directory. This operation is not idempotent.
  207. */
  208. static __be32
  209. nfsd3_proc_mkdir(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
  210. struct nfsd3_diropres *resp)
  211. {
  212. __be32 nfserr;
  213. dprintk("nfsd: MKDIR(3) %s %.*s\n",
  214. SVCFH_fmt(&argp->fh),
  215. argp->len,
  216. argp->name);
  217. argp->attrs.ia_valid &= ~ATTR_SIZE;
  218. fh_copy(&resp->dirfh, &argp->fh);
  219. fh_init(&resp->fh, NFS3_FHSIZE);
  220. nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
  221. &argp->attrs, S_IFDIR, 0, &resp->fh);
  222. fh_unlock(&resp->dirfh);
  223. RETURN_STATUS(nfserr);
  224. }
  225. static __be32
  226. nfsd3_proc_symlink(struct svc_rqst *rqstp, struct nfsd3_symlinkargs *argp,
  227. struct nfsd3_diropres *resp)
  228. {
  229. __be32 nfserr;
  230. dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
  231. SVCFH_fmt(&argp->ffh),
  232. argp->flen, argp->fname,
  233. argp->tlen, argp->tname);
  234. fh_copy(&resp->dirfh, &argp->ffh);
  235. fh_init(&resp->fh, NFS3_FHSIZE);
  236. nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
  237. argp->tname, &resp->fh);
  238. RETURN_STATUS(nfserr);
  239. }
  240. /*
  241. * Make socket/fifo/device.
  242. */
  243. static __be32
  244. nfsd3_proc_mknod(struct svc_rqst *rqstp, struct nfsd3_mknodargs *argp,
  245. struct nfsd3_diropres *resp)
  246. {
  247. __be32 nfserr;
  248. int type;
  249. dev_t rdev = 0;
  250. dprintk("nfsd: MKNOD(3) %s %.*s\n",
  251. SVCFH_fmt(&argp->fh),
  252. argp->len,
  253. argp->name);
  254. fh_copy(&resp->dirfh, &argp->fh);
  255. fh_init(&resp->fh, NFS3_FHSIZE);
  256. if (argp->ftype == 0 || argp->ftype >= NF3BAD)
  257. RETURN_STATUS(nfserr_inval);
  258. if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
  259. rdev = MKDEV(argp->major, argp->minor);
  260. if (MAJOR(rdev) != argp->major ||
  261. MINOR(rdev) != argp->minor)
  262. RETURN_STATUS(nfserr_inval);
  263. } else
  264. if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
  265. RETURN_STATUS(nfserr_inval);
  266. type = nfs3_ftypes[argp->ftype];
  267. nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
  268. &argp->attrs, type, rdev, &resp->fh);
  269. fh_unlock(&resp->dirfh);
  270. RETURN_STATUS(nfserr);
  271. }
  272. /*
  273. * Remove file/fifo/socket etc.
  274. */
  275. static __be32
  276. nfsd3_proc_remove(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
  277. struct nfsd3_attrstat *resp)
  278. {
  279. __be32 nfserr;
  280. dprintk("nfsd: REMOVE(3) %s %.*s\n",
  281. SVCFH_fmt(&argp->fh),
  282. argp->len,
  283. argp->name);
  284. /* Unlink. -S_IFDIR means file must not be a directory */
  285. fh_copy(&resp->fh, &argp->fh);
  286. nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
  287. fh_unlock(&resp->fh);
  288. RETURN_STATUS(nfserr);
  289. }
  290. /*
  291. * Remove a directory
  292. */
  293. static __be32
  294. nfsd3_proc_rmdir(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
  295. struct nfsd3_attrstat *resp)
  296. {
  297. __be32 nfserr;
  298. dprintk("nfsd: RMDIR(3) %s %.*s\n",
  299. SVCFH_fmt(&argp->fh),
  300. argp->len,
  301. argp->name);
  302. fh_copy(&resp->fh, &argp->fh);
  303. nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
  304. fh_unlock(&resp->fh);
  305. RETURN_STATUS(nfserr);
  306. }
  307. static __be32
  308. nfsd3_proc_rename(struct svc_rqst *rqstp, struct nfsd3_renameargs *argp,
  309. struct nfsd3_renameres *resp)
  310. {
  311. __be32 nfserr;
  312. dprintk("nfsd: RENAME(3) %s %.*s ->\n",
  313. SVCFH_fmt(&argp->ffh),
  314. argp->flen,
  315. argp->fname);
  316. dprintk("nfsd: -> %s %.*s\n",
  317. SVCFH_fmt(&argp->tfh),
  318. argp->tlen,
  319. argp->tname);
  320. fh_copy(&resp->ffh, &argp->ffh);
  321. fh_copy(&resp->tfh, &argp->tfh);
  322. nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
  323. &resp->tfh, argp->tname, argp->tlen);
  324. RETURN_STATUS(nfserr);
  325. }
  326. static __be32
  327. nfsd3_proc_link(struct svc_rqst *rqstp, struct nfsd3_linkargs *argp,
  328. struct nfsd3_linkres *resp)
  329. {
  330. __be32 nfserr;
  331. dprintk("nfsd: LINK(3) %s ->\n",
  332. SVCFH_fmt(&argp->ffh));
  333. dprintk("nfsd: -> %s %.*s\n",
  334. SVCFH_fmt(&argp->tfh),
  335. argp->tlen,
  336. argp->tname);
  337. fh_copy(&resp->fh, &argp->ffh);
  338. fh_copy(&resp->tfh, &argp->tfh);
  339. nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
  340. &resp->fh);
  341. RETURN_STATUS(nfserr);
  342. }
  343. /*
  344. * Read a portion of a directory.
  345. */
  346. static __be32
  347. nfsd3_proc_readdir(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
  348. struct nfsd3_readdirres *resp)
  349. {
  350. __be32 nfserr;
  351. int count;
  352. dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
  353. SVCFH_fmt(&argp->fh),
  354. argp->count, (u32) argp->cookie);
  355. /* Make sure we've room for the NULL ptr & eof flag, and shrink to
  356. * client read size */
  357. count = (argp->count >> 2) - 2;
  358. /* Read directory and encode entries on the fly */
  359. fh_copy(&resp->fh, &argp->fh);
  360. resp->buflen = count;
  361. resp->common.err = nfs_ok;
  362. resp->buffer = argp->buffer;
  363. resp->rqstp = rqstp;
  364. nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie,
  365. &resp->common, nfs3svc_encode_entry);
  366. memcpy(resp->verf, argp->verf, 8);
  367. resp->count = resp->buffer - argp->buffer;
  368. if (resp->offset)
  369. xdr_encode_hyper(resp->offset, argp->cookie);
  370. RETURN_STATUS(nfserr);
  371. }
  372. /*
  373. * Read a portion of a directory, including file handles and attrs.
  374. * For now, we choose to ignore the dircount parameter.
  375. */
  376. static __be32
  377. nfsd3_proc_readdirplus(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
  378. struct nfsd3_readdirres *resp)
  379. {
  380. __be32 nfserr;
  381. int count = 0;
  382. loff_t offset;
  383. struct page **p;
  384. caddr_t page_addr = NULL;
  385. dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
  386. SVCFH_fmt(&argp->fh),
  387. argp->count, (u32) argp->cookie);
  388. /* Convert byte count to number of words (i.e. >> 2),
  389. * and reserve room for the NULL ptr & eof flag (-2 words) */
  390. resp->count = (argp->count >> 2) - 2;
  391. /* Read directory and encode entries on the fly */
  392. fh_copy(&resp->fh, &argp->fh);
  393. resp->common.err = nfs_ok;
  394. resp->buffer = argp->buffer;
  395. resp->buflen = resp->count;
  396. resp->rqstp = rqstp;
  397. offset = argp->cookie;
  398. nfserr = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
  399. if (nfserr)
  400. RETURN_STATUS(nfserr);
  401. if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS)
  402. RETURN_STATUS(nfserr_notsupp);
  403. nfserr = nfsd_readdir(rqstp, &resp->fh,
  404. &offset,
  405. &resp->common,
  406. nfs3svc_encode_entry_plus);
  407. memcpy(resp->verf, argp->verf, 8);
  408. for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
  409. page_addr = page_address(*p);
  410. if (((caddr_t)resp->buffer >= page_addr) &&
  411. ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
  412. count += (caddr_t)resp->buffer - page_addr;
  413. break;
  414. }
  415. count += PAGE_SIZE;
  416. }
  417. resp->count = count >> 2;
  418. if (resp->offset) {
  419. if (unlikely(resp->offset1)) {
  420. /* we ended up with offset on a page boundary */
  421. *resp->offset = htonl(offset >> 32);
  422. *resp->offset1 = htonl(offset & 0xffffffff);
  423. resp->offset1 = NULL;
  424. } else {
  425. xdr_encode_hyper(resp->offset, offset);
  426. }
  427. }
  428. RETURN_STATUS(nfserr);
  429. }
  430. /*
  431. * Get file system stats
  432. */
  433. static __be32
  434. nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  435. struct nfsd3_fsstatres *resp)
  436. {
  437. __be32 nfserr;
  438. dprintk("nfsd: FSSTAT(3) %s\n",
  439. SVCFH_fmt(&argp->fh));
  440. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
  441. fh_put(&argp->fh);
  442. RETURN_STATUS(nfserr);
  443. }
  444. /*
  445. * Get file system info
  446. */
  447. static __be32
  448. nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  449. struct nfsd3_fsinfores *resp)
  450. {
  451. __be32 nfserr;
  452. u32 max_blocksize = svc_max_payload(rqstp);
  453. dprintk("nfsd: FSINFO(3) %s\n",
  454. SVCFH_fmt(&argp->fh));
  455. resp->f_rtmax = max_blocksize;
  456. resp->f_rtpref = max_blocksize;
  457. resp->f_rtmult = PAGE_SIZE;
  458. resp->f_wtmax = max_blocksize;
  459. resp->f_wtpref = max_blocksize;
  460. resp->f_wtmult = PAGE_SIZE;
  461. resp->f_dtpref = PAGE_SIZE;
  462. resp->f_maxfilesize = ~(u32) 0;
  463. resp->f_properties = NFS3_FSF_DEFAULT;
  464. nfserr = fh_verify(rqstp, &argp->fh, 0,
  465. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  466. /* Check special features of the file system. May request
  467. * different read/write sizes for file systems known to have
  468. * problems with large blocks */
  469. if (nfserr == 0) {
  470. struct super_block *sb = argp->fh.fh_dentry->d_sb;
  471. /* Note that we don't care for remote fs's here */
  472. if (sb->s_magic == MSDOS_SUPER_MAGIC) {
  473. resp->f_properties = NFS3_FSF_BILLYBOY;
  474. }
  475. resp->f_maxfilesize = sb->s_maxbytes;
  476. }
  477. fh_put(&argp->fh);
  478. RETURN_STATUS(nfserr);
  479. }
  480. /*
  481. * Get pathconf info for the specified file
  482. */
  483. static __be32
  484. nfsd3_proc_pathconf(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
  485. struct nfsd3_pathconfres *resp)
  486. {
  487. __be32 nfserr;
  488. dprintk("nfsd: PATHCONF(3) %s\n",
  489. SVCFH_fmt(&argp->fh));
  490. /* Set default pathconf */
  491. resp->p_link_max = 255; /* at least */
  492. resp->p_name_max = 255; /* at least */
  493. resp->p_no_trunc = 0;
  494. resp->p_chown_restricted = 1;
  495. resp->p_case_insensitive = 0;
  496. resp->p_case_preserving = 1;
  497. nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
  498. if (nfserr == 0) {
  499. struct super_block *sb = argp->fh.fh_dentry->d_sb;
  500. /* Note that we don't care for remote fs's here */
  501. switch (sb->s_magic) {
  502. case EXT2_SUPER_MAGIC:
  503. resp->p_link_max = EXT2_LINK_MAX;
  504. resp->p_name_max = EXT2_NAME_LEN;
  505. break;
  506. case MSDOS_SUPER_MAGIC:
  507. resp->p_case_insensitive = 1;
  508. resp->p_case_preserving = 0;
  509. break;
  510. }
  511. }
  512. fh_put(&argp->fh);
  513. RETURN_STATUS(nfserr);
  514. }
  515. /*
  516. * Commit a file (range) to stable storage.
  517. */
  518. static __be32
  519. nfsd3_proc_commit(struct svc_rqst * rqstp, struct nfsd3_commitargs *argp,
  520. struct nfsd3_commitres *resp)
  521. {
  522. __be32 nfserr;
  523. dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
  524. SVCFH_fmt(&argp->fh),
  525. argp->count,
  526. (unsigned long long) argp->offset);
  527. if (argp->offset > NFS_OFFSET_MAX)
  528. RETURN_STATUS(nfserr_inval);
  529. fh_copy(&resp->fh, &argp->fh);
  530. nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);
  531. RETURN_STATUS(nfserr);
  532. }
  533. /*
  534. * NFSv3 Server procedures.
  535. * Only the results of non-idempotent operations are cached.
  536. */
  537. #define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle
  538. #define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
  539. #define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
  540. #define nfsd3_mkdirargs nfsd3_createargs
  541. #define nfsd3_readdirplusargs nfsd3_readdirargs
  542. #define nfsd3_fhandleargs nfsd_fhandle
  543. #define nfsd3_fhandleres nfsd3_attrstat
  544. #define nfsd3_attrstatres nfsd3_attrstat
  545. #define nfsd3_wccstatres nfsd3_attrstat
  546. #define nfsd3_createres nfsd3_diropres
  547. #define nfsd3_voidres nfsd3_voidargs
  548. struct nfsd3_voidargs { int dummy; };
  549. #define PROC(name, argt, rest, relt, cache, respsize) \
  550. { (svc_procfunc) nfsd3_proc_##name, \
  551. (kxdrproc_t) nfs3svc_decode_##argt##args, \
  552. (kxdrproc_t) nfs3svc_encode_##rest##res, \
  553. (kxdrproc_t) nfs3svc_release_##relt, \
  554. sizeof(struct nfsd3_##argt##args), \
  555. sizeof(struct nfsd3_##rest##res), \
  556. 0, \
  557. cache, \
  558. respsize, \
  559. }
  560. #define ST 1 /* status*/
  561. #define FH 17 /* filehandle with length */
  562. #define AT 21 /* attributes */
  563. #define pAT (1+AT) /* post attributes - conditional */
  564. #define WC (7+pAT) /* WCC attributes */
  565. static struct svc_procedure nfsd_procedures3[22] = {
  566. [NFS3PROC_NULL] = {
  567. .pc_func = (svc_procfunc) nfsd3_proc_null,
  568. .pc_encode = (kxdrproc_t) nfs3svc_encode_voidres,
  569. .pc_argsize = sizeof(struct nfsd3_voidargs),
  570. .pc_ressize = sizeof(struct nfsd3_voidres),
  571. .pc_cachetype = RC_NOCACHE,
  572. .pc_xdrressize = ST,
  573. },
  574. [NFS3PROC_GETATTR] = {
  575. .pc_func = (svc_procfunc) nfsd3_proc_getattr,
  576. .pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
  577. .pc_encode = (kxdrproc_t) nfs3svc_encode_attrstatres,
  578. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  579. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  580. .pc_ressize = sizeof(struct nfsd3_attrstatres),
  581. .pc_cachetype = RC_NOCACHE,
  582. .pc_xdrressize = ST+AT,
  583. },
  584. [NFS3PROC_SETATTR] = {
  585. .pc_func = (svc_procfunc) nfsd3_proc_setattr,
  586. .pc_decode = (kxdrproc_t) nfs3svc_decode_sattrargs,
  587. .pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
  588. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  589. .pc_argsize = sizeof(struct nfsd3_sattrargs),
  590. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  591. .pc_cachetype = RC_REPLBUFF,
  592. .pc_xdrressize = ST+WC,
  593. },
  594. [NFS3PROC_LOOKUP] = {
  595. .pc_func = (svc_procfunc) nfsd3_proc_lookup,
  596. .pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
  597. .pc_encode = (kxdrproc_t) nfs3svc_encode_diropres,
  598. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  599. .pc_argsize = sizeof(struct nfsd3_diropargs),
  600. .pc_ressize = sizeof(struct nfsd3_diropres),
  601. .pc_cachetype = RC_NOCACHE,
  602. .pc_xdrressize = ST+FH+pAT+pAT,
  603. },
  604. [NFS3PROC_ACCESS] = {
  605. .pc_func = (svc_procfunc) nfsd3_proc_access,
  606. .pc_decode = (kxdrproc_t) nfs3svc_decode_accessargs,
  607. .pc_encode = (kxdrproc_t) nfs3svc_encode_accessres,
  608. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  609. .pc_argsize = sizeof(struct nfsd3_accessargs),
  610. .pc_ressize = sizeof(struct nfsd3_accessres),
  611. .pc_cachetype = RC_NOCACHE,
  612. .pc_xdrressize = ST+pAT+1,
  613. },
  614. [NFS3PROC_READLINK] = {
  615. .pc_func = (svc_procfunc) nfsd3_proc_readlink,
  616. .pc_decode = (kxdrproc_t) nfs3svc_decode_readlinkargs,
  617. .pc_encode = (kxdrproc_t) nfs3svc_encode_readlinkres,
  618. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  619. .pc_argsize = sizeof(struct nfsd3_readlinkargs),
  620. .pc_ressize = sizeof(struct nfsd3_readlinkres),
  621. .pc_cachetype = RC_NOCACHE,
  622. .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
  623. },
  624. [NFS3PROC_READ] = {
  625. .pc_func = (svc_procfunc) nfsd3_proc_read,
  626. .pc_decode = (kxdrproc_t) nfs3svc_decode_readargs,
  627. .pc_encode = (kxdrproc_t) nfs3svc_encode_readres,
  628. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  629. .pc_argsize = sizeof(struct nfsd3_readargs),
  630. .pc_ressize = sizeof(struct nfsd3_readres),
  631. .pc_cachetype = RC_NOCACHE,
  632. .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
  633. },
  634. [NFS3PROC_WRITE] = {
  635. .pc_func = (svc_procfunc) nfsd3_proc_write,
  636. .pc_decode = (kxdrproc_t) nfs3svc_decode_writeargs,
  637. .pc_encode = (kxdrproc_t) nfs3svc_encode_writeres,
  638. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  639. .pc_argsize = sizeof(struct nfsd3_writeargs),
  640. .pc_ressize = sizeof(struct nfsd3_writeres),
  641. .pc_cachetype = RC_REPLBUFF,
  642. .pc_xdrressize = ST+WC+4,
  643. },
  644. [NFS3PROC_CREATE] = {
  645. .pc_func = (svc_procfunc) nfsd3_proc_create,
  646. .pc_decode = (kxdrproc_t) nfs3svc_decode_createargs,
  647. .pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
  648. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  649. .pc_argsize = sizeof(struct nfsd3_createargs),
  650. .pc_ressize = sizeof(struct nfsd3_createres),
  651. .pc_cachetype = RC_REPLBUFF,
  652. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  653. },
  654. [NFS3PROC_MKDIR] = {
  655. .pc_func = (svc_procfunc) nfsd3_proc_mkdir,
  656. .pc_decode = (kxdrproc_t) nfs3svc_decode_mkdirargs,
  657. .pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
  658. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  659. .pc_argsize = sizeof(struct nfsd3_mkdirargs),
  660. .pc_ressize = sizeof(struct nfsd3_createres),
  661. .pc_cachetype = RC_REPLBUFF,
  662. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  663. },
  664. [NFS3PROC_SYMLINK] = {
  665. .pc_func = (svc_procfunc) nfsd3_proc_symlink,
  666. .pc_decode = (kxdrproc_t) nfs3svc_decode_symlinkargs,
  667. .pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
  668. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  669. .pc_argsize = sizeof(struct nfsd3_symlinkargs),
  670. .pc_ressize = sizeof(struct nfsd3_createres),
  671. .pc_cachetype = RC_REPLBUFF,
  672. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  673. },
  674. [NFS3PROC_MKNOD] = {
  675. .pc_func = (svc_procfunc) nfsd3_proc_mknod,
  676. .pc_decode = (kxdrproc_t) nfs3svc_decode_mknodargs,
  677. .pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
  678. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  679. .pc_argsize = sizeof(struct nfsd3_mknodargs),
  680. .pc_ressize = sizeof(struct nfsd3_createres),
  681. .pc_cachetype = RC_REPLBUFF,
  682. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  683. },
  684. [NFS3PROC_REMOVE] = {
  685. .pc_func = (svc_procfunc) nfsd3_proc_remove,
  686. .pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
  687. .pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
  688. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  689. .pc_argsize = sizeof(struct nfsd3_diropargs),
  690. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  691. .pc_cachetype = RC_REPLBUFF,
  692. .pc_xdrressize = ST+WC,
  693. },
  694. [NFS3PROC_RMDIR] = {
  695. .pc_func = (svc_procfunc) nfsd3_proc_rmdir,
  696. .pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
  697. .pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
  698. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  699. .pc_argsize = sizeof(struct nfsd3_diropargs),
  700. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  701. .pc_cachetype = RC_REPLBUFF,
  702. .pc_xdrressize = ST+WC,
  703. },
  704. [NFS3PROC_RENAME] = {
  705. .pc_func = (svc_procfunc) nfsd3_proc_rename,
  706. .pc_decode = (kxdrproc_t) nfs3svc_decode_renameargs,
  707. .pc_encode = (kxdrproc_t) nfs3svc_encode_renameres,
  708. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  709. .pc_argsize = sizeof(struct nfsd3_renameargs),
  710. .pc_ressize = sizeof(struct nfsd3_renameres),
  711. .pc_cachetype = RC_REPLBUFF,
  712. .pc_xdrressize = ST+WC+WC,
  713. },
  714. [NFS3PROC_LINK] = {
  715. .pc_func = (svc_procfunc) nfsd3_proc_link,
  716. .pc_decode = (kxdrproc_t) nfs3svc_decode_linkargs,
  717. .pc_encode = (kxdrproc_t) nfs3svc_encode_linkres,
  718. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
  719. .pc_argsize = sizeof(struct nfsd3_linkargs),
  720. .pc_ressize = sizeof(struct nfsd3_linkres),
  721. .pc_cachetype = RC_REPLBUFF,
  722. .pc_xdrressize = ST+pAT+WC,
  723. },
  724. [NFS3PROC_READDIR] = {
  725. .pc_func = (svc_procfunc) nfsd3_proc_readdir,
  726. .pc_decode = (kxdrproc_t) nfs3svc_decode_readdirargs,
  727. .pc_encode = (kxdrproc_t) nfs3svc_encode_readdirres,
  728. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  729. .pc_argsize = sizeof(struct nfsd3_readdirargs),
  730. .pc_ressize = sizeof(struct nfsd3_readdirres),
  731. .pc_cachetype = RC_NOCACHE,
  732. },
  733. [NFS3PROC_READDIRPLUS] = {
  734. .pc_func = (svc_procfunc) nfsd3_proc_readdirplus,
  735. .pc_decode = (kxdrproc_t) nfs3svc_decode_readdirplusargs,
  736. .pc_encode = (kxdrproc_t) nfs3svc_encode_readdirres,
  737. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  738. .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
  739. .pc_ressize = sizeof(struct nfsd3_readdirres),
  740. .pc_cachetype = RC_NOCACHE,
  741. },
  742. [NFS3PROC_FSSTAT] = {
  743. .pc_func = (svc_procfunc) nfsd3_proc_fsstat,
  744. .pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
  745. .pc_encode = (kxdrproc_t) nfs3svc_encode_fsstatres,
  746. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  747. .pc_ressize = sizeof(struct nfsd3_fsstatres),
  748. .pc_cachetype = RC_NOCACHE,
  749. .pc_xdrressize = ST+pAT+2*6+1,
  750. },
  751. [NFS3PROC_FSINFO] = {
  752. .pc_func = (svc_procfunc) nfsd3_proc_fsinfo,
  753. .pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
  754. .pc_encode = (kxdrproc_t) nfs3svc_encode_fsinfores,
  755. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  756. .pc_ressize = sizeof(struct nfsd3_fsinfores),
  757. .pc_cachetype = RC_NOCACHE,
  758. .pc_xdrressize = ST+pAT+12,
  759. },
  760. [NFS3PROC_PATHCONF] = {
  761. .pc_func = (svc_procfunc) nfsd3_proc_pathconf,
  762. .pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
  763. .pc_encode = (kxdrproc_t) nfs3svc_encode_pathconfres,
  764. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  765. .pc_ressize = sizeof(struct nfsd3_pathconfres),
  766. .pc_cachetype = RC_NOCACHE,
  767. .pc_xdrressize = ST+pAT+6,
  768. },
  769. [NFS3PROC_COMMIT] = {
  770. .pc_func = (svc_procfunc) nfsd3_proc_commit,
  771. .pc_decode = (kxdrproc_t) nfs3svc_decode_commitargs,
  772. .pc_encode = (kxdrproc_t) nfs3svc_encode_commitres,
  773. .pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
  774. .pc_argsize = sizeof(struct nfsd3_commitargs),
  775. .pc_ressize = sizeof(struct nfsd3_commitres),
  776. .pc_cachetype = RC_NOCACHE,
  777. .pc_xdrressize = ST+WC+2,
  778. },
  779. };
  780. struct svc_version nfsd_version3 = {
  781. .vs_vers = 3,
  782. .vs_nproc = 22,
  783. .vs_proc = nfsd_procedures3,
  784. .vs_dispatch = nfsd_dispatch,
  785. .vs_xdrsize = NFS3_SVC_XDRSIZE,
  786. };