blob: db2ac22ac1b42801a14e5eab8641109a3aa61505 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _RAID10_H
3#define _RAID10_H
4
Jonathan Brassowdc280d982012-07-31 10:03:52 +10005struct raid10_info {
NeilBrown69335ef2011-12-23 10:17:54 +11006 struct md_rdev *rdev, *replacement;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 sector_t head_position;
NeilBrown2bb77732011-07-27 11:00:36 +10008 int recovery_disabled; /* matches
9 * mddev->recovery_disabled
10 * when we shouldn't try
11 * recovering this device.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013};
14
NeilBrowne879a872011-10-11 16:49:02 +110015struct r10conf {
NeilBrownfd01b882011-10-11 16:47:53 +110016 struct mddev *mddev;
Jonathan Brassowdc280d982012-07-31 10:03:52 +100017 struct raid10_info *mirrors;
18 struct raid10_info *mirrors_new, *mirrors_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 spinlock_t device_lock;
20
21 /* geometry */
NeilBrown5cf00fc2012-05-21 09:28:20 +100022 struct geom {
23 int raid_disks;
24 int near_copies; /* number of copies laid out
NeilBrown69335ef2011-12-23 10:17:54 +110025 * raid0 style */
NeilBrown5cf00fc2012-05-21 09:28:20 +100026 int far_copies; /* number of copies laid out
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * at large strides across drives
28 */
NeilBrown5cf00fc2012-05-21 09:28:20 +100029 int far_offset; /* far_copies are offset by 1
NeilBrown69335ef2011-12-23 10:17:54 +110030 * stripe instead of many
NeilBrownc93983b2006-06-26 00:27:41 -070031 */
NeilBrown5cf00fc2012-05-21 09:28:20 +100032 sector_t stride; /* distance between far copies.
NeilBrownc93983b2006-06-26 00:27:41 -070033 * This is size / far_copies unless
34 * far_offset, in which case it is
35 * 1 stripe.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 */
Jonathan Brassow475901a2013-02-21 13:28:10 +110037 int far_set_size; /* The number of devices in a set,
38 * where a 'set' are devices that
39 * contain far/offset copies of
40 * each other.
41 */
NeilBrown5cf00fc2012-05-21 09:28:20 +100042 int chunk_shift; /* shift from chunks to sectors */
43 sector_t chunk_mask;
NeilBrownf8c9e742012-05-21 09:28:33 +100044 } prev, geo;
NeilBrown5cf00fc2012-05-21 09:28:20 +100045 int copies; /* near_copies * far_copies.
46 * must be <= raid_disks
47 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
NeilBrown69335ef2011-12-23 10:17:54 +110049 sector_t dev_sectors; /* temp copy of
50 * mddev->dev_sectors */
NeilBrownf8c9e742012-05-21 09:28:33 +100051 sector_t reshape_progress;
NeilBrown3ea7daa2012-05-22 13:53:47 +100052 sector_t reshape_safe;
53 unsigned long reshape_checkpoint;
54 sector_t offset_diff;
Trela, Maciejdab8b292010-03-08 16:02:45 +110055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 struct list_head retry_list;
NeilBrown95af5872015-08-14 11:26:17 +100057 /* A separate list of r1bio which just need raid_end_bio_io called.
58 * This mustn't happen for writes which had any errors if the superblock
59 * needs to be written.
60 */
61 struct list_head bio_end_io_list;
62
NeilBrown6cce3b22006-01-06 00:20:16 -080063 /* queue pending writes and submit them on unplug */
64 struct bio_list pending_bio_list;
NeilBrown34db0cd2011-10-11 16:50:01 +110065 int pending_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 spinlock_t resync_lock;
Tomasz Majchrzak0e5313e2016-06-24 14:20:16 +020068 atomic_t nr_pending;
NeilBrown69335ef2011-12-23 10:17:54 +110069 int nr_waiting;
70 int nr_queued;
71 int barrier;
Tomasz Majchrzak0e5313e2016-06-24 14:20:16 +020072 int array_freeze_pending;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 sector_t next_resync;
NeilBrown6cce3b22006-01-06 00:20:16 -080074 int fullsync; /* set to 1 if a full sync is needed,
75 * (fresh device added).
76 * Cleared when a sync completes.
77 */
NeilBrown69335ef2011-12-23 10:17:54 +110078 int have_replacement; /* There is at least one
79 * replacement device.
80 */
NeilBrown0a27ec92006-01-06 00:20:13 -080081 wait_queue_head_t wait_barrier;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
NeilBrown69335ef2011-12-23 10:17:54 +110083 mempool_t *r10bio_pool;
84 mempool_t *r10buf_pool;
NeilBrown4443ae12006-01-06 00:20:28 -080085 struct page *tmppage;
NeilBrownfc9977d2017-04-05 14:05:51 +100086 struct bio_set *bio_split;
Trela, Maciejdab8b292010-03-08 16:02:45 +110087
88 /* When taking over an array from a different personality, we store
89 * the new thread here until we fully activate the array.
90 */
NeilBrown2b8bf342011-10-11 16:48:23 +110091 struct md_thread *thread;
Guoqing Jiang8db87912017-10-24 15:11:52 +080092
93 /*
94 * Keep track of cluster resync window to send to other nodes.
95 */
96 sector_t cluster_sync_low;
97 sector_t cluster_sync_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 * this is our 'private' RAID10 bio.
102 *
103 * it contains information about what kind of IO operations were started
104 * for this RAID10 operation, and about their status:
105 */
106
NeilBrown9f2c9d12011-10-11 16:48:43 +1100107struct r10bio {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 atomic_t remaining; /* 'have we finished' count,
109 * used from IRQ handlers
110 */
111 sector_t sector; /* virtual sector number */
112 int sectors;
113 unsigned long state;
NeilBrownfd01b882011-10-11 16:47:53 +1100114 struct mddev *mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 /*
116 * original bio going to /dev/mdx
117 */
118 struct bio *master_bio;
119 /*
120 * if the IO is in READ direction, then this is where we read
121 */
122 int read_slot;
123
124 struct list_head retry_list;
125 /*
126 * if the IO is in WRITE direction, then multiple bios are used,
127 * one for each copy.
128 * When resyncing we also use one for each copy.
129 * When reconstructing, we use 2 bios, one for read, one for write.
130 * We choose the number when they are allocated.
NeilBrown69335ef2011-12-23 10:17:54 +1100131 * We sometimes need an extra bio to write to the replacement.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 */
NeilBrowne0ee7782012-08-18 09:51:42 +1000133 struct r10dev {
NeilBrown69335ef2011-12-23 10:17:54 +1100134 struct bio *bio;
135 union {
136 struct bio *repl_bio; /* used for resync and
137 * writes */
138 struct md_rdev *rdev; /* used for reads
139 * (read_slot >= 0) */
140 };
141 sector_t addr;
142 int devnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } devs[0];
144};
145
146/* bits for r10bio.state */
NeilBrown69335ef2011-12-23 10:17:54 +1100147enum r10bio_state {
148 R10BIO_Uptodate,
149 R10BIO_IsSync,
150 R10BIO_IsRecover,
NeilBrown3ea7daa2012-05-22 13:53:47 +1000151 R10BIO_IsReshape,
NeilBrown69335ef2011-12-23 10:17:54 +1100152 R10BIO_Degraded,
NeilBrown856e08e2011-07-28 11:39:23 +1000153/* Set ReadError on bios that experience a read error
154 * so that raid10d knows what to do with them.
155 */
NeilBrown69335ef2011-12-23 10:17:54 +1100156 R10BIO_ReadError,
NeilBrown749c55e2011-07-28 11:39:24 +1000157/* If a write for this request means we can clear some
158 * known-bad-block records, we set this flag.
159 */
NeilBrown69335ef2011-12-23 10:17:54 +1100160 R10BIO_MadeGood,
161 R10BIO_WriteError,
NeilBrownf8c9e742012-05-21 09:28:33 +1000162/* During a reshape we might be performing IO on the
163 * 'previous' part of the array, in which case this
164 * flag is set
165 */
166 R10BIO_Previous,
NeilBrown8d3ca832016-11-18 16:16:12 +1100167/* failfast devices did receive failfast requests. */
168 R10BIO_FailFast,
NeilBrown69335ef2011-12-23 10:17:54 +1100169};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#endif