Skip to content

Commit a949a81

Browse files
calebsanderkawasaki
authored andcommitted
ublk: remove ubq checks from ublk_{get,put}_req_ref()
ublk_get_req_ref() and ublk_put_req_ref() currently call ublk_need_req_ref(ubq) to check whether the ublk device features require reference counting of its requests. However, all callers already know that reference counting is required: - __ublk_check_and_get_req() is only called from ublk_check_and_get_req() if user copy is enabled, and from ublk_register_io_buf() if zero copy is enabled - ublk_io_release() is only called for requests registered by ublk_register_io_buf(), which requires zero copy - ublk_ch_read_iter() and ublk_ch_write_iter() only call ublk_put_req_ref() if ublk_check_and_get_req() succeeded, which requires user copy to be enabled So drop the ublk_need_req_ref() check and the ubq argument in ublk_get_req_ref() and ublk_put_req_ref(). Signed-off-by: Caleb Sander Mateos <[email protected]>
1 parent 73e4593 commit a949a81

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

drivers/block/ublk_drv.c

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -692,29 +692,19 @@ static inline void ublk_init_req_ref(const struct ublk_queue *ubq,
692692
}
693693
}
694694

695-
static inline bool ublk_get_req_ref(const struct ublk_queue *ubq,
696-
struct request *req)
695+
static inline bool ublk_get_req_ref(struct request *req)
697696
{
698-
if (ublk_need_req_ref(ubq)) {
699-
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
700-
701-
return refcount_inc_not_zero(&data->ref);
702-
}
697+
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
703698

704-
return true;
699+
return refcount_inc_not_zero(&data->ref);
705700
}
706701

707-
static inline void ublk_put_req_ref(const struct ublk_queue *ubq,
708-
struct request *req)
702+
static inline void ublk_put_req_ref(struct request *req)
709703
{
710-
if (ublk_need_req_ref(ubq)) {
711-
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
704+
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
712705

713-
if (refcount_dec_and_test(&data->ref))
714-
__ublk_complete_rq(req);
715-
} else {
706+
if (refcount_dec_and_test(&data->ref))
716707
__ublk_complete_rq(req);
717-
}
718708
}
719709

720710
static inline void ublk_sub_req_ref(struct request *req)
@@ -2006,9 +1996,8 @@ static inline int ublk_set_auto_buf_reg(struct io_uring_cmd *cmd)
20061996
static void ublk_io_release(void *priv)
20071997
{
20081998
struct request *rq = priv;
2009-
struct ublk_queue *ubq = rq->mq_hctx->driver_data;
20101999

2011-
ublk_put_req_ref(ubq, rq);
2000+
ublk_put_req_ref(rq);
20122001
}
20132002

20142003
static int ublk_register_io_buf(struct io_uring_cmd *cmd,
@@ -2029,7 +2018,7 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
20292018
ret = io_buffer_register_bvec(cmd, req, ublk_io_release, index,
20302019
issue_flags);
20312020
if (ret) {
2032-
ublk_put_req_ref(ubq, req);
2021+
ublk_put_req_ref(req);
20332022
return ret;
20342023
}
20352024

@@ -2305,7 +2294,7 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
23052294
if (!req)
23062295
return NULL;
23072296

2308-
if (!ublk_get_req_ref(ubq, req))
2297+
if (!ublk_get_req_ref(req))
23092298
return NULL;
23102299

23112300
if (unlikely(!blk_mq_request_started(req) || req->tag != tag))
@@ -2319,7 +2308,7 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
23192308

23202309
return req;
23212310
fail_put:
2322-
ublk_put_req_ref(ubq, req);
2311+
ublk_put_req_ref(req);
23232312
return NULL;
23242313
}
23252314

@@ -2433,13 +2422,12 @@ static struct request *ublk_check_and_get_req(struct kiocb *iocb,
24332422
*off = buf_off;
24342423
return req;
24352424
fail:
2436-
ublk_put_req_ref(ubq, req);
2425+
ublk_put_req_ref(req);
24372426
return ERR_PTR(-EACCES);
24382427
}
24392428

24402429
static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
24412430
{
2442-
struct ublk_queue *ubq;
24432431
struct request *req;
24442432
size_t buf_off;
24452433
size_t ret;
@@ -2449,15 +2437,13 @@ static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
24492437
return PTR_ERR(req);
24502438

24512439
ret = ublk_copy_user_pages(req, buf_off, to, ITER_DEST);
2452-
ubq = req->mq_hctx->driver_data;
2453-
ublk_put_req_ref(ubq, req);
2440+
ublk_put_req_ref(req);
24542441

24552442
return ret;
24562443
}
24572444

24582445
static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from)
24592446
{
2460-
struct ublk_queue *ubq;
24612447
struct request *req;
24622448
size_t buf_off;
24632449
size_t ret;
@@ -2467,8 +2453,7 @@ static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from)
24672453
return PTR_ERR(req);
24682454

24692455
ret = ublk_copy_user_pages(req, buf_off, from, ITER_SOURCE);
2470-
ubq = req->mq_hctx->driver_data;
2471-
ublk_put_req_ref(ubq, req);
2456+
ublk_put_req_ref(req);
24722457

24732458
return ret;
24742459
}

0 commit comments

Comments
 (0)