aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bio.h')
-rw-r--r--include/linux/bio.h135
1 files changed, 78 insertions, 57 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 0933a14e6414..6a642098e5c3 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -26,21 +26,8 @@
26 26
27#ifdef CONFIG_BLOCK 27#ifdef CONFIG_BLOCK
28 28
29/* Platforms may set this to teach the BIO layer about IOMMU hardware. */
30#include <asm/io.h> 29#include <asm/io.h>
31 30
32#if defined(BIO_VMERGE_MAX_SIZE) && defined(BIO_VMERGE_BOUNDARY)
33#define BIOVEC_VIRT_START_SIZE(x) (bvec_to_phys(x) & (BIO_VMERGE_BOUNDARY - 1))
34#define BIOVEC_VIRT_OVERSIZE(x) ((x) > BIO_VMERGE_MAX_SIZE)
35#else
36#define BIOVEC_VIRT_START_SIZE(x) 0
37#define BIOVEC_VIRT_OVERSIZE(x) 0
38#endif
39
40#ifndef BIO_VMERGE_BOUNDARY
41#define BIO_VMERGE_BOUNDARY 0
42#endif
43
44#define BIO_DEBUG 31#define BIO_DEBUG
45 32
46#ifdef BIO_DEBUG 33#ifdef BIO_DEBUG
@@ -88,25 +75,21 @@ struct bio {
88 /* Number of segments in this BIO after 75 /* Number of segments in this BIO after
89 * physical address coalescing is performed. 76 * physical address coalescing is performed.
90 */ 77 */
91 unsigned short bi_phys_segments; 78 unsigned int bi_phys_segments;
92
93 /* Number of segments after physical and DMA remapping
94 * hardware coalescing is performed.
95 */
96 unsigned short bi_hw_segments;
97 79
98 unsigned int bi_size; /* residual I/O count */ 80 unsigned int bi_size; /* residual I/O count */
99 81
100 /* 82 /*
101 * To keep track of the max hw size, we account for the 83 * To keep track of the max segment size, we account for the
102 * sizes of the first and last virtually mergeable segments 84 * sizes of the first and last mergeable segments in this bio.
103 * in this bio
104 */ 85 */
105 unsigned int bi_hw_front_size; 86 unsigned int bi_seg_front_size;
106 unsigned int bi_hw_back_size; 87 unsigned int bi_seg_back_size;
107 88
108 unsigned int bi_max_vecs; /* max bvl_vecs we can hold */ 89 unsigned int bi_max_vecs; /* max bvl_vecs we can hold */
109 90
91 unsigned int bi_comp_cpu; /* completion CPU */
92
110 struct bio_vec *bi_io_vec; /* the actual vec list */ 93 struct bio_vec *bi_io_vec; /* the actual vec list */
111 94
112 bio_end_io_t *bi_end_io; 95 bio_end_io_t *bi_end_io;
@@ -126,11 +109,14 @@ struct bio {
126#define BIO_UPTODATE 0 /* ok after I/O completion */ 109#define BIO_UPTODATE 0 /* ok after I/O completion */
127#define BIO_RW_BLOCK 1 /* RW_AHEAD set, and read/write would block */ 110#define BIO_RW_BLOCK 1 /* RW_AHEAD set, and read/write would block */
128#define BIO_EOF 2 /* out-out-bounds error */ 111#define BIO_EOF 2 /* out-out-bounds error */
129#define BIO_SEG_VALID 3 /* nr_hw_seg valid */ 112#define BIO_SEG_VALID 3 /* bi_phys_segments valid */
130#define BIO_CLONED 4 /* doesn't own data */ 113#define BIO_CLONED 4 /* doesn't own data */
131#define BIO_BOUNCED 5 /* bio is a bounce bio */ 114#define BIO_BOUNCED 5 /* bio is a bounce bio */
132#define BIO_USER_MAPPED 6 /* contains user pages */ 115#define BIO_USER_MAPPED 6 /* contains user pages */
133#define BIO_EOPNOTSUPP 7 /* not supported */ 116#define BIO_EOPNOTSUPP 7 /* not supported */
117#define BIO_CPU_AFFINE 8 /* complete bio on same CPU as submitted */
118#define BIO_NULL_MAPPED 9 /* contains invalid user pages */
119#define BIO_FS_INTEGRITY 10 /* fs owns integrity data, not block layer */
134#define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag))) 120#define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))
135 121
136/* 122/*
@@ -144,18 +130,36 @@ struct bio {
144/* 130/*
145 * bio bi_rw flags 131 * bio bi_rw flags
146 * 132 *
147 * bit 0 -- read (not set) or write (set) 133 * bit 0 -- data direction
134 * If not set, bio is a read from device. If set, it's a write to device.
148 * bit 1 -- rw-ahead when set 135 * bit 1 -- rw-ahead when set
149 * bit 2 -- barrier 136 * bit 2 -- barrier
150 * bit 3 -- fail fast, don't want low level driver retries 137 * Insert a serialization point in the IO queue, forcing previously
151 * bit 4 -- synchronous I/O hint: the block layer will unplug immediately 138 * submitted IO to be completed before this oen is issued.
139 * bit 3 -- synchronous I/O hint: the block layer will unplug immediately
140 * Note that this does NOT indicate that the IO itself is sync, just
141 * that the block layer will not postpone issue of this IO by plugging.
142 * bit 4 -- metadata request
143 * Used for tracing to differentiate metadata and data IO. May also
144 * get some preferential treatment in the IO scheduler
145 * bit 5 -- discard sectors
146 * Informs the lower level device that this range of sectors is no longer
147 * used by the file system and may thus be freed by the device. Used
148 * for flash based storage.
149 * bit 6 -- fail fast device errors
150 * bit 7 -- fail fast transport errors
151 * bit 8 -- fail fast driver errors
152 * Don't want driver retries for any fast fail whatever the reason.
152 */ 153 */
153#define BIO_RW 0 154#define BIO_RW 0 /* Must match RW in req flags (blkdev.h) */
154#define BIO_RW_AHEAD 1 155#define BIO_RW_AHEAD 1 /* Must match FAILFAST in req flags */
155#define BIO_RW_BARRIER 2 156#define BIO_RW_BARRIER 2
156#define BIO_RW_FAILFAST 3 157#define BIO_RW_SYNC 3
157#define BIO_RW_SYNC 4 158#define BIO_RW_META 4
158#define BIO_RW_META 5 159#define BIO_RW_DISCARD 5
160#define BIO_RW_FAILFAST_DEV 6
161#define BIO_RW_FAILFAST_TRANSPORT 7
162#define BIO_RW_FAILFAST_DRIVER 8
159 163
160/* 164/*
161 * upper 16 bits of bi_rw define the io priority of this bio 165 * upper 16 bits of bi_rw define the io priority of this bio
@@ -182,17 +186,21 @@ struct bio {
182#define bio_sectors(bio) ((bio)->bi_size >> 9) 186#define bio_sectors(bio) ((bio)->bi_size >> 9)
183#define bio_barrier(bio) ((bio)->bi_rw & (1 << BIO_RW_BARRIER)) 187#define bio_barrier(bio) ((bio)->bi_rw & (1 << BIO_RW_BARRIER))
184#define bio_sync(bio) ((bio)->bi_rw & (1 << BIO_RW_SYNC)) 188#define bio_sync(bio) ((bio)->bi_rw & (1 << BIO_RW_SYNC))
185#define bio_failfast(bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST)) 189#define bio_failfast_dev(bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST_DEV))
190#define bio_failfast_transport(bio) \
191 ((bio)->bi_rw & (1 << BIO_RW_FAILFAST_TRANSPORT))
192#define bio_failfast_driver(bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST_DRIVER))
186#define bio_rw_ahead(bio) ((bio)->bi_rw & (1 << BIO_RW_AHEAD)) 193#define bio_rw_ahead(bio) ((bio)->bi_rw & (1 << BIO_RW_AHEAD))
187#define bio_rw_meta(bio) ((bio)->bi_rw & (1 << BIO_RW_META)) 194#define bio_rw_meta(bio) ((bio)->bi_rw & (1 << BIO_RW_META))
188#define bio_empty_barrier(bio) (bio_barrier(bio) && !(bio)->bi_size) 195#define bio_discard(bio) ((bio)->bi_rw & (1 << BIO_RW_DISCARD))
196#define bio_empty_barrier(bio) (bio_barrier(bio) && !bio_has_data(bio) && !bio_discard(bio))
189 197
190static inline unsigned int bio_cur_sectors(struct bio *bio) 198static inline unsigned int bio_cur_sectors(struct bio *bio)
191{ 199{
192 if (bio->bi_vcnt) 200 if (bio->bi_vcnt)
193 return bio_iovec(bio)->bv_len >> 9; 201 return bio_iovec(bio)->bv_len >> 9;
194 202 else /* dataless requests such as discard */
195 return 0; 203 return bio->bi_size >> 9;
196} 204}
197 205
198static inline void *bio_data(struct bio *bio) 206static inline void *bio_data(struct bio *bio)
@@ -228,16 +236,18 @@ static inline void *bio_data(struct bio *bio)
228#define __BVEC_END(bio) bio_iovec_idx((bio), (bio)->bi_vcnt - 1) 236#define __BVEC_END(bio) bio_iovec_idx((bio), (bio)->bi_vcnt - 1)
229#define __BVEC_START(bio) bio_iovec_idx((bio), (bio)->bi_idx) 237#define __BVEC_START(bio) bio_iovec_idx((bio), (bio)->bi_idx)
230 238
239/* Default implementation of BIOVEC_PHYS_MERGEABLE */
240#define __BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
241 ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
242
231/* 243/*
232 * allow arch override, for eg virtualized architectures (put in asm/io.h) 244 * allow arch override, for eg virtualized architectures (put in asm/io.h)
233 */ 245 */
234#ifndef BIOVEC_PHYS_MERGEABLE 246#ifndef BIOVEC_PHYS_MERGEABLE
235#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \ 247#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
236 ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2))) 248 __BIOVEC_PHYS_MERGEABLE(vec1, vec2)
237#endif 249#endif
238 250
239#define BIOVEC_VIRT_MERGEABLE(vec1, vec2) \
240 ((((bvec_to_phys((vec1)) + (vec1)->bv_len) | bvec_to_phys((vec2))) & (BIO_VMERGE_BOUNDARY - 1)) == 0)
241#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \ 251#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
242 (((addr1) | (mask)) == (((addr2) - 1) | (mask))) 252 (((addr1) | (mask)) == (((addr2) - 1) | (mask)))
243#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \ 253#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
@@ -319,15 +329,14 @@ struct bio_pair {
319 atomic_t cnt; 329 atomic_t cnt;
320 int error; 330 int error;
321}; 331};
322extern struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, 332extern struct bio_pair *bio_split(struct bio *bi, int first_sectors);
323 int first_sectors);
324extern mempool_t *bio_split_pool;
325extern void bio_pair_release(struct bio_pair *dbio); 333extern void bio_pair_release(struct bio_pair *dbio);
326 334
327extern struct bio_set *bioset_create(int, int); 335extern struct bio_set *bioset_create(int, int);
328extern void bioset_free(struct bio_set *); 336extern void bioset_free(struct bio_set *);
329 337
330extern struct bio *bio_alloc(gfp_t, int); 338extern struct bio *bio_alloc(gfp_t, int);
339extern struct bio *bio_kmalloc(gfp_t, int);
331extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *); 340extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *);
332extern void bio_put(struct bio *); 341extern void bio_put(struct bio *);
333extern void bio_free(struct bio *, struct bio_set *); 342extern void bio_free(struct bio *, struct bio_set *);
@@ -335,7 +344,6 @@ extern void bio_free(struct bio *, struct bio_set *);
335extern void bio_endio(struct bio *, int); 344extern void bio_endio(struct bio *, int);
336struct request_queue; 345struct request_queue;
337extern int bio_phys_segments(struct request_queue *, struct bio *); 346extern int bio_phys_segments(struct request_queue *, struct bio *);
338extern int bio_hw_segments(struct request_queue *, struct bio *);
339 347
340extern void __bio_clone(struct bio *, struct bio *); 348extern void __bio_clone(struct bio *, struct bio *);
341extern struct bio *bio_clone(struct bio *, gfp_t); 349extern struct bio *bio_clone(struct bio *, gfp_t);
@@ -346,12 +354,14 @@ extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
346extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, 354extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
347 unsigned int, unsigned int); 355 unsigned int, unsigned int);
348extern int bio_get_nr_vecs(struct block_device *); 356extern int bio_get_nr_vecs(struct block_device *);
357extern sector_t bio_sector_offset(struct bio *, unsigned short, unsigned int);
349extern struct bio *bio_map_user(struct request_queue *, struct block_device *, 358extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
350 unsigned long, unsigned int, int); 359 unsigned long, unsigned int, int, gfp_t);
351struct sg_iovec; 360struct sg_iovec;
361struct rq_map_data;
352extern struct bio *bio_map_user_iov(struct request_queue *, 362extern struct bio *bio_map_user_iov(struct request_queue *,
353 struct block_device *, 363 struct block_device *,
354 struct sg_iovec *, int, int); 364 struct sg_iovec *, int, int, gfp_t);
355extern void bio_unmap_user(struct bio *); 365extern void bio_unmap_user(struct bio *);
356extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int, 366extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int,
357 gfp_t); 367 gfp_t);
@@ -359,15 +369,25 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
359 gfp_t, int); 369 gfp_t, int);
360extern void bio_set_pages_dirty(struct bio *bio); 370extern void bio_set_pages_dirty(struct bio *bio);
361extern void bio_check_pages_dirty(struct bio *bio); 371extern void bio_check_pages_dirty(struct bio *bio);
362extern struct bio *bio_copy_user(struct request_queue *, unsigned long, unsigned int, int); 372extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
363extern struct bio *bio_copy_user_iov(struct request_queue *, struct sg_iovec *, 373 unsigned long, unsigned int, int, gfp_t);
364 int, int); 374extern struct bio *bio_copy_user_iov(struct request_queue *,
375 struct rq_map_data *, struct sg_iovec *,
376 int, int, gfp_t);
365extern int bio_uncopy_user(struct bio *); 377extern int bio_uncopy_user(struct bio *);
366void zero_fill_bio(struct bio *bio); 378void zero_fill_bio(struct bio *bio);
367extern struct bio_vec *bvec_alloc_bs(gfp_t, int, unsigned long *, struct bio_set *); 379extern struct bio_vec *bvec_alloc_bs(gfp_t, int, unsigned long *, struct bio_set *);
368extern unsigned int bvec_nr_vecs(unsigned short idx); 380extern unsigned int bvec_nr_vecs(unsigned short idx);
369 381
370/* 382/*
383 * Allow queuer to specify a completion CPU for this bio
384 */
385static inline void bio_set_completion_cpu(struct bio *bio, unsigned int cpu)
386{
387 bio->bi_comp_cpu = cpu;
388}
389
390/*
371 * bio_set is used to allow other portions of the IO system to 391 * bio_set is used to allow other portions of the IO system to
372 * allocate their own private memory pools for bio and iovec structures. 392 * allocate their own private memory pools for bio and iovec structures.
373 * These memory pools in turn all allocate from the bio_slab 393 * These memory pools in turn all allocate from the bio_slab
@@ -445,6 +465,14 @@ static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
445 __bio_kmap_irq((bio), (bio)->bi_idx, (flags)) 465 __bio_kmap_irq((bio), (bio)->bi_idx, (flags))
446#define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags) 466#define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags)
447 467
468/*
469 * Check whether this bio carries any data or not. A NULL bio is allowed.
470 */
471static inline int bio_has_data(struct bio *bio)
472{
473 return bio && bio->bi_io_vec != NULL;
474}
475
448#if defined(CONFIG_BLK_DEV_INTEGRITY) 476#if defined(CONFIG_BLK_DEV_INTEGRITY)
449 477
450#define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)])) 478#define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)]))
@@ -458,14 +486,7 @@ static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
458#define bip_for_each_vec(bvl, bip, i) \ 486#define bip_for_each_vec(bvl, bip, i) \
459 __bip_for_each_vec(bvl, bip, i, (bip)->bip_idx) 487 __bip_for_each_vec(bvl, bip, i, (bip)->bip_idx)
460 488
461static inline int bio_integrity(struct bio *bio) 489#define bio_integrity(bio) (bio->bi_integrity != NULL)
462{
463#if defined(CONFIG_BLK_DEV_INTEGRITY)
464 return bio->bi_integrity != NULL;
465#else
466 return 0;
467#endif
468}
469 490
470extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *); 491extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *);
471extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); 492extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);