Skip to contentSkip to conversation

hold trans_mutex when using btrfs_record_root_in_trans

PATCH New Yan Zheng 1 participant 1 message Feb 9, 2009 Btrfs file system

lore
Share & tools
lore

Yan Zheng

author
#0 lore raw

PATCH 1/1 hold trans_mutex when using btrfs_record_root_in_trans

Hello,

we should hold the trans_mutex when using
btrfs_record_root_in_trans. Thank you,

---

fs/btrfs/extent-tree.c +2 -0
diff -urp 1/fs/btrfs/extent-tree.c 2/fs/btrfs/extent-tree.c
@@ -5640,7 +5640,9 @@ static noinline int relocate_one_extent(
 			prev_block = block_start;
 		}
 
+		mutex_lock(&extent_root->fs_info->trans_mutex);
 		btrfs_record_root_in_trans(found_root);
+		mutex_unlock(&extent_root->fs_info->trans_mutex);
 		if (ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) {
 			/*
 			 * try to update data extent references while
fs/btrfs/transaction.c +2 -0
diff -urp 1/fs/btrfs/transaction.c 2/fs/btrfs/transaction.c
@@ -688,7 +688,9 @@ static noinline int drop_dirty_roots(str
 		num_bytes -= btrfs_root_used(&dirty->root->root_item);
 		bytes_used = btrfs_root_used(&root->root_item);
 		if (num_bytes) {
+			mutex_lock(&root->fs_info->trans_mutex);
 			btrfs_record_root_in_trans(root);
+			mutex_unlock(&root->fs_info->trans_mutex);
 			btrfs_set_root_used(&root->root_item,
 					    bytes_used - num_bytes);
 		}
fs/btrfs/tree-log.c +2 -0
diff -urp 1/fs/btrfs/tree-log.c 2/fs/btrfs/tree-log.c
@@ -2832,7 +2832,9 @@ again:
 		BUG_ON(!wc.replay_dest);
 
 		wc.replay_dest->log_root = log;
+		mutex_lock(&fs_info->trans_mutex);
 		btrfs_record_root_in_trans(wc.replay_dest);
+		mutex_unlock(&fs_info->trans_mutex);
 		ret = walk_log_tree(trans, log, &wc);
 		BUG_ON(ret);