Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (C) 2012 Fusion-io  All rights reserved.
  4 * Copyright (C) 2012 Intel Corp. All rights reserved.
  5 */
  6
  7#ifndef BTRFS_RAID56_H
  8#define BTRFS_RAID56_H
  9
 10#include <linux/workqueue.h>
 11#include "volumes.h"
 12
 13enum btrfs_rbio_ops {
 14	BTRFS_RBIO_WRITE,
 15	BTRFS_RBIO_READ_REBUILD,
 16	BTRFS_RBIO_PARITY_SCRUB,
 17	BTRFS_RBIO_REBUILD_MISSING,
 18};
 19
 20struct btrfs_raid_bio {
 21	struct btrfs_io_context *bioc;
 22
 23	/*
 24	 * While we're doing RMW on a stripe we put it into a hash table so we
 25	 * can lock the stripe and merge more rbios into it.
 26	 */
 27	struct list_head hash_list;
 28
 29	/* LRU list for the stripe cache */
 30	struct list_head stripe_cache;
 31
 32	/* For scheduling work in the helper threads */
 33	struct work_struct work;
 34
 35	/*
 36	 * bio_list and bio_list_lock are used to add more bios into the stripe
 37	 * in hopes of avoiding the full RMW
 38	 */
 39	struct bio_list bio_list;
 40	spinlock_t bio_list_lock;
 41
 42	/*
 43	 * Also protected by the bio_list_lock, the plug list is used by the
 44	 * plugging code to collect partial bios while plugged.  The stripe
 45	 * locking code also uses it to hand off the stripe lock to the next
 46	 * pending IO.
 47	 */
 48	struct list_head plug_list;
 49
 50	/* Flags that tell us if it is safe to merge with this bio. */
 51	unsigned long flags;
 52
 53	/*
 54	 * Set if we're doing a parity rebuild for a read from higher up, which
 55	 * is handled differently from a parity rebuild as part of RMW.
 56	 */
 57	enum btrfs_rbio_ops operation;
 58
 59	/* How many pages there are for the full stripe including P/Q */
 60	u16 nr_pages;
 61
 62	/* How many sectors there are for the full stripe including P/Q */
 63	u16 nr_sectors;
 64
 65	/* Number of data stripes (no p/q) */
 66	u8 nr_data;
 67
 68	/* Numer of all stripes (including P/Q) */
 69	u8 real_stripes;
 70
 71	/* How many pages there are for each stripe */
 72	u8 stripe_npages;
 73
 74	/* How many sectors there are for each stripe */
 75	u8 stripe_nsectors;
 76
 77	/* Stripe number that we're scrubbing  */
 78	u8 scrubp;
 79
 80	/*
 81	 * Size of all the bios in the bio_list.  This helps us decide if the
 82	 * rbio maps to a full stripe or not.
 83	 */
 84	int bio_list_bytes;
 85
 86	refcount_t refs;
 87
 88	atomic_t stripes_pending;
 89
 90	wait_queue_head_t io_wait;
 91
 92	/* Bitmap to record which horizontal stripe has data */
 93	unsigned long dbitmap;
 94
 95	/* Allocated with stripe_nsectors-many bits for finish_*() calls */
 96	unsigned long finish_pbitmap;
 97
 98	/*
 99	 * These are two arrays of pointers.  We allocate the rbio big enough
100	 * to hold them both and setup their locations when the rbio is
101	 * allocated.
102	 */
103
104	/*
105	 * Pointers to pages that we allocated for reading/writing stripes
106	 * directly from the disk (including P/Q).
107	 */
108	struct page **stripe_pages;
109
110	/* Pointers to the sectors in the bio_list, for faster lookup */
111	struct sector_ptr *bio_sectors;
112
113	/*
114	 * For subpage support, we need to map each sector to above
115	 * stripe_pages.
116	 */
117	struct sector_ptr *stripe_sectors;
118
119	/* Allocated with real_stripes-many pointers for finish_*() calls */
120	void **finish_pointers;
121
122	/*
123	 * The bitmap recording where IO errors happened.
124	 * Each bit is corresponding to one sector in either bio_sectors[] or
125	 * stripe_sectors[] array.
126	 *
127	 * The reason we don't use another bit in sector_ptr is, we have two
128	 * arrays of sectors, and a lot of IO can use sectors in both arrays.
129	 * Thus making it much harder to iterate.
130	 */
131	unsigned long *error_bitmap;
132
133	/*
134	 * Checksum buffer if the rbio is for data.  The buffer should cover
135	 * all data sectors (exlcuding P/Q sectors).
136	 */
137	u8 *csum_buf;
138
139	/*
140	 * Each bit represents if the corresponding sector has data csum found.
141	 * Should only cover data sectors (excluding P/Q sectors).
142	 */
143	unsigned long *csum_bitmap;
144};
145
146/*
147 * For trace event usage only. Records useful debug info for each bio submitted
148 * by RAID56 to each physical device.
149 *
150 * No matter signed or not, (-1) is always the one indicating we can not grab
151 * the proper stripe number.
 
 
 
 
 
 
 
 
 
 
 
152 */
153struct raid56_bio_trace_info {
154	u64 devid;
155
156	/* The offset inside the stripe. (<= STRIPE_LEN) */
157	u32 offset;
158
159	/*
160	 * Stripe number.
161	 * 0 is the first data stripe, and nr_data for P stripe,
162	 * nr_data + 1 for Q stripe.
163	 * >= real_stripes for
164	 */
165	u8 stripe_nr;
166};
167
168static inline int nr_data_stripes(const struct map_lookup *map)
169{
170	return map->num_stripes - btrfs_nr_parity_stripes(map->type);
 
 
 
 
 
171}
172
 
 
 
 
173#define RAID5_P_STRIPE ((u64)-2)
174#define RAID6_Q_STRIPE ((u64)-1)
175
176#define is_parity_stripe(x) (((x) == RAID5_P_STRIPE) ||		\
177			     ((x) == RAID6_Q_STRIPE))
178
 
179struct btrfs_device;
180
181void raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
182			   int mirror_num);
183void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc);
 
 
184
185void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page,
186			    unsigned int pgoff, u64 logical);
187
188struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
189				struct btrfs_io_context *bioc,
190				struct btrfs_device *scrub_dev,
191				unsigned long *dbitmap, int stripe_nsectors);
 
192void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
193
194struct btrfs_raid_bio *
195raid56_alloc_missing_rbio(struct bio *bio, struct btrfs_io_context *bioc);
 
196void raid56_submit_missing_rbio(struct btrfs_raid_bio *rbio);
197
198int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
199void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
200
201#endif
v4.6
 
 1/*
 2 * Copyright (C) 2012 Fusion-io  All rights reserved.
 3 * Copyright (C) 2012 Intel Corp. All rights reserved.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public
 7 * License v2 as published by the Free Software Foundation.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 021110-1307, USA.
18 */
 
 
 
 
 
19
20#ifndef __BTRFS_RAID56__
21#define __BTRFS_RAID56__
22static inline int nr_parity_stripes(struct map_lookup *map)
 
 
 
 
 
 
 
23{
24	if (map->type & BTRFS_BLOCK_GROUP_RAID5)
25		return 1;
26	else if (map->type & BTRFS_BLOCK_GROUP_RAID6)
27		return 2;
28	else
29		return 0;
30}
31
32static inline int nr_data_stripes(struct map_lookup *map)
33{
34	return map->num_stripes - nr_parity_stripes(map);
35}
36#define RAID5_P_STRIPE ((u64)-2)
37#define RAID6_Q_STRIPE ((u64)-1)
38
39#define is_parity_stripe(x) (((x) == RAID5_P_STRIPE) ||		\
40			     ((x) == RAID6_Q_STRIPE))
41
42struct btrfs_raid_bio;
43struct btrfs_device;
44
45int raid56_parity_recover(struct btrfs_root *root, struct bio *bio,
46			  struct btrfs_bio *bbio, u64 stripe_len,
47			  int mirror_num, int generic_io);
48int raid56_parity_write(struct btrfs_root *root, struct bio *bio,
49			       struct btrfs_bio *bbio, u64 stripe_len);
50
51void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page,
52			    u64 logical);
53
54struct btrfs_raid_bio *
55raid56_parity_alloc_scrub_rbio(struct btrfs_root *root, struct bio *bio,
56			       struct btrfs_bio *bbio, u64 stripe_len,
57			       struct btrfs_device *scrub_dev,
58			       unsigned long *dbitmap, int stripe_nsectors);
59void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
60
61struct btrfs_raid_bio *
62raid56_alloc_missing_rbio(struct btrfs_root *root, struct bio *bio,
63			  struct btrfs_bio *bbio, u64 length);
64void raid56_submit_missing_rbio(struct btrfs_raid_bio *rbio);
65
66int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
67void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
 
68#endif