From 7c66e9fac5c7883fb85107f06f472a2fa3ed4322 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Wed, 26 Mar 2025 09:39:59 -0400
Subject: [PATCH] migrate_superblock: make sure we remove old superblock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 c_src/cmd_migrate.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/c_src/cmd_migrate.c b/c_src/cmd_migrate.c
index 8155a2b3..639aba64 100644
--- a/c_src/cmd_migrate.c
+++ b/c_src/cmd_migrate.c
@@ -419,6 +419,11 @@ int cmd_migrate_superblock(int argc, char *argv[])
 	sb->layout.sb_offset[0] = cpu_to_le64(BCH_SB_SECTOR);
 	sb->layout.sb_offset[1] = cpu_to_le64(BCH_SB_SECTOR + sb_size);
 
+	/* also write first 0-3.5k bytes with zeroes, ensure we blow away old
+	 * superblock */
+	static const char zeroes[BCH_SB_SECTOR << 9];
+	xpwrite(fd, zeroes, BCH_SB_SECTOR << 9, 0, "zeroing start of disk");
+
 	bch2_super_write(fd, sb);
 	close(fd);