2
* Copyright (C) 2004-2008 Heinz Mauelshagen, Red Hat GmbH.
5
* Copyright (C) 2007 Intel Corporation. All rights reserved.
6
* November, 2007 - additions for Create, Delete, Rebuild & Raid 10.
8
* See file LICENSE at the top of this source tree for license information.
14
#include <dmraid/list.h>
18
* Unified RAID set types.
22
t_group = 0x02, /* To group subsets (eg, Intel Software RAID). */
23
t_partition = 0x04, /* FIXME: remove in favour of kpartx ? */
29
* Higher RAID types below not supported (yet)
30
* because of device-mapper constraints.
40
/* Check macros for types. */
41
#define T_UNDEF(r) ((r)->type & t_undef)
42
#define T_GROUP(r) ((r)->type & t_group)
43
#define T_PARTITION(r) ((r)->type & t_partition)
44
#define T_SPARE(r) ((r)->type & t_spare)
45
#define T_LINEAR(r) ((r)->type & t_linear)
46
#define T_RAID0(r) ((r)->type & t_raid0)
47
#define T_RAID1(r) ((r)->type & t_raid1)
48
#define T_RAID4(r) ((r)->type & t_raid4)
49
#define T_RAID5(r) (((r)->type & t_raid5_ls) || \
50
((r)->type & t_raid5_rs) || \
51
((r)->type & t_raid5_la) || \
52
((r)->type & t_raid5_ra))
53
#define T_RAID6(r) ((r)->type & t_raid6)
56
/* Types for count_devs(). */
64
* Mapping struct for RAID type unification.
66
* Format handler allocates an array and inserts mappings
67
* from format specific types to the unified ones above.
70
unsigned int type; /* Must be long enough for vendor definition. */
71
enum type unified_type;
74
/* RAID disk/set status. */
77
s_broken = 0x02, /* Completely broken (not accessible). */
78
s_inconsistent = 0x04, /* RAID disk/set inconsistent (needs
79
synchronization or reconfiguration). */
80
/* FIXME: is s_nosync sufficient or do I need s_upgrade (eg, NVidia) */
81
s_nosync = 0x08, /* RAID disk/set *not* in sync
82
(needs synchronization). */
83
s_ok = 0x10, /* Fully operational. */
84
s_setup = 0x20, /* Only during RAID setup transition. */
85
s_init = 0x40, /* RAID set to be created */
86
s_config = 0x80, /* RAID set hasn't been configured */
90
* Mapping struct for RAID status unification.
92
* Format handler allocates an array and inserts mappings
93
* from format specific status to the unified ones above.
95
enum compare { AND, EQUAL };
98
enum status unified_status;
101
/* Check macros for states. */
102
#define S_UNDEF(status) ((status) & s_undef)
103
#define S_BROKEN(status) ((status) & s_broken)
104
#define S_INCONSISTENT(status) ((status) & s_inconsistent)
105
#define S_NOSYNC(status) ((status) & s_nosync)
106
#define S_OK(status) ((status) & s_ok)
107
#define S_SETUP(status) ((status) & s_setup)
110
/* find_*() function enums */
112
FIND_TOP, /* Search top level RAID sets only. */
113
FIND_ALL, /* Decend all RAID set trees. */
116
/* Device information. */
118
struct list_head list; /* Global chain of discovered devices. */
120
char *path; /* Actual device node path. */
121
char *serial; /* ATA/SCSI serial number. */
122
uint64_t sectors; /* Device size. */
125
/* Metadata areas and size stored on a RAID device. */
127
uint64_t offset; /* on disk metadata offset in sectors. */
128
size_t size; /* on disk metadata size in bytes. */
129
void *area; /* pointer to format specific metadata. */
133
* Abstracted RAID device.
135
* A RAID device is a member of a RAID set and can only
136
* exist at the lowest level of a RAID set stack (eg, for RAID10).
139
struct list_head list; /* Global chain of RAID devices. */
140
struct list_head devs; /* Chain of devices belonging to set. */
142
char *name; /* Metadata format handler generated
143
name of set this device belongs to. */
145
struct dev_info *di; /* Pointer to dev_info. */
146
struct dmraid_format *fmt; /* Format handler for this device. */
148
enum status status; /* Status of device. */
149
enum type type; /* Type of device. */
151
uint64_t offset; /* Data offset on device. */
152
uint64_t sectors; /* Length of the segment to map. */
154
unsigned int areas; /* # of metadata areas on the device. */
155
struct meta_areas *meta_areas; /* Dynamic array of metadata areas. */
158
* For format handler use (eg, to keep references between calls).
160
* WARNING: non pointer members need to get zeroed before exit,
161
* because the metadata layer frees private->ptr on cleanup.
171
* Abstracted (hierarchical) RAID set.
173
* Can be used to form a tree of subsets with arbitrary depths.
174
* Defines RAID attributes for the set as a whole (eg: RAID0, Status).
177
f_maximize = 0x01, /* If set, maximize set capacity,
178
if not set, limit to smallest device. */
179
f_partitions = 0x02, /* Set has partitions. */
182
#define F_MAXIMIZE(rs) ((rs)->flags & f_maximize)
183
#define F_PARTITIONS(rs) ((rs)->flags & f_partitions)
186
struct list_head list; /* Chain of independent sets. */
189
* List of subsets (eg, RAID10) which make up RAID set stacks.
191
* Lowest level identified by list_empty() here.
193
struct list_head sets;
196
* List of RAID devices making up a set.
198
* Higher RAID sets in a stack will have list_empty() here.
200
* Lowest level will hold device definitions
201
* for arbitrary block devices here.
203
struct list_head devs;
204
unsigned int total_devs; /* The number of devices expected */
205
unsigned int found_devs; /* The number of devices found */
207
char *name; /* Name of the set. */
209
uint64_t size; /* size of a raid set */
210
unsigned int stride; /* Stride size. */
211
enum type type; /* Unified raid type. */
212
enum flags flags; /* Set flags. */
213
enum status status; /* Status of set. */
216
extern struct raid_set *get_raid_set(struct lib_context *lc,
217
struct raid_dev *rd);
218
extern struct dmraid_format *get_format(struct raid_set *rs);
219
extern const char *get_type(struct lib_context *lc, enum type type);
220
extern const char *get_dm_type(struct lib_context *lc, enum type type);
221
extern const char *get_set_type(struct lib_context *lc, void *rs);
222
extern const char *get_status(struct lib_context *lc, enum status status);
223
extern uint64_t total_sectors(struct lib_context *lc, struct raid_set *rs);
224
extern struct dev_info *alloc_dev_info(struct lib_context *lc, char *path);
225
extern void free_dev_info(struct lib_context *lc, struct dev_info *di);
226
extern struct raid_dev *alloc_raid_dev(struct lib_context *lc, const char *who);
227
extern void free_raid_dev(struct lib_context *lc, struct raid_dev **rd);
228
extern void list_add_sorted(struct lib_context *lc,
229
struct list_head *to, struct list_head *new,
230
int (*sort) (struct list_head * pos,
231
struct list_head * new));
232
extern struct raid_set *alloc_raid_set(struct lib_context *lc, const char *who);
233
extern unsigned int count_sets(struct lib_context *lc, struct list_head *list);
234
extern unsigned int count_devs(struct lib_context *lc, struct raid_set *rs,
235
enum count_type type);
236
extern void free_raid_set(struct lib_context *lc, struct raid_set *rs);
237
extern struct raid_set *find_set(struct lib_context *lc,
238
struct list_head *list, const char *name,
240
extern struct raid_set *find_or_alloc_raid_set(struct lib_context *lc,
241
char *name, enum find where,
243
struct list_head *list,
244
void (*create) (struct raid_set
250
#define NO_CREATE NULL
251
#define NO_CREATE_ARG NULL
252
extern const char *get_set_name(struct lib_context *lc, void *rs);
253
extern int group_set(struct lib_context *lc, char **name);
260
extern void process_sets(struct lib_context *lc,
261
int (*func) (struct lib_context * lc, void *rs,
262
int arg), int arg, enum set_type type);
263
extern int write_set(struct lib_context *lc, void *rs);
264
extern int partitioned_set(struct lib_context *lc, void *rs);
265
extern int base_partitioned_set(struct lib_context *lc, void *rs);
266
extern void discover_raid_devices(struct lib_context *lc, char **devices);
267
extern void discover_partitions(struct lib_context *lc);
268
extern unsigned int count_devices(struct lib_context *lc, enum dev_type type);
269
extern enum status rd_status(struct states *states, unsigned int status,
271
extern enum type rd_type(struct types *types, unsigned int type);
272
extern void file_metadata(struct lib_context *lc, const char *handler,
273
char *path, void *data, size_t size, uint64_t offset);
274
extern void file_dev_size(struct lib_context *lc, const char *handler,
275
struct dev_info *di);
276
extern int write_dev(struct lib_context *lc, struct raid_dev *rd, int erase);
277
extern int erase_metadata(struct lib_context *lc);
278
extern int delete_raidsets(struct lib_context *lc);
279
extern int lib_perform(struct lib_context *lc, enum action action,
280
struct prepost *p, char **argv);