From: Hannes Reinecke <hare@suse.de>
To: Daniel Wagner <wagi@kernel.org>,
James Smart <james.smart@broadcom.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 04/11] nvmet-fcloop: track ref counts for nports
Date: Fri, 28 Feb 2025 08:19:19 +0100 [thread overview]
Message-ID: <d4b09a75-30f8-4db7-a02b-25ae405f7340@suse.de> (raw)
In-Reply-To: <20250226-nvmet-fcloop-v1-4-c0bd83d43e6a@kernel.org>
On 2/26/25 19:45, Daniel Wagner wrote:
> A nport object is always used in association with targerport,
> remoteport, tport and rport objects. Add explicit references for any of
> the associated object. This makes the unreliable reference updates in
> the two callback fcloop_targetport_delete and fcloop_remoteport_delete
> obsolete.
>
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
> drivers/nvme/target/fcloop.c | 57 +++++++++++++++++++++++++++++++++++---------
> 1 file changed, 46 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
> index de1963c34bd88d0335f70de569565740fd395a0a..80693705c069dd114b2d4f15d0482dd2d713a273 100644
> --- a/drivers/nvme/target/fcloop.c
> +++ b/drivers/nvme/target/fcloop.c
> @@ -1071,16 +1071,11 @@ fcloop_remoteport_delete(struct nvme_fc_remote_port *remoteport)
> struct fcloop_rport *rport = remoteport->private;
>
> flush_work(&rport->ls_work);
> - fcloop_nport_put(rport->nport);
> }
>
> static void
> fcloop_targetport_delete(struct nvmet_fc_target_port *targetport)
> {
> - struct fcloop_tport *tport = targetport->private;
> -
> - flush_work(&tport->ls_work);
> - fcloop_nport_put(tport->nport);
> }
>
Errm. Isn't this function empty now? Can't it be remove altogether?
> #define FCLOOP_HW_QUEUES 4
> @@ -1358,6 +1353,7 @@ fcloop_create_remote_port(struct device *dev, struct device_attribute *attr,
> struct nvme_fc_port_info pinfo;
> int ret;
>
> + /* nport ref get: rport */
> nport = fcloop_alloc_nport(buf, count, true);
> if (!nport)
> return -EIO;
> @@ -1375,6 +1371,9 @@ fcloop_create_remote_port(struct device *dev, struct device_attribute *attr,
> return ret;
> }
>
> + /* nport ref get: remoteport */
> + fcloop_nport_get(nport);
> +
> /* success */
> rport = remoteport->private;
> rport->remoteport = remoteport;
> @@ -1403,16 +1402,27 @@ __unlink_remote_port(struct fcloop_nport *nport)
> nport->tport->remoteport = NULL;
> nport->rport = NULL;
>
> + /* nport ref put: rport */
> + fcloop_nport_put(nport);
> +
> return rport;
> }
>
> static int
> __remoteport_unreg(struct fcloop_nport *nport, struct fcloop_rport *rport)
> {
> - if (!rport)
> - return -EALREADY;
> + int ret;
>
> - return nvme_fc_unregister_remoteport(rport->remoteport);
> + if (!rport) {
> + ret = -EALREADY;
> + goto out;
> + }
> +
> + ret = nvme_fc_unregister_remoteport(rport->remoteport);
> +out:
> + /* nport ref put: remoteport */
> + fcloop_nport_put(nport);
> + return ret;
> }
>
> static ssize_t
> @@ -1434,6 +1444,9 @@ fcloop_delete_remote_port(struct device *dev, struct device_attribute *attr,
> list_for_each_entry(tmpport, &fcloop_nports, nport_list) {
> if (tmpport->node_name == nodename &&
> tmpport->port_name == portname && tmpport->rport) {
> +
> + if (!fcloop_nport_get(tmpport))
> + break;
> nport = tmpport;
> rport = __unlink_remote_port(nport);
> break;
> @@ -1447,6 +1460,8 @@ fcloop_delete_remote_port(struct device *dev, struct device_attribute *attr,
>
> ret = __remoteport_unreg(nport, rport);
>
> + fcloop_nport_put(nport);
> +
> return ret ? ret : count;
> }
>
> @@ -1460,6 +1475,7 @@ fcloop_create_target_port(struct device *dev, struct device_attribute *attr,
> struct nvmet_fc_port_info tinfo;
> int ret;
>
> + /* nport ref get: tport */
> nport = fcloop_alloc_nport(buf, count, false);
> if (!nport)
> return -EIO;
> @@ -1475,6 +1491,9 @@ fcloop_create_target_port(struct device *dev, struct device_attribute *attr,
> return ret;
> }
>
> + /* nport ref get: targetport */
> + fcloop_nport_get(nport);
> +
I would rather move it to the end of the function, after we set all the
references. But that's probably personal style...
> /* success */
> tport = targetport->private;
> tport->targetport = targetport;
> @@ -1501,16 +1520,27 @@ __unlink_target_port(struct fcloop_nport *nport)
> nport->rport->targetport = NULL;
> nport->tport = NULL;
>
> + /* nport ref put: tport */
> + fcloop_nport_put(nport);
> +
> return tport;
> }
>
> static int
> __targetport_unreg(struct fcloop_nport *nport, struct fcloop_tport *tport)
> {
> - if (!tport)
> - return -EALREADY;
> + int ret;
That's iffy.
Q1: How can you end up with a NULL tport?
Q2: Why do we have _two_ arguments? Can't we use 'nport->tport'?
Q3: What do you do when tport is valid and tport != nport->tport?
>
> - return nvmet_fc_unregister_targetport(tport->targetport);
> + if (!tport) {
> + ret = -EALREADY;
> + goto out;
> + }
> +
> + ret = nvmet_fc_unregister_targetport(tport->targetport);
> +out:
> + /* nport ref put: targetport */
> + fcloop_nport_put(nport);
> + return ret;
> }
>
> static ssize_t
> @@ -1532,6 +1562,9 @@ fcloop_delete_target_port(struct device *dev, struct device_attribute *attr,
> list_for_each_entry(tmpport, &fcloop_nports, nport_list) {
> if (tmpport->node_name == nodename &&
> tmpport->port_name == portname && tmpport->tport) {
> +
> + if (!fcloop_nport_get(tmpport))
> + break;
> nport = tmpport;
> tport = __unlink_target_port(nport);
> break;
> @@ -1545,6 +1578,8 @@ fcloop_delete_target_port(struct device *dev, struct device_attribute *attr,
>
> ret = __targetport_unreg(nport, tport);
>
> + fcloop_nport_put(nport);
> +
> return ret ? ret : count;
> }
>
>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
next prev parent reply other threads:[~2025-02-28 7:19 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 18:45 [PATCH 00/11] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-02-26 18:45 ` [PATCH 01/11] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-02-28 7:04 ` Hannes Reinecke
2025-03-05 14:16 ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 02/11] nvmet-fcloop: add ref counting to lport Daniel Wagner
2025-02-28 7:05 ` Hannes Reinecke
2025-03-05 14:17 ` Christoph Hellwig
2025-03-06 9:26 ` Daniel Wagner
2025-03-06 10:06 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 03/11] nvmet-fcloop: refactor fcloop_nport_alloc Daniel Wagner
2025-02-28 7:11 ` Hannes Reinecke
2025-02-28 7:56 ` Daniel Wagner
2025-03-05 14:18 ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 04/11] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-02-28 7:19 ` Hannes Reinecke [this message]
2025-02-28 8:09 ` Daniel Wagner
2025-02-28 8:18 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 05/11] nvmet-fcloop: track tport with ref counting Daniel Wagner
2025-02-28 7:27 ` Hannes Reinecke
2025-02-28 8:30 ` Daniel Wagner
2025-02-28 14:31 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 06/11] nvmet-fcloop: track rport " Daniel Wagner
2025-02-28 7:29 ` Hannes Reinecke
2025-02-26 18:45 ` [PATCH 07/11] nvmet-fc: update tgtport ref per assoc Daniel Wagner
2025-02-28 7:30 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 08/11] nvmet-fc: take tgtport reference only once Daniel Wagner
2025-02-28 7:34 ` Hannes Reinecke
2025-02-28 8:45 ` Daniel Wagner
2025-02-26 18:46 ` [PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-02-28 7:35 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 10/11] nvmet-fc: inline nvmet_fc_delete_assoc Daniel Wagner
2025-02-28 7:36 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 11/11] nvmet-fc: inline nvmet_fc_free_hostport Daniel Wagner
2025-02-28 7:37 ` Hannes Reinecke
2025-02-27 16:30 ` [PATCH 00/11] nvmet-fcloop: track resources via reference counting 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=d4b09a75-30f8-4db7-a02b-25ae405f7340@suse.de \
--to=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 \
--cc=wagi@kernel.org \
/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®