blob: 492b70d43bb6c11a22d71069addcb1d2f725264c [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;
45};
46
Boaz Harroshd866d872011-09-28 14:43:09 +030047struct ore_dev {
48 struct osd_dev *od;
49};
50
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070051struct ore_components {
Boaz Harrosh3bd98562011-09-28 12:04:23 +030052 unsigned first_dev; /* First logical device no */
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070053 unsigned numdevs; /* Num of devices in array */
54 /* If @single_comp == EC_SINGLE_COMP, @comps points to a single
55 * component. else there are @numdevs components
56 */
57 enum EC_COMP_USAGE {
58 EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
59 } single_comp;
60 struct ore_comp *comps;
Boaz Harroshd866d872011-09-28 14:43:09 +030061
62 /* Array of pointers to ore_dev-* . User will usually have these pointed
63 * too a bigger struct which contain an "ore_dev ored" member and use
64 * container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
65 * structure.
66 */
67 struct ore_dev **ods;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070068};
69
Boaz Harroshd866d872011-09-28 14:43:09 +030070/* ore_comp_dev Recievies a logical device index */
71static inline struct osd_dev *ore_comp_dev(
72 const struct ore_components *oc, unsigned i)
73{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030074 BUG_ON((i < oc->first_dev) || (oc->first_dev + oc->numdevs <= i));
75 return oc->ods[i - oc->first_dev]->od;
Boaz Harroshd866d872011-09-28 14:43:09 +030076}
77
78static inline void ore_comp_set_dev(
79 struct ore_components *oc, unsigned i, struct osd_dev *od)
80{
Boaz Harrosh3bd98562011-09-28 12:04:23 +030081 oc->ods[i - oc->first_dev]->od = od;
Boaz Harroshd866d872011-09-28 14:43:09 +030082}
83
Boaz Harrosheb507bc2011-08-10 14:17:28 -070084struct ore_striping_info {
85 u64 obj_offset;
86 u64 group_length;
87 u64 M; /* for truncate */
88 unsigned dev;
89 unsigned unit_off;
90};
91
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070092struct ore_io_state;
93typedef void (*ore_io_done_fn)(struct ore_io_state *ios, void *private);
94
95struct ore_io_state {
96 struct kref kref;
Boaz Harrosh98260752011-10-02 15:32:50 +020097 struct ore_striping_info si;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -070098
99 void *private;
100 ore_io_done_fn done;
101
102 struct ore_layout *layout;
Boaz Harrosh5bf696d2011-09-28 11:39:59 +0300103 struct ore_components *oc;
Boaz Harrosh8ff660a2011-08-06 19:26:31 -0700104
105 /* Global read/write IO*/
106 loff_t offset;
107 unsigned long length;
108 void *kern_buff;
109
110 struct page **pages;
111 unsigned nr_pages;
112 unsigned pgbase;
113 unsigned pages_consumed;
114
115 /* Attributes */
116 unsigned in_attr_len;
117 struct osd_attr *in_attr;
118 unsigned out_attr_len;
119 struct osd_attr *out_attr;
120
121 bool reading;
122
123 /* Variable array of size numdevs */
124 unsigned numdevs;
125 struct ore_per_dev_state {
126 struct osd_request *or;
127 struct bio *bio;
128 loff_t offset;
129 unsigned length;
130 unsigned dev;
131 } per_dev[];
132};
133
134static inline unsigned ore_io_state_size(unsigned numdevs)
135{
136 return sizeof(struct ore_io_state) +
137 sizeof(struct ore_per_dev_state) * numdevs;
138}
139
140/* ore.c */
141int ore_get_rw_state(struct ore_layout *layout, struct ore_components *comps,
142 bool is_reading, u64 offset, u64 length,
143 struct ore_io_state **ios);
144int ore_get_io_state(struct ore_layout *layout, struct ore_components *comps,
145 struct ore_io_state **ios);
146void ore_put_io_state(struct ore_io_state *ios);
147
148int ore_check_io(struct ore_io_state *ios, u64 *resid);
149
150int ore_create(struct ore_io_state *ios);
151int ore_remove(struct ore_io_state *ios);
152int ore_write(struct ore_io_state *ios);
153int ore_read(struct ore_io_state *ios);
154int ore_truncate(struct ore_layout *layout, struct ore_components *comps,
155 u64 size);
156
157int extract_attr_from_ios(struct ore_io_state *ios, struct osd_attr *attr);
158
159extern const struct osd_attr g_attr_logical_length;
160
161#endif