diff mbox series

[RFCv1,09/72] libext2fs: Add flush cleanup API

Message ID 81451e5fcf02b502164e0e9f049df940b07de715.1667822611.git.ritesh.list@gmail.com
State Under Review
Delegated to: Theodore Ts'o
Headers show
Series e2fsprogs: Parallel fsck support | expand

Commit Message

Ritesh Harjani (IBM) Nov. 7, 2022, 12:20 p.m. UTC
From: Li Xi <lixi@ddn.com>

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
 lib/ext2fs/ext2_io.h |  2 ++
 lib/ext2fs/undo_io.c | 19 +++++++++++++++++++
 lib/ext2fs/unix_io.c | 24 +++++++++++++++++++++---
 3 files changed, 42 insertions(+), 3 deletions(-)

Comments

Andreas Dilger Nov. 18, 2022, 1:39 p.m. UTC | #1
On Nov 7, 2022, at 06:23, Ritesh Harjani (IBM) <ritesh.list@gmail.com> wrote:
> 
> ´╗┐From: Li Xi <lixi@ddn.com>
> 
> Signed-off-by: Li Xi <lixi@ddn.com>
> Signed-off-by: Wang Shilong <wshilong@ddn.com>
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> lib/ext2fs/ext2_io.h |  2 ++
> lib/ext2fs/undo_io.c | 19 +++++++++++++++++++
> lib/ext2fs/unix_io.c | 24 +++++++++++++++++++++---
> 3 files changed, 42 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
> index 8fe5b323..8cc355be 100644
> --- a/lib/ext2fs/ext2_io.h
> +++ b/lib/ext2fs/ext2_io.h
> @@ -82,6 +82,7 @@ struct struct_io_manager {
>    errcode_t (*write_blk)(io_channel channel, unsigned long block,
>                   int count, const void *data);
>    errcode_t (*flush)(io_channel channel);
> +    errcode_t (*flush_cleanup)(io_channel channel);
>    errcode_t (*write_byte)(io_channel channel, unsigned long offset,
>                int count, const void *data);
>    errcode_t (*set_option)(io_channel channel, const char *option,
> @@ -116,6 +117,7 @@ struct struct_io_manager {
> #define io_channel_read_blk(c,b,n,d)    ((c)->manager->read_blk((c),b,n,d))
> #define io_channel_write_blk(c,b,n,d)    ((c)->manager->write_blk((c),b,n,d))
> #define io_channel_flush(c)        ((c)->manager->flush((c)))
> +#define io_channel_flush_cleanup(c)    ((c)->manager->flush_cleanup((c)))
> #define io_channel_bumpcount(c)        ((c)->refcount++)
> 
> /* io_manager.c */
> diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c
> index f4a6d526..678ff421 100644
> --- a/lib/ext2fs/undo_io.c
> +++ b/lib/ext2fs/undo_io.c
> @@ -1024,6 +1024,24 @@ static errcode_t undo_flush(io_channel channel)
>    return retval;
> }
> 
> +/*
> + * Flush data buffers to disk and cleanup the cache.
> + */
> +static errcode_t undo_flush_cleanup(io_channel channel)
> +{
> +    errcode_t    retval = 0;
> +    struct undo_private_data *data;
> +
> +    EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
> +    data = (struct undo_private_data *) channel->private_data;
> +    EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
> +
> +    if (data->real)
> +        retval = io_channel_flush_cleanup(data->real);
> +
> +    return retval;
> +}
> +
> static errcode_t undo_set_option(io_channel channel, const char *option,
>                 const char *arg)
> {
> @@ -1095,6 +1113,7 @@ static struct struct_io_manager struct_undo_manager = {
>    .read_blk    = undo_read_blk,
>    .write_blk    = undo_write_blk,
>    .flush        = undo_flush,
> +    .flush_cleanup    = undo_flush_cleanup,
>    .write_byte    = undo_write_byte,
>    .set_option    = undo_set_option,
>    .get_stats    = undo_get_stats,
> diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
> index 5b894826..8f8118a3 100644
> --- a/lib/ext2fs/unix_io.c
> +++ b/lib/ext2fs/unix_io.c
> @@ -1173,9 +1173,9 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
> }
> 
> /*
> - * Flush data buffers to disk.
> + * Flush data buffers to disk and invalidate cache if needed
>  */
> -static errcode_t unix_flush(io_channel channel)
> +static errcode_t _unix_flush(io_channel channel, int invalidate)
> {
>    struct unix_private_data *data;
>    errcode_t retval = 0;
> @@ -1185,7 +1185,7 @@ static errcode_t unix_flush(io_channel channel)
>    EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
> 
> #ifndef NO_IO_CACHE
> -    retval = flush_cached_blocks(channel, data, 0);
> +    retval = flush_cached_blocks(channel, data, invalidate);
> #endif
> #ifdef HAVE_FSYNC
>    if (!retval && fsync(data->dev) != 0)
> @@ -1194,6 +1194,22 @@ static errcode_t unix_flush(io_channel channel)
>    return retval;
> }
> 
> +/*
> + * Flush data buffers to disk.
> + */
> +static errcode_t unix_flush(io_channel channel)
> +{
> +    return _unix_flush(channel, 0);
> +}
> +
> +/*
> + * Flush data buffers to disk and invalidate cache.
> + */
> +static errcode_t unix_flush_cleanup(io_channel channel)
> +{
> +    return _unix_flush(channel, 1);
> +}
> +
> static errcode_t unix_set_option(io_channel channel, const char *option,
>                 const char *arg)
> {
> @@ -1383,6 +1399,7 @@ static struct struct_io_manager struct_unix_manager = {
>    .discard    = unix_discard,
>    .cache_readahead    = unix_cache_readahead,
>    .zeroout    = unix_zeroout,
> +    .flush_cleanup    = unix_flush_cleanup,
> };
> 
> io_manager unix_io_manager = &struct_unix_manager;
> @@ -1404,6 +1421,7 @@ static struct struct_io_manager struct_unixfd_manager = {
>    .discard    = unix_discard,
>    .cache_readahead    = unix_cache_readahead,
>    .zeroout    = unix_zeroout,
> +    .flush_cleanup    = unix_flush_cleanup,
> };
> 
> io_manager unixfd_io_manager = &struct_unixfd_manager;
> -- 
> 2.37.3
>
diff mbox series

Patch

diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index 8fe5b323..8cc355be 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -82,6 +82,7 @@  struct struct_io_manager {
 	errcode_t (*write_blk)(io_channel channel, unsigned long block,
 			       int count, const void *data);
 	errcode_t (*flush)(io_channel channel);
+	errcode_t (*flush_cleanup)(io_channel channel);
 	errcode_t (*write_byte)(io_channel channel, unsigned long offset,
 				int count, const void *data);
 	errcode_t (*set_option)(io_channel channel, const char *option,
@@ -116,6 +117,7 @@  struct struct_io_manager {
 #define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
 #define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
 #define io_channel_flush(c) 		((c)->manager->flush((c)))
+#define io_channel_flush_cleanup(c) 	((c)->manager->flush_cleanup((c)))
 #define io_channel_bumpcount(c)		((c)->refcount++)
 
 /* io_manager.c */
diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c
index f4a6d526..678ff421 100644
--- a/lib/ext2fs/undo_io.c
+++ b/lib/ext2fs/undo_io.c
@@ -1024,6 +1024,24 @@  static errcode_t undo_flush(io_channel channel)
 	return retval;
 }
 
+/*
+ * Flush data buffers to disk and cleanup the cache.
+ */
+static errcode_t undo_flush_cleanup(io_channel channel)
+{
+	errcode_t	retval = 0;
+	struct undo_private_data *data;
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	data = (struct undo_private_data *) channel->private_data;
+	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+
+	if (data->real)
+		retval = io_channel_flush_cleanup(data->real);
+
+	return retval;
+}
+
 static errcode_t undo_set_option(io_channel channel, const char *option,
 				 const char *arg)
 {
@@ -1095,6 +1113,7 @@  static struct struct_io_manager struct_undo_manager = {
 	.read_blk	= undo_read_blk,
 	.write_blk	= undo_write_blk,
 	.flush		= undo_flush,
+	.flush_cleanup	= undo_flush_cleanup,
 	.write_byte	= undo_write_byte,
 	.set_option	= undo_set_option,
 	.get_stats	= undo_get_stats,
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 5b894826..8f8118a3 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -1173,9 +1173,9 @@  static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
 }
 
 /*
- * Flush data buffers to disk.
+ * Flush data buffers to disk and invalidate cache if needed
  */
-static errcode_t unix_flush(io_channel channel)
+static errcode_t _unix_flush(io_channel channel, int invalidate)
 {
 	struct unix_private_data *data;
 	errcode_t retval = 0;
@@ -1185,7 +1185,7 @@  static errcode_t unix_flush(io_channel channel)
 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
 
 #ifndef NO_IO_CACHE
-	retval = flush_cached_blocks(channel, data, 0);
+	retval = flush_cached_blocks(channel, data, invalidate);
 #endif
 #ifdef HAVE_FSYNC
 	if (!retval && fsync(data->dev) != 0)
@@ -1194,6 +1194,22 @@  static errcode_t unix_flush(io_channel channel)
 	return retval;
 }
 
+/*
+ * Flush data buffers to disk.
+ */
+static errcode_t unix_flush(io_channel channel)
+{
+	return _unix_flush(channel, 0);
+}
+
+/*
+ * Flush data buffers to disk and invalidate cache.
+ */
+static errcode_t unix_flush_cleanup(io_channel channel)
+{
+	return _unix_flush(channel, 1);
+}
+
 static errcode_t unix_set_option(io_channel channel, const char *option,
 				 const char *arg)
 {
@@ -1383,6 +1399,7 @@  static struct struct_io_manager struct_unix_manager = {
 	.discard	= unix_discard,
 	.cache_readahead	= unix_cache_readahead,
 	.zeroout	= unix_zeroout,
+	.flush_cleanup	= unix_flush_cleanup,
 };
 
 io_manager unix_io_manager = &struct_unix_manager;
@@ -1404,6 +1421,7 @@  static struct struct_io_manager struct_unixfd_manager = {
 	.discard	= unix_discard,
 	.cache_readahead	= unix_cache_readahead,
 	.zeroout	= unix_zeroout,
+	.flush_cleanup	= unix_flush_cleanup,
 };
 
 io_manager unixfd_io_manager = &struct_unixfd_manager;