blob: 3442e8fe3fcd0a113c4e0ec367482754ec2d61fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _RAID1_H
2#define _RAID1_H
3
colyli@suse.defd768632017-02-18 03:05:56 +08004/*
5 * each barrier unit size is 64MB fow now
6 * note: it must be larger than RESYNC_DEPTH
7 */
8#define BARRIER_UNIT_SECTOR_BITS 17
9#define BARRIER_UNIT_SECTOR_SIZE (1<<17)
10/*
11 * In struct r1conf, the following members are related to I/O barrier
12 * buckets,
13 * int *nr_pending;
14 * int *nr_waiting;
15 * int *nr_queued;
16 * int *barrier;
17 * Each of them points to array of integers, each array is designed to
18 * have BARRIER_BUCKETS_NR elements and occupy a single memory page. The
19 * data width of integer variables is 4, equal to 1<<(ilog2(sizeof(int))),
20 * BARRIER_BUCKETS_NR_BITS is defined as (PAGE_SHIFT - ilog2(sizeof(int)))
21 * to make sure an array of integers with BARRIER_BUCKETS_NR elements just
22 * exactly occupies a single memory page.
23 */
24#define BARRIER_BUCKETS_NR_BITS (PAGE_SHIFT - ilog2(sizeof(int)))
25#define BARRIER_BUCKETS_NR (1<<BARRIER_BUCKETS_NR_BITS)
26
Jonathan Brassow0eaf8222012-07-31 10:03:52 +100027struct raid1_info {
NeilBrown3cb03002011-10-11 16:45:26 +110028 struct md_rdev *rdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 sector_t head_position;
Shaohua Libe4d3282012-07-31 10:03:53 +100030
31 /* When choose the best device for a read (read_balance())
32 * we try to keep sequential reads one the same device
33 */
34 sector_t next_seq_sect;
Shaohua Li12cee5a2012-07-31 10:03:53 +100035 sector_t seq_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
38/*
39 * memory pools need a pointer to the mddev, so they can force an unplug
40 * when memory is tight, and a count of the number of drives that the
41 * pool was allocated for, so they know how much to allocate and free.
42 * mddev->raid_disks cannot be used, as it can change while a pool is active
43 * These two datums are stored in a kmalloced struct.
NeilBrown8f19ccb2011-12-23 10:17:56 +110044 * The 'raid_disks' here is twice the raid_disks in r1conf.
45 * This allows space for each 'real' device can have a replacement in the
46 * second half of the array.
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 */
48
49struct pool_info {
NeilBrownfd01b882011-10-11 16:47:53 +110050 struct mddev *mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int raid_disks;
52};
53
NeilBrowne8096362011-10-11 16:49:05 +110054struct r1conf {
NeilBrownfd01b882011-10-11 16:47:53 +110055 struct mddev *mddev;
Jonathan Brassow0eaf8222012-07-31 10:03:52 +100056 struct raid1_info *mirrors; /* twice 'raid_disks' to
NeilBrown8f19ccb2011-12-23 10:17:56 +110057 * allow for replacements.
58 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int raid_disks;
NeilBrownce550c22011-10-07 14:22:33 +110060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 spinlock_t device_lock;
62
NeilBrown9f2c9d12011-10-11 16:48:43 +110063 /* list of 'struct r1bio' that need to be processed by raid1d,
64 * whether to retry a read, writeout a resync or recovery
65 * block, or anything else.
NeilBrownce550c22011-10-07 14:22:33 +110066 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct list_head retry_list;
NeilBrown55ce74d2015-08-14 11:11:10 +100068 /* A separate list of r1bio which just need raid_end_bio_io called.
69 * This mustn't happen for writes which had any errors if the superblock
70 * needs to be written.
71 */
72 struct list_head bio_end_io_list;
NeilBrownce550c22011-10-07 14:22:33 +110073
74 /* queue pending writes to be submitted on unplug */
NeilBrown191ea9b2005-06-21 17:17:23 -070075 struct bio_list pending_bio_list;
NeilBrown34db0cd2011-10-11 16:50:01 +110076 int pending_count;
NeilBrown191ea9b2005-06-21 17:17:23 -070077
NeilBrownce550c22011-10-07 14:22:33 +110078 /* for use when syncing mirrors:
79 * We don't allow both normal IO and resync/recovery IO at
80 * the same time - resync/recovery can only happen when there
81 * is no other IO. So when either is active, the other has to wait.
82 * See more details description in raid1.c near raise_barrier().
83 */
84 wait_queue_head_t wait_barrier;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 spinlock_t resync_lock;
colyli@suse.defd768632017-02-18 03:05:56 +080086 int *nr_pending;
87 int *nr_waiting;
88 int *nr_queued;
89 int *barrier;
majianpengb364e3d2013-11-14 15:16:18 +110090 int array_frozen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
NeilBrownce550c22011-10-07 14:22:33 +110092 /* Set to 1 if a full sync is needed, (fresh device added).
93 * Cleared when a sync completes.
94 */
95 int fullsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
NeilBrownce550c22011-10-07 14:22:33 +110097 /* When the same as mddev->recovery_disabled we don't allow
98 * recovery to be attempted as we expect a read error.
99 */
100 int recovery_disabled;
101
NeilBrownce550c22011-10-07 14:22:33 +1100102 /* poolinfo contains information about the content of the
103 * mempools - it changes when the array grows or shrinks
104 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 struct pool_info *poolinfo;
NeilBrown9f2c9d12011-10-11 16:48:43 +1100106 mempool_t *r1bio_pool;
107 mempool_t *r1buf_pool;
NeilBrown709ae482009-12-14 12:49:51 +1100108
NeilBrownce550c22011-10-07 14:22:33 +1100109 /* temporary buffer to synchronous IO when attempting to repair
110 * a read error.
111 */
112 struct page *tmppage;
113
NeilBrown709ae482009-12-14 12:49:51 +1100114 /* When taking over an array from a different personality, we store
115 * the new thread here until we fully activate the array.
116 */
NeilBrown2b8bf342011-10-11 16:48:23 +1100117 struct md_thread *thread;
Goldwyn Rodriguesc40f3412015-08-19 08:14:42 +1000118
119 /* Keep track of cluster resync window to send to other
120 * nodes.
121 */
122 sector_t cluster_sync_low;
123 sector_t cluster_sync_high;
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 * this is our 'private' RAID1 bio.
129 *
130 * it contains information about what kind of IO operations were started
131 * for this RAID1 operation, and about their status:
132 */
133
NeilBrown9f2c9d12011-10-11 16:48:43 +1100134struct r1bio {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 atomic_t remaining; /* 'have we finished' count,
136 * used from IRQ handlers
137 */
NeilBrown4b6d2872005-09-09 16:23:47 -0700138 atomic_t behind_remaining; /* number of write-behind ios remaining
139 * in this BehindIO request
140 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 sector_t sector;
142 int sectors;
143 unsigned long state;
NeilBrownfd01b882011-10-11 16:47:53 +1100144 struct mddev *mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /*
146 * original bio going to /dev/mdx
147 */
148 struct bio *master_bio;
149 /*
150 * if the IO is in READ direction, then this is where we read
151 */
152 int read_disk;
153
154 struct list_head retry_list;
NeilBrownaf6d7b72011-05-11 14:51:19 +1000155 /* Next two are only valid when R1BIO_BehindIO is set */
NeilBrown2ca68f52011-07-28 11:32:10 +1000156 struct bio_vec *behind_bvecs;
NeilBrownaf6d7b72011-05-11 14:51:19 +1000157 int behind_page_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 /*
159 * if the IO is in WRITE direction, then multiple bios are used.
160 * We choose the number when they are allocated.
161 */
162 struct bio *bios[0];
NeilBrown191ea9b2005-06-21 17:17:23 -0700163 /* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164};
165
166/* bits for r1bio.state */
NeilBrownbe306c22016-11-09 10:21:33 +1100167enum r1bio_state {
168 R1BIO_Uptodate,
169 R1BIO_IsSync,
170 R1BIO_Degraded,
171 R1BIO_BehindIO,
NeilBrownd2eb35a2011-07-28 11:31:48 +1000172/* Set ReadError on bios that experience a readerror so that
173 * raid1d knows what to do with them.
174 */
NeilBrownbe306c22016-11-09 10:21:33 +1100175 R1BIO_ReadError,
NeilBrown4b6d2872005-09-09 16:23:47 -0700176/* For write-behind requests, we call bi_end_io when
177 * the last non-write-behind device completes, providing
178 * any write was successful. Otherwise we call when
179 * any write-behind write succeeds, otherwise we call
180 * with failure when last write completes (and all failed).
181 * Record that bi_end_io was called with this flag...
182 */
NeilBrownbe306c22016-11-09 10:21:33 +1100183 R1BIO_Returned,
NeilBrown4367af52011-07-28 11:31:49 +1000184/* If a write for this request means we can clear some
185 * known-bad-block records, we set this flag
186 */
NeilBrownbe306c22016-11-09 10:21:33 +1100187 R1BIO_MadeGood,
188 R1BIO_WriteError,
NeilBrown2e52d442016-11-18 16:16:12 +1100189 R1BIO_FailFast,
NeilBrownbe306c22016-11-09 10:21:33 +1100190};
colyli@suse.defd768632017-02-18 03:05:56 +0800191
192static inline int sector_to_idx(sector_t sector)
193{
194 return hash_long(sector >> BARRIER_UNIT_SECTOR_BITS,
195 BARRIER_BUCKETS_NR_BITS);
196}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif