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

scsi: target: Add the DUMMY flag to rd_mcp

This commit adds the DUMMY flag to the rd_mcp backend that forces a logical
unit to report itself as not connected device of an unknown type.
Essentially this allows users to create devices identical to the device for
the virtual LUN 0, making it possible to explicitly create a LUN 0 device
and configure its WWNs (e.g. vendor or product name).

Link: https://lore.kernel.org/r/20210322200938.53300-2-k.shelekhin@yadro.com
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Konstantin Shelekhin and committed by
Martin K. Petersen
0aecfa66 bc3f2b42

+24 -4
+23 -4
drivers/target/target_core_rd.c
··· 530 530 } 531 531 532 532 enum { 533 - Opt_rd_pages, Opt_rd_nullio, Opt_err 533 + Opt_rd_pages, Opt_rd_nullio, Opt_rd_dummy, Opt_err 534 534 }; 535 535 536 536 static match_table_t tokens = { 537 537 {Opt_rd_pages, "rd_pages=%d"}, 538 538 {Opt_rd_nullio, "rd_nullio=%d"}, 539 + {Opt_rd_dummy, "rd_dummy=%d"}, 539 540 {Opt_err, NULL} 540 541 }; 541 542 ··· 575 574 pr_debug("RAMDISK: Setting NULLIO flag: %d\n", arg); 576 575 rd_dev->rd_flags |= RDF_NULLIO; 577 576 break; 577 + case Opt_rd_dummy: 578 + match_int(args, &arg); 579 + if (arg != 1) 580 + break; 581 + 582 + pr_debug("RAMDISK: Setting DUMMY flag: %d\n", arg); 583 + rd_dev->rd_flags |= RDF_DUMMY; 584 + break; 578 585 default: 579 586 break; 580 587 } ··· 599 590 ssize_t bl = sprintf(b, "TCM RamDisk ID: %u RamDisk Makeup: rd_mcp\n", 600 591 rd_dev->rd_dev_id); 601 592 bl += sprintf(b + bl, " PAGES/PAGE_SIZE: %u*%lu" 602 - " SG_table_count: %u nullio: %d\n", rd_dev->rd_page_count, 593 + " SG_table_count: %u nullio: %d dummy: %d\n", 594 + rd_dev->rd_page_count, 603 595 PAGE_SIZE, rd_dev->sg_table_count, 604 - !!(rd_dev->rd_flags & RDF_NULLIO)); 596 + !!(rd_dev->rd_flags & RDF_NULLIO), 597 + !!(rd_dev->rd_flags & RDF_DUMMY)); 605 598 return bl; 599 + } 600 + 601 + static u32 rd_get_device_type(struct se_device *dev) 602 + { 603 + if (RD_DEV(dev)->rd_flags & RDF_DUMMY) 604 + return 0x3f; /* Unknown device type, not connected */ 605 + else 606 + return sbc_get_device_type(dev); 606 607 } 607 608 608 609 static sector_t rd_get_blocks(struct se_device *dev) ··· 666 647 .parse_cdb = rd_parse_cdb, 667 648 .set_configfs_dev_params = rd_set_configfs_dev_params, 668 649 .show_configfs_dev_params = rd_show_configfs_dev_params, 669 - .get_device_type = sbc_get_device_type, 650 + .get_device_type = rd_get_device_type, 670 651 .get_blocks = rd_get_blocks, 671 652 .init_prot = rd_init_prot, 672 653 .free_prot = rd_free_prot,
+1
drivers/target/target_core_rd.h
··· 28 28 29 29 #define RDF_HAS_PAGE_COUNT 0x01 30 30 #define RDF_NULLIO 0x02 31 + #define RDF_DUMMY 0x04 31 32 32 33 struct rd_dev { 33 34 struct se_device dev;