From 5a71a6bcc7173e136cd3fa2f38f40ba7dd10b52f Mon Sep 17 00:00:00 2001 From: Boojin Kim Date: Wed, 24 Jan 2018 17:01:43 +0900 Subject: [PATCH] [COMMON] bio: support diskcipher Change-Id: I61774e13ba45c5a21ea9e08d820534302deaf91d Signed-off-by: Boojin Kim --- block/bio.c | 5 +++++ block/blk-merge.c | 5 +++++ include/linux/bio.h | 8 ++++++++ include/linux/blk_types.h | 6 ++++++ include/linux/blkdev.h | 9 +++++++++ 5 files changed, 33 insertions(+) diff --git a/block/bio.c b/block/bio.c index 7f978eac9a7a..01a037c1d3f4 100644 --- a/block/bio.c +++ b/block/bio.c @@ -607,6 +607,9 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src) bio->bi_io_vec = bio_src->bi_io_vec; bio_clone_blkcg_association(bio, bio_src); + + if (bio->bi_opf & REQ_AUX_PRIV) + bio->bi_aux_private = bio_src->bi_aux_private; } EXPORT_SYMBOL(__bio_clone_fast); @@ -689,6 +692,8 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; + if (bio->bi_opf & REQ_AUX_PRIV) + bio->bi_aux_private = bio_src->bi_aux_private; switch (bio_op(bio)) { case REQ_OP_DISCARD: diff --git a/block/blk-merge.c b/block/blk-merge.c index f5dedd57dff6..7e7f42e2e450 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -673,6 +673,9 @@ static struct request *attempt_merge(struct request_queue *q, !blk_write_same_mergeable(req->bio, next->bio)) return NULL; + if (!blk_crypt_mergeable(req->bio, next->bio)) + return NULL; + /* * Don't allow merge of different write hints, or for a hint with * non-hint IO. @@ -799,6 +802,8 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) !blk_write_same_mergeable(rq->bio, bio)) return false; + if (!blk_crypt_mergeable(rq->bio, bio)) + return false; /* * Don't allow merge of different write hints, or for a hint with * non-hint IO. diff --git a/include/linux/bio.h b/include/linux/bio.h index 45f00dd6323c..52cb51456ce2 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -123,6 +123,14 @@ static inline void *bio_data(struct bio *bio) return NULL; } +static inline bool bio_has_crypt(struct bio *bio) +{ + if (bio && (bio->bi_opf & REQ_CRYPT)) + return true; + else + return false; +} + /* * will die */ diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 1c8a8a2aedf7..4dc0b3e03dac 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -78,6 +78,8 @@ struct bio { bio_end_io_t *bi_end_io; void *bi_private; + void *bi_aux_private; + #ifdef CONFIG_BLK_CGROUP /* * Optional ioc and css associated with this bio. Put on bio @@ -222,6 +224,8 @@ enum req_flag_bits { __REQ_INTEGRITY, /* I/O includes block integrity payload */ __REQ_FUA, /* forced unit access */ __REQ_PREFLUSH, /* request for cache flush */ + __REQ_AUX_PRIV, /* use bi_aux_private */ + __REQ_CRYPT, /* request inline crypt */ __REQ_RAHEAD, /* read ahead, can fail anytime */ __REQ_BACKGROUND, /* background IO */ @@ -241,6 +245,8 @@ enum req_flag_bits { #define REQ_NOMERGE (1ULL << __REQ_NOMERGE) #define REQ_IDLE (1ULL << __REQ_IDLE) #define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY) +#define REQ_AUX_PRIV (1ULL << __REQ_AUX_PRIV) +#define REQ_CRYPT (1ULL << __REQ_CRYPT) #define REQ_FUA (1ULL << __REQ_FUA) #define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH) #define REQ_RAHEAD (1ULL << __REQ_RAHEAD) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6362e3606aa5..c280518d8f8f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -866,6 +866,15 @@ static inline unsigned int blk_queue_depth(struct request_queue *q) return q->nr_requests; } +static inline bool blk_crypt_mergeable(struct bio *a, struct bio *b) +{ + if (bio_has_crypt(a) && bio_has_crypt(b)) + if (a->bi_aux_private != b->bi_aux_private) + return false; + + return true; +} + /* * q->prep_rq_fn return values */ -- 2.20.1