public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mkfs: add discard support
@ 2009-10-06 18:47 Christoph Hellwig
  2009-10-07  4:42 ` Dave Chinner
  0 siblings, 1 reply; 15+ messages in thread
From: Christoph Hellwig @ 2009-10-06 18:47 UTC (permalink / raw)
  To: xfs

Call the BLKDISCARD ioctl to mark the whole disk as unused before creating
a new filesystem.  This will allow SSDs, Arrays with thin provisioning support
and virtual machines to make smarter allocation decisions.

Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: xfsprogs-dev/mkfs/xfs_mkfs.c
===================================================================
--- xfsprogs-dev.orig/mkfs/xfs_mkfs.c	2009-10-06 18:02:34.000000000 +0000
+++ xfsprogs-dev/mkfs/xfs_mkfs.c	2009-10-06 18:03:55.000000000 +0000
@@ -605,6 +605,29 @@ done:
 	free(buf);
 }
 
+#ifdef __linux__
+
+#ifndef BLKDISCARD
+#define BLKDISCARD	_IO(0x12,119)
+#endif
+
+static void
+discard_blocks(dev_t dev, __uint64_t nsectors)
+{
+	int fd = libxfs_device_to_fd(dev);
+	__uint64_t range[2] = { 0, nsectors << 9 };
+
+	/*
+	 * We intentionally ignore errors from the discard ioctl.  It is
+	 * not nessecary for the mkfs functionality but just an optimization.
+	 */
+	if (fd > 0)
+		ioctl(fd, BLKDISCARD, &range);
+}
+#else
+#define discard_blocks(dev, nsectors)
+#endif
+
 int
 main(
 	int			argc,
@@ -1645,6 +1668,12 @@ main(
 		}
 	}
 
+	discard_blocks(xi.ddev, xi.dsize);
+	if (xi.rtdev)
+		discard_blocks(xi.rtdev, xi.rtsize);
+	if (xi.logdev && xi.logdev != xi.ddev)
+		discard_blocks(xi.logdev, xi.logBBsize);
+
 	if (!liflag && !ldflag)
 		loginternal = xi.logdev == 0;
 	if (xi.logname)

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-11-12 16:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1235789111.21721254856913943.JavaMail.root@mail-au.aconex.com>
2009-10-06 19:24 ` [PATCH] mkfs: add discard support Nathan Scott
2009-10-06 19:26   ` Christoph Hellwig
2009-10-07  1:18   ` Christoph Hellwig
2009-10-07  1:20     ` Nathan Scott
2009-10-07  3:55       ` Eric Sandeen
2009-11-12 16:04       ` Christoph Hellwig
2009-10-06 18:47 Christoph Hellwig
2009-10-07  4:42 ` Dave Chinner
2009-10-07  6:05   ` Michael Monnerie
2009-10-07 14:11   ` Christoph Hellwig
2009-10-07 20:24   ` Andi Kleen
2009-10-09  2:30     ` Dave Chinner
2009-10-10  4:22       ` Andi Kleen
2009-10-10 16:24       ` Christoph Hellwig
2009-10-12  1:33         ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox