pnfs_osd_xdr.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 <ooo@electrozaur.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. /*
  43. * draft-ietf-nfsv4-minorversion-22
  44. * draft-ietf-nfsv4-pnfs-obj-12
  45. */
  46. /* Layout Structure */
  47. enum pnfs_osd_raid_algorithm4 {
  48. PNFS_OSD_RAID_0 = 1,
  49. PNFS_OSD_RAID_4 = 2,
  50. PNFS_OSD_RAID_5 = 3,
  51. PNFS_OSD_RAID_PQ = 4 /* Reed-Solomon P+Q */
  52. };
  53. /* struct pnfs_osd_data_map4 {
  54. * uint32_t odm_num_comps;
  55. * length4 odm_stripe_unit;
  56. * uint32_t odm_group_width;
  57. * uint32_t odm_group_depth;
  58. * uint32_t odm_mirror_cnt;
  59. * pnfs_osd_raid_algorithm4 odm_raid_algorithm;
  60. * };
  61. */
  62. struct pnfs_osd_data_map {
  63. u32 odm_num_comps;
  64. u64 odm_stripe_unit;
  65. u32 odm_group_width;
  66. u32 odm_group_depth;
  67. u32 odm_mirror_cnt;
  68. u32 odm_raid_algorithm;
  69. };
  70. /* struct pnfs_osd_objid4 {
  71. * deviceid4 oid_device_id;
  72. * uint64_t oid_partition_id;
  73. * uint64_t oid_object_id;
  74. * };
  75. */
  76. struct pnfs_osd_objid {
  77. struct nfs4_deviceid oid_device_id;
  78. u64 oid_partition_id;
  79. u64 oid_object_id;
  80. };
  81. /* For printout. I use:
  82. * kprint("dev(%llx:%llx)", _DEVID_LO(pointer), _DEVID_HI(pointer));
  83. * BE style
  84. */
  85. #define _DEVID_LO(oid_device_id) \
  86. (unsigned long long)be64_to_cpup((__be64 *)(oid_device_id)->data)
  87. #define _DEVID_HI(oid_device_id) \
  88. (unsigned long long)be64_to_cpup(((__be64 *)(oid_device_id)->data) + 1)
  89. enum pnfs_osd_version {
  90. PNFS_OSD_MISSING = 0,
  91. PNFS_OSD_VERSION_1 = 1,
  92. PNFS_OSD_VERSION_2 = 2
  93. };
  94. struct pnfs_osd_opaque_cred {
  95. u32 cred_len;
  96. void *cred;
  97. };
  98. enum pnfs_osd_cap_key_sec {
  99. PNFS_OSD_CAP_KEY_SEC_NONE = 0,
  100. PNFS_OSD_CAP_KEY_SEC_SSV = 1,
  101. };
  102. /* struct pnfs_osd_object_cred4 {
  103. * pnfs_osd_objid4 oc_object_id;
  104. * pnfs_osd_version4 oc_osd_version;
  105. * pnfs_osd_cap_key_sec4 oc_cap_key_sec;
  106. * opaque oc_capability_key<>;
  107. * opaque oc_capability<>;
  108. * };
  109. */
  110. struct pnfs_osd_object_cred {
  111. struct pnfs_osd_objid oc_object_id;
  112. u32 oc_osd_version;
  113. u32 oc_cap_key_sec;
  114. struct pnfs_osd_opaque_cred oc_cap_key;
  115. struct pnfs_osd_opaque_cred oc_cap;
  116. };
  117. /* struct pnfs_osd_layout4 {
  118. * pnfs_osd_data_map4 olo_map;
  119. * uint32_t olo_comps_index;
  120. * pnfs_osd_object_cred4 olo_components<>;
  121. * };
  122. */
  123. struct pnfs_osd_layout {
  124. struct pnfs_osd_data_map olo_map;
  125. u32 olo_comps_index;
  126. u32 olo_num_comps;
  127. struct pnfs_osd_object_cred *olo_comps;
  128. };
  129. /* Device Address */
  130. enum pnfs_osd_targetid_type {
  131. OBJ_TARGET_ANON = 1,
  132. OBJ_TARGET_SCSI_NAME = 2,
  133. OBJ_TARGET_SCSI_DEVICE_ID = 3,
  134. };
  135. /* union pnfs_osd_targetid4 switch (pnfs_osd_targetid_type4 oti_type) {
  136. * case OBJ_TARGET_SCSI_NAME:
  137. * string oti_scsi_name<>;
  138. *
  139. * case OBJ_TARGET_SCSI_DEVICE_ID:
  140. * opaque oti_scsi_device_id<>;
  141. *
  142. * default:
  143. * void;
  144. * };
  145. *
  146. * union pnfs_osd_targetaddr4 switch (bool ota_available) {
  147. * case TRUE:
  148. * netaddr4 ota_netaddr;
  149. * case FALSE:
  150. * void;
  151. * };
  152. *
  153. * struct pnfs_osd_deviceaddr4 {
  154. * pnfs_osd_targetid4 oda_targetid;
  155. * pnfs_osd_targetaddr4 oda_targetaddr;
  156. * uint64_t oda_lun;
  157. * opaque oda_systemid<>;
  158. * pnfs_osd_object_cred4 oda_root_obj_cred;
  159. * opaque oda_osdname<>;
  160. * };
  161. */
  162. struct pnfs_osd_targetid {
  163. u32 oti_type;
  164. struct nfs4_string oti_scsi_device_id;
  165. };
  166. /* struct netaddr4 {
  167. * // see struct rpcb in RFC1833
  168. * string r_netid<>; // network id
  169. * string r_addr<>; // universal address
  170. * };
  171. */
  172. struct pnfs_osd_net_addr {
  173. struct nfs4_string r_netid;
  174. struct nfs4_string r_addr;
  175. };
  176. struct pnfs_osd_targetaddr {
  177. u32 ota_available;
  178. struct pnfs_osd_net_addr ota_netaddr;
  179. };
  180. struct pnfs_osd_deviceaddr {
  181. struct pnfs_osd_targetid oda_targetid;
  182. struct pnfs_osd_targetaddr oda_targetaddr;
  183. u8 oda_lun[8];
  184. struct nfs4_string oda_systemid;
  185. struct pnfs_osd_object_cred oda_root_obj_cred;
  186. struct nfs4_string oda_osdname;
  187. };
  188. /* LAYOUTCOMMIT: layoutupdate */
  189. /* union pnfs_osd_deltaspaceused4 switch (bool dsu_valid) {
  190. * case TRUE:
  191. * int64_t dsu_delta;
  192. * case FALSE:
  193. * void;
  194. * };
  195. *
  196. * struct pnfs_osd_layoutupdate4 {
  197. * pnfs_osd_deltaspaceused4 olu_delta_space_used;
  198. * bool olu_ioerr_flag;
  199. * };
  200. */
  201. struct pnfs_osd_layoutupdate {
  202. u32 dsu_valid;
  203. s64 dsu_delta;
  204. u32 olu_ioerr_flag;
  205. };
  206. /* LAYOUTRETURN: I/O Rrror Report */
  207. enum pnfs_osd_errno {
  208. PNFS_OSD_ERR_EIO = 1,
  209. PNFS_OSD_ERR_NOT_FOUND = 2,
  210. PNFS_OSD_ERR_NO_SPACE = 3,
  211. PNFS_OSD_ERR_BAD_CRED = 4,
  212. PNFS_OSD_ERR_NO_ACCESS = 5,
  213. PNFS_OSD_ERR_UNREACHABLE = 6,
  214. PNFS_OSD_ERR_RESOURCE = 7
  215. };
  216. /* struct pnfs_osd_ioerr4 {
  217. * pnfs_osd_objid4 oer_component;
  218. * length4 oer_comp_offset;
  219. * length4 oer_comp_length;
  220. * bool oer_iswrite;
  221. * pnfs_osd_errno4 oer_errno;
  222. * };
  223. */
  224. struct pnfs_osd_ioerr {
  225. struct pnfs_osd_objid oer_component;
  226. u64 oer_comp_offset;
  227. u64 oer_comp_length;
  228. u32 oer_iswrite;
  229. u32 oer_errno;
  230. };
  231. /* OSD XDR Client API */
  232. /* Layout helpers */
  233. /* Layout decoding is done in two parts:
  234. * 1. First Call pnfs_osd_xdr_decode_layout_map to read in only the header part
  235. * of the layout. @iter members need not be initialized.
  236. * Returned:
  237. * @layout members are set. (@layout->olo_comps set to NULL).
  238. *
  239. * Zero on success, or negative error if passed xdr is broken.
  240. *
  241. * 2. 2nd Call pnfs_osd_xdr_decode_layout_comp() in a loop until it returns
  242. * false, to decode the next component.
  243. * Returned:
  244. * true if there is more to decode or false if we are done or error.
  245. *
  246. * Example:
  247. * struct pnfs_osd_xdr_decode_layout_iter iter;
  248. * struct pnfs_osd_layout layout;
  249. * struct pnfs_osd_object_cred comp;
  250. * int status;
  251. *
  252. * status = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr);
  253. * if (unlikely(status))
  254. * goto err;
  255. * while(pnfs_osd_xdr_decode_layout_comp(&comp, &iter, xdr, &status)) {
  256. * // All of @comp strings point to inside the xdr_buffer
  257. * // or scrach buffer. Copy them out to user memory eg.
  258. * copy_single_comp(dest_comp++, &comp);
  259. * }
  260. * if (unlikely(status))
  261. * goto err;
  262. */
  263. struct pnfs_osd_xdr_decode_layout_iter {
  264. unsigned total_comps;
  265. unsigned decoded_comps;
  266. };
  267. extern int pnfs_osd_xdr_decode_layout_map(struct pnfs_osd_layout *layout,
  268. struct pnfs_osd_xdr_decode_layout_iter *iter, struct xdr_stream *xdr);
  269. extern bool pnfs_osd_xdr_decode_layout_comp(struct pnfs_osd_object_cred *comp,
  270. struct pnfs_osd_xdr_decode_layout_iter *iter, struct xdr_stream *xdr,
  271. int *err);
  272. /* Device Info helpers */
  273. /* Note: All strings inside @deviceaddr point to space inside @p.
  274. * @p should stay valid while @deviceaddr is in use.
  275. */
  276. extern void pnfs_osd_xdr_decode_deviceaddr(
  277. struct pnfs_osd_deviceaddr *deviceaddr, __be32 *p);
  278. /* layoutupdate (layout_commit) xdr helpers */
  279. extern int
  280. pnfs_osd_xdr_encode_layoutupdate(struct xdr_stream *xdr,
  281. struct pnfs_osd_layoutupdate *lou);
  282. /* osd_ioerror encoding (layout_return) */
  283. extern __be32 *pnfs_osd_xdr_ioerr_reserve_space(struct xdr_stream *xdr);
  284. extern void pnfs_osd_xdr_encode_ioerr(__be32 *p, struct pnfs_osd_ioerr *ioerr);
  285. #endif /* __PNFS_OSD_XDR_H__ */