xref: /openbmc/linux/drivers/md/raid10.h (revision 9470114d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _RAID10_H
3 #define _RAID10_H
4 
5 /* Note: raid10_info.rdev can be set to NULL asynchronously by
6  * raid10_remove_disk.
7  * There are three safe ways to access raid10_info.rdev.
8  * 1/ when holding mddev->reconfig_mutex
9  * 2/ when resync/recovery/reshape is known to be happening - i.e. in code
10  *    that is called as part of performing resync/recovery/reshape.
11  * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
12  *    and if it is non-NULL, increment rdev->nr_pending before dropping the
13  *    RCU lock.
14  * When .rdev is set to NULL, the nr_pending count checked again and if it has
15  * been incremented, the pointer is put back in .rdev.
16  */
17 
18 struct raid10_info {
19 	struct md_rdev	*rdev, *replacement;
20 	sector_t	head_position;
21 	int		recovery_disabled;	/* matches
22 						 * mddev->recovery_disabled
23 						 * when we shouldn't try
24 						 * recovering this device.
25 						 */
26 };
27 
28 struct r10conf {
29 	struct mddev		*mddev;
30 	struct raid10_info	*mirrors;
31 	struct raid10_info	*mirrors_new, *mirrors_old;
32 	spinlock_t		device_lock;
33 
34 	/* geometry */
35 	struct geom {
36 		int		raid_disks;
37 		int		near_copies;  /* number of copies laid out
38 					       * raid0 style */
39 		int		far_copies;   /* number of copies laid out
40 					       * at large strides across drives
41 					       */
42 		int		far_offset;   /* far_copies are offset by 1
43 					       * stripe instead of many
44 					       */
45 		sector_t	stride;	      /* distance between far copies.
46 					       * This is size / far_copies unless
47 					       * far_offset, in which case it is
48 					       * 1 stripe.
49 					       */
50 		int             far_set_size; /* The number of devices in a set,
51 					       * where a 'set' are devices that
52 					       * contain far/offset copies of
53 					       * each other.
54 					       */
55 		int		chunk_shift; /* shift from chunks to sectors */
56 		sector_t	chunk_mask;
57 	} prev, geo;
58 	int			copies;	      /* near_copies * far_copies.
59 					       * must be <= raid_disks
60 					       */
61 
62 	sector_t		dev_sectors;  /* temp copy of
63 					       * mddev->dev_sectors */
64 	sector_t		reshape_progress;
65 	sector_t		reshape_safe;
66 	unsigned long		reshape_checkpoint;
67 	sector_t		offset_diff;
68 
69 	struct list_head	retry_list;
70 	/* A separate list of r1bio which just need raid_end_bio_io called.
71 	 * This mustn't happen for writes which had any errors if the superblock
72 	 * needs to be written.
73 	 */
74 	struct list_head	bio_end_io_list;
75 
76 	/* queue pending writes and submit them on unplug */
77 	struct bio_list		pending_bio_list;
78 
79 	seqlock_t		resync_lock;
80 	atomic_t		nr_pending;
81 	int			nr_waiting;
82 	int			nr_queued;
83 	int			barrier;
84 	int			array_freeze_pending;
85 	sector_t		next_resync;
86 	int			fullsync;  /* set to 1 if a full sync is needed,
87 					    * (fresh device added).
88 					    * Cleared when a sync completes.
89 					    */
90 	int			have_replacement; /* There is at least one
91 						   * replacement device.
92 						   */
93 	wait_queue_head_t	wait_barrier;
94 
95 	mempool_t		r10bio_pool;
96 	mempool_t		r10buf_pool;
97 	struct page		*tmppage;
98 	struct bio_set		bio_split;
99 
100 	/* When taking over an array from a different personality, we store
101 	 * the new thread here until we fully activate the array.
102 	 */
103 	struct md_thread __rcu	*thread;
104 
105 	/*
106 	 * Keep track of cluster resync window to send to other nodes.
107 	 */
108 	sector_t		cluster_sync_low;
109 	sector_t		cluster_sync_high;
110 };
111 
112 /*
113  * this is our 'private' RAID10 bio.
114  *
115  * it contains information about what kind of IO operations were started
116  * for this RAID10 operation, and about their status:
117  */
118 
119 struct r10bio {
120 	atomic_t		remaining; /* 'have we finished' count,
121 					    * used from IRQ handlers
122 					    */
123 	sector_t		sector;	/* virtual sector number */
124 	int			sectors;
125 	unsigned long		state;
126 	struct mddev		*mddev;
127 	/*
128 	 * original bio going to /dev/mdx
129 	 */
130 	struct bio		*master_bio;
131 	/*
132 	 * if the IO is in READ direction, then this is where we read
133 	 */
134 	int			read_slot;
135 
136 	struct list_head	retry_list;
137 	/*
138 	 * if the IO is in WRITE direction, then multiple bios are used,
139 	 * one for each copy.
140 	 * When resyncing we also use one for each copy.
141 	 * When reconstructing, we use 2 bios, one for read, one for write.
142 	 * We choose the number when they are allocated.
143 	 * We sometimes need an extra bio to write to the replacement.
144 	 */
145 	struct r10dev {
146 		struct bio	*bio;
147 		union {
148 			struct bio	*repl_bio; /* used for resync and
149 						    * writes */
150 			struct md_rdev	*rdev;	   /* used for reads
151 						    * (read_slot >= 0) */
152 		};
153 		sector_t	addr;
154 		int		devnum;
155 	} devs[];
156 };
157 
158 /* bits for r10bio.state */
159 enum r10bio_state {
160 	R10BIO_Uptodate,
161 	R10BIO_IsSync,
162 	R10BIO_IsRecover,
163 	R10BIO_IsReshape,
164 	R10BIO_Degraded,
165 /* Set ReadError on bios that experience a read error
166  * so that raid10d knows what to do with them.
167  */
168 	R10BIO_ReadError,
169 /* If a write for this request means we can clear some
170  * known-bad-block records, we set this flag.
171  */
172 	R10BIO_MadeGood,
173 	R10BIO_WriteError,
174 /* During a reshape we might be performing IO on the
175  * 'previous' part of the array, in which case this
176  * flag is set
177  */
178 	R10BIO_Previous,
179 /* failfast devices did receive failfast requests. */
180 	R10BIO_FailFast,
181 	R10BIO_Discard,
182 };
183 #endif
184