Skip to content

Commit

Permalink
Btrfs: set inode's logged_trans/last_log_commit after ranged fsync
Browse files Browse the repository at this point in the history
When a ranged fsync finishes if there are still extent maps in the modified
list, still set the inode's logged_trans and last_log_commit. This is important
in case an inode is fsync'ed and unlinked in the same transaction, to ensure its
inode ref gets deleted from the log and the respective dentries in its parent
are deleted too from the log (if the parent directory was fsync'ed in the same
transaction).

Instead make btrfs_inode_in_log() return false if the list of modified extent
maps isn't empty.

This is an incremental on top of the v4 version of the patch:

    "Btrfs: fix fsync data loss after a ranged fsync"

which was added to its v5, but didn't make it on time.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
fdmanana authored and masoncl committed Sep 16, 2014
1 parent b0d5d10 commit 125c4cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
13 changes: 11 additions & 2 deletions fs/btrfs/btrfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,17 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
BTRFS_I(inode)->last_sub_trans <=
BTRFS_I(inode)->last_log_commit &&
BTRFS_I(inode)->last_sub_trans <=
BTRFS_I(inode)->root->last_log_commit)
return 1;
BTRFS_I(inode)->root->last_log_commit) {
/*
* After a ranged fsync we might have left some extent maps
* (that fall outside the fsync's range). So return false
* here if the list isn't empty, to make sure btrfs_log_inode()
* will be called and process those extent maps.
*/
smp_mb();
if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents))
return 1;
}
return 0;
}

Expand Down
14 changes: 2 additions & 12 deletions fs/btrfs/tree-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -4093,18 +4093,8 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
}
}

write_lock(&em_tree->lock);
/*
* If we're doing a ranged fsync and there are still modified extents
* in the list, we must run on the next fsync call as it might cover
* those extents (a full fsync or an fsync for other range).
*/
if (list_empty(&em_tree->modified_extents)) {
BTRFS_I(inode)->logged_trans = trans->transid;
BTRFS_I(inode)->last_log_commit =
BTRFS_I(inode)->last_sub_trans;
}
write_unlock(&em_tree->lock);
BTRFS_I(inode)->logged_trans = trans->transid;
BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans;
out_unlock:
if (unlikely(err))
btrfs_put_logged_extents(&logged_list);
Expand Down

0 comments on commit 125c4cf

Please sign in to comment.