blob: be7f8d9cfc63f43e90827b38b2d5b1e2bbca224c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _RAID10_H
2#define _RAID10_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004typedef struct mirror_info mirror_info_t;
5
6struct mirror_info {
NeilBrown3cb03002011-10-11 16:45:26 +11007 struct md_rdev *rdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 sector_t head_position;
NeilBrown2bb77732011-07-27 11:00:36 +10009 int recovery_disabled; /* matches
10 * mddev->recovery_disabled
11 * when we shouldn't try
12 * recovering this device.
13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014};
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016struct r10_private_data_s {
NeilBrownfd01b882011-10-11 16:47:53 +110017 struct mddev *mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 mirror_info_t *mirrors;
19 int raid_disks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 spinlock_t device_lock;
21
22 /* geometry */
Lucas De Marchi25985ed2011-03-30 22:57:33 -030023 int near_copies; /* number of copies laid out raid0 style */
24 int far_copies; /* number of copies laid out
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * at large strides across drives
26 */
NeilBrownc93983b2006-06-26 00:27:41 -070027 int far_offset; /* far_copies are offset by 1 stripe
28 * instead of many
29 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 int copies; /* near_copies * far_copies.
31 * must be <= raid_disks
32 */
33 sector_t stride; /* distance between far copies.
NeilBrownc93983b2006-06-26 00:27:41 -070034 * This is size / far_copies unless
35 * far_offset, in which case it is
36 * 1 stripe.
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
Trela, Maciejdab8b292010-03-08 16:02:45 +110039 sector_t dev_sectors; /* temp copy of mddev->dev_sectors */
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 int chunk_shift; /* shift from chunks to sectors */
42 sector_t chunk_mask;
43
44 struct list_head retry_list;
NeilBrown6cce3b22006-01-06 00:20:16 -080045 /* queue pending writes and submit them on unplug */
46 struct bio_list pending_bio_list;
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 spinlock_t resync_lock;
50 int nr_pending;
NeilBrown0a27ec92006-01-06 00:20:13 -080051 int nr_waiting;
NeilBrown4443ae12006-01-06 00:20:28 -080052 int nr_queued;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 int barrier;
54 sector_t next_resync;
NeilBrown6cce3b22006-01-06 00:20:16 -080055 int fullsync; /* set to 1 if a full sync is needed,
56 * (fresh device added).
57 * Cleared when a sync completes.
58 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
NeilBrown0a27ec92006-01-06 00:20:13 -080060 wait_queue_head_t wait_barrier;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 mempool_t *r10bio_pool;
63 mempool_t *r10buf_pool;
NeilBrown4443ae12006-01-06 00:20:28 -080064 struct page *tmppage;
Trela, Maciejdab8b292010-03-08 16:02:45 +110065
66 /* When taking over an array from a different personality, we store
67 * the new thread here until we fully activate the array.
68 */
NeilBrown2b8bf342011-10-11 16:48:23 +110069 struct md_thread *thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
72typedef struct r10_private_data_s conf_t;
73
74/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * this is our 'private' RAID10 bio.
76 *
77 * it contains information about what kind of IO operations were started
78 * for this RAID10 operation, and about their status:
79 */
80
NeilBrown9f2c9d12011-10-11 16:48:43 +110081struct r10bio {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 atomic_t remaining; /* 'have we finished' count,
83 * used from IRQ handlers
84 */
85 sector_t sector; /* virtual sector number */
86 int sectors;
87 unsigned long state;
NeilBrownfd01b882011-10-11 16:47:53 +110088 struct mddev *mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 /*
90 * original bio going to /dev/mdx
91 */
92 struct bio *master_bio;
93 /*
94 * if the IO is in READ direction, then this is where we read
95 */
96 int read_slot;
97
98 struct list_head retry_list;
99 /*
100 * if the IO is in WRITE direction, then multiple bios are used,
101 * one for each copy.
102 * When resyncing we also use one for each copy.
103 * When reconstructing, we use 2 bios, one for read, one for write.
104 * We choose the number when they are allocated.
105 */
106 struct {
107 struct bio *bio;
108 sector_t addr;
109 int devnum;
110 } devs[0];
111};
112
NeilBrown0eb3ff12006-01-06 00:20:29 -0800113/* when we get a read error on a read-only array, we redirect to another
114 * device without failing the first device, or trying to over-write to
115 * correct the read error. To keep track of bad blocks on a per-bio
116 * level, we store IO_BLOCKED in the appropriate 'bios' pointer
117 */
118#define IO_BLOCKED ((struct bio*)1)
NeilBrown749c55e2011-07-28 11:39:24 +1000119/* When we successfully write to a known bad-block, we need to remove the
120 * bad-block marking which must be done from process context. So we record
121 * the success by setting devs[n].bio to IO_MADE_GOOD
122 */
123#define IO_MADE_GOOD ((struct bio *)2)
124
125#define BIO_SPECIAL(bio) ((unsigned long)bio <= 2)
NeilBrown0eb3ff12006-01-06 00:20:29 -0800126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/* bits for r10bio.state */
128#define R10BIO_Uptodate 0
129#define R10BIO_IsSync 1
130#define R10BIO_IsRecover 2
NeilBrown6cce3b22006-01-06 00:20:16 -0800131#define R10BIO_Degraded 3
NeilBrown856e08e2011-07-28 11:39:23 +1000132/* Set ReadError on bios that experience a read error
133 * so that raid10d knows what to do with them.
134 */
135#define R10BIO_ReadError 4
NeilBrown749c55e2011-07-28 11:39:24 +1000136/* If a write for this request means we can clear some
137 * known-bad-block records, we set this flag.
138 */
139#define R10BIO_MadeGood 5
NeilBrownbd870a12011-07-28 11:39:24 +1000140#define R10BIO_WriteError 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif