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; |
| 43 | u64 group_depth; |
| 44 | unsigned group_count; |
| 45 | }; |
| 46 | |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 47 | struct ore_dev { |
| 48 | struct osd_dev *od; |
| 49 | }; |
| 50 | |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 51 | struct ore_components { |
| 52 | unsigned numdevs; /* Num of devices in array */ |
| 53 | /* If @single_comp == EC_SINGLE_COMP, @comps points to a single |
| 54 | * component. else there are @numdevs components |
| 55 | */ |
| 56 | enum EC_COMP_USAGE { |
| 57 | EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff |
| 58 | } single_comp; |
| 59 | struct ore_comp *comps; |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 60 | |
| 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; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Boaz Harrosh | d866d87 | 2011-09-28 14:43:09 +0300 | [diff] [blame] | 69 | /* ore_comp_dev Recievies a logical device index */ |
| 70 | static inline struct osd_dev *ore_comp_dev( |
| 71 | const struct ore_components *oc, unsigned i) |
| 72 | { |
| 73 | BUG_ON(oc->numdevs <= i); |
| 74 | return oc->ods[i]->od; |
| 75 | } |
| 76 | |
| 77 | static inline void ore_comp_set_dev( |
| 78 | struct ore_components *oc, unsigned i, struct osd_dev *od) |
| 79 | { |
| 80 | oc->ods[i]->od = od; |
| 81 | } |
| 82 | |
Boaz Harrosh | eb507bc | 2011-08-10 14:17:28 -0700 | [diff] [blame] | 83 | struct ore_striping_info { |
| 84 | u64 obj_offset; |
| 85 | u64 group_length; |
| 86 | u64 M; /* for truncate */ |
| 87 | unsigned dev; |
| 88 | unsigned unit_off; |
| 89 | }; |
| 90 | |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 91 | struct ore_io_state; |
| 92 | typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private); |
| 93 | |
| 94 | struct ore_io_state { |
| 95 | struct kref kref; |
Boaz Harrosh | 9826075 | 2011-10-02 15:32:50 +0200 | [diff] [blame^] | 96 | struct ore_striping_info si; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 97 | |
| 98 | void *private; |
| 99 | ore_io_done_fn done; |
| 100 | |
| 101 | struct ore_layout *layout; |
Boaz Harrosh | 5bf696d | 2011-09-28 11:39:59 +0300 | [diff] [blame] | 102 | struct ore_components *oc; |
Boaz Harrosh | 8ff660a | 2011-08-06 19:26:31 -0700 | [diff] [blame] | 103 | |
| 104 | /* Global read/write IO*/ |
| 105 | loff_t offset; |
| 106 | unsigned long length; |
| 107 | void *kern_buff; |
| 108 | |
| 109 | struct page **pages; |
| 110 | unsigned nr_pages; |
| 111 | unsigned pgbase; |
| 112 | unsigned pages_consumed; |
| 113 | |
| 114 | /* Attributes */ |
| 115 | unsigned in_attr_len; |
| 116 | struct osd_attr *in_attr; |
| 117 | unsigned out_attr_len; |
| 118 | struct osd_attr *out_attr; |
| 119 | |
| 120 | bool reading; |
| 121 | |
| 122 | /* Variable array of size numdevs */ |
| 123 | unsigned numdevs; |
| 124 | struct ore_per_dev_state { |
| 125 | struct osd_request *or; |
| 126 | struct bio *bio; |
| 127 | loff_t offset; |
| 128 | unsigned length; |
| 129 | unsigned dev; |
| 130 | } per_dev[]; |
| 131 | }; |
| 132 | |
| 133 | static inline unsigned ore_io_state_size(unsigned numdevs) |
| 134 | { |
| 135 | return sizeof(struct ore_io_state) + |
| 136 | sizeof(struct ore_per_dev_state) * numdevs; |
| 137 | } |
| 138 | |
| 139 | /* ore.c */ |
| 140 | int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps, |
| 141 | bool is_reading, u64 offset, u64 length, |
| 142 | struct ore_io_state **ios); |
| 143 | int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps, |
| 144 | struct ore_io_state **ios); |
| 145 | void ore_put_io_state(struct ore_io_state *ios); |
| 146 | |
| 147 | int ore_check_io(struct ore_io_state *ios, u64 *resid); |
| 148 | |
| 149 | int ore_create(struct ore_io_state *ios); |
| 150 | int ore_remove(struct ore_io_state *ios); |
| 151 | int ore_write(struct ore_io_state *ios); |
| 152 | int ore_read(struct ore_io_state *ios); |
| 153 | int ore_truncate(struct ore_layout *layout, struct ore_components *comps, |
| 154 | u64 size); |
| 155 | |
| 156 | int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr); |
| 157 | |
| 158 | extern const struct osd_attr g_attr_logical_length; |
| 159 | |
| 160 | #endif |