blob: 4f46e8e528deec48d51a52fcbb0126fe0f2a2386 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_BIO_RECORD_H
8#define DM_BIO_RECORD_H
9
10#include <linux/bio.h>
11
12/*
13 * There are lots of mutable fields in the bio struct that get
14 * changed by the lower levels of the block layer. Some targets,
15 * such as multipath, may wish to resubmit a bio on error. The
16 * functions in this file help the target record and restore the
17 * original bio state.
18 */
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010019
20struct dm_bio_vec_details {
21#if PAGE_SIZE < 65536
22 __u16 bv_len;
23 __u16 bv_offset;
24#else
25 unsigned bv_len;
26 unsigned bv_offset;
27#endif
28};
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct dm_bio_details {
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 struct block_device *bi_bdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 unsigned long bi_flags;
Kent Overstreet75d5d812013-08-07 14:24:19 -070033 struct bvec_iter bi_iter;
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010034 struct dm_bio_vec_details bi_io_vec[BIO_MAX_PAGES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070035};
36
37static inline void dm_bio_record(struct dm_bio_details *bd, struct bio *bio)
38{
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010039 unsigned i;
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 bd->bi_bdev = bio->bi_bdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 bd->bi_flags = bio->bi_flags;
Kent Overstreet75d5d812013-08-07 14:24:19 -070043 bd->bi_iter = bio->bi_iter;
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010044
45 for (i = 0; i < bio->bi_vcnt; i++) {
46 bd->bi_io_vec[i].bv_len = bio->bi_io_vec[i].bv_len;
47 bd->bi_io_vec[i].bv_offset = bio->bi_io_vec[i].bv_offset;
48 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51static inline void dm_bio_restore(struct dm_bio_details *bd, struct bio *bio)
52{
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010053 unsigned i;
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 bio->bi_bdev = bd->bi_bdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 bio->bi_flags = bd->bi_flags;
Kent Overstreet75d5d812013-08-07 14:24:19 -070057 bio->bi_iter = bd->bi_iter;
Mikulas Patockaa920f6b2009-04-02 19:55:23 +010058
59 for (i = 0; i < bio->bi_vcnt; i++) {
60 bio->bi_io_vec[i].bv_len = bd->bi_io_vec[i].bv_len;
61 bio->bi_io_vec[i].bv_offset = bd->bi_io_vec[i].bv_offset;
62 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65#endif