From: Luis Chamberlain <mcgrof@kernel.org>
To: James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, linux-scsi@vger.kernel.org
Cc: mcgrof@kernel.org, gost.dev@samsung.com, s.prabhu@samsung.com,
linux-kernel@vger.kernel.org
Subject: [PATCH] scsi_debug: Fix shared UUID issue when creating multiple hosts
Date: Tue, 1 Jul 2025 15:02:34 -0700 [thread overview]
Message-ID: <20250701220234.1605559-1-mcgrof@kernel.org> (raw)
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)
Reported-by: Swarna Prabhu <s.prabhu@samsung.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/scsi/scsi_debug.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index f0eec4708ddd..4d0b17861adb 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -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;
--
2.45.2
next reply other threads:[~2025-07-01 22:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 22:02 Luis Chamberlain [this message]
2025-07-02 9:57 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250701220234.1605559-1-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=gost.dev@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=s.prabhu@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®