osd_ore.h 4.0 KB

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