Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm ebs: pass discards down to underlying device

Make use of dm_bufio_issue_discard() to pass discards down to the
underlying device.

Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Heinz Mauelshagen and committed by
Mike Snitzer
a5089a95 6fbeb004

+34 -7
+34 -7
drivers/md/dm-ebs-target.c
··· 132 132 return r; 133 133 } 134 134 135 - /* 'Discard' blocks, i.e. release them from the bufio cache. */ 136 - static int __ebs_forget_bio(struct ebs_c *ec, struct bio *bio) 135 + /* 136 + * Discard bio's blocks, i.e. pass discards down. 137 + * 138 + * Avoid discarding partial blocks at beginning and end; 139 + * return 0 in case no blocks can be discarded as a result. 140 + */ 141 + static int __ebs_discard_bio(struct ebs_c *ec, struct bio *bio) 142 + { 143 + sector_t block, blocks, sector = bio->bi_iter.bi_sector; 144 + 145 + block = __sector_to_block(ec, sector); 146 + blocks = __nr_blocks(ec, bio); 147 + 148 + /* 149 + * Partial first underlying block (__nr_blocks() may have 150 + * resulted in one block). 151 + */ 152 + if (__block_mod(sector, ec->u_bs)) { 153 + block++; 154 + blocks--; 155 + } 156 + 157 + /* Partial last underlying block if any. */ 158 + if (blocks && __block_mod(bio_end_sector(bio), ec->u_bs)) 159 + blocks--; 160 + 161 + return blocks ? dm_bufio_issue_discard(ec->bufio, block, blocks) : 0; 162 + } 163 + 164 + /* Release blocks them from the bufio cache. */ 165 + static void __ebs_forget_bio(struct ebs_c *ec, struct bio *bio) 137 166 { 138 167 sector_t blocks, sector = bio->bi_iter.bi_sector; 139 168 140 169 blocks = __nr_blocks(ec, bio); 141 170 for (; blocks--; sector += ec->u_bs) 142 171 dm_bufio_forget(ec->bufio, __sector_to_block(ec, sector)); 143 - 144 - return 0; 145 172 } 146 173 147 174 /* Worker funtion to process incoming bios. */ ··· 210 183 write = true; 211 184 r = __ebs_rw_bio(ec, WRITE, bio); 212 185 } else if (bio_op(bio) == REQ_OP_DISCARD) { 213 - /* FIXME: (optionally) call dm_bufio_discard_buffers() once upstream. */ 214 - r = __ebs_forget_bio(ec, bio); 186 + __ebs_forget_bio(ec, bio); 187 + r = __ebs_discard_bio(ec, bio); 215 188 } 216 189 217 190 if (r < 0) ··· 436 409 437 410 static struct target_type ebs_target = { 438 411 .name = "ebs", 439 - .version = {1, 0, 0}, 412 + .version = {1, 0, 1}, 440 413 .features = DM_TARGET_PASSES_INTEGRITY, 441 414 .module = THIS_MODULE, 442 415 .ctr = ebs_ctr,