mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@kernel.org>
To: James Smart <james.smart@broadcom.com>,
	Christoph Hellwig <hch@lst.de>,  Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>
Cc: Hannes Reinecke <hare@suse.de>, Keith Busch <kbusch@kernel.org>,
	 linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	 Daniel Wagner <wagi@kernel.org>
Subject: [PATCH v3 02/18] nvmet-fcloop: replace kref with refcount
Date: Tue, 18 Mar 2025 11:39:56 +0100	[thread overview]
Message-ID: <20250318-nvmet-fcloop-v3-2-05fec0fc02f6@kernel.org> (raw)
In-Reply-To: <20250318-nvmet-fcloop-v3-0-05fec0fc02f6@kernel.org>

The kref wrapper is not really adding any value ontop of refcount. Thus
replace the kref API with the refcount API.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
---
 drivers/nvme/target/fcloop.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
index 09546c3161fd9828234e58641de3e53519e27824..cfce70d1b11ff305b203d716f78fad23f114e9c3 100644
--- a/drivers/nvme/target/fcloop.c
+++ b/drivers/nvme/target/fcloop.c
@@ -239,7 +239,7 @@ struct fcloop_nport {
 	struct fcloop_tport *tport;
 	struct fcloop_lport *lport;
 	struct list_head nport_list;
-	struct kref ref;
+	refcount_t ref;
 	u64 node_name;
 	u64 port_name;
 	u32 port_role;
@@ -273,7 +273,7 @@ struct fcloop_fcpreq {
 	u32				inistate;
 	bool				active;
 	bool				aborted;
-	struct kref			ref;
+	refcount_t			ref;
 	struct work_struct		fcp_rcv_work;
 	struct work_struct		abort_rcv_work;
 	struct work_struct		tio_done_work;
@@ -533,24 +533,18 @@ fcloop_tgt_discovery_evt(struct nvmet_fc_target_port *tgtport)
 }
 
 static void
-fcloop_tfcp_req_free(struct kref *ref)
+fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req)
 {
-	struct fcloop_fcpreq *tfcp_req =
-		container_of(ref, struct fcloop_fcpreq, ref);
+	if (!refcount_dec_and_test(&tfcp_req->ref))
+		return;
 
 	kfree(tfcp_req);
 }
 
-static void
-fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req)
-{
-	kref_put(&tfcp_req->ref, fcloop_tfcp_req_free);
-}
-
 static int
 fcloop_tfcp_req_get(struct fcloop_fcpreq *tfcp_req)
 {
-	return kref_get_unless_zero(&tfcp_req->ref);
+	return refcount_inc_not_zero(&tfcp_req->ref);
 }
 
 static void
@@ -747,7 +741,7 @@ fcloop_fcp_req(struct nvme_fc_local_port *localport,
 	INIT_WORK(&tfcp_req->fcp_rcv_work, fcloop_fcp_recv_work);
 	INIT_WORK(&tfcp_req->abort_rcv_work, fcloop_fcp_abort_recv_work);
 	INIT_WORK(&tfcp_req->tio_done_work, fcloop_tgt_fcprqst_done_work);
-	kref_init(&tfcp_req->ref);
+	refcount_set(&tfcp_req->ref, 1);
 
 	queue_work(nvmet_wq, &tfcp_req->fcp_rcv_work);
 
@@ -1000,12 +994,13 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport,
 }
 
 static void
-fcloop_nport_free(struct kref *ref)
+fcloop_nport_put(struct fcloop_nport *nport)
 {
-	struct fcloop_nport *nport =
-		container_of(ref, struct fcloop_nport, ref);
 	unsigned long flags;
 
+	if (!refcount_dec_and_test(&nport->ref))
+		return;
+
 	spin_lock_irqsave(&fcloop_lock, flags);
 	list_del(&nport->nport_list);
 	spin_unlock_irqrestore(&fcloop_lock, flags);
@@ -1013,16 +1008,10 @@ fcloop_nport_free(struct kref *ref)
 	kfree(nport);
 }
 
-static void
-fcloop_nport_put(struct fcloop_nport *nport)
-{
-	kref_put(&nport->ref, fcloop_nport_free);
-}
-
 static int
 fcloop_nport_get(struct fcloop_nport *nport)
 {
-	return kref_get_unless_zero(&nport->ref);
+	return refcount_inc_not_zero(&nport->ref);
 }
 
 static void
@@ -1253,7 +1242,7 @@ fcloop_alloc_nport(const char *buf, size_t count, bool remoteport)
 		newnport->port_role = opts->roles;
 	if (opts->mask & NVMF_OPT_FCADDR)
 		newnport->port_id = opts->fcaddr;
-	kref_init(&newnport->ref);
+	refcount_set(&newnport->ref, 1);
 
 	spin_lock_irqsave(&fcloop_lock, flags);
 

-- 
2.48.1


  parent reply	other threads:[~2025-03-18 10:40 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18 10:39 [PATCH v3 00/18] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-03-18 10:39 ` [PATCH v3 01/18] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-03-18 10:39 ` Daniel Wagner [this message]
2025-03-18 10:56   ` [PATCH v3 02/18] nvmet-fcloop: replace kref with refcount Hannes Reinecke
2025-04-02 14:03     ` Daniel Wagner
2025-04-02 14:06       ` Hannes Reinecke
2025-03-21  6:03   ` Christoph Hellwig
2025-03-21 14:16   ` Hannes Reinecke
2025-03-18 10:39 ` [PATCH v3 03/18] nvmet-fcloop: add ref counting to lport Daniel Wagner
2025-03-21  6:04   ` Christoph Hellwig
2025-03-18 10:39 ` [PATCH v3 04/18] nvmet-fcloop: refactor fcloop_nport_alloc Daniel Wagner
2025-03-18 11:02   ` Hannes Reinecke
2025-03-18 13:38     ` Daniel Wagner
2025-03-18 14:10       ` Hannes Reinecke
2025-03-21  6:05       ` Christoph Hellwig
2025-03-18 10:39 ` [PATCH v3 05/18] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-03-18 11:06   ` Hannes Reinecke
2025-03-18 13:44     ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 06/18] nvmet-fcloop: sync targetport removal Daniel Wagner
2025-03-18 11:07   ` Hannes Reinecke
2025-03-21  6:08   ` Christoph Hellwig
2025-04-02 16:39     ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 07/18] nvmet-fcloop: update refs on tfcp_req Daniel Wagner
2025-03-18 11:09   ` Hannes Reinecke
2025-03-21  6:08   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 08/18] nvmet-fcloop: add missing fcloop_callback_host_done Daniel Wagner
2025-03-18 11:12   ` Hannes Reinecke
2025-03-18 13:49     ` Daniel Wagner
2025-04-02 17:08       ` Daniel Wagner
2025-04-03 13:25         ` Daniel Wagner
2025-04-04  7:28           ` Daniel Wagner
2025-03-21  6:12   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 09/18] nvmet-fcloop: prevent double port deletion Daniel Wagner
2025-03-18 11:15   ` Hannes Reinecke
2025-03-18 13:55     ` Daniel Wagner
2025-03-21  6:13   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 10/18] nvmet-fcloop: allocate/free fcloop_lsreq directly Daniel Wagner
2025-03-18 11:17   ` Hannes Reinecke
2025-03-18 13:58     ` Daniel Wagner
2025-04-08 11:20       ` Daniel Wagner
2025-03-19 22:47   ` James Smart
2025-04-04 12:53     ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 11/18] nvmet-fc: inline nvmet_fc_delete_assoc Daniel Wagner
2025-03-21  6:14   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 12/18] nvmet-fc: inline nvmet_fc_free_hostport Daniel Wagner
2025-03-21  6:15   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 13/18] nvmet-fc: update tgtport ref per assoc Daniel Wagner
2025-03-21  6:15   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 14/18] nvmet-fc: take tgtport reference only once Daniel Wagner
2025-03-18 11:18   ` Hannes Reinecke
2025-03-21  6:17   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 15/18] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-03-21  6:19   ` Christoph Hellwig
2025-04-08 11:29     ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 16/18] nvmet-fc: take tgtport refs for portentry Daniel Wagner
2025-03-18 11:19   ` Hannes Reinecke
2025-03-18 10:40 ` [PATCH v3 17/18] nvmet-fc: put ref when assoc->del_work is already scheduled Daniel Wagner
2025-03-18 11:20   ` Hannes Reinecke
2025-03-21  6:19   ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 18/18] nvme-fc: do not reference lsrsp after failure Daniel Wagner
2025-03-18 11:33   ` Hannes Reinecke
2025-03-18 14:01     ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250318-nvmet-fcloop-v3-2-05fec0fc02f6@kernel.org \
    --to=wagi@kernel.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®