nfs3proc.c 24 KB

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