aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo2018-01-25 12:02:56 -0600
committerGreg Kroah-Hartman2018-02-22 08:45:00 -0600
commit87dc89fc6127643d29fb9606600eb92be41704fb (patch)
tree14403b774fd7d8513a2fde5629c1ea24fbccb979
parent145832a93f28fb80d6cb22b5cd84df5a6e63f47b (diff)
downloadkernel-omap-87dc89fc6127643d29fb9606600eb92be41704fb.tar.gz
kernel-omap-87dc89fc6127643d29fb9606600eb92be41704fb.tar.xz
kernel-omap-87dc89fc6127643d29fb9606600eb92be41704fb.zip
Btrfs: fix unexpected -EEXIST when creating new inode
commit 900c9981680067573671ecc5cbfa7c5770be3a40 upstream. The highest objectid, which is assigned to new inode, is decided at the time of initializing fs roots. However, in cases where log replay gets processed, the btree which fs root owns might be changed, so we have to search it again for the highest objectid, otherwise creating new inode would end up with -EEXIST. cc: <stable@vger.kernel.org> v4.4-rc6+ Fixes: f32e48e92596 ("Btrfs: Initialize btrfs_root->highest_objectid when loading tree root and subvolume roots") Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Reviewed-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/btrfs/tree-log.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 61a37fdff73c..d6359af9789d 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -26,6 +26,7 @@
26#include "print-tree.h" 26#include "print-tree.h"
27#include "backref.h" 27#include "backref.h"
28#include "hash.h" 28#include "hash.h"
29#include "inode-map.h"
29 30
30/* magic values for the inode_only field in btrfs_log_inode: 31/* magic values for the inode_only field in btrfs_log_inode:
31 * 32 *
@@ -5523,6 +5524,23 @@ again:
5523 path); 5524 path);
5524 } 5525 }
5525 5526
5527 if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) {
5528 struct btrfs_root *root = wc.replay_dest;
5529
5530 btrfs_release_path(path);
5531
5532 /*
5533 * We have just replayed everything, and the highest
5534 * objectid of fs roots probably has changed in case
5535 * some inode_item's got replayed.
5536 *
5537 * root->objectid_mutex is not acquired as log replay
5538 * could only happen during mount.
5539 */
5540 ret = btrfs_find_highest_objectid(root,
5541 &root->highest_objectid);
5542 }
5543
5526 key.offset = found_key.offset - 1; 5544 key.offset = found_key.offset - 1;
5527 wc.replay_dest->log_root = NULL; 5545 wc.replay_dest->log_root = NULL;
5528 free_extent_buffer(log->node); 5546 free_extent_buffer(log->node);