diff options
author | Andy Grover <agrover@redhat.com> | 2012-07-12 20:34:58 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-07-16 20:35:24 -0400 |
commit | e80ac6c4cc073d54daef8ba4ced88347d130d314 (patch) | |
tree | dfa41df2e34fc759e3b9c1b47efec0fdc73799c3 /drivers/target | |
parent | cdf88a2fe3825458c584cd751aa843ab3af6a42c (diff) |
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 <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/target_core_device.c | 166 | ||||
-rw-r--r-- | drivers/target/target_core_internal.h | 6 | ||||
-rw-r--r-- | drivers/target/target_core_tpg.c | 8 |
3 files changed, 103 insertions, 77 deletions
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 415c71ecdff0..0a1c907a531b 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c | |||
@@ -300,8 +300,8 @@ int core_free_device_list_for_node( | |||
300 | lun = deve->se_lun; | 300 | lun = deve->se_lun; |
301 | 301 | ||
302 | spin_unlock_irq(&nacl->device_list_lock); | 302 | spin_unlock_irq(&nacl->device_list_lock); |
303 | core_update_device_list_for_node(lun, NULL, deve->mapped_lun, | 303 | core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, |
304 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); | 304 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); |
305 | spin_lock_irq(&nacl->device_list_lock); | 305 | spin_lock_irq(&nacl->device_list_lock); |
306 | } | 306 | } |
307 | spin_unlock_irq(&nacl->device_list_lock); | 307 | spin_unlock_irq(&nacl->device_list_lock); |
@@ -342,72 +342,46 @@ void core_update_device_list_access( | |||
342 | spin_unlock_irq(&nacl->device_list_lock); | 342 | spin_unlock_irq(&nacl->device_list_lock); |
343 | } | 343 | } |
344 | 344 | ||
345 | /* core_update_device_list_for_node(): | 345 | /* core_enable_device_list_for_node(): |
346 | * | 346 | * |
347 | * | 347 | * |
348 | */ | 348 | */ |
349 | int core_update_device_list_for_node( | 349 | int core_enable_device_list_for_node( |
350 | struct se_lun *lun, | 350 | struct se_lun *lun, |
351 | struct se_lun_acl *lun_acl, | 351 | struct se_lun_acl *lun_acl, |
352 | u32 mapped_lun, | 352 | u32 mapped_lun, |
353 | u32 lun_access, | 353 | u32 lun_access, |
354 | struct se_node_acl *nacl, | 354 | struct se_node_acl *nacl, |
355 | struct se_portal_group *tpg, | 355 | struct se_portal_group *tpg) |
356 | int enable) | ||
357 | { | 356 | { |
358 | struct se_port *port = lun->lun_sep; | 357 | struct se_port *port = lun->lun_sep; |
359 | struct se_dev_entry *deve = nacl->device_list[mapped_lun]; | 358 | struct se_dev_entry *deve; |
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 | } | ||
380 | 359 | ||
381 | spin_lock_irq(&nacl->device_list_lock); | 360 | spin_lock_irq(&nacl->device_list_lock); |
382 | if (enable) { | 361 | |
383 | /* | 362 | deve = nacl->device_list[mapped_lun]; |
384 | * Check if the call is handling demo mode -> explict LUN ACL | 363 | |
385 | * transition. This transition must be for the same struct se_lun | 364 | /* |
386 | * + mapped_lun that was setup in demo mode.. | 365 | * Check if the call is handling demo mode -> explict LUN ACL |
387 | */ | 366 | * transition. This transition must be for the same struct se_lun |
388 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { | 367 | * + mapped_lun that was setup in demo mode.. |
389 | if (deve->se_lun_acl != NULL) { | 368 | */ |
390 | pr_err("struct se_dev_entry->se_lun_acl" | 369 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { |
391 | " already set for demo mode -> explict" | 370 | if (deve->se_lun_acl != NULL) { |
392 | " LUN ACL transition\n"); | 371 | pr_err("struct se_dev_entry->se_lun_acl" |
393 | spin_unlock_irq(&nacl->device_list_lock); | 372 | " already set for demo mode -> explict" |
394 | return -EINVAL; | 373 | " LUN ACL transition\n"); |
395 | } | 374 | spin_unlock_irq(&nacl->device_list_lock); |
396 | if (deve->se_lun != lun) { | 375 | return -EINVAL; |
397 | pr_err("struct se_dev_entry->se_lun does" | 376 | } |
398 | " match passed struct se_lun for demo mode" | 377 | if (deve->se_lun != lun) { |
399 | " -> explict LUN ACL transition\n"); | 378 | pr_err("struct se_dev_entry->se_lun does" |
400 | spin_unlock_irq(&nacl->device_list_lock); | 379 | " match passed struct se_lun for demo mode" |
401 | return -EINVAL; | 380 | " -> explict LUN ACL transition\n"); |
402 | } | 381 | spin_unlock_irq(&nacl->device_list_lock); |
403 | deve->se_lun_acl = lun_acl; | 382 | return -EINVAL; |
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; | ||
410 | } | 383 | } |
384 | deve->se_lun_acl = lun_acl; | ||
411 | 385 | ||
412 | if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { | 386 | if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { |
413 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; | 387 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; |
@@ -417,20 +391,70 @@ int core_update_device_list_for_node( | |||
417 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; | 391 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; |
418 | } | 392 | } |
419 | 393 | ||
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++; | ||
426 | spin_unlock_irq(&nacl->device_list_lock); | 394 | spin_unlock_irq(&nacl->device_list_lock); |
395 | return 0; | ||
396 | } | ||
427 | 397 | ||
428 | spin_lock_bh(&port->sep_alua_lock); | 398 | deve->se_lun = lun; |
429 | list_add_tail(&deve->alua_port_list, &port->sep_alua_list); | 399 | deve->se_lun_acl = lun_acl; |
430 | spin_unlock_bh(&port->sep_alua_lock); | 400 | deve->mapped_lun = mapped_lun; |
401 | deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS; | ||
431 | 402 | ||
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; | ||
433 | } | 409 | } |
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 | |||
434 | /* | 458 | /* |
435 | * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE | 459 | * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE |
436 | * PR operation to complete. | 460 | * PR operation to complete. |
@@ -475,9 +499,9 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg) | |||
475 | continue; | 499 | continue; |
476 | spin_unlock_irq(&nacl->device_list_lock); | 500 | spin_unlock_irq(&nacl->device_list_lock); |
477 | 501 | ||
478 | core_update_device_list_for_node(lun, NULL, | 502 | core_disable_device_list_for_node(lun, NULL, |
479 | deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, | 503 | deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, |
480 | nacl, tpg, 0); | 504 | nacl, tpg); |
481 | 505 | ||
482 | spin_lock_irq(&nacl->device_list_lock); | 506 | spin_lock_irq(&nacl->device_list_lock); |
483 | } | 507 | } |
@@ -1469,8 +1493,8 @@ int core_dev_add_initiator_node_lun_acl( | |||
1469 | 1493 | ||
1470 | lacl->se_lun = lun; | 1494 | lacl->se_lun = lun; |
1471 | 1495 | ||
1472 | if (core_update_device_list_for_node(lun, lacl, lacl->mapped_lun, | 1496 | if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun, |
1473 | lun_access, nacl, tpg, 1) < 0) | 1497 | lun_access, nacl, tpg) < 0) |
1474 | return -EINVAL; | 1498 | return -EINVAL; |
1475 | 1499 | ||
1476 | spin_lock(&lun->lun_acl_lock); | 1500 | spin_lock(&lun->lun_acl_lock); |
@@ -1513,8 +1537,8 @@ int core_dev_del_initiator_node_lun_acl( | |||
1513 | smp_mb__after_atomic_dec(); | 1537 | smp_mb__after_atomic_dec(); |
1514 | spin_unlock(&lun->lun_acl_lock); | 1538 | spin_unlock(&lun->lun_acl_lock); |
1515 | 1539 | ||
1516 | core_update_device_list_for_node(lun, NULL, lacl->mapped_lun, | 1540 | core_disable_device_list_for_node(lun, NULL, lacl->mapped_lun, |
1517 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); | 1541 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); |
1518 | 1542 | ||
1519 | lacl->se_lun = NULL; | 1543 | lacl->se_lun = NULL; |
1520 | 1544 | ||
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index d41a9bb89ce1..0fd428225d11 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h | |||
@@ -10,8 +10,10 @@ int core_free_device_list_for_node(struct se_node_acl *, | |||
10 | struct se_portal_group *); | 10 | struct se_portal_group *); |
11 | void core_dec_lacl_count(struct se_node_acl *, struct se_cmd *); | 11 | void core_dec_lacl_count(struct se_node_acl *, struct se_cmd *); |
12 | void core_update_device_list_access(u32, u32, struct se_node_acl *); | 12 | 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 *, | 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 *, int); | 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 *); | ||
15 | void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *); | 17 | void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *); |
16 | int core_dev_export(struct se_device *, struct se_portal_group *, | 18 | int core_dev_export(struct se_device *, struct se_portal_group *, |
17 | struct se_lun *); | 19 | struct se_lun *); |
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 5ca340cff111..b8628a5014b9 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c | |||
@@ -77,8 +77,8 @@ static void core_clear_initiator_node_from_tpg( | |||
77 | 77 | ||
78 | lun = deve->se_lun; | 78 | lun = deve->se_lun; |
79 | spin_unlock_irq(&nacl->device_list_lock); | 79 | spin_unlock_irq(&nacl->device_list_lock); |
80 | core_update_device_list_for_node(lun, NULL, deve->mapped_lun, | 80 | core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, |
81 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); | 81 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); |
82 | 82 | ||
83 | spin_lock_irq(&nacl->device_list_lock); | 83 | spin_lock_irq(&nacl->device_list_lock); |
84 | } | 84 | } |
@@ -172,8 +172,8 @@ void core_tpg_add_node_to_devs( | |||
172 | (lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ? | 172 | (lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ? |
173 | "READ-WRITE" : "READ-ONLY"); | 173 | "READ-WRITE" : "READ-ONLY"); |
174 | 174 | ||
175 | core_update_device_list_for_node(lun, NULL, lun->unpacked_lun, | 175 | core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun, |
176 | lun_access, acl, tpg, 1); | 176 | lun_access, acl, tpg); |
177 | spin_lock(&tpg->tpg_lun_lock); | 177 | spin_lock(&tpg->tpg_lun_lock); |
178 | } | 178 | } |
179 | spin_unlock(&tpg->tpg_lun_lock); | 179 | spin_unlock(&tpg->tpg_lun_lock); |