osd_ore.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (C) 2011
  3. * Boaz Harrosh <ooo@electrozaur.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. #include <linux/bug.h>
  29. struct ore_comp {
  30. struct osd_obj_id obj;
  31. u8 cred[OSD_CAP_LEN];
  32. };
  33. struct ore_layout {
  34. /* Our way of looking at the data_map */
  35. enum pnfs_osd_raid_algorithm4
  36. raid_algorithm;
  37. unsigned stripe_unit;
  38. unsigned mirrors_p1;
  39. unsigned group_width;
  40. unsigned parity;
  41. u64 group_depth;
  42. unsigned group_count;
  43. /* Cached often needed calculations filled in by
  44. * ore_verify_layout
  45. */
  46. unsigned long max_io_length; /* Max length that should be passed to
  47. * ore_get_rw_state
  48. */
  49. };
  50. struct ore_dev {
  51. struct osd_dev *od;
  52. };
  53. struct ore_components {
  54. unsigned first_dev; /* First logical device no */
  55. unsigned numdevs; /* Num of devices in array */
  56. /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
  57. * component. else there are @numdevs components
  58. */
  59. enum EC_COMP_USAGE {
  60. EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
  61. } single_comp;
  62. struct ore_comp *comps;
  63. /* Array of pointers to ore_dev-* . User will usually have these pointed
  64. * too a bigger struct which contain an "ore_dev ored" member and use
  65. * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
  66. * structure.
  67. */
  68. struct ore_dev **ods;
  69. };
  70. /* ore_comp_dev Recievies a logical device index */
  71. static inline struct osd_dev *ore_comp_dev(
  72. const struct ore_components *oc, unsigned i)
  73. {
  74. BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
  75. return oc->ods[i - oc->first_dev]->od;
  76. }
  77. static inline void ore_comp_set_dev(
  78. struct ore_components *oc, unsigned i, struct osd_dev *od)
  79. {
  80. oc->ods[i - oc->first_dev]->od = od;
  81. }
  82. struct ore_striping_info {
  83. u64 offset;
  84. u64 obj_offset;
  85. u64 length;
  86. u64 first_stripe_start; /* only used in raid writes */
  87. u64 M; /* for truncate */
  88. unsigned bytes_in_stripe;
  89. unsigned dev;
  90. unsigned par_dev;
  91. unsigned unit_off;
  92. unsigned cur_pg;
  93. unsigned cur_comp;
  94. unsigned maxdevUnits;
  95. };
  96. struct ore_io_state;
  97. typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
  98. struct _ore_r4w_op {
  99. /* @Priv given here is passed ios->private */
  100. struct page * (*get_page)(void *priv, u64 page_index, bool *uptodate);
  101. void (*put_page)(void *priv, struct page *page);
  102. };
  103. struct ore_io_state {
  104. struct kref kref;
  105. struct ore_striping_info si;
  106. void *private;
  107. ore_io_done_fn done;
  108. struct ore_layout *layout;
  109. struct ore_components *oc;
  110. /* Global read/write IO*/
  111. loff_t offset;
  112. unsigned long length;
  113. void *kern_buff;
  114. struct page **pages;
  115. unsigned nr_pages;
  116. unsigned pgbase;
  117. unsigned pages_consumed;
  118. /* Attributes */
  119. unsigned in_attr_len;
  120. struct osd_attr *in_attr;
  121. unsigned out_attr_len;
  122. struct osd_attr *out_attr;
  123. bool reading;
  124. /* House keeping of Parity pages */
  125. bool extra_part_alloc;
  126. struct page **parity_pages;
  127. unsigned max_par_pages;
  128. unsigned cur_par_page;
  129. unsigned sgs_per_dev;
  130. struct __stripe_pages_2d *sp2d;
  131. struct ore_io_state *ios_read_4_write;
  132. const struct _ore_r4w_op *r4w;
  133. /* Variable array of size numdevs */
  134. unsigned numdevs;
  135. struct ore_per_dev_state {
  136. struct osd_request *or;
  137. struct bio *bio;
  138. loff_t offset;
  139. unsigned length;
  140. unsigned last_sgs_total;
  141. unsigned dev;
  142. struct osd_sg_entry *sglist;
  143. unsigned cur_sg;
  144. } per_dev[];
  145. };
  146. static inline unsigned ore_io_state_size(unsigned numdevs)
  147. {
  148. return sizeof(struct ore_io_state) +
  149. sizeof(struct ore_per_dev_state) * numdevs;
  150. }
  151. /* ore.c */
  152. int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
  153. void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset,
  154. u64 length, struct ore_striping_info *si);
  155. int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
  156. bool is_reading, u64 offset, u64 length,
  157. struct ore_io_state **ios);
  158. int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
  159. struct ore_io_state **ios);
  160. void ore_put_io_state(struct ore_io_state *ios);
  161. typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od,
  162. unsigned dev_index, enum osd_err_priority oep,
  163. u64 dev_offset, u64 dev_len);
  164. int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep);
  165. int ore_create(struct ore_io_state *ios);
  166. int ore_remove(struct ore_io_state *ios);
  167. int ore_write(struct ore_io_state *ios);
  168. int ore_read(struct ore_io_state *ios);
  169. int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
  170. u64 size);
  171. int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
  172. extern const struct osd_attr g_attr_logical_length;
  173. #endif