Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>,
	linux-nvme@lists.infradead.org, Sagi Grimberg <sagi@grimberg.me>,
	Keith Busch <keith.busch@wdc.com>,
	James Smart <james.smart@broadcom.com>
Subject: [PATCH 7/7] nvme-fcloop: use a device for lport
Date: Tue, 22 Sep 2020 14:15:01 +0200	[thread overview]
Message-ID: <20200922121501.32851-8-hare@suse.de> (raw)
In-Reply-To: <20200922121501.32851-1-hare@suse.de>

Add a 'struct device' to the lport such that the lport will show
up in sysfs and we get a valid name in the logging output.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/target/fcloop.c | 53 ++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 14 deletions(-)

diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
index b84f8754b3a3..1af1917ddf4c 100644
--- a/drivers/nvme/target/fcloop.c
+++ b/drivers/nvme/target/fcloop.c
@@ -214,6 +214,7 @@ static LIST_HEAD(fcloop_nports);
 static DEFINE_IDA(fcloop_portid_ida);
 
 struct fcloop_lport {
+	struct device dev;
 	struct nvme_fc_local_port *localport;
 	struct list_head lport_list;
 	struct completion unreg_done;
@@ -1053,6 +1054,16 @@ static struct nvmet_fc_target_template tgttemplate = {
 	.lsrqst_priv_sz		= sizeof(struct fcloop_lsreq),
 };
 
+static void fcloop_release_lport(struct device *dev)
+{
+	struct fcloop_lport *lport =
+		container_of(dev, struct fcloop_lport, dev);
+
+	ida_free(&fcloop_portid_ida, lport->port_id);
+
+	kfree(lport);
+}
+
 static ssize_t
 fcloop_create_local_port(struct device *dev, struct device_attribute *attr,
 		const char *buf, size_t count)
@@ -1063,7 +1074,7 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr,
 	struct fcloop_lport *lport;
 	struct fcloop_lport_priv *lport_priv;
 	unsigned long flags;
-	int ret = -ENOMEM, port_id;
+	int ret = -ENOMEM, port_id, port_num;
 
 	lport = kzalloc(sizeof(*lport), GFP_KERNEL);
 	if (!lport)
@@ -1094,25 +1105,39 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr,
 		goto out_free_ida;
 	}
 
+	lport->port_id = port_id;
+	lport->dev.class = fcloop_class;
+	lport->dev.release = fcloop_release_lport;
+	dev_set_name(&lport->dev, "lport%d", lport->port_id);
+	device_initialize(&lport->dev);
+
 	memset(&pinfo, 0, sizeof(pinfo));
 	pinfo.node_name = opts->wwnn;
 	pinfo.port_name = opts->wwpn;
 	pinfo.port_role = opts->roles;
 	pinfo.port_id = port_id;
 
-	ret = nvme_fc_register_localport(&pinfo, &fctemplate, NULL, &localport);
-	if (!ret) {
-		/* success */
-		lport_priv = localport->private;
-		lport_priv->lport = lport;
+	ret = nvme_fc_register_localport(&pinfo, &fctemplate,
+					 &lport->dev, &localport);
+	if (ret)
+		goto out_free_ida;
 
-		lport->localport = localport;
-		INIT_LIST_HEAD(&lport->lport_list);
+	/* success */
+	lport_priv = localport->private;
+	lport_priv->lport = lport;
 
-		spin_lock_irqsave(&fcloop_lock, flags);
-		list_add_tail(&lport->lport_list, &fcloop_lports);
-		spin_unlock_irqrestore(&fcloop_lock, flags);
+	lport->localport = localport;
+	INIT_LIST_HEAD(&lport->lport_list);
+
+	ret = device_add(&lport->dev);
+	if (ret) {
+		nvme_fc_unregister_localport(lport->localport);
+		goto out_free_ida;
 	}
+	spin_lock_irqsave(&fcloop_lock, flags);
+	list_add_tail(&lport->lport_list, &fcloop_lports);
+	spin_unlock_irqrestore(&fcloop_lock, flags);
+
 out_free_ida:
 	if (ret)
 		ida_free(&fcloop_portid_ida, port_id);
@@ -1138,15 +1163,15 @@ __wait_localport_unreg(struct fcloop_lport *lport)
 {
 	int ret;
 
+	device_del(&lport->dev);
+
 	init_completion(&lport->unreg_done);
 
 	ret = nvme_fc_unregister_localport(lport->localport);
 
 	wait_for_completion(&lport->unreg_done);
 
-	ida_free(&fcloop_portid_ida, lport->port_id);
-
-	kfree(lport);
+	put_device(&lport->dev);
 
 	return ret;
 }
-- 
2.16.4


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2020-09-22 12:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 12:14 [PATCH 0/7] nvme-fcloop: fix shutdown and improve logging Hannes Reinecke
2020-09-22 12:14 ` [PATCH 1/7] nvme-fcloop: flush workqueue before calling nvme_fc_unregister_remoteport() Hannes Reinecke
2020-10-05 17:14   ` James Smart
2020-09-22 12:14 ` [PATCH 2/7] nvmet-fc: use per-target workqueue when removing associations Hannes Reinecke
2020-10-05 17:18   ` James Smart
2020-09-22 12:14 ` [PATCH 3/7] nvme-fcloop: use IDA for port ids Hannes Reinecke
2020-10-05 17:33   ` James Smart
2020-10-09 13:57     ` Hannes Reinecke
2020-09-22 12:14 ` [PATCH 4/7] nvmet-fc: use feature flag for virtual LLDD Hannes Reinecke
2020-10-05 17:37   ` James Smart
2020-09-22 12:14 ` [PATCH 5/7] nvme-fc: " Hannes Reinecke
2020-10-05 17:38   ` James Smart
2020-09-22 12:15 ` [PATCH 6/7] nvme-fcloop: use a device for nport Hannes Reinecke
2020-10-05 17:41   ` James Smart
2020-09-22 12:15 ` Hannes Reinecke [this message]
2020-10-05 17:45   ` [PATCH 7/7] nvme-fcloop: use a device for lport James Smart

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=20200922121501.32851-8-hare@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=keith.busch@wdc.com \
    --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