Skip to contentSkip to conversation

target/tcm_fc: Misc. fixups

PATCH Applied Andy Grover 3 participants 7 messages Apr 4, 2014 – Apr 6, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover target/tcm_fc: Misc. fixups

Hi nab and fcoe developers,

In fixing the other issue I just posted a patch for, I found some other things in the tcm_fc fabric that could be improved. Please take a look?

Thanks! -- Regards -- Andy

Andy Grover (5):
target/tcm_fc: Don't export ft_lport_list target/tcm_fc: Limit to 1 TPG per wwn target/tcm_fc: Rename structs and list members for clarity target/tcm_fc: Rename ft_{add,del}_lport to {add,del}_wwn target/tcm_fc: Rename ft_tport_create to ft_tport_get

 drivers/target/tcm_fc/tcm_fc.h   | 12 +++----
 drivers/target/tcm_fc/tfc_conf.c | 75 ++++++++++++++++++++--------------------
 drivers/target/tcm_fc/tfc_sess.c |  6 ++--
 3 files changed, 46 insertions(+), 47 deletions(-)
Signature · 1 line
1.9.0

A message that is not in the archive (sent off-list or not yet received): 1396655655-31060-1-git-send-email-agrover-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/5 target/tcm_fc: Don't export ft_lport_list

Nobody outside tfc_conf.c uses it.

---
 drivers/target/tcm_fc/tcm_fc.h   | 1 -
 drivers/target/tcm_fc/tfc_conf.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/target/tcm_fc/tcm_fc.h +0 -1
index 4f4b971..aba6861 100644
@@ -128,7 +128,6 @@ struct ft_cmd {
 	u32 sg_cnt;			/* No. of item in scatterlist */
 };
 
-extern struct list_head ft_lport_list;
 extern struct mutex ft_lport_lock;
 extern struct fc4_prov ft_prov;
 extern struct target_fabric_configfs *ft_configfs;
drivers/target/tcm_fc/tfc_conf.c +1 -1
index b8b5a71..9c2da1f 100644
@@ -50,7 +50,7 @@
 
 struct target_fabric_configfs *ft_configfs;
 
-LIST_HEAD(ft_lport_list);
+static LIST_HEAD(ft_lport_list);
 DEFINE_MUTEX(ft_lport_lock);
 
 unsigned int ft_debug_logging;
Signature · 1 line
1.9.0
#3 lore raw

PATCH 2/5 target/tcm_fc: Limit to 1 TPG per wwn

In reply to a message not in the archive

tcm_fc doesn't support multiple TPGs per wwn. For proof, see ft_lport_find_tpg. Enforce this in the code.

Replace ft_lport_wwn.tpg_list with a single pointer. We can't fold ft_tpg into ft_lport_wwn because they can have different lifetimes.

---
 drivers/target/tcm_fc/tcm_fc.h   |  3 +--
 drivers/target/tcm_fc/tfc_conf.c | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 11 deletions(-)
drivers/target/tcm_fc/tcm_fc.h +1 -2
index aba6861..7290f8f 100644
@@ -96,7 +96,6 @@ struct ft_tpg {
 	u32 index;
 	struct ft_lport_acl *lport_acl;
 	struct ft_tport *tport;		/* active tport or NULL */
-	struct list_head list;		/* linkage in ft_lport_acl tpg_list */
 	struct list_head lun_list;	/* head of LUNs */
 	struct se_portal_group se_tpg;
 	struct workqueue_struct *workqueue;
@@ -105,8 +104,8 @@ struct ft_tpg {
 struct ft_lport_acl {
 	u64 wwpn;
 	char name[FT_NAMELEN];
+	struct ft_tpg *tpg;
 	struct list_head list;
-	struct list_head tpg_list;
 	struct se_wwn fc_lport_wwn;
 };
 
drivers/target/tcm_fc/tfc_conf.c +11 -9
index 9c2da1f..ccfa328 100644
@@ -318,6 +318,11 @@ static struct se_portal_group *ft_add_tpg(
 	if (index > UINT_MAX)
 		return NULL;
 
+	if ((index != 1)) {
+		pr_err("Error, a single TPG=1 is used for HW port mappings\n");
+		return ERR_PTR(-ENOSYS);
+	}
+
 	lacl = container_of(wwn, struct ft_lport_acl, fc_lport_wwn);
 	tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
 	if (!tpg)
@@ -342,7 +347,7 @@ static struct se_portal_group *ft_add_tpg(
 	tpg->workqueue = wq;
 
 	mutex_lock(&ft_lport_lock);
-	list_add_tail(&tpg->list, &lacl->tpg_list);
+	lacl->tpg = tpg;
 	mutex_unlock(&ft_lport_lock);
 
 	return &tpg->se_tpg;
@@ -351,6 +356,7 @@ static struct se_portal_group *ft_add_tpg(
 static void ft_del_tpg(struct se_portal_group *se_tpg)
 {
 	struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
+	struct ft_lport_acl *lacl = tpg->lport_acl;
 
 	pr_debug("del tpg %s\n",
 		    config_item_name(&tpg->se_tpg.tpg_group.cg_item));
@@ -361,7 +367,8 @@ static void ft_del_tpg(struct se_portal_group *se_tpg)
 	synchronize_rcu();
 
 	mutex_lock(&ft_lport_lock);
-	list_del(&tpg->list);
+	lacl->tpg = NULL;
+
 	if (tpg->tport) {
 		tpg->tport->tpg = NULL;
 		tpg->tport = NULL;
@@ -381,14 +388,10 @@ static void ft_del_tpg(struct se_portal_group *se_tpg)
 struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
 {
 	struct ft_lport_acl *lacl;
-	struct ft_tpg *tpg;
 
 	list_for_each_entry(lacl, &ft_lport_list, list) {
-		if (lacl->wwpn == lport->wwpn) {
-			list_for_each_entry(tpg, &lacl->tpg_list, list)
-				return tpg; /* XXX for now return first entry */
-			return NULL;
-		}
+		if (lacl->wwpn == lport->wwpn)
+			return lacl->tpg;
 	}
 	return NULL;
 }
@@ -417,7 +420,6 @@ static struct se_wwn *ft_add_lport(
 	if (!lacl)
 		return NULL;
 	lacl->wwpn = wwpn;
-	INIT_LIST_HEAD(&lacl->tpg_list);
 
 	mutex_lock(&ft_lport_lock);
 	list_for_each_entry(old_lacl, &ft_lport_list, list) {
Signature · 1 line
1.9.0
#4 lore raw

PATCH 3/5 target/tcm_fc: Rename structs and list members for clarity

In reply to a message not in the archive

Rename struct ft_lport_acl to ft_lport_wwn. "acl" is associated with something different in LIO terms. Really, ft_lport_wwn is the fabric-specific wrapper for the struct se_wwn.

Rename "lacl" local variables to "ft_wwn" as well.

Rename list_heads used as list members to make it clear they're nodes, not heads.

Rename lport_node to ft_wwn_node.

Rename ft_lport_list to ft_wwn_list

---
 drivers/target/tcm_fc/tcm_fc.h   |  8 +++---
 drivers/target/tcm_fc/tfc_conf.c | 57 ++++++++++++++++++++--------------------
 2 files changed, 32 insertions(+), 33 deletions(-)
drivers/target/tcm_fc/tcm_fc.h +4 -4
index 7290f8f..a0bcfd3 100644
@@ -94,19 +94,19 @@ struct ft_lun {
  */
 struct ft_tpg {
 	u32 index;
-	struct ft_lport_acl *lport_acl;
+	struct ft_lport_wwn *lport_wwn;
 	struct ft_tport *tport;		/* active tport or NULL */
 	struct list_head lun_list;	/* head of LUNs */
 	struct se_portal_group se_tpg;
 	struct workqueue_struct *workqueue;
 };
 
-struct ft_lport_acl {
+struct ft_lport_wwn {
 	u64 wwpn;
 	char name[FT_NAMELEN];
+	struct list_head ft_wwn_node;
 	struct ft_tpg *tpg;
-	struct list_head list;
-	struct se_wwn fc_lport_wwn;
+	struct se_wwn se_wwn;
 };
 
 /*
drivers/target/tcm_fc/tfc_conf.c +28 -29

138 lines not on this page · raw message

Signature · 1 line
1.9.0
#5 lore raw

PATCH 4/5 target/tcm_fc: Rename ft_{add, del}_lport to {add, del}_wwn

In reply to a message not in the archive

These functions are not adding or deleting an lport. They are adding a wwn that may match with an lport that is present on the system.

Renaming ft_del_lport also means we won't have functions named both ft_del_lport and ft_lport_del any more.

---
 drivers/target/tcm_fc/tfc_conf.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/target/tcm_fc/tfc_conf.c +6 -6
index bd7d544..efdcb96 100644
@@ -403,7 +403,7 @@ struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
  * Add lport to allowed config.
  * The name is the WWPN in lower-case ASCII, colon-separated bytes.
  */
-static struct se_wwn *ft_add_lport(
+static struct se_wwn *ft_add_wwn(
 	struct target_fabric_configfs *tf,
 	struct config_group *group,
 	const char *name)
@@ -412,7 +412,7 @@ static struct se_wwn *ft_add_lport(
 	struct ft_lport_wwn *old_ft_wwn;
 	u64 wwpn;
 
-	pr_debug("add lport %s\n", name);
+	pr_debug("add wwn %s\n", name);
 	if (ft_parse_wwn(name, &wwpn, 1) < 0)
 		return NULL;
 	ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL);
@@ -435,12 +435,12 @@ static struct se_wwn *ft_add_lport(
 	return &ft_wwn->se_wwn;
 }
 
-static void ft_del_lport(struct se_wwn *wwn)
+static void ft_del_wwn(struct se_wwn *wwn)
 {
 	struct ft_lport_wwn *ft_wwn = container_of(wwn,
 				struct ft_lport_wwn, se_wwn);
 
-	pr_debug("del lport %s\n", ft_wwn->name);
+	pr_debug("del wwn %s\n", ft_wwn->name);
 	mutex_lock(&ft_lport_lock);
 	list_del(&ft_wwn->ft_wwn_node);
 	mutex_unlock(&ft_lport_lock);
@@ -542,8 +542,8 @@ static struct target_core_fabric_ops ft_fabric_ops = {
 	 * Setup function pointers for generic logic in
 	 * target_core_fabric_configfs.c
 	 */
-	.fabric_make_wwn =		&ft_add_lport,
-	.fabric_drop_wwn =		&ft_del_lport,
+	.fabric_make_wwn =		&ft_add_wwn,
+	.fabric_drop_wwn =		&ft_del_wwn,
 	.fabric_make_tpg =		&ft_add_tpg,
 	.fabric_drop_tpg =		&ft_del_tpg,
 	.fabric_post_link =		NULL,
Signature · 1 line
1.9.0
#6 lore raw

PATCH 5/5 target/tcm_fc: Rename ft_tport_create to ft_tport_get

In reply to a message not in the archive

Because it doesn't always create, if there's an existing one it just returns it.

---
 drivers/target/tcm_fc/tfc_sess.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/target/tcm_fc/tfc_sess.c +3 -3
index 0475142..746adb8 100644
@@ -51,7 +51,7 @@ static void ft_sess_delete_all(struct ft_tport *);
  * Lookup or allocate target local port.
  * Caller holds ft_lport_lock.
  */
-static struct ft_tport *ft_tport_create(struct fc_lport *lport)
+static struct ft_tport *ft_tport_get(struct fc_lport *lport)
 {
 	struct ft_tpg *tpg;
 	struct ft_tport *tport;
@@ -114,7 +114,7 @@ static void ft_tport_delete(struct ft_tport *tport)
 void ft_lport_add(struct fc_lport *lport, void *arg)
 {
 	mutex_lock(&ft_lport_lock);
-	ft_tport_create(lport);
+	ft_tport_get(lport);
 	mutex_unlock(&ft_lport_lock);
 }
 
@@ -351,7 +351,7 @@ static int ft_prli_locked(struct fc_rport_priv *rdata, u32 spp_len,
 	struct ft_node_acl *acl;
 	u32 fcp_parm;
 
-	tport = ft_tport_create(rdata->local_port);
+	tport = ft_tport_get(rdata->local_port);
 	if (!tport)
 		goto not_target;	/* not a target for this local port */
 
Signature · 1 line
1.9.0
#7 lore raw
In reply to a message not in the archive
Quoted 14 lines · Andy Grover

Hi nab and fcoe developers,

In fixing the other issue I just posted a patch for, I found some other things in the tcm_fc fabric that could be improved. Please take a look?

Thanks! -- Regards -- Andy

Andy Grover (5):
target/tcm_fc: Don't export ft_lport_list target/tcm_fc: Limit to 1 TPG per wwn target/tcm_fc: Rename structs and list members for clarity target/tcm_fc: Rename ft_{add,del}_lport to {add,del}_wwn target/tcm_fc: Rename ft_tport_create to ft_tport_get

Quoted 5 lines
 drivers/target/tcm_fc/tcm_fc.h   | 12 +++----
 drivers/target/tcm_fc/tfc_conf.c | 75 ++++++++++++++++++++--------------------
 drivers/target/tcm_fc/tfc_sess.c |  6 ++--
 3 files changed, 46 insertions(+), 47 deletions(-)

These all look reasonable.

Applied to target-pending/for-next.

--nab