target: Simplify lu_gp handling code
Subsystems (2)
cover target: Simplify lu_gp handling code
This set changes the behavior added here:
https://lkml.org/lkml/2009/2/12/22
We can simplify code paths dealing with lu_gp if we just have to handle (default_lu_gp vs explicit lu_gp), instead of (default_lu_gp vs explicit lu_gp vs NULL). The only consequence would be that showing logical unit group identifier (target_core_spc.c:358) in vpd83 info couldn't be disabled, and there didn't seem to be a reason I could come up with for why anyone would ever want to disable it - if you don't care, just don't look at it.
Andy Grover (2):
target: Ensure lu_gp_mem->lu_gp is never NULL
target: Simplify target_core_store_alua_lu_gp
drivers/target/target_core_alua.c | 6 ++--- drivers/target/target_core_configfs.c | 47 +++++++++++------------------------ 2 files changed, 16 insertions(+), 37 deletions(-)
Signature · 1 line
1.8.5.3
PATCH 1/2 target: Ensure lu_gp_mem->lu_gp is never NULL
->lu_gp should never be NULL, because if lu_gp_mem is not in an explicit group, it should be in default_lu_gp. Change target_core_store_alua_lu_gp to make this so.
Also, fix a typo in a comment in that function.
Finally, in core_alua_free_lu_gp, explicitly leave the old group before joining default_lu_gp, allowing simpler logic.
--- drivers/target/target_core_alua.c | 6 ++---- drivers/target/target_core_configfs.c | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/target/target_core_alua.c +2 -4
@@ -1599,11 +1599,9 @@ void core_alua_free_lu_gp(struct t10_alua_lu_gp *lu_gp)* we want to re-associate a given lu_gp_mem with default_lu_gp. */ spin_lock (&lu_gp_mem->lu_gp_mem_lock); +__core_alua_drop_lu_gp_mem (lu_gp_mem, lu_gp);if (lu_gp != default_lu_gp) -__core_alua_attach_lu_gp_mem (lu_gp_mem, - default_lu_gp); -else - lu_gp_mem->lu_gp =NULL ; +__core_alua_attach_lu_gp_mem (lu_gp_mem, default_lu_gp);spin_unlock (&lu_gp_mem->lu_gp_mem_lock);spin_lock (&lu_gp->lu_gp_lock);
drivers/target/target_core_configfs.c +2 -1
@@ -1693,7 +1693,7 @@ static ssize_t target_core_store_alua_lu_gp(/* * core_alua_get_lu_gp_by_name() will increment reference to * struct t10_alua_lu_gp. This reference is released with -* core_alua_get_lu_gp_by_name below(). +* core_alua_put_lu_gp_from_name() below. */ lu_gp_new =core_alua_get_lu_gp_by_name (strstrip (buf));if (!lu_gp_new)
@@ -1717,6 +1717,7 @@ static ssize_t target_core_store_alua_lu_gp( lu_gp->lu_gp_id);__core_alua_drop_lu_gp_mem (lu_gp_mem, lu_gp); +__core_alua_attach_lu_gp_mem (lu_gp_mem, default_lu_gp);spin_unlock (&lu_gp_mem->lu_gp_mem_lock);return count;
Signature · 1 line
1.8.5.3
PATCH 2/2 target: Simplify target_core_store_alua_lu_gp
In reply to Andy GroverIf we know that lu_gp_mem->lu_gp will never be NULL, and "NULL" means "set back to default_lu_gp" instead of really set to NULL (not allowed), then we can simplify this function by not special-casing the !lu_gp_new case, and setting lu_gp_new to default_lu_gp at the top.
--- drivers/target/target_core_configfs.c | 46 ++++++++++------------------------- 1 file changed, 13 insertions(+), 33 deletions(-)
drivers/target/target_core_configfs.c +13 -33
@@ -1673,7 +1673,6 @@ static ssize_t target_core_store_alua_lu_gp(struct t10_alua_lu_gp *lu_gp =NULL , *lu_gp_new =NULL ;struct t10_alua_lu_gp_member *lu_gp_mem;unsigned char buf[LU_GROUP_NAME_BUF ]; -int move =0 ; lu_gp_mem = dev->dev_alua_lu_gp_mem;if (!lu_gp_mem)
@@ -1689,7 +1688,13 @@ static ssize_t target_core_store_alua_lu_gp(* Any ALUA logical unit alias besides "NULL" means we will be * making a new group association. */ -if (strcmp (strstrip (buf),"NULL" )) { +if (!strcmp (strstrip (buf),"NULL" )) { +/* +* Clearing an existing lu_gp association, and going back to +* the default group. +*/ + lu_gp_new = default_lu_gp; + }else {/* * core_alua_get_lu_gp_by_name() will increment reference to * struct t10_alua_lu_gp. This reference is released with
@@ -1701,48 +1706,23 @@ static ssize_t target_core_store_alua_lu_gp( }spin_lock (&lu_gp_mem->lu_gp_mem_lock); + lu_gp = lu_gp_mem->lu_gp; -if (lu_gp) { -/* -* Clearing an existing lu_gp association, and replacing -* with NULL -*/ -if (!lu_gp_new) { -pr_debug ("Target_Core_ConfigFS: Releasing %s/%s" -" from ALUA LU Group: core/alua/lu_gps/%s, ID:" -" %hu\n" , -config_item_name (&hba->hba_group.cg_item), -config_item_name (&dev->dev_group.cg_item), -config_item_name (&lu_gp->lu_gp_group.cg_item), - lu_gp->lu_gp_id); - -__core_alua_drop_lu_gp_mem (lu_gp_mem, lu_gp); -__core_alua_attach_lu_gp_mem (lu_gp_mem, default_lu_gp); -spin_unlock (&lu_gp_mem->lu_gp_mem_lock); - -return count; - } -/* -* Removing existing association of lu_gp_mem with lu_gp -*/ -__core_alua_drop_lu_gp_mem (lu_gp_mem, lu_gp); - move =1 ; - } -/* -* Associate lu_gp_mem with lu_gp_new. -*/ +__core_alua_drop_lu_gp_mem (lu_gp_mem, lu_gp);__core_alua_attach_lu_gp_mem (lu_gp_mem, lu_gp_new); +spin_unlock (&lu_gp_mem->lu_gp_mem_lock);pr_debug ("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" " core/alua/lu_gps/%s, ID: %hu\n" , - (move) ?"Moving" :"Adding" , + (lu_gp != default_lu_gp) ?"Moving" :"Adding" ,config_item_name (&hba->hba_group.cg_item),config_item_name (&dev->dev_group.cg_item),config_item_name (&lu_gp_new->lu_gp_group.cg_item), lu_gp_new->lu_gp_id); -core_alua_put_lu_gp_from_name (lu_gp_new); +if (lu_gp_new != default_lu_gp) +core_alua_put_lu_gp_from_name (lu_gp_new);return count; }
Signature · 1 line
1.8.5.3