xref: /OK3568_Linux_fs/kernel/drivers/md/dm-bio-record.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is released under the GPL.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef DM_BIO_RECORD_H
8*4882a593Smuzhiyun #define DM_BIO_RECORD_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/bio.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun  * There are lots of mutable fields in the bio struct that get
14*4882a593Smuzhiyun  * changed by the lower levels of the block layer.  Some targets,
15*4882a593Smuzhiyun  * such as multipath, may wish to resubmit a bio on error.  The
16*4882a593Smuzhiyun  * functions in this file help the target record and restore the
17*4882a593Smuzhiyun  * original bio state.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun struct dm_bio_details {
21*4882a593Smuzhiyun 	struct gendisk *bi_disk;
22*4882a593Smuzhiyun 	u8 bi_partno;
23*4882a593Smuzhiyun 	int __bi_remaining;
24*4882a593Smuzhiyun 	unsigned long bi_flags;
25*4882a593Smuzhiyun 	struct bvec_iter bi_iter;
26*4882a593Smuzhiyun 	bio_end_io_t *bi_end_io;
27*4882a593Smuzhiyun #if defined(CONFIG_BLK_DEV_INTEGRITY)
28*4882a593Smuzhiyun 	struct bio_integrity_payload *bi_integrity;
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun 
dm_bio_record(struct dm_bio_details * bd,struct bio * bio)32*4882a593Smuzhiyun static inline void dm_bio_record(struct dm_bio_details *bd, struct bio *bio)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	bd->bi_disk = bio->bi_disk;
35*4882a593Smuzhiyun 	bd->bi_partno = bio->bi_partno;
36*4882a593Smuzhiyun 	bd->bi_flags = bio->bi_flags;
37*4882a593Smuzhiyun 	bd->bi_iter = bio->bi_iter;
38*4882a593Smuzhiyun 	bd->__bi_remaining = atomic_read(&bio->__bi_remaining);
39*4882a593Smuzhiyun 	bd->bi_end_io = bio->bi_end_io;
40*4882a593Smuzhiyun #if defined(CONFIG_BLK_DEV_INTEGRITY)
41*4882a593Smuzhiyun 	bd->bi_integrity = bio_integrity(bio);
42*4882a593Smuzhiyun #endif
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun 
dm_bio_restore(struct dm_bio_details * bd,struct bio * bio)45*4882a593Smuzhiyun static inline void dm_bio_restore(struct dm_bio_details *bd, struct bio *bio)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	bio->bi_disk = bd->bi_disk;
48*4882a593Smuzhiyun 	bio->bi_partno = bd->bi_partno;
49*4882a593Smuzhiyun 	bio->bi_flags = bd->bi_flags;
50*4882a593Smuzhiyun 	bio->bi_iter = bd->bi_iter;
51*4882a593Smuzhiyun 	atomic_set(&bio->__bi_remaining, bd->__bi_remaining);
52*4882a593Smuzhiyun 	bio->bi_end_io = bd->bi_end_io;
53*4882a593Smuzhiyun #if defined(CONFIG_BLK_DEV_INTEGRITY)
54*4882a593Smuzhiyun 	bio->bi_integrity = bd->bi_integrity;
55*4882a593Smuzhiyun #endif
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #endif
59