From: Christoph Hellwig <hch@lst.de>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: add discard support to mkfs
Date: Fri, 30 Oct 2009 10:46:01 +0100 [thread overview]
Message-ID: <20091030094601.GA9906@lst.de> (raw)
Discard the whole device before starting to create the filesystem structures.
Modelled after similar support in mkfs.xfs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: btrfs-progs-unstable/utils.c
===================================================================
--- btrfs-progs-unstable.orig/utils.c 2009-10-30 09:34:00.000000000 +0000
+++ btrfs-progs-unstable/utils.c 2009-10-30 09:38:01.000000000 +0000
@@ -46,6 +46,20 @@
static inline int ioctl(int fd, int define, u64 *size) { return 0; }
#endif
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static int
+discard_blocks(int fd, u64 start, u64 len)
+{
+ u64 range[2] = { start, len };
+
+ if (ioctl(fd, BLKDISCARD, &range) < 0)
+ return errno;
+ return 0;
+}
+
static u64 reference_root_table[] = {
[1] = BTRFS_ROOT_TREE_OBJECTID,
[2] = BTRFS_EXTENT_TREE_OBJECTID,
@@ -532,6 +546,13 @@ int btrfs_prepare_device(int fd, char *f
"(must be at least 256 MB)\n", file);
exit(1);
}
+
+ /*
+ * We intentionally ignore errors from the discard ioctl. It is
+ * not necessary for the mkfs functionality but just an optimization.
+ */
+ discard_blocks(fd, 0, block_count);
+
ret = zero_dev_start(fd);
if (ret) {
fprintf(stderr, "failed to zero device start %d\n", ret);
reply other threads:[~2009-10-30 9:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20091030094601.GA9906@lst.de \
--to=hch@lst.de \
--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