From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: force overwrite should wipe stale SB
Date: Fri, 5 Sep 2014 23:51:24 +0800 [thread overview]
Message-ID: <1409932284-30895-1-git-send-email-anand.jain@oracle.com> (raw)
Here is a test case which says it all..
mkfs.xfs -f $DEV
mkfs.btrfs -f $DEV
mount $DEV $MNT
mount: /dev/vdiskc: more filesystems detected. This should not happen,
use -t <type> to explicitly specify the filesystem type or
use wipefs(8) to clean up the device.
mount: you must specify the filesystem type
with this patch btrfs_prepare_device() also wipes old FS if any,
btrfs_prepare_device() is called after we have verified that
user has provided -f option.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
utils.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/utils.c b/utils.c
index 0064587..8b0c751 100644
--- a/utils.c
+++ b/utils.c
@@ -678,6 +678,35 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
return 0;
}
+static void wipe_existing_fs(int fd)
+{
+ blkid_probe pr = NULL;
+
+ pr = blkid_new_probe();
+ if (!pr)
+ return;
+
+ if (blkid_probe_set_device(pr, fd, 0, 0))
+ goto out;
+
+ blkid_probe_enable_superblocks(pr, 1);
+ blkid_probe_set_superblocks_flags(pr,
+ BLKID_SUBLKS_MAGIC |
+ BLKID_SUBLKS_TYPE |
+ BLKID_SUBLKS_USAGE |
+ BLKID_SUBLKS_LABEL |
+ BLKID_SUBLKS_UUID);
+
+ blkid_probe_enable_partitions(pr, 1);
+
+ while (blkid_do_probe(pr) == 0)
+ blkid_do_wipe(pr, 0);
+
+ fsync(fd);
+out:
+ blkid_free_probe(pr);
+}
+
int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
u64 max_block_count, int *mixed, int discard)
{
@@ -729,6 +758,8 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
return 1;
}
+ wipe_existing_fs(fd);
+
*block_count_ret = block_count;
return 0;
}
--
1.7.1
next reply other threads:[~2014-09-05 8:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-05 15:51 Anand Jain [this message]
2014-09-15 16:15 ` [PATCH] btrfs-progs: force overwrite should wipe stale SB David Sterba
2014-10-01 11:26 ` David Sterba
2014-10-01 11:45 ` Anand Jain
2014-10-01 23:22 ` [PATCH v2] " Anand Jain
2014-10-10 7:39 ` David Sterba
2014-10-10 7:47 ` Anand Jain
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=1409932284-30895-1-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).