osd_ore.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (C) 2011
  3. * Boaz Harrosh <bharrosh@panasas.com>
  4. *
  5. * Public Declarations of the ORE API
  6. *
  7. * This file is part of the ORE (Object Raid Engine) library.
  8. *
  9. * ORE is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation. (GPL v2)
  12. *
  13. * ORE is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with the ORE; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef __ORE_H__
  23. #define __ORE_H__
  24. #include <scsi/osd_initiator.h>
  25. #include <scsi/osd_attributes.h>
  26. #include <scsi/osd_sec.h>
  27. #include <linux/pnfs_osd_xdr.h>
  28. struct ore_comp {
  29. struct osd_obj_id obj;
  30. u8 cred[OSD_CAP_LEN];
  31. };
  32. struct ore_layout {
  33. /* Our way of looking at the data_map */
  34. enum pnfs_osd_raid_algorithm4
  35. raid_algorithm;
  36. unsigned stripe_unit;
  37. unsigned mirrors_p1;
  38. unsigned group_width;
  39. unsigned parity;
  40. u64 group_depth;
  41. unsigned group_count;
  42. /* Cached often needed calculations filled in by
  43. * ore_verify_layout
  44. */
  45. unsigned long max_io_length; /* Max length that should be passed to
  46. * ore_get_rw_state
  47. */
  48. };
  49. struct ore_dev {
  50. struct osd_dev *od;
  51. };
  52. struct ore_components {
  53. unsigned first_dev; /* First logical device no */
  54. unsigned numdevs; /* Num of devices in array */
  55. /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
  56. * component. else there are @numdevs components
  57. */
  58. enum EC_COMP_USAGE {
  59. EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
  60. } single_comp;
  61. struct ore_comp *comps;
  62. /* Array of pointers to ore_dev-* . User will usually have these pointed
  63. * too a bigger struct which contain an "ore_dev ored" member and use
  64. * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
  65. * structure.
  66. */
  67. struct ore_dev **ods;
  68. };
  69. /* ore_comp_dev Recievies a logical device index */
  70. static inline struct osd_dev *ore_comp_dev(
  71. const struct ore_components *oc, unsigned i)
  72. {
  73. BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
  74. return oc->ods[i - oc->first_dev]->od;
  75. }
  76. static inline void ore_comp_set_dev(
  77. struct ore_components *oc, unsigned i, struct osd_dev *od)
  78. {
  79. oc->ods[i - oc->first_dev]->od = od;
  80. }
  81. struct ore_striping_info {
  82. u64 offset;
  83. u64 obj_offset;
  84. u64 length;
  85. u64 first_stripe_start; /* only used in raid writes */
  86. u64 M; /* for truncate */
  87. unsigned bytes_in_stripe;
  88. unsigned dev;
  89. unsigned par_dev;
  90. unsigned unit_off;
  91. unsigned cur_pg;
  92. unsigned cur_comp;
  93. };
  94. struct ore_io_state;
  95. typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
  96. struct _ore_r4w_op {
  97. /* @Priv given here is passed ios->private */
  98. struct page * (*get_page)(void *priv, u64 page_index, bool *uptodate);
  99. void (*put_page)(void *priv, struct page *page);
  100. };
  101. struct ore_io_state {
  102. struct kref kref;
  103. struct ore_striping_info si;
  104. void *private;
  105. ore_io_done_fn done;
  106. struct ore_layout *layout;
  107. struct ore_components *oc;
  108. /* Global read/write IO*/
  109. loff_t offset;
  110. unsigned long length;
  111. void *kern_buff;
  112. struct page **pages;
  113. unsigned nr_pages;
  114. unsigned pgbase;
  115. unsigned pages_consumed;
  116. /* Attributes */
  117. unsigned in_attr_len;
  118. struct osd_attr *in_attr;
  119. unsigned out_attr_len;
  120. struct osd_attr *out_attr;
  121. bool reading;
  122. /* House keeping of Parity pages */
  123. bool extra_part_alloc;
  124. struct page **parity_pages;
  125. unsigned max_par_pages;
  126. unsigned cur_par_page;
  127. unsigned sgs_per_dev;
  128. struct __stripe_pages_2d *sp2d;
  129. struct ore_io_state *ios_read_4_write;
  130. const struct _ore_r4w_op *r4w;
  131. /* Variable array of size numdevs */
  132. unsigned numdevs;
  133. struct ore_per_dev_state {
  134. struct osd_request *or;
  135. struct bio *bio;
  136. loff_t offset;
  137. unsigned length;
  138. unsigned last_sgs_total;
  139. unsigned dev;
  140. struct osd_sg_entry *sglist;
  141. unsigned cur_sg;
  142. } per_dev[];
  143. };
  144. static inline unsigned ore_io_state_size(unsigned numdevs)
  145. {
  146. return sizeof(struct ore_io_state) +
  147. sizeof(struct ore_per_dev_state) * numdevs;
  148. }
  149. /* ore.c */
  150. int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
  151. void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset,
  152. u64 length, struct ore_striping_info *si);
  153. int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
  154. bool is_reading, u64 offset, u64 length,
  155. struct ore_io_state **ios);
  156. int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
  157. struct ore_io_state **ios);
  158. void ore_put_io_state(struct ore_io_state *ios);
  159. typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od,
  160. unsigned dev_index, enum osd_err_priority oep,
  161. u64 dev_offset, u64 dev_len);
  162. int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep);
  163. int ore_create(struct ore_io_state *ios);
  164. int ore_remove(struct ore_io_state *ios);
  165. int ore_write(struct ore_io_state *ios);
  166. int ore_read(struct ore_io_state *ios);
  167. int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
  168. u64 size);
  169. int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
  170. extern const struct osd_attr g_attr_logical_length;
  171. #endif