Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andy Grover and committed by
Nicholas Bellinger
e80ac6c4 cdf88a2f

+104 -78
+96 -72
drivers/target/target_core_device.c
··· 300 300 lun = deve->se_lun; 301 301 302 302 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); 305 305 spin_lock_irq(&nacl->device_list_lock); 306 306 } 307 307 spin_unlock_irq(&nacl->device_list_lock); ··· 342 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 350 struct se_lun *lun, 351 351 struct se_lun_acl *lun_acl, 352 352 u32 mapped_lun, 353 353 u32 lun_access, 354 354 struct se_node_acl *nacl, 355 - struct se_portal_group *tpg, 356 - int enable) 355 + struct se_portal_group *tpg) 357 356 { 358 357 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; 380 359 381 360 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; 410 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; 383 + } 384 + deve->se_lun_acl = lun_acl; 411 385 412 386 if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { 413 387 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; ··· 391 417 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 392 418 } 393 419 394 - if (trans) { 395 - spin_unlock_irq(&nacl->device_list_lock); 396 - return 0; 397 - } 398 - deve->creation_time = get_jiffies_64(); 399 - deve->attach_count++; 400 420 spin_unlock_irq(&nacl->device_list_lock); 401 - 402 - spin_lock_bh(&port->sep_alua_lock); 403 - list_add_tail(&deve->alua_port_list, &port->sep_alua_list); 404 - spin_unlock_bh(&port->sep_alua_lock); 405 - 406 421 return 0; 407 422 } 423 + 424 + deve->se_lun = lun; 425 + deve->se_lun_acl = lun_acl; 426 + deve->mapped_lun = mapped_lun; 427 + deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS; 428 + 429 + if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { 430 + deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; 431 + deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; 432 + } else { 433 + deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; 434 + deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 435 + } 436 + 437 + deve->creation_time = get_jiffies_64(); 438 + deve->attach_count++; 439 + spin_unlock_irq(&nacl->device_list_lock); 440 + 441 + spin_lock_bh(&port->sep_alua_lock); 442 + list_add_tail(&deve->alua_port_list, &port->sep_alua_list); 443 + spin_unlock_bh(&port->sep_alua_lock); 444 + 445 + return 0; 446 + } 447 + 448 + /* core_disable_device_list_for_node(): 449 + * 450 + * 451 + */ 452 + int core_disable_device_list_for_node( 453 + struct se_lun *lun, 454 + struct se_lun_acl *lun_acl, 455 + u32 mapped_lun, 456 + u32 lun_access, 457 + struct se_node_acl *nacl, 458 + struct se_portal_group *tpg) 459 + { 460 + struct se_port *port = lun->lun_sep; 461 + struct se_dev_entry *deve; 462 + 463 + spin_lock_irq(&nacl->device_list_lock); 464 + 465 + deve = nacl->device_list[mapped_lun]; 466 + 467 + /* 468 + * If the MappedLUN entry is being disabled, the entry in 469 + * port->sep_alua_list must be removed now before clearing the 470 + * struct se_dev_entry pointers below as logic in 471 + * core_alua_do_transition_tg_pt() depends on these being present. 472 + * 473 + * deve->se_lun_acl will be NULL for demo-mode created LUNs 474 + * that have not been explicitly converted to MappedLUNs -> 475 + * struct se_lun_acl, but we remove deve->alua_port_list from 476 + * port->sep_alua_list. This also means that active UAs and 477 + * NodeACL context specific PR metadata for demo-mode 478 + * MappedLUN *deve will be released below.. 479 + */ 480 + spin_lock_bh(&port->sep_alua_lock); 481 + list_del(&deve->alua_port_list); 482 + spin_unlock_bh(&port->sep_alua_lock); 483 + 408 484 /* 409 485 * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE 410 486 * PR operation to complete. ··· 499 475 continue; 500 476 spin_unlock_irq(&nacl->device_list_lock); 501 477 502 - core_update_device_list_for_node(lun, NULL, 478 + core_disable_device_list_for_node(lun, NULL, 503 479 deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, 504 - nacl, tpg, 0); 480 + nacl, tpg); 505 481 506 482 spin_lock_irq(&nacl->device_list_lock); 507 483 } ··· 1493 1469 1494 1470 lacl->se_lun = lun; 1495 1471 1496 - if (core_update_device_list_for_node(lun, lacl, lacl->mapped_lun, 1497 - lun_access, nacl, tpg, 1) < 0) 1472 + if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun, 1473 + lun_access, nacl, tpg) < 0) 1498 1474 return -EINVAL; 1499 1475 1500 1476 spin_lock(&lun->lun_acl_lock); ··· 1537 1513 smp_mb__after_atomic_dec(); 1538 1514 spin_unlock(&lun->lun_acl_lock); 1539 1515 1540 - core_update_device_list_for_node(lun, NULL, lacl->mapped_lun, 1541 - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); 1516 + core_disable_device_list_for_node(lun, NULL, lacl->mapped_lun, 1517 + TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); 1542 1518 1543 1519 lacl->se_lun = NULL; 1544 1520
+4 -2
drivers/target/target_core_internal.h
··· 10 10 struct se_portal_group *); 11 11 void core_dec_lacl_count(struct se_node_acl *, struct se_cmd *); 12 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 *, 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 *); 15 17 void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *); 16 18 int core_dev_export(struct se_device *, struct se_portal_group *, 17 19 struct se_lun *);
+4 -4
drivers/target/target_core_tpg.c
··· 77 77 78 78 lun = deve->se_lun; 79 79 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); 82 82 83 83 spin_lock_irq(&nacl->device_list_lock); 84 84 } ··· 172 172 (lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ? 173 173 "READ-WRITE" : "READ-ONLY"); 174 174 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); 177 177 spin_lock(&tpg->tpg_lun_lock); 178 178 } 179 179 spin_unlock(&tpg->tpg_lun_lock);