Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 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 | |
| 25 | #include <scsi/osd_initiator.h> |
| 26 | #include <scsi/osd_attributes.h> |
| 27 | #include <scsi/osd_sec.h> |
| 28 | #include <linux/pnfs_osd_xdr.h> |
| 29 | |
| 30 | struct ore_comp { |
| 31 | struct osd_obj_id obj; |
| 32 | u8 cred[OSD_CAP_LEN]; |
| 33 | }; |
| 34 | |
| 35 | struct ore_layout { |
| 36 | /* Our way of looking at the data_map */ |
Boaz Harrosh | 8d2d83a | 2011-08-10 14:15:02 -0700 | [diff] [blame] | 37 | enum pnfs_osd_raid_algorithm4 |
| 38 | raid_algorithm; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 39 | unsigned stripe_unit; |
| 40 | unsigned mirrors_p1; |
| 41 | |
| 42 | unsigned group_width; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 43 | unsigned parity; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 44 | u64 group_depth; |
| 45 | unsigned group_count; |
Boaz Harrosh | 5a51c0c | 2011-09-28 13:18:45 +0300 | [diff] [blame] | 46 | |
| 47 | /* Cached often needed calculations filled in by |
| 48 | * ore_verify_layout |
| 49 | */ |
| 50 | unsigned long max_io_length; /* Max length that should be passed to |
| 51 | * ore_get_rw_state |
| 52 | */ |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 55 | struct ore_dev { |
| 56 | struct osd_dev *od; |
| 57 | }; |
| 58 | |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 59 | struct ore_components { |
Boaz Harrosh | 3bd9856 | 2011-09-28 12:04:23 +0300 | [diff] [blame] | 60 | unsigned first_dev; /* First logical device no */ |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 61 | unsigned numdevs; /* Num of devices in array */ |
| 62 | /* If @single_comp == EC_SINGLE_COMP, @comps points to a single |
| 63 | * component. else there are @numdevs components |
| 64 | */ |
| 65 | enum EC_COMP_USAGE { |
| 66 | EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff |
| 67 | } single_comp; |
| 68 | struct ore_comp *comps; |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 69 | |
| 70 | /* Array of pointers to ore_dev-* . User will usually have these pointed |
| 71 | * too a bigger struct which contain an "ore_dev ored" member and use |
| 72 | * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger |
| 73 | * structure. |
| 74 | */ |
| 75 | struct ore_dev **ods; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 78 | /* ore_comp_dev Recievies a logical device index */ |
| 79 | static inline struct osd_dev *ore_comp_dev( |
| 80 | const struct ore_components *oc, unsigned i) |
| 81 | { |
Boaz Harrosh | 3bd9856 | 2011-09-28 12:04:23 +0300 | [diff] [blame] | 82 | BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i)); |
| 83 | return oc->ods[i - oc->first_dev]->od; |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static inline void ore_comp_set_dev( |
| 87 | struct ore_components *oc, unsigned i, struct osd_dev *od) |
| 88 | { |
Boaz Harrosh | 3bd9856 | 2011-09-28 12:04:23 +0300 | [diff] [blame] | 89 | oc->ods[i - oc->first_dev]->od = od; |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 90 | } |
| 91 | |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 92 | struct ore_striping_info { |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 93 | u64 offset; |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 94 | u64 obj_offset; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 95 | u64 length; |
| 96 | u64 first_stripe_start; /* only used in raid writes */ |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 97 | u64 M; /* for truncate */ |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 98 | unsigned bytes_in_stripe; |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 99 | unsigned dev; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 100 | unsigned par_dev; |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 101 | unsigned unit_off; |
Boaz Harrosh | 769ba8d | 2011-10-14 15:33:51 +0200 | [diff] [blame] | 102 | unsigned cur_pg; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 103 | unsigned cur_comp; |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 106 | struct ore_io_state; |
| 107 | typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private); |
Boaz Harrosh | 769ba8d | 2011-10-14 15:33:51 +0200 | [diff] [blame] | 108 | struct _ore_r4w_op { |
| 109 | /* @Priv given here is passed ios->private */ |
| 110 | struct page * (*get_page)(void *priv, u64 page_index, bool *uptodate); |
| 111 | void (*put_page)(void *priv, struct page *page); |
| 112 | }; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 113 | |
| 114 | struct ore_io_state { |
| 115 | struct kref kref; |
Boaz Harrosh | 9826075 | 2011-10-02 15:32:50 +0200 | [diff] [blame] | 116 | struct ore_striping_info si; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 117 | |
| 118 | void *private; |
| 119 | ore_io_done_fn done; |
| 120 | |
| 121 | struct ore_layout *layout; |
Boaz Harrosh | 5bf696d | 2011-09-28 11:39:59 +0300 | [diff] [blame] | 122 | struct ore_components *oc; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 123 | |
| 124 | /* Global read/write IO*/ |
| 125 | loff_t offset; |
| 126 | unsigned long length; |
| 127 | void *kern_buff; |
| 128 | |
| 129 | struct page **pages; |
| 130 | unsigned nr_pages; |
| 131 | unsigned pgbase; |
| 132 | unsigned pages_consumed; |
| 133 | |
| 134 | /* Attributes */ |
| 135 | unsigned in_attr_len; |
| 136 | struct osd_attr *in_attr; |
| 137 | unsigned out_attr_len; |
| 138 | struct osd_attr *out_attr; |
| 139 | |
| 140 | bool reading; |
| 141 | |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 142 | /* House keeping of Parity pages */ |
| 143 | bool extra_part_alloc; |
| 144 | struct page **parity_pages; |
| 145 | unsigned max_par_pages; |
| 146 | unsigned cur_par_page; |
| 147 | unsigned sgs_per_dev; |
Boaz Harrosh | 769ba8d | 2011-10-14 15:33:51 +0200 | [diff] [blame] | 148 | struct __stripe_pages_2d *sp2d; |
| 149 | struct ore_io_state *ios_read_4_write; |
| 150 | const struct _ore_r4w_op *r4w; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 151 | |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 152 | /* Variable array of size numdevs */ |
| 153 | unsigned numdevs; |
| 154 | struct ore_per_dev_state { |
| 155 | struct osd_request *or; |
| 156 | struct bio *bio; |
| 157 | loff_t offset; |
| 158 | unsigned length; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 159 | unsigned last_sgs_total; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 160 | unsigned dev; |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 161 | struct osd_sg_entry *sglist; |
| 162 | unsigned cur_sg; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 163 | } per_dev[]; |
| 164 | }; |
| 165 | |
| 166 | static inline unsigned ore_io_state_size(unsigned numdevs) |
| 167 | { |
| 168 | return sizeof(struct ore_io_state) + |
| 169 | sizeof(struct ore_per_dev_state) * numdevs; |
| 170 | } |
| 171 | |
| 172 | /* ore.c */ |
Boaz Harrosh | 5a51c0c | 2011-09-28 13:18:45 +0300 | [diff] [blame] | 173 | int ore_verify_layout(unsigned total_comps, struct ore_layout *layout); |
Boaz Harrosh | 611d7a5 | 2011-10-04 14:20:17 +0200 | [diff] [blame] | 174 | void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset, |
Boaz Harrosh | a1fec1d | 2011-10-12 18:42:22 +0200 | [diff] [blame] | 175 | u64 length, struct ore_striping_info *si); |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 176 | int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps, |
| 177 | bool is_reading, u64 offset, u64 length, |
| 178 | struct ore_io_state **ios); |
| 179 | int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps, |
| 180 | struct ore_io_state **ios); |
| 181 | void ore_put_io_state(struct ore_io_state *ios); |
| 182 | |
Boaz Harrosh | 4b46c9f | 2011-09-28 13:25:50 +0300 | [diff] [blame] | 183 | typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od, |
| 184 | unsigned dev_index, enum osd_err_priority oep, |
| 185 | u64 dev_offset, u64 dev_len); |
| 186 | int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep); |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 187 | |
| 188 | int ore_create(struct ore_io_state *ios); |
| 189 | int ore_remove(struct ore_io_state *ios); |
| 190 | int ore_write(struct ore_io_state *ios); |
| 191 | int ore_read(struct ore_io_state *ios); |
| 192 | int ore_truncate(struct ore_layout *layout, struct ore_components *comps, |
| 193 | u64 size); |
| 194 | |
| 195 | int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr); |
| 196 | |
| 197 | extern const struct osd_attr g_attr_logical_length; |
| 198 | |
| 199 | #endif |