Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _RAID10_H
0003 #define _RAID10_H
0004 
0005 /* Note: raid10_info.rdev can be set to NULL asynchronously by
0006  * raid10_remove_disk.
0007  * There are three safe ways to access raid10_info.rdev.
0008  * 1/ when holding mddev->reconfig_mutex
0009  * 2/ when resync/recovery/reshape is known to be happening - i.e. in code
0010  *    that is called as part of performing resync/recovery/reshape.
0011  * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
0012  *    and if it is non-NULL, increment rdev->nr_pending before dropping the
0013  *    RCU lock.
0014  * When .rdev is set to NULL, the nr_pending count checked again and if it has
0015  * been incremented, the pointer is put back in .rdev.
0016  */
0017 
0018 struct raid10_info {
0019     struct md_rdev  *rdev, *replacement;
0020     sector_t    head_position;
0021     int     recovery_disabled;  /* matches
0022                          * mddev->recovery_disabled
0023                          * when we shouldn't try
0024                          * recovering this device.
0025                          */
0026 };
0027 
0028 struct r10conf {
0029     struct mddev        *mddev;
0030     struct raid10_info  *mirrors;
0031     struct raid10_info  *mirrors_new, *mirrors_old;
0032     spinlock_t      device_lock;
0033 
0034     /* geometry */
0035     struct geom {
0036         int     raid_disks;
0037         int     near_copies;  /* number of copies laid out
0038                            * raid0 style */
0039         int     far_copies;   /* number of copies laid out
0040                            * at large strides across drives
0041                            */
0042         int     far_offset;   /* far_copies are offset by 1
0043                            * stripe instead of many
0044                            */
0045         sector_t    stride;       /* distance between far copies.
0046                            * This is size / far_copies unless
0047                            * far_offset, in which case it is
0048                            * 1 stripe.
0049                            */
0050         int             far_set_size; /* The number of devices in a set,
0051                            * where a 'set' are devices that
0052                            * contain far/offset copies of
0053                            * each other.
0054                            */
0055         int     chunk_shift; /* shift from chunks to sectors */
0056         sector_t    chunk_mask;
0057     } prev, geo;
0058     int         copies;       /* near_copies * far_copies.
0059                            * must be <= raid_disks
0060                            */
0061 
0062     sector_t        dev_sectors;  /* temp copy of
0063                            * mddev->dev_sectors */
0064     sector_t        reshape_progress;
0065     sector_t        reshape_safe;
0066     unsigned long       reshape_checkpoint;
0067     sector_t        offset_diff;
0068 
0069     struct list_head    retry_list;
0070     /* A separate list of r1bio which just need raid_end_bio_io called.
0071      * This mustn't happen for writes which had any errors if the superblock
0072      * needs to be written.
0073      */
0074     struct list_head    bio_end_io_list;
0075 
0076     /* queue pending writes and submit them on unplug */
0077     struct bio_list     pending_bio_list;
0078 
0079     spinlock_t      resync_lock;
0080     atomic_t        nr_pending;
0081     int         nr_waiting;
0082     int         nr_queued;
0083     int         barrier;
0084     int         array_freeze_pending;
0085     sector_t        next_resync;
0086     int         fullsync;  /* set to 1 if a full sync is needed,
0087                         * (fresh device added).
0088                         * Cleared when a sync completes.
0089                         */
0090     int         have_replacement; /* There is at least one
0091                            * replacement device.
0092                            */
0093     wait_queue_head_t   wait_barrier;
0094 
0095     mempool_t       r10bio_pool;
0096     mempool_t       r10buf_pool;
0097     struct page     *tmppage;
0098     struct bio_set      bio_split;
0099 
0100     /* When taking over an array from a different personality, we store
0101      * the new thread here until we fully activate the array.
0102      */
0103     struct md_thread    *thread;
0104 
0105     /*
0106      * Keep track of cluster resync window to send to other nodes.
0107      */
0108     sector_t        cluster_sync_low;
0109     sector_t        cluster_sync_high;
0110 };
0111 
0112 /*
0113  * this is our 'private' RAID10 bio.
0114  *
0115  * it contains information about what kind of IO operations were started
0116  * for this RAID10 operation, and about their status:
0117  */
0118 
0119 struct r10bio {
0120     atomic_t        remaining; /* 'have we finished' count,
0121                         * used from IRQ handlers
0122                         */
0123     sector_t        sector; /* virtual sector number */
0124     int         sectors;
0125     unsigned long       state;
0126     unsigned long       start_time;
0127     struct mddev        *mddev;
0128     /*
0129      * original bio going to /dev/mdx
0130      */
0131     struct bio      *master_bio;
0132     /*
0133      * if the IO is in READ direction, then this is where we read
0134      */
0135     int         read_slot;
0136 
0137     struct list_head    retry_list;
0138     /*
0139      * if the IO is in WRITE direction, then multiple bios are used,
0140      * one for each copy.
0141      * When resyncing we also use one for each copy.
0142      * When reconstructing, we use 2 bios, one for read, one for write.
0143      * We choose the number when they are allocated.
0144      * We sometimes need an extra bio to write to the replacement.
0145      */
0146     struct r10dev {
0147         struct bio  *bio;
0148         union {
0149             struct bio  *repl_bio; /* used for resync and
0150                             * writes */
0151             struct md_rdev  *rdev;     /* used for reads
0152                             * (read_slot >= 0) */
0153         };
0154         sector_t    addr;
0155         int     devnum;
0156     } devs[];
0157 };
0158 
0159 /* bits for r10bio.state */
0160 enum r10bio_state {
0161     R10BIO_Uptodate,
0162     R10BIO_IsSync,
0163     R10BIO_IsRecover,
0164     R10BIO_IsReshape,
0165     R10BIO_Degraded,
0166 /* Set ReadError on bios that experience a read error
0167  * so that raid10d knows what to do with them.
0168  */
0169     R10BIO_ReadError,
0170 /* If a write for this request means we can clear some
0171  * known-bad-block records, we set this flag.
0172  */
0173     R10BIO_MadeGood,
0174     R10BIO_WriteError,
0175 /* During a reshape we might be performing IO on the
0176  * 'previous' part of the array, in which case this
0177  * flag is set
0178  */
0179     R10BIO_Previous,
0180 /* failfast devices did receive failfast requests. */
0181     R10BIO_FailFast,
0182     R10BIO_Discard,
0183 };
0184 #endif