blob: af2231a0fd098de95f0faa06b5692025780972f1 [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>
29
30struct ore_comp {
31 struct osd_obj_id obj;
32 u8 cred[OSD_CAP_LEN];
33};
34
35struct ore_layout {
36 /* Our way of looking at the data_map */
Boaz Harrosh8d2d83a2011-08-10 14:15:02 -070037 enum pnfs_osd_raid_algorithm4
38 raid_algorithm;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070039 unsigned stripe_unit;
40 unsigned mirrors_p1;
41
42 unsigned group_width;
43 u64 group_depth;
44 unsigned group_count;
Boaz Harrosh5a51c0c2011-09-28 13:18:45 +030045
46 /* Cached often needed calculations filled in by
47 * ore_verify_layout
48 */
49 unsigned long max_io_length; /* Max length that should be passed to
50 * ore_get_rw_state
51 */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070052};
53
Boaz Harroshd866d872011-09-28 14:43:09 +030054struct ore_dev {
55 struct osd_dev *od;
56};
57
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070058struct ore_components {
Boaz Harrosh3bd98562011-09-28 12:04:23 +030059 unsigned first_dev; /* First logical device no */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070060 unsigned numdevs; /* Num of devices in array */
61 /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
62 * component. else there are @numdevs components
63 */
64 enum EC_COMP_USAGE {
65 EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
66 } single_comp;
67 struct ore_comp *comps;
Boaz Harroshd866d872011-09-28 14:43:09 +030068
69 /* Array of pointers to ore_dev-* . User will usually have these pointed
70 * too a bigger struct which contain an "ore_dev ored" member and use
71 * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
72 * structure.
73 */
74 struct ore_dev **ods;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070075};
76
Boaz Harroshd866d872011-09-28 14:43:09 +030077/* ore_comp_dev Recievies a logical device index */
78static inline struct osd_dev *ore_comp_dev(
79 const struct ore_components *oc, unsigned i)
80{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030081 BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
82 return oc->ods[i - oc->first_dev]->od;
Boaz Harroshd866d872011-09-28 14:43:09 +030083}
84
85static inline void ore_comp_set_dev(
86 struct ore_components *oc, unsigned i, struct osd_dev *od)
87{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030088 oc->ods[i - oc->first_dev]->od = od;
Boaz Harroshd866d872011-09-28 14:43:09 +030089}
90
Boaz Harrosheb507bc2011-08-10 14:17:28 -070091struct ore_striping_info {
92 u64 obj_offset;
93 u64 group_length;
94 u64 M; /* for truncate */
95 unsigned dev;
96 unsigned unit_off;
97};
98
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070099struct ore_io_state;
100typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
101
102struct ore_io_state {
103 struct kref kref;
Boaz Harrosh98260752011-10-02 15:32:50 +0200104 struct ore_striping_info si;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700105
106 void *private;
107 ore_io_done_fn done;
108
109 struct ore_layout *layout;
Boaz Harrosh5bf696d2011-09-28 11:39:59 +0300110 struct ore_components *oc;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700111
112 /* Global read/write IO*/
113 loff_t offset;
114 unsigned long length;
115 void *kern_buff;
116
117 struct page **pages;
118 unsigned nr_pages;
119 unsigned pgbase;
120 unsigned pages_consumed;
121
122 /* Attributes */
123 unsigned in_attr_len;
124 struct osd_attr *in_attr;
125 unsigned out_attr_len;
126 struct osd_attr *out_attr;
127
128 bool reading;
129
130 /* Variable array of size numdevs */
131 unsigned numdevs;
132 struct ore_per_dev_state {
133 struct osd_request *or;
134 struct bio *bio;
135 loff_t offset;
136 unsigned length;
137 unsigned dev;
138 } per_dev[];
139};
140
141static inline unsigned ore_io_state_size(unsigned numdevs)
142{
143 return sizeof(struct ore_io_state) +
144 sizeof(struct ore_per_dev_state) * numdevs;
145}
146
147/* ore.c */
Boaz Harrosh5a51c0c2011-09-28 13:18:45 +0300148int ore_verify_layout(unsigned total_comps, struct ore_layout *layout);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700149int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
150 bool is_reading, u64 offset, u64 length,
151 struct ore_io_state **ios);
152int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
153 struct ore_io_state **ios);
154void ore_put_io_state(struct ore_io_state *ios);
155
Boaz Harrosh4b46c9f2011-09-28 13:25:50 +0300156typedef void (*ore_on_dev_error)(struct ore_io_state *ios, struct ore_dev *od,
157 unsigned dev_index, enum osd_err_priority oep,
158 u64 dev_offset, u64 dev_len);
159int ore_check_io(struct ore_io_state *ios, ore_on_dev_error rep);
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700160
161int ore_create(struct ore_io_state *ios);
162int ore_remove(struct ore_io_state *ios);
163int ore_write(struct ore_io_state *ios);
164int ore_read(struct ore_io_state *ios);
165int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
166 u64 size);
167
168int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
169
170extern const struct osd_attr g_attr_logical_length;
171
172#endif