nfs3proc.c 25 KB

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