Skip to content

Commit b1c3b46

Browse files
Ming Leiaxboe
authored andcommitted
ublk: convert to refcount_t
Convert to refcount_t and prepare for supporting to register bvec buffer automatically, which needs to initialize reference counter as 2, and kref doesn't provide this interface, so convert to refcount_t. Reviewed-by: Caleb Sander Mateos <[email protected]> Suggested-by: Caleb Sander Mateos <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3fee125 commit b1c3b46

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/block/ublk_drv.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT)
8080

8181
struct ublk_rq_data {
82-
struct kref ref;
82+
refcount_t ref;
8383
};
8484

8585
struct ublk_uring_cmd_pdu {
@@ -488,7 +488,6 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
488488
#endif
489489

490490
static inline void __ublk_complete_rq(struct request *req);
491-
static void ublk_complete_rq(struct kref *ref);
492491

493492
static dev_t ublk_chr_devt;
494493
static const struct class ublk_chr_class = {
@@ -648,7 +647,7 @@ static inline void ublk_init_req_ref(const struct ublk_queue *ubq,
648647
if (ublk_need_req_ref(ubq)) {
649648
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
650649

651-
kref_init(&data->ref);
650+
refcount_set(&data->ref, 1);
652651
}
653652
}
654653

@@ -658,7 +657,7 @@ static inline bool ublk_get_req_ref(const struct ublk_queue *ubq,
658657
if (ublk_need_req_ref(ubq)) {
659658
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
660659

661-
return kref_get_unless_zero(&data->ref);
660+
return refcount_inc_not_zero(&data->ref);
662661
}
663662

664663
return true;
@@ -670,7 +669,8 @@ static inline void ublk_put_req_ref(const struct ublk_queue *ubq,
670669
if (ublk_need_req_ref(ubq)) {
671670
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
672671

673-
kref_put(&data->ref, ublk_complete_rq);
672+
if (refcount_dec_and_test(&data->ref))
673+
__ublk_complete_rq(req);
674674
} else {
675675
__ublk_complete_rq(req);
676676
}
@@ -1122,15 +1122,6 @@ static inline void __ublk_complete_rq(struct request *req)
11221122
blk_mq_end_request(req, res);
11231123
}
11241124

1125-
static void ublk_complete_rq(struct kref *ref)
1126-
{
1127-
struct ublk_rq_data *data = container_of(ref, struct ublk_rq_data,
1128-
ref);
1129-
struct request *req = blk_mq_rq_from_pdu(data);
1130-
1131-
__ublk_complete_rq(req);
1132-
}
1133-
11341125
static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req,
11351126
int res, unsigned issue_flags)
11361127
{

0 commit comments

Comments
 (0)