Skip to content

Commit 7435e90

Browse files
lgeaxboe
authored andcommitted
drbd: zero-out partial unaligned discards on local backend
For consistency, also zero-out partial unaligned chunks of discard requests on the local backend. Signed-off-by: Philipp Reisner <[email protected]> Signed-off-by: Lars Ellenberg <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 69ba1ee commit 7435e90

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

drivers/block/drbd/drbd_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ extern void start_resync_timer_fn(unsigned long data);
15531553
extern void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req);
15541554

15551555
/* drbd_receiver.c */
1556+
extern int drbd_issue_discard_or_zero_out(struct drbd_device *device,
1557+
sector_t start, unsigned int nr_sectors, bool discard);
15561558
extern int drbd_receiver(struct drbd_thread *thi);
15571559
extern int drbd_ack_receiver(struct drbd_thread *thi);
15581560
extern void drbd_send_ping_wf(struct work_struct *ws);

drivers/block/drbd/drbd_req.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,16 @@ static int drbd_process_write_request(struct drbd_request *req)
11561156
return remote;
11571157
}
11581158

1159+
static void drbd_process_discard_req(struct drbd_request *req)
1160+
{
1161+
int err = drbd_issue_discard_or_zero_out(req->device,
1162+
req->i.sector, req->i.size >> 9, true);
1163+
1164+
if (err)
1165+
req->private_bio->bi_error = -EIO;
1166+
bio_endio(req->private_bio);
1167+
}
1168+
11591169
static void
11601170
drbd_submit_req_private_bio(struct drbd_request *req)
11611171
{
@@ -1176,6 +1186,8 @@ drbd_submit_req_private_bio(struct drbd_request *req)
11761186
: rw == READ ? DRBD_FAULT_DT_RD
11771187
: DRBD_FAULT_DT_RA))
11781188
bio_io_error(bio);
1189+
else if (bio_op(bio) == REQ_OP_DISCARD)
1190+
drbd_process_discard_req(req);
11791191
else
11801192
generic_make_request(bio);
11811193
put_ldev(device);
@@ -1227,18 +1239,23 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long
12271239
/* Update disk stats */
12281240
_drbd_start_io_acct(device, req);
12291241

1242+
/* process discards always from our submitter thread */
1243+
if (bio_op(bio) & REQ_OP_DISCARD)
1244+
goto queue_for_submitter_thread;
1245+
12301246
if (rw == WRITE && req->private_bio && req->i.size
12311247
&& !test_bit(AL_SUSPENDED, &device->flags)) {
1232-
if (!drbd_al_begin_io_fastpath(device, &req->i)) {
1233-
atomic_inc(&device->ap_actlog_cnt);
1234-
drbd_queue_write(device, req);
1235-
return NULL;
1236-
}
1248+
if (!drbd_al_begin_io_fastpath(device, &req->i))
1249+
goto queue_for_submitter_thread;
12371250
req->rq_state |= RQ_IN_ACT_LOG;
12381251
req->in_actlog_jif = jiffies;
12391252
}
1240-
12411253
return req;
1254+
1255+
queue_for_submitter_thread:
1256+
atomic_inc(&device->ap_actlog_cnt);
1257+
drbd_queue_write(device, req);
1258+
return NULL;
12421259
}
12431260

12441261
static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request *req)

0 commit comments

Comments
 (0)