[Python-Dev] Ext4 data loss
"Martin v. Löwis"
martin at v.loewis.de
Wed Mar 11 09:47:36 CET 2009
>> We already have os.fsync() and os.fdatasync(). Should the sync() (and
>> datasync()?) method be added as an object-oriented convenience?
>
> It's more than an object oriented convenience. fsync() takes a file
> descriptor as argument. Therefore I assume fsync() only syncs the data
> to disk that was written to the file descriptor. [*]
[...]
> [*] Is my assumption correct, anybody?
Not necessarily. In Linux, for many releases, fsync() was really
equivalent to sync() (i.e. flushing all data for all files on all
file systems to disk). It may be that some systems still implement
it that way today.
However, even it it was true, I don't see why a .sync method would
be more than a convenience. An application wishing to sync a file
before close can do
f.flush()
os.fsync(f.fileno)
f.close()
With a sync method, it would become
f.flush()
f.sync()
f.close()
which is *really* nothing more than convenience.
O'd also like to point to the O_SYNC/O_DSYNC/O_RSYNC open(2)
flags. Applications that require durable writes can also chose
to set those on open, and be done.
Regrds,
Martin
More information about the Python-Dev
mailing list