blob: a5f9b960dfc8f0ca329c1fc510956f379e817fdd [file] [log] [blame]
Boaz Harrosh8ff660a2011-08-06 19:26:31 -07001/*
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>
Paul Gortmaker187f1882011-11-23 20:12:59 -050029#include <linux/bug.h>
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070030
31struct ore_comp {
32 struct osd_obj_id obj;
33 u8 cred[OSD_CAP_LEN];
34};
35
36struct ore_layout {
37 /* Our way of looking at the data_map */
Boaz Harrosh8d2d83a2011-08-10 14:15:02 -070038 enum pnfs_osd_raid_algorithm4
39 raid_algorithm;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070040 unsigned stripe_unit;
41 unsigned mirrors_p1;
42
43 unsigned group_width;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +020044 unsigned parity;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070045 u64 group_depth;
46 unsigned group_count;
Boaz Harrosh5a51c0c2011-09-28 13:18:45 +030047
48 /* Cached often needed calculations filled in by
49 * ore_verify_layout
50 */
51 unsigned long max_io_length; /* Max length that should be passed to
52 * ore_get_rw_state
53 */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070054};
55
Boaz Harroshd866d872011-09-28 14:43:09 +030056struct ore_dev {
57 struct osd_dev *od;
58};
59
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070060struct ore_components {
Boaz Harrosh3bd98562011-09-28 12:04:23 +030061 unsigned first_dev; /* First logical device no */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070062 unsigned numdevs; /* Num of devices in array */
63 /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
64 * component. else there are @numdevs components
65 */
66 enum EC_COMP_USAGE {
67 EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
68 } single_comp;
69 struct ore_comp *comps;
Boaz Harroshd866d872011-09-28 14:43:09 +030070
71 /* Array of pointers to ore_dev-* . User will usually have these pointed
72 * too a bigger struct which contain an "ore_dev ored" member and use
73 * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
74 * structure.
75 */
76 struct ore_dev **ods;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070077};
78
Boaz Harroshd866d872011-09-28 14:43:09 +030079/* ore_comp_dev Recievies a logical device index */
80static inline struct osd_dev *ore_comp_dev(
81 const struct ore_components *oc, unsigned i)
82{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030083 BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
84 return oc->ods[i - oc->first_dev]->od;
Boaz Harroshd866d872011-09-28 14:43:09 +030085}
86
87static inline void ore_comp_set_dev(
88 struct ore_components *oc, unsigned i, struct osd_dev *od)
89{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030090 oc->ods[i - oc->first_dev]->od = od;
Boaz Harroshd866d872011-09-28 14:43:09 +030091}
92
Boaz Harrosheb507bc2011-08-10 14:17:28 -070093struct ore_striping_info {
Boaz Harrosha1fec1d2011-10-12 18:42:22 +020094 u64 offset;
Boaz Harrosheb507bc2011-08-10 14:17:28 -070095 u64 obj_offset;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +020096 u64 length;
97 u64 first_stripe_start; /* only used in raid writes */
Boaz Harrosheb507bc2011-08-10 14:17:28 -070098 u64 M; /* for truncate */
Boaz Harrosha1fec1d2011-10-12 18:42:22 +020099 unsigned bytes_in_stripe;
Boaz Harrosheb507bc2011-08-10 14:17:28 -0700100 unsigned dev;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200101 unsigned par_dev;
Boaz Harrosheb507bc2011-08-10 14:17:28 -0700102 unsigned unit_off;
Boaz Harrosh769ba8d2011-10-14 15:33:51 +0200103 unsigned cur_pg;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200104 unsigned cur_comp;
Boaz Harrosheb507bc2011-08-10 14:17:28 -0700105};
106
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700107struct ore_io_state;
108typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
Boaz Harrosh769ba8d2011-10-14 15:33:51 +0200109struct _ore_r4w_op {
110 /* @Priv given here is passed ios->private */
111 struct page * (*get_page)(void *priv, u64 page_index, bool *uptodate);
112 void (*put_page)(void *priv, struct page *page);
113};
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700114
115struct ore_io_state {
116 struct kref kref;
Boaz Harrosh98260752011-10-02 15:32:50 +0200117 struct ore_striping_info si;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700118
119 void *private;
120 ore_io_done_fn done;
121
122 struct ore_layout *layout;
Boaz Harrosh5bf696d2011-09-28 11:39:59 +0300123 struct ore_components *oc;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700124
125 /* Global read/write IO*/
126 loff_t offset;
127 unsigned long length;
128 void *kern_buff;
129
130 struct page **pages;
131 unsigned nr_pages;
132 unsigned pgbase;
133 unsigned pages_consumed;
134
135 /* Attributes */
136 unsigned in_attr_len;
137 struct osd_attr *in_attr;
138 unsigned out_attr_len;
139 struct osd_attr *out_attr;
140
141 bool reading;
142
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200143 /* House keeping of Parity pages */
144 bool extra_part_alloc;
145 struct page **parity_pages;
146 unsigned max_par_pages;
147 unsigned cur_par_page;
148 unsigned sgs_per_dev;
Boaz Harrosh769ba8d2011-10-14 15:33:51 +0200149 struct __stripe_pages_2d *sp2d;
150 struct ore_io_state *ios_read_4_write;
151 const struct _ore_r4w_op *r4w;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200152
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700153 /* Variable array of size numdevs */
154 unsigned numdevs;
155 struct ore_per_dev_state {
156 struct osd_request *or;
157 struct bio *bio;
158 loff_t offset;
159 unsigned length;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200160 unsigned last_sgs_total;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700161 unsigned dev;
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200162 struct osd_sg_entry *sglist;
163 unsigned cur_sg;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700164 } per_dev[];
165};
166
167static inline unsigned ore_io_state_size(unsigned numdevs)
168{
169 return sizeof(struct ore_io_state) +
170 sizeof(struct ore_per_dev_state) * numdevs;
171}
172
173/* ore.c */
Boaz Harrosh5a51c0c2011-09-28 13:18:45 +0300174int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
Boaz Harrosh611d7a52011-10-04 14:20:17 +0200175void ore_calc_stripe_info(struct ore_layout *layout, u64 file_offset,
Boaz Harrosha1fec1d2011-10-12 18:42:22 +0200176 u64 length, struct ore_striping_info *si);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700177int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
178 bool is_reading, u64 offset, u64 length,
179 struct ore_io_state **ios);
180int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
181 struct ore_io_state **ios);
182void ore_put_io_state(struct ore_io_state *ios);
183
Boaz Harrosh4b46c9f2011-09-28 13:25:50 +0300184typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od,
185 unsigned dev_index, enum osd_err_priority oep,
186 u64 dev_offset, u64 dev_len);
187int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700188
189int ore_create(struct ore_io_state *ios);
190int ore_remove(struct ore_io_state *ios);
191int ore_write(struct ore_io_state *ios);
192int ore_read(struct ore_io_state *ios);
193int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
194 u64 size);
195
196int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
197
198extern const struct osd_attr g_attr_logical_length;
199
200#endif