Skip to contentSkip to conversation

Btrfs: Protect the readonly flag of block group

PATCH New WuBo 1 participant 1 message Jul 26, 2011 Btrfs file system

lore
Share & tools
lore

WuBo

author
#0 lore raw

PATCH 1/1 Btrfs: Protect the readonly flag of block group

The access for ro in btrfs_block_group_cache should be protected because of the racy lock in relocation.

---
 fs/btrfs/extent-tree.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +7 -4
index 9ee6bd5..cc9bf80 100644
@@ -8143,11 +8143,14 @@ static int set_block_group_ro(struct btrfs_block_group_cache *cache)
 	u64 num_bytes;
 	int ret = -ENOSPC;
 
-	if (cache->ro)
-		return 0;
-
 	spin_lock(&sinfo->lock);
 	spin_lock(&cache->lock);
+
+	if (cache->ro) {
+		ret = 0;
+		goto out;
+	}
+
 	num_bytes = cache->key.offset - cache->reserved - cache->pinned -
 		    cache->bytes_super - btrfs_block_group_used(&cache->item);
 
@@ -8160,7 +8163,7 @@ static int set_block_group_ro(struct btrfs_block_group_cache *cache)
 		cache->ro = 1;
 		ret = 0;
 	}
-
+out:
 	spin_unlock(&cache->lock);
 	spin_unlock(&sinfo->lock);
 	return ret;

-- 1.7.3.1