On 5/19/22 10:00 AM, Tao Liu wrote:
On Thu, May 19, 2022 at 10:52 PM Eric Sandeen
<sandeen(a)redhat.com> wrote:
>
> On 5/19/22 9:39 AM, Tao Liu wrote:
>>> I'm not aware of any "fsync" shell command, unfortunately.
It'd be nice.
>>>
>> Since we are programming in pure shell script, it would be strange if
>> we insert a c program which call fsync on vmcore specifically for the
>> purpose, is there any best practice on how to achieve this?
>
> Yes...
>
>> Thanks,
>> Tao Liu
>>
>>> sync -f syncs the filesystem of the target file, not just the file itself -
>>> but that's fine. [1]
>
> ^^^^ this.
Right, I get the point. Thank you all for the good suggestions and
discussion! I will have a try and test on it, thank you very much!
Great! One caveat I just noticed ...
commit 5679897eb104cec9e99609c3f045a0c20603da4c
Author: Darrick J. Wong <djwong(a)kernel.org>
Date: Sun Jan 30 08:53:16 2022 -0800
vfs: make sync_filesystem return errors from ->sync_fs
Strangely, sync_filesystem ignores the return code from the ->sync_fs
call, which means that syscalls like syncfs(2) never see the error.
This doesn't seem right, so fix that.
Signed-off-by: Darrick J. Wong <djwong(a)kernel.org>
Reviewed-by: Jan Kara <jack(a)suse.cz>
Reviewed-by: Christoph Hellwig <hch(a)lst.de>
Acked-by: Christian Brauner <brauner(a)kernel.org>
I'm not sure how long that flaw has existed, but that fix went into v5.17,
and also to the stable kernel releases.
I think you should still use sync -f (unless you want to write an fsync helper),
but be aware that it might still miss errors on older kernels. :(
-Eric