~psusi/ubuntu/precise/dmraid/fix-gpt

« back to all changes in this revision

Viewing changes to 1.0.0.rc15/include/dmraid/metadata.h

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano, 6af052c
  • Date: 2009-03-25 22:34:59 UTC
  • mfrom: (2.1.9 sid)
  • mto: (2.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20090325223459-y54f0rmxem7htn6r
Tags: 1.0.0.rc15-6
[6af052c] Remove 15_isw_incorrect_status_fix.patch, it causes a
segfault. (Closes: #521104)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004-2008  Heinz Mauelshagen, Red Hat GmbH.
 
3
 *                          All rights reserved.
 
4
 *
 
5
 * Copyright (C) 2007   Intel Corporation. All rights reserved.
 
6
 * November, 2007 - additions for Create, Delete, Rebuild & Raid 10. 
 
7
 * 
 
8
 * See file LICENSE at the top of this source tree for license information.
 
9
 */
 
10
 
 
11
#ifndef _META_H_
 
12
#define _META_H_
 
13
 
 
14
#include <dmraid/list.h>
 
15
#include <stdint.h>
 
16
 
 
17
/*
 
18
 * Unified RAID set types.
 
19
 */
 
20
enum type {
 
21
        t_undef = 0x01,
 
22
        t_group = 0x02,         /* To group subsets (eg, Intel Software RAID). */
 
23
        t_partition = 0x04,     /* FIXME: remove in favour of kpartx ? */
 
24
        t_spare = 0x08,
 
25
        t_linear = 0x10,
 
26
        t_raid0 = 0x20,
 
27
        t_raid1 = 0x40,
 
28
        /*
 
29
         * Higher RAID types below not supported (yet)
 
30
         * because of device-mapper constraints.
 
31
         */
 
32
        t_raid4 = 0x80,
 
33
        t_raid5_ls = 0x100,
 
34
        t_raid5_rs = 0x200,
 
35
        t_raid5_la = 0x400,
 
36
        t_raid5_ra = 0x800,
 
37
        t_raid6 = 0x1000,
 
38
};
 
39
 
 
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)
 
54
 
 
55
 
 
56
/* Types for count_devs(). */
 
57
enum count_type {
 
58
        ct_all = 0,
 
59
        ct_dev,
 
60
        ct_spare,
 
61
};
 
62
 
 
63
/*
 
64
 * Mapping struct for RAID type unification.
 
65
 *
 
66
 * Format handler allocates an array and inserts mappings
 
67
 * from format specific types to the unified ones above.
 
68
 */
 
69
struct types {
 
70
        unsigned int type;      /* Must be long enough for vendor definition. */
 
71
        enum type unified_type;
 
72
};
 
73
 
 
74
/* RAID disk/set status. */
 
75
enum status {
 
76
        s_undef = 0x01,
 
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 */
 
87
};
 
88
 
 
89
/*
 
90
 * Mapping struct for RAID status unification.
 
91
 *
 
92
 * Format handler allocates an array and inserts mappings
 
93
 * from format specific status to the unified ones above.
 
94
 */
 
95
enum compare { AND, EQUAL };
 
96
struct states {
 
97
        unsigned int status;
 
98
        enum status unified_status;
 
99
};
 
100
 
 
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)
 
108
 
 
109
 
 
110
/* find_*() function enums */
 
111
enum find {
 
112
        FIND_TOP,               /* Search top level RAID sets only. */
 
113
        FIND_ALL,               /* Decend all RAID set trees. */
 
114
};
 
115
 
 
116
/* Device information. */
 
117
struct dev_info {
 
118
        struct list_head list;  /* Global chain of discovered devices. */
 
119
 
 
120
        char *path;             /* Actual device node path. */
 
121
        char *serial;           /* ATA/SCSI serial number. */
 
122
        uint64_t sectors;       /* Device size. */
 
123
};
 
124
 
 
125
/* Metadata areas and size stored on a RAID device. */
 
126
struct meta_areas {
 
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. */
 
130
};
 
131
 
 
132
/*
 
133
 * Abstracted RAID device.
 
134
 *
 
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).
 
137
 */
 
138
struct raid_dev {
 
139
        struct list_head list;  /* Global chain of RAID devices. */
 
140
        struct list_head devs;  /* Chain of devices belonging to set. */
 
141
 
 
142
        char *name;             /* Metadata format handler generated
 
143
                                   name of set this device belongs to. */
 
144
 
 
145
        struct dev_info *di;    /* Pointer to dev_info. */
 
146
        struct dmraid_format *fmt;      /* Format handler for this device. */
 
147
 
 
148
        enum status status;     /* Status of device. */
 
149
        enum type type;         /* Type of device. */
 
150
 
 
151
        uint64_t offset;        /* Data offset on device. */
 
152
        uint64_t sectors;       /* Length of the segment to map. */
 
153
 
 
154
        unsigned int areas;     /* # of metadata areas on the device. */
 
155
        struct meta_areas *meta_areas;  /* Dynamic array of metadata areas. */
 
156
 
 
157
        /*
 
158
         * For format handler use (eg, to keep references between calls).
 
159
         * 
 
160
         * WARNING: non pointer members need to get zeroed before exit,
 
161
         *          because the metadata layer frees private->ptr on cleanup.
 
162
         */
 
163
        union {
 
164
                void *ptr;
 
165
                uint32_t n32;
 
166
                uint64_t n64;
 
167
        } private;
 
168
};
 
169
 
 
170
/*
 
171
 * Abstracted (hierarchical) RAID set.
 
172
 *
 
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).
 
175
 */
 
176
enum flags {
 
177
        f_maximize = 0x01,      /* If set, maximize set capacity,
 
178
                                   if not set, limit to smallest device. */
 
179
        f_partitions = 0x02,    /* Set has partitions. */
 
180
};
 
181
 
 
182
#define F_MAXIMIZE(rs)          ((rs)->flags & f_maximize)
 
183
#define F_PARTITIONS(rs)        ((rs)->flags & f_partitions)
 
184
 
 
185
struct raid_set {
 
186
        struct list_head list;  /* Chain of independent sets. */
 
187
 
 
188
        /*
 
189
         * List of subsets (eg, RAID10) which make up RAID set stacks.
 
190
         *
 
191
         * Lowest level identified by list_empty() here.
 
192
         */
 
193
        struct list_head sets;
 
194
 
 
195
        /*
 
196
         * List of RAID devices making up a set.
 
197
         *
 
198
         * Higher RAID sets in a stack will have list_empty() here.
 
199
         *
 
200
         * Lowest level will hold device definitions
 
201
         * for arbitrary block devices here.
 
202
         */
 
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 */
 
206
 
 
207
        char *name;             /* Name of the set. */
 
208
 
 
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. */
 
214
};
 
215
 
 
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,
 
239
                                 enum find where);
 
240
extern struct raid_set *find_or_alloc_raid_set(struct lib_context *lc,
 
241
                                               char *name, enum find where,
 
242
                                               struct raid_dev *rd,
 
243
                                               struct list_head *list,
 
244
                                               void (*create) (struct raid_set
 
245
                                                               * super,
 
246
                                                               void *private),
 
247
                                               void *private);
 
248
#define NO_RD           NULL
 
249
#define NO_LIST         NULL
 
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);
 
254
 
 
255
enum set_type {
 
256
        SETS,
 
257
        PARTITIONS,
 
258
};
 
259
 
 
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,
 
270
                             enum compare cmp);
 
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);
 
281
#endif