osd_ore.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. u64 group_depth;
  40. unsigned group_count;
  41. /* Cached often needed calculations filled in by
  42. * ore_verify_layout
  43. */
  44. unsigned long max_io_length; /* Max length that should be passed to
  45. * ore_get_rw_state
  46. */
  47. };
  48. struct ore_dev {
  49. struct osd_dev *od;
  50. };
  51. struct ore_components {
  52. unsigned first_dev; /* First logical device no */
  53. unsigned numdevs; /* Num of devices in array */
  54. /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
  55. * component. else there are @numdevs components
  56. */
  57. enum EC_COMP_USAGE {
  58. EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
  59. } single_comp;
  60. struct ore_comp *comps;
  61. /* Array of pointers to ore_dev-* . User will usually have these pointed
  62. * too a bigger struct which contain an "ore_dev ored" member and use
  63. * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
  64. * structure.
  65. */
  66. struct ore_dev **ods;
  67. };
  68. /* ore_comp_dev Recievies a logical device index */
  69. static inline struct osd_dev *ore_comp_dev(
  70. const struct ore_components *oc, unsigned i)
  71. {
  72. BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
  73. return oc->ods[i - oc->first_dev]->od;
  74. }
  75. static inline void ore_comp_set_dev(
  76. struct ore_components *oc, unsigned i, struct osd_dev *od)
  77. {
  78. oc->ods[i - oc->first_dev]->od = od;
  79. }
  80. struct ore_striping_info {
  81. u64 obj_offset;
  82. u64 group_length;
  83. u64 M; /* for truncate */
  84. unsigned dev;
  85. unsigned unit_off;
  86. };
  87. struct ore_io_state;
  88. typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
  89. struct ore_io_state {
  90. struct kref kref;
  91. struct ore_striping_info si;
  92. void *private;
  93. ore_io_done_fn done;
  94. struct ore_layout *layout;
  95. struct ore_components *oc;
  96. /* Global read/write IO*/
  97. loff_t offset;
  98. unsigned long length;
  99. void *kern_buff;
  100. struct page **pages;
  101. unsigned nr_pages;
  102. unsigned pgbase;
  103. unsigned pages_consumed;
  104. /* Attributes */
  105. unsigned in_attr_len;
  106. struct osd_attr *in_attr;
  107. unsigned out_attr_len;
  108. struct osd_attr *out_attr;
  109. bool reading;
  110. /* Variable array of size numdevs */
  111. unsigned numdevs;
  112. struct ore_per_dev_state {
  113. struct osd_request *or;
  114. struct bio *bio;
  115. loff_t offset;
  116. unsigned length;
  117. unsigned dev;
  118. } per_dev[];
  119. };
  120. static inline unsigned ore_io_state_size(unsigned numdevs)
  121. {
  122. return sizeof(struct ore_io_state) +
  123. sizeof(struct ore_per_dev_state) * numdevs;
  124. }
  125. /* ore.c */
  126. int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
  127. int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
  128. bool is_reading, u64 offset, u64 length,
  129. struct ore_io_state **ios);
  130. int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
  131. struct ore_io_state **ios);
  132. void ore_put_io_state(struct ore_io_state *ios);
  133. int ore_check_io(struct ore_io_state *ios, u64 *resid);
  134. int ore_create(struct ore_io_state *ios);
  135. int ore_remove(struct ore_io_state *ios);
  136. int ore_write(struct ore_io_state *ios);
  137. int ore_read(struct ore_io_state *ios);
  138. int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
  139. u64 size);
  140. int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
  141. extern const struct osd_attr g_attr_logical_length;
  142. #endif