osd_ore.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. #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. };
  95. struct ore_io_state;
  96. typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
  97. struct _ore_r4w_op {
  98. /* @Priv given here is passed ios->private */
  99. struct page * (*get_page)(void *priv, u64 page_index, bool *uptodate);
  100. void (*put_page)(void *priv, struct page *page);
  101. };
  102. struct ore_io_state {
  103. struct kref kref;
  104. struct ore_striping_info si;
  105. void *private;
  106. ore_io_done_fn done;
  107. struct ore_layout *layout;
  108. struct ore_components *oc;
  109. /* Global read/write IO*/
  110. loff_t offset;
  111. unsigned long length;
  112. void *kern_buff;
  113. struct page **pages;
  114. unsigned nr_pages;
  115. unsigned pgbase;
  116. unsigned pages_consumed;
  117. /* Attributes */
  118. unsigned in_attr_len;
  119. struct osd_attr *in_attr;
  120. unsigned out_attr_len;
  121. struct osd_attr *out_attr;
  122. bool reading;
  123. /* House keeping of Parity pages */
  124. bool extra_part_alloc;
  125. struct page **parity_pages;
  126. unsigned max_par_pages;
  127. unsigned cur_par_page;
  128. unsigned sgs_per_dev;
  129. struct __stripe_pages_2d *sp2d;
  130. struct ore_io_state *ios_read_4_write;
  131. const struct _ore_r4w_op *r4w;
  132. /* Variable array of size numdevs */
  133. unsigned numdevs;
  134. struct ore_per_dev_state {
  135. struct osd_request *or;
  136. struct bio *bio;
  137. loff_t offset;
  138. unsigned length;
  139. unsigned last_sgs_total;
  140. unsigned dev;
  141. struct osd_sg_entry *sglist;
  142. unsigned cur_sg;
  143. } per_dev[];
  144. };
  145. static inline unsigned ore_io_state_size(unsigned numdevs)
  146. {
  147. return sizeof(struct ore_io_state) +
  148. sizeof(struct ore_per_dev_state) * numdevs;
  149. }
  150. /* ore.c */
  151. int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
  152. void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset,
  153. u64 length, struct ore_striping_info *si);
  154. int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
  155. bool is_reading, u64 offset, u64 length,
  156. struct ore_io_state **ios);
  157. int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
  158. struct ore_io_state **ios);
  159. void ore_put_io_state(struct ore_io_state *ios);
  160. typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od,
  161. unsigned dev_index, enum osd_err_priority oep,
  162. u64 dev_offset, u64 dev_len);
  163. int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep);
  164. int ore_create(struct ore_io_state *ios);
  165. int ore_remove(struct ore_io_state *ios);
  166. int ore_write(struct ore_io_state *ios);
  167. int ore_read(struct ore_io_state *ios);
  168. int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
  169. u64 size);
  170. int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
  171. extern const struct osd_attr g_attr_logical_length;
  172. #endif