scsi_debug: Fix shared UUID issue when creating multiple hosts
PATCH 1/1 scsi_debug: Fix shared UUID issue when creating multiple hosts
When creating multiple scsi_debug hosts (e.g., modprobe scsi_debug add_host=2), all devices share the same backing storage by default. This causes filesystem UUIDs to be shared between devices like /dev/sda and /dev/sdb, leading to confusion and potential mount issues.
For example:
# modprobe scsi_debug add_host=2 dev_size_mb=1024 # mkfs.xfs -f /dev/sda # wipefs /dev/sda /dev/sdb Both devices show the same UUID, which is incorrect behavior.
Fix this by automatically enabling separate per-host stores when multiple hosts are created, while preserving backward compatibility for single-host scenarios. Users can still explicitly control this behavior via the per_host_store parameter.
After this fix:
- Single host: Uses shared store (unchanged behavior)
- Multiple hosts: Automatically uses separate stores (fixes UUID issue)
- Explicit per_host_store=1: Always separate stores (unchanged behavior)
--- drivers/scsi/scsi_debug.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/scsi/scsi_debug.c +14 -3
@@ -8034,12 +8034,18 @@ static ssize_t add_host_store(struct device_driver *ddp, const char *buf,bool found;unsigned long idx;struct sdeb_store_info *sip; +bool uniq_uuid_required = false;bool want_phs = (sdebug_fake_rw ==0 ) && sdebug_per_host_store;int delta_hosts;if (sscanf (buf,"%d" , &delta_hosts) !=1 )return -EINVAL ;if (delta_hosts >0 ) { +if (delta_hosts >1 ) { + uniq_uuid_required = true; +if (sdebug_fake_rw ==0 ) + want_phs = true; + } do { found = false; if (want_phs) {
@@ -8054,7 +8060,7 @@ static ssize_t add_host_store(struct device_driver *ddp, const char *buf,else sdebug_do_add_host (true); }else { -sdebug_do_add_host (false); +sdebug_do_add_host (uniq_uuid_required); } }while (--delta_hosts); }else if (delta_hosts <0 ) {
@@ -8383,6 +8389,7 @@ static struct device *pseudo_primary;static int __init scsi_debug_init (void ) {bool want_store = (sdebug_fake_rw ==0 ); +bool uniq_uuid_required = false;unsigned long sz;int k, ret, hosts_to_add;int idx =-1 ;
@@ -8578,6 +8585,9 @@ static int __init scsi_debug_init(void) } hosts_to_add = sdebug_add_host; +if (hosts_to_add >1 ) + uniq_uuid_required = true; + sdebug_add_host =0 ; sdebug_debugfs_root =debugfs_create_dir ("scsi_debug" ,NULL );
@@ -8593,8 +8603,9 @@ static int __init scsi_debug_init(void)break ; } }else { - ret =sdebug_do_add_host (want_store && - sdebug_per_host_store); +bool use_store = want_store && + (sdebug_per_host_store || uniq_uuid_required); + ret =sdebug_do_add_host (use_store);if (ret <0 ) {pr_err ("add_host k=%d error=%d\n" , k, -ret);break ;
Signature · 1 line
2.45.2
Quoted 11 lines · Luis Chamberlain
When creating multiple
scsi_debughosts (e.g., modprobescsi_debugadd_host=2), all devices share the same backing storage by default. This causes filesystem UUIDs to be shared between devices like/dev/sdaand/dev/sdb, leading to confusion and potential mount issues.For example:
# modprobe scsi_debug add_host=2 dev_size_mb=1024 # mkfs.xfs -f /dev/sda # wipefs /dev/sda /dev/sdb Both devices show the same UUID, which is incorrect behavior.
Quoted 7 lines
Fix this by automatically enabling separate per-host stores when multiple hosts are created, while preserving backward compatibility for single-host scenarios. Users can still explicitly control this behavior via the
per_host_storeparameter.After this fix:
- Single host: Uses shared store (unchanged behavior)
Does phs even have any affect for only a single scsi_debug host?
I thought that phs means that each host has its own backing storage which is shared among all devices for that host.
Quoted 70 lines
- Multiple hosts: Automatically uses separate stores (fixes UUID issue)
- Explicit per_host_store=1: Always separate stores (unchanged behavior)Quoted 1 line
Reported-by Swarna Prabhu <[email protected]>Signed-off-by Luis Chamberlain <[email protected]>--- drivers/scsi/scsi_debug.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/scsi/scsi_debug.c +14
-3@@ -8034,12 +8034,18 @@ static ssize_t add_host_store(struct device_driver *ddp, const char *buf,bool found;unsigned long idx;struct sdeb_store_info *sip; +bool uniq_uuid_required = false;bool want_phs = (sdebug_fake_rw ==0 ) && sdebug_per_host_store;int delta_hosts;if (sscanf (buf,"%d" , &delta_hosts) !=1 )return -EINVAL ;if (delta_hosts >0 ) { +if (delta_hosts >1 ) { + uniq_uuid_required = true; +if (sdebug_fake_rw ==0 ) + want_phs = true; + } do { found = false; if (want_phs) {@@ -8054,7 +8060,7 @@ static ssize_t add_host_store(struct device_driver *ddp, const char *buf,else sdebug_do_add_host (true); }else { -sdebug_do_add_host (false); +sdebug_do_add_host (uniq_uuid_required); } }while (--delta_hosts); }else if (delta_hosts <0 ) {@@ -8383,6 +8389,7 @@ static struct device *pseudo_primary;static int __init scsi_debug_init (void ) {bool want_store = (sdebug_fake_rw ==0 ); +bool uniq_uuid_required = false;unsigned long sz;int k, ret, hosts_to_add;int idx =-1 ;@@ -8578,6 +8585,9 @@ static int __init scsi_debug_init(void) } hosts_to_add = sdebug_add_host; +if (hosts_to_add >1 ) + uniq_uuid_required = true; + sdebug_add_host =0 ; sdebug_debugfs_root =debugfs_create_dir ("scsi_debug" ,NULL );@@ -8593,8 +8603,9 @@ static int __init scsi_debug_init(void)break ; } }else { - ret =sdebug_do_add_host (want_store && - sdebug_per_host_store); +bool use_store = want_store && + (sdebug_per_host_store || uniq_uuid_required); + ret =sdebug_do_add_host (use_store);if (ret <0 ) {pr_err ("add_host k=%d error=%d\n" , k, -ret);break ;