nfs3proc.c 25 KB

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