nfs42xdr.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
  4. */
  5. #ifndef __LINUX_FS_NFS_NFS4_2XDR_H
  6. #define __LINUX_FS_NFS_NFS4_2XDR_H
  7. #include "nfs42.h"
  8. #define encode_fallocate_maxsz (encode_stateid_maxsz + \
  9. 2 /* offset */ + \
  10. 2 /* length */)
  11. #define NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\
  12. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  13. 2 /* wr_count */ + \
  14. 1 /* wr_committed */ + \
  15. XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  16. #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
  17. encode_fallocate_maxsz)
  18. #define decode_allocate_maxsz (op_decode_hdr_maxsz)
  19. #define encode_copy_maxsz (op_encode_hdr_maxsz + \
  20. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  21. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  22. 2 + 2 + 2 + 1 + 1 + 1 +\
  23. 1 + /* One cnr_source_server */\
  24. 1 + /* nl4_type */ \
  25. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  26. #define decode_copy_maxsz (op_decode_hdr_maxsz + \
  27. NFS42_WRITE_RES_SIZE + \
  28. 1 /* cr_consecutive */ + \
  29. 1 /* cr_synchronous */)
  30. #define encode_offload_cancel_maxsz (op_encode_hdr_maxsz + \
  31. XDR_QUADLEN(NFS4_STATEID_SIZE))
  32. #define decode_offload_cancel_maxsz (op_decode_hdr_maxsz)
  33. #define encode_copy_notify_maxsz (op_encode_hdr_maxsz + \
  34. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  35. 1 + /* nl4_type */ \
  36. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  37. #define decode_copy_notify_maxsz (op_decode_hdr_maxsz + \
  38. 3 + /* cnr_lease_time */\
  39. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  40. 1 + /* Support 1 cnr_source_server */\
  41. 1 + /* nl4_type */ \
  42. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  43. #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
  44. encode_fallocate_maxsz)
  45. #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
  46. #define encode_read_plus_maxsz (op_encode_hdr_maxsz + \
  47. encode_stateid_maxsz + 3)
  48. #define NFS42_READ_PLUS_SEGMENT_SIZE (1 /* data_content4 */ + \
  49. 2 /* data_info4.di_offset */ + \
  50. 2 /* data_info4.di_length */)
  51. #define decode_read_plus_maxsz (op_decode_hdr_maxsz + \
  52. 1 /* rpr_eof */ + \
  53. 1 /* rpr_contents count */ + \
  54. 2 * NFS42_READ_PLUS_SEGMENT_SIZE)
  55. #define encode_seek_maxsz (op_encode_hdr_maxsz + \
  56. encode_stateid_maxsz + \
  57. 2 /* offset */ + \
  58. 1 /* whence */)
  59. #define decode_seek_maxsz (op_decode_hdr_maxsz + \
  60. 1 /* eof */ + \
  61. 1 /* whence */ + \
  62. 2 /* offset */ + \
  63. 2 /* length */)
  64. #define encode_io_info_maxsz 4
  65. #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
  66. 2 /* offset */ + \
  67. 2 /* length */ + \
  68. encode_stateid_maxsz + \
  69. encode_io_info_maxsz + \
  70. encode_io_info_maxsz + \
  71. 1 /* opaque devaddr4 length */ + \
  72. XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
  73. #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
  74. #define encode_device_error_maxsz (XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
  75. 1 /* status */ + 1 /* opnum */)
  76. #define encode_layouterror_maxsz (op_decode_hdr_maxsz + \
  77. 2 /* offset */ + \
  78. 2 /* length */ + \
  79. encode_stateid_maxsz + \
  80. 1 /* Array size */ + \
  81. encode_device_error_maxsz)
  82. #define decode_layouterror_maxsz (op_decode_hdr_maxsz)
  83. #define encode_clone_maxsz (encode_stateid_maxsz + \
  84. encode_stateid_maxsz + \
  85. 2 /* src offset */ + \
  86. 2 /* dst offset */ + \
  87. 2 /* count */)
  88. #define decode_clone_maxsz (op_decode_hdr_maxsz)
  89. #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
  90. encode_sequence_maxsz + \
  91. encode_putfh_maxsz + \
  92. encode_allocate_maxsz + \
  93. encode_getattr_maxsz)
  94. #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
  95. decode_sequence_maxsz + \
  96. decode_putfh_maxsz + \
  97. decode_allocate_maxsz + \
  98. decode_getattr_maxsz)
  99. #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \
  100. encode_sequence_maxsz + \
  101. encode_putfh_maxsz + \
  102. encode_savefh_maxsz + \
  103. encode_putfh_maxsz + \
  104. encode_copy_maxsz + \
  105. encode_commit_maxsz)
  106. #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \
  107. decode_sequence_maxsz + \
  108. decode_putfh_maxsz + \
  109. decode_savefh_maxsz + \
  110. decode_putfh_maxsz + \
  111. decode_copy_maxsz + \
  112. decode_commit_maxsz)
  113. #define NFS4_enc_offload_cancel_sz (compound_encode_hdr_maxsz + \
  114. encode_sequence_maxsz + \
  115. encode_putfh_maxsz + \
  116. encode_offload_cancel_maxsz)
  117. #define NFS4_dec_offload_cancel_sz (compound_decode_hdr_maxsz + \
  118. decode_sequence_maxsz + \
  119. decode_putfh_maxsz + \
  120. decode_offload_cancel_maxsz)
  121. #define NFS4_enc_copy_notify_sz (compound_encode_hdr_maxsz + \
  122. encode_putfh_maxsz + \
  123. encode_copy_notify_maxsz)
  124. #define NFS4_dec_copy_notify_sz (compound_decode_hdr_maxsz + \
  125. decode_putfh_maxsz + \
  126. decode_copy_notify_maxsz)
  127. #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
  128. encode_sequence_maxsz + \
  129. encode_putfh_maxsz + \
  130. encode_deallocate_maxsz + \
  131. encode_getattr_maxsz)
  132. #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
  133. decode_sequence_maxsz + \
  134. decode_putfh_maxsz + \
  135. decode_deallocate_maxsz + \
  136. decode_getattr_maxsz)
  137. #define NFS4_enc_read_plus_sz (compound_encode_hdr_maxsz + \
  138. encode_sequence_maxsz + \
  139. encode_putfh_maxsz + \
  140. encode_read_plus_maxsz)
  141. #define NFS4_dec_read_plus_sz (compound_decode_hdr_maxsz + \
  142. decode_sequence_maxsz + \
  143. decode_putfh_maxsz + \
  144. decode_read_plus_maxsz)
  145. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  146. encode_sequence_maxsz + \
  147. encode_putfh_maxsz + \
  148. encode_seek_maxsz)
  149. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  150. decode_sequence_maxsz + \
  151. decode_putfh_maxsz + \
  152. decode_seek_maxsz)
  153. #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
  154. encode_sequence_maxsz + \
  155. encode_putfh_maxsz + \
  156. PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
  157. #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
  158. decode_sequence_maxsz + \
  159. decode_putfh_maxsz + \
  160. PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
  161. #define NFS4_enc_layouterror_sz (compound_encode_hdr_maxsz + \
  162. encode_sequence_maxsz + \
  163. encode_putfh_maxsz + \
  164. NFS42_LAYOUTERROR_MAX * \
  165. encode_layouterror_maxsz)
  166. #define NFS4_dec_layouterror_sz (compound_decode_hdr_maxsz + \
  167. decode_sequence_maxsz + \
  168. decode_putfh_maxsz + \
  169. NFS42_LAYOUTERROR_MAX * \
  170. decode_layouterror_maxsz)
  171. #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
  172. encode_sequence_maxsz + \
  173. encode_putfh_maxsz + \
  174. encode_savefh_maxsz + \
  175. encode_putfh_maxsz + \
  176. encode_clone_maxsz + \
  177. encode_getattr_maxsz)
  178. #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
  179. decode_sequence_maxsz + \
  180. decode_putfh_maxsz + \
  181. decode_savefh_maxsz + \
  182. decode_putfh_maxsz + \
  183. decode_clone_maxsz + \
  184. decode_getattr_maxsz)
  185. /* Not limited by NFS itself, limited by the generic xattr code */
  186. #define nfs4_xattr_name_maxsz XDR_QUADLEN(XATTR_NAME_MAX)
  187. #define encode_getxattr_maxsz (op_encode_hdr_maxsz + 1 + \
  188. nfs4_xattr_name_maxsz)
  189. #define decode_getxattr_maxsz (op_decode_hdr_maxsz + 1 + 1)
  190. #define encode_setxattr_maxsz (op_encode_hdr_maxsz + \
  191. 1 + nfs4_xattr_name_maxsz + 1)
  192. #define decode_setxattr_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  193. #define encode_listxattrs_maxsz (op_encode_hdr_maxsz + 2 + 1)
  194. #define decode_listxattrs_maxsz (op_decode_hdr_maxsz + 2 + 1 + 1 + 1)
  195. #define encode_removexattr_maxsz (op_encode_hdr_maxsz + 1 + \
  196. nfs4_xattr_name_maxsz)
  197. #define decode_removexattr_maxsz (op_decode_hdr_maxsz + \
  198. decode_change_info_maxsz)
  199. #define NFS4_enc_getxattr_sz (compound_encode_hdr_maxsz + \
  200. encode_sequence_maxsz + \
  201. encode_putfh_maxsz + \
  202. encode_getxattr_maxsz)
  203. #define NFS4_dec_getxattr_sz (compound_decode_hdr_maxsz + \
  204. decode_sequence_maxsz + \
  205. decode_putfh_maxsz + \
  206. decode_getxattr_maxsz)
  207. #define NFS4_enc_setxattr_sz (compound_encode_hdr_maxsz + \
  208. encode_sequence_maxsz + \
  209. encode_putfh_maxsz + \
  210. encode_setxattr_maxsz)
  211. #define NFS4_dec_setxattr_sz (compound_decode_hdr_maxsz + \
  212. decode_sequence_maxsz + \
  213. decode_putfh_maxsz + \
  214. decode_setxattr_maxsz)
  215. #define NFS4_enc_listxattrs_sz (compound_encode_hdr_maxsz + \
  216. encode_sequence_maxsz + \
  217. encode_putfh_maxsz + \
  218. encode_listxattrs_maxsz)
  219. #define NFS4_dec_listxattrs_sz (compound_decode_hdr_maxsz + \
  220. decode_sequence_maxsz + \
  221. decode_putfh_maxsz + \
  222. decode_listxattrs_maxsz)
  223. #define NFS4_enc_removexattr_sz (compound_encode_hdr_maxsz + \
  224. encode_sequence_maxsz + \
  225. encode_putfh_maxsz + \
  226. encode_removexattr_maxsz)
  227. #define NFS4_dec_removexattr_sz (compound_decode_hdr_maxsz + \
  228. decode_sequence_maxsz + \
  229. decode_putfh_maxsz + \
  230. decode_removexattr_maxsz)
  231. /*
  232. * These values specify the maximum amount of data that is not
  233. * associated with the extended attribute name or extended
  234. * attribute list in the SETXATTR, GETXATTR and LISTXATTR
  235. * respectively.
  236. */
  237. const u32 nfs42_maxsetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  238. compound_encode_hdr_maxsz +
  239. encode_sequence_maxsz +
  240. encode_putfh_maxsz + 1 +
  241. nfs4_xattr_name_maxsz)
  242. * XDR_UNIT);
  243. const u32 nfs42_maxgetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  244. compound_decode_hdr_maxsz +
  245. decode_sequence_maxsz +
  246. decode_putfh_maxsz + 1) * XDR_UNIT);
  247. const u32 nfs42_maxlistxattrs_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  248. compound_decode_hdr_maxsz +
  249. decode_sequence_maxsz +
  250. decode_putfh_maxsz + 3) * XDR_UNIT);
  251. static void encode_fallocate(struct xdr_stream *xdr,
  252. const struct nfs42_falloc_args *args)
  253. {
  254. encode_nfs4_stateid(xdr, &args->falloc_stateid);
  255. encode_uint64(xdr, args->falloc_offset);
  256. encode_uint64(xdr, args->falloc_length);
  257. }
  258. static void encode_allocate(struct xdr_stream *xdr,
  259. const struct nfs42_falloc_args *args,
  260. struct compound_hdr *hdr)
  261. {
  262. encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
  263. encode_fallocate(xdr, args);
  264. }
  265. static void encode_nl4_server(struct xdr_stream *xdr,
  266. const struct nl4_server *ns)
  267. {
  268. encode_uint32(xdr, ns->nl4_type);
  269. switch (ns->nl4_type) {
  270. case NL4_NAME:
  271. case NL4_URL:
  272. encode_string(xdr, ns->u.nl4_str_sz, ns->u.nl4_str);
  273. break;
  274. case NL4_NETADDR:
  275. encode_string(xdr, ns->u.nl4_addr.netid_len,
  276. ns->u.nl4_addr.netid);
  277. encode_string(xdr, ns->u.nl4_addr.addr_len,
  278. ns->u.nl4_addr.addr);
  279. break;
  280. default:
  281. WARN_ON_ONCE(1);
  282. }
  283. }
  284. static void encode_copy(struct xdr_stream *xdr,
  285. const struct nfs42_copy_args *args,
  286. struct compound_hdr *hdr)
  287. {
  288. encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
  289. encode_nfs4_stateid(xdr, &args->src_stateid);
  290. encode_nfs4_stateid(xdr, &args->dst_stateid);
  291. encode_uint64(xdr, args->src_pos);
  292. encode_uint64(xdr, args->dst_pos);
  293. encode_uint64(xdr, args->count);
  294. encode_uint32(xdr, 1); /* consecutive = true */
  295. encode_uint32(xdr, args->sync);
  296. if (args->cp_src == NULL) { /* intra-ssc */
  297. encode_uint32(xdr, 0); /* no src server list */
  298. return;
  299. }
  300. encode_uint32(xdr, 1); /* supporting 1 server */
  301. encode_nl4_server(xdr, args->cp_src);
  302. }
  303. static void encode_offload_cancel(struct xdr_stream *xdr,
  304. const struct nfs42_offload_status_args *args,
  305. struct compound_hdr *hdr)
  306. {
  307. encode_op_hdr(xdr, OP_OFFLOAD_CANCEL, decode_offload_cancel_maxsz, hdr);
  308. encode_nfs4_stateid(xdr, &args->osa_stateid);
  309. }
  310. static void encode_copy_notify(struct xdr_stream *xdr,
  311. const struct nfs42_copy_notify_args *args,
  312. struct compound_hdr *hdr)
  313. {
  314. encode_op_hdr(xdr, OP_COPY_NOTIFY, decode_copy_notify_maxsz, hdr);
  315. encode_nfs4_stateid(xdr, &args->cna_src_stateid);
  316. encode_nl4_server(xdr, &args->cna_dst);
  317. }
  318. static void encode_deallocate(struct xdr_stream *xdr,
  319. const struct nfs42_falloc_args *args,
  320. struct compound_hdr *hdr)
  321. {
  322. encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
  323. encode_fallocate(xdr, args);
  324. }
  325. static void encode_read_plus(struct xdr_stream *xdr,
  326. const struct nfs_pgio_args *args,
  327. struct compound_hdr *hdr)
  328. {
  329. encode_op_hdr(xdr, OP_READ_PLUS, decode_read_plus_maxsz, hdr);
  330. encode_nfs4_stateid(xdr, &args->stateid);
  331. encode_uint64(xdr, args->offset);
  332. encode_uint32(xdr, args->count);
  333. }
  334. static void encode_seek(struct xdr_stream *xdr,
  335. const struct nfs42_seek_args *args,
  336. struct compound_hdr *hdr)
  337. {
  338. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  339. encode_nfs4_stateid(xdr, &args->sa_stateid);
  340. encode_uint64(xdr, args->sa_offset);
  341. encode_uint32(xdr, args->sa_what);
  342. }
  343. static void encode_layoutstats(struct xdr_stream *xdr,
  344. const struct nfs42_layoutstat_args *args,
  345. struct nfs42_layoutstat_devinfo *devinfo,
  346. struct compound_hdr *hdr)
  347. {
  348. __be32 *p;
  349. encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
  350. p = reserve_space(xdr, 8 + 8);
  351. p = xdr_encode_hyper(p, devinfo->offset);
  352. p = xdr_encode_hyper(p, devinfo->length);
  353. encode_nfs4_stateid(xdr, &args->stateid);
  354. p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
  355. p = xdr_encode_hyper(p, devinfo->read_count);
  356. p = xdr_encode_hyper(p, devinfo->read_bytes);
  357. p = xdr_encode_hyper(p, devinfo->write_count);
  358. p = xdr_encode_hyper(p, devinfo->write_bytes);
  359. p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
  360. NFS4_DEVICEID4_SIZE);
  361. /* Encode layoutupdate4 */
  362. *p++ = cpu_to_be32(devinfo->layout_type);
  363. if (devinfo->ld_private.ops)
  364. devinfo->ld_private.ops->encode(xdr, args,
  365. &devinfo->ld_private);
  366. else
  367. encode_uint32(xdr, 0);
  368. }
  369. static void encode_clone(struct xdr_stream *xdr,
  370. const struct nfs42_clone_args *args,
  371. struct compound_hdr *hdr)
  372. {
  373. __be32 *p;
  374. encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr);
  375. encode_nfs4_stateid(xdr, &args->src_stateid);
  376. encode_nfs4_stateid(xdr, &args->dst_stateid);
  377. p = reserve_space(xdr, 3*8);
  378. p = xdr_encode_hyper(p, args->src_offset);
  379. p = xdr_encode_hyper(p, args->dst_offset);
  380. xdr_encode_hyper(p, args->count);
  381. }
  382. static void encode_device_error(struct xdr_stream *xdr,
  383. const struct nfs42_device_error *error)
  384. {
  385. __be32 *p;
  386. p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 2*4);
  387. p = xdr_encode_opaque_fixed(p, error->dev_id.data,
  388. NFS4_DEVICEID4_SIZE);
  389. *p++ = cpu_to_be32(error->status);
  390. *p = cpu_to_be32(error->opnum);
  391. }
  392. static void encode_layouterror(struct xdr_stream *xdr,
  393. const struct nfs42_layout_error *args,
  394. struct compound_hdr *hdr)
  395. {
  396. __be32 *p;
  397. encode_op_hdr(xdr, OP_LAYOUTERROR, decode_layouterror_maxsz, hdr);
  398. p = reserve_space(xdr, 8 + 8);
  399. p = xdr_encode_hyper(p, args->offset);
  400. p = xdr_encode_hyper(p, args->length);
  401. encode_nfs4_stateid(xdr, &args->stateid);
  402. p = reserve_space(xdr, 4);
  403. *p = cpu_to_be32(1);
  404. encode_device_error(xdr, &args->errors[0]);
  405. }
  406. static void encode_setxattr(struct xdr_stream *xdr,
  407. const struct nfs42_setxattrargs *arg,
  408. struct compound_hdr *hdr)
  409. {
  410. __be32 *p;
  411. BUILD_BUG_ON(XATTR_CREATE != SETXATTR4_CREATE);
  412. BUILD_BUG_ON(XATTR_REPLACE != SETXATTR4_REPLACE);
  413. encode_op_hdr(xdr, OP_SETXATTR, decode_setxattr_maxsz, hdr);
  414. p = reserve_space(xdr, 4);
  415. *p = cpu_to_be32(arg->xattr_flags);
  416. encode_string(xdr, strlen(arg->xattr_name), arg->xattr_name);
  417. p = reserve_space(xdr, 4);
  418. *p = cpu_to_be32(arg->xattr_len);
  419. if (arg->xattr_len)
  420. xdr_write_pages(xdr, arg->xattr_pages, 0, arg->xattr_len);
  421. }
  422. static int decode_setxattr(struct xdr_stream *xdr,
  423. struct nfs4_change_info *cinfo)
  424. {
  425. int status;
  426. status = decode_op_hdr(xdr, OP_SETXATTR);
  427. if (status)
  428. goto out;
  429. status = decode_change_info(xdr, cinfo);
  430. out:
  431. return status;
  432. }
  433. static void encode_getxattr(struct xdr_stream *xdr, const char *name,
  434. struct compound_hdr *hdr)
  435. {
  436. encode_op_hdr(xdr, OP_GETXATTR, decode_getxattr_maxsz, hdr);
  437. encode_string(xdr, strlen(name), name);
  438. }
  439. static int decode_getxattr(struct xdr_stream *xdr,
  440. struct nfs42_getxattrres *res,
  441. struct rpc_rqst *req)
  442. {
  443. int status;
  444. __be32 *p;
  445. u32 len, rdlen;
  446. status = decode_op_hdr(xdr, OP_GETXATTR);
  447. if (status)
  448. return status;
  449. p = xdr_inline_decode(xdr, 4);
  450. if (unlikely(!p))
  451. return -EIO;
  452. len = be32_to_cpup(p);
  453. if (len > req->rq_rcv_buf.page_len)
  454. return -ERANGE;
  455. res->xattr_len = len;
  456. if (len > 0) {
  457. rdlen = xdr_read_pages(xdr, len);
  458. if (rdlen < len)
  459. return -EIO;
  460. }
  461. return 0;
  462. }
  463. static void encode_removexattr(struct xdr_stream *xdr, const char *name,
  464. struct compound_hdr *hdr)
  465. {
  466. encode_op_hdr(xdr, OP_REMOVEXATTR, decode_removexattr_maxsz, hdr);
  467. encode_string(xdr, strlen(name), name);
  468. }
  469. static int decode_removexattr(struct xdr_stream *xdr,
  470. struct nfs4_change_info *cinfo)
  471. {
  472. int status;
  473. status = decode_op_hdr(xdr, OP_REMOVEXATTR);
  474. if (status)
  475. goto out;
  476. status = decode_change_info(xdr, cinfo);
  477. out:
  478. return status;
  479. }
  480. static void encode_listxattrs(struct xdr_stream *xdr,
  481. const struct nfs42_listxattrsargs *arg,
  482. struct compound_hdr *hdr)
  483. {
  484. __be32 *p;
  485. encode_op_hdr(xdr, OP_LISTXATTRS, decode_listxattrs_maxsz, hdr);
  486. p = reserve_space(xdr, 12);
  487. if (unlikely(!p))
  488. return;
  489. p = xdr_encode_hyper(p, arg->cookie);
  490. /*
  491. * RFC 8276 says to specify the full max length of the LISTXATTRS
  492. * XDR reply. Count is set to the XDR length of the names array
  493. * plus the EOF marker. So, add the cookie and the names count.
  494. */
  495. *p = cpu_to_be32(arg->count + 8 + 4);
  496. }
  497. static int decode_listxattrs(struct xdr_stream *xdr,
  498. struct nfs42_listxattrsres *res)
  499. {
  500. int status;
  501. __be32 *p;
  502. u32 count, len, ulen;
  503. size_t left, copied;
  504. char *buf;
  505. status = decode_op_hdr(xdr, OP_LISTXATTRS);
  506. if (status) {
  507. /*
  508. * Special case: for LISTXATTRS, NFS4ERR_TOOSMALL
  509. * should be translated to ERANGE.
  510. */
  511. if (status == -ETOOSMALL)
  512. status = -ERANGE;
  513. goto out;
  514. }
  515. p = xdr_inline_decode(xdr, 8);
  516. if (unlikely(!p))
  517. return -EIO;
  518. xdr_decode_hyper(p, &res->cookie);
  519. p = xdr_inline_decode(xdr, 4);
  520. if (unlikely(!p))
  521. return -EIO;
  522. left = res->xattr_len;
  523. buf = res->xattr_buf;
  524. count = be32_to_cpup(p);
  525. copied = 0;
  526. /*
  527. * We have asked for enough room to encode the maximum number
  528. * of possible attribute names, so everything should fit.
  529. *
  530. * But, don't rely on that assumption. Just decode entries
  531. * until they don't fit anymore, just in case the server did
  532. * something odd.
  533. */
  534. while (count--) {
  535. p = xdr_inline_decode(xdr, 4);
  536. if (unlikely(!p))
  537. return -EIO;
  538. len = be32_to_cpup(p);
  539. if (len > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) {
  540. status = -ERANGE;
  541. goto out;
  542. }
  543. p = xdr_inline_decode(xdr, len);
  544. if (unlikely(!p))
  545. return -EIO;
  546. ulen = len + XATTR_USER_PREFIX_LEN + 1;
  547. if (buf) {
  548. if (ulen > left) {
  549. status = -ERANGE;
  550. goto out;
  551. }
  552. memcpy(buf, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
  553. memcpy(buf + XATTR_USER_PREFIX_LEN, p, len);
  554. buf[ulen - 1] = 0;
  555. buf += ulen;
  556. left -= ulen;
  557. }
  558. copied += ulen;
  559. }
  560. p = xdr_inline_decode(xdr, 4);
  561. if (unlikely(!p))
  562. return -EIO;
  563. res->eof = be32_to_cpup(p);
  564. res->copied = copied;
  565. out:
  566. if (status == -ERANGE && res->xattr_len == XATTR_LIST_MAX)
  567. status = -E2BIG;
  568. return status;
  569. }
  570. /*
  571. * Encode ALLOCATE request
  572. */
  573. static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
  574. struct xdr_stream *xdr,
  575. const void *data)
  576. {
  577. const struct nfs42_falloc_args *args = data;
  578. struct compound_hdr hdr = {
  579. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  580. };
  581. encode_compound_hdr(xdr, req, &hdr);
  582. encode_sequence(xdr, &args->seq_args, &hdr);
  583. encode_putfh(xdr, args->falloc_fh, &hdr);
  584. encode_allocate(xdr, args, &hdr);
  585. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  586. encode_nops(&hdr);
  587. }
  588. static void encode_copy_commit(struct xdr_stream *xdr,
  589. const struct nfs42_copy_args *args,
  590. struct compound_hdr *hdr)
  591. {
  592. __be32 *p;
  593. encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
  594. p = reserve_space(xdr, 12);
  595. p = xdr_encode_hyper(p, args->dst_pos);
  596. *p = cpu_to_be32(args->count);
  597. }
  598. /*
  599. * Encode COPY request
  600. */
  601. static void nfs4_xdr_enc_copy(struct rpc_rqst *req,
  602. struct xdr_stream *xdr,
  603. const void *data)
  604. {
  605. const struct nfs42_copy_args *args = data;
  606. struct compound_hdr hdr = {
  607. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  608. };
  609. encode_compound_hdr(xdr, req, &hdr);
  610. encode_sequence(xdr, &args->seq_args, &hdr);
  611. encode_putfh(xdr, args->src_fh, &hdr);
  612. encode_savefh(xdr, &hdr);
  613. encode_putfh(xdr, args->dst_fh, &hdr);
  614. encode_copy(xdr, args, &hdr);
  615. if (args->sync)
  616. encode_copy_commit(xdr, args, &hdr);
  617. encode_nops(&hdr);
  618. }
  619. /*
  620. * Encode OFFLOAD_CANEL request
  621. */
  622. static void nfs4_xdr_enc_offload_cancel(struct rpc_rqst *req,
  623. struct xdr_stream *xdr,
  624. const void *data)
  625. {
  626. const struct nfs42_offload_status_args *args = data;
  627. struct compound_hdr hdr = {
  628. .minorversion = nfs4_xdr_minorversion(&args->osa_seq_args),
  629. };
  630. encode_compound_hdr(xdr, req, &hdr);
  631. encode_sequence(xdr, &args->osa_seq_args, &hdr);
  632. encode_putfh(xdr, args->osa_src_fh, &hdr);
  633. encode_offload_cancel(xdr, args, &hdr);
  634. encode_nops(&hdr);
  635. }
  636. /*
  637. * Encode COPY_NOTIFY request
  638. */
  639. static void nfs4_xdr_enc_copy_notify(struct rpc_rqst *req,
  640. struct xdr_stream *xdr,
  641. const void *data)
  642. {
  643. const struct nfs42_copy_notify_args *args = data;
  644. struct compound_hdr hdr = {
  645. .minorversion = nfs4_xdr_minorversion(&args->cna_seq_args),
  646. };
  647. encode_compound_hdr(xdr, req, &hdr);
  648. encode_sequence(xdr, &args->cna_seq_args, &hdr);
  649. encode_putfh(xdr, args->cna_src_fh, &hdr);
  650. encode_copy_notify(xdr, args, &hdr);
  651. encode_nops(&hdr);
  652. }
  653. /*
  654. * Encode DEALLOCATE request
  655. */
  656. static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
  657. struct xdr_stream *xdr,
  658. const void *data)
  659. {
  660. const struct nfs42_falloc_args *args = data;
  661. struct compound_hdr hdr = {
  662. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  663. };
  664. encode_compound_hdr(xdr, req, &hdr);
  665. encode_sequence(xdr, &args->seq_args, &hdr);
  666. encode_putfh(xdr, args->falloc_fh, &hdr);
  667. encode_deallocate(xdr, args, &hdr);
  668. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  669. encode_nops(&hdr);
  670. }
  671. /*
  672. * Encode READ_PLUS request
  673. */
  674. static void nfs4_xdr_enc_read_plus(struct rpc_rqst *req,
  675. struct xdr_stream *xdr,
  676. const void *data)
  677. {
  678. const struct nfs_pgio_args *args = data;
  679. struct compound_hdr hdr = {
  680. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  681. };
  682. encode_compound_hdr(xdr, req, &hdr);
  683. encode_sequence(xdr, &args->seq_args, &hdr);
  684. encode_putfh(xdr, args->fh, &hdr);
  685. encode_read_plus(xdr, args, &hdr);
  686. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  687. args->count, hdr.replen);
  688. encode_nops(&hdr);
  689. }
  690. /*
  691. * Encode SEEK request
  692. */
  693. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  694. struct xdr_stream *xdr,
  695. const void *data)
  696. {
  697. const struct nfs42_seek_args *args = data;
  698. struct compound_hdr hdr = {
  699. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  700. };
  701. encode_compound_hdr(xdr, req, &hdr);
  702. encode_sequence(xdr, &args->seq_args, &hdr);
  703. encode_putfh(xdr, args->sa_fh, &hdr);
  704. encode_seek(xdr, args, &hdr);
  705. encode_nops(&hdr);
  706. }
  707. /*
  708. * Encode LAYOUTSTATS request
  709. */
  710. static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
  711. struct xdr_stream *xdr,
  712. const void *data)
  713. {
  714. const struct nfs42_layoutstat_args *args = data;
  715. int i;
  716. struct compound_hdr hdr = {
  717. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  718. };
  719. encode_compound_hdr(xdr, req, &hdr);
  720. encode_sequence(xdr, &args->seq_args, &hdr);
  721. encode_putfh(xdr, args->fh, &hdr);
  722. WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  723. for (i = 0; i < args->num_dev; i++)
  724. encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
  725. encode_nops(&hdr);
  726. }
  727. /*
  728. * Encode CLONE request
  729. */
  730. static void nfs4_xdr_enc_clone(struct rpc_rqst *req,
  731. struct xdr_stream *xdr,
  732. const void *data)
  733. {
  734. const struct nfs42_clone_args *args = data;
  735. struct compound_hdr hdr = {
  736. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  737. };
  738. encode_compound_hdr(xdr, req, &hdr);
  739. encode_sequence(xdr, &args->seq_args, &hdr);
  740. encode_putfh(xdr, args->src_fh, &hdr);
  741. encode_savefh(xdr, &hdr);
  742. encode_putfh(xdr, args->dst_fh, &hdr);
  743. encode_clone(xdr, args, &hdr);
  744. encode_getfattr(xdr, args->dst_bitmask, &hdr);
  745. encode_nops(&hdr);
  746. }
  747. /*
  748. * Encode LAYOUTERROR request
  749. */
  750. static void nfs4_xdr_enc_layouterror(struct rpc_rqst *req,
  751. struct xdr_stream *xdr,
  752. const void *data)
  753. {
  754. const struct nfs42_layouterror_args *args = data;
  755. struct compound_hdr hdr = {
  756. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  757. };
  758. int i;
  759. encode_compound_hdr(xdr, req, &hdr);
  760. encode_sequence(xdr, &args->seq_args, &hdr);
  761. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  762. for (i = 0; i < args->num_errors; i++)
  763. encode_layouterror(xdr, &args->errors[i], &hdr);
  764. encode_nops(&hdr);
  765. }
  766. static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  767. {
  768. return decode_op_hdr(xdr, OP_ALLOCATE);
  769. }
  770. static int decode_write_response(struct xdr_stream *xdr,
  771. struct nfs42_write_res *res)
  772. {
  773. __be32 *p;
  774. int status, count;
  775. p = xdr_inline_decode(xdr, 4);
  776. if (unlikely(!p))
  777. return -EIO;
  778. count = be32_to_cpup(p);
  779. if (count > 1)
  780. return -EREMOTEIO;
  781. else if (count == 1) {
  782. status = decode_opaque_fixed(xdr, &res->stateid,
  783. NFS4_STATEID_SIZE);
  784. if (unlikely(status))
  785. return -EIO;
  786. }
  787. p = xdr_inline_decode(xdr, 8 + 4);
  788. if (unlikely(!p))
  789. return -EIO;
  790. p = xdr_decode_hyper(p, &res->count);
  791. res->verifier.committed = be32_to_cpup(p);
  792. return decode_verifier(xdr, &res->verifier.verifier);
  793. }
  794. static int decode_nl4_server(struct xdr_stream *xdr, struct nl4_server *ns)
  795. {
  796. struct nfs42_netaddr *naddr;
  797. uint32_t dummy;
  798. char *dummy_str;
  799. __be32 *p;
  800. int status;
  801. /* nl_type */
  802. p = xdr_inline_decode(xdr, 4);
  803. if (unlikely(!p))
  804. return -EIO;
  805. ns->nl4_type = be32_to_cpup(p);
  806. switch (ns->nl4_type) {
  807. case NL4_NAME:
  808. case NL4_URL:
  809. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  810. if (unlikely(status))
  811. return status;
  812. if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
  813. return -EIO;
  814. memcpy(&ns->u.nl4_str, dummy_str, dummy);
  815. ns->u.nl4_str_sz = dummy;
  816. break;
  817. case NL4_NETADDR:
  818. naddr = &ns->u.nl4_addr;
  819. /* netid string */
  820. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  821. if (unlikely(status))
  822. return status;
  823. if (unlikely(dummy > RPCBIND_MAXNETIDLEN))
  824. return -EIO;
  825. naddr->netid_len = dummy;
  826. memcpy(naddr->netid, dummy_str, naddr->netid_len);
  827. /* uaddr string */
  828. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  829. if (unlikely(status))
  830. return status;
  831. if (unlikely(dummy > RPCBIND_MAXUADDRLEN))
  832. return -EIO;
  833. naddr->addr_len = dummy;
  834. memcpy(naddr->addr, dummy_str, naddr->addr_len);
  835. break;
  836. default:
  837. WARN_ON_ONCE(1);
  838. return -EIO;
  839. }
  840. return 0;
  841. }
  842. static int decode_copy_requirements(struct xdr_stream *xdr,
  843. struct nfs42_copy_res *res) {
  844. __be32 *p;
  845. p = xdr_inline_decode(xdr, 4 + 4);
  846. if (unlikely(!p))
  847. return -EIO;
  848. res->consecutive = be32_to_cpup(p++);
  849. res->synchronous = be32_to_cpup(p++);
  850. return 0;
  851. }
  852. static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
  853. {
  854. int status;
  855. status = decode_op_hdr(xdr, OP_COPY);
  856. if (status == NFS4ERR_OFFLOAD_NO_REQS) {
  857. status = decode_copy_requirements(xdr, res);
  858. if (status)
  859. return status;
  860. return NFS4ERR_OFFLOAD_NO_REQS;
  861. } else if (status)
  862. return status;
  863. status = decode_write_response(xdr, &res->write_res);
  864. if (status)
  865. return status;
  866. return decode_copy_requirements(xdr, res);
  867. }
  868. static int decode_offload_cancel(struct xdr_stream *xdr,
  869. struct nfs42_offload_status_res *res)
  870. {
  871. return decode_op_hdr(xdr, OP_OFFLOAD_CANCEL);
  872. }
  873. static int decode_copy_notify(struct xdr_stream *xdr,
  874. struct nfs42_copy_notify_res *res)
  875. {
  876. __be32 *p;
  877. int status, count;
  878. status = decode_op_hdr(xdr, OP_COPY_NOTIFY);
  879. if (status)
  880. return status;
  881. /* cnr_lease_time */
  882. p = xdr_inline_decode(xdr, 12);
  883. if (unlikely(!p))
  884. return -EIO;
  885. p = xdr_decode_hyper(p, &res->cnr_lease_time.seconds);
  886. res->cnr_lease_time.nseconds = be32_to_cpup(p);
  887. status = decode_opaque_fixed(xdr, &res->cnr_stateid, NFS4_STATEID_SIZE);
  888. if (unlikely(status))
  889. return -EIO;
  890. /* number of source addresses */
  891. p = xdr_inline_decode(xdr, 4);
  892. if (unlikely(!p))
  893. return -EIO;
  894. count = be32_to_cpup(p);
  895. if (count > 1)
  896. pr_warn("NFS: %s: nsvr %d > Supported. Use first servers\n",
  897. __func__, count);
  898. status = decode_nl4_server(xdr, &res->cnr_src);
  899. if (unlikely(status))
  900. return -EIO;
  901. return 0;
  902. }
  903. static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  904. {
  905. return decode_op_hdr(xdr, OP_DEALLOCATE);
  906. }
  907. static int decode_read_plus_data(struct xdr_stream *xdr,
  908. struct nfs_pgio_res *res)
  909. {
  910. uint32_t count, recvd;
  911. uint64_t offset;
  912. __be32 *p;
  913. p = xdr_inline_decode(xdr, 8 + 4);
  914. if (!p)
  915. return 1;
  916. p = xdr_decode_hyper(p, &offset);
  917. count = be32_to_cpup(p);
  918. recvd = xdr_align_data(xdr, res->count, count);
  919. res->count += recvd;
  920. if (count > recvd)
  921. return 1;
  922. return 0;
  923. }
  924. static int decode_read_plus_hole(struct xdr_stream *xdr, struct nfs_pgio_res *res,
  925. uint32_t *eof)
  926. {
  927. uint64_t offset, length, recvd;
  928. __be32 *p;
  929. p = xdr_inline_decode(xdr, 8 + 8);
  930. if (!p)
  931. return 1;
  932. p = xdr_decode_hyper(p, &offset);
  933. p = xdr_decode_hyper(p, &length);
  934. recvd = xdr_expand_hole(xdr, res->count, length);
  935. res->count += recvd;
  936. if (recvd < length)
  937. return 1;
  938. return 0;
  939. }
  940. static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  941. {
  942. uint32_t eof, segments, type;
  943. int status, i;
  944. __be32 *p;
  945. status = decode_op_hdr(xdr, OP_READ_PLUS);
  946. if (status)
  947. return status;
  948. p = xdr_inline_decode(xdr, 4 + 4);
  949. if (unlikely(!p))
  950. return -EIO;
  951. eof = be32_to_cpup(p++);
  952. segments = be32_to_cpup(p++);
  953. if (segments == 0)
  954. goto out;
  955. for (i = 0; i < segments; i++) {
  956. p = xdr_inline_decode(xdr, 4);
  957. if (!p)
  958. goto early_out;
  959. type = be32_to_cpup(p++);
  960. if (type == NFS4_CONTENT_DATA)
  961. status = decode_read_plus_data(xdr, res);
  962. else if (type == NFS4_CONTENT_HOLE)
  963. status = decode_read_plus_hole(xdr, res, &eof);
  964. else
  965. return -EINVAL;
  966. if (status < 0)
  967. return status;
  968. if (status > 0)
  969. goto early_out;
  970. }
  971. out:
  972. res->eof = eof;
  973. return 0;
  974. early_out:
  975. if (unlikely(!i))
  976. return -EIO;
  977. res->eof = 0;
  978. return 0;
  979. }
  980. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  981. {
  982. int status;
  983. __be32 *p;
  984. status = decode_op_hdr(xdr, OP_SEEK);
  985. if (status)
  986. return status;
  987. p = xdr_inline_decode(xdr, 4 + 8);
  988. if (unlikely(!p))
  989. return -EIO;
  990. res->sr_eof = be32_to_cpup(p++);
  991. p = xdr_decode_hyper(p, &res->sr_offset);
  992. return 0;
  993. }
  994. static int decode_layoutstats(struct xdr_stream *xdr)
  995. {
  996. return decode_op_hdr(xdr, OP_LAYOUTSTATS);
  997. }
  998. static int decode_clone(struct xdr_stream *xdr)
  999. {
  1000. return decode_op_hdr(xdr, OP_CLONE);
  1001. }
  1002. static int decode_layouterror(struct xdr_stream *xdr)
  1003. {
  1004. return decode_op_hdr(xdr, OP_LAYOUTERROR);
  1005. }
  1006. /*
  1007. * Decode ALLOCATE request
  1008. */
  1009. static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
  1010. struct xdr_stream *xdr,
  1011. void *data)
  1012. {
  1013. struct nfs42_falloc_res *res = data;
  1014. struct compound_hdr hdr;
  1015. int status;
  1016. status = decode_compound_hdr(xdr, &hdr);
  1017. if (status)
  1018. goto out;
  1019. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1020. if (status)
  1021. goto out;
  1022. status = decode_putfh(xdr);
  1023. if (status)
  1024. goto out;
  1025. status = decode_allocate(xdr, res);
  1026. if (status)
  1027. goto out;
  1028. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  1029. out:
  1030. return status;
  1031. }
  1032. /*
  1033. * Decode COPY response
  1034. */
  1035. static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp,
  1036. struct xdr_stream *xdr,
  1037. void *data)
  1038. {
  1039. struct nfs42_copy_res *res = data;
  1040. struct compound_hdr hdr;
  1041. int status;
  1042. status = decode_compound_hdr(xdr, &hdr);
  1043. if (status)
  1044. goto out;
  1045. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1046. if (status)
  1047. goto out;
  1048. status = decode_putfh(xdr);
  1049. if (status)
  1050. goto out;
  1051. status = decode_savefh(xdr);
  1052. if (status)
  1053. goto out;
  1054. status = decode_putfh(xdr);
  1055. if (status)
  1056. goto out;
  1057. status = decode_copy(xdr, res);
  1058. if (status)
  1059. goto out;
  1060. if (res->commit_res.verf)
  1061. status = decode_commit(xdr, &res->commit_res);
  1062. out:
  1063. return status;
  1064. }
  1065. /*
  1066. * Decode OFFLOAD_CANCEL response
  1067. */
  1068. static int nfs4_xdr_dec_offload_cancel(struct rpc_rqst *rqstp,
  1069. struct xdr_stream *xdr,
  1070. void *data)
  1071. {
  1072. struct nfs42_offload_status_res *res = data;
  1073. struct compound_hdr hdr;
  1074. int status;
  1075. status = decode_compound_hdr(xdr, &hdr);
  1076. if (status)
  1077. goto out;
  1078. status = decode_sequence(xdr, &res->osr_seq_res, rqstp);
  1079. if (status)
  1080. goto out;
  1081. status = decode_putfh(xdr);
  1082. if (status)
  1083. goto out;
  1084. status = decode_offload_cancel(xdr, res);
  1085. out:
  1086. return status;
  1087. }
  1088. /*
  1089. * Decode COPY_NOTIFY response
  1090. */
  1091. static int nfs4_xdr_dec_copy_notify(struct rpc_rqst *rqstp,
  1092. struct xdr_stream *xdr,
  1093. void *data)
  1094. {
  1095. struct nfs42_copy_notify_res *res = data;
  1096. struct compound_hdr hdr;
  1097. int status;
  1098. status = decode_compound_hdr(xdr, &hdr);
  1099. if (status)
  1100. goto out;
  1101. status = decode_sequence(xdr, &res->cnr_seq_res, rqstp);
  1102. if (status)
  1103. goto out;
  1104. status = decode_putfh(xdr);
  1105. if (status)
  1106. goto out;
  1107. status = decode_copy_notify(xdr, res);
  1108. out:
  1109. return status;
  1110. }
  1111. /*
  1112. * Decode DEALLOCATE request
  1113. */
  1114. static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
  1115. struct xdr_stream *xdr,
  1116. void *data)
  1117. {
  1118. struct nfs42_falloc_res *res = data;
  1119. struct compound_hdr hdr;
  1120. int status;
  1121. status = decode_compound_hdr(xdr, &hdr);
  1122. if (status)
  1123. goto out;
  1124. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1125. if (status)
  1126. goto out;
  1127. status = decode_putfh(xdr);
  1128. if (status)
  1129. goto out;
  1130. status = decode_deallocate(xdr, res);
  1131. if (status)
  1132. goto out;
  1133. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  1134. out:
  1135. return status;
  1136. }
  1137. /*
  1138. * Decode READ_PLUS request
  1139. */
  1140. static int nfs4_xdr_dec_read_plus(struct rpc_rqst *rqstp,
  1141. struct xdr_stream *xdr,
  1142. void *data)
  1143. {
  1144. struct nfs_pgio_res *res = data;
  1145. struct compound_hdr hdr;
  1146. int status;
  1147. status = decode_compound_hdr(xdr, &hdr);
  1148. if (status)
  1149. goto out;
  1150. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1151. if (status)
  1152. goto out;
  1153. status = decode_putfh(xdr);
  1154. if (status)
  1155. goto out;
  1156. status = decode_read_plus(xdr, res);
  1157. if (!status)
  1158. status = res->count;
  1159. out:
  1160. return status;
  1161. }
  1162. /*
  1163. * Decode SEEK request
  1164. */
  1165. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  1166. struct xdr_stream *xdr,
  1167. void *data)
  1168. {
  1169. struct nfs42_seek_res *res = data;
  1170. struct compound_hdr hdr;
  1171. int status;
  1172. status = decode_compound_hdr(xdr, &hdr);
  1173. if (status)
  1174. goto out;
  1175. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1176. if (status)
  1177. goto out;
  1178. status = decode_putfh(xdr);
  1179. if (status)
  1180. goto out;
  1181. status = decode_seek(xdr, res);
  1182. out:
  1183. return status;
  1184. }
  1185. /*
  1186. * Decode LAYOUTSTATS request
  1187. */
  1188. static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
  1189. struct xdr_stream *xdr,
  1190. void *data)
  1191. {
  1192. struct nfs42_layoutstat_res *res = data;
  1193. struct compound_hdr hdr;
  1194. int status, i;
  1195. status = decode_compound_hdr(xdr, &hdr);
  1196. if (status)
  1197. goto out;
  1198. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1199. if (status)
  1200. goto out;
  1201. status = decode_putfh(xdr);
  1202. if (status)
  1203. goto out;
  1204. WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  1205. for (i = 0; i < res->num_dev; i++) {
  1206. status = decode_layoutstats(xdr);
  1207. if (status)
  1208. goto out;
  1209. }
  1210. out:
  1211. res->rpc_status = status;
  1212. return status;
  1213. }
  1214. /*
  1215. * Decode CLONE request
  1216. */
  1217. static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp,
  1218. struct xdr_stream *xdr,
  1219. void *data)
  1220. {
  1221. struct nfs42_clone_res *res = data;
  1222. struct compound_hdr hdr;
  1223. int status;
  1224. status = decode_compound_hdr(xdr, &hdr);
  1225. if (status)
  1226. goto out;
  1227. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1228. if (status)
  1229. goto out;
  1230. status = decode_putfh(xdr);
  1231. if (status)
  1232. goto out;
  1233. status = decode_savefh(xdr);
  1234. if (status)
  1235. goto out;
  1236. status = decode_putfh(xdr);
  1237. if (status)
  1238. goto out;
  1239. status = decode_clone(xdr);
  1240. if (status)
  1241. goto out;
  1242. decode_getfattr(xdr, res->dst_fattr, res->server);
  1243. out:
  1244. res->rpc_status = status;
  1245. return status;
  1246. }
  1247. /*
  1248. * Decode LAYOUTERROR request
  1249. */
  1250. static int nfs4_xdr_dec_layouterror(struct rpc_rqst *rqstp,
  1251. struct xdr_stream *xdr,
  1252. void *data)
  1253. {
  1254. struct nfs42_layouterror_res *res = data;
  1255. struct compound_hdr hdr;
  1256. int status, i;
  1257. status = decode_compound_hdr(xdr, &hdr);
  1258. if (status)
  1259. goto out;
  1260. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1261. if (status)
  1262. goto out;
  1263. status = decode_putfh(xdr);
  1264. for (i = 0; i < res->num_errors && status == 0; i++)
  1265. status = decode_layouterror(xdr);
  1266. out:
  1267. res->rpc_status = status;
  1268. return status;
  1269. }
  1270. #ifdef CONFIG_NFS_V4_2
  1271. static void nfs4_xdr_enc_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  1272. const void *data)
  1273. {
  1274. const struct nfs42_setxattrargs *args = data;
  1275. struct compound_hdr hdr = {
  1276. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1277. };
  1278. encode_compound_hdr(xdr, req, &hdr);
  1279. encode_sequence(xdr, &args->seq_args, &hdr);
  1280. encode_putfh(xdr, args->fh, &hdr);
  1281. encode_setxattr(xdr, args, &hdr);
  1282. encode_nops(&hdr);
  1283. }
  1284. static int nfs4_xdr_dec_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  1285. void *data)
  1286. {
  1287. struct nfs42_setxattrres *res = data;
  1288. struct compound_hdr hdr;
  1289. int status;
  1290. status = decode_compound_hdr(xdr, &hdr);
  1291. if (status)
  1292. goto out;
  1293. status = decode_sequence(xdr, &res->seq_res, req);
  1294. if (status)
  1295. goto out;
  1296. status = decode_putfh(xdr);
  1297. if (status)
  1298. goto out;
  1299. status = decode_setxattr(xdr, &res->cinfo);
  1300. out:
  1301. return status;
  1302. }
  1303. static void nfs4_xdr_enc_getxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  1304. const void *data)
  1305. {
  1306. const struct nfs42_getxattrargs *args = data;
  1307. struct compound_hdr hdr = {
  1308. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1309. };
  1310. size_t plen;
  1311. encode_compound_hdr(xdr, req, &hdr);
  1312. encode_sequence(xdr, &args->seq_args, &hdr);
  1313. encode_putfh(xdr, args->fh, &hdr);
  1314. encode_getxattr(xdr, args->xattr_name, &hdr);
  1315. plen = args->xattr_len ? args->xattr_len : XATTR_SIZE_MAX;
  1316. rpc_prepare_reply_pages(req, args->xattr_pages, 0, plen,
  1317. hdr.replen);
  1318. req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
  1319. encode_nops(&hdr);
  1320. }
  1321. static int nfs4_xdr_dec_getxattr(struct rpc_rqst *rqstp,
  1322. struct xdr_stream *xdr, void *data)
  1323. {
  1324. struct nfs42_getxattrres *res = data;
  1325. struct compound_hdr hdr;
  1326. int status;
  1327. status = decode_compound_hdr(xdr, &hdr);
  1328. if (status)
  1329. goto out;
  1330. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1331. if (status)
  1332. goto out;
  1333. status = decode_putfh(xdr);
  1334. if (status)
  1335. goto out;
  1336. status = decode_getxattr(xdr, res, rqstp);
  1337. out:
  1338. return status;
  1339. }
  1340. static void nfs4_xdr_enc_listxattrs(struct rpc_rqst *req,
  1341. struct xdr_stream *xdr, const void *data)
  1342. {
  1343. const struct nfs42_listxattrsargs *args = data;
  1344. struct compound_hdr hdr = {
  1345. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1346. };
  1347. encode_compound_hdr(xdr, req, &hdr);
  1348. encode_sequence(xdr, &args->seq_args, &hdr);
  1349. encode_putfh(xdr, args->fh, &hdr);
  1350. encode_listxattrs(xdr, args, &hdr);
  1351. rpc_prepare_reply_pages(req, args->xattr_pages, 0, args->count,
  1352. hdr.replen);
  1353. encode_nops(&hdr);
  1354. }
  1355. static int nfs4_xdr_dec_listxattrs(struct rpc_rqst *rqstp,
  1356. struct xdr_stream *xdr, void *data)
  1357. {
  1358. struct nfs42_listxattrsres *res = data;
  1359. struct compound_hdr hdr;
  1360. int status;
  1361. xdr_set_scratch_buffer(xdr, page_address(res->scratch), PAGE_SIZE);
  1362. status = decode_compound_hdr(xdr, &hdr);
  1363. if (status)
  1364. goto out;
  1365. status = decode_sequence(xdr, &res->seq_res, rqstp);
  1366. if (status)
  1367. goto out;
  1368. status = decode_putfh(xdr);
  1369. if (status)
  1370. goto out;
  1371. status = decode_listxattrs(xdr, res);
  1372. out:
  1373. return status;
  1374. }
  1375. static void nfs4_xdr_enc_removexattr(struct rpc_rqst *req,
  1376. struct xdr_stream *xdr, const void *data)
  1377. {
  1378. const struct nfs42_removexattrargs *args = data;
  1379. struct compound_hdr hdr = {
  1380. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1381. };
  1382. encode_compound_hdr(xdr, req, &hdr);
  1383. encode_sequence(xdr, &args->seq_args, &hdr);
  1384. encode_putfh(xdr, args->fh, &hdr);
  1385. encode_removexattr(xdr, args->xattr_name, &hdr);
  1386. encode_nops(&hdr);
  1387. }
  1388. static int nfs4_xdr_dec_removexattr(struct rpc_rqst *req,
  1389. struct xdr_stream *xdr, void *data)
  1390. {
  1391. struct nfs42_removexattrres *res = data;
  1392. struct compound_hdr hdr;
  1393. int status;
  1394. status = decode_compound_hdr(xdr, &hdr);
  1395. if (status)
  1396. goto out;
  1397. status = decode_sequence(xdr, &res->seq_res, req);
  1398. if (status)
  1399. goto out;
  1400. status = decode_putfh(xdr);
  1401. if (status)
  1402. goto out;
  1403. status = decode_removexattr(xdr, &res->cinfo);
  1404. out:
  1405. return status;
  1406. }
  1407. #endif
  1408. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */