mkfs: add discard support
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · ----- "Christoph Hellwig
Index:
xfsprogs-dev/mkfs/xfs_mkfs.c
===================================================================
---xfsprogs-dev.orig/mkfs/xfs_mkfs.c2009-10-06 18:02:34.000000000
+0000
+++xfsprogs-dev/mkfs/xfs_mkfs.c2009-10-06 18:03:55.000000000 +0000
Review done: · line 612
Quoted 8 lines
(quoted diff) +5
-0@@ -605,6 +605,29 @@ done: free(buf); } +#ifdef __linux__ + +#ifndef BLKDISCARD +#define BLKDISCARD _IO(0x12,119) +#endif
It might be a bit cleaner to add this in with the existing platform- specific code in libxfs/linux.c (or perhaps include/platform_defs.h) with wrappers for the other platforms, rather than putting it directly in mkfs like this? repair may want to use this someday too, I guess.
cheers.
Signature · 6 lines
Nathan _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 4 lines · Nathan Scott
It might be a bit cleaner to add this in with the existing platform- specific code in
libxfs/linux.c(or perhapsinclude/platform_defs.h) with wrappers for the other platforms, rather than putting it directly in mkfs like this? repair may want to use this someday too, I guess.
Yeah, that might be better.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 4 lines
It might be a bit cleaner to add this in with the existing platform- specific code in
libxfs/linux.c(or perhapsinclude/platform_defs.h) with wrappers for the other platforms, rather than putting it directly in mkfs like this? repair may want to use this someday too, I guess.
How about this one?
Signature · 125 lines
Subject: [PATCH] mkfs: add discard support From: Christoph Hellwig <[email protected]> Cal 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 <[email protected]> Index: xfsprogs-dev/mkfs/xfs_mkfs.c =================================================================== --- xfsprogs-dev.orig/mkfs/xfs_mkfs.c 2009-10-06 18:46:06.000000000 +0000 +++ xfsprogs-dev/mkfs/xfs_mkfs.c 2009-10-07 01:09:49.000000000 +0000 @@ -605,6 +605,20 @@ done: free(buf); } +static void +discard_blocks(dev_t dev, __uint64_t nsectors) +{ + int fd; + + /* + * We intentionally ignore errors from the discard ioctl. It is + * not nessecary for the mkfs functionality but just an optimization. + */ + fd = libxfs_device_to_fd(dev); + if (fd > 0) + platform_discard_blocks(fd, 0, nsectors << 9); +} + int main( int argc, @@ -1645,6 +1659,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) Index: xfsprogs-dev/include/linux.h =================================================================== --- xfsprogs-dev.orig/include/linux.h 2009-10-07 01:06:00.000000000 +0000 +++ xfsprogs-dev/include/linux.h 2009-10-07 01:13:12.000000000 +0000 @@ -93,6 +93,20 @@ static __inline__ void platform_uuid_cop uuid_copy(*dst, *src); } +#ifndef BLKDISCARD +#define BLKDISCARD _IO(0x12,119) +#endif + +static __inline__ int +platform_discard_blocks(int fd, off64_t start, off64_t end) +{ + __uint64_t range[2] = { start, end }; + + if (ioctl(fd, BLKDISCARD, &range) < 0) + return errno; + return 0; +} + #if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 1)) # define constpp const char * const * #else Index: xfsprogs-dev/include/darwin.h =================================================================== --- xfsprogs-dev.orig/include/darwin.h 2009-10-07 01:15:38.000000000 +0000 +++ xfsprogs-dev/include/darwin.h 2009-10-07 01:16:19.000000000 +0000 @@ -154,4 +154,10 @@ typedef unsigned char uchar_t; #define HAVE_FID 1 +static __inline__ int +platform_discard_blocks(int fd, off64_t start, off64_t end) +{ + return 0; +} + #endif /* __XFS_DARWIN_H__ */ Index: xfsprogs-dev/include/freebsd.h =================================================================== --- xfsprogs-dev.orig/include/freebsd.h 2009-10-07 01:15:38.000000000 +0000 +++ xfsprogs-dev/include/freebsd.h 2009-10-07 01:16:06.000000000 +0000 @@ -139,4 +139,10 @@ static __inline__ void platform_uuid_cop memcpy(dst, src, sizeof(uuid_t)); } +static __inline__ int +platform_discard_blocks(int fd, off64_t start, off64_t end) +{ + return 0; +} + #endif /* __XFS_FREEBSD_H__ */ Index: xfsprogs-dev/include/irix.h =================================================================== --- xfsprogs-dev.orig/include/irix.h 2009-10-07 01:15:38.000000000 +0000 +++ xfsprogs-dev/include/irix.h 2009-10-07 01:16:29.000000000 +0000 @@ -337,6 +337,12 @@ static __inline__ void platform_uuid_cop memcpy(dst, src, sizeof(uuid_t)); } +static __inline__ int +platform_discard_blocks(int fd, off64_t start, off64_t end) +{ + return 0; +} + static __inline__ char * strsep(char **s, const char *ct) { char *sbegin = *s, *end; _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · ----- "Christoph Hellwig
Quoted 1 line
It might be a bit cleaner to add this in with the existing
platform-
Quoted 1 line
specific code in
libxfs/linux.c(or perhaps
include/platform_defs.h)Quoted 1 line
with wrappers for the other platforms, rather than putting it
directly
Quoted 1 line
in mkfs like this? repair may want to use this someday too, I
guess.
How about this one?
Looks good to me.
cheers.
Signature · 6 lines
Nathan _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 9 lines · Nathan Scott
Quoted 7 lines · ----- "Christoph Hellwig
Quoted 1 line
It might be a bit cleaner to add this in with the existing
platform-
Quoted 1 line
specific code in
libxfs/linux.c(or perhaps
include/platform_defs.h)Quoted 1 line
with wrappers for the other platforms, rather than putting it
directly
Quoted 1 line
in mkfs like this? repair may want to use this someday too, I
Quoted 9 lines
Quoted 4 lines
guess.
How about this one?
Looks good to me.
cheers.
looks good to me too, thanks.
need to get that vertex flashed w/ trim support some day...
-eric
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Adding the discard helper to the platform headers now causes the build to fail for some external users of the xfs headers because off64_t doesn't exist without the large file configure magic. E.g. for xfstests:
checking xfs/xfs.h usability... no
checking xfs/xfs.h presence... yes
configure: WARNING: xfs/xfs.h: present but cannot be compiled
configure: WARNING: xfs/xfs.h: check for missing prerequisite headers?
configure: WARNING: xfs/xfs.h: see the Autoconf documentation
configure: WARNING: xfs/xfs.h: section "Present But Cannot Be Compiled"
configure: WARNING: xfs/xfs.h: proceeding with the compiler's result checking for xfs/xfs.h... no
commenting out the discard helper fixes this. We might be able to just switch to a int64_t or similar instead, even if that's a bit ugly.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs