direct-io.hg

changeset 2303:1a4a77d3fdb5

bitkeeper revision 1.1159.42.6 (4124d979a7-WTSkxhJT2RPTsBFY3IA)

Relocate file to the correct place.
author kaf24@scramble.cl.cam.ac.uk
date Thu Aug 19 16:46:49 2004 +0000 (2004-08-19)
parents f0960adc6590
children a2ba99e7ce71
files .rootkeys linux-2.6.7-xen-sparse/bio.h linux-2.6.7-xen-sparse/include/linux/bio.h
line diff
     1.1 --- a/.rootkeys	Thu Aug 19 16:43:50 2004 +0000
     1.2 +++ b/.rootkeys	Thu Aug 19 16:46:49 2004 +0000
     1.3 @@ -171,7 +171,6 @@ 4110f478aeQWllIN7J4kouAHiAqrPw linux-2.6
     1.4  40f56239sFcjHiIRmnObRIDF-zaeKQ linux-2.6.7-xen-sparse/arch/xen/kernel/process.c
     1.5  40f562392LBhwmOxVPsYdkYXMxI_ZQ linux-2.6.7-xen-sparse/arch/xen/kernel/reboot.c
     1.6  3f68905c5eiA-lBMQSvXLMWS1ikDEA linux-2.6.7-xen-sparse/arch/xen/kernel/xen_proc.c
     1.7 -4124d8c4aocX7A-jIbuGraWN84pxGQ linux-2.6.7-xen-sparse/bio.h
     1.8  4108f5c1WfTIrs0HZFeV39sttekCTw linux-2.6.7-xen-sparse/drivers/char/mem.c
     1.9  4111308bZAIzwf_Kzu6x1TZYZ3E0_Q linux-2.6.7-xen-sparse/drivers/char/tty_io.c
    1.10  40f56239Dp_vMTgz8TEbvo1hjHGc3w linux-2.6.7-xen-sparse/drivers/xen/Makefile
    1.11 @@ -243,6 +242,7 @@ 3f108af1ylCIm82H052FVTfXACBHrw linux-2.6
    1.12  4122466356eIBnC9ot44WSVVIFyhQA linux-2.6.7-xen-sparse/include/asm-xen/queues.h
    1.13  3fa8e3f0kBLeE4To2vpdi3cpJbIkbQ linux-2.6.7-xen-sparse/include/asm-xen/suspend.h
    1.14  3f689063BoW-HWV3auUJ-OqXfcGArw linux-2.6.7-xen-sparse/include/asm-xen/xen_proc.h
    1.15 +4124d8c4aocX7A-jIbuGraWN84pxGQ linux-2.6.7-xen-sparse/include/linux/bio.h
    1.16  40f56a0ddHCSs3501MY4hRf22tctOw linux-2.6.7-xen-sparse/mkbuildtree
    1.17  410a94a4KT6I6X0LVc7djB39tRDp4g linux-2.6.7-xen-sparse/mm/page_alloc.c
    1.18  40e1b09db5mN69Ijj0X_Eol-S7dXiw tools/Make.defs
     2.1 --- a/linux-2.6.7-xen-sparse/bio.h	Thu Aug 19 16:43:50 2004 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,304 +0,0 @@
     2.4 -/*
     2.5 - * 2.5 block I/O model
     2.6 - *
     2.7 - * Copyright (C) 2001 Jens Axboe <axboe@suse.de>
     2.8 - *
     2.9 - * This program is free software; you can redistribute it and/or modify
    2.10 - * it under the terms of the GNU General Public License version 2 as
    2.11 - * published by the Free Software Foundation.
    2.12 - *
    2.13 - * This program is distributed in the hope that it will be useful,
    2.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 -
    2.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.17 - * GNU General Public License for more details.
    2.18 - *
    2.19 - * You should have received a copy of the GNU General Public Licens
    2.20 - * along with this program; if not, write to the Free Software
    2.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-
    2.22 - */
    2.23 -#ifndef __LINUX_BIO_H
    2.24 -#define __LINUX_BIO_H
    2.25 -
    2.26 -#include <linux/highmem.h>
    2.27 -#include <linux/mempool.h>
    2.28 -
    2.29 -/* Platforms may set this to teach the BIO layer about IOMMU hardware. */
    2.30 -#include <asm/io.h>
    2.31 -#ifndef BIO_VMERGE_BOUNDARY
    2.32 -#define BIO_VMERGE_BOUNDARY	0
    2.33 -#endif
    2.34 -
    2.35 -#define BIO_DEBUG
    2.36 -
    2.37 -#ifdef BIO_DEBUG
    2.38 -#define BIO_BUG_ON	BUG_ON
    2.39 -#else
    2.40 -#define BIO_BUG_ON
    2.41 -#endif
    2.42 -
    2.43 -#define BIO_MAX_PAGES		(256)
    2.44 -#define BIO_MAX_SIZE		(BIO_MAX_PAGES << PAGE_CACHE_SHIFT)
    2.45 -#define BIO_MAX_SECTORS		(BIO_MAX_SIZE >> 9)
    2.46 -
    2.47 -/*
    2.48 - * was unsigned short, but we might as well be ready for > 64kB I/O pages
    2.49 - */
    2.50 -struct bio_vec {
    2.51 -	struct page	*bv_page;
    2.52 -	unsigned int	bv_len;
    2.53 -	unsigned int	bv_offset;
    2.54 -};
    2.55 -
    2.56 -struct bio;
    2.57 -typedef int (bio_end_io_t) (struct bio *, unsigned int, int);
    2.58 -typedef void (bio_destructor_t) (struct bio *);
    2.59 -
    2.60 -/*
    2.61 - * main unit of I/O for the block layer and lower layers (ie drivers and
    2.62 - * stacking drivers)
    2.63 - */
    2.64 -struct bio {
    2.65 -	sector_t		bi_sector;
    2.66 -	struct bio		*bi_next;	/* request queue link */
    2.67 -	struct block_device	*bi_bdev;
    2.68 -	unsigned long		bi_flags;	/* status, command, etc */
    2.69 -	unsigned long		bi_rw;		/* bottom bits READ/WRITE,
    2.70 -						 * top bits priority
    2.71 -						 */
    2.72 -
    2.73 -	unsigned short		bi_vcnt;	/* how many bio_vec's */
    2.74 -	unsigned short		bi_idx;		/* current index into bvl_vec */
    2.75 -
    2.76 -	/* Number of segments in this BIO after
    2.77 -	 * physical address coalescing is performed.
    2.78 -	 */
    2.79 -	unsigned short		bi_phys_segments;
    2.80 -
    2.81 -	/* Number of segments after physical and DMA remapping
    2.82 -	 * hardware coalescing is performed.
    2.83 -	 */
    2.84 -	unsigned short		bi_hw_segments;
    2.85 -
    2.86 -	unsigned int		bi_size;	/* residual I/O count */
    2.87 -	unsigned int		bi_max_vecs;	/* max bvl_vecs we can hold */
    2.88 -
    2.89 -	struct bio_vec		*bi_io_vec;	/* the actual vec list */
    2.90 -
    2.91 -	bio_end_io_t		*bi_end_io;
    2.92 -	atomic_t		bi_cnt;		/* pin count */
    2.93 -
    2.94 -	void			*bi_private;
    2.95 -
    2.96 -	bio_destructor_t	*bi_destructor;	/* destructor */
    2.97 -};
    2.98 -
    2.99 -/*
   2.100 - * bio flags
   2.101 - */
   2.102 -#define BIO_UPTODATE	0	/* ok after I/O completion */
   2.103 -#define BIO_RW_BLOCK	1	/* RW_AHEAD set, and read/write would block */
   2.104 -#define BIO_EOF		2	/* out-out-bounds error */
   2.105 -#define BIO_SEG_VALID	3	/* nr_hw_seg valid */
   2.106 -#define BIO_CLONED	4	/* doesn't own data */
   2.107 -#define BIO_BOUNCED	5	/* bio is a bounce bio */
   2.108 -#define bio_flagged(bio, flag)	((bio)->bi_flags & (1 << (flag)))
   2.109 -
   2.110 -/*
   2.111 - * top 4 bits of bio flags indicate the pool this bio came from
   2.112 - */
   2.113 -#define BIO_POOL_BITS		(4)
   2.114 -#define BIO_POOL_OFFSET		(BITS_PER_LONG - BIO_POOL_BITS)
   2.115 -#define BIO_POOL_MASK		(1UL << BIO_POOL_OFFSET)
   2.116 -#define BIO_POOL_IDX(bio)	((bio)->bi_flags >> BIO_POOL_OFFSET)	
   2.117 -
   2.118 -/*
   2.119 - * bio bi_rw flags
   2.120 - *
   2.121 - * bit 0 -- read (not set) or write (set)
   2.122 - * bit 1 -- rw-ahead when set
   2.123 - * bit 2 -- barrier
   2.124 - * bit 3 -- fail fast, don't want low level driver retries
   2.125 - * bit 4 -- synchronous I/O hint: the block layer will unplug immediately
   2.126 - */
   2.127 -#define BIO_RW		0
   2.128 -#define BIO_RW_AHEAD	1
   2.129 -#define BIO_RW_BARRIER	2
   2.130 -#define BIO_RW_FAILFAST	3
   2.131 -#define BIO_RW_SYNC	4
   2.132 -
   2.133 -/*
   2.134 - * various member access, note that bio_data should of course not be used
   2.135 - * on highmem page vectors
   2.136 - */
   2.137 -#define bio_iovec_idx(bio, idx)	(&((bio)->bi_io_vec[(idx)]))
   2.138 -#define bio_iovec(bio)		bio_iovec_idx((bio), (bio)->bi_idx)
   2.139 -#define bio_page(bio)		bio_iovec((bio))->bv_page
   2.140 -#define bio_offset(bio)		bio_iovec((bio))->bv_offset
   2.141 -#define bio_segments(bio)	((bio)->bi_vcnt - (bio)->bi_idx)
   2.142 -#define bio_sectors(bio)	((bio)->bi_size >> 9)
   2.143 -#define bio_cur_sectors(bio)	(bio_iovec(bio)->bv_len >> 9)
   2.144 -#define bio_data(bio)		(page_address(bio_page((bio))) + bio_offset((bio)))
   2.145 -#define bio_barrier(bio)	((bio)->bi_rw & (1 << BIO_RW_BARRIER))
   2.146 -#define bio_sync(bio)		((bio)->bi_rw & (1 << BIO_RW_SYNC))
   2.147 -
   2.148 -/*
   2.149 - * will die
   2.150 - */
   2.151 -#define bio_to_phys(bio)	(page_to_phys(bio_page((bio))) + (unsigned long) bio_offset((bio)))
   2.152 -#define bvec_to_phys(bv)	(page_to_phys((bv)->bv_page) + (unsigned long) (bv)->bv_offset)
   2.153 -
   2.154 -/*
   2.155 - * queues that have highmem support enabled may still need to revert to
   2.156 - * PIO transfers occasionally and thus map high pages temporarily. For
   2.157 - * permanent PIO fall back, user is probably better off disabling highmem
   2.158 - * I/O completely on that queue (see ide-dma for example)
   2.159 - */
   2.160 -#define __bio_kmap_atomic(bio, idx, kmtype)				\
   2.161 -	(kmap_atomic(bio_iovec_idx((bio), (idx))->bv_page, kmtype) +	\
   2.162 -		bio_iovec_idx((bio), (idx))->bv_offset)
   2.163 -
   2.164 -#define __bio_kunmap_atomic(addr, kmtype) kunmap_atomic(addr, kmtype)
   2.165 -
   2.166 -/*
   2.167 - * merge helpers etc
   2.168 - */
   2.169 -
   2.170 -#define __BVEC_END(bio)		bio_iovec_idx((bio), (bio)->bi_vcnt - 1)
   2.171 -#define __BVEC_START(bio)	bio_iovec_idx((bio), (bio)->bi_idx)
   2.172 -/* Platforms may set this to restrict multi-page buffer merging. */
   2.173 -#ifndef BIOVEC_PHYS_MERGEABLE
   2.174 -#define BIOVEC_PHYS_MERGEABLE(vec1, vec2)	\
   2.175 -	((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
   2.176 -#endif
   2.177 -#define BIOVEC_VIRT_MERGEABLE(vec1, vec2)	\
   2.178 -	((((bvec_to_phys((vec1)) + (vec1)->bv_len) | bvec_to_phys((vec2))) & (BIO_VMERGE_BOUNDARY - 1)) == 0)
   2.179 -#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
   2.180 -	(((addr1) | (mask)) == (((addr2) - 1) | (mask)))
   2.181 -#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
   2.182 -	__BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, (q)->seg_boundary_mask)
   2.183 -#define BIO_SEG_BOUNDARY(q, b1, b2) \
   2.184 -	BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2)))
   2.185 -
   2.186 -#define bio_io_error(bio, bytes) bio_endio((bio), (bytes), -EIO)
   2.187 -
   2.188 -/*
   2.189 - * drivers should not use the __ version unless they _really_ want to
   2.190 - * run through the entire bio and not just pending pieces
   2.191 - */
   2.192 -#define __bio_for_each_segment(bvl, bio, i, start_idx)			\
   2.193 -	for (bvl = bio_iovec_idx((bio), (start_idx)), i = (start_idx);	\
   2.194 -	     i < (bio)->bi_vcnt;					\
   2.195 -	     bvl++, i++)
   2.196 -
   2.197 -#define bio_for_each_segment(bvl, bio, i)				\
   2.198 -	__bio_for_each_segment(bvl, bio, i, (bio)->bi_idx)
   2.199 -
   2.200 -/*
   2.201 - * get a reference to a bio, so it won't disappear. the intended use is
   2.202 - * something like:
   2.203 - *
   2.204 - * bio_get(bio);
   2.205 - * submit_bio(rw, bio);
   2.206 - * if (bio->bi_flags ...)
   2.207 - *	do_something
   2.208 - * bio_put(bio);
   2.209 - *
   2.210 - * without the bio_get(), it could potentially complete I/O before submit_bio
   2.211 - * returns. and then bio would be freed memory when if (bio->bi_flags ...)
   2.212 - * runs
   2.213 - */
   2.214 -#define bio_get(bio)	atomic_inc(&(bio)->bi_cnt)
   2.215 -
   2.216 -
   2.217 -/*
   2.218 - * A bio_pair is used when we need to split a bio.
   2.219 - * This can only happen for a bio that refers to just one
   2.220 - * page of data, and in the unusual situation when the
   2.221 - * page crosses a chunk/device boundary
   2.222 - *
   2.223 - * The address of the master bio is stored in bio1.bi_private
   2.224 - * The address of the pool the pair was allocated from is stored
   2.225 - *   in bio2.bi_private
   2.226 - */
   2.227 -struct bio_pair {
   2.228 -	struct bio	bio1, bio2;
   2.229 -	struct bio_vec	bv1, bv2;
   2.230 -	atomic_t	cnt;
   2.231 -	int		error;
   2.232 -};
   2.233 -extern struct bio_pair *bio_split(struct bio *bi, mempool_t *pool,
   2.234 -				  int first_sectors);
   2.235 -extern mempool_t *bio_split_pool;
   2.236 -extern void bio_pair_release(struct bio_pair *dbio);
   2.237 -
   2.238 -extern struct bio *bio_alloc(int, int);
   2.239 -extern void bio_put(struct bio *);
   2.240 -
   2.241 -extern void bio_endio(struct bio *, unsigned int, int);
   2.242 -struct request_queue;
   2.243 -extern int bio_phys_segments(struct request_queue *, struct bio *);
   2.244 -extern int bio_hw_segments(struct request_queue *, struct bio *);
   2.245 -
   2.246 -extern void __bio_clone(struct bio *, struct bio *);
   2.247 -extern struct bio *bio_clone(struct bio *, int);
   2.248 -
   2.249 -extern void bio_init(struct bio *);
   2.250 -
   2.251 -extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
   2.252 -extern int bio_get_nr_vecs(struct block_device *);
   2.253 -extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
   2.254 -				unsigned long, unsigned int, int);
   2.255 -extern void bio_unmap_user(struct bio *, int);
   2.256 -extern void bio_set_pages_dirty(struct bio *bio);
   2.257 -extern void bio_check_pages_dirty(struct bio *bio);
   2.258 -
   2.259 -#ifdef CONFIG_HIGHMEM
   2.260 -/*
   2.261 - * remember to add offset! and never ever reenable interrupts between a
   2.262 - * bvec_kmap_irq and bvec_kunmap_irq!!
   2.263 - *
   2.264 - * This function MUST be inlined - it plays with the CPU interrupt flags.
   2.265 - * Hence the `extern inline'.
   2.266 - */
   2.267 -extern inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
   2.268 -{
   2.269 -	unsigned long addr;
   2.270 -
   2.271 -	/*
   2.272 -	 * might not be a highmem page, but the preempt/irq count
   2.273 -	 * balancing is a lot nicer this way
   2.274 -	 */
   2.275 -	local_irq_save(*flags);
   2.276 -	addr = (unsigned long) kmap_atomic(bvec->bv_page, KM_BIO_SRC_IRQ);
   2.277 -
   2.278 -	BUG_ON(addr & ~PAGE_MASK);
   2.279 -
   2.280 -	return (char *) addr + bvec->bv_offset;
   2.281 -}
   2.282 -
   2.283 -extern inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
   2.284 -{
   2.285 -	unsigned long ptr = (unsigned long) buffer & PAGE_MASK;
   2.286 -
   2.287 -	kunmap_atomic((void *) ptr, KM_BIO_SRC_IRQ);
   2.288 -	local_irq_restore(*flags);
   2.289 -}
   2.290 -
   2.291 -#else
   2.292 -#define bvec_kmap_irq(bvec, flags)	(page_address((bvec)->bv_page) + (bvec)->bv_offset)
   2.293 -#define bvec_kunmap_irq(buf, flags)	do { *(flags) = 0; } while (0)
   2.294 -#endif
   2.295 -
   2.296 -extern inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
   2.297 -				   unsigned long *flags)
   2.298 -{
   2.299 -	return bvec_kmap_irq(bio_iovec_idx(bio, idx), flags);
   2.300 -}
   2.301 -#define __bio_kunmap_irq(buf, flags)	bvec_kunmap_irq(buf, flags)
   2.302 -
   2.303 -#define bio_kmap_irq(bio, flags) \
   2.304 -	__bio_kmap_irq((bio), (bio)->bi_idx, (flags))
   2.305 -#define bio_kunmap_irq(buf,flags)	__bio_kunmap_irq(buf, flags)
   2.306 -
   2.307 -#endif /* __LINUX_BIO_H */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/linux-2.6.7-xen-sparse/include/linux/bio.h	Thu Aug 19 16:46:49 2004 +0000
     3.3 @@ -0,0 +1,304 @@
     3.4 +/*
     3.5 + * 2.5 block I/O model
     3.6 + *
     3.7 + * Copyright (C) 2001 Jens Axboe <axboe@suse.de>
     3.8 + *
     3.9 + * This program is free software; you can redistribute it and/or modify
    3.10 + * it under the terms of the GNU General Public License version 2 as
    3.11 + * published by the Free Software Foundation.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +
    3.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.17 + * GNU General Public License for more details.
    3.18 + *
    3.19 + * You should have received a copy of the GNU General Public Licens
    3.20 + * along with this program; if not, write to the Free Software
    3.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-
    3.22 + */
    3.23 +#ifndef __LINUX_BIO_H
    3.24 +#define __LINUX_BIO_H
    3.25 +
    3.26 +#include <linux/highmem.h>
    3.27 +#include <linux/mempool.h>
    3.28 +
    3.29 +/* Platforms may set this to teach the BIO layer about IOMMU hardware. */
    3.30 +#include <asm/io.h>
    3.31 +#ifndef BIO_VMERGE_BOUNDARY
    3.32 +#define BIO_VMERGE_BOUNDARY	0
    3.33 +#endif
    3.34 +
    3.35 +#define BIO_DEBUG
    3.36 +
    3.37 +#ifdef BIO_DEBUG
    3.38 +#define BIO_BUG_ON	BUG_ON
    3.39 +#else
    3.40 +#define BIO_BUG_ON
    3.41 +#endif
    3.42 +
    3.43 +#define BIO_MAX_PAGES		(256)
    3.44 +#define BIO_MAX_SIZE		(BIO_MAX_PAGES << PAGE_CACHE_SHIFT)
    3.45 +#define BIO_MAX_SECTORS		(BIO_MAX_SIZE >> 9)
    3.46 +
    3.47 +/*
    3.48 + * was unsigned short, but we might as well be ready for > 64kB I/O pages
    3.49 + */
    3.50 +struct bio_vec {
    3.51 +	struct page	*bv_page;
    3.52 +	unsigned int	bv_len;
    3.53 +	unsigned int	bv_offset;
    3.54 +};
    3.55 +
    3.56 +struct bio;
    3.57 +typedef int (bio_end_io_t) (struct bio *, unsigned int, int);
    3.58 +typedef void (bio_destructor_t) (struct bio *);
    3.59 +
    3.60 +/*
    3.61 + * main unit of I/O for the block layer and lower layers (ie drivers and
    3.62 + * stacking drivers)
    3.63 + */
    3.64 +struct bio {
    3.65 +	sector_t		bi_sector;
    3.66 +	struct bio		*bi_next;	/* request queue link */
    3.67 +	struct block_device	*bi_bdev;
    3.68 +	unsigned long		bi_flags;	/* status, command, etc */
    3.69 +	unsigned long		bi_rw;		/* bottom bits READ/WRITE,
    3.70 +						 * top bits priority
    3.71 +						 */
    3.72 +
    3.73 +	unsigned short		bi_vcnt;	/* how many bio_vec's */
    3.74 +	unsigned short		bi_idx;		/* current index into bvl_vec */
    3.75 +
    3.76 +	/* Number of segments in this BIO after
    3.77 +	 * physical address coalescing is performed.
    3.78 +	 */
    3.79 +	unsigned short		bi_phys_segments;
    3.80 +
    3.81 +	/* Number of segments after physical and DMA remapping
    3.82 +	 * hardware coalescing is performed.
    3.83 +	 */
    3.84 +	unsigned short		bi_hw_segments;
    3.85 +
    3.86 +	unsigned int		bi_size;	/* residual I/O count */
    3.87 +	unsigned int		bi_max_vecs;	/* max bvl_vecs we can hold */
    3.88 +
    3.89 +	struct bio_vec		*bi_io_vec;	/* the actual vec list */
    3.90 +
    3.91 +	bio_end_io_t		*bi_end_io;
    3.92 +	atomic_t		bi_cnt;		/* pin count */
    3.93 +
    3.94 +	void			*bi_private;
    3.95 +
    3.96 +	bio_destructor_t	*bi_destructor;	/* destructor */
    3.97 +};
    3.98 +
    3.99 +/*
   3.100 + * bio flags
   3.101 + */
   3.102 +#define BIO_UPTODATE	0	/* ok after I/O completion */
   3.103 +#define BIO_RW_BLOCK	1	/* RW_AHEAD set, and read/write would block */
   3.104 +#define BIO_EOF		2	/* out-out-bounds error */
   3.105 +#define BIO_SEG_VALID	3	/* nr_hw_seg valid */
   3.106 +#define BIO_CLONED	4	/* doesn't own data */
   3.107 +#define BIO_BOUNCED	5	/* bio is a bounce bio */
   3.108 +#define bio_flagged(bio, flag)	((bio)->bi_flags & (1 << (flag)))
   3.109 +
   3.110 +/*
   3.111 + * top 4 bits of bio flags indicate the pool this bio came from
   3.112 + */
   3.113 +#define BIO_POOL_BITS		(4)
   3.114 +#define BIO_POOL_OFFSET		(BITS_PER_LONG - BIO_POOL_BITS)
   3.115 +#define BIO_POOL_MASK		(1UL << BIO_POOL_OFFSET)
   3.116 +#define BIO_POOL_IDX(bio)	((bio)->bi_flags >> BIO_POOL_OFFSET)	
   3.117 +
   3.118 +/*
   3.119 + * bio bi_rw flags
   3.120 + *
   3.121 + * bit 0 -- read (not set) or write (set)
   3.122 + * bit 1 -- rw-ahead when set
   3.123 + * bit 2 -- barrier
   3.124 + * bit 3 -- fail fast, don't want low level driver retries
   3.125 + * bit 4 -- synchronous I/O hint: the block layer will unplug immediately
   3.126 + */
   3.127 +#define BIO_RW		0
   3.128 +#define BIO_RW_AHEAD	1
   3.129 +#define BIO_RW_BARRIER	2
   3.130 +#define BIO_RW_FAILFAST	3
   3.131 +#define BIO_RW_SYNC	4
   3.132 +
   3.133 +/*
   3.134 + * various member access, note that bio_data should of course not be used
   3.135 + * on highmem page vectors
   3.136 + */
   3.137 +#define bio_iovec_idx(bio, idx)	(&((bio)->bi_io_vec[(idx)]))
   3.138 +#define bio_iovec(bio)		bio_iovec_idx((bio), (bio)->bi_idx)
   3.139 +#define bio_page(bio)		bio_iovec((bio))->bv_page
   3.140 +#define bio_offset(bio)		bio_iovec((bio))->bv_offset
   3.141 +#define bio_segments(bio)	((bio)->bi_vcnt - (bio)->bi_idx)
   3.142 +#define bio_sectors(bio)	((bio)->bi_size >> 9)
   3.143 +#define bio_cur_sectors(bio)	(bio_iovec(bio)->bv_len >> 9)
   3.144 +#define bio_data(bio)		(page_address(bio_page((bio))) + bio_offset((bio)))
   3.145 +#define bio_barrier(bio)	((bio)->bi_rw & (1 << BIO_RW_BARRIER))
   3.146 +#define bio_sync(bio)		((bio)->bi_rw & (1 << BIO_RW_SYNC))
   3.147 +
   3.148 +/*
   3.149 + * will die
   3.150 + */
   3.151 +#define bio_to_phys(bio)	(page_to_phys(bio_page((bio))) + (unsigned long) bio_offset((bio)))
   3.152 +#define bvec_to_phys(bv)	(page_to_phys((bv)->bv_page) + (unsigned long) (bv)->bv_offset)
   3.153 +
   3.154 +/*
   3.155 + * queues that have highmem support enabled may still need to revert to
   3.156 + * PIO transfers occasionally and thus map high pages temporarily. For
   3.157 + * permanent PIO fall back, user is probably better off disabling highmem
   3.158 + * I/O completely on that queue (see ide-dma for example)
   3.159 + */
   3.160 +#define __bio_kmap_atomic(bio, idx, kmtype)				\
   3.161 +	(kmap_atomic(bio_iovec_idx((bio), (idx))->bv_page, kmtype) +	\
   3.162 +		bio_iovec_idx((bio), (idx))->bv_offset)
   3.163 +
   3.164 +#define __bio_kunmap_atomic(addr, kmtype) kunmap_atomic(addr, kmtype)
   3.165 +
   3.166 +/*
   3.167 + * merge helpers etc
   3.168 + */
   3.169 +
   3.170 +#define __BVEC_END(bio)		bio_iovec_idx((bio), (bio)->bi_vcnt - 1)
   3.171 +#define __BVEC_START(bio)	bio_iovec_idx((bio), (bio)->bi_idx)
   3.172 +/* Platforms may set this to restrict multi-page buffer merging. */
   3.173 +#ifndef BIOVEC_PHYS_MERGEABLE
   3.174 +#define BIOVEC_PHYS_MERGEABLE(vec1, vec2)	\
   3.175 +	((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
   3.176 +#endif
   3.177 +#define BIOVEC_VIRT_MERGEABLE(vec1, vec2)	\
   3.178 +	((((bvec_to_phys((vec1)) + (vec1)->bv_len) | bvec_to_phys((vec2))) & (BIO_VMERGE_BOUNDARY - 1)) == 0)
   3.179 +#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
   3.180 +	(((addr1) | (mask)) == (((addr2) - 1) | (mask)))
   3.181 +#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
   3.182 +	__BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, (q)->seg_boundary_mask)
   3.183 +#define BIO_SEG_BOUNDARY(q, b1, b2) \
   3.184 +	BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2)))
   3.185 +
   3.186 +#define bio_io_error(bio, bytes) bio_endio((bio), (bytes), -EIO)
   3.187 +
   3.188 +/*
   3.189 + * drivers should not use the __ version unless they _really_ want to
   3.190 + * run through the entire bio and not just pending pieces
   3.191 + */
   3.192 +#define __bio_for_each_segment(bvl, bio, i, start_idx)			\
   3.193 +	for (bvl = bio_iovec_idx((bio), (start_idx)), i = (start_idx);	\
   3.194 +	     i < (bio)->bi_vcnt;					\
   3.195 +	     bvl++, i++)
   3.196 +
   3.197 +#define bio_for_each_segment(bvl, bio, i)				\
   3.198 +	__bio_for_each_segment(bvl, bio, i, (bio)->bi_idx)
   3.199 +
   3.200 +/*
   3.201 + * get a reference to a bio, so it won't disappear. the intended use is
   3.202 + * something like:
   3.203 + *
   3.204 + * bio_get(bio);
   3.205 + * submit_bio(rw, bio);
   3.206 + * if (bio->bi_flags ...)
   3.207 + *	do_something
   3.208 + * bio_put(bio);
   3.209 + *
   3.210 + * without the bio_get(), it could potentially complete I/O before submit_bio
   3.211 + * returns. and then bio would be freed memory when if (bio->bi_flags ...)
   3.212 + * runs
   3.213 + */
   3.214 +#define bio_get(bio)	atomic_inc(&(bio)->bi_cnt)
   3.215 +
   3.216 +
   3.217 +/*
   3.218 + * A bio_pair is used when we need to split a bio.
   3.219 + * This can only happen for a bio that refers to just one
   3.220 + * page of data, and in the unusual situation when the
   3.221 + * page crosses a chunk/device boundary
   3.222 + *
   3.223 + * The address of the master bio is stored in bio1.bi_private
   3.224 + * The address of the pool the pair was allocated from is stored
   3.225 + *   in bio2.bi_private
   3.226 + */
   3.227 +struct bio_pair {
   3.228 +	struct bio	bio1, bio2;
   3.229 +	struct bio_vec	bv1, bv2;
   3.230 +	atomic_t	cnt;
   3.231 +	int		error;
   3.232 +};
   3.233 +extern struct bio_pair *bio_split(struct bio *bi, mempool_t *pool,
   3.234 +				  int first_sectors);
   3.235 +extern mempool_t *bio_split_pool;
   3.236 +extern void bio_pair_release(struct bio_pair *dbio);
   3.237 +
   3.238 +extern struct bio *bio_alloc(int, int);
   3.239 +extern void bio_put(struct bio *);
   3.240 +
   3.241 +extern void bio_endio(struct bio *, unsigned int, int);
   3.242 +struct request_queue;
   3.243 +extern int bio_phys_segments(struct request_queue *, struct bio *);
   3.244 +extern int bio_hw_segments(struct request_queue *, struct bio *);
   3.245 +
   3.246 +extern void __bio_clone(struct bio *, struct bio *);
   3.247 +extern struct bio *bio_clone(struct bio *, int);
   3.248 +
   3.249 +extern void bio_init(struct bio *);
   3.250 +
   3.251 +extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
   3.252 +extern int bio_get_nr_vecs(struct block_device *);
   3.253 +extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
   3.254 +				unsigned long, unsigned int, int);
   3.255 +extern void bio_unmap_user(struct bio *, int);
   3.256 +extern void bio_set_pages_dirty(struct bio *bio);
   3.257 +extern void bio_check_pages_dirty(struct bio *bio);
   3.258 +
   3.259 +#ifdef CONFIG_HIGHMEM
   3.260 +/*
   3.261 + * remember to add offset! and never ever reenable interrupts between a
   3.262 + * bvec_kmap_irq and bvec_kunmap_irq!!
   3.263 + *
   3.264 + * This function MUST be inlined - it plays with the CPU interrupt flags.
   3.265 + * Hence the `extern inline'.
   3.266 + */
   3.267 +extern inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
   3.268 +{
   3.269 +	unsigned long addr;
   3.270 +
   3.271 +	/*
   3.272 +	 * might not be a highmem page, but the preempt/irq count
   3.273 +	 * balancing is a lot nicer this way
   3.274 +	 */
   3.275 +	local_irq_save(*flags);
   3.276 +	addr = (unsigned long) kmap_atomic(bvec->bv_page, KM_BIO_SRC_IRQ);
   3.277 +
   3.278 +	BUG_ON(addr & ~PAGE_MASK);
   3.279 +
   3.280 +	return (char *) addr + bvec->bv_offset;
   3.281 +}
   3.282 +
   3.283 +extern inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
   3.284 +{
   3.285 +	unsigned long ptr = (unsigned long) buffer & PAGE_MASK;
   3.286 +
   3.287 +	kunmap_atomic((void *) ptr, KM_BIO_SRC_IRQ);
   3.288 +	local_irq_restore(*flags);
   3.289 +}
   3.290 +
   3.291 +#else
   3.292 +#define bvec_kmap_irq(bvec, flags)	(page_address((bvec)->bv_page) + (bvec)->bv_offset)
   3.293 +#define bvec_kunmap_irq(buf, flags)	do { *(flags) = 0; } while (0)
   3.294 +#endif
   3.295 +
   3.296 +extern inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
   3.297 +				   unsigned long *flags)
   3.298 +{
   3.299 +	return bvec_kmap_irq(bio_iovec_idx(bio, idx), flags);
   3.300 +}
   3.301 +#define __bio_kunmap_irq(buf, flags)	bvec_kunmap_irq(buf, flags)
   3.302 +
   3.303 +#define bio_kmap_irq(bio, flags) \
   3.304 +	__bio_kmap_irq((bio), (bio)->bi_idx, (flags))
   3.305 +#define bio_kunmap_irq(buf,flags)	__bio_kunmap_irq(buf, flags)
   3.306 +
   3.307 +#endif /* __LINUX_BIO_H */