Skip to content

Commit e80ac6c

Browse files
Andy GroverNicholas Bellinger
Andy Grover
authored and
Nicholas Bellinger
committed
target: refactor core_update_device_list_for_node()
Code was almost entirely divided based on value of bool param "enable". Split it into two functions. Signed-off-by: Andy Grover <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent cdf88a2 commit e80ac6c

File tree

3 files changed

+103
-77
lines changed

3 files changed

+103
-77
lines changed

drivers/target/target_core_device.c

Lines changed: 95 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ int core_free_device_list_for_node(
300300
lun = deve->se_lun;
301301

302302
spin_unlock_irq(&nacl->device_list_lock);
303-
core_update_device_list_for_node(lun, NULL, deve->mapped_lun,
304-
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0);
303+
core_disable_device_list_for_node(lun, NULL, deve->mapped_lun,
304+
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg);
305305
spin_lock_irq(&nacl->device_list_lock);
306306
}
307307
spin_unlock_irq(&nacl->device_list_lock);
@@ -342,72 +342,46 @@ void core_update_device_list_access(
342342
spin_unlock_irq(&nacl->device_list_lock);
343343
}
344344

345-
/* core_update_device_list_for_node():
345+
/* core_enable_device_list_for_node():
346346
*
347347
*
348348
*/
349-
int core_update_device_list_for_node(
349+
int core_enable_device_list_for_node(
350350
struct se_lun *lun,
351351
struct se_lun_acl *lun_acl,
352352
u32 mapped_lun,
353353
u32 lun_access,
354354
struct se_node_acl *nacl,
355-
struct se_portal_group *tpg,
356-
int enable)
355+
struct se_portal_group *tpg)
357356
{
358357
struct se_port *port = lun->lun_sep;
359-
struct se_dev_entry *deve = nacl->device_list[mapped_lun];
360-
int trans = 0;
361-
/*
362-
* If the MappedLUN entry is being disabled, the entry in
363-
* port->sep_alua_list must be removed now before clearing the
364-
* struct se_dev_entry pointers below as logic in
365-
* core_alua_do_transition_tg_pt() depends on these being present.
366-
*/
367-
if (!enable) {
368-
/*
369-
* deve->se_lun_acl will be NULL for demo-mode created LUNs
370-
* that have not been explicitly concerted to MappedLUNs ->
371-
* struct se_lun_acl, but we remove deve->alua_port_list from
372-
* port->sep_alua_list. This also means that active UAs and
373-
* NodeACL context specific PR metadata for demo-mode
374-
* MappedLUN *deve will be released below..
375-
*/
376-
spin_lock_bh(&port->sep_alua_lock);
377-
list_del(&deve->alua_port_list);
378-
spin_unlock_bh(&port->sep_alua_lock);
379-
}
358+
struct se_dev_entry *deve;
380359

381360
spin_lock_irq(&nacl->device_list_lock);
382-
if (enable) {
383-
/*
384-
* Check if the call is handling demo mode -> explict LUN ACL
385-
* transition. This transition must be for the same struct se_lun
386-
* + mapped_lun that was setup in demo mode..
387-
*/
388-
if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
389-
if (deve->se_lun_acl != NULL) {
390-
pr_err("struct se_dev_entry->se_lun_acl"
391-
" already set for demo mode -> explict"
392-
" LUN ACL transition\n");
393-
spin_unlock_irq(&nacl->device_list_lock);
394-
return -EINVAL;
395-
}
396-
if (deve->se_lun != lun) {
397-
pr_err("struct se_dev_entry->se_lun does"
398-
" match passed struct se_lun for demo mode"
399-
" -> explict LUN ACL transition\n");
400-
spin_unlock_irq(&nacl->device_list_lock);
401-
return -EINVAL;
402-
}
403-
deve->se_lun_acl = lun_acl;
404-
trans = 1;
405-
} else {
406-
deve->se_lun = lun;
407-
deve->se_lun_acl = lun_acl;
408-
deve->mapped_lun = mapped_lun;
409-
deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS;
361+
362+
deve = nacl->device_list[mapped_lun];
363+
364+
/*
365+
* Check if the call is handling demo mode -> explict LUN ACL
366+
* transition. This transition must be for the same struct se_lun
367+
* + mapped_lun that was setup in demo mode..
368+
*/
369+
if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
370+
if (deve->se_lun_acl != NULL) {
371+
pr_err("struct se_dev_entry->se_lun_acl"
372+
" already set for demo mode -> explict"
373+
" LUN ACL transition\n");
374+
spin_unlock_irq(&nacl->device_list_lock);
375+
return -EINVAL;
376+
}
377+
if (deve->se_lun != lun) {
378+
pr_err("struct se_dev_entry->se_lun does"
379+
" match passed struct se_lun for demo mode"
380+
" -> explict LUN ACL transition\n");
381+
spin_unlock_irq(&nacl->device_list_lock);
382+
return -EINVAL;
410383
}
384+
deve->se_lun_acl = lun_acl;
411385

412386
if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
413387
deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
@@ -417,20 +391,70 @@ int core_update_device_list_for_node(
417391
deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
418392
}
419393

420-
if (trans) {
421-
spin_unlock_irq(&nacl->device_list_lock);
422-
return 0;
423-
}
424-
deve->creation_time = get_jiffies_64();
425-
deve->attach_count++;
426394
spin_unlock_irq(&nacl->device_list_lock);
395+
return 0;
396+
}
427397

428-
spin_lock_bh(&port->sep_alua_lock);
429-
list_add_tail(&deve->alua_port_list, &port->sep_alua_list);
430-
spin_unlock_bh(&port->sep_alua_lock);
398+
deve->se_lun = lun;
399+
deve->se_lun_acl = lun_acl;
400+
deve->mapped_lun = mapped_lun;
401+
deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS;
431402

432-
return 0;
403+
if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) {
404+
deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY;
405+
deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE;
406+
} else {
407+
deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE;
408+
deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY;
433409
}
410+
411+
deve->creation_time = get_jiffies_64();
412+
deve->attach_count++;
413+
spin_unlock_irq(&nacl->device_list_lock);
414+
415+
spin_lock_bh(&port->sep_alua_lock);
416+
list_add_tail(&deve->alua_port_list, &port->sep_alua_list);
417+
spin_unlock_bh(&port->sep_alua_lock);
418+
419+
return 0;
420+
}
421+
422+
/* core_disable_device_list_for_node():
423+
*
424+
*
425+
*/
426+
int core_disable_device_list_for_node(
427+
struct se_lun *lun,
428+
struct se_lun_acl *lun_acl,
429+
u32 mapped_lun,
430+
u32 lun_access,
431+
struct se_node_acl *nacl,
432+
struct se_portal_group *tpg)
433+
{
434+
struct se_port *port = lun->lun_sep;
435+
struct se_dev_entry *deve;
436+
437+
spin_lock_irq(&nacl->device_list_lock);
438+
439+
deve = nacl->device_list[mapped_lun];
440+
441+
/*
442+
* If the MappedLUN entry is being disabled, the entry in
443+
* port->sep_alua_list must be removed now before clearing the
444+
* struct se_dev_entry pointers below as logic in
445+
* core_alua_do_transition_tg_pt() depends on these being present.
446+
*
447+
* deve->se_lun_acl will be NULL for demo-mode created LUNs
448+
* that have not been explicitly converted to MappedLUNs ->
449+
* struct se_lun_acl, but we remove deve->alua_port_list from
450+
* port->sep_alua_list. This also means that active UAs and
451+
* NodeACL context specific PR metadata for demo-mode
452+
* MappedLUN *deve will be released below..
453+
*/
454+
spin_lock_bh(&port->sep_alua_lock);
455+
list_del(&deve->alua_port_list);
456+
spin_unlock_bh(&port->sep_alua_lock);
457+
434458
/*
435459
* Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE
436460
* PR operation to complete.
@@ -475,9 +499,9 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
475499
continue;
476500
spin_unlock_irq(&nacl->device_list_lock);
477501

478-
core_update_device_list_for_node(lun, NULL,
502+
core_disable_device_list_for_node(lun, NULL,
479503
deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS,
480-
nacl, tpg, 0);
504+
nacl, tpg);
481505

482506
spin_lock_irq(&nacl->device_list_lock);
483507
}
@@ -1469,8 +1493,8 @@ int core_dev_add_initiator_node_lun_acl(
14691493

14701494
lacl->se_lun = lun;
14711495

1472-
if (core_update_device_list_for_node(lun, lacl, lacl->mapped_lun,
1473-
lun_access, nacl, tpg, 1) < 0)
1496+
if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun,
1497+
lun_access, nacl, tpg) < 0)
14741498
return -EINVAL;
14751499

14761500
spin_lock(&lun->lun_acl_lock);
@@ -1513,8 +1537,8 @@ int core_dev_del_initiator_node_lun_acl(
15131537
smp_mb__after_atomic_dec();
15141538
spin_unlock(&lun->lun_acl_lock);
15151539

1516-
core_update_device_list_for_node(lun, NULL, lacl->mapped_lun,
1517-
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0);
1540+
core_disable_device_list_for_node(lun, NULL, lacl->mapped_lun,
1541+
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg);
15181542

15191543
lacl->se_lun = NULL;
15201544

drivers/target/target_core_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ int core_free_device_list_for_node(struct se_node_acl *,
1010
struct se_portal_group *);
1111
void core_dec_lacl_count(struct se_node_acl *, struct se_cmd *);
1212
void core_update_device_list_access(u32, u32, struct se_node_acl *);
13-
int core_update_device_list_for_node(struct se_lun *, struct se_lun_acl *,
14-
u32, u32, struct se_node_acl *, struct se_portal_group *, int);
13+
int core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
14+
u32, u32, struct se_node_acl *, struct se_portal_group *);
15+
int core_disable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
16+
u32, u32, struct se_node_acl *, struct se_portal_group *);
1517
void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *);
1618
int core_dev_export(struct se_device *, struct se_portal_group *,
1719
struct se_lun *);

drivers/target/target_core_tpg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ static void core_clear_initiator_node_from_tpg(
7777

7878
lun = deve->se_lun;
7979
spin_unlock_irq(&nacl->device_list_lock);
80-
core_update_device_list_for_node(lun, NULL, deve->mapped_lun,
81-
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0);
80+
core_disable_device_list_for_node(lun, NULL, deve->mapped_lun,
81+
TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg);
8282

8383
spin_lock_irq(&nacl->device_list_lock);
8484
}
@@ -172,8 +172,8 @@ void core_tpg_add_node_to_devs(
172172
(lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ?
173173
"READ-WRITE" : "READ-ONLY");
174174

175-
core_update_device_list_for_node(lun, NULL, lun->unpacked_lun,
176-
lun_access, acl, tpg, 1);
175+
core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun,
176+
lun_access, acl, tpg);
177177
spin_lock(&tpg->tpg_lun_lock);
178178
}
179179
spin_unlock(&tpg->tpg_lun_lock);

0 commit comments

Comments
 (0)