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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 7, 2022, at 06:23, Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> wrote:
> 
> From: Li Xi <lixi@xxxxxxx>
> 
> Signed-off-by: Li Xi <lixi@xxxxxxx>
> Signed-off-by: Wang Shilong <wshilong@xxxxxxx>
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>

Reviewed-by: Andreas Dilger <adilger@xxxxxxxxx>

> ---
> 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
> 




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux