dm-bio-record.h revision 75d5d8156500cd3833d66806889372e294af514d
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file is released under the GPL.
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef DM_BIO_RECORD_H
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DM_BIO_RECORD_H
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/bio.h>
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * There are lots of mutable fields in the bio struct that get
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * changed by the lower levels of the block layer.  Some targets,
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * such as multipath, may wish to resubmit a bio on error.  The
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * functions in this file help the target record and restore the
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * original bio state.
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
19a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
20a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patockastruct dm_bio_vec_details {
21a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka#if PAGE_SIZE < 65536
22a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	__u16 bv_len;
23a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	__u16 bv_offset;
24a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka#else
25a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	unsigned bv_len;
26a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	unsigned bv_offset;
27a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka#endif
28a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka};
29a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct dm_bio_details {
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct block_device *bi_bdev;
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long bi_flags;
3375d5d8156500cd3833d66806889372e294af514dKent Overstreet	struct bvec_iter bi_iter;
34a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	struct dm_bio_vec_details bi_io_vec[BIO_MAX_PAGES];
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void dm_bio_record(struct dm_bio_details *bd, struct bio *bio)
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
39a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	unsigned i;
40a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	bd->bi_bdev = bio->bi_bdev;
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	bd->bi_flags = bio->bi_flags;
4375d5d8156500cd3833d66806889372e294af514dKent Overstreet	bd->bi_iter = bio->bi_iter;
44a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
45a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	for (i = 0; i < bio->bi_vcnt; i++) {
46a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka		bd->bi_io_vec[i].bv_len = bio->bi_io_vec[i].bv_len;
47a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka		bd->bi_io_vec[i].bv_offset = bio->bi_io_vec[i].bv_offset;
48a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	}
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void dm_bio_restore(struct dm_bio_details *bd, struct bio *bio)
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
53a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	unsigned i;
54a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	bio->bi_bdev = bd->bi_bdev;
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	bio->bi_flags = bd->bi_flags;
5775d5d8156500cd3833d66806889372e294af514dKent Overstreet	bio->bi_iter = bd->bi_iter;
58a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka
59a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	for (i = 0; i < bio->bi_vcnt; i++) {
60a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka		bio->bi_io_vec[i].bv_len = bd->bi_io_vec[i].bv_len;
61a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka		bio->bi_io_vec[i].bv_offset = bd->bi_io_vec[i].bv_offset;
62a920f6b3accc77d9dddbc98a7426be23ee479625Mikulas Patocka	}
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
66