nfs3proc.c 24 KB

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