nfs3xdr.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/nfs/nfs3xdr.c
  4. *
  5. * XDR functions to encode/decode NFSv3 RPC arguments and results.
  6. *
  7. * Copyright (C) 1996, 1997 Olaf Kirch
  8. */
  9. #include <linux/param.h>
  10. #include <linux/time.h>
  11. #include <linux/mm.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/in.h>
  15. #include <linux/pagemap.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/kdev_t.h>
  18. #include <linux/sunrpc/clnt.h>
  19. #include <linux/nfs.h>
  20. #include <linux/nfs3.h>
  21. #include <linux/nfs_fs.h>
  22. #include <linux/nfsacl.h>
  23. #include "nfstrace.h"
  24. #include "internal.h"
  25. #define NFSDBG_FACILITY NFSDBG_XDR
  26. /* Mapping from NFS error code to "errno" error code. */
  27. #define errno_NFSERR_IO EIO
  28. /*
  29. * Declare the space requirements for NFS arguments and replies as
  30. * number of 32bit-words
  31. */
  32. #define NFS3_pagepad_sz (1) /* Page padding */
  33. #define NFS3_fhandle_sz (1+16)
  34. #define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
  35. #define NFS3_post_op_fh_sz (1+NFS3_fh_sz)
  36. #define NFS3_sattr_sz (15)
  37. #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
  38. #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
  39. #define NFS3_fattr_sz (21)
  40. #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2)
  41. #define NFS3_wcc_attr_sz (6)
  42. #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz)
  43. #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz)
  44. #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz)
  45. #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  46. #define NFS3_getattrargs_sz (NFS3_fh_sz)
  47. #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3)
  48. #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  49. #define NFS3_accessargs_sz (NFS3_fh_sz+1)
  50. #define NFS3_readlinkargs_sz (NFS3_fh_sz)
  51. #define NFS3_readargs_sz (NFS3_fh_sz+3)
  52. #define NFS3_writeargs_sz (NFS3_fh_sz+5)
  53. #define NFS3_createargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
  54. #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz)
  55. #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz)
  56. #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz)
  57. #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz)
  58. #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz)
  59. #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz)
  60. #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3)
  61. #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4)
  62. #define NFS3_commitargs_sz (NFS3_fh_sz+3)
  63. #define NFS3_getattrres_sz (1+NFS3_fattr_sz)
  64. #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz)
  65. #define NFS3_removeres_sz (NFS3_setattrres_sz)
  66. #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
  67. #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
  68. #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1+NFS3_pagepad_sz)
  69. #define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+NFS3_pagepad_sz)
  70. #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
  71. #define NFS3_createres_sz (1+NFS3_post_op_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
  72. #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
  73. #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
  74. #define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2+NFS3_pagepad_sz)
  75. #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
  76. #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
  77. #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
  78. #define NFS3_commitres_sz (1+NFS3_wcc_data_sz+2)
  79. #define ACL3_getaclargs_sz (NFS3_fh_sz+1)
  80. #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
  81. XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
  82. #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
  83. XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+\
  84. NFS3_pagepad_sz)
  85. #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
  86. static int nfs3_stat_to_errno(enum nfs_stat);
  87. /*
  88. * Map file type to S_IFMT bits
  89. */
  90. static const umode_t nfs_type2fmt[] = {
  91. [NF3BAD] = 0,
  92. [NF3REG] = S_IFREG,
  93. [NF3DIR] = S_IFDIR,
  94. [NF3BLK] = S_IFBLK,
  95. [NF3CHR] = S_IFCHR,
  96. [NF3LNK] = S_IFLNK,
  97. [NF3SOCK] = S_IFSOCK,
  98. [NF3FIFO] = S_IFIFO,
  99. };
  100. static struct user_namespace *rpc_userns(const struct rpc_clnt *clnt)
  101. {
  102. if (clnt && clnt->cl_cred)
  103. return clnt->cl_cred->user_ns;
  104. return &init_user_ns;
  105. }
  106. static struct user_namespace *rpc_rqst_userns(const struct rpc_rqst *rqstp)
  107. {
  108. if (rqstp->rq_task)
  109. return rpc_userns(rqstp->rq_task->tk_client);
  110. return &init_user_ns;
  111. }
  112. /*
  113. * Encode/decode NFSv3 basic data types
  114. *
  115. * Basic NFSv3 data types are defined in section 2.5 of RFC 1813:
  116. * "NFS Version 3 Protocol Specification".
  117. *
  118. * Not all basic data types have their own encoding and decoding
  119. * functions. For run-time efficiency, some data types are encoded
  120. * or decoded inline.
  121. */
  122. static void encode_uint32(struct xdr_stream *xdr, u32 value)
  123. {
  124. __be32 *p = xdr_reserve_space(xdr, 4);
  125. *p = cpu_to_be32(value);
  126. }
  127. static int decode_uint32(struct xdr_stream *xdr, u32 *value)
  128. {
  129. __be32 *p;
  130. p = xdr_inline_decode(xdr, 4);
  131. if (unlikely(!p))
  132. return -EIO;
  133. *value = be32_to_cpup(p);
  134. return 0;
  135. }
  136. static int decode_uint64(struct xdr_stream *xdr, u64 *value)
  137. {
  138. __be32 *p;
  139. p = xdr_inline_decode(xdr, 8);
  140. if (unlikely(!p))
  141. return -EIO;
  142. xdr_decode_hyper(p, value);
  143. return 0;
  144. }
  145. /*
  146. * fileid3
  147. *
  148. * typedef uint64 fileid3;
  149. */
  150. static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid)
  151. {
  152. return xdr_decode_hyper(p, fileid);
  153. }
  154. static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid)
  155. {
  156. return decode_uint64(xdr, fileid);
  157. }
  158. /*
  159. * filename3
  160. *
  161. * typedef string filename3<>;
  162. */
  163. static void encode_filename3(struct xdr_stream *xdr,
  164. const char *name, u32 length)
  165. {
  166. __be32 *p;
  167. WARN_ON_ONCE(length > NFS3_MAXNAMLEN);
  168. p = xdr_reserve_space(xdr, 4 + length);
  169. xdr_encode_opaque(p, name, length);
  170. }
  171. static int decode_inline_filename3(struct xdr_stream *xdr,
  172. const char **name, u32 *length)
  173. {
  174. __be32 *p;
  175. u32 count;
  176. p = xdr_inline_decode(xdr, 4);
  177. if (unlikely(!p))
  178. return -EIO;
  179. count = be32_to_cpup(p);
  180. if (count > NFS3_MAXNAMLEN)
  181. goto out_nametoolong;
  182. p = xdr_inline_decode(xdr, count);
  183. if (unlikely(!p))
  184. return -EIO;
  185. *name = (const char *)p;
  186. *length = count;
  187. return 0;
  188. out_nametoolong:
  189. dprintk("NFS: returned filename too long: %u\n", count);
  190. return -ENAMETOOLONG;
  191. }
  192. /*
  193. * nfspath3
  194. *
  195. * typedef string nfspath3<>;
  196. */
  197. static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages,
  198. const u32 length)
  199. {
  200. encode_uint32(xdr, length);
  201. xdr_write_pages(xdr, pages, 0, length);
  202. }
  203. static int decode_nfspath3(struct xdr_stream *xdr)
  204. {
  205. u32 recvd, count;
  206. __be32 *p;
  207. p = xdr_inline_decode(xdr, 4);
  208. if (unlikely(!p))
  209. return -EIO;
  210. count = be32_to_cpup(p);
  211. if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
  212. goto out_nametoolong;
  213. recvd = xdr_read_pages(xdr, count);
  214. if (unlikely(count > recvd))
  215. goto out_cheating;
  216. xdr_terminate_string(xdr->buf, count);
  217. return 0;
  218. out_nametoolong:
  219. dprintk("NFS: returned pathname too long: %u\n", count);
  220. return -ENAMETOOLONG;
  221. out_cheating:
  222. dprintk("NFS: server cheating in pathname result: "
  223. "count %u > recvd %u\n", count, recvd);
  224. return -EIO;
  225. }
  226. /*
  227. * cookie3
  228. *
  229. * typedef uint64 cookie3
  230. */
  231. static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie)
  232. {
  233. return xdr_encode_hyper(p, cookie);
  234. }
  235. static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie)
  236. {
  237. return decode_uint64(xdr, cookie);
  238. }
  239. /*
  240. * cookieverf3
  241. *
  242. * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
  243. */
  244. static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier)
  245. {
  246. memcpy(p, verifier, NFS3_COOKIEVERFSIZE);
  247. return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE);
  248. }
  249. static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier)
  250. {
  251. __be32 *p;
  252. p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
  253. if (unlikely(!p))
  254. return -EIO;
  255. memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
  256. return 0;
  257. }
  258. /*
  259. * createverf3
  260. *
  261. * typedef opaque createverf3[NFS3_CREATEVERFSIZE];
  262. */
  263. static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier)
  264. {
  265. __be32 *p;
  266. p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE);
  267. memcpy(p, verifier, NFS3_CREATEVERFSIZE);
  268. }
  269. static int decode_writeverf3(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  270. {
  271. __be32 *p;
  272. p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
  273. if (unlikely(!p))
  274. return -EIO;
  275. memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
  276. return 0;
  277. }
  278. /*
  279. * size3
  280. *
  281. * typedef uint64 size3;
  282. */
  283. static __be32 *xdr_decode_size3(__be32 *p, u64 *size)
  284. {
  285. return xdr_decode_hyper(p, size);
  286. }
  287. /*
  288. * nfsstat3
  289. *
  290. * enum nfsstat3 {
  291. * NFS3_OK = 0,
  292. * ...
  293. * }
  294. */
  295. #define NFS3_OK NFS_OK
  296. static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
  297. {
  298. __be32 *p;
  299. p = xdr_inline_decode(xdr, 4);
  300. if (unlikely(!p))
  301. return -EIO;
  302. if (unlikely(*p != cpu_to_be32(NFS3_OK)))
  303. goto out_status;
  304. *status = 0;
  305. return 0;
  306. out_status:
  307. *status = be32_to_cpup(p);
  308. trace_nfs_xdr_status(xdr, (int)*status);
  309. return 0;
  310. }
  311. /*
  312. * ftype3
  313. *
  314. * enum ftype3 {
  315. * NF3REG = 1,
  316. * NF3DIR = 2,
  317. * NF3BLK = 3,
  318. * NF3CHR = 4,
  319. * NF3LNK = 5,
  320. * NF3SOCK = 6,
  321. * NF3FIFO = 7
  322. * };
  323. */
  324. static void encode_ftype3(struct xdr_stream *xdr, const u32 type)
  325. {
  326. encode_uint32(xdr, type);
  327. }
  328. static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode)
  329. {
  330. u32 type;
  331. type = be32_to_cpup(p++);
  332. if (type > NF3FIFO)
  333. type = NF3NON;
  334. *mode = nfs_type2fmt[type];
  335. return p;
  336. }
  337. /*
  338. * specdata3
  339. *
  340. * struct specdata3 {
  341. * uint32 specdata1;
  342. * uint32 specdata2;
  343. * };
  344. */
  345. static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev)
  346. {
  347. __be32 *p;
  348. p = xdr_reserve_space(xdr, 8);
  349. *p++ = cpu_to_be32(MAJOR(rdev));
  350. *p = cpu_to_be32(MINOR(rdev));
  351. }
  352. static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev)
  353. {
  354. unsigned int major, minor;
  355. major = be32_to_cpup(p++);
  356. minor = be32_to_cpup(p++);
  357. *rdev = MKDEV(major, minor);
  358. if (MAJOR(*rdev) != major || MINOR(*rdev) != minor)
  359. *rdev = 0;
  360. return p;
  361. }
  362. /*
  363. * nfs_fh3
  364. *
  365. * struct nfs_fh3 {
  366. * opaque data<NFS3_FHSIZE>;
  367. * };
  368. */
  369. static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh)
  370. {
  371. __be32 *p;
  372. WARN_ON_ONCE(fh->size > NFS3_FHSIZE);
  373. p = xdr_reserve_space(xdr, 4 + fh->size);
  374. xdr_encode_opaque(p, fh->data, fh->size);
  375. }
  376. static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
  377. {
  378. u32 length;
  379. __be32 *p;
  380. p = xdr_inline_decode(xdr, 4);
  381. if (unlikely(!p))
  382. return -EIO;
  383. length = be32_to_cpup(p++);
  384. if (unlikely(length > NFS3_FHSIZE || length == 0))
  385. goto out_toobig;
  386. p = xdr_inline_decode(xdr, length);
  387. if (unlikely(!p))
  388. return -EIO;
  389. fh->size = length;
  390. memcpy(fh->data, p, length);
  391. return 0;
  392. out_toobig:
  393. trace_nfs_xdr_bad_filehandle(xdr, NFSERR_BADHANDLE);
  394. return -E2BIG;
  395. }
  396. static void zero_nfs_fh3(struct nfs_fh *fh)
  397. {
  398. memset(fh, 0, sizeof(*fh));
  399. }
  400. /*
  401. * nfstime3
  402. *
  403. * struct nfstime3 {
  404. * uint32 seconds;
  405. * uint32 nseconds;
  406. * };
  407. */
  408. static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec64 *timep)
  409. {
  410. *p++ = cpu_to_be32((u32)timep->tv_sec);
  411. *p++ = cpu_to_be32(timep->tv_nsec);
  412. return p;
  413. }
  414. static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec64 *timep)
  415. {
  416. timep->tv_sec = be32_to_cpup(p++);
  417. timep->tv_nsec = be32_to_cpup(p++);
  418. return p;
  419. }
  420. /*
  421. * sattr3
  422. *
  423. * enum time_how {
  424. * DONT_CHANGE = 0,
  425. * SET_TO_SERVER_TIME = 1,
  426. * SET_TO_CLIENT_TIME = 2
  427. * };
  428. *
  429. * union set_mode3 switch (bool set_it) {
  430. * case TRUE:
  431. * mode3 mode;
  432. * default:
  433. * void;
  434. * };
  435. *
  436. * union set_uid3 switch (bool set_it) {
  437. * case TRUE:
  438. * uid3 uid;
  439. * default:
  440. * void;
  441. * };
  442. *
  443. * union set_gid3 switch (bool set_it) {
  444. * case TRUE:
  445. * gid3 gid;
  446. * default:
  447. * void;
  448. * };
  449. *
  450. * union set_size3 switch (bool set_it) {
  451. * case TRUE:
  452. * size3 size;
  453. * default:
  454. * void;
  455. * };
  456. *
  457. * union set_atime switch (time_how set_it) {
  458. * case SET_TO_CLIENT_TIME:
  459. * nfstime3 atime;
  460. * default:
  461. * void;
  462. * };
  463. *
  464. * union set_mtime switch (time_how set_it) {
  465. * case SET_TO_CLIENT_TIME:
  466. * nfstime3 mtime;
  467. * default:
  468. * void;
  469. * };
  470. *
  471. * struct sattr3 {
  472. * set_mode3 mode;
  473. * set_uid3 uid;
  474. * set_gid3 gid;
  475. * set_size3 size;
  476. * set_atime atime;
  477. * set_mtime mtime;
  478. * };
  479. */
  480. static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr,
  481. struct user_namespace *userns)
  482. {
  483. u32 nbytes;
  484. __be32 *p;
  485. /*
  486. * In order to make only a single xdr_reserve_space() call,
  487. * pre-compute the total number of bytes to be reserved.
  488. * Six boolean values, one for each set_foo field, are always
  489. * present in the encoded result, so start there.
  490. */
  491. nbytes = 6 * 4;
  492. if (attr->ia_valid & ATTR_MODE)
  493. nbytes += 4;
  494. if (attr->ia_valid & ATTR_UID)
  495. nbytes += 4;
  496. if (attr->ia_valid & ATTR_GID)
  497. nbytes += 4;
  498. if (attr->ia_valid & ATTR_SIZE)
  499. nbytes += 8;
  500. if (attr->ia_valid & ATTR_ATIME_SET)
  501. nbytes += 8;
  502. if (attr->ia_valid & ATTR_MTIME_SET)
  503. nbytes += 8;
  504. p = xdr_reserve_space(xdr, nbytes);
  505. if (attr->ia_valid & ATTR_MODE) {
  506. *p++ = xdr_one;
  507. *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO);
  508. } else
  509. *p++ = xdr_zero;
  510. if (attr->ia_valid & ATTR_UID) {
  511. *p++ = xdr_one;
  512. *p++ = cpu_to_be32(from_kuid_munged(userns, attr->ia_uid));
  513. } else
  514. *p++ = xdr_zero;
  515. if (attr->ia_valid & ATTR_GID) {
  516. *p++ = xdr_one;
  517. *p++ = cpu_to_be32(from_kgid_munged(userns, attr->ia_gid));
  518. } else
  519. *p++ = xdr_zero;
  520. if (attr->ia_valid & ATTR_SIZE) {
  521. *p++ = xdr_one;
  522. p = xdr_encode_hyper(p, (u64)attr->ia_size);
  523. } else
  524. *p++ = xdr_zero;
  525. if (attr->ia_valid & ATTR_ATIME_SET) {
  526. *p++ = xdr_two;
  527. p = xdr_encode_nfstime3(p, &attr->ia_atime);
  528. } else if (attr->ia_valid & ATTR_ATIME) {
  529. *p++ = xdr_one;
  530. } else
  531. *p++ = xdr_zero;
  532. if (attr->ia_valid & ATTR_MTIME_SET) {
  533. *p++ = xdr_two;
  534. xdr_encode_nfstime3(p, &attr->ia_mtime);
  535. } else if (attr->ia_valid & ATTR_MTIME) {
  536. *p = xdr_one;
  537. } else
  538. *p = xdr_zero;
  539. }
  540. /*
  541. * fattr3
  542. *
  543. * struct fattr3 {
  544. * ftype3 type;
  545. * mode3 mode;
  546. * uint32 nlink;
  547. * uid3 uid;
  548. * gid3 gid;
  549. * size3 size;
  550. * size3 used;
  551. * specdata3 rdev;
  552. * uint64 fsid;
  553. * fileid3 fileid;
  554. * nfstime3 atime;
  555. * nfstime3 mtime;
  556. * nfstime3 ctime;
  557. * };
  558. */
  559. static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  560. struct user_namespace *userns)
  561. {
  562. umode_t fmode;
  563. __be32 *p;
  564. p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2);
  565. if (unlikely(!p))
  566. return -EIO;
  567. p = xdr_decode_ftype3(p, &fmode);
  568. fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
  569. fattr->nlink = be32_to_cpup(p++);
  570. fattr->uid = make_kuid(userns, be32_to_cpup(p++));
  571. if (!uid_valid(fattr->uid))
  572. goto out_uid;
  573. fattr->gid = make_kgid(userns, be32_to_cpup(p++));
  574. if (!gid_valid(fattr->gid))
  575. goto out_gid;
  576. p = xdr_decode_size3(p, &fattr->size);
  577. p = xdr_decode_size3(p, &fattr->du.nfs3.used);
  578. p = xdr_decode_specdata3(p, &fattr->rdev);
  579. p = xdr_decode_hyper(p, &fattr->fsid.major);
  580. fattr->fsid.minor = 0;
  581. p = xdr_decode_fileid3(p, &fattr->fileid);
  582. p = xdr_decode_nfstime3(p, &fattr->atime);
  583. p = xdr_decode_nfstime3(p, &fattr->mtime);
  584. xdr_decode_nfstime3(p, &fattr->ctime);
  585. fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
  586. fattr->valid |= NFS_ATTR_FATTR_V3;
  587. return 0;
  588. out_uid:
  589. dprintk("NFS: returned invalid uid\n");
  590. return -EINVAL;
  591. out_gid:
  592. dprintk("NFS: returned invalid gid\n");
  593. return -EINVAL;
  594. }
  595. /*
  596. * post_op_attr
  597. *
  598. * union post_op_attr switch (bool attributes_follow) {
  599. * case TRUE:
  600. * fattr3 attributes;
  601. * case FALSE:
  602. * void;
  603. * };
  604. */
  605. static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  606. struct user_namespace *userns)
  607. {
  608. __be32 *p;
  609. p = xdr_inline_decode(xdr, 4);
  610. if (unlikely(!p))
  611. return -EIO;
  612. if (*p != xdr_zero)
  613. return decode_fattr3(xdr, fattr, userns);
  614. return 0;
  615. }
  616. /*
  617. * wcc_attr
  618. * struct wcc_attr {
  619. * size3 size;
  620. * nfstime3 mtime;
  621. * nfstime3 ctime;
  622. * };
  623. */
  624. static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  625. {
  626. __be32 *p;
  627. p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2);
  628. if (unlikely(!p))
  629. return -EIO;
  630. fattr->valid |= NFS_ATTR_FATTR_PRESIZE
  631. | NFS_ATTR_FATTR_PRECHANGE
  632. | NFS_ATTR_FATTR_PREMTIME
  633. | NFS_ATTR_FATTR_PRECTIME;
  634. p = xdr_decode_size3(p, &fattr->pre_size);
  635. p = xdr_decode_nfstime3(p, &fattr->pre_mtime);
  636. xdr_decode_nfstime3(p, &fattr->pre_ctime);
  637. fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
  638. return 0;
  639. }
  640. /*
  641. * pre_op_attr
  642. * union pre_op_attr switch (bool attributes_follow) {
  643. * case TRUE:
  644. * wcc_attr attributes;
  645. * case FALSE:
  646. * void;
  647. * };
  648. *
  649. * wcc_data
  650. *
  651. * struct wcc_data {
  652. * pre_op_attr before;
  653. * post_op_attr after;
  654. * };
  655. */
  656. static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
  657. {
  658. __be32 *p;
  659. p = xdr_inline_decode(xdr, 4);
  660. if (unlikely(!p))
  661. return -EIO;
  662. if (*p != xdr_zero)
  663. return decode_wcc_attr(xdr, fattr);
  664. return 0;
  665. }
  666. static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  667. struct user_namespace *userns)
  668. {
  669. int error;
  670. error = decode_pre_op_attr(xdr, fattr);
  671. if (unlikely(error))
  672. goto out;
  673. error = decode_post_op_attr(xdr, fattr, userns);
  674. out:
  675. return error;
  676. }
  677. /*
  678. * post_op_fh3
  679. *
  680. * union post_op_fh3 switch (bool handle_follows) {
  681. * case TRUE:
  682. * nfs_fh3 handle;
  683. * case FALSE:
  684. * void;
  685. * };
  686. */
  687. static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
  688. {
  689. __be32 *p = xdr_inline_decode(xdr, 4);
  690. if (unlikely(!p))
  691. return -EIO;
  692. if (*p != xdr_zero)
  693. return decode_nfs_fh3(xdr, fh);
  694. zero_nfs_fh3(fh);
  695. return 0;
  696. }
  697. /*
  698. * diropargs3
  699. *
  700. * struct diropargs3 {
  701. * nfs_fh3 dir;
  702. * filename3 name;
  703. * };
  704. */
  705. static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh,
  706. const char *name, u32 length)
  707. {
  708. encode_nfs_fh3(xdr, fh);
  709. encode_filename3(xdr, name, length);
  710. }
  711. /*
  712. * NFSv3 XDR encode functions
  713. *
  714. * NFSv3 argument types are defined in section 3.3 of RFC 1813:
  715. * "NFS Version 3 Protocol Specification".
  716. */
  717. /*
  718. * 3.3.1 GETATTR3args
  719. *
  720. * struct GETATTR3args {
  721. * nfs_fh3 object;
  722. * };
  723. */
  724. static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req,
  725. struct xdr_stream *xdr,
  726. const void *data)
  727. {
  728. const struct nfs_fh *fh = data;
  729. encode_nfs_fh3(xdr, fh);
  730. }
  731. /*
  732. * 3.3.2 SETATTR3args
  733. *
  734. * union sattrguard3 switch (bool check) {
  735. * case TRUE:
  736. * nfstime3 obj_ctime;
  737. * case FALSE:
  738. * void;
  739. * };
  740. *
  741. * struct SETATTR3args {
  742. * nfs_fh3 object;
  743. * sattr3 new_attributes;
  744. * sattrguard3 guard;
  745. * };
  746. */
  747. static void encode_sattrguard3(struct xdr_stream *xdr,
  748. const struct nfs3_sattrargs *args)
  749. {
  750. __be32 *p;
  751. if (args->guard) {
  752. p = xdr_reserve_space(xdr, 4 + 8);
  753. *p++ = xdr_one;
  754. xdr_encode_nfstime3(p, &args->guardtime);
  755. } else {
  756. p = xdr_reserve_space(xdr, 4);
  757. *p = xdr_zero;
  758. }
  759. }
  760. static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req,
  761. struct xdr_stream *xdr,
  762. const void *data)
  763. {
  764. const struct nfs3_sattrargs *args = data;
  765. encode_nfs_fh3(xdr, args->fh);
  766. encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req));
  767. encode_sattrguard3(xdr, args);
  768. }
  769. /*
  770. * 3.3.3 LOOKUP3args
  771. *
  772. * struct LOOKUP3args {
  773. * diropargs3 what;
  774. * };
  775. */
  776. static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req,
  777. struct xdr_stream *xdr,
  778. const void *data)
  779. {
  780. const struct nfs3_diropargs *args = data;
  781. encode_diropargs3(xdr, args->fh, args->name, args->len);
  782. }
  783. /*
  784. * 3.3.4 ACCESS3args
  785. *
  786. * struct ACCESS3args {
  787. * nfs_fh3 object;
  788. * uint32 access;
  789. * };
  790. */
  791. static void encode_access3args(struct xdr_stream *xdr,
  792. const struct nfs3_accessargs *args)
  793. {
  794. encode_nfs_fh3(xdr, args->fh);
  795. encode_uint32(xdr, args->access);
  796. }
  797. static void nfs3_xdr_enc_access3args(struct rpc_rqst *req,
  798. struct xdr_stream *xdr,
  799. const void *data)
  800. {
  801. const struct nfs3_accessargs *args = data;
  802. encode_access3args(xdr, args);
  803. }
  804. /*
  805. * 3.3.5 READLINK3args
  806. *
  807. * struct READLINK3args {
  808. * nfs_fh3 symlink;
  809. * };
  810. */
  811. static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req,
  812. struct xdr_stream *xdr,
  813. const void *data)
  814. {
  815. const struct nfs3_readlinkargs *args = data;
  816. encode_nfs_fh3(xdr, args->fh);
  817. rpc_prepare_reply_pages(req, args->pages, args->pgbase, args->pglen,
  818. NFS3_readlinkres_sz - NFS3_pagepad_sz);
  819. }
  820. /*
  821. * 3.3.6 READ3args
  822. *
  823. * struct READ3args {
  824. * nfs_fh3 file;
  825. * offset3 offset;
  826. * count3 count;
  827. * };
  828. */
  829. static void encode_read3args(struct xdr_stream *xdr,
  830. const struct nfs_pgio_args *args)
  831. {
  832. __be32 *p;
  833. encode_nfs_fh3(xdr, args->fh);
  834. p = xdr_reserve_space(xdr, 8 + 4);
  835. p = xdr_encode_hyper(p, args->offset);
  836. *p = cpu_to_be32(args->count);
  837. }
  838. static void nfs3_xdr_enc_read3args(struct rpc_rqst *req,
  839. struct xdr_stream *xdr,
  840. const void *data)
  841. {
  842. const struct nfs_pgio_args *args = data;
  843. unsigned int replen = args->replen ? args->replen :
  844. NFS3_readres_sz - NFS3_pagepad_sz;
  845. encode_read3args(xdr, args);
  846. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  847. args->count, replen);
  848. req->rq_rcv_buf.flags |= XDRBUF_READ;
  849. }
  850. /*
  851. * 3.3.7 WRITE3args
  852. *
  853. * enum stable_how {
  854. * UNSTABLE = 0,
  855. * DATA_SYNC = 1,
  856. * FILE_SYNC = 2
  857. * };
  858. *
  859. * struct WRITE3args {
  860. * nfs_fh3 file;
  861. * offset3 offset;
  862. * count3 count;
  863. * stable_how stable;
  864. * opaque data<>;
  865. * };
  866. */
  867. static void encode_write3args(struct xdr_stream *xdr,
  868. const struct nfs_pgio_args *args)
  869. {
  870. __be32 *p;
  871. encode_nfs_fh3(xdr, args->fh);
  872. p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4);
  873. p = xdr_encode_hyper(p, args->offset);
  874. *p++ = cpu_to_be32(args->count);
  875. *p++ = cpu_to_be32(args->stable);
  876. *p = cpu_to_be32(args->count);
  877. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  878. }
  879. static void nfs3_xdr_enc_write3args(struct rpc_rqst *req,
  880. struct xdr_stream *xdr,
  881. const void *data)
  882. {
  883. const struct nfs_pgio_args *args = data;
  884. encode_write3args(xdr, args);
  885. xdr->buf->flags |= XDRBUF_WRITE;
  886. }
  887. /*
  888. * 3.3.8 CREATE3args
  889. *
  890. * enum createmode3 {
  891. * UNCHECKED = 0,
  892. * GUARDED = 1,
  893. * EXCLUSIVE = 2
  894. * };
  895. *
  896. * union createhow3 switch (createmode3 mode) {
  897. * case UNCHECKED:
  898. * case GUARDED:
  899. * sattr3 obj_attributes;
  900. * case EXCLUSIVE:
  901. * createverf3 verf;
  902. * };
  903. *
  904. * struct CREATE3args {
  905. * diropargs3 where;
  906. * createhow3 how;
  907. * };
  908. */
  909. static void encode_createhow3(struct xdr_stream *xdr,
  910. const struct nfs3_createargs *args,
  911. struct user_namespace *userns)
  912. {
  913. encode_uint32(xdr, args->createmode);
  914. switch (args->createmode) {
  915. case NFS3_CREATE_UNCHECKED:
  916. case NFS3_CREATE_GUARDED:
  917. encode_sattr3(xdr, args->sattr, userns);
  918. break;
  919. case NFS3_CREATE_EXCLUSIVE:
  920. encode_createverf3(xdr, args->verifier);
  921. break;
  922. default:
  923. BUG();
  924. }
  925. }
  926. static void nfs3_xdr_enc_create3args(struct rpc_rqst *req,
  927. struct xdr_stream *xdr,
  928. const void *data)
  929. {
  930. const struct nfs3_createargs *args = data;
  931. encode_diropargs3(xdr, args->fh, args->name, args->len);
  932. encode_createhow3(xdr, args, rpc_rqst_userns(req));
  933. }
  934. /*
  935. * 3.3.9 MKDIR3args
  936. *
  937. * struct MKDIR3args {
  938. * diropargs3 where;
  939. * sattr3 attributes;
  940. * };
  941. */
  942. static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req,
  943. struct xdr_stream *xdr,
  944. const void *data)
  945. {
  946. const struct nfs3_mkdirargs *args = data;
  947. encode_diropargs3(xdr, args->fh, args->name, args->len);
  948. encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req));
  949. }
  950. /*
  951. * 3.3.10 SYMLINK3args
  952. *
  953. * struct symlinkdata3 {
  954. * sattr3 symlink_attributes;
  955. * nfspath3 symlink_data;
  956. * };
  957. *
  958. * struct SYMLINK3args {
  959. * diropargs3 where;
  960. * symlinkdata3 symlink;
  961. * };
  962. */
  963. static void encode_symlinkdata3(struct xdr_stream *xdr,
  964. const void *data,
  965. struct user_namespace *userns)
  966. {
  967. const struct nfs3_symlinkargs *args = data;
  968. encode_sattr3(xdr, args->sattr, userns);
  969. encode_nfspath3(xdr, args->pages, args->pathlen);
  970. }
  971. static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req,
  972. struct xdr_stream *xdr,
  973. const void *data)
  974. {
  975. const struct nfs3_symlinkargs *args = data;
  976. encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
  977. encode_symlinkdata3(xdr, args, rpc_rqst_userns(req));
  978. xdr->buf->flags |= XDRBUF_WRITE;
  979. }
  980. /*
  981. * 3.3.11 MKNOD3args
  982. *
  983. * struct devicedata3 {
  984. * sattr3 dev_attributes;
  985. * specdata3 spec;
  986. * };
  987. *
  988. * union mknoddata3 switch (ftype3 type) {
  989. * case NF3CHR:
  990. * case NF3BLK:
  991. * devicedata3 device;
  992. * case NF3SOCK:
  993. * case NF3FIFO:
  994. * sattr3 pipe_attributes;
  995. * default:
  996. * void;
  997. * };
  998. *
  999. * struct MKNOD3args {
  1000. * diropargs3 where;
  1001. * mknoddata3 what;
  1002. * };
  1003. */
  1004. static void encode_devicedata3(struct xdr_stream *xdr,
  1005. const struct nfs3_mknodargs *args,
  1006. struct user_namespace *userns)
  1007. {
  1008. encode_sattr3(xdr, args->sattr, userns);
  1009. encode_specdata3(xdr, args->rdev);
  1010. }
  1011. static void encode_mknoddata3(struct xdr_stream *xdr,
  1012. const struct nfs3_mknodargs *args,
  1013. struct user_namespace *userns)
  1014. {
  1015. encode_ftype3(xdr, args->type);
  1016. switch (args->type) {
  1017. case NF3CHR:
  1018. case NF3BLK:
  1019. encode_devicedata3(xdr, args, userns);
  1020. break;
  1021. case NF3SOCK:
  1022. case NF3FIFO:
  1023. encode_sattr3(xdr, args->sattr, userns);
  1024. break;
  1025. case NF3REG:
  1026. case NF3DIR:
  1027. break;
  1028. default:
  1029. BUG();
  1030. }
  1031. }
  1032. static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req,
  1033. struct xdr_stream *xdr,
  1034. const void *data)
  1035. {
  1036. const struct nfs3_mknodargs *args = data;
  1037. encode_diropargs3(xdr, args->fh, args->name, args->len);
  1038. encode_mknoddata3(xdr, args, rpc_rqst_userns(req));
  1039. }
  1040. /*
  1041. * 3.3.12 REMOVE3args
  1042. *
  1043. * struct REMOVE3args {
  1044. * diropargs3 object;
  1045. * };
  1046. */
  1047. static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req,
  1048. struct xdr_stream *xdr,
  1049. const void *data)
  1050. {
  1051. const struct nfs_removeargs *args = data;
  1052. encode_diropargs3(xdr, args->fh, args->name.name, args->name.len);
  1053. }
  1054. /*
  1055. * 3.3.14 RENAME3args
  1056. *
  1057. * struct RENAME3args {
  1058. * diropargs3 from;
  1059. * diropargs3 to;
  1060. * };
  1061. */
  1062. static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req,
  1063. struct xdr_stream *xdr,
  1064. const void *data)
  1065. {
  1066. const struct nfs_renameargs *args = data;
  1067. const struct qstr *old = args->old_name;
  1068. const struct qstr *new = args->new_name;
  1069. encode_diropargs3(xdr, args->old_dir, old->name, old->len);
  1070. encode_diropargs3(xdr, args->new_dir, new->name, new->len);
  1071. }
  1072. /*
  1073. * 3.3.15 LINK3args
  1074. *
  1075. * struct LINK3args {
  1076. * nfs_fh3 file;
  1077. * diropargs3 link;
  1078. * };
  1079. */
  1080. static void nfs3_xdr_enc_link3args(struct rpc_rqst *req,
  1081. struct xdr_stream *xdr,
  1082. const void *data)
  1083. {
  1084. const struct nfs3_linkargs *args = data;
  1085. encode_nfs_fh3(xdr, args->fromfh);
  1086. encode_diropargs3(xdr, args->tofh, args->toname, args->tolen);
  1087. }
  1088. /*
  1089. * 3.3.16 READDIR3args
  1090. *
  1091. * struct READDIR3args {
  1092. * nfs_fh3 dir;
  1093. * cookie3 cookie;
  1094. * cookieverf3 cookieverf;
  1095. * count3 count;
  1096. * };
  1097. */
  1098. static void encode_readdir3args(struct xdr_stream *xdr,
  1099. const struct nfs3_readdirargs *args)
  1100. {
  1101. __be32 *p;
  1102. encode_nfs_fh3(xdr, args->fh);
  1103. p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4);
  1104. p = xdr_encode_cookie3(p, args->cookie);
  1105. p = xdr_encode_cookieverf3(p, args->verf);
  1106. *p = cpu_to_be32(args->count);
  1107. }
  1108. static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req,
  1109. struct xdr_stream *xdr,
  1110. const void *data)
  1111. {
  1112. const struct nfs3_readdirargs *args = data;
  1113. encode_readdir3args(xdr, args);
  1114. rpc_prepare_reply_pages(req, args->pages, 0, args->count,
  1115. NFS3_readdirres_sz - NFS3_pagepad_sz);
  1116. }
  1117. /*
  1118. * 3.3.17 READDIRPLUS3args
  1119. *
  1120. * struct READDIRPLUS3args {
  1121. * nfs_fh3 dir;
  1122. * cookie3 cookie;
  1123. * cookieverf3 cookieverf;
  1124. * count3 dircount;
  1125. * count3 maxcount;
  1126. * };
  1127. */
  1128. static void encode_readdirplus3args(struct xdr_stream *xdr,
  1129. const struct nfs3_readdirargs *args)
  1130. {
  1131. uint32_t dircount = args->count;
  1132. uint32_t maxcount = args->count;
  1133. __be32 *p;
  1134. encode_nfs_fh3(xdr, args->fh);
  1135. p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4);
  1136. p = xdr_encode_cookie3(p, args->cookie);
  1137. p = xdr_encode_cookieverf3(p, args->verf);
  1138. /*
  1139. * readdirplus: need dircount + buffer size.
  1140. * We just make sure we make dircount big enough
  1141. */
  1142. *p++ = cpu_to_be32(dircount);
  1143. *p = cpu_to_be32(maxcount);
  1144. }
  1145. static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req,
  1146. struct xdr_stream *xdr,
  1147. const void *data)
  1148. {
  1149. const struct nfs3_readdirargs *args = data;
  1150. encode_readdirplus3args(xdr, args);
  1151. rpc_prepare_reply_pages(req, args->pages, 0, args->count,
  1152. NFS3_readdirres_sz - NFS3_pagepad_sz);
  1153. }
  1154. /*
  1155. * 3.3.21 COMMIT3args
  1156. *
  1157. * struct COMMIT3args {
  1158. * nfs_fh3 file;
  1159. * offset3 offset;
  1160. * count3 count;
  1161. * };
  1162. */
  1163. static void encode_commit3args(struct xdr_stream *xdr,
  1164. const struct nfs_commitargs *args)
  1165. {
  1166. __be32 *p;
  1167. encode_nfs_fh3(xdr, args->fh);
  1168. p = xdr_reserve_space(xdr, 8 + 4);
  1169. p = xdr_encode_hyper(p, args->offset);
  1170. *p = cpu_to_be32(args->count);
  1171. }
  1172. static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req,
  1173. struct xdr_stream *xdr,
  1174. const void *data)
  1175. {
  1176. const struct nfs_commitargs *args = data;
  1177. encode_commit3args(xdr, args);
  1178. }
  1179. #ifdef CONFIG_NFS_V3_ACL
  1180. static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req,
  1181. struct xdr_stream *xdr,
  1182. const void *data)
  1183. {
  1184. const struct nfs3_getaclargs *args = data;
  1185. encode_nfs_fh3(xdr, args->fh);
  1186. encode_uint32(xdr, args->mask);
  1187. if (args->mask & (NFS_ACL | NFS_DFACL)) {
  1188. rpc_prepare_reply_pages(req, args->pages, 0,
  1189. NFSACL_MAXPAGES << PAGE_SHIFT,
  1190. ACL3_getaclres_sz - NFS3_pagepad_sz);
  1191. req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
  1192. }
  1193. }
  1194. static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
  1195. struct xdr_stream *xdr,
  1196. const void *data)
  1197. {
  1198. const struct nfs3_setaclargs *args = data;
  1199. unsigned int base;
  1200. int error;
  1201. encode_nfs_fh3(xdr, NFS_FH(args->inode));
  1202. encode_uint32(xdr, args->mask);
  1203. base = req->rq_slen;
  1204. if (args->npages != 0)
  1205. xdr_write_pages(xdr, args->pages, 0, args->len);
  1206. else
  1207. xdr_reserve_space(xdr, args->len);
  1208. error = nfsacl_encode(xdr->buf, base, args->inode,
  1209. (args->mask & NFS_ACL) ?
  1210. args->acl_access : NULL, 1, 0);
  1211. /* FIXME: this is just broken */
  1212. BUG_ON(error < 0);
  1213. error = nfsacl_encode(xdr->buf, base + error, args->inode,
  1214. (args->mask & NFS_DFACL) ?
  1215. args->acl_default : NULL, 1,
  1216. NFS_ACL_DEFAULT);
  1217. BUG_ON(error < 0);
  1218. }
  1219. #endif /* CONFIG_NFS_V3_ACL */
  1220. /*
  1221. * NFSv3 XDR decode functions
  1222. *
  1223. * NFSv3 result types are defined in section 3.3 of RFC 1813:
  1224. * "NFS Version 3 Protocol Specification".
  1225. */
  1226. /*
  1227. * 3.3.1 GETATTR3res
  1228. *
  1229. * struct GETATTR3resok {
  1230. * fattr3 obj_attributes;
  1231. * };
  1232. *
  1233. * union GETATTR3res switch (nfsstat3 status) {
  1234. * case NFS3_OK:
  1235. * GETATTR3resok resok;
  1236. * default:
  1237. * void;
  1238. * };
  1239. */
  1240. static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
  1241. struct xdr_stream *xdr,
  1242. void *result)
  1243. {
  1244. enum nfs_stat status;
  1245. int error;
  1246. error = decode_nfsstat3(xdr, &status);
  1247. if (unlikely(error))
  1248. goto out;
  1249. if (status != NFS3_OK)
  1250. goto out_default;
  1251. error = decode_fattr3(xdr, result, rpc_rqst_userns(req));
  1252. out:
  1253. return error;
  1254. out_default:
  1255. return nfs3_stat_to_errno(status);
  1256. }
  1257. /*
  1258. * 3.3.2 SETATTR3res
  1259. *
  1260. * struct SETATTR3resok {
  1261. * wcc_data obj_wcc;
  1262. * };
  1263. *
  1264. * struct SETATTR3resfail {
  1265. * wcc_data obj_wcc;
  1266. * };
  1267. *
  1268. * union SETATTR3res switch (nfsstat3 status) {
  1269. * case NFS3_OK:
  1270. * SETATTR3resok resok;
  1271. * default:
  1272. * SETATTR3resfail resfail;
  1273. * };
  1274. */
  1275. static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
  1276. struct xdr_stream *xdr,
  1277. void *result)
  1278. {
  1279. enum nfs_stat status;
  1280. int error;
  1281. error = decode_nfsstat3(xdr, &status);
  1282. if (unlikely(error))
  1283. goto out;
  1284. error = decode_wcc_data(xdr, result, rpc_rqst_userns(req));
  1285. if (unlikely(error))
  1286. goto out;
  1287. if (status != NFS3_OK)
  1288. goto out_status;
  1289. out:
  1290. return error;
  1291. out_status:
  1292. return nfs3_stat_to_errno(status);
  1293. }
  1294. /*
  1295. * 3.3.3 LOOKUP3res
  1296. *
  1297. * struct LOOKUP3resok {
  1298. * nfs_fh3 object;
  1299. * post_op_attr obj_attributes;
  1300. * post_op_attr dir_attributes;
  1301. * };
  1302. *
  1303. * struct LOOKUP3resfail {
  1304. * post_op_attr dir_attributes;
  1305. * };
  1306. *
  1307. * union LOOKUP3res switch (nfsstat3 status) {
  1308. * case NFS3_OK:
  1309. * LOOKUP3resok resok;
  1310. * default:
  1311. * LOOKUP3resfail resfail;
  1312. * };
  1313. */
  1314. static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
  1315. struct xdr_stream *xdr,
  1316. void *data)
  1317. {
  1318. struct user_namespace *userns = rpc_rqst_userns(req);
  1319. struct nfs3_diropres *result = data;
  1320. enum nfs_stat status;
  1321. int error;
  1322. error = decode_nfsstat3(xdr, &status);
  1323. if (unlikely(error))
  1324. goto out;
  1325. if (status != NFS3_OK)
  1326. goto out_default;
  1327. error = decode_nfs_fh3(xdr, result->fh);
  1328. if (unlikely(error))
  1329. goto out;
  1330. error = decode_post_op_attr(xdr, result->fattr, userns);
  1331. if (unlikely(error))
  1332. goto out;
  1333. error = decode_post_op_attr(xdr, result->dir_attr, userns);
  1334. out:
  1335. return error;
  1336. out_default:
  1337. error = decode_post_op_attr(xdr, result->dir_attr, userns);
  1338. if (unlikely(error))
  1339. goto out;
  1340. return nfs3_stat_to_errno(status);
  1341. }
  1342. /*
  1343. * 3.3.4 ACCESS3res
  1344. *
  1345. * struct ACCESS3resok {
  1346. * post_op_attr obj_attributes;
  1347. * uint32 access;
  1348. * };
  1349. *
  1350. * struct ACCESS3resfail {
  1351. * post_op_attr obj_attributes;
  1352. * };
  1353. *
  1354. * union ACCESS3res switch (nfsstat3 status) {
  1355. * case NFS3_OK:
  1356. * ACCESS3resok resok;
  1357. * default:
  1358. * ACCESS3resfail resfail;
  1359. * };
  1360. */
  1361. static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
  1362. struct xdr_stream *xdr,
  1363. void *data)
  1364. {
  1365. struct nfs3_accessres *result = data;
  1366. enum nfs_stat status;
  1367. int error;
  1368. error = decode_nfsstat3(xdr, &status);
  1369. if (unlikely(error))
  1370. goto out;
  1371. error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
  1372. if (unlikely(error))
  1373. goto out;
  1374. if (status != NFS3_OK)
  1375. goto out_default;
  1376. error = decode_uint32(xdr, &result->access);
  1377. out:
  1378. return error;
  1379. out_default:
  1380. return nfs3_stat_to_errno(status);
  1381. }
  1382. /*
  1383. * 3.3.5 READLINK3res
  1384. *
  1385. * struct READLINK3resok {
  1386. * post_op_attr symlink_attributes;
  1387. * nfspath3 data;
  1388. * };
  1389. *
  1390. * struct READLINK3resfail {
  1391. * post_op_attr symlink_attributes;
  1392. * };
  1393. *
  1394. * union READLINK3res switch (nfsstat3 status) {
  1395. * case NFS3_OK:
  1396. * READLINK3resok resok;
  1397. * default:
  1398. * READLINK3resfail resfail;
  1399. * };
  1400. */
  1401. static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
  1402. struct xdr_stream *xdr,
  1403. void *result)
  1404. {
  1405. enum nfs_stat status;
  1406. int error;
  1407. error = decode_nfsstat3(xdr, &status);
  1408. if (unlikely(error))
  1409. goto out;
  1410. error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
  1411. if (unlikely(error))
  1412. goto out;
  1413. if (status != NFS3_OK)
  1414. goto out_default;
  1415. error = decode_nfspath3(xdr);
  1416. out:
  1417. return error;
  1418. out_default:
  1419. return nfs3_stat_to_errno(status);
  1420. }
  1421. /*
  1422. * 3.3.6 READ3res
  1423. *
  1424. * struct READ3resok {
  1425. * post_op_attr file_attributes;
  1426. * count3 count;
  1427. * bool eof;
  1428. * opaque data<>;
  1429. * };
  1430. *
  1431. * struct READ3resfail {
  1432. * post_op_attr file_attributes;
  1433. * };
  1434. *
  1435. * union READ3res switch (nfsstat3 status) {
  1436. * case NFS3_OK:
  1437. * READ3resok resok;
  1438. * default:
  1439. * READ3resfail resfail;
  1440. * };
  1441. */
  1442. static int decode_read3resok(struct xdr_stream *xdr,
  1443. struct nfs_pgio_res *result)
  1444. {
  1445. u32 eof, count, ocount, recvd;
  1446. __be32 *p;
  1447. p = xdr_inline_decode(xdr, 4 + 4 + 4);
  1448. if (unlikely(!p))
  1449. return -EIO;
  1450. count = be32_to_cpup(p++);
  1451. eof = be32_to_cpup(p++);
  1452. ocount = be32_to_cpup(p++);
  1453. if (unlikely(ocount != count))
  1454. goto out_mismatch;
  1455. recvd = xdr_read_pages(xdr, count);
  1456. if (unlikely(count > recvd))
  1457. goto out_cheating;
  1458. out:
  1459. result->eof = eof;
  1460. result->count = count;
  1461. return count;
  1462. out_mismatch:
  1463. dprintk("NFS: READ count doesn't match length of opaque: "
  1464. "count %u != ocount %u\n", count, ocount);
  1465. return -EIO;
  1466. out_cheating:
  1467. dprintk("NFS: server cheating in read result: "
  1468. "count %u > recvd %u\n", count, recvd);
  1469. count = recvd;
  1470. eof = 0;
  1471. goto out;
  1472. }
  1473. static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1474. void *data)
  1475. {
  1476. struct nfs_pgio_res *result = data;
  1477. unsigned int pos;
  1478. enum nfs_stat status;
  1479. int error;
  1480. pos = xdr_stream_pos(xdr);
  1481. error = decode_nfsstat3(xdr, &status);
  1482. if (unlikely(error))
  1483. goto out;
  1484. error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
  1485. if (unlikely(error))
  1486. goto out;
  1487. result->op_status = status;
  1488. if (status != NFS3_OK)
  1489. goto out_status;
  1490. result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
  1491. error = decode_read3resok(xdr, result);
  1492. out:
  1493. return error;
  1494. out_status:
  1495. return nfs3_stat_to_errno(status);
  1496. }
  1497. /*
  1498. * 3.3.7 WRITE3res
  1499. *
  1500. * enum stable_how {
  1501. * UNSTABLE = 0,
  1502. * DATA_SYNC = 1,
  1503. * FILE_SYNC = 2
  1504. * };
  1505. *
  1506. * struct WRITE3resok {
  1507. * wcc_data file_wcc;
  1508. * count3 count;
  1509. * stable_how committed;
  1510. * writeverf3 verf;
  1511. * };
  1512. *
  1513. * struct WRITE3resfail {
  1514. * wcc_data file_wcc;
  1515. * };
  1516. *
  1517. * union WRITE3res switch (nfsstat3 status) {
  1518. * case NFS3_OK:
  1519. * WRITE3resok resok;
  1520. * default:
  1521. * WRITE3resfail resfail;
  1522. * };
  1523. */
  1524. static int decode_write3resok(struct xdr_stream *xdr,
  1525. struct nfs_pgio_res *result)
  1526. {
  1527. __be32 *p;
  1528. p = xdr_inline_decode(xdr, 4 + 4);
  1529. if (unlikely(!p))
  1530. return -EIO;
  1531. result->count = be32_to_cpup(p++);
  1532. result->verf->committed = be32_to_cpup(p++);
  1533. if (unlikely(result->verf->committed > NFS_FILE_SYNC))
  1534. goto out_badvalue;
  1535. if (decode_writeverf3(xdr, &result->verf->verifier))
  1536. return -EIO;
  1537. return result->count;
  1538. out_badvalue:
  1539. dprintk("NFS: bad stable_how value: %u\n", result->verf->committed);
  1540. return -EIO;
  1541. }
  1542. static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1543. void *data)
  1544. {
  1545. struct nfs_pgio_res *result = data;
  1546. enum nfs_stat status;
  1547. int error;
  1548. error = decode_nfsstat3(xdr, &status);
  1549. if (unlikely(error))
  1550. goto out;
  1551. error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
  1552. if (unlikely(error))
  1553. goto out;
  1554. result->op_status = status;
  1555. if (status != NFS3_OK)
  1556. goto out_status;
  1557. error = decode_write3resok(xdr, result);
  1558. out:
  1559. return error;
  1560. out_status:
  1561. return nfs3_stat_to_errno(status);
  1562. }
  1563. /*
  1564. * 3.3.8 CREATE3res
  1565. *
  1566. * struct CREATE3resok {
  1567. * post_op_fh3 obj;
  1568. * post_op_attr obj_attributes;
  1569. * wcc_data dir_wcc;
  1570. * };
  1571. *
  1572. * struct CREATE3resfail {
  1573. * wcc_data dir_wcc;
  1574. * };
  1575. *
  1576. * union CREATE3res switch (nfsstat3 status) {
  1577. * case NFS3_OK:
  1578. * CREATE3resok resok;
  1579. * default:
  1580. * CREATE3resfail resfail;
  1581. * };
  1582. */
  1583. static int decode_create3resok(struct xdr_stream *xdr,
  1584. struct nfs3_diropres *result,
  1585. struct user_namespace *userns)
  1586. {
  1587. int error;
  1588. error = decode_post_op_fh3(xdr, result->fh);
  1589. if (unlikely(error))
  1590. goto out;
  1591. error = decode_post_op_attr(xdr, result->fattr, userns);
  1592. if (unlikely(error))
  1593. goto out;
  1594. /* The server isn't required to return a file handle.
  1595. * If it didn't, force the client to perform a LOOKUP
  1596. * to determine the correct file handle and attribute
  1597. * values for the new object. */
  1598. if (result->fh->size == 0)
  1599. result->fattr->valid = 0;
  1600. error = decode_wcc_data(xdr, result->dir_attr, userns);
  1601. out:
  1602. return error;
  1603. }
  1604. static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
  1605. struct xdr_stream *xdr,
  1606. void *data)
  1607. {
  1608. struct user_namespace *userns = rpc_rqst_userns(req);
  1609. struct nfs3_diropres *result = data;
  1610. enum nfs_stat status;
  1611. int error;
  1612. error = decode_nfsstat3(xdr, &status);
  1613. if (unlikely(error))
  1614. goto out;
  1615. if (status != NFS3_OK)
  1616. goto out_default;
  1617. error = decode_create3resok(xdr, result, userns);
  1618. out:
  1619. return error;
  1620. out_default:
  1621. error = decode_wcc_data(xdr, result->dir_attr, userns);
  1622. if (unlikely(error))
  1623. goto out;
  1624. return nfs3_stat_to_errno(status);
  1625. }
  1626. /*
  1627. * 3.3.12 REMOVE3res
  1628. *
  1629. * struct REMOVE3resok {
  1630. * wcc_data dir_wcc;
  1631. * };
  1632. *
  1633. * struct REMOVE3resfail {
  1634. * wcc_data dir_wcc;
  1635. * };
  1636. *
  1637. * union REMOVE3res switch (nfsstat3 status) {
  1638. * case NFS3_OK:
  1639. * REMOVE3resok resok;
  1640. * default:
  1641. * REMOVE3resfail resfail;
  1642. * };
  1643. */
  1644. static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
  1645. struct xdr_stream *xdr,
  1646. void *data)
  1647. {
  1648. struct nfs_removeres *result = data;
  1649. enum nfs_stat status;
  1650. int error;
  1651. error = decode_nfsstat3(xdr, &status);
  1652. if (unlikely(error))
  1653. goto out;
  1654. error = decode_wcc_data(xdr, result->dir_attr, rpc_rqst_userns(req));
  1655. if (unlikely(error))
  1656. goto out;
  1657. if (status != NFS3_OK)
  1658. goto out_status;
  1659. out:
  1660. return error;
  1661. out_status:
  1662. return nfs3_stat_to_errno(status);
  1663. }
  1664. /*
  1665. * 3.3.14 RENAME3res
  1666. *
  1667. * struct RENAME3resok {
  1668. * wcc_data fromdir_wcc;
  1669. * wcc_data todir_wcc;
  1670. * };
  1671. *
  1672. * struct RENAME3resfail {
  1673. * wcc_data fromdir_wcc;
  1674. * wcc_data todir_wcc;
  1675. * };
  1676. *
  1677. * union RENAME3res switch (nfsstat3 status) {
  1678. * case NFS3_OK:
  1679. * RENAME3resok resok;
  1680. * default:
  1681. * RENAME3resfail resfail;
  1682. * };
  1683. */
  1684. static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
  1685. struct xdr_stream *xdr,
  1686. void *data)
  1687. {
  1688. struct user_namespace *userns = rpc_rqst_userns(req);
  1689. struct nfs_renameres *result = data;
  1690. enum nfs_stat status;
  1691. int error;
  1692. error = decode_nfsstat3(xdr, &status);
  1693. if (unlikely(error))
  1694. goto out;
  1695. error = decode_wcc_data(xdr, result->old_fattr, userns);
  1696. if (unlikely(error))
  1697. goto out;
  1698. error = decode_wcc_data(xdr, result->new_fattr, userns);
  1699. if (unlikely(error))
  1700. goto out;
  1701. if (status != NFS3_OK)
  1702. goto out_status;
  1703. out:
  1704. return error;
  1705. out_status:
  1706. return nfs3_stat_to_errno(status);
  1707. }
  1708. /*
  1709. * 3.3.15 LINK3res
  1710. *
  1711. * struct LINK3resok {
  1712. * post_op_attr file_attributes;
  1713. * wcc_data linkdir_wcc;
  1714. * };
  1715. *
  1716. * struct LINK3resfail {
  1717. * post_op_attr file_attributes;
  1718. * wcc_data linkdir_wcc;
  1719. * };
  1720. *
  1721. * union LINK3res switch (nfsstat3 status) {
  1722. * case NFS3_OK:
  1723. * LINK3resok resok;
  1724. * default:
  1725. * LINK3resfail resfail;
  1726. * };
  1727. */
  1728. static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
  1729. void *data)
  1730. {
  1731. struct user_namespace *userns = rpc_rqst_userns(req);
  1732. struct nfs3_linkres *result = data;
  1733. enum nfs_stat status;
  1734. int error;
  1735. error = decode_nfsstat3(xdr, &status);
  1736. if (unlikely(error))
  1737. goto out;
  1738. error = decode_post_op_attr(xdr, result->fattr, userns);
  1739. if (unlikely(error))
  1740. goto out;
  1741. error = decode_wcc_data(xdr, result->dir_attr, userns);
  1742. if (unlikely(error))
  1743. goto out;
  1744. if (status != NFS3_OK)
  1745. goto out_status;
  1746. out:
  1747. return error;
  1748. out_status:
  1749. return nfs3_stat_to_errno(status);
  1750. }
  1751. /**
  1752. * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in
  1753. * the local page cache
  1754. * @xdr: XDR stream where entry resides
  1755. * @entry: buffer to fill in with entry data
  1756. * @plus: boolean indicating whether this should be a readdirplus entry
  1757. *
  1758. * Returns zero if successful, otherwise a negative errno value is
  1759. * returned.
  1760. *
  1761. * This function is not invoked during READDIR reply decoding, but
  1762. * rather whenever an application invokes the getdents(2) system call
  1763. * on a directory already in our cache.
  1764. *
  1765. * 3.3.16 entry3
  1766. *
  1767. * struct entry3 {
  1768. * fileid3 fileid;
  1769. * filename3 name;
  1770. * cookie3 cookie;
  1771. * fhandle3 filehandle;
  1772. * post_op_attr3 attributes;
  1773. * entry3 *nextentry;
  1774. * };
  1775. *
  1776. * 3.3.17 entryplus3
  1777. * struct entryplus3 {
  1778. * fileid3 fileid;
  1779. * filename3 name;
  1780. * cookie3 cookie;
  1781. * post_op_attr name_attributes;
  1782. * post_op_fh3 name_handle;
  1783. * entryplus3 *nextentry;
  1784. * };
  1785. */
  1786. int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  1787. bool plus)
  1788. {
  1789. struct user_namespace *userns = rpc_userns(entry->server->client);
  1790. __be32 *p;
  1791. int error;
  1792. u64 new_cookie;
  1793. p = xdr_inline_decode(xdr, 4);
  1794. if (unlikely(!p))
  1795. return -EAGAIN;
  1796. if (*p == xdr_zero) {
  1797. p = xdr_inline_decode(xdr, 4);
  1798. if (unlikely(!p))
  1799. return -EAGAIN;
  1800. if (*p == xdr_zero)
  1801. return -EAGAIN;
  1802. entry->eof = 1;
  1803. return -EBADCOOKIE;
  1804. }
  1805. error = decode_fileid3(xdr, &entry->ino);
  1806. if (unlikely(error))
  1807. return -EAGAIN;
  1808. error = decode_inline_filename3(xdr, &entry->name, &entry->len);
  1809. if (unlikely(error))
  1810. return error == -ENAMETOOLONG ? -ENAMETOOLONG : -EAGAIN;
  1811. error = decode_cookie3(xdr, &new_cookie);
  1812. if (unlikely(error))
  1813. return -EAGAIN;
  1814. entry->d_type = DT_UNKNOWN;
  1815. if (plus) {
  1816. entry->fattr->valid = 0;
  1817. error = decode_post_op_attr(xdr, entry->fattr, userns);
  1818. if (unlikely(error))
  1819. return -EAGAIN;
  1820. if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
  1821. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  1822. if (entry->fattr->fileid != entry->ino) {
  1823. entry->fattr->mounted_on_fileid = entry->ino;
  1824. entry->fattr->valid |= NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  1825. }
  1826. /* In fact, a post_op_fh3: */
  1827. p = xdr_inline_decode(xdr, 4);
  1828. if (unlikely(!p))
  1829. return -EAGAIN;
  1830. if (*p != xdr_zero) {
  1831. error = decode_nfs_fh3(xdr, entry->fh);
  1832. if (unlikely(error))
  1833. return -EAGAIN;
  1834. } else
  1835. zero_nfs_fh3(entry->fh);
  1836. }
  1837. entry->cookie = new_cookie;
  1838. return 0;
  1839. }
  1840. /*
  1841. * 3.3.16 READDIR3res
  1842. *
  1843. * struct dirlist3 {
  1844. * entry3 *entries;
  1845. * bool eof;
  1846. * };
  1847. *
  1848. * struct READDIR3resok {
  1849. * post_op_attr dir_attributes;
  1850. * cookieverf3 cookieverf;
  1851. * dirlist3 reply;
  1852. * };
  1853. *
  1854. * struct READDIR3resfail {
  1855. * post_op_attr dir_attributes;
  1856. * };
  1857. *
  1858. * union READDIR3res switch (nfsstat3 status) {
  1859. * case NFS3_OK:
  1860. * READDIR3resok resok;
  1861. * default:
  1862. * READDIR3resfail resfail;
  1863. * };
  1864. *
  1865. * Read the directory contents into the page cache, but otherwise
  1866. * don't touch them. The actual decoding is done by nfs3_decode_entry()
  1867. * during subsequent nfs_readdir() calls.
  1868. */
  1869. static int decode_dirlist3(struct xdr_stream *xdr)
  1870. {
  1871. return xdr_read_pages(xdr, xdr->buf->page_len);
  1872. }
  1873. static int decode_readdir3resok(struct xdr_stream *xdr,
  1874. struct nfs3_readdirres *result,
  1875. struct user_namespace *userns)
  1876. {
  1877. int error;
  1878. error = decode_post_op_attr(xdr, result->dir_attr, userns);
  1879. if (unlikely(error))
  1880. goto out;
  1881. /* XXX: do we need to check if result->verf != NULL ? */
  1882. error = decode_cookieverf3(xdr, result->verf);
  1883. if (unlikely(error))
  1884. goto out;
  1885. error = decode_dirlist3(xdr);
  1886. out:
  1887. return error;
  1888. }
  1889. static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
  1890. struct xdr_stream *xdr,
  1891. void *data)
  1892. {
  1893. struct nfs3_readdirres *result = data;
  1894. enum nfs_stat status;
  1895. int error;
  1896. error = decode_nfsstat3(xdr, &status);
  1897. if (unlikely(error))
  1898. goto out;
  1899. if (status != NFS3_OK)
  1900. goto out_default;
  1901. error = decode_readdir3resok(xdr, result, rpc_rqst_userns(req));
  1902. out:
  1903. return error;
  1904. out_default:
  1905. error = decode_post_op_attr(xdr, result->dir_attr, rpc_rqst_userns(req));
  1906. if (unlikely(error))
  1907. goto out;
  1908. return nfs3_stat_to_errno(status);
  1909. }
  1910. /*
  1911. * 3.3.18 FSSTAT3res
  1912. *
  1913. * struct FSSTAT3resok {
  1914. * post_op_attr obj_attributes;
  1915. * size3 tbytes;
  1916. * size3 fbytes;
  1917. * size3 abytes;
  1918. * size3 tfiles;
  1919. * size3 ffiles;
  1920. * size3 afiles;
  1921. * uint32 invarsec;
  1922. * };
  1923. *
  1924. * struct FSSTAT3resfail {
  1925. * post_op_attr obj_attributes;
  1926. * };
  1927. *
  1928. * union FSSTAT3res switch (nfsstat3 status) {
  1929. * case NFS3_OK:
  1930. * FSSTAT3resok resok;
  1931. * default:
  1932. * FSSTAT3resfail resfail;
  1933. * };
  1934. */
  1935. static int decode_fsstat3resok(struct xdr_stream *xdr,
  1936. struct nfs_fsstat *result)
  1937. {
  1938. __be32 *p;
  1939. p = xdr_inline_decode(xdr, 8 * 6 + 4);
  1940. if (unlikely(!p))
  1941. return -EIO;
  1942. p = xdr_decode_size3(p, &result->tbytes);
  1943. p = xdr_decode_size3(p, &result->fbytes);
  1944. p = xdr_decode_size3(p, &result->abytes);
  1945. p = xdr_decode_size3(p, &result->tfiles);
  1946. p = xdr_decode_size3(p, &result->ffiles);
  1947. xdr_decode_size3(p, &result->afiles);
  1948. /* ignore invarsec */
  1949. return 0;
  1950. }
  1951. static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
  1952. struct xdr_stream *xdr,
  1953. void *data)
  1954. {
  1955. struct nfs_fsstat *result = data;
  1956. enum nfs_stat status;
  1957. int error;
  1958. error = decode_nfsstat3(xdr, &status);
  1959. if (unlikely(error))
  1960. goto out;
  1961. error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
  1962. if (unlikely(error))
  1963. goto out;
  1964. if (status != NFS3_OK)
  1965. goto out_status;
  1966. error = decode_fsstat3resok(xdr, result);
  1967. out:
  1968. return error;
  1969. out_status:
  1970. return nfs3_stat_to_errno(status);
  1971. }
  1972. /*
  1973. * 3.3.19 FSINFO3res
  1974. *
  1975. * struct FSINFO3resok {
  1976. * post_op_attr obj_attributes;
  1977. * uint32 rtmax;
  1978. * uint32 rtpref;
  1979. * uint32 rtmult;
  1980. * uint32 wtmax;
  1981. * uint32 wtpref;
  1982. * uint32 wtmult;
  1983. * uint32 dtpref;
  1984. * size3 maxfilesize;
  1985. * nfstime3 time_delta;
  1986. * uint32 properties;
  1987. * };
  1988. *
  1989. * struct FSINFO3resfail {
  1990. * post_op_attr obj_attributes;
  1991. * };
  1992. *
  1993. * union FSINFO3res switch (nfsstat3 status) {
  1994. * case NFS3_OK:
  1995. * FSINFO3resok resok;
  1996. * default:
  1997. * FSINFO3resfail resfail;
  1998. * };
  1999. */
  2000. static int decode_fsinfo3resok(struct xdr_stream *xdr,
  2001. struct nfs_fsinfo *result)
  2002. {
  2003. __be32 *p;
  2004. p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4);
  2005. if (unlikely(!p))
  2006. return -EIO;
  2007. result->rtmax = be32_to_cpup(p++);
  2008. result->rtpref = be32_to_cpup(p++);
  2009. result->rtmult = be32_to_cpup(p++);
  2010. result->wtmax = be32_to_cpup(p++);
  2011. result->wtpref = be32_to_cpup(p++);
  2012. result->wtmult = be32_to_cpup(p++);
  2013. result->dtpref = be32_to_cpup(p++);
  2014. p = xdr_decode_size3(p, &result->maxfilesize);
  2015. xdr_decode_nfstime3(p, &result->time_delta);
  2016. /* ignore properties */
  2017. result->lease_time = 0;
  2018. result->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED;
  2019. result->xattr_support = 0;
  2020. return 0;
  2021. }
  2022. static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
  2023. struct xdr_stream *xdr,
  2024. void *data)
  2025. {
  2026. struct nfs_fsinfo *result = data;
  2027. enum nfs_stat status;
  2028. int error;
  2029. error = decode_nfsstat3(xdr, &status);
  2030. if (unlikely(error))
  2031. goto out;
  2032. error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
  2033. if (unlikely(error))
  2034. goto out;
  2035. if (status != NFS3_OK)
  2036. goto out_status;
  2037. error = decode_fsinfo3resok(xdr, result);
  2038. out:
  2039. return error;
  2040. out_status:
  2041. return nfs3_stat_to_errno(status);
  2042. }
  2043. /*
  2044. * 3.3.20 PATHCONF3res
  2045. *
  2046. * struct PATHCONF3resok {
  2047. * post_op_attr obj_attributes;
  2048. * uint32 linkmax;
  2049. * uint32 name_max;
  2050. * bool no_trunc;
  2051. * bool chown_restricted;
  2052. * bool case_insensitive;
  2053. * bool case_preserving;
  2054. * };
  2055. *
  2056. * struct PATHCONF3resfail {
  2057. * post_op_attr obj_attributes;
  2058. * };
  2059. *
  2060. * union PATHCONF3res switch (nfsstat3 status) {
  2061. * case NFS3_OK:
  2062. * PATHCONF3resok resok;
  2063. * default:
  2064. * PATHCONF3resfail resfail;
  2065. * };
  2066. */
  2067. static int decode_pathconf3resok(struct xdr_stream *xdr,
  2068. struct nfs_pathconf *result)
  2069. {
  2070. __be32 *p;
  2071. p = xdr_inline_decode(xdr, 4 * 6);
  2072. if (unlikely(!p))
  2073. return -EIO;
  2074. result->max_link = be32_to_cpup(p++);
  2075. result->max_namelen = be32_to_cpup(p);
  2076. /* ignore remaining fields */
  2077. return 0;
  2078. }
  2079. static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
  2080. struct xdr_stream *xdr,
  2081. void *data)
  2082. {
  2083. struct nfs_pathconf *result = data;
  2084. enum nfs_stat status;
  2085. int error;
  2086. error = decode_nfsstat3(xdr, &status);
  2087. if (unlikely(error))
  2088. goto out;
  2089. error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
  2090. if (unlikely(error))
  2091. goto out;
  2092. if (status != NFS3_OK)
  2093. goto out_status;
  2094. error = decode_pathconf3resok(xdr, result);
  2095. out:
  2096. return error;
  2097. out_status:
  2098. return nfs3_stat_to_errno(status);
  2099. }
  2100. /*
  2101. * 3.3.21 COMMIT3res
  2102. *
  2103. * struct COMMIT3resok {
  2104. * wcc_data file_wcc;
  2105. * writeverf3 verf;
  2106. * };
  2107. *
  2108. * struct COMMIT3resfail {
  2109. * wcc_data file_wcc;
  2110. * };
  2111. *
  2112. * union COMMIT3res switch (nfsstat3 status) {
  2113. * case NFS3_OK:
  2114. * COMMIT3resok resok;
  2115. * default:
  2116. * COMMIT3resfail resfail;
  2117. * };
  2118. */
  2119. static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
  2120. struct xdr_stream *xdr,
  2121. void *data)
  2122. {
  2123. struct nfs_commitres *result = data;
  2124. struct nfs_writeverf *verf = result->verf;
  2125. enum nfs_stat status;
  2126. int error;
  2127. error = decode_nfsstat3(xdr, &status);
  2128. if (unlikely(error))
  2129. goto out;
  2130. error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
  2131. if (unlikely(error))
  2132. goto out;
  2133. result->op_status = status;
  2134. if (status != NFS3_OK)
  2135. goto out_status;
  2136. error = decode_writeverf3(xdr, &verf->verifier);
  2137. if (!error)
  2138. verf->committed = NFS_FILE_SYNC;
  2139. out:
  2140. return error;
  2141. out_status:
  2142. return nfs3_stat_to_errno(status);
  2143. }
  2144. #ifdef CONFIG_NFS_V3_ACL
  2145. static inline int decode_getacl3resok(struct xdr_stream *xdr,
  2146. struct nfs3_getaclres *result,
  2147. struct user_namespace *userns)
  2148. {
  2149. struct posix_acl **acl;
  2150. unsigned int *aclcnt;
  2151. size_t hdrlen;
  2152. int error;
  2153. error = decode_post_op_attr(xdr, result->fattr, userns);
  2154. if (unlikely(error))
  2155. goto out;
  2156. error = decode_uint32(xdr, &result->mask);
  2157. if (unlikely(error))
  2158. goto out;
  2159. error = -EINVAL;
  2160. if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
  2161. goto out;
  2162. hdrlen = xdr_stream_pos(xdr);
  2163. acl = NULL;
  2164. if (result->mask & NFS_ACL)
  2165. acl = &result->acl_access;
  2166. aclcnt = NULL;
  2167. if (result->mask & NFS_ACLCNT)
  2168. aclcnt = &result->acl_access_count;
  2169. error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl);
  2170. if (unlikely(error <= 0))
  2171. goto out;
  2172. acl = NULL;
  2173. if (result->mask & NFS_DFACL)
  2174. acl = &result->acl_default;
  2175. aclcnt = NULL;
  2176. if (result->mask & NFS_DFACLCNT)
  2177. aclcnt = &result->acl_default_count;
  2178. error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl);
  2179. if (unlikely(error <= 0))
  2180. return error;
  2181. error = 0;
  2182. out:
  2183. return error;
  2184. }
  2185. static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
  2186. struct xdr_stream *xdr,
  2187. void *result)
  2188. {
  2189. enum nfs_stat status;
  2190. int error;
  2191. error = decode_nfsstat3(xdr, &status);
  2192. if (unlikely(error))
  2193. goto out;
  2194. if (status != NFS3_OK)
  2195. goto out_default;
  2196. error = decode_getacl3resok(xdr, result, rpc_rqst_userns(req));
  2197. out:
  2198. return error;
  2199. out_default:
  2200. return nfs3_stat_to_errno(status);
  2201. }
  2202. static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
  2203. struct xdr_stream *xdr,
  2204. void *result)
  2205. {
  2206. enum nfs_stat status;
  2207. int error;
  2208. error = decode_nfsstat3(xdr, &status);
  2209. if (unlikely(error))
  2210. goto out;
  2211. if (status != NFS3_OK)
  2212. goto out_default;
  2213. error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
  2214. out:
  2215. return error;
  2216. out_default:
  2217. return nfs3_stat_to_errno(status);
  2218. }
  2219. #endif /* CONFIG_NFS_V3_ACL */
  2220. /*
  2221. * We need to translate between nfs status return values and
  2222. * the local errno values which may not be the same.
  2223. */
  2224. static const struct {
  2225. int stat;
  2226. int errno;
  2227. } nfs_errtbl[] = {
  2228. { NFS_OK, 0 },
  2229. { NFSERR_PERM, -EPERM },
  2230. { NFSERR_NOENT, -ENOENT },
  2231. { NFSERR_IO, -errno_NFSERR_IO},
  2232. { NFSERR_NXIO, -ENXIO },
  2233. /* { NFSERR_EAGAIN, -EAGAIN }, */
  2234. { NFSERR_ACCES, -EACCES },
  2235. { NFSERR_EXIST, -EEXIST },
  2236. { NFSERR_XDEV, -EXDEV },
  2237. { NFSERR_NODEV, -ENODEV },
  2238. { NFSERR_NOTDIR, -ENOTDIR },
  2239. { NFSERR_ISDIR, -EISDIR },
  2240. { NFSERR_INVAL, -EINVAL },
  2241. { NFSERR_FBIG, -EFBIG },
  2242. { NFSERR_NOSPC, -ENOSPC },
  2243. { NFSERR_ROFS, -EROFS },
  2244. { NFSERR_MLINK, -EMLINK },
  2245. { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
  2246. { NFSERR_NOTEMPTY, -ENOTEMPTY },
  2247. { NFSERR_DQUOT, -EDQUOT },
  2248. { NFSERR_STALE, -ESTALE },
  2249. { NFSERR_REMOTE, -EREMOTE },
  2250. #ifdef EWFLUSH
  2251. { NFSERR_WFLUSH, -EWFLUSH },
  2252. #endif
  2253. { NFSERR_BADHANDLE, -EBADHANDLE },
  2254. { NFSERR_NOT_SYNC, -ENOTSYNC },
  2255. { NFSERR_BAD_COOKIE, -EBADCOOKIE },
  2256. { NFSERR_NOTSUPP, -ENOTSUPP },
  2257. { NFSERR_TOOSMALL, -ETOOSMALL },
  2258. { NFSERR_SERVERFAULT, -EREMOTEIO },
  2259. { NFSERR_BADTYPE, -EBADTYPE },
  2260. { NFSERR_JUKEBOX, -EJUKEBOX },
  2261. { -1, -EIO }
  2262. };
  2263. /**
  2264. * nfs3_stat_to_errno - convert an NFS status code to a local errno
  2265. * @status: NFS status code to convert
  2266. *
  2267. * Returns a local errno value, or -EIO if the NFS status code is
  2268. * not recognized. This function is used jointly by NFSv2 and NFSv3.
  2269. */
  2270. static int nfs3_stat_to_errno(enum nfs_stat status)
  2271. {
  2272. int i;
  2273. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  2274. if (nfs_errtbl[i].stat == (int)status)
  2275. return nfs_errtbl[i].errno;
  2276. }
  2277. dprintk("NFS: Unrecognized nfs status value: %u\n", status);
  2278. return nfs_errtbl[i].errno;
  2279. }
  2280. #define PROC(proc, argtype, restype, timer) \
  2281. [NFS3PROC_##proc] = { \
  2282. .p_proc = NFS3PROC_##proc, \
  2283. .p_encode = nfs3_xdr_enc_##argtype##3args, \
  2284. .p_decode = nfs3_xdr_dec_##restype##3res, \
  2285. .p_arglen = NFS3_##argtype##args_sz, \
  2286. .p_replen = NFS3_##restype##res_sz, \
  2287. .p_timer = timer, \
  2288. .p_statidx = NFS3PROC_##proc, \
  2289. .p_name = #proc, \
  2290. }
  2291. const struct rpc_procinfo nfs3_procedures[] = {
  2292. PROC(GETATTR, getattr, getattr, 1),
  2293. PROC(SETATTR, setattr, setattr, 0),
  2294. PROC(LOOKUP, lookup, lookup, 2),
  2295. PROC(ACCESS, access, access, 1),
  2296. PROC(READLINK, readlink, readlink, 3),
  2297. PROC(READ, read, read, 3),
  2298. PROC(WRITE, write, write, 4),
  2299. PROC(CREATE, create, create, 0),
  2300. PROC(MKDIR, mkdir, create, 0),
  2301. PROC(SYMLINK, symlink, create, 0),
  2302. PROC(MKNOD, mknod, create, 0),
  2303. PROC(REMOVE, remove, remove, 0),
  2304. PROC(RMDIR, lookup, setattr, 0),
  2305. PROC(RENAME, rename, rename, 0),
  2306. PROC(LINK, link, link, 0),
  2307. PROC(READDIR, readdir, readdir, 3),
  2308. PROC(READDIRPLUS, readdirplus, readdir, 3),
  2309. PROC(FSSTAT, getattr, fsstat, 0),
  2310. PROC(FSINFO, getattr, fsinfo, 0),
  2311. PROC(PATHCONF, getattr, pathconf, 0),
  2312. PROC(COMMIT, commit, commit, 5),
  2313. };
  2314. static unsigned int nfs_version3_counts[ARRAY_SIZE(nfs3_procedures)];
  2315. const struct rpc_version nfs_version3 = {
  2316. .number = 3,
  2317. .nrprocs = ARRAY_SIZE(nfs3_procedures),
  2318. .procs = nfs3_procedures,
  2319. .counts = nfs_version3_counts,
  2320. };
  2321. #ifdef CONFIG_NFS_V3_ACL
  2322. static const struct rpc_procinfo nfs3_acl_procedures[] = {
  2323. [ACLPROC3_GETACL] = {
  2324. .p_proc = ACLPROC3_GETACL,
  2325. .p_encode = nfs3_xdr_enc_getacl3args,
  2326. .p_decode = nfs3_xdr_dec_getacl3res,
  2327. .p_arglen = ACL3_getaclargs_sz,
  2328. .p_replen = ACL3_getaclres_sz,
  2329. .p_timer = 1,
  2330. .p_name = "GETACL",
  2331. },
  2332. [ACLPROC3_SETACL] = {
  2333. .p_proc = ACLPROC3_SETACL,
  2334. .p_encode = nfs3_xdr_enc_setacl3args,
  2335. .p_decode = nfs3_xdr_dec_setacl3res,
  2336. .p_arglen = ACL3_setaclargs_sz,
  2337. .p_replen = ACL3_setaclres_sz,
  2338. .p_timer = 0,
  2339. .p_name = "SETACL",
  2340. },
  2341. };
  2342. static unsigned int nfs3_acl_counts[ARRAY_SIZE(nfs3_acl_procedures)];
  2343. const struct rpc_version nfsacl_version3 = {
  2344. .number = 3,
  2345. .nrprocs = ARRAY_SIZE(nfs3_acl_procedures),
  2346. .procs = nfs3_acl_procedures,
  2347. .counts = nfs3_acl_counts,
  2348. };
  2349. #endif /* CONFIG_NFS_V3_ACL */