nfs3xdr.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * XDR support for nfsd/protocol version 3.
  4. *
  5. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <[email protected]>
  6. *
  7. * 2003-08-09 Jamie Lokier: Use htonl() for nanoseconds, not htons()!
  8. */
  9. #include <linux/namei.h>
  10. #include <linux/sunrpc/svc_xprt.h>
  11. #include "xdr3.h"
  12. #include "auth.h"
  13. #include "netns.h"
  14. #include "vfs.h"
  15. /*
  16. * Force construction of an empty post-op attr
  17. */
  18. static const struct svc_fh nfs3svc_null_fh = {
  19. .fh_no_wcc = true,
  20. };
  21. /*
  22. * time_delta. {1, 0} means the server is accurate only
  23. * to the nearest second.
  24. */
  25. static const struct timespec64 nfs3svc_time_delta = {
  26. .tv_sec = 1,
  27. .tv_nsec = 0,
  28. };
  29. /*
  30. * Mapping of S_IF* types to NFS file types
  31. */
  32. static const u32 nfs3_ftypes[] = {
  33. NF3NON, NF3FIFO, NF3CHR, NF3BAD,
  34. NF3DIR, NF3BAD, NF3BLK, NF3BAD,
  35. NF3REG, NF3BAD, NF3LNK, NF3BAD,
  36. NF3SOCK, NF3BAD, NF3LNK, NF3BAD,
  37. };
  38. /*
  39. * Basic NFSv3 data types (RFC 1813 Sections 2.5 and 2.6)
  40. */
  41. static __be32 *
  42. encode_nfstime3(__be32 *p, const struct timespec64 *time)
  43. {
  44. *p++ = cpu_to_be32((u32)time->tv_sec);
  45. *p++ = cpu_to_be32(time->tv_nsec);
  46. return p;
  47. }
  48. static bool
  49. svcxdr_decode_nfstime3(struct xdr_stream *xdr, struct timespec64 *timep)
  50. {
  51. __be32 *p;
  52. p = xdr_inline_decode(xdr, XDR_UNIT * 2);
  53. if (!p)
  54. return false;
  55. timep->tv_sec = be32_to_cpup(p++);
  56. timep->tv_nsec = be32_to_cpup(p);
  57. return true;
  58. }
  59. /**
  60. * svcxdr_decode_nfs_fh3 - Decode an NFSv3 file handle
  61. * @xdr: XDR stream positioned at an undecoded NFSv3 FH
  62. * @fhp: OUT: filled-in server file handle
  63. *
  64. * Return values:
  65. * %false: The encoded file handle was not valid
  66. * %true: @fhp has been initialized
  67. */
  68. bool
  69. svcxdr_decode_nfs_fh3(struct xdr_stream *xdr, struct svc_fh *fhp)
  70. {
  71. __be32 *p;
  72. u32 size;
  73. if (xdr_stream_decode_u32(xdr, &size) < 0)
  74. return false;
  75. if (size == 0 || size > NFS3_FHSIZE)
  76. return false;
  77. p = xdr_inline_decode(xdr, size);
  78. if (!p)
  79. return false;
  80. fh_init(fhp, NFS3_FHSIZE);
  81. fhp->fh_handle.fh_size = size;
  82. memcpy(&fhp->fh_handle.fh_raw, p, size);
  83. return true;
  84. }
  85. /**
  86. * svcxdr_encode_nfsstat3 - Encode an NFSv3 status code
  87. * @xdr: XDR stream
  88. * @status: status value to encode
  89. *
  90. * Return values:
  91. * %false: Send buffer space was exhausted
  92. * %true: Success
  93. */
  94. bool
  95. svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status)
  96. {
  97. __be32 *p;
  98. p = xdr_reserve_space(xdr, sizeof(status));
  99. if (!p)
  100. return false;
  101. *p = status;
  102. return true;
  103. }
  104. static bool
  105. svcxdr_encode_nfs_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp)
  106. {
  107. u32 size = fhp->fh_handle.fh_size;
  108. __be32 *p;
  109. p = xdr_reserve_space(xdr, XDR_UNIT + size);
  110. if (!p)
  111. return false;
  112. *p++ = cpu_to_be32(size);
  113. if (size)
  114. p[XDR_QUADLEN(size) - 1] = 0;
  115. memcpy(p, &fhp->fh_handle.fh_raw, size);
  116. return true;
  117. }
  118. static bool
  119. svcxdr_encode_post_op_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp)
  120. {
  121. if (xdr_stream_encode_item_present(xdr) < 0)
  122. return false;
  123. if (!svcxdr_encode_nfs_fh3(xdr, fhp))
  124. return false;
  125. return true;
  126. }
  127. static bool
  128. svcxdr_encode_cookieverf3(struct xdr_stream *xdr, const __be32 *verf)
  129. {
  130. __be32 *p;
  131. p = xdr_reserve_space(xdr, NFS3_COOKIEVERFSIZE);
  132. if (!p)
  133. return false;
  134. memcpy(p, verf, NFS3_COOKIEVERFSIZE);
  135. return true;
  136. }
  137. static bool
  138. svcxdr_encode_writeverf3(struct xdr_stream *xdr, const __be32 *verf)
  139. {
  140. __be32 *p;
  141. p = xdr_reserve_space(xdr, NFS3_WRITEVERFSIZE);
  142. if (!p)
  143. return false;
  144. memcpy(p, verf, NFS3_WRITEVERFSIZE);
  145. return true;
  146. }
  147. static bool
  148. svcxdr_decode_filename3(struct xdr_stream *xdr, char **name, unsigned int *len)
  149. {
  150. u32 size, i;
  151. __be32 *p;
  152. char *c;
  153. if (xdr_stream_decode_u32(xdr, &size) < 0)
  154. return false;
  155. if (size == 0 || size > NFS3_MAXNAMLEN)
  156. return false;
  157. p = xdr_inline_decode(xdr, size);
  158. if (!p)
  159. return false;
  160. *len = size;
  161. *name = (char *)p;
  162. for (i = 0, c = *name; i < size; i++, c++) {
  163. if (*c == '\0' || *c == '/')
  164. return false;
  165. }
  166. return true;
  167. }
  168. static bool
  169. svcxdr_decode_diropargs3(struct xdr_stream *xdr, struct svc_fh *fhp,
  170. char **name, unsigned int *len)
  171. {
  172. return svcxdr_decode_nfs_fh3(xdr, fhp) &&
  173. svcxdr_decode_filename3(xdr, name, len);
  174. }
  175. static bool
  176. svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  177. struct iattr *iap)
  178. {
  179. u32 set_it;
  180. iap->ia_valid = 0;
  181. if (xdr_stream_decode_bool(xdr, &set_it) < 0)
  182. return false;
  183. if (set_it) {
  184. u32 mode;
  185. if (xdr_stream_decode_u32(xdr, &mode) < 0)
  186. return false;
  187. iap->ia_valid |= ATTR_MODE;
  188. iap->ia_mode = mode;
  189. }
  190. if (xdr_stream_decode_bool(xdr, &set_it) < 0)
  191. return false;
  192. if (set_it) {
  193. u32 uid;
  194. if (xdr_stream_decode_u32(xdr, &uid) < 0)
  195. return false;
  196. iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), uid);
  197. if (uid_valid(iap->ia_uid))
  198. iap->ia_valid |= ATTR_UID;
  199. }
  200. if (xdr_stream_decode_bool(xdr, &set_it) < 0)
  201. return false;
  202. if (set_it) {
  203. u32 gid;
  204. if (xdr_stream_decode_u32(xdr, &gid) < 0)
  205. return false;
  206. iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), gid);
  207. if (gid_valid(iap->ia_gid))
  208. iap->ia_valid |= ATTR_GID;
  209. }
  210. if (xdr_stream_decode_bool(xdr, &set_it) < 0)
  211. return false;
  212. if (set_it) {
  213. u64 newsize;
  214. if (xdr_stream_decode_u64(xdr, &newsize) < 0)
  215. return false;
  216. iap->ia_valid |= ATTR_SIZE;
  217. iap->ia_size = newsize;
  218. }
  219. if (xdr_stream_decode_u32(xdr, &set_it) < 0)
  220. return false;
  221. switch (set_it) {
  222. case DONT_CHANGE:
  223. break;
  224. case SET_TO_SERVER_TIME:
  225. iap->ia_valid |= ATTR_ATIME;
  226. break;
  227. case SET_TO_CLIENT_TIME:
  228. if (!svcxdr_decode_nfstime3(xdr, &iap->ia_atime))
  229. return false;
  230. iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
  231. break;
  232. default:
  233. return false;
  234. }
  235. if (xdr_stream_decode_u32(xdr, &set_it) < 0)
  236. return false;
  237. switch (set_it) {
  238. case DONT_CHANGE:
  239. break;
  240. case SET_TO_SERVER_TIME:
  241. iap->ia_valid |= ATTR_MTIME;
  242. break;
  243. case SET_TO_CLIENT_TIME:
  244. if (!svcxdr_decode_nfstime3(xdr, &iap->ia_mtime))
  245. return false;
  246. iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
  247. break;
  248. default:
  249. return false;
  250. }
  251. return true;
  252. }
  253. static bool
  254. svcxdr_decode_sattrguard3(struct xdr_stream *xdr, struct nfsd3_sattrargs *args)
  255. {
  256. __be32 *p;
  257. u32 check;
  258. if (xdr_stream_decode_bool(xdr, &check) < 0)
  259. return false;
  260. if (check) {
  261. p = xdr_inline_decode(xdr, XDR_UNIT * 2);
  262. if (!p)
  263. return false;
  264. args->check_guard = 1;
  265. args->guardtime = be32_to_cpup(p);
  266. } else
  267. args->check_guard = 0;
  268. return true;
  269. }
  270. static bool
  271. svcxdr_decode_specdata3(struct xdr_stream *xdr, struct nfsd3_mknodargs *args)
  272. {
  273. __be32 *p;
  274. p = xdr_inline_decode(xdr, XDR_UNIT * 2);
  275. if (!p)
  276. return false;
  277. args->major = be32_to_cpup(p++);
  278. args->minor = be32_to_cpup(p);
  279. return true;
  280. }
  281. static bool
  282. svcxdr_decode_devicedata3(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  283. struct nfsd3_mknodargs *args)
  284. {
  285. return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) &&
  286. svcxdr_decode_specdata3(xdr, args);
  287. }
  288. static bool
  289. svcxdr_encode_fattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  290. const struct svc_fh *fhp, const struct kstat *stat)
  291. {
  292. struct user_namespace *userns = nfsd_user_namespace(rqstp);
  293. __be32 *p;
  294. u64 fsid;
  295. p = xdr_reserve_space(xdr, XDR_UNIT * 21);
  296. if (!p)
  297. return false;
  298. *p++ = cpu_to_be32(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
  299. *p++ = cpu_to_be32((u32)(stat->mode & S_IALLUGO));
  300. *p++ = cpu_to_be32((u32)stat->nlink);
  301. *p++ = cpu_to_be32((u32)from_kuid_munged(userns, stat->uid));
  302. *p++ = cpu_to_be32((u32)from_kgid_munged(userns, stat->gid));
  303. if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN)
  304. p = xdr_encode_hyper(p, (u64)NFS3_MAXPATHLEN);
  305. else
  306. p = xdr_encode_hyper(p, (u64)stat->size);
  307. /* used */
  308. p = xdr_encode_hyper(p, ((u64)stat->blocks) << 9);
  309. /* rdev */
  310. *p++ = cpu_to_be32((u32)MAJOR(stat->rdev));
  311. *p++ = cpu_to_be32((u32)MINOR(stat->rdev));
  312. switch(fsid_source(fhp)) {
  313. case FSIDSOURCE_FSID:
  314. fsid = (u64)fhp->fh_export->ex_fsid;
  315. break;
  316. case FSIDSOURCE_UUID:
  317. fsid = ((u64 *)fhp->fh_export->ex_uuid)[0];
  318. fsid ^= ((u64 *)fhp->fh_export->ex_uuid)[1];
  319. break;
  320. default:
  321. fsid = (u64)huge_encode_dev(fhp->fh_dentry->d_sb->s_dev);
  322. }
  323. p = xdr_encode_hyper(p, fsid);
  324. /* fileid */
  325. p = xdr_encode_hyper(p, stat->ino);
  326. p = encode_nfstime3(p, &stat->atime);
  327. p = encode_nfstime3(p, &stat->mtime);
  328. encode_nfstime3(p, &stat->ctime);
  329. return true;
  330. }
  331. static bool
  332. svcxdr_encode_wcc_attr(struct xdr_stream *xdr, const struct svc_fh *fhp)
  333. {
  334. __be32 *p;
  335. p = xdr_reserve_space(xdr, XDR_UNIT * 6);
  336. if (!p)
  337. return false;
  338. p = xdr_encode_hyper(p, (u64)fhp->fh_pre_size);
  339. p = encode_nfstime3(p, &fhp->fh_pre_mtime);
  340. encode_nfstime3(p, &fhp->fh_pre_ctime);
  341. return true;
  342. }
  343. static bool
  344. svcxdr_encode_pre_op_attr(struct xdr_stream *xdr, const struct svc_fh *fhp)
  345. {
  346. if (!fhp->fh_pre_saved) {
  347. if (xdr_stream_encode_item_absent(xdr) < 0)
  348. return false;
  349. return true;
  350. }
  351. if (xdr_stream_encode_item_present(xdr) < 0)
  352. return false;
  353. return svcxdr_encode_wcc_attr(xdr, fhp);
  354. }
  355. /**
  356. * svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes
  357. * @rqstp: Context of a completed RPC transaction
  358. * @xdr: XDR stream
  359. * @fhp: File handle to encode
  360. *
  361. * Return values:
  362. * %false: Send buffer space was exhausted
  363. * %true: Success
  364. */
  365. bool
  366. svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  367. const struct svc_fh *fhp)
  368. {
  369. struct dentry *dentry = fhp->fh_dentry;
  370. struct kstat stat;
  371. /*
  372. * The inode may be NULL if the call failed because of a
  373. * stale file handle. In this case, no attributes are
  374. * returned.
  375. */
  376. if (fhp->fh_no_wcc || !dentry || !d_really_is_positive(dentry))
  377. goto no_post_op_attrs;
  378. if (fh_getattr(fhp, &stat) != nfs_ok)
  379. goto no_post_op_attrs;
  380. if (xdr_stream_encode_item_present(xdr) < 0)
  381. return false;
  382. lease_get_mtime(d_inode(dentry), &stat.mtime);
  383. if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &stat))
  384. return false;
  385. return true;
  386. no_post_op_attrs:
  387. return xdr_stream_encode_item_absent(xdr) > 0;
  388. }
  389. /*
  390. * Encode weak cache consistency data
  391. */
  392. static bool
  393. svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  394. const struct svc_fh *fhp)
  395. {
  396. struct dentry *dentry = fhp->fh_dentry;
  397. if (!dentry || !d_really_is_positive(dentry) || !fhp->fh_post_saved)
  398. goto neither;
  399. /* before */
  400. if (!svcxdr_encode_pre_op_attr(xdr, fhp))
  401. return false;
  402. /* after */
  403. if (xdr_stream_encode_item_present(xdr) < 0)
  404. return false;
  405. if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &fhp->fh_post_attr))
  406. return false;
  407. return true;
  408. neither:
  409. if (xdr_stream_encode_item_absent(xdr) < 0)
  410. return false;
  411. if (!svcxdr_encode_post_op_attr(rqstp, xdr, fhp))
  412. return false;
  413. return true;
  414. }
  415. /*
  416. * XDR decode functions
  417. */
  418. bool
  419. nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  420. {
  421. struct nfsd_fhandle *args = rqstp->rq_argp;
  422. return svcxdr_decode_nfs_fh3(xdr, &args->fh);
  423. }
  424. bool
  425. nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  426. {
  427. struct nfsd3_sattrargs *args = rqstp->rq_argp;
  428. return svcxdr_decode_nfs_fh3(xdr, &args->fh) &&
  429. svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) &&
  430. svcxdr_decode_sattrguard3(xdr, args);
  431. }
  432. bool
  433. nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  434. {
  435. struct nfsd3_diropargs *args = rqstp->rq_argp;
  436. return svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len);
  437. }
  438. bool
  439. nfs3svc_decode_accessargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  440. {
  441. struct nfsd3_accessargs *args = rqstp->rq_argp;
  442. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  443. return false;
  444. if (xdr_stream_decode_u32(xdr, &args->access) < 0)
  445. return false;
  446. return true;
  447. }
  448. bool
  449. nfs3svc_decode_readargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  450. {
  451. struct nfsd3_readargs *args = rqstp->rq_argp;
  452. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  453. return false;
  454. if (xdr_stream_decode_u64(xdr, &args->offset) < 0)
  455. return false;
  456. if (xdr_stream_decode_u32(xdr, &args->count) < 0)
  457. return false;
  458. return true;
  459. }
  460. bool
  461. nfs3svc_decode_writeargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  462. {
  463. struct nfsd3_writeargs *args = rqstp->rq_argp;
  464. u32 max_blocksize = svc_max_payload(rqstp);
  465. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  466. return false;
  467. if (xdr_stream_decode_u64(xdr, &args->offset) < 0)
  468. return false;
  469. if (xdr_stream_decode_u32(xdr, &args->count) < 0)
  470. return false;
  471. if (xdr_stream_decode_u32(xdr, &args->stable) < 0)
  472. return false;
  473. /* opaque data */
  474. if (xdr_stream_decode_u32(xdr, &args->len) < 0)
  475. return false;
  476. /* request sanity */
  477. if (args->count != args->len)
  478. return false;
  479. if (args->count > max_blocksize) {
  480. args->count = max_blocksize;
  481. args->len = max_blocksize;
  482. }
  483. return xdr_stream_subsegment(xdr, &args->payload, args->count);
  484. }
  485. bool
  486. nfs3svc_decode_createargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  487. {
  488. struct nfsd3_createargs *args = rqstp->rq_argp;
  489. if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len))
  490. return false;
  491. if (xdr_stream_decode_u32(xdr, &args->createmode) < 0)
  492. return false;
  493. switch (args->createmode) {
  494. case NFS3_CREATE_UNCHECKED:
  495. case NFS3_CREATE_GUARDED:
  496. return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs);
  497. case NFS3_CREATE_EXCLUSIVE:
  498. args->verf = xdr_inline_decode(xdr, NFS3_CREATEVERFSIZE);
  499. if (!args->verf)
  500. return false;
  501. break;
  502. default:
  503. return false;
  504. }
  505. return true;
  506. }
  507. bool
  508. nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  509. {
  510. struct nfsd3_createargs *args = rqstp->rq_argp;
  511. return svcxdr_decode_diropargs3(xdr, &args->fh,
  512. &args->name, &args->len) &&
  513. svcxdr_decode_sattr3(rqstp, xdr, &args->attrs);
  514. }
  515. bool
  516. nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  517. {
  518. struct nfsd3_symlinkargs *args = rqstp->rq_argp;
  519. struct kvec *head = rqstp->rq_arg.head;
  520. if (!svcxdr_decode_diropargs3(xdr, &args->ffh, &args->fname, &args->flen))
  521. return false;
  522. if (!svcxdr_decode_sattr3(rqstp, xdr, &args->attrs))
  523. return false;
  524. if (xdr_stream_decode_u32(xdr, &args->tlen) < 0)
  525. return false;
  526. /* symlink_data */
  527. args->first.iov_len = head->iov_len - xdr_stream_pos(xdr);
  528. args->first.iov_base = xdr_inline_decode(xdr, args->tlen);
  529. return args->first.iov_base != NULL;
  530. }
  531. bool
  532. nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  533. {
  534. struct nfsd3_mknodargs *args = rqstp->rq_argp;
  535. if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len))
  536. return false;
  537. if (xdr_stream_decode_u32(xdr, &args->ftype) < 0)
  538. return false;
  539. switch (args->ftype) {
  540. case NF3CHR:
  541. case NF3BLK:
  542. return svcxdr_decode_devicedata3(rqstp, xdr, args);
  543. case NF3SOCK:
  544. case NF3FIFO:
  545. return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs);
  546. case NF3REG:
  547. case NF3DIR:
  548. case NF3LNK:
  549. /* Valid XDR but illegal file types */
  550. break;
  551. default:
  552. return false;
  553. }
  554. return true;
  555. }
  556. bool
  557. nfs3svc_decode_renameargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  558. {
  559. struct nfsd3_renameargs *args = rqstp->rq_argp;
  560. return svcxdr_decode_diropargs3(xdr, &args->ffh,
  561. &args->fname, &args->flen) &&
  562. svcxdr_decode_diropargs3(xdr, &args->tfh,
  563. &args->tname, &args->tlen);
  564. }
  565. bool
  566. nfs3svc_decode_linkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  567. {
  568. struct nfsd3_linkargs *args = rqstp->rq_argp;
  569. return svcxdr_decode_nfs_fh3(xdr, &args->ffh) &&
  570. svcxdr_decode_diropargs3(xdr, &args->tfh,
  571. &args->tname, &args->tlen);
  572. }
  573. bool
  574. nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  575. {
  576. struct nfsd3_readdirargs *args = rqstp->rq_argp;
  577. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  578. return false;
  579. if (xdr_stream_decode_u64(xdr, &args->cookie) < 0)
  580. return false;
  581. args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
  582. if (!args->verf)
  583. return false;
  584. if (xdr_stream_decode_u32(xdr, &args->count) < 0)
  585. return false;
  586. return true;
  587. }
  588. bool
  589. nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  590. {
  591. struct nfsd3_readdirargs *args = rqstp->rq_argp;
  592. u32 dircount;
  593. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  594. return false;
  595. if (xdr_stream_decode_u64(xdr, &args->cookie) < 0)
  596. return false;
  597. args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
  598. if (!args->verf)
  599. return false;
  600. /* dircount is ignored */
  601. if (xdr_stream_decode_u32(xdr, &dircount) < 0)
  602. return false;
  603. if (xdr_stream_decode_u32(xdr, &args->count) < 0)
  604. return false;
  605. return true;
  606. }
  607. bool
  608. nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  609. {
  610. struct nfsd3_commitargs *args = rqstp->rq_argp;
  611. if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
  612. return false;
  613. if (xdr_stream_decode_u64(xdr, &args->offset) < 0)
  614. return false;
  615. if (xdr_stream_decode_u32(xdr, &args->count) < 0)
  616. return false;
  617. return true;
  618. }
  619. /*
  620. * XDR encode functions
  621. */
  622. /* GETATTR */
  623. bool
  624. nfs3svc_encode_getattrres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  625. {
  626. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  627. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  628. return false;
  629. switch (resp->status) {
  630. case nfs_ok:
  631. lease_get_mtime(d_inode(resp->fh.fh_dentry), &resp->stat.mtime);
  632. if (!svcxdr_encode_fattr3(rqstp, xdr, &resp->fh, &resp->stat))
  633. return false;
  634. break;
  635. }
  636. return true;
  637. }
  638. /* SETATTR, REMOVE, RMDIR */
  639. bool
  640. nfs3svc_encode_wccstat(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  641. {
  642. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  643. return svcxdr_encode_nfsstat3(xdr, resp->status) &&
  644. svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh);
  645. }
  646. /* LOOKUP */
  647. bool
  648. nfs3svc_encode_lookupres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  649. {
  650. struct nfsd3_diropres *resp = rqstp->rq_resp;
  651. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  652. return false;
  653. switch (resp->status) {
  654. case nfs_ok:
  655. if (!svcxdr_encode_nfs_fh3(xdr, &resp->fh))
  656. return false;
  657. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  658. return false;
  659. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh))
  660. return false;
  661. break;
  662. default:
  663. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh))
  664. return false;
  665. }
  666. return true;
  667. }
  668. /* ACCESS */
  669. bool
  670. nfs3svc_encode_accessres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  671. {
  672. struct nfsd3_accessres *resp = rqstp->rq_resp;
  673. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  674. return false;
  675. switch (resp->status) {
  676. case nfs_ok:
  677. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  678. return false;
  679. if (xdr_stream_encode_u32(xdr, resp->access) < 0)
  680. return false;
  681. break;
  682. default:
  683. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  684. return false;
  685. }
  686. return true;
  687. }
  688. /* READLINK */
  689. bool
  690. nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  691. {
  692. struct nfsd3_readlinkres *resp = rqstp->rq_resp;
  693. struct kvec *head = rqstp->rq_res.head;
  694. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  695. return false;
  696. switch (resp->status) {
  697. case nfs_ok:
  698. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  699. return false;
  700. if (xdr_stream_encode_u32(xdr, resp->len) < 0)
  701. return false;
  702. xdr_write_pages(xdr, resp->pages, 0, resp->len);
  703. if (svc_encode_result_payload(rqstp, head->iov_len, resp->len) < 0)
  704. return false;
  705. break;
  706. default:
  707. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  708. return false;
  709. }
  710. return true;
  711. }
  712. /* READ */
  713. bool
  714. nfs3svc_encode_readres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  715. {
  716. struct nfsd3_readres *resp = rqstp->rq_resp;
  717. struct kvec *head = rqstp->rq_res.head;
  718. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  719. return false;
  720. switch (resp->status) {
  721. case nfs_ok:
  722. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  723. return false;
  724. if (xdr_stream_encode_u32(xdr, resp->count) < 0)
  725. return false;
  726. if (xdr_stream_encode_bool(xdr, resp->eof) < 0)
  727. return false;
  728. if (xdr_stream_encode_u32(xdr, resp->count) < 0)
  729. return false;
  730. xdr_write_pages(xdr, resp->pages, rqstp->rq_res.page_base,
  731. resp->count);
  732. if (svc_encode_result_payload(rqstp, head->iov_len, resp->count) < 0)
  733. return false;
  734. break;
  735. default:
  736. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  737. return false;
  738. }
  739. return true;
  740. }
  741. /* WRITE */
  742. bool
  743. nfs3svc_encode_writeres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  744. {
  745. struct nfsd3_writeres *resp = rqstp->rq_resp;
  746. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  747. return false;
  748. switch (resp->status) {
  749. case nfs_ok:
  750. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh))
  751. return false;
  752. if (xdr_stream_encode_u32(xdr, resp->count) < 0)
  753. return false;
  754. if (xdr_stream_encode_u32(xdr, resp->committed) < 0)
  755. return false;
  756. if (!svcxdr_encode_writeverf3(xdr, resp->verf))
  757. return false;
  758. break;
  759. default:
  760. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh))
  761. return false;
  762. }
  763. return true;
  764. }
  765. /* CREATE, MKDIR, SYMLINK, MKNOD */
  766. bool
  767. nfs3svc_encode_createres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  768. {
  769. struct nfsd3_diropres *resp = rqstp->rq_resp;
  770. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  771. return false;
  772. switch (resp->status) {
  773. case nfs_ok:
  774. if (!svcxdr_encode_post_op_fh3(xdr, &resp->fh))
  775. return false;
  776. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  777. return false;
  778. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh))
  779. return false;
  780. break;
  781. default:
  782. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh))
  783. return false;
  784. }
  785. return true;
  786. }
  787. /* RENAME */
  788. bool
  789. nfs3svc_encode_renameres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  790. {
  791. struct nfsd3_renameres *resp = rqstp->rq_resp;
  792. return svcxdr_encode_nfsstat3(xdr, resp->status) &&
  793. svcxdr_encode_wcc_data(rqstp, xdr, &resp->ffh) &&
  794. svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh);
  795. }
  796. /* LINK */
  797. bool
  798. nfs3svc_encode_linkres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  799. {
  800. struct nfsd3_linkres *resp = rqstp->rq_resp;
  801. return svcxdr_encode_nfsstat3(xdr, resp->status) &&
  802. svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh) &&
  803. svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh);
  804. }
  805. /* READDIR */
  806. bool
  807. nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  808. {
  809. struct nfsd3_readdirres *resp = rqstp->rq_resp;
  810. struct xdr_buf *dirlist = &resp->dirlist;
  811. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  812. return false;
  813. switch (resp->status) {
  814. case nfs_ok:
  815. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  816. return false;
  817. if (!svcxdr_encode_cookieverf3(xdr, resp->verf))
  818. return false;
  819. xdr_write_pages(xdr, dirlist->pages, 0, dirlist->len);
  820. /* no more entries */
  821. if (xdr_stream_encode_item_absent(xdr) < 0)
  822. return false;
  823. if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0)
  824. return false;
  825. break;
  826. default:
  827. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
  828. return false;
  829. }
  830. return true;
  831. }
  832. static __be32
  833. compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
  834. const char *name, int namlen, u64 ino)
  835. {
  836. struct svc_export *exp;
  837. struct dentry *dparent, *dchild;
  838. __be32 rv = nfserr_noent;
  839. dparent = cd->fh.fh_dentry;
  840. exp = cd->fh.fh_export;
  841. if (isdotent(name, namlen)) {
  842. if (namlen == 2) {
  843. dchild = dget_parent(dparent);
  844. /*
  845. * Don't return filehandle for ".." if we're at
  846. * the filesystem or export root:
  847. */
  848. if (dchild == dparent)
  849. goto out;
  850. if (dparent == exp->ex_path.dentry)
  851. goto out;
  852. } else
  853. dchild = dget(dparent);
  854. } else
  855. dchild = lookup_positive_unlocked(name, dparent, namlen);
  856. if (IS_ERR(dchild))
  857. return rv;
  858. if (d_mountpoint(dchild))
  859. goto out;
  860. if (dchild->d_inode->i_ino != ino)
  861. goto out;
  862. rv = fh_compose(fhp, exp, dchild, &cd->fh);
  863. out:
  864. dput(dchild);
  865. return rv;
  866. }
  867. /**
  868. * nfs3svc_encode_cookie3 - Encode a directory offset cookie
  869. * @resp: readdir result context
  870. * @offset: offset cookie to encode
  871. *
  872. * The buffer space for the offset cookie has already been reserved
  873. * by svcxdr_encode_entry3_common().
  874. */
  875. void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset)
  876. {
  877. __be64 cookie = cpu_to_be64(offset);
  878. if (!resp->cookie_offset)
  879. return;
  880. write_bytes_to_xdr_buf(&resp->dirlist, resp->cookie_offset, &cookie,
  881. sizeof(cookie));
  882. resp->cookie_offset = 0;
  883. }
  884. static bool
  885. svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name,
  886. int namlen, loff_t offset, u64 ino)
  887. {
  888. struct xdr_buf *dirlist = &resp->dirlist;
  889. struct xdr_stream *xdr = &resp->xdr;
  890. if (xdr_stream_encode_item_present(xdr) < 0)
  891. return false;
  892. /* fileid */
  893. if (xdr_stream_encode_u64(xdr, ino) < 0)
  894. return false;
  895. /* name */
  896. if (xdr_stream_encode_opaque(xdr, name, min(namlen, NFS3_MAXNAMLEN)) < 0)
  897. return false;
  898. /* cookie */
  899. resp->cookie_offset = dirlist->len;
  900. if (xdr_stream_encode_u64(xdr, OFFSET_MAX) < 0)
  901. return false;
  902. return true;
  903. }
  904. /**
  905. * nfs3svc_encode_entry3 - encode one NFSv3 READDIR entry
  906. * @data: directory context
  907. * @name: name of the object to be encoded
  908. * @namlen: length of that name, in bytes
  909. * @offset: the offset of the previous entry
  910. * @ino: the fileid of this entry
  911. * @d_type: unused
  912. *
  913. * Return values:
  914. * %0: Entry was successfully encoded.
  915. * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err
  916. *
  917. * On exit, the following fields are updated:
  918. * - resp->xdr
  919. * - resp->common.err
  920. * - resp->cookie_offset
  921. */
  922. int nfs3svc_encode_entry3(void *data, const char *name, int namlen,
  923. loff_t offset, u64 ino, unsigned int d_type)
  924. {
  925. struct readdir_cd *ccd = data;
  926. struct nfsd3_readdirres *resp = container_of(ccd,
  927. struct nfsd3_readdirres,
  928. common);
  929. unsigned int starting_length = resp->dirlist.len;
  930. /* The offset cookie for the previous entry */
  931. nfs3svc_encode_cookie3(resp, offset);
  932. if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino))
  933. goto out_toosmall;
  934. xdr_commit_encode(&resp->xdr);
  935. resp->common.err = nfs_ok;
  936. return 0;
  937. out_toosmall:
  938. resp->cookie_offset = 0;
  939. resp->common.err = nfserr_toosmall;
  940. resp->dirlist.len = starting_length;
  941. return -EINVAL;
  942. }
  943. static bool
  944. svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name,
  945. int namlen, u64 ino)
  946. {
  947. struct xdr_stream *xdr = &resp->xdr;
  948. struct svc_fh *fhp = &resp->scratch;
  949. bool result;
  950. result = false;
  951. fh_init(fhp, NFS3_FHSIZE);
  952. if (compose_entry_fh(resp, fhp, name, namlen, ino) != nfs_ok)
  953. goto out_noattrs;
  954. if (!svcxdr_encode_post_op_attr(resp->rqstp, xdr, fhp))
  955. goto out;
  956. if (!svcxdr_encode_post_op_fh3(xdr, fhp))
  957. goto out;
  958. result = true;
  959. out:
  960. fh_put(fhp);
  961. return result;
  962. out_noattrs:
  963. if (xdr_stream_encode_item_absent(xdr) < 0)
  964. return false;
  965. if (xdr_stream_encode_item_absent(xdr) < 0)
  966. return false;
  967. return true;
  968. }
  969. /**
  970. * nfs3svc_encode_entryplus3 - encode one NFSv3 READDIRPLUS entry
  971. * @data: directory context
  972. * @name: name of the object to be encoded
  973. * @namlen: length of that name, in bytes
  974. * @offset: the offset of the previous entry
  975. * @ino: the fileid of this entry
  976. * @d_type: unused
  977. *
  978. * Return values:
  979. * %0: Entry was successfully encoded.
  980. * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err
  981. *
  982. * On exit, the following fields are updated:
  983. * - resp->xdr
  984. * - resp->common.err
  985. * - resp->cookie_offset
  986. */
  987. int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen,
  988. loff_t offset, u64 ino, unsigned int d_type)
  989. {
  990. struct readdir_cd *ccd = data;
  991. struct nfsd3_readdirres *resp = container_of(ccd,
  992. struct nfsd3_readdirres,
  993. common);
  994. unsigned int starting_length = resp->dirlist.len;
  995. /* The offset cookie for the previous entry */
  996. nfs3svc_encode_cookie3(resp, offset);
  997. if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino))
  998. goto out_toosmall;
  999. if (!svcxdr_encode_entry3_plus(resp, name, namlen, ino))
  1000. goto out_toosmall;
  1001. xdr_commit_encode(&resp->xdr);
  1002. resp->common.err = nfs_ok;
  1003. return 0;
  1004. out_toosmall:
  1005. resp->cookie_offset = 0;
  1006. resp->common.err = nfserr_toosmall;
  1007. resp->dirlist.len = starting_length;
  1008. return -EINVAL;
  1009. }
  1010. static bool
  1011. svcxdr_encode_fsstat3resok(struct xdr_stream *xdr,
  1012. const struct nfsd3_fsstatres *resp)
  1013. {
  1014. const struct kstatfs *s = &resp->stats;
  1015. u64 bs = s->f_bsize;
  1016. __be32 *p;
  1017. p = xdr_reserve_space(xdr, XDR_UNIT * 13);
  1018. if (!p)
  1019. return false;
  1020. p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */
  1021. p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */
  1022. p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */
  1023. p = xdr_encode_hyper(p, s->f_files); /* total inodes */
  1024. p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */
  1025. p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */
  1026. *p = cpu_to_be32(resp->invarsec); /* mean unchanged time */
  1027. return true;
  1028. }
  1029. /* FSSTAT */
  1030. bool
  1031. nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  1032. {
  1033. struct nfsd3_fsstatres *resp = rqstp->rq_resp;
  1034. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  1035. return false;
  1036. switch (resp->status) {
  1037. case nfs_ok:
  1038. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1039. return false;
  1040. if (!svcxdr_encode_fsstat3resok(xdr, resp))
  1041. return false;
  1042. break;
  1043. default:
  1044. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1045. return false;
  1046. }
  1047. return true;
  1048. }
  1049. static bool
  1050. svcxdr_encode_fsinfo3resok(struct xdr_stream *xdr,
  1051. const struct nfsd3_fsinfores *resp)
  1052. {
  1053. __be32 *p;
  1054. p = xdr_reserve_space(xdr, XDR_UNIT * 12);
  1055. if (!p)
  1056. return false;
  1057. *p++ = cpu_to_be32(resp->f_rtmax);
  1058. *p++ = cpu_to_be32(resp->f_rtpref);
  1059. *p++ = cpu_to_be32(resp->f_rtmult);
  1060. *p++ = cpu_to_be32(resp->f_wtmax);
  1061. *p++ = cpu_to_be32(resp->f_wtpref);
  1062. *p++ = cpu_to_be32(resp->f_wtmult);
  1063. *p++ = cpu_to_be32(resp->f_dtpref);
  1064. p = xdr_encode_hyper(p, resp->f_maxfilesize);
  1065. p = encode_nfstime3(p, &nfs3svc_time_delta);
  1066. *p = cpu_to_be32(resp->f_properties);
  1067. return true;
  1068. }
  1069. /* FSINFO */
  1070. bool
  1071. nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  1072. {
  1073. struct nfsd3_fsinfores *resp = rqstp->rq_resp;
  1074. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  1075. return false;
  1076. switch (resp->status) {
  1077. case nfs_ok:
  1078. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1079. return false;
  1080. if (!svcxdr_encode_fsinfo3resok(xdr, resp))
  1081. return false;
  1082. break;
  1083. default:
  1084. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1085. return false;
  1086. }
  1087. return true;
  1088. }
  1089. static bool
  1090. svcxdr_encode_pathconf3resok(struct xdr_stream *xdr,
  1091. const struct nfsd3_pathconfres *resp)
  1092. {
  1093. __be32 *p;
  1094. p = xdr_reserve_space(xdr, XDR_UNIT * 6);
  1095. if (!p)
  1096. return false;
  1097. *p++ = cpu_to_be32(resp->p_link_max);
  1098. *p++ = cpu_to_be32(resp->p_name_max);
  1099. p = xdr_encode_bool(p, resp->p_no_trunc);
  1100. p = xdr_encode_bool(p, resp->p_chown_restricted);
  1101. p = xdr_encode_bool(p, resp->p_case_insensitive);
  1102. xdr_encode_bool(p, resp->p_case_preserving);
  1103. return true;
  1104. }
  1105. /* PATHCONF */
  1106. bool
  1107. nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  1108. {
  1109. struct nfsd3_pathconfres *resp = rqstp->rq_resp;
  1110. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  1111. return false;
  1112. switch (resp->status) {
  1113. case nfs_ok:
  1114. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1115. return false;
  1116. if (!svcxdr_encode_pathconf3resok(xdr, resp))
  1117. return false;
  1118. break;
  1119. default:
  1120. if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
  1121. return false;
  1122. }
  1123. return true;
  1124. }
  1125. /* COMMIT */
  1126. bool
  1127. nfs3svc_encode_commitres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  1128. {
  1129. struct nfsd3_commitres *resp = rqstp->rq_resp;
  1130. if (!svcxdr_encode_nfsstat3(xdr, resp->status))
  1131. return false;
  1132. switch (resp->status) {
  1133. case nfs_ok:
  1134. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh))
  1135. return false;
  1136. if (!svcxdr_encode_writeverf3(xdr, resp->verf))
  1137. return false;
  1138. break;
  1139. default:
  1140. if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh))
  1141. return false;
  1142. }
  1143. return true;
  1144. }
  1145. /*
  1146. * XDR release functions
  1147. */
  1148. void
  1149. nfs3svc_release_fhandle(struct svc_rqst *rqstp)
  1150. {
  1151. struct nfsd3_attrstat *resp = rqstp->rq_resp;
  1152. fh_put(&resp->fh);
  1153. }
  1154. void
  1155. nfs3svc_release_fhandle2(struct svc_rqst *rqstp)
  1156. {
  1157. struct nfsd3_fhandle_pair *resp = rqstp->rq_resp;
  1158. fh_put(&resp->fh1);
  1159. fh_put(&resp->fh2);
  1160. }