Commit dd8e7217 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: replay dir_index items before other items

A user reported a bug where his log would not replay because he was getting
-EEXIST back.  This was because he had a file moved into a directory that was
logged.  What happens is the file had a lower inode number, and so it is
processed first when replaying the log, and so we add the inode ref in for the
directory it was moved to.  But then we process the directories DIR_INDEX item
and try to add the inode ref for that inode and it fails because we already
added it when we replayed the inode.  To solve this problem we need to just
process any DIR_INDEX items we have in the log first so this all is taken care
of, and then we can replay the rest of the items.  With this patch my reproducer
can remount the file system properly instead of erroring out.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent a5874ce6
...@@ -93,7 +93,8 @@ ...@@ -93,7 +93,8 @@
*/ */
#define LOG_WALK_PIN_ONLY 0 #define LOG_WALK_PIN_ONLY 0
#define LOG_WALK_REPLAY_INODES 1 #define LOG_WALK_REPLAY_INODES 1
#define LOG_WALK_REPLAY_ALL 2 #define LOG_WALK_REPLAY_DIR_INDEX 2
#define LOG_WALK_REPLAY_ALL 3
static int btrfs_log_inode(struct btrfs_trans_handle *trans, static int btrfs_log_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct inode *inode, struct btrfs_root *root, struct inode *inode,
...@@ -2027,6 +2028,15 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb, ...@@ -2027,6 +2028,15 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
if (ret) if (ret)
break; break;
} }
if (key.type == BTRFS_DIR_INDEX_KEY &&
wc->stage == LOG_WALK_REPLAY_DIR_INDEX) {
ret = replay_one_dir_item(wc->trans, root, path,
eb, i, &key);
if (ret)
break;
}
if (wc->stage < LOG_WALK_REPLAY_ALL) if (wc->stage < LOG_WALK_REPLAY_ALL)
continue; continue;
...@@ -2048,8 +2058,7 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb, ...@@ -2048,8 +2058,7 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
eb, i, &key); eb, i, &key);
if (ret) if (ret)
break; break;
} else if (key.type == BTRFS_DIR_ITEM_KEY || } else if (key.type == BTRFS_DIR_ITEM_KEY) {
key.type == BTRFS_DIR_INDEX_KEY) {
ret = replay_one_dir_item(wc->trans, root, path, ret = replay_one_dir_item(wc->trans, root, path,
eb, i, &key); eb, i, &key);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment