[QUESTION] multiple fsync() vs single sync()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

In this pseudo-code (extracted from OpenStack Swift [1]):
    fd=open("/tmp/tempfile", O_CREAT | O_WRONLY);
    write(fd, ...);
    fsetxattr(fd, ...);
    fsync(fd);
    rename("/tmp/tempfile", "/data/foobar");
    dirfd = open("/data", O_DIRECTORY | O_RDONLY);
    fsync(dirfd);

OR (the same without temporary file):
    fd=open("/data", O_TMPFILE | O_WRONLY);
    write(fd, ...);
    fsetxattr(fd, ...);
    fsync(fd);
    linkat(AT_FDCWD, "/proc/self/fd/" + fd, AT_FDCWD, "/data/foobar", AT_SYMLINK_FOLLOW);
    dirfd = open("/data", O_DIRECTORY | O_RDONLY);
    fsync(dirfd);


I’m guaranteed that, what ever happen, I’ll have a complete file (data+xattr) or no file at all in the directory /data.

First question: is that a correct assumption or is there any loopholes?

Second question, if I replace the two fsync() by one sync(), do I get the same guarantee?
    fd=open("/data", O_TMPFILE | O_WRONLY);
    write(fd, ...);
    fsetxattr(fd, ...);
    linkat(AT_FDCWD, « /proc/self/fd/" + fd, AT_FDCWD, "/data/foobar", AT_SYMLINK_FOLLOW);
    sync();

>From what I understand of the FAQ [1], write_barrier guarantee that journal (aka log) will be written before the inode (aka metadata). Did I miss something?

Many thanks for your help.

[1] https://github.com/openstack/swift/blob/2.19.0/swift/obj/diskfile.py#L1674-L1694
[2] http://xfs.org/index.php/XFS_FAQ#Q:_What_is_the_problem_with_the_write_cache_on_journaled_filesystems.3F

-- 
Romain





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux