2014-07-24 22:41:33

by yuanh

[permalink] [raw]
Subject: linux fsync behaviour

Hi all,

Two file descriptors are pointing the same file. When fsync is called on
one fd, the data written by the other fd will also be flushed? We are using
linux XFS.

Thanks,

-Yuan



--
View this message in context: http://linux-kernel.2935.n7.nabble.com/linux-fsync-behaviour-tp911707.html
Sent from the Linux Kernel mailing list archive at Nabble.com.


2014-07-25 01:18:33

by Dave Chinner

[permalink] [raw]
Subject: Re: linux fsync behaviour

On Thu, Jul 24, 2014 at 03:41:31PM -0700, yuanh wrote:
> Hi all,
>
> Two file descriptors are pointing the same file. When fsync is called on
> one fd, the data written by the other fd will also be flushed? We are using
> linux XFS.

Yes.

-Dave.
--
Dave Chinner
[email protected]

2014-07-25 07:38:30

by Anton Altaparmakov

[permalink] [raw]
Subject: Re: linux fsync behaviour

Hi,

On 25 Jul 2014, at 02:17, Dave Chinner <[email protected]> wrote:
> On Thu, Jul 24, 2014 at 03:41:31PM -0700, yuanh wrote:
>> Hi all,
>>
>> Two file descriptors are pointing the same file. When fsync is called on
>> one fd, the data written by the other fd will also be flushed? We are using
>> linux XFS.
>
> Yes.

But beware of the common mistake of using fwrite + fsync which does not actually do what you intend at all and you must instead use fwrite + fflush + fsync... If you are using write(2) then just fsync is obviously fine.

Best regards,

Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
University of Cambridge Information Services, Roger Needham Building
7 JJ Thomson Avenue, Cambridge, CB3 0RB, UK