osd_ore.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. void *private;
  85. ore_io_done_fn done;
  86. struct ore_layout *layout;
  87. struct ore_components *oc;
  88. /* Global read/write IO*/
  89. loff_t offset;
  90. unsigned long length;
  91. void *kern_buff;
  92. struct page **pages;
  93. unsigned nr_pages;
  94. unsigned pgbase;
  95. unsigned pages_consumed;
  96. /* Attributes */
  97. unsigned in_attr_len;
  98. struct osd_attr *in_attr;
  99. unsigned out_attr_len;
  100. struct osd_attr *out_attr;
  101. bool reading;
  102. /* Variable array of size numdevs */
  103. unsigned numdevs;
  104. struct ore_per_dev_state {
  105. struct osd_request *or;
  106. struct bio *bio;
  107. loff_t offset;
  108. unsigned length;
  109. unsigned dev;
  110. } per_dev[];
  111. };
  112. static inline unsigned ore_io_state_size(unsigned numdevs)
  113. {
  114. return sizeof(struct ore_io_state) +
  115. sizeof(struct ore_per_dev_state) * numdevs;
  116. }
  117. /* ore.c */
  118. int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
  119. bool is_reading, u64 offset, u64 length,
  120. struct ore_io_state **ios);
  121. int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
  122. struct ore_io_state **ios);
  123. void ore_put_io_state(struct ore_io_state *ios);
  124. int ore_check_io(struct ore_io_state *ios, u64 *resid);
  125. int ore_create(struct ore_io_state *ios);
  126. int ore_remove(struct ore_io_state *ios);
  127. int ore_write(struct ore_io_state *ios);
  128. int ore_read(struct ore_io_state *ios);
  129. int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
  130. u64 size);
  131. int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
  132. extern const struct osd_attr g_attr_logical_length;
  133. #endif