[Devel] [PATCH] ploop: force journal commit after dio_post_submit

Dmitry Monakhov dmonakhov at openvz.org
Thu Apr 28 23:54:16 PDT 2016


Maxim Patlasov <mpatlasov at virtuozzo.com> writes:

> Dima,
>
> Just to let me understand the patch better, can you please give a 
> call-path for "forcing transaction commit" in ordinary ext4 life-cycle 
> (without ploop) when it handles O_DIRECT write(2) to an uninitialized 
> extent?
According to POSIX regardless to whenever you perform write via buffered or direct path
you must call fsync(2) in order to guarantee data reach nonvolatile storage.
This is mandatory because even in case O_DIRECT data written may still
be in volatile disk cache.

If you perform O_DIRECT ->ext4_ext_direct_IO
it calls generic __blockdev_direct_IO which has ->end_io callback arg
which is called once all bios completed. In case of ext4 it is
ext4_end_io_dio
If it is allocation or unwritten path it will convert unwritten extent to
written and finally call aio_complete() to signal user about aio completion.
At this moment all extent modification already in journal. So once user
call fsync it will call jbd2_complete_transaction() which is
simply guarantee that transaction becomes stable on disk.


>
> Thanks,
> Maxim
>
> On 04/27/2016 07:42 AM, Dmitry Monakhov wrote:
>> Once we converted extent to initialized it can be part of uncompleted
>> journal transaction, so we have to force transaction commit at some point.
>> The easiest way to do it is to perform unconditional fsync.
>> https://jira.sw.ru/browse/PSBM-45326
>>
>> TODO: This case and others can be optimized by deferring fsync.But this is
>>        subject of another patch.
>>
>> Signed-off-by: Dmitry Monakhov <dmonakhov at openvz.org>
>> ---
>>   drivers/block/ploop/io_direct.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
>> index 8032999..5a2e12a 100644
>> --- a/drivers/block/ploop/io_direct.c
>> +++ b/drivers/block/ploop/io_direct.c
>> @@ -523,6 +523,8 @@ dio_post_submit(struct ploop_io *io, struct ploop_request * preq)
>>   	err = io->files.file->f_op->fallocate(io->files.file,
>>   					      FALLOC_FL_CONVERT_UNWRITTEN,
>>   					      (loff_t)sec << 9, clu_siz);
>> +	if (!err)
>> +		err = io->files.file->f_op->FOP_FSYNC(io->files.file, 0);
In fact we may delay fsync here until FLUSH or FUA preq arrives. But this
is subject for optimization for later patches.
>>   	file_end_write(io->files.file);
>>   	if (err) {
>>   		PLOOP_REQ_SET_ERROR(preq, err);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://lists.openvz.org/pipermail/devel/attachments/20160429/262e479a/attachment.sig>


More information about the Devel mailing list