summaryrefslogtreecommitdiff
path: root/lib/ext2fs/unix_io.c
diff options
context:
space:
mode:
authorLukas Czerner <lczerner@redhat.com>2010-11-18 03:38:37 +0000
committerTheodore Ts'o <tytso@mit.edu>2010-11-22 20:41:46 -0500
commitd866599ab4955858b1541f0891b1b165ba66493a (patch)
tree8044870624bd8bc18a6ac26a3abef8f7064a0343 /lib/ext2fs/unix_io.c
parente90a59ed434d6c5e38dd148aa4ba5b22b8f7eb24 (diff)
downloade2fsprogs-d866599ab4955858b1541f0891b1b165ba66493a.tar.gz
e2fsprogs: Add CHANNEL_FLAGS_DISCARD_ZEROES flag for io_manager
When the device have discard support and simultaneously discard zeroes data (and it is properly advertised), then we can take advantage of such behavior in several e2fsprogs tools. Add new flag CHANNEL_FLAGS_DISCARD_ZEROES for struct_io_channel so each io_manager can take advantage of this. The flag is properly set according to BLKDISCARDZEROES ioctl in unix_open. Also remove old mke2fs_discard_zeroes_data() function and substitute it with helper which test this flag. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/unix_io.c')
-rw-r--r--lib/ext2fs/unix_io.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 2302374c..82e0fe44 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -425,12 +425,18 @@ static errcode_t flush_cached_blocks(io_channel channel,
}
#endif /* NO_IO_CACHE */
+#ifdef __linux__
+#ifndef BLKDISCARDZEROES
+#define BLKDISCARDZEROES _IO(0x12,124)
+#endif
+#endif
+
static errcode_t unix_open(const char *name, int flags, io_channel *channel)
{
io_channel io = NULL;
struct unix_private_data *data = NULL;
errcode_t retval;
- int open_flags;
+ int open_flags, zeroes = 0;
struct stat st;
#ifdef __linux__
struct utsname ut;
@@ -487,6 +493,12 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
}
#endif
+#ifdef BLKDISCARDZEROES
+ ioctl(data->dev, BLKDISCARDZEROES, &zeroes);
+ if (zeroes)
+ io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES;
+#endif
+
#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
/*
* Some operating systems require that the buffers be aligned,