raid10.h 4.4 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2 3 4
#ifndef _RAID10_H
#define _RAID10_H

5
struct raid10_info {
6
	struct md_rdev	*rdev, *replacement;
L
Linus Torvalds 已提交
7
	sector_t	head_position;
8 9 10 11 12
	int		recovery_disabled;	/* matches
						 * mddev->recovery_disabled
						 * when we shouldn't try
						 * recovering this device.
						 */
L
Linus Torvalds 已提交
13 14
};

15
struct r10conf {
16
	struct mddev		*mddev;
17 18
	struct raid10_info	*mirrors;
	struct raid10_info	*mirrors_new, *mirrors_old;
L
Linus Torvalds 已提交
19 20 21
	spinlock_t		device_lock;

	/* geometry */
22 23 24
	struct geom {
		int		raid_disks;
		int		near_copies;  /* number of copies laid out
25
					       * raid0 style */
26
		int		far_copies;   /* number of copies laid out
L
Linus Torvalds 已提交
27 28
					       * at large strides across drives
					       */
29
		int		far_offset;   /* far_copies are offset by 1
30
					       * stripe instead of many
31
					       */
32
		sector_t	stride;	      /* distance between far copies.
33 34 35
					       * This is size / far_copies unless
					       * far_offset, in which case it is
					       * 1 stripe.
L
Linus Torvalds 已提交
36
					       */
37 38 39 40 41
		int             far_set_size; /* The number of devices in a set,
					       * where a 'set' are devices that
					       * contain far/offset copies of
					       * each other.
					       */
42 43
		int		chunk_shift; /* shift from chunks to sectors */
		sector_t	chunk_mask;
44
	} prev, geo;
45 46 47
	int			copies;	      /* near_copies * far_copies.
					       * must be <= raid_disks
					       */
L
Linus Torvalds 已提交
48

49 50
	sector_t		dev_sectors;  /* temp copy of
					       * mddev->dev_sectors */
51
	sector_t		reshape_progress;
N
NeilBrown 已提交
52 53 54
	sector_t		reshape_safe;
	unsigned long		reshape_checkpoint;
	sector_t		offset_diff;
55

L
Linus Torvalds 已提交
56
	struct list_head	retry_list;
57 58 59 60 61 62
	/* A separate list of r1bio which just need raid_end_bio_io called.
	 * This mustn't happen for writes which had any errors if the superblock
	 * needs to be written.
	 */
	struct list_head	bio_end_io_list;

63 64
	/* queue pending writes and submit them on unplug */
	struct bio_list		pending_bio_list;
65
	int			pending_count;
L
Linus Torvalds 已提交
66 67

	spinlock_t		resync_lock;
68
	atomic_t		nr_pending;
69 70 71
	int			nr_waiting;
	int			nr_queued;
	int			barrier;
72
	int			array_freeze_pending;
L
Linus Torvalds 已提交
73
	sector_t		next_resync;
74 75 76 77
	int			fullsync;  /* set to 1 if a full sync is needed,
					    * (fresh device added).
					    * Cleared when a sync completes.
					    */
78 79 80
	int			have_replacement; /* There is at least one
						   * replacement device.
						   */
81
	wait_queue_head_t	wait_barrier;
L
Linus Torvalds 已提交
82

83 84
	mempool_t		*r10bio_pool;
	mempool_t		*r10buf_pool;
85
	struct page		*tmppage;
86
	struct bio_set		*bio_split;
87 88 89 90

	/* When taking over an array from a different personality, we store
	 * the new thread here until we fully activate the array.
	 */
91
	struct md_thread	*thread;
92 93 94 95 96 97

	/*
	 * Keep track of cluster resync window to send to other nodes.
	 */
	sector_t		cluster_sync_low;
	sector_t		cluster_sync_high;
L
Linus Torvalds 已提交
98 99 100 101 102 103 104 105 106
};

/*
 * this is our 'private' RAID10 bio.
 *
 * it contains information about what kind of IO operations were started
 * for this RAID10 operation, and about their status:
 */

107
struct r10bio {
L
Linus Torvalds 已提交
108 109 110 111 112 113
	atomic_t		remaining; /* 'have we finished' count,
					    * used from IRQ handlers
					    */
	sector_t		sector;	/* virtual sector number */
	int			sectors;
	unsigned long		state;
114
	struct mddev		*mddev;
L
Linus Torvalds 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	/*
	 * original bio going to /dev/mdx
	 */
	struct bio		*master_bio;
	/*
	 * if the IO is in READ direction, then this is where we read
	 */
	int			read_slot;

	struct list_head	retry_list;
	/*
	 * if the IO is in WRITE direction, then multiple bios are used,
	 * one for each copy.
	 * When resyncing we also use one for each copy.
	 * When reconstructing, we use 2 bios, one for read, one for write.
	 * We choose the number when they are allocated.
131
	 * We sometimes need an extra bio to write to the replacement.
L
Linus Torvalds 已提交
132
	 */
133
	struct r10dev {
134 135 136 137 138 139 140 141 142
		struct bio	*bio;
		union {
			struct bio	*repl_bio; /* used for resync and
						    * writes */
			struct md_rdev	*rdev;	   /* used for reads
						    * (read_slot >= 0) */
		};
		sector_t	addr;
		int		devnum;
L
Linus Torvalds 已提交
143 144 145 146
	} devs[0];
};

/* bits for r10bio.state */
147 148 149 150
enum r10bio_state {
	R10BIO_Uptodate,
	R10BIO_IsSync,
	R10BIO_IsRecover,
N
NeilBrown 已提交
151
	R10BIO_IsReshape,
152
	R10BIO_Degraded,
153 154 155
/* Set ReadError on bios that experience a read error
 * so that raid10d knows what to do with them.
 */
156
	R10BIO_ReadError,
157 158 159
/* If a write for this request means we can clear some
 * known-bad-block records, we set this flag.
 */
160 161
	R10BIO_MadeGood,
	R10BIO_WriteError,
162 163 164 165 166
/* During a reshape we might be performing IO on the
 * 'previous' part of the array, in which case this
 * flag is set
 */
	R10BIO_Previous,
167 168
/* failfast devices did receive failfast requests. */
	R10BIO_FailFast,
169
};
L
Linus Torvalds 已提交
170
#endif