• Filipe Manana's avatar
    btrfs: ensure fiemap doesn't race with writes when FIEMAP_FLAG_SYNC is given · 418b0902
    Filipe Manana authored
    When FIEMAP_FLAG_SYNC is given to fiemap the expectation is that that
    are no concurrent writes and we get a stable view of the inode's extent
    layout.
    
    When the flag is given we flush all IO (and wait for ordered extents to
    complete) and then lock the inode in shared mode, however that leaves open
    the possibility that a write might happen right after the flushing and
    before locking the inode. So fix this by flushing again after locking the
    inode - we leave the initial flushing before locking the inode to avoid
    holding the lock and blocking other RO operations while waiting for IO
    and ordered extents to complete. The second flushing while holding the
    inode's lock will most of the time do nothing or very little since the
    time window for new writes to have happened is small.
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    418b0902
inode.c 316 KB