nfs3proc.c 24 KB

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