diff mbox

[2/7] e2fsprogs: Add discard_zeroes_data into struct_io_manager

Message ID 1288115658-7004-3-git-send-email-lczerner@redhat.com
State Not Applicable, archived
Headers show

Commit Message

Lukas Czerner Oct. 26, 2010, 5:54 p.m. UTC
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 variable discard_zeroes_data into struct_io_manager structure so
each io_manager can take advantage of this. Set it to 0 by default in
unix_io_manager and test_io_manager and fill it with BLKDISCARDZEROES
ioctl in unix_open.

Every other io_manager which would like to take advantage of this should
set the default to 0 in its io_manager definition and then check and set
the value preferably in *_open() function.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 lib/ext2fs/ext2_io.h |    1 +
 lib/ext2fs/test_io.c |    1 +
 lib/ext2fs/unix_io.c |   12 ++++++++++++
 3 files changed, 14 insertions(+), 0 deletions(-)

Comments

Eric Sandeen Nov. 16, 2010, 6:46 p.m. UTC | #1
On 10/26/10 12:54 PM, Lukas Czerner wrote:
> 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 variable discard_zeroes_data into struct_io_manager structure so
> each io_manager can take advantage of this. Set it to 0 by default in
> unix_io_manager and test_io_manager and fill it with BLKDISCARDZEROES
> ioctl in unix_open.
> 
> Every other io_manager which would like to take advantage of this should
> set the default to 0 in its io_manager definition and then check and set
> the value preferably in *_open() function.

Hm, sticking this in struct_io_manager seems a little bit odd.  Wrong,
even ;).

Maybe this can go in the flags on the fs->io_channel?

-Eric

> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
>  lib/ext2fs/ext2_io.h |    1 +
>  lib/ext2fs/test_io.c |    1 +
>  lib/ext2fs/unix_io.c |   12 ++++++++++++
>  3 files changed, 14 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
> index d202007..cc79fda 100644
> --- a/lib/ext2fs/ext2_io.h
> +++ b/lib/ext2fs/ext2_io.h
> @@ -85,6 +85,7 @@ struct struct_io_manager {
>  					int count, const void *data);
>  	errcode_t (*discard)(io_channel channel, unsigned long long block,
>  			     unsigned long long count, const void *data);
> +	int	discard_zeroes_data;
>  	long	reserved[16];
>  };
>  
> diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
> index 8d887a8..2fac849 100644
> --- a/lib/ext2fs/test_io.c
> +++ b/lib/ext2fs/test_io.c
> @@ -89,6 +89,7 @@ static struct struct_io_manager struct_test_manager = {
>  	test_get_stats,
>  	test_read_blk64,
>  	test_write_blk64,
> +	0,				/* discard zeroes data */
>  };
>  
>  io_manager test_io_manager = &struct_test_manager;
> diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
> index 5b6cdec..b3908dc 100644
> --- a/lib/ext2fs/unix_io.c
> +++ b/lib/ext2fs/unix_io.c
> @@ -133,6 +133,7 @@ static struct struct_io_manager struct_unix_manager = {
>  	unix_read_blk64,
>  	unix_write_blk64,
>  	unix_discard,
> +	0,				/* discard zeroes data */
>  };
>  
>  io_manager unix_io_manager = &struct_unix_manager;
> @@ -425,6 +426,12 @@ 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;
> @@ -487,6 +494,11 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
>  	}
>  #endif
>  
> +#ifdef BLKDISCARDZEROES
> +	ioctl(data->dev, BLKDISCARDZEROES,
> +		&unix_io_manager->discard_zeroes_data);
> +#endif
> +
>  #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>  	/*
>  	 * Some operating systems require that the buffers be aligned,

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index d202007..cc79fda 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -85,6 +85,7 @@  struct struct_io_manager {
 					int count, const void *data);
 	errcode_t (*discard)(io_channel channel, unsigned long long block,
 			     unsigned long long count, const void *data);
+	int	discard_zeroes_data;
 	long	reserved[16];
 };
 
diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
index 8d887a8..2fac849 100644
--- a/lib/ext2fs/test_io.c
+++ b/lib/ext2fs/test_io.c
@@ -89,6 +89,7 @@  static struct struct_io_manager struct_test_manager = {
 	test_get_stats,
 	test_read_blk64,
 	test_write_blk64,
+	0,				/* discard zeroes data */
 };
 
 io_manager test_io_manager = &struct_test_manager;
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 5b6cdec..b3908dc 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -133,6 +133,7 @@  static struct struct_io_manager struct_unix_manager = {
 	unix_read_blk64,
 	unix_write_blk64,
 	unix_discard,
+	0,				/* discard zeroes data */
 };
 
 io_manager unix_io_manager = &struct_unix_manager;
@@ -425,6 +426,12 @@  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;
@@ -487,6 +494,11 @@  static errcode_t unix_open(const char *name, int flags, io_channel *channel)
 	}
 #endif
 
+#ifdef BLKDISCARDZEROES
+	ioctl(data->dev, BLKDISCARDZEROES,
+		&unix_io_manager->discard_zeroes_data);
+#endif
+
 #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 	/*
 	 * Some operating systems require that the buffers be aligned,