Maxim Patlasov <mpatla...@virtuozzo.com> writes:

> While handling fallocate(), ext4 firstly calls ext4_update_inode_size(),
> then ext4_mark_inode_dirty().  Both update only in-core state. After
> fallocate(), ploop updates BAT bypassing vfs layer (submit bio to
> underlying block device). Hence, it's possible that BAT is already
> updated, but i_size in now written to the disk yet. If a crash happens
> in the middle, BAT points beyond end-of-file, i.e. ploop image is
> corrupted.
>
> The patch fixes the problem by ordinary fsync(). This is OK because
> we fallocate relatively seldom (PLOOP_MAX_PREALLOC=128MB) and also
> because no dirty pages to sync (all I/O is direct).
>
> https://jira.sw.ru/browse/PSBM-45326
ACK
>
> Signed-off-by: Maxim Patlasov <mpatla...@virtuozzo.com>
> ---
>  drivers/block/ploop/io_direct.c |    6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
> index 0c7e0c4..8032999 100644
> --- a/drivers/block/ploop/io_direct.c
> +++ b/drivers/block/ploop/io_direct.c
> @@ -376,6 +376,7 @@ cached_submit(struct ploop_io *io, iblock_t iblk, struct 
> ploop_request * preq,
>       loff_t new_size;
>       loff_t used_pos;
>       bool may_fallocate = io->files.file->f_op->fallocate &&
> +             io->files.file->f_op->fsync &&
>               io->files.flags & EXT4_EXTENTS_FL;
>  
>       trace_cached_submit(preq);
> @@ -404,6 +405,11 @@ try_again:
>                               }
>                       }
>  
> +                     /* flush new i_size to disk */
> +                     err = io->files.file->f_op->FOP_FSYNC(io->files.file, 
> 0);
> +                     if (err)
> +                             goto end_write;
> +
>                       io->prealloced_size = prealloc;
>               }
>  

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to