1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ef740c37SChristoph Hellwig #ifndef _RAID10_H 3ef740c37SChristoph Hellwig #define _RAID10_H 4ef740c37SChristoph Hellwig 5f2785b52SNeilBrown /* Note: raid10_info.rdev can be set to NULL asynchronously by 6f2785b52SNeilBrown * raid10_remove_disk. 7f2785b52SNeilBrown * There are three safe ways to access raid10_info.rdev. 8f2785b52SNeilBrown * 1/ when holding mddev->reconfig_mutex 9f2785b52SNeilBrown * 2/ when resync/recovery/reshape is known to be happening - i.e. in code 10f2785b52SNeilBrown * that is called as part of performing resync/recovery/reshape. 11f2785b52SNeilBrown * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer 12f2785b52SNeilBrown * and if it is non-NULL, increment rdev->nr_pending before dropping the 13f2785b52SNeilBrown * RCU lock. 14f2785b52SNeilBrown * When .rdev is set to NULL, the nr_pending count checked again and if it has 15f2785b52SNeilBrown * been incremented, the pointer is put back in .rdev. 16f2785b52SNeilBrown */ 17f2785b52SNeilBrown 18dc280d98SJonathan Brassow struct raid10_info { 1969335ef3SNeilBrown struct md_rdev *rdev, *replacement; 20ef740c37SChristoph Hellwig sector_t head_position; 212bb77736SNeilBrown int recovery_disabled; /* matches 222bb77736SNeilBrown * mddev->recovery_disabled 232bb77736SNeilBrown * when we shouldn't try 242bb77736SNeilBrown * recovering this device. 252bb77736SNeilBrown */ 26ef740c37SChristoph Hellwig }; 27ef740c37SChristoph Hellwig 28e879a879SNeilBrown struct r10conf { 29fd01b88cSNeilBrown struct mddev *mddev; 30dc280d98SJonathan Brassow struct raid10_info *mirrors; 31dc280d98SJonathan Brassow struct raid10_info *mirrors_new, *mirrors_old; 32ef740c37SChristoph Hellwig spinlock_t device_lock; 33ef740c37SChristoph Hellwig 34ef740c37SChristoph Hellwig /* geometry */ 355cf00fcdSNeilBrown struct geom { 365cf00fcdSNeilBrown int raid_disks; 3769335ef3SNeilBrown int near_copies; /* number of copies laid out 3869335ef3SNeilBrown * raid0 style */ 3925985edcSLucas De Marchi int far_copies; /* number of copies laid out 40ef740c37SChristoph Hellwig * at large strides across drives 41ef740c37SChristoph Hellwig */ 4269335ef3SNeilBrown int far_offset; /* far_copies are offset by 1 4369335ef3SNeilBrown * stripe instead of many 44ef740c37SChristoph Hellwig */ 45ef740c37SChristoph Hellwig sector_t stride; /* distance between far copies. 46ef740c37SChristoph Hellwig * This is size / far_copies unless 47ef740c37SChristoph Hellwig * far_offset, in which case it is 48ef740c37SChristoph Hellwig * 1 stripe. 49ef740c37SChristoph Hellwig */ 50475901afSJonathan Brassow int far_set_size; /* The number of devices in a set, 51475901afSJonathan Brassow * where a 'set' are devices that 52475901afSJonathan Brassow * contain far/offset copies of 53475901afSJonathan Brassow * each other. 54475901afSJonathan Brassow */ 555cf00fcdSNeilBrown int chunk_shift; /* shift from chunks to sectors */ 565cf00fcdSNeilBrown sector_t chunk_mask; 57f8c9e74fSNeilBrown } prev, geo; 585cf00fcdSNeilBrown int copies; /* near_copies * far_copies. 595cf00fcdSNeilBrown * must be <= raid_disks 605cf00fcdSNeilBrown */ 61ef740c37SChristoph Hellwig 6269335ef3SNeilBrown sector_t dev_sectors; /* temp copy of 6369335ef3SNeilBrown * mddev->dev_sectors */ 64f8c9e74fSNeilBrown sector_t reshape_progress; 653ea7daa5SNeilBrown sector_t reshape_safe; 663ea7daa5SNeilBrown unsigned long reshape_checkpoint; 673ea7daa5SNeilBrown sector_t offset_diff; 68dab8b292STrela, Maciej 69ef740c37SChristoph Hellwig struct list_head retry_list; 7095af587eSNeilBrown /* A separate list of r1bio which just need raid_end_bio_io called. 7195af587eSNeilBrown * This mustn't happen for writes which had any errors if the superblock 7295af587eSNeilBrown * needs to be written. 7395af587eSNeilBrown */ 7495af587eSNeilBrown struct list_head bio_end_io_list; 7595af587eSNeilBrown 76ef740c37SChristoph Hellwig /* queue pending writes and submit them on unplug */ 77ef740c37SChristoph Hellwig struct bio_list pending_bio_list; 78ef740c37SChristoph Hellwig 79b9b083f9SYu Kuai seqlock_t resync_lock; 800e5313e2STomasz Majchrzak atomic_t nr_pending; 81ef740c37SChristoph Hellwig int nr_waiting; 82ef740c37SChristoph Hellwig int nr_queued; 83ef740c37SChristoph Hellwig int barrier; 840e5313e2STomasz Majchrzak int array_freeze_pending; 85ef740c37SChristoph Hellwig sector_t next_resync; 86ef740c37SChristoph Hellwig int fullsync; /* set to 1 if a full sync is needed, 87ef740c37SChristoph Hellwig * (fresh device added). 88ef740c37SChristoph Hellwig * Cleared when a sync completes. 89ef740c37SChristoph Hellwig */ 9069335ef3SNeilBrown int have_replacement; /* There is at least one 9169335ef3SNeilBrown * replacement device. 9269335ef3SNeilBrown */ 93ef740c37SChristoph Hellwig wait_queue_head_t wait_barrier; 94ef740c37SChristoph Hellwig 95afeee514SKent Overstreet mempool_t r10bio_pool; 96afeee514SKent Overstreet mempool_t r10buf_pool; 97ef740c37SChristoph Hellwig struct page *tmppage; 98afeee514SKent Overstreet struct bio_set bio_split; 99dab8b292STrela, Maciej 100dab8b292STrela, Maciej /* When taking over an array from a different personality, we store 101dab8b292STrela, Maciej * the new thread here until we fully activate the array. 102dab8b292STrela, Maciej */ 103*44693154SYu Kuai struct md_thread __rcu *thread; 1048db87912SGuoqing Jiang 1058db87912SGuoqing Jiang /* 1068db87912SGuoqing Jiang * Keep track of cluster resync window to send to other nodes. 1078db87912SGuoqing Jiang */ 1088db87912SGuoqing Jiang sector_t cluster_sync_low; 1098db87912SGuoqing Jiang sector_t cluster_sync_high; 110ef740c37SChristoph Hellwig }; 111ef740c37SChristoph Hellwig 112ef740c37SChristoph Hellwig /* 113ef740c37SChristoph Hellwig * this is our 'private' RAID10 bio. 114ef740c37SChristoph Hellwig * 115ef740c37SChristoph Hellwig * it contains information about what kind of IO operations were started 116ef740c37SChristoph Hellwig * for this RAID10 operation, and about their status: 117ef740c37SChristoph Hellwig */ 118ef740c37SChristoph Hellwig 1199f2c9d12SNeilBrown struct r10bio { 120ef740c37SChristoph Hellwig atomic_t remaining; /* 'have we finished' count, 121ef740c37SChristoph Hellwig * used from IRQ handlers 122ef740c37SChristoph Hellwig */ 123ef740c37SChristoph Hellwig sector_t sector; /* virtual sector number */ 124ef740c37SChristoph Hellwig int sectors; 125ef740c37SChristoph Hellwig unsigned long state; 126fd01b88cSNeilBrown struct mddev *mddev; 127ef740c37SChristoph Hellwig /* 128ef740c37SChristoph Hellwig * original bio going to /dev/mdx 129ef740c37SChristoph Hellwig */ 130ef740c37SChristoph Hellwig struct bio *master_bio; 131ef740c37SChristoph Hellwig /* 132ef740c37SChristoph Hellwig * if the IO is in READ direction, then this is where we read 133ef740c37SChristoph Hellwig */ 134ef740c37SChristoph Hellwig int read_slot; 135ef740c37SChristoph Hellwig 136ef740c37SChristoph Hellwig struct list_head retry_list; 137ef740c37SChristoph Hellwig /* 138ef740c37SChristoph Hellwig * if the IO is in WRITE direction, then multiple bios are used, 139ef740c37SChristoph Hellwig * one for each copy. 140ef740c37SChristoph Hellwig * When resyncing we also use one for each copy. 141ef740c37SChristoph Hellwig * When reconstructing, we use 2 bios, one for read, one for write. 142ef740c37SChristoph Hellwig * We choose the number when they are allocated. 14369335ef3SNeilBrown * We sometimes need an extra bio to write to the replacement. 144ef740c37SChristoph Hellwig */ 145e0ee7785SNeilBrown struct r10dev { 146ef740c37SChristoph Hellwig struct bio *bio; 14769335ef3SNeilBrown union { 14869335ef3SNeilBrown struct bio *repl_bio; /* used for resync and 14969335ef3SNeilBrown * writes */ 15069335ef3SNeilBrown struct md_rdev *rdev; /* used for reads 15169335ef3SNeilBrown * (read_slot >= 0) */ 15269335ef3SNeilBrown }; 153ef740c37SChristoph Hellwig sector_t addr; 154ef740c37SChristoph Hellwig int devnum; 155358369f0SGustavo A. R. Silva } devs[]; 156ef740c37SChristoph Hellwig }; 157ef740c37SChristoph Hellwig 158ef740c37SChristoph Hellwig /* bits for r10bio.state */ 15969335ef3SNeilBrown enum r10bio_state { 16069335ef3SNeilBrown R10BIO_Uptodate, 16169335ef3SNeilBrown R10BIO_IsSync, 16269335ef3SNeilBrown R10BIO_IsRecover, 1633ea7daa5SNeilBrown R10BIO_IsReshape, 164856e08e2SNeilBrown /* Set ReadError on bios that experience a read error 165856e08e2SNeilBrown * so that raid10d knows what to do with them. 166856e08e2SNeilBrown */ 16769335ef3SNeilBrown R10BIO_ReadError, 168749c55e9SNeilBrown /* If a write for this request means we can clear some 169749c55e9SNeilBrown * known-bad-block records, we set this flag. 170749c55e9SNeilBrown */ 17169335ef3SNeilBrown R10BIO_MadeGood, 17269335ef3SNeilBrown R10BIO_WriteError, 173f8c9e74fSNeilBrown /* During a reshape we might be performing IO on the 174f8c9e74fSNeilBrown * 'previous' part of the array, in which case this 175f8c9e74fSNeilBrown * flag is set 176f8c9e74fSNeilBrown */ 177f8c9e74fSNeilBrown R10BIO_Previous, 1788d3ca83dSNeilBrown /* failfast devices did receive failfast requests. */ 1798d3ca83dSNeilBrown R10BIO_FailFast, 180254c271dSXiao Ni R10BIO_Discard, 18169335ef3SNeilBrown }; 182ef740c37SChristoph Hellwig #endif 183