nfs3proc.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Process version 3 NFS requests.
  4. *
  5. * Copyright (C) 1996, 1997, 1998 Olaf Kirch <[email protected]>
  6. */
  7. #include <linux/fs.h>
  8. #include <linux/ext2_fs.h>
  9. #include <linux/magic.h>
  10. #include <linux/namei.h>
  11. #include "cache.h"
  12. #include "xdr3.h"
  13. #include "vfs.h"
  14. #include "filecache.h"
  15. #define NFSDDBG_FACILITY NFSDDBG_PROC
  16. static int nfs3_ftypes[] = {
  17. 0, /* NF3NON */
  18. S_IFREG, /* NF3REG */
  19. S_IFDIR, /* NF3DIR */
  20. S_IFBLK, /* NF3BLK */
  21. S_IFCHR, /* NF3CHR */
  22. S_IFLNK, /* NF3LNK */
  23. S_IFSOCK, /* NF3SOCK */
  24. S_IFIFO, /* NF3FIFO */
  25. };
  26. /*
  27. * NULL call.
  28. */
  29. static __be32
  30. nfsd3_proc_null(struct svc_rqst *rqstp)
  31. {
  32. return rpc_success;
  33. }
  34. /*
  35. * Get a file's attributes
  36. */
  37. static __be32
  38. nfsd3_proc_getattr(struct svc_rqst *rqstp)
  39. {
  40. struct nfsd_fhandle *argp = rqstp->rq_argp;
  41. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  42. dprintk("nfsd: GETATTR(3) %s\n",
  43. SVCFH_fmt(&argp->fh));
  44. fh_copy(&resp->fh, &argp->fh);
  45. resp->status = fh_verify(rqstp, &resp->fh, 0,
  46. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  47. if (resp->status != nfs_ok)
  48. goto out;
  49. resp->status = fh_getattr(&resp->fh, &resp->stat);
  50. out:
  51. return rpc_success;
  52. }
  53. /*
  54. * Set a file's attributes
  55. */
  56. static __be32
  57. nfsd3_proc_setattr(struct svc_rqst *rqstp)
  58. {
  59. struct nfsd3_sattrargs *argp = rqstp->rq_argp;
  60. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  61. struct nfsd_attrs attrs = {
  62. .na_iattr = &argp->attrs,
  63. };
  64. dprintk("nfsd: SETATTR(3) %s\n",
  65. SVCFH_fmt(&argp->fh));
  66. fh_copy(&resp->fh, &argp->fh);
  67. resp->status = nfsd_setattr(rqstp, &resp->fh, &attrs,
  68. argp->check_guard, argp->guardtime);
  69. return rpc_success;
  70. }
  71. /*
  72. * Look up a path name component
  73. */
  74. static __be32
  75. nfsd3_proc_lookup(struct svc_rqst *rqstp)
  76. {
  77. struct nfsd3_diropargs *argp = rqstp->rq_argp;
  78. struct nfsd3_diropres *resp = rqstp->rq_resp;
  79. dprintk("nfsd: LOOKUP(3) %s %.*s\n",
  80. SVCFH_fmt(&argp->fh),
  81. argp->len,
  82. argp->name);
  83. fh_copy(&resp->dirfh, &argp->fh);
  84. fh_init(&resp->fh, NFS3_FHSIZE);
  85. resp->status = nfsd_lookup(rqstp, &resp->dirfh,
  86. argp->name, argp->len,
  87. &resp->fh);
  88. return rpc_success;
  89. }
  90. /*
  91. * Check file access
  92. */
  93. static __be32
  94. nfsd3_proc_access(struct svc_rqst *rqstp)
  95. {
  96. struct nfsd3_accessargs *argp = rqstp->rq_argp;
  97. struct nfsd3_accessres *resp = rqstp->rq_resp;
  98. dprintk("nfsd: ACCESS(3) %s 0x%x\n",
  99. SVCFH_fmt(&argp->fh),
  100. argp->access);
  101. fh_copy(&resp->fh, &argp->fh);
  102. resp->access = argp->access;
  103. resp->status = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
  104. return rpc_success;
  105. }
  106. /*
  107. * Read a symlink.
  108. */
  109. static __be32
  110. nfsd3_proc_readlink(struct svc_rqst *rqstp)
  111. {
  112. struct nfsd_fhandle *argp = rqstp->rq_argp;
  113. struct nfsd3_readlinkres *resp = rqstp->rq_resp;
  114. dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
  115. /* Read the symlink. */
  116. fh_copy(&resp->fh, &argp->fh);
  117. resp->len = NFS3_MAXPATHLEN;
  118. resp->pages = rqstp->rq_next_page++;
  119. resp->status = nfsd_readlink(rqstp, &resp->fh,
  120. page_address(*resp->pages), &resp->len);
  121. return rpc_success;
  122. }
  123. /*
  124. * Read a portion of a file.
  125. */
  126. static __be32
  127. nfsd3_proc_read(struct svc_rqst *rqstp)
  128. {
  129. struct nfsd3_readargs *argp = rqstp->rq_argp;
  130. struct nfsd3_readres *resp = rqstp->rq_resp;
  131. unsigned int len;
  132. int v;
  133. dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
  134. SVCFH_fmt(&argp->fh),
  135. (unsigned long) argp->count,
  136. (unsigned long long) argp->offset);
  137. argp->count = min_t(u32, argp->count, svc_max_payload(rqstp));
  138. argp->count = min_t(u32, argp->count, rqstp->rq_res.buflen);
  139. if (argp->offset > (u64)OFFSET_MAX)
  140. argp->offset = (u64)OFFSET_MAX;
  141. if (argp->offset + argp->count > (u64)OFFSET_MAX)
  142. argp->count = (u64)OFFSET_MAX - argp->offset;
  143. v = 0;
  144. len = argp->count;
  145. resp->pages = rqstp->rq_next_page;
  146. while (len > 0) {
  147. struct page *page = *(rqstp->rq_next_page++);
  148. rqstp->rq_vec[v].iov_base = page_address(page);
  149. rqstp->rq_vec[v].iov_len = min_t(unsigned int, len, PAGE_SIZE);
  150. len -= rqstp->rq_vec[v].iov_len;
  151. v++;
  152. }
  153. /* Obtain buffer pointer for payload.
  154. * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
  155. * + 1 (xdr opaque byte count) = 26
  156. */
  157. resp->count = argp->count;
  158. svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
  159. fh_copy(&resp->fh, &argp->fh);
  160. resp->status = nfsd_read(rqstp, &resp->fh, argp->offset,
  161. rqstp->rq_vec, v, &resp->count, &resp->eof);
  162. return rpc_success;
  163. }
  164. /*
  165. * Write data to a file
  166. */
  167. static __be32
  168. nfsd3_proc_write(struct svc_rqst *rqstp)
  169. {
  170. struct nfsd3_writeargs *argp = rqstp->rq_argp;
  171. struct nfsd3_writeres *resp = rqstp->rq_resp;
  172. unsigned long cnt = argp->len;
  173. unsigned int nvecs;
  174. dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
  175. SVCFH_fmt(&argp->fh),
  176. argp->len,
  177. (unsigned long long) argp->offset,
  178. argp->stable? " stable" : "");
  179. resp->status = nfserr_fbig;
  180. if (argp->offset > (u64)OFFSET_MAX ||
  181. argp->offset + argp->len > (u64)OFFSET_MAX)
  182. return rpc_success;
  183. fh_copy(&resp->fh, &argp->fh);
  184. resp->committed = argp->stable;
  185. nvecs = svc_fill_write_vector(rqstp, &argp->payload);
  186. resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
  187. rqstp->rq_vec, nvecs, &cnt,
  188. resp->committed, resp->verf);
  189. resp->count = cnt;
  190. return rpc_success;
  191. }
  192. /*
  193. * Implement NFSv3's unchecked, guarded, and exclusive CREATE
  194. * semantics for regular files. Except for the created file,
  195. * this operation is stateless on the server.
  196. *
  197. * Upon return, caller must release @fhp and @resfhp.
  198. */
  199. static __be32
  200. nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
  201. struct svc_fh *resfhp, struct nfsd3_createargs *argp)
  202. {
  203. struct iattr *iap = &argp->attrs;
  204. struct dentry *parent, *child;
  205. struct nfsd_attrs attrs = {
  206. .na_iattr = iap,
  207. };
  208. __u32 v_mtime, v_atime;
  209. struct inode *inode;
  210. __be32 status;
  211. int host_err;
  212. if (isdotent(argp->name, argp->len))
  213. return nfserr_exist;
  214. if (!(iap->ia_valid & ATTR_MODE))
  215. iap->ia_mode = 0;
  216. status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
  217. if (status != nfs_ok)
  218. return status;
  219. parent = fhp->fh_dentry;
  220. inode = d_inode(parent);
  221. host_err = fh_want_write(fhp);
  222. if (host_err)
  223. return nfserrno(host_err);
  224. inode_lock_nested(inode, I_MUTEX_PARENT);
  225. child = lookup_one_len(argp->name, parent, argp->len);
  226. if (IS_ERR(child)) {
  227. status = nfserrno(PTR_ERR(child));
  228. goto out;
  229. }
  230. if (d_really_is_negative(child)) {
  231. status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
  232. if (status != nfs_ok)
  233. goto out;
  234. }
  235. status = fh_compose(resfhp, fhp->fh_export, child, fhp);
  236. if (status != nfs_ok)
  237. goto out;
  238. v_mtime = 0;
  239. v_atime = 0;
  240. if (argp->createmode == NFS3_CREATE_EXCLUSIVE) {
  241. u32 *verifier = (u32 *)argp->verf;
  242. /*
  243. * Solaris 7 gets confused (bugid 4218508) if these have
  244. * the high bit set, as do xfs filesystems without the
  245. * "bigtime" feature. So just clear the high bits.
  246. */
  247. v_mtime = verifier[0] & 0x7fffffff;
  248. v_atime = verifier[1] & 0x7fffffff;
  249. }
  250. if (d_really_is_positive(child)) {
  251. status = nfs_ok;
  252. switch (argp->createmode) {
  253. case NFS3_CREATE_UNCHECKED:
  254. if (!d_is_reg(child))
  255. break;
  256. iap->ia_valid &= ATTR_SIZE;
  257. goto set_attr;
  258. case NFS3_CREATE_GUARDED:
  259. status = nfserr_exist;
  260. break;
  261. case NFS3_CREATE_EXCLUSIVE:
  262. if (d_inode(child)->i_mtime.tv_sec == v_mtime &&
  263. d_inode(child)->i_atime.tv_sec == v_atime &&
  264. d_inode(child)->i_size == 0) {
  265. break;
  266. }
  267. status = nfserr_exist;
  268. }
  269. goto out;
  270. }
  271. if (!IS_POSIXACL(inode))
  272. iap->ia_mode &= ~current_umask();
  273. fh_fill_pre_attrs(fhp);
  274. host_err = vfs_create(&init_user_ns, inode, child, iap->ia_mode, true);
  275. if (host_err < 0) {
  276. status = nfserrno(host_err);
  277. goto out;
  278. }
  279. fh_fill_post_attrs(fhp);
  280. /* A newly created file already has a file size of zero. */
  281. if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
  282. iap->ia_valid &= ~ATTR_SIZE;
  283. if (argp->createmode == NFS3_CREATE_EXCLUSIVE) {
  284. iap->ia_valid = ATTR_MTIME | ATTR_ATIME |
  285. ATTR_MTIME_SET | ATTR_ATIME_SET;
  286. iap->ia_mtime.tv_sec = v_mtime;
  287. iap->ia_atime.tv_sec = v_atime;
  288. iap->ia_mtime.tv_nsec = 0;
  289. iap->ia_atime.tv_nsec = 0;
  290. }
  291. set_attr:
  292. status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
  293. out:
  294. inode_unlock(inode);
  295. if (child && !IS_ERR(child))
  296. dput(child);
  297. fh_drop_write(fhp);
  298. return status;
  299. }
  300. static __be32
  301. nfsd3_proc_create(struct svc_rqst *rqstp)
  302. {
  303. struct nfsd3_createargs *argp = rqstp->rq_argp;
  304. struct nfsd3_diropres *resp = rqstp->rq_resp;
  305. svc_fh *dirfhp, *newfhp;
  306. dprintk("nfsd: CREATE(3) %s %.*s\n",
  307. SVCFH_fmt(&argp->fh),
  308. argp->len,
  309. argp->name);
  310. dirfhp = fh_copy(&resp->dirfh, &argp->fh);
  311. newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
  312. resp->status = nfsd3_create_file(rqstp, dirfhp, newfhp, argp);
  313. return rpc_success;
  314. }
  315. /*
  316. * Make directory. This operation is not idempotent.
  317. */
  318. static __be32
  319. nfsd3_proc_mkdir(struct svc_rqst *rqstp)
  320. {
  321. struct nfsd3_createargs *argp = rqstp->rq_argp;
  322. struct nfsd3_diropres *resp = rqstp->rq_resp;
  323. struct nfsd_attrs attrs = {
  324. .na_iattr = &argp->attrs,
  325. };
  326. dprintk("nfsd: MKDIR(3) %s %.*s\n",
  327. SVCFH_fmt(&argp->fh),
  328. argp->len,
  329. argp->name);
  330. argp->attrs.ia_valid &= ~ATTR_SIZE;
  331. fh_copy(&resp->dirfh, &argp->fh);
  332. fh_init(&resp->fh, NFS3_FHSIZE);
  333. resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
  334. &attrs, S_IFDIR, 0, &resp->fh);
  335. return rpc_success;
  336. }
  337. static __be32
  338. nfsd3_proc_symlink(struct svc_rqst *rqstp)
  339. {
  340. struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
  341. struct nfsd3_diropres *resp = rqstp->rq_resp;
  342. struct nfsd_attrs attrs = {
  343. .na_iattr = &argp->attrs,
  344. };
  345. if (argp->tlen == 0) {
  346. resp->status = nfserr_inval;
  347. goto out;
  348. }
  349. if (argp->tlen > NFS3_MAXPATHLEN) {
  350. resp->status = nfserr_nametoolong;
  351. goto out;
  352. }
  353. argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
  354. page_address(rqstp->rq_arg.pages[0]),
  355. argp->tlen);
  356. if (IS_ERR(argp->tname)) {
  357. resp->status = nfserrno(PTR_ERR(argp->tname));
  358. goto out;
  359. }
  360. dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
  361. SVCFH_fmt(&argp->ffh),
  362. argp->flen, argp->fname,
  363. argp->tlen, argp->tname);
  364. fh_copy(&resp->dirfh, &argp->ffh);
  365. fh_init(&resp->fh, NFS3_FHSIZE);
  366. resp->status = nfsd_symlink(rqstp, &resp->dirfh, argp->fname,
  367. argp->flen, argp->tname, &attrs, &resp->fh);
  368. kfree(argp->tname);
  369. out:
  370. return rpc_success;
  371. }
  372. /*
  373. * Make socket/fifo/device.
  374. */
  375. static __be32
  376. nfsd3_proc_mknod(struct svc_rqst *rqstp)
  377. {
  378. struct nfsd3_mknodargs *argp = rqstp->rq_argp;
  379. struct nfsd3_diropres *resp = rqstp->rq_resp;
  380. struct nfsd_attrs attrs = {
  381. .na_iattr = &argp->attrs,
  382. };
  383. int type;
  384. dev_t rdev = 0;
  385. dprintk("nfsd: MKNOD(3) %s %.*s\n",
  386. SVCFH_fmt(&argp->fh),
  387. argp->len,
  388. argp->name);
  389. fh_copy(&resp->dirfh, &argp->fh);
  390. fh_init(&resp->fh, NFS3_FHSIZE);
  391. if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
  392. rdev = MKDEV(argp->major, argp->minor);
  393. if (MAJOR(rdev) != argp->major ||
  394. MINOR(rdev) != argp->minor) {
  395. resp->status = nfserr_inval;
  396. goto out;
  397. }
  398. } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
  399. resp->status = nfserr_badtype;
  400. goto out;
  401. }
  402. type = nfs3_ftypes[argp->ftype];
  403. resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
  404. &attrs, type, rdev, &resp->fh);
  405. out:
  406. return rpc_success;
  407. }
  408. /*
  409. * Remove file/fifo/socket etc.
  410. */
  411. static __be32
  412. nfsd3_proc_remove(struct svc_rqst *rqstp)
  413. {
  414. struct nfsd3_diropargs *argp = rqstp->rq_argp;
  415. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  416. dprintk("nfsd: REMOVE(3) %s %.*s\n",
  417. SVCFH_fmt(&argp->fh),
  418. argp->len,
  419. argp->name);
  420. /* Unlink. -S_IFDIR means file must not be a directory */
  421. fh_copy(&resp->fh, &argp->fh);
  422. resp->status = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR,
  423. argp->name, argp->len);
  424. return rpc_success;
  425. }
  426. /*
  427. * Remove a directory
  428. */
  429. static __be32
  430. nfsd3_proc_rmdir(struct svc_rqst *rqstp)
  431. {
  432. struct nfsd3_diropargs *argp = rqstp->rq_argp;
  433. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  434. dprintk("nfsd: RMDIR(3) %s %.*s\n",
  435. SVCFH_fmt(&argp->fh),
  436. argp->len,
  437. argp->name);
  438. fh_copy(&resp->fh, &argp->fh);
  439. resp->status = nfsd_unlink(rqstp, &resp->fh, S_IFDIR,
  440. argp->name, argp->len);
  441. return rpc_success;
  442. }
  443. static __be32
  444. nfsd3_proc_rename(struct svc_rqst *rqstp)
  445. {
  446. struct nfsd3_renameargs *argp = rqstp->rq_argp;
  447. struct nfsd3_renameres *resp = rqstp->rq_resp;
  448. dprintk("nfsd: RENAME(3) %s %.*s ->\n",
  449. SVCFH_fmt(&argp->ffh),
  450. argp->flen,
  451. argp->fname);
  452. dprintk("nfsd: -> %s %.*s\n",
  453. SVCFH_fmt(&argp->tfh),
  454. argp->tlen,
  455. argp->tname);
  456. fh_copy(&resp->ffh, &argp->ffh);
  457. fh_copy(&resp->tfh, &argp->tfh);
  458. resp->status = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
  459. &resp->tfh, argp->tname, argp->tlen);
  460. return rpc_success;
  461. }
  462. static __be32
  463. nfsd3_proc_link(struct svc_rqst *rqstp)
  464. {
  465. struct nfsd3_linkargs *argp = rqstp->rq_argp;
  466. struct nfsd3_linkres *resp = rqstp->rq_resp;
  467. dprintk("nfsd: LINK(3) %s ->\n",
  468. SVCFH_fmt(&argp->ffh));
  469. dprintk("nfsd: -> %s %.*s\n",
  470. SVCFH_fmt(&argp->tfh),
  471. argp->tlen,
  472. argp->tname);
  473. fh_copy(&resp->fh, &argp->ffh);
  474. fh_copy(&resp->tfh, &argp->tfh);
  475. resp->status = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
  476. &resp->fh);
  477. return rpc_success;
  478. }
  479. static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
  480. struct nfsd3_readdirres *resp,
  481. u32 count)
  482. {
  483. struct xdr_buf *buf = &resp->dirlist;
  484. struct xdr_stream *xdr = &resp->xdr;
  485. unsigned int sendbuf = min_t(unsigned int, rqstp->rq_res.buflen,
  486. svc_max_payload(rqstp));
  487. memset(buf, 0, sizeof(*buf));
  488. /* Reserve room for the NULL ptr & eof flag (-2 words) */
  489. buf->buflen = clamp(count, (u32)(XDR_UNIT * 2), sendbuf);
  490. buf->buflen -= XDR_UNIT * 2;
  491. buf->pages = rqstp->rq_next_page;
  492. rqstp->rq_next_page += (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
  493. xdr_init_encode_pages(xdr, buf, buf->pages, NULL);
  494. }
  495. /*
  496. * Read a portion of a directory.
  497. */
  498. static __be32
  499. nfsd3_proc_readdir(struct svc_rqst *rqstp)
  500. {
  501. struct nfsd3_readdirargs *argp = rqstp->rq_argp;
  502. struct nfsd3_readdirres *resp = rqstp->rq_resp;
  503. loff_t offset;
  504. dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
  505. SVCFH_fmt(&argp->fh),
  506. argp->count, (u32) argp->cookie);
  507. nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
  508. fh_copy(&resp->fh, &argp->fh);
  509. resp->common.err = nfs_ok;
  510. resp->cookie_offset = 0;
  511. resp->rqstp = rqstp;
  512. offset = argp->cookie;
  513. resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
  514. &resp->common, nfs3svc_encode_entry3);
  515. memcpy(resp->verf, argp->verf, 8);
  516. nfs3svc_encode_cookie3(resp, offset);
  517. /* Recycle only pages that were part of the reply */
  518. rqstp->rq_next_page = resp->xdr.page_ptr + 1;
  519. return rpc_success;
  520. }
  521. /*
  522. * Read a portion of a directory, including file handles and attrs.
  523. * For now, we choose to ignore the dircount parameter.
  524. */
  525. static __be32
  526. nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
  527. {
  528. struct nfsd3_readdirargs *argp = rqstp->rq_argp;
  529. struct nfsd3_readdirres *resp = rqstp->rq_resp;
  530. loff_t offset;
  531. dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
  532. SVCFH_fmt(&argp->fh),
  533. argp->count, (u32) argp->cookie);
  534. nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
  535. fh_copy(&resp->fh, &argp->fh);
  536. resp->common.err = nfs_ok;
  537. resp->cookie_offset = 0;
  538. resp->rqstp = rqstp;
  539. offset = argp->cookie;
  540. resp->status = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
  541. if (resp->status != nfs_ok)
  542. goto out;
  543. if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS) {
  544. resp->status = nfserr_notsupp;
  545. goto out;
  546. }
  547. resp->status = nfsd_readdir(rqstp, &resp->fh, &offset,
  548. &resp->common, nfs3svc_encode_entryplus3);
  549. memcpy(resp->verf, argp->verf, 8);
  550. nfs3svc_encode_cookie3(resp, offset);
  551. /* Recycle only pages that were part of the reply */
  552. rqstp->rq_next_page = resp->xdr.page_ptr + 1;
  553. out:
  554. return rpc_success;
  555. }
  556. /*
  557. * Get file system stats
  558. */
  559. static __be32
  560. nfsd3_proc_fsstat(struct svc_rqst *rqstp)
  561. {
  562. struct nfsd_fhandle *argp = rqstp->rq_argp;
  563. struct nfsd3_fsstatres *resp = rqstp->rq_resp;
  564. dprintk("nfsd: FSSTAT(3) %s\n",
  565. SVCFH_fmt(&argp->fh));
  566. resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
  567. fh_put(&argp->fh);
  568. return rpc_success;
  569. }
  570. /*
  571. * Get file system info
  572. */
  573. static __be32
  574. nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
  575. {
  576. struct nfsd_fhandle *argp = rqstp->rq_argp;
  577. struct nfsd3_fsinfores *resp = rqstp->rq_resp;
  578. u32 max_blocksize = svc_max_payload(rqstp);
  579. dprintk("nfsd: FSINFO(3) %s\n",
  580. SVCFH_fmt(&argp->fh));
  581. resp->f_rtmax = max_blocksize;
  582. resp->f_rtpref = max_blocksize;
  583. resp->f_rtmult = PAGE_SIZE;
  584. resp->f_wtmax = max_blocksize;
  585. resp->f_wtpref = max_blocksize;
  586. resp->f_wtmult = PAGE_SIZE;
  587. resp->f_dtpref = max_blocksize;
  588. resp->f_maxfilesize = ~(u32) 0;
  589. resp->f_properties = NFS3_FSF_DEFAULT;
  590. resp->status = fh_verify(rqstp, &argp->fh, 0,
  591. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  592. /* Check special features of the file system. May request
  593. * different read/write sizes for file systems known to have
  594. * problems with large blocks */
  595. if (resp->status == nfs_ok) {
  596. struct super_block *sb = argp->fh.fh_dentry->d_sb;
  597. /* Note that we don't care for remote fs's here */
  598. if (sb->s_magic == MSDOS_SUPER_MAGIC) {
  599. resp->f_properties = NFS3_FSF_BILLYBOY;
  600. }
  601. resp->f_maxfilesize = sb->s_maxbytes;
  602. }
  603. fh_put(&argp->fh);
  604. return rpc_success;
  605. }
  606. /*
  607. * Get pathconf info for the specified file
  608. */
  609. static __be32
  610. nfsd3_proc_pathconf(struct svc_rqst *rqstp)
  611. {
  612. struct nfsd_fhandle *argp = rqstp->rq_argp;
  613. struct nfsd3_pathconfres *resp = rqstp->rq_resp;
  614. dprintk("nfsd: PATHCONF(3) %s\n",
  615. SVCFH_fmt(&argp->fh));
  616. /* Set default pathconf */
  617. resp->p_link_max = 255; /* at least */
  618. resp->p_name_max = 255; /* at least */
  619. resp->p_no_trunc = 0;
  620. resp->p_chown_restricted = 1;
  621. resp->p_case_insensitive = 0;
  622. resp->p_case_preserving = 1;
  623. resp->status = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
  624. if (resp->status == nfs_ok) {
  625. struct super_block *sb = argp->fh.fh_dentry->d_sb;
  626. /* Note that we don't care for remote fs's here */
  627. switch (sb->s_magic) {
  628. case EXT2_SUPER_MAGIC:
  629. resp->p_link_max = EXT2_LINK_MAX;
  630. resp->p_name_max = EXT2_NAME_LEN;
  631. break;
  632. case MSDOS_SUPER_MAGIC:
  633. resp->p_case_insensitive = 1;
  634. resp->p_case_preserving = 0;
  635. break;
  636. }
  637. }
  638. fh_put(&argp->fh);
  639. return rpc_success;
  640. }
  641. /*
  642. * Commit a file (range) to stable storage.
  643. */
  644. static __be32
  645. nfsd3_proc_commit(struct svc_rqst *rqstp)
  646. {
  647. struct nfsd3_commitargs *argp = rqstp->rq_argp;
  648. struct nfsd3_commitres *resp = rqstp->rq_resp;
  649. struct nfsd_file *nf;
  650. dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
  651. SVCFH_fmt(&argp->fh),
  652. argp->count,
  653. (unsigned long long) argp->offset);
  654. fh_copy(&resp->fh, &argp->fh);
  655. resp->status = nfsd_file_acquire_gc(rqstp, &resp->fh, NFSD_MAY_WRITE |
  656. NFSD_MAY_NOT_BREAK_LEASE, &nf);
  657. if (resp->status)
  658. goto out;
  659. resp->status = nfsd_commit(rqstp, &resp->fh, nf, argp->offset,
  660. argp->count, resp->verf);
  661. nfsd_file_put(nf);
  662. out:
  663. return rpc_success;
  664. }
  665. /*
  666. * NFSv3 Server procedures.
  667. * Only the results of non-idempotent operations are cached.
  668. */
  669. #define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
  670. #define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
  671. #define nfsd3_mkdirargs nfsd3_createargs
  672. #define nfsd3_readdirplusargs nfsd3_readdirargs
  673. #define nfsd3_fhandleargs nfsd_fhandle
  674. #define nfsd3_attrstatres nfsd3_attrstat
  675. #define nfsd3_wccstatres nfsd3_attrstat
  676. #define nfsd3_createres nfsd3_diropres
  677. #define ST 1 /* status*/
  678. #define FH 17 /* filehandle with length */
  679. #define AT 21 /* attributes */
  680. #define pAT (1+AT) /* post attributes - conditional */
  681. #define WC (7+pAT) /* WCC attributes */
  682. static const struct svc_procedure nfsd_procedures3[22] = {
  683. [NFS3PROC_NULL] = {
  684. .pc_func = nfsd3_proc_null,
  685. .pc_decode = nfssvc_decode_voidarg,
  686. .pc_encode = nfssvc_encode_voidres,
  687. .pc_argsize = sizeof(struct nfsd_voidargs),
  688. .pc_argzero = sizeof(struct nfsd_voidargs),
  689. .pc_ressize = sizeof(struct nfsd_voidres),
  690. .pc_cachetype = RC_NOCACHE,
  691. .pc_xdrressize = ST,
  692. .pc_name = "NULL",
  693. },
  694. [NFS3PROC_GETATTR] = {
  695. .pc_func = nfsd3_proc_getattr,
  696. .pc_decode = nfs3svc_decode_fhandleargs,
  697. .pc_encode = nfs3svc_encode_getattrres,
  698. .pc_release = nfs3svc_release_fhandle,
  699. .pc_argsize = sizeof(struct nfsd_fhandle),
  700. .pc_argzero = sizeof(struct nfsd_fhandle),
  701. .pc_ressize = sizeof(struct nfsd3_attrstatres),
  702. .pc_cachetype = RC_NOCACHE,
  703. .pc_xdrressize = ST+AT,
  704. .pc_name = "GETATTR",
  705. },
  706. [NFS3PROC_SETATTR] = {
  707. .pc_func = nfsd3_proc_setattr,
  708. .pc_decode = nfs3svc_decode_sattrargs,
  709. .pc_encode = nfs3svc_encode_wccstatres,
  710. .pc_release = nfs3svc_release_fhandle,
  711. .pc_argsize = sizeof(struct nfsd3_sattrargs),
  712. .pc_argzero = sizeof(struct nfsd3_sattrargs),
  713. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  714. .pc_cachetype = RC_REPLBUFF,
  715. .pc_xdrressize = ST+WC,
  716. .pc_name = "SETATTR",
  717. },
  718. [NFS3PROC_LOOKUP] = {
  719. .pc_func = nfsd3_proc_lookup,
  720. .pc_decode = nfs3svc_decode_diropargs,
  721. .pc_encode = nfs3svc_encode_lookupres,
  722. .pc_release = nfs3svc_release_fhandle2,
  723. .pc_argsize = sizeof(struct nfsd3_diropargs),
  724. .pc_argzero = sizeof(struct nfsd3_diropargs),
  725. .pc_ressize = sizeof(struct nfsd3_diropres),
  726. .pc_cachetype = RC_NOCACHE,
  727. .pc_xdrressize = ST+FH+pAT+pAT,
  728. .pc_name = "LOOKUP",
  729. },
  730. [NFS3PROC_ACCESS] = {
  731. .pc_func = nfsd3_proc_access,
  732. .pc_decode = nfs3svc_decode_accessargs,
  733. .pc_encode = nfs3svc_encode_accessres,
  734. .pc_release = nfs3svc_release_fhandle,
  735. .pc_argsize = sizeof(struct nfsd3_accessargs),
  736. .pc_argzero = sizeof(struct nfsd3_accessargs),
  737. .pc_ressize = sizeof(struct nfsd3_accessres),
  738. .pc_cachetype = RC_NOCACHE,
  739. .pc_xdrressize = ST+pAT+1,
  740. .pc_name = "ACCESS",
  741. },
  742. [NFS3PROC_READLINK] = {
  743. .pc_func = nfsd3_proc_readlink,
  744. .pc_decode = nfs3svc_decode_fhandleargs,
  745. .pc_encode = nfs3svc_encode_readlinkres,
  746. .pc_release = nfs3svc_release_fhandle,
  747. .pc_argsize = sizeof(struct nfsd_fhandle),
  748. .pc_argzero = sizeof(struct nfsd_fhandle),
  749. .pc_ressize = sizeof(struct nfsd3_readlinkres),
  750. .pc_cachetype = RC_NOCACHE,
  751. .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
  752. .pc_name = "READLINK",
  753. },
  754. [NFS3PROC_READ] = {
  755. .pc_func = nfsd3_proc_read,
  756. .pc_decode = nfs3svc_decode_readargs,
  757. .pc_encode = nfs3svc_encode_readres,
  758. .pc_release = nfs3svc_release_fhandle,
  759. .pc_argsize = sizeof(struct nfsd3_readargs),
  760. .pc_argzero = sizeof(struct nfsd3_readargs),
  761. .pc_ressize = sizeof(struct nfsd3_readres),
  762. .pc_cachetype = RC_NOCACHE,
  763. .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
  764. .pc_name = "READ",
  765. },
  766. [NFS3PROC_WRITE] = {
  767. .pc_func = nfsd3_proc_write,
  768. .pc_decode = nfs3svc_decode_writeargs,
  769. .pc_encode = nfs3svc_encode_writeres,
  770. .pc_release = nfs3svc_release_fhandle,
  771. .pc_argsize = sizeof(struct nfsd3_writeargs),
  772. .pc_argzero = sizeof(struct nfsd3_writeargs),
  773. .pc_ressize = sizeof(struct nfsd3_writeres),
  774. .pc_cachetype = RC_REPLBUFF,
  775. .pc_xdrressize = ST+WC+4,
  776. .pc_name = "WRITE",
  777. },
  778. [NFS3PROC_CREATE] = {
  779. .pc_func = nfsd3_proc_create,
  780. .pc_decode = nfs3svc_decode_createargs,
  781. .pc_encode = nfs3svc_encode_createres,
  782. .pc_release = nfs3svc_release_fhandle2,
  783. .pc_argsize = sizeof(struct nfsd3_createargs),
  784. .pc_argzero = sizeof(struct nfsd3_createargs),
  785. .pc_ressize = sizeof(struct nfsd3_createres),
  786. .pc_cachetype = RC_REPLBUFF,
  787. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  788. .pc_name = "CREATE",
  789. },
  790. [NFS3PROC_MKDIR] = {
  791. .pc_func = nfsd3_proc_mkdir,
  792. .pc_decode = nfs3svc_decode_mkdirargs,
  793. .pc_encode = nfs3svc_encode_createres,
  794. .pc_release = nfs3svc_release_fhandle2,
  795. .pc_argsize = sizeof(struct nfsd3_mkdirargs),
  796. .pc_argzero = sizeof(struct nfsd3_mkdirargs),
  797. .pc_ressize = sizeof(struct nfsd3_createres),
  798. .pc_cachetype = RC_REPLBUFF,
  799. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  800. .pc_name = "MKDIR",
  801. },
  802. [NFS3PROC_SYMLINK] = {
  803. .pc_func = nfsd3_proc_symlink,
  804. .pc_decode = nfs3svc_decode_symlinkargs,
  805. .pc_encode = nfs3svc_encode_createres,
  806. .pc_release = nfs3svc_release_fhandle2,
  807. .pc_argsize = sizeof(struct nfsd3_symlinkargs),
  808. .pc_argzero = sizeof(struct nfsd3_symlinkargs),
  809. .pc_ressize = sizeof(struct nfsd3_createres),
  810. .pc_cachetype = RC_REPLBUFF,
  811. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  812. .pc_name = "SYMLINK",
  813. },
  814. [NFS3PROC_MKNOD] = {
  815. .pc_func = nfsd3_proc_mknod,
  816. .pc_decode = nfs3svc_decode_mknodargs,
  817. .pc_encode = nfs3svc_encode_createres,
  818. .pc_release = nfs3svc_release_fhandle2,
  819. .pc_argsize = sizeof(struct nfsd3_mknodargs),
  820. .pc_argzero = sizeof(struct nfsd3_mknodargs),
  821. .pc_ressize = sizeof(struct nfsd3_createres),
  822. .pc_cachetype = RC_REPLBUFF,
  823. .pc_xdrressize = ST+(1+FH+pAT)+WC,
  824. .pc_name = "MKNOD",
  825. },
  826. [NFS3PROC_REMOVE] = {
  827. .pc_func = nfsd3_proc_remove,
  828. .pc_decode = nfs3svc_decode_diropargs,
  829. .pc_encode = nfs3svc_encode_wccstatres,
  830. .pc_release = nfs3svc_release_fhandle,
  831. .pc_argsize = sizeof(struct nfsd3_diropargs),
  832. .pc_argzero = sizeof(struct nfsd3_diropargs),
  833. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  834. .pc_cachetype = RC_REPLBUFF,
  835. .pc_xdrressize = ST+WC,
  836. .pc_name = "REMOVE",
  837. },
  838. [NFS3PROC_RMDIR] = {
  839. .pc_func = nfsd3_proc_rmdir,
  840. .pc_decode = nfs3svc_decode_diropargs,
  841. .pc_encode = nfs3svc_encode_wccstatres,
  842. .pc_release = nfs3svc_release_fhandle,
  843. .pc_argsize = sizeof(struct nfsd3_diropargs),
  844. .pc_argzero = sizeof(struct nfsd3_diropargs),
  845. .pc_ressize = sizeof(struct nfsd3_wccstatres),
  846. .pc_cachetype = RC_REPLBUFF,
  847. .pc_xdrressize = ST+WC,
  848. .pc_name = "RMDIR",
  849. },
  850. [NFS3PROC_RENAME] = {
  851. .pc_func = nfsd3_proc_rename,
  852. .pc_decode = nfs3svc_decode_renameargs,
  853. .pc_encode = nfs3svc_encode_renameres,
  854. .pc_release = nfs3svc_release_fhandle2,
  855. .pc_argsize = sizeof(struct nfsd3_renameargs),
  856. .pc_argzero = sizeof(struct nfsd3_renameargs),
  857. .pc_ressize = sizeof(struct nfsd3_renameres),
  858. .pc_cachetype = RC_REPLBUFF,
  859. .pc_xdrressize = ST+WC+WC,
  860. .pc_name = "RENAME",
  861. },
  862. [NFS3PROC_LINK] = {
  863. .pc_func = nfsd3_proc_link,
  864. .pc_decode = nfs3svc_decode_linkargs,
  865. .pc_encode = nfs3svc_encode_linkres,
  866. .pc_release = nfs3svc_release_fhandle2,
  867. .pc_argsize = sizeof(struct nfsd3_linkargs),
  868. .pc_argzero = sizeof(struct nfsd3_linkargs),
  869. .pc_ressize = sizeof(struct nfsd3_linkres),
  870. .pc_cachetype = RC_REPLBUFF,
  871. .pc_xdrressize = ST+pAT+WC,
  872. .pc_name = "LINK",
  873. },
  874. [NFS3PROC_READDIR] = {
  875. .pc_func = nfsd3_proc_readdir,
  876. .pc_decode = nfs3svc_decode_readdirargs,
  877. .pc_encode = nfs3svc_encode_readdirres,
  878. .pc_release = nfs3svc_release_fhandle,
  879. .pc_argsize = sizeof(struct nfsd3_readdirargs),
  880. .pc_argzero = sizeof(struct nfsd3_readdirargs),
  881. .pc_ressize = sizeof(struct nfsd3_readdirres),
  882. .pc_cachetype = RC_NOCACHE,
  883. .pc_name = "READDIR",
  884. },
  885. [NFS3PROC_READDIRPLUS] = {
  886. .pc_func = nfsd3_proc_readdirplus,
  887. .pc_decode = nfs3svc_decode_readdirplusargs,
  888. .pc_encode = nfs3svc_encode_readdirres,
  889. .pc_release = nfs3svc_release_fhandle,
  890. .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
  891. .pc_argzero = sizeof(struct nfsd3_readdirplusargs),
  892. .pc_ressize = sizeof(struct nfsd3_readdirres),
  893. .pc_cachetype = RC_NOCACHE,
  894. .pc_name = "READDIRPLUS",
  895. },
  896. [NFS3PROC_FSSTAT] = {
  897. .pc_func = nfsd3_proc_fsstat,
  898. .pc_decode = nfs3svc_decode_fhandleargs,
  899. .pc_encode = nfs3svc_encode_fsstatres,
  900. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  901. .pc_argzero = sizeof(struct nfsd3_fhandleargs),
  902. .pc_ressize = sizeof(struct nfsd3_fsstatres),
  903. .pc_cachetype = RC_NOCACHE,
  904. .pc_xdrressize = ST+pAT+2*6+1,
  905. .pc_name = "FSSTAT",
  906. },
  907. [NFS3PROC_FSINFO] = {
  908. .pc_func = nfsd3_proc_fsinfo,
  909. .pc_decode = nfs3svc_decode_fhandleargs,
  910. .pc_encode = nfs3svc_encode_fsinfores,
  911. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  912. .pc_argzero = sizeof(struct nfsd3_fhandleargs),
  913. .pc_ressize = sizeof(struct nfsd3_fsinfores),
  914. .pc_cachetype = RC_NOCACHE,
  915. .pc_xdrressize = ST+pAT+12,
  916. .pc_name = "FSINFO",
  917. },
  918. [NFS3PROC_PATHCONF] = {
  919. .pc_func = nfsd3_proc_pathconf,
  920. .pc_decode = nfs3svc_decode_fhandleargs,
  921. .pc_encode = nfs3svc_encode_pathconfres,
  922. .pc_argsize = sizeof(struct nfsd3_fhandleargs),
  923. .pc_argzero = sizeof(struct nfsd3_fhandleargs),
  924. .pc_ressize = sizeof(struct nfsd3_pathconfres),
  925. .pc_cachetype = RC_NOCACHE,
  926. .pc_xdrressize = ST+pAT+6,
  927. .pc_name = "PATHCONF",
  928. },
  929. [NFS3PROC_COMMIT] = {
  930. .pc_func = nfsd3_proc_commit,
  931. .pc_decode = nfs3svc_decode_commitargs,
  932. .pc_encode = nfs3svc_encode_commitres,
  933. .pc_release = nfs3svc_release_fhandle,
  934. .pc_argsize = sizeof(struct nfsd3_commitargs),
  935. .pc_argzero = sizeof(struct nfsd3_commitargs),
  936. .pc_ressize = sizeof(struct nfsd3_commitres),
  937. .pc_cachetype = RC_NOCACHE,
  938. .pc_xdrressize = ST+WC+2,
  939. .pc_name = "COMMIT",
  940. },
  941. };
  942. static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
  943. const struct svc_version nfsd_version3 = {
  944. .vs_vers = 3,
  945. .vs_nproc = 22,
  946. .vs_proc = nfsd_procedures3,
  947. .vs_dispatch = nfsd_dispatch,
  948. .vs_count = nfsd_count3,
  949. .vs_xdrsize = NFS3_SVC_XDRSIZE,
  950. };