nfs3proc.c 24 KB

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