9

I can't find a simple, straight answer about which filesystem metadata operations are actually persisted to the ext4 & xfs filesystem journals. Note that I am not inquiring about what POSIX declares to be "atomic". I'm more concerned about what subset of atomic filesystem operations are effectively durable by virtue of running with a journal enabled without having to bend over backwards and fsync(2) all the time.

Operations I'm fairly certain count:

  • creat(2)
  • link(2)
  • unlink(2)
  • rename(2)
  • mkdir(2)
  • rmdir(2)

Operations I'm not entirely sure about:

  • symlink(2)

The symlink(2) case is the most troubling, since there does not seem to be any straightforward way to fsync(2) or fdatasync(2) the underlying datablocks that store the content of a symlink. Knowing that the journal takes care of this for me would be a relief.

4 Answers 4

2

I'm more concerned about what subset of atomic filesystem operations are effectively durable by virtue of running with a journal enabled without having to bend over backwards and fsync(2) all the time.

None. If you want to be sure that changes persist after a crash, you must fsync, period. Journaling only guarantees that in the event of a crash, none of the operations you listed will be half done.

4
  • I know that if I care I must fsync files and directories to know for certain if the blocks have hit spinning rust, but there is no method I have been able to find that lets me fsync the blocks that back a symlink if it spills out of the inode. At that point my only recourse is to rely upon the journal or never ever use symlinks again for anything that matters. Commented May 11, 2014 at 18:17
  • @naelyn, an fsync() will flush all blocks related to a file, including a non fast symlink. Commented May 11, 2014 at 20:58
  • 2
    how do I open an appropriate file descriptor for use in an fsync that would flush a non-fast symlink's blocks? Commented May 11, 2014 at 21:56
  • 1
    @naelyn, oh yea... good point... might need to ask about that one on the linux-fsdevel mailing list... with hard links I believe you open and sync the directory containing it, maybe symlinks work the same? Commented May 11, 2014 at 22:14
0

For performance reasons, ext4 by default only writes filesystem metadata through the journal.

I believe XFS also journals all metadata transactions, unless you've tweaked the filesystem.

2
  • 1
    Yeah but what is "metadata" specifically? A directory's blocks: sure. The inodes themselves: yep. Symlinks with a target small enough to fit into the inode itself: probably? Symlinks where the target spills over into auxillary blocks: ?????? Commented Apr 29, 2014 at 2:23
  • link would help Commented Jan 30, 2015 at 15:19
0

You are aware that the ext4 journal operates by block number and not operation, correct? "Metadata" would be anything other than that actual data blocks for the given inode, regardless of what operation you used to modify the block in question.

0

xfstests appears to claim that fsync() on a directory should persist any symlinks it contains.

I have not verified this. It is possible I have missed something.

xfstests is used by many developers of Linux filesystems. This test is in the "generic" directory. It implies it should apply to all Linux filesystems. (Or at least, all block device filesystems. The test works by using a special virtual block device).

https://github.com/kdave/xfstests/blob/master/tests/generic/348

# Test creating a symlink, fsync its parent directory, power fail and mount
# again the filesystem. After these steps the symlink should exist and its
# content must match what we specified when we created it (must not be empty
# or point to something else).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.