From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B57A220FA8B for ; Fri, 9 May 2025 15:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746803200; cv=none; b=IsVZoeInkKinE32LdrOJ/HXjL6UKq/izenuKCZ97sH3MqOGYz0LFVFrk2QsW+OVmplYS/RQK0rbS5HK+SyYXmbKfce1ELGHmHYTrpZELt1EkBLrlmzsaA0MvFRiR2GyHLbQh8TrI68HFcOn6qzI3/vgeEwutmkAGjy1Vi+7BTJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746803200; c=relaxed/simple; bh=N0YZ9FKsxJ2LCFXlQK4trJTyoAuuDxYbBZmjDa49M9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bytp80Ej9cS9PNajTr664jCB2KVMSMmPR6bPd2beHo3wG/iwQ5Pv2mnRNdDLGJGpHjV2+7/KzJYZNcS7MQMmHyZW0v1gsMeLWmZTL1bnxUDtx4B2FFRIS4eCmGrujFnUQNRwFfYLQXIjOntPIQP/Z0XUrMGRSWhZZF6cUcpeKRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KAAWSI3V; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KAAWSI3V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746803197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=in1A5ApuQDXmJwHneWph4saklElSzBjsT+g0rd0Ve+Y=; b=KAAWSI3VJctRDp/MlsBXdKmE/JvEcXf3O/ZNJW/3H6dHh8mBIHUJ05LZXk6zE/TE+SJ8k8 dth41H6nZlDEIwGKYpLHARNr064ERBEhv2IufTWACixTQZ3siK5vGqnrVVcJP0GzABo/5P euLNFT+K/TlOwcQg/m9jUGyyjuNile8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-7iALsUeXMC2KO5_WKWi3TA-1; Fri, 09 May 2025 11:06:31 -0400 X-MC-Unique: 7iALsUeXMC2KO5_WKWi3TA-1 X-Mimecast-MFC-AGG-ID: 7iALsUeXMC2KO5_WKWi3TA_1746803189 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A381219560B0; Fri, 9 May 2025 15:06:29 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8101F3000221; Fri, 9 May 2025 15:06:27 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Uday Shankar , Caleb Sander Mateos , Keith Busch , Ming Lei Subject: [PATCH V3 2/6] ublk: convert to refcount_t Date: Fri, 9 May 2025 23:06:05 +0800 Message-ID: <20250509150611.3395206-3-ming.lei@redhat.com> In-Reply-To: <20250509150611.3395206-1-ming.lei@redhat.com> References: <20250509150611.3395206-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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 Suggested-by: Caleb Sander Mateos Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 31f06e734250..ab5b0a5e98e9 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -79,7 +79,7 @@ UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT) struct ublk_rq_data { - struct kref ref; + refcount_t ref; }; struct ublk_uring_cmd_pdu { @@ -488,7 +488,6 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq, #endif static inline void __ublk_complete_rq(struct request *req); -static void ublk_complete_rq(struct kref *ref); static dev_t ublk_chr_devt; static const struct class ublk_chr_class = { @@ -648,7 +647,7 @@ static inline void ublk_init_req_ref(const struct ublk_queue *ubq, if (ublk_need_req_ref(ubq)) { struct ublk_rq_data *data = blk_mq_rq_to_pdu(req); - kref_init(&data->ref); + refcount_set(&data->ref, 1); } } @@ -658,7 +657,7 @@ static inline bool ublk_get_req_ref(const struct ublk_queue *ubq, if (ublk_need_req_ref(ubq)) { struct ublk_rq_data *data = blk_mq_rq_to_pdu(req); - return kref_get_unless_zero(&data->ref); + return refcount_inc_not_zero(&data->ref); } return true; @@ -670,7 +669,8 @@ static inline void ublk_put_req_ref(const struct ublk_queue *ubq, if (ublk_need_req_ref(ubq)) { struct ublk_rq_data *data = blk_mq_rq_to_pdu(req); - kref_put(&data->ref, ublk_complete_rq); + if (refcount_dec_and_test(&data->ref)) + __ublk_complete_rq(req); } else { __ublk_complete_rq(req); } @@ -1122,15 +1122,6 @@ static inline void __ublk_complete_rq(struct request *req) blk_mq_end_request(req, res); } -static void ublk_complete_rq(struct kref *ref) -{ - struct ublk_rq_data *data = container_of(ref, struct ublk_rq_data, - ref); - struct request *req = blk_mq_rq_from_pdu(data); - - __ublk_complete_rq(req); -} - static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req, int res, unsigned issue_flags) { -- 2.47.0