Skip to content

Commit a5089a9

Browse files
mauelshasnitm
authored andcommitted
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>
1 parent 6fbeb00 commit a5089a9

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

‎drivers/md/dm-ebs-target.c‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,43 @@ static int __ebs_rw_bio(struct ebs_c *ec, int rw, struct bio *bio)
132132
return r;
133133
}
134134

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)
137166
{
138167
sector_t blocks, sector = bio->bi_iter.bi_sector;
139168

140169
blocks = __nr_blocks(ec, bio);
141170
for (; blocks--; sector += ec->u_bs)
142171
dm_bufio_forget(ec->bufio, __sector_to_block(ec, sector));
143-
144-
return 0;
145172
}
146173

147174
/* Worker funtion to process incoming bios. */
@@ -183,8 +210,8 @@ static void __ebs_process_bios(struct work_struct *ws)
183210
write = true;
184211
r = __ebs_rw_bio(ec, WRITE, bio);
185212
} else if (bio_op(bio) == REQ_OP_DISCARD) {
186-
/* FIXME: (optionally) call dm_bufio_discard_buffers() once upstream. */
187-
r = __ebs_forget_bio(ec, bio);
213+
__ebs_forget_bio(ec, bio);
214+
r = __ebs_discard_bio(ec, bio);
188215
}
189216

190217
if (r < 0)
@@ -409,7 +436,7 @@ static int ebs_iterate_devices(struct dm_target *ti,
409436

410437
static struct target_type ebs_target = {
411438
.name = "ebs",
412-
.version = {1, 0, 0},
439+
.version = {1, 0, 1},
413440
.features = DM_TARGET_PASSES_INTEGRITY,
414441
.module = THIS_MODULE,
415442
.ctr = ebs_ctr,

0 commit comments

Comments
 (0)