osd_ore.h 4.1 KB

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