Skip to contentSkip to conversation

Btrfs: avoid transaction stuff when readonly

RFC PATCH Superseded liubo 3 participants 6 messages Dec 1, 2010 – Dec 2, 2010 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

liubo

author
#0 lore raw

RFC PATCH v2 2/4 Btrfs: avoid transaction stuff when readonly

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

---
 fs/btrfs/transaction.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/btrfs/transaction.c +3 -0
index 1fffbc0..14a597d 100644
@@ -181,6 +181,9 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
 	struct btrfs_trans_handle *h;
 	struct btrfs_transaction *cur_trans;
 	int ret;
+
+	if (root->fs_info->sb->s_flags & MS_RDONLY)
+		return ERR_PTR(-EROFS);
 again:
 	h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
 	if (!h)
Signature · 1 line
1.7.1
author
#1 lore raw
Quoted 3 lines · liubo

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

This patch may lead btrfs panic.

Since btrfs allows transaction under readonly fs state, which is a bit weird, btrfs does not even check the returned transaction from start_transaction, although it may return -ENOMEM.

With this patch, if btrfs flips readonly or is mounted readonly, to start a transaction will get a -EROFS. So we needs to check transaction more carefully, rather than just leave it alone.

thanks,
Liu Bo

Quoted 19 lines
---
 fs/btrfs/transaction.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/btrfs/transaction.c +3 -0
index 1fffbc0..14a597d 100644
@@ -181,6 +181,9 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
 	struct btrfs_trans_handle *h;
 	struct btrfs_transaction *cur_trans;
 	int ret;
+
+	if (root->fs_info->sb->s_flags & MS_RDONLY)
+		return ERR_PTR(-EROFS);
 again:
 	h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
 	if (!h)
#2 lore raw
Quoted 10 lines · liubo
Quoted 3 lines · liubo

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

This patch may lead btrfs panic.

Since btrfs allows transaction under readonly fs state, which is a bit weird, btrfs does not even check the returned transaction from start_transaction, although it may return -ENOMEM.

btrfs may do log replay even mount as readonly.

author
#3 lore raw
Quoted 5 lines · Zheng
Quoted 4 lines · liubo
Quoted 3 lines · liubo

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

Quoted 7 lines
Quoted 5 lines

This patch may lead btrfs panic.

Since btrfs allows transaction under readonly fs state, which is a bit weird, btrfs does not even check the returned transaction from start_transaction, although it may return -ENOMEM.

btrfs may do log replay even mount as readonly.

Yeah, it it right.

log replay maybe does take place when btrfs is mounted as readonly, but after the FS is broken, is btrfs willing to do log replay in such case?

thanks,
Liu Bo

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Yan, Zheng
Quoted 6 lines · Zheng
Quoted 5 lines · liubo
Quoted 3 lines · liubo

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

Quoted 8 lines
Quoted 5 lines

This patch may lead btrfs panic.

Since btrfs allows transaction under readonly fs state, which is a bit weird, btrfs does not even check the returned transaction from start_transaction, although it may return -ENOMEM.

btrfs may do log replay even mount as readonly.

What part is logged besides tree roots and/or superblocks?

author
#5 lore raw
Quoted 8 lines · Mike Fedyk
Quoted 7 lines · Zheng
Quoted 6 lines · liubo
Quoted 3 lines · liubo

When the filesystem is readonly, avoid transaction stuff by checking MS_RDONLY at start transaction time.

This patch may lead btrfs panic.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Since btrfs allows transaction under readonly fs state, which is a bit weird, btrfs does not even check the returned transaction from start_transaction, although it may return -ENOMEM.

btrfs may do log replay even mount as readonly.

What part is logged besides tree roots and/or superblocks?

log tree is used for log replay after crash and fast fsync and O_SYNC, it logs inodes.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html