pnfs_osd_xdr.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * pNFS-osd on-the-wire data structures
  3. *
  4. * Copyright (C) 2007 Panasas Inc. [year of first publication]
  5. * All rights reserved.
  6. *
  7. * Benny Halevy <bhalevy@panasas.com>
  8. * Boaz Harrosh <bharrosh@panasas.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * See the file COPYING included with this distribution for more details.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * 3. Neither the name of the Panasas company nor the names of its
  24. * contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  28. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  29. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  34. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. #ifndef __PNFS_OSD_XDR_H__
  40. #define __PNFS_OSD_XDR_H__
  41. #include <linux/nfs_fs.h>
  42. #include <linux/nfs_page.h>
  43. /*
  44. * draft-ietf-nfsv4-minorversion-22
  45. * draft-ietf-nfsv4-pnfs-obj-12
  46. */
  47. /* Layout Structure */
  48. enum pnfs_osd_raid_algorithm4 {
  49. PNFS_OSD_RAID_0 = 1,
  50. PNFS_OSD_RAID_4 = 2,
  51. PNFS_OSD_RAID_5 = 3,
  52. PNFS_OSD_RAID_PQ = 4 /* Reed-Solomon P+Q */
  53. };
  54. /* struct pnfs_osd_data_map4 {
  55. * uint32_t odm_num_comps;
  56. * length4 odm_stripe_unit;
  57. * uint32_t odm_group_width;
  58. * uint32_t odm_group_depth;
  59. * uint32_t odm_mirror_cnt;
  60. * pnfs_osd_raid_algorithm4 odm_raid_algorithm;
  61. * };
  62. */
  63. struct pnfs_osd_data_map {
  64. u32 odm_num_comps;
  65. u64 odm_stripe_unit;
  66. u32 odm_group_width;
  67. u32 odm_group_depth;
  68. u32 odm_mirror_cnt;
  69. u32 odm_raid_algorithm;
  70. };
  71. /* struct pnfs_osd_objid4 {
  72. * deviceid4 oid_device_id;
  73. * uint64_t oid_partition_id;
  74. * uint64_t oid_object_id;
  75. * };
  76. */
  77. struct pnfs_osd_objid {
  78. struct nfs4_deviceid oid_device_id;
  79. u64 oid_partition_id;
  80. u64 oid_object_id;
  81. };
  82. /* For printout. I use:
  83. * kprint("dev(%llx:%llx)", _DEVID_LO(pointer), _DEVID_HI(pointer));
  84. * BE style
  85. */
  86. #define _DEVID_LO(oid_device_id) \
  87. (unsigned long long)be64_to_cpup((__be64 *)(oid_device_id)->data)
  88. #define _DEVID_HI(oid_device_id) \
  89. (unsigned long long)be64_to_cpup(((__be64 *)(oid_device_id)->data) + 1)
  90. enum pnfs_osd_version {
  91. PNFS_OSD_MISSING = 0,
  92. PNFS_OSD_VERSION_1 = 1,
  93. PNFS_OSD_VERSION_2 = 2
  94. };
  95. struct pnfs_osd_opaque_cred {
  96. u32 cred_len;
  97. void *cred;
  98. };
  99. enum pnfs_osd_cap_key_sec {
  100. PNFS_OSD_CAP_KEY_SEC_NONE = 0,
  101. PNFS_OSD_CAP_KEY_SEC_SSV = 1,
  102. };
  103. /* struct pnfs_osd_object_cred4 {
  104. * pnfs_osd_objid4 oc_object_id;
  105. * pnfs_osd_version4 oc_osd_version;
  106. * pnfs_osd_cap_key_sec4 oc_cap_key_sec;
  107. * opaque oc_capability_key<>;
  108. * opaque oc_capability<>;
  109. * };
  110. */
  111. struct pnfs_osd_object_cred {
  112. struct pnfs_osd_objid oc_object_id;
  113. u32 oc_osd_version;
  114. u32 oc_cap_key_sec;
  115. struct pnfs_osd_opaque_cred oc_cap_key;
  116. struct pnfs_osd_opaque_cred oc_cap;
  117. };
  118. /* struct pnfs_osd_layout4 {
  119. * pnfs_osd_data_map4 olo_map;
  120. * uint32_t olo_comps_index;
  121. * pnfs_osd_object_cred4 olo_components<>;
  122. * };
  123. */
  124. struct pnfs_osd_layout {
  125. struct pnfs_osd_data_map olo_map;
  126. u32 olo_comps_index;
  127. u32 olo_num_comps;
  128. struct pnfs_osd_object_cred *olo_comps;
  129. };
  130. /* Device Address */
  131. enum pnfs_osd_targetid_type {
  132. OBJ_TARGET_ANON = 1,
  133. OBJ_TARGET_SCSI_NAME = 2,
  134. OBJ_TARGET_SCSI_DEVICE_ID = 3,
  135. };
  136. /* union pnfs_osd_targetid4 switch (pnfs_osd_targetid_type4 oti_type) {
  137. * case OBJ_TARGET_SCSI_NAME:
  138. * string oti_scsi_name<>;
  139. *
  140. * case OBJ_TARGET_SCSI_DEVICE_ID:
  141. * opaque oti_scsi_device_id<>;
  142. *
  143. * default:
  144. * void;
  145. * };
  146. *
  147. * union pnfs_osd_targetaddr4 switch (bool ota_available) {
  148. * case TRUE:
  149. * netaddr4 ota_netaddr;
  150. * case FALSE:
  151. * void;
  152. * };
  153. *
  154. * struct pnfs_osd_deviceaddr4 {
  155. * pnfs_osd_targetid4 oda_targetid;
  156. * pnfs_osd_targetaddr4 oda_targetaddr;
  157. * uint64_t oda_lun;
  158. * opaque oda_systemid<>;
  159. * pnfs_osd_object_cred4 oda_root_obj_cred;
  160. * opaque oda_osdname<>;
  161. * };
  162. */
  163. struct pnfs_osd_targetid {
  164. u32 oti_type;
  165. struct nfs4_string oti_scsi_device_id;
  166. };
  167. /* struct netaddr4 {
  168. * // see struct rpcb in RFC1833
  169. * string r_netid<>; // network id
  170. * string r_addr<>; // universal address
  171. * };
  172. */
  173. struct pnfs_osd_net_addr {
  174. struct nfs4_string r_netid;
  175. struct nfs4_string r_addr;
  176. };
  177. struct pnfs_osd_targetaddr {
  178. u32 ota_available;
  179. struct pnfs_osd_net_addr ota_netaddr;
  180. };
  181. struct pnfs_osd_deviceaddr {
  182. struct pnfs_osd_targetid oda_targetid;
  183. struct pnfs_osd_targetaddr oda_targetaddr;
  184. u8 oda_lun[8];
  185. struct nfs4_string oda_systemid;
  186. struct pnfs_osd_object_cred oda_root_obj_cred;
  187. struct nfs4_string oda_osdname;
  188. };
  189. /* LAYOUTCOMMIT: layoutupdate */
  190. /* union pnfs_osd_deltaspaceused4 switch (bool dsu_valid) {
  191. * case TRUE:
  192. * int64_t dsu_delta;
  193. * case FALSE:
  194. * void;
  195. * };
  196. *
  197. * struct pnfs_osd_layoutupdate4 {
  198. * pnfs_osd_deltaspaceused4 olu_delta_space_used;
  199. * bool olu_ioerr_flag;
  200. * };
  201. */
  202. struct pnfs_osd_layoutupdate {
  203. u32 dsu_valid;
  204. s64 dsu_delta;
  205. u32 olu_ioerr_flag;
  206. };
  207. /* LAYOUTRETURN: I/O Rrror Report */
  208. enum pnfs_osd_errno {
  209. PNFS_OSD_ERR_EIO = 1,
  210. PNFS_OSD_ERR_NOT_FOUND = 2,
  211. PNFS_OSD_ERR_NO_SPACE = 3,
  212. PNFS_OSD_ERR_BAD_CRED = 4,
  213. PNFS_OSD_ERR_NO_ACCESS = 5,
  214. PNFS_OSD_ERR_UNREACHABLE = 6,
  215. PNFS_OSD_ERR_RESOURCE = 7
  216. };
  217. /* struct pnfs_osd_ioerr4 {
  218. * pnfs_osd_objid4 oer_component;
  219. * length4 oer_comp_offset;
  220. * length4 oer_comp_length;
  221. * bool oer_iswrite;
  222. * pnfs_osd_errno4 oer_errno;
  223. * };
  224. */
  225. struct pnfs_osd_ioerr {
  226. struct pnfs_osd_objid oer_component;
  227. u64 oer_comp_offset;
  228. u64 oer_comp_length;
  229. u32 oer_iswrite;
  230. u32 oer_errno;
  231. };
  232. /* OSD XDR Client API */
  233. /* Layout helpers */
  234. /* Layout decoding is done in two parts:
  235. * 1. First Call pnfs_osd_xdr_decode_layout_map to read in only the header part
  236. * of the layout. @iter members need not be initialized.
  237. * Returned:
  238. * @layout members are set. (@layout->olo_comps set to NULL).
  239. *
  240. * Zero on success, or negative error if passed xdr is broken.
  241. *
  242. * 2. 2nd Call pnfs_osd_xdr_decode_layout_comp() in a loop until it returns
  243. * false, to decode the next component.
  244. * Returned:
  245. * true if there is more to decode or false if we are done or error.
  246. *
  247. * Example:
  248. * struct pnfs_osd_xdr_decode_layout_iter iter;
  249. * struct pnfs_osd_layout layout;
  250. * struct pnfs_osd_object_cred comp;
  251. * int status;
  252. *
  253. * status = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
  254. * if (unlikely(status))
  255. * goto err;
  256. * while(pnfs_osd_xdr_decode_layout_comp(&comp, &iter, xdr, &status)) {
  257. * // All of @comp strings point to inside the xdr_buffer
  258. * // or scrach buffer. Copy them out to user memory eg.
  259. * copy_single_comp(dest_comp++, &comp);
  260. * }
  261. * if (unlikely(status))
  262. * goto err;
  263. */
  264. struct pnfs_osd_xdr_decode_layout_iter {
  265. unsigned total_comps;
  266. unsigned decoded_comps;
  267. };
  268. extern int pnfs_osd_xdr_decode_layout_map(struct pnfs_osd_layout *layout,
  269. struct pnfs_osd_xdr_decode_layout_iter *iter, struct xdr_stream *xdr);
  270. extern bool pnfs_osd_xdr_decode_layout_comp(struct pnfs_osd_object_cred *comp,
  271. struct pnfs_osd_xdr_decode_layout_iter *iter, struct xdr_stream *xdr,
  272. int *err);
  273. /* Device Info helpers */
  274. /* Note: All strings inside @deviceaddr point to space inside @p.
  275. * @p should stay valid while @deviceaddr is in use.
  276. */
  277. extern void pnfs_osd_xdr_decode_deviceaddr(
  278. struct pnfs_osd_deviceaddr *deviceaddr, __be32 *p);
  279. /* layoutupdate (layout_commit) xdr helpers */
  280. extern int
  281. pnfs_osd_xdr_encode_layoutupdate(struct xdr_stream *xdr,
  282. struct pnfs_osd_layoutupdate *lou);
  283. /* osd_ioerror encoding (layout_return) */
  284. extern __be32 *pnfs_osd_xdr_ioerr_reserve_space(struct xdr_stream *xdr);
  285. extern void pnfs_osd_xdr_encode_ioerr(__be32 *p, struct pnfs_osd_ioerr *ioerr);
  286. #endif /* __PNFS_OSD_XDR_H__ */