Skip to contentSkip to conversation

ocfs2: Refactor read-only checks to use ocfs2_emergency_state

PATCH Superseded Ahmet Eray Karadag 2 participants 7 messages Nov 18, 2025 – Dec 1, 2025 OCFS2

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover ocfs2: Refactor read-only checks to use ocfs2_emergency_state

Hi all,

Following the fix for the make_bad_inode validation failure (syzbot ID:
b93b65ee321c97861072), this separate series introduces a new helper function, ocfs2_emergency_state(), to improve and centralize read-only and error state checking.

This is modeled after the ext4_emergency_state() pattern, providing a single, unified location for checking all filesystem-level emergency conditions. This makes the code cleaner and ensures that any future checks (e.g., for fatal error states) can be added in one place.

This series is structured as follows:

1. The first patch introduces the ocfs2_emergency_state() helper (currently checking for -EROFS) and applies it to ocfs2_setattr to provide a "fail-fast" mechanism, as suggested by Albin Babu Varghese.
2. The second patch completes the refactoring by converting all remaining read-only checks throughout OCFS2 to use this new helper.

Ahmet Eray Karadag (2):
ocfs2: Add ocfs2_emergency_state helper and apply to setattr
ocfs2: Convert remaining read-only checks to ocfs2_emergency_state

 fs/ocfs2/buffer_head_io.c |  4 ++--
 fs/ocfs2/file.c           | 23 ++++++++++++++++-------
 fs/ocfs2/inode.c          |  3 +--
 fs/ocfs2/move_extents.c   |  5 +++--
 fs/ocfs2/ocfs2.h          |  8 ++++++++
 fs/ocfs2/resize.c         |  8 +++++---
 fs/ocfs2/super.c          |  2 +-
 7 files changed, 36 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 ocfs2: Add ocfs2_emergency_state helper and apply to setattr

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/file.c  | 6 ++++++
 fs/ocfs2/ocfs2.h | 8 ++++++++
 2 files changed, 14 insertions(+)
fs/ocfs2/file.c +6 -0
index 21d797ccccd0..03a98985ac92 100644
@@ -1137,6 +1137,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 					from_kgid(&init_user_ns, attr->ia_gid) : 0);
 
 	/* ensuring we don't even attempt to truncate a symlink */
+	status = ocfs2_emergency_state(osb);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail;
+	}
+
 	if (S_ISLNK(inode->i_mode))
 		attr->ia_valid &= ~ATTR_SIZE;
 
fs/ocfs2/ocfs2.h +8 -0
index 6aaa94c554c1..2ac16632dd19 100644
@@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
 	return ret;
 }
 
+static inline int ocfs2_emergency_state(struct ocfs2_super *osb)
+{
+	if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) {
+		return -EROFS;
+	}
+	return 0;
+}
+
 static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
 {
 	return (osb->s_feature_incompat &
Signature · 1 line
2.43.0
reviewer
#2 lore raw

Re: [PATCH 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr

Quoted 33 lines · Ahmet Eray Karadag

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/file.c  | 6 ++++++
 fs/ocfs2/ocfs2.h | 8 ++++++++
 2 files changed, 14 insertions(+)
fs/ocfs2/file.c +0 -0
index 21d797ccccd0..03a98985ac92 100644

fs/ocfs2/file.c int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 1145

Quoted 9 lines
fs/ocfs2/file.c +6 -0
@@ -1137,6 +1137,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 					from_kgid(&init_user_ns, attr->ia_gid) : 0);
 
 	/* ensuring we don't even attempt to truncate a symlink */
+	status = ocfs2_emergency_state(osb);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail;
+	}
+

I prefer the ext4_emerency_state() style, using "if (unlikely(status))" here.

Quoted 9 lines
fs/ocfs2/file.c +0 -0
 	if (S_ISLNK(inode->i_mode))
 		attr->ia_valid &= ~ATTR_SIZE;
 
fs/ocfs2/ocfs2.h +0 -0
index 6aaa94c554c1..2ac16632dd19 100644
@@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
 	return ret;

fs/ocfs2/ocfs2.h static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb) · line 690

Quoted 10 lines
fs/ocfs2/ocfs2.h +8 -0
 }
 
+static inline int ocfs2_emergency_state(struct ocfs2_super *osb)
+{
+	if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) {
+		return -EROFS;
+	}
+	return 0;
+}
+

calling ocfs2_is_[soft|hard]_readonly() is a little expensive because it involves acquiring the spinlock osb->osb_lock twice. In my view, we could introduce a new function, such as ocfs2_is_readonly():

```
static inline int ocfs2_is_readonly(struct ocfs2_super *osb)
{
        int ret;

        spin_lock(&osb->osb_lock);
        ret = osb->osb_flags & (OCFS2_OSB_SOFT_RO | OCFS2_OSB_HARD_RO);
        spin_unlock(&osb->osb_lock);

        return ret
}
```

Thanks,
Heming

Quoted 6 lines
fs/ocfs2/ocfs2.h +0 -0
 static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
 {
 	return (osb->s_feature_incompat &
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr

Quoted 57 lines · Heming Zhao
Quoted 33 lines · Ahmet Eray Karadag

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/file.c  | 6 ++++++
 fs/ocfs2/ocfs2.h | 8 ++++++++
 2 files changed, 14 insertions(+)
fs/ocfs2/file.c +0 -0
index 21d797ccccd0..03a98985ac92 100644

fs/ocfs2/file.c int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 1145

Quoted 9 lines
fs/ocfs2/file.c +6 -0
@@ -1137,6 +1137,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 					from_kgid(&init_user_ns, attr->ia_gid) : 0);
 
 	/* ensuring we don't even attempt to truncate a symlink */
+	status = ocfs2_emergency_state(osb);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail;
+	}
+

I prefer the ext4_emerency_state() style, using "if (unlikely(status))" here.

Quoted 11 lines
fs/ocfs2/file.c +0 -0
 	if (S_ISLNK(inode->i_mode))
 		attr->ia_valid &= ~ATTR_SIZE;
 
fs/ocfs2/ocfs2.h +0 -0
index 6aaa94c554c1..2ac16632dd19 100644
@@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
 	return ret;
 }
 
Quoted 12 lines

fs/ocfs2/ocfs2.h static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb) · line 690

Quoted 8 lines
fs/ocfs2/ocfs2.h +8 -0
+static inline int ocfs2_emergency_state(struct ocfs2_super *osb)
+{
+	if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) {
+		return -EROFS;
+	}
+	return 0;
+}
+

calling ocfs2_is_[soft|hard]_readonly() is a little expensive because it involves acquiring the spinlock osb->osb_lock twice. In my view, we could introduce a new function, such as ocfs2_is_readonly():

In ext4, the helper functions check read-only flags without acquiring a lock. Would it be problematic to do the same in ocfs2?

Quoted 14 lines
```
static inline int ocfs2_is_readonly(struct ocfs2_super *osb)
{
        int ret;

        spin_lock(&osb->osb_lock);
        ret = osb->osb_flags & (OCFS2_OSB_SOFT_RO | OCFS2_OSB_HARD_RO);
        spin_unlock(&osb->osb_lock);

        return ret
}
```
Quoted 9 lines

Thanks,
Heming

Quoted 6 lines
fs/ocfs2/ocfs2.h +0 -0
 static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
 {
 	return (osb->s_feature_incompat &
Signature · 1 line
2.43.0

I agree with the other comments. We will send v2.

reviewer
#4 lore raw

Re: [PATCH 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr

Quoted 70 lines · Ahmet Eray Karadag
Quoted 57 lines · Heming Zhao
Quoted 33 lines · Ahmet Eray Karadag

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/file.c  | 6 ++++++
 fs/ocfs2/ocfs2.h | 8 ++++++++
 2 files changed, 14 insertions(+)
fs/ocfs2/file.c +0 -0
index 21d797ccccd0..03a98985ac92 100644

fs/ocfs2/file.c int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 1145

Quoted 9 lines
fs/ocfs2/file.c +6 -0
@@ -1137,6 +1137,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 					from_kgid(&init_user_ns, attr->ia_gid) : 0);
 
 	/* ensuring we don't even attempt to truncate a symlink */
+	status = ocfs2_emergency_state(osb);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail;
+	}
+

I prefer the ext4_emerency_state() style, using "if (unlikely(status))" here.

Quoted 11 lines
fs/ocfs2/file.c +0 -0
 	if (S_ISLNK(inode->i_mode))
 		attr->ia_valid &= ~ATTR_SIZE;
 
fs/ocfs2/ocfs2.h +0 -0
index 6aaa94c554c1..2ac16632dd19 100644
@@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
 	return ret;
 }
 
Quoted 12 lines

fs/ocfs2/ocfs2.h static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb) · line 690

Quoted 8 lines
fs/ocfs2/ocfs2.h +8 -0
+static inline int ocfs2_emergency_state(struct ocfs2_super *osb)
+{
+	if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) {
+		return -EROFS;
+	}
+	return 0;
+}
+

calling ocfs2_is_[soft|hard]_readonly() is a little expensive because it involves acquiring the spinlock osb->osb_lock twice. In my view, we could introduce a new function, such as ocfs2_is_readonly():

Quoted 2 lines

In ext4, the helper functions check read-only flags without acquiring a lock. Would it be problematic to do the same in ocfs2?

Comparing with the ext4 code, in my view, OCFS2 incorrectly mixes the normal read-only state with the emergency read-only state. For the minimal code change, we must currently acquire the spinlock to access osb->osb_flags.

Thanks,
Heming

Quoted 24 lines
Quoted 14 lines
```
static inline int ocfs2_is_readonly(struct ocfs2_super *osb)
{
        int ret;

        spin_lock(&osb->osb_lock);
        ret = osb->osb_flags & (OCFS2_OSB_SOFT_RO | OCFS2_OSB_HARD_RO);
        spin_unlock(&osb->osb_lock);

        return ret
}
```
Quoted 9 lines

Thanks,
Heming

Quoted 6 lines
fs/ocfs2/ocfs2.h +0 -0
 static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
 {
 	return (osb->s_feature_incompat &
Signature · 1 line
2.43.0

I agree with the other comments. We will send v2.

#5 lore raw

PATCH 2/2 ocfs2: Convert remaining read-only checks to ocfs2_emergency_state

In reply to Ahmet Eray Karadag

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/buffer_head_io.c |  4 ++--
 fs/ocfs2/file.c           | 17 ++++++++++-------
 fs/ocfs2/inode.c          |  3 +--
 fs/ocfs2/move_extents.c   |  5 +++--
 fs/ocfs2/resize.c         |  8 +++++---
 fs/ocfs2/super.c          |  2 +-
 6 files changed, 22 insertions(+), 17 deletions(-)
fs/ocfs2/buffer_head_io.c +2 -2
index 8f714406528d..c43d4a58aa9a 100644
@@ -434,8 +434,8 @@ int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
 	BUG_ON(buffer_jbd(bh));
 	ocfs2_check_super_or_backup(osb->sb, bh->b_blocknr);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) {
-		ret = -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0) {
 		mlog_errno(ret);
 		goto out;
 	}
fs/ocfs2/file.c +10 -7
index 03a98985ac92..c299b73cf4ec 100644
@@ -179,8 +179,9 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
 			      file->f_path.dentry->d_name.name,
 			      (unsigned long long)datasync);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;
 
 	err = file_write_and_wait_range(file, start, end);
 	if (err)
@@ -209,7 +210,7 @@ int ocfs2_should_update_atime(struct inode *inode,
 	struct timespec64 now;
 	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
+	if (ocfs2_emergency_state(osb))
 		return 0;
 
 	if ((inode->i_flags & S_NOATIME) ||
@@ -1949,8 +1950,9 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
 	handle_t *handle;
 	unsigned long long max_off = inode->i_sb->s_maxbytes;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;
 
 	inode_lock(inode);
 
@@ -2713,8 +2715,9 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
 		return -EINVAL;
 	if (!ocfs2_refcount_tree(osb))
 		return -EOPNOTSUPP;
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;
 
 	/* Lock both files against IO */
 	ret = ocfs2_reflink_inodes_lock(inode_in, &in_bh, inode_out, &out_bh);
fs/ocfs2/inode.c +1 -2
index 415ad29ec758..dca8db61bc0f 100644
@@ -1586,8 +1586,7 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb,
 	trace_ocfs2_filecheck_repair_inode_block(
 		(unsigned long long)bh->b_blocknr);
 
-	if (ocfs2_is_hard_readonly(OCFS2_SB(sb)) ||
-	    ocfs2_is_soft_readonly(OCFS2_SB(sb))) {
+	if (ocfs2_emergency_state(OCFS2_SB(sb))) {
 		mlog(ML_ERROR,
 		     "Filecheck: cannot repair dinode #%llu "
 		     "on readonly filesystem\n",
fs/ocfs2/move_extents.c +3 -2
index 86f2631e6360..f586593b3a63 100644
@@ -898,8 +898,9 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context)
 	struct buffer_head *di_bh = NULL;
 	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	status = ocfs2_emergency_state(osb);
+	if (status < 0)
+		return status;
 
 	inode_lock(inode);
 
fs/ocfs2/resize.c +5 -3
index b0733c08ed13..d9f5e1d065b4 100644
@@ -276,8 +276,9 @@ int ocfs2_group_extend(struct inode * inode, int new_clusters)
 	u32 first_new_cluster;
 	u64 lgd_blkno;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;
 
 	if (new_clusters < 0)
 		return -EINVAL;
@@ -466,7 +467,8 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
 	u16 cl_bpc;
 	u64 bg_ptr;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
 		return -EROFS;
 
 	main_bm_inode = ocfs2_get_system_file_inode(osb,
fs/ocfs2/super.c +1 -1
index 53daa4482406..c6019d260efc 100644
@@ -2487,7 +2487,7 @@ static int ocfs2_handle_error(struct super_block *sb)
 		rv = -EIO;
 	} else { /* default option */
 		rv = -EROFS;
-		if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
+		if (sb_rdonly(sb) && ocfs2_emergency_state(osb))
 			return rv;
 
 		pr_crit("OCFS2: File system is now read-only.\n");
Signature · 1 line
2.43.0
reviewer
#6 lore raw

Re: [PATCH 2/2] ocfs2: Convert remaining read-only checks to ocfs2_emergency_state

Quoted 36 lines · Ahmet Eray Karadag

To centralize error checking, follow the pattern of other filesystems like ext4 (which uses ext4_emergency_state()), and prepare for future enhancements, this patch introduces a new helper function:
ocfs2_emergency_state().

The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set.

This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place.

This patch also adds this new check to the beginning of ocfs2_setattr(). This ensures that operations like ftruncate (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state.

---
 fs/ocfs2/buffer_head_io.c |  4 ++--
 fs/ocfs2/file.c           | 17 ++++++++++-------
 fs/ocfs2/inode.c          |  3 +--
 fs/ocfs2/move_extents.c   |  5 +++--
 fs/ocfs2/resize.c         |  8 +++++---
 fs/ocfs2/super.c          |  2 +-
 6 files changed, 22 insertions(+), 17 deletions(-)
fs/ocfs2/buffer_head_io.c +0 -0
index 8f714406528d..c43d4a58aa9a 100644

fs/ocfs2/buffer_head_io.c int ocfs2_write_super_or_backup(struct ocfs2_super *osb, · line 441

Quoted 10 lines
fs/ocfs2/buffer_head_io.c +2 -2
@@ -434,8 +434,8 @@ int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
 	BUG_ON(buffer_jbd(bh));
 	ocfs2_check_super_or_backup(osb->sb, bh->b_blocknr);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) {
-		ret = -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0) {
 		mlog_errno(ret);
 		goto out;
 	}

as comment in patch [1/2], I prefer "if (unlikely(ret))" here.

fs/ocfs2/file.c static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end, · line 184

Quoted 13 lines
fs/ocfs2/file.c +3 -2
index 03a98985ac92..c299b73cf4ec 100644
@@ -179,8 +179,9 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
 			      file->f_path.dentry->d_name.name,
 			      (unsigned long long)datasync);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;

ditto

fs/ocfs2/file.c int ocfs2_should_update_atime(struct inode *inode, · line 214

Quoted 10 lines
fs/ocfs2/file.c +1 -1
 	err = file_write_and_wait_range(file, start, end);
 	if (err)
@@ -209,7 +210,7 @@ int ocfs2_should_update_atime(struct inode *inode,
 	struct timespec64 now;
 	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
+	if (ocfs2_emergency_state(osb))
 		return 0;

ditto

fs/ocfs2/file.c static int __ocfs2_change_file_space(struct file *file, struct inode *inode, · line 1955

Quoted 11 lines
fs/ocfs2/file.c +3 -2
 	if ((inode->i_flags & S_NOATIME) ||
@@ -1949,8 +1950,9 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
 	handle_t *handle;
 	unsigned long long max_off = inode->i_sb->s_maxbytes;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;

ditto

fs/ocfs2/file.c static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, · line 2720

Quoted 12 lines
fs/ocfs2/file.c +3 -2
 	inode_lock(inode);
 
@@ -2713,8 +2715,9 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
 		return -EINVAL;
 	if (!ocfs2_refcount_tree(osb))
 		return -EOPNOTSUPP;
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;

ditto

Quoted 8 lines
fs/ocfs2/file.c +0 -0
 	/* Lock both files against IO */
 	ret = ocfs2_reflink_inodes_lock(inode_in, &in_bh, inode_out, &out_bh);
fs/ocfs2/inode.c +0 -0
index 415ad29ec758..dca8db61bc0f 100644

fs/ocfs2/inode.c static int ocfs2_filecheck_repair_inode_block(struct super_block *sb, · line 1589

Quoted 6 lines
fs/ocfs2/inode.c +1 -2
@@ -1586,8 +1586,7 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb,
 	trace_ocfs2_filecheck_repair_inode_block(
 		(unsigned long long)bh->b_blocknr);
 
-	if (ocfs2_is_hard_readonly(OCFS2_SB(sb)) ||
-	    ocfs2_is_soft_readonly(OCFS2_SB(sb))) {
+	if (ocfs2_emergency_state(OCFS2_SB(sb))) {

ditto

Quoted 8 lines
fs/ocfs2/inode.c +0 -0
 		mlog(ML_ERROR,
 		     "Filecheck: cannot repair dinode #%llu "
 		     "on readonly filesystem\n",
fs/ocfs2/move_extents.c +0 -0
index 86f2631e6360..f586593b3a63 100644

fs/ocfs2/move_extents.c static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) · line 903

Quoted 8 lines
fs/ocfs2/move_extents.c +3 -2
@@ -898,8 +898,9 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context)
 	struct buffer_head *di_bh = NULL;
 	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	status = ocfs2_emergency_state(osb);
+	if (status < 0)
+		return status;

ditto

Quoted 8 lines
fs/ocfs2/move_extents.c +0 -0
 	inode_lock(inode);
 
fs/ocfs2/resize.c +0 -0
index b0733c08ed13..d9f5e1d065b4 100644

fs/ocfs2/resize.c int ocfs2_group_extend(struct inode * inode, int new_clusters) · line 281

Quoted 8 lines
fs/ocfs2/resize.c +3 -2
@@ -276,8 +276,9 @@ int ocfs2_group_extend(struct inode * inode, int new_clusters)
 	u32 first_new_cluster;
 	u64 lgd_blkno;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
-		return -EROFS;
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
+		return ret;

ditto

fs/ocfs2/resize.c int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input) · line 472

Quoted 11 lines
fs/ocfs2/resize.c +2 -1
 	if (new_clusters < 0)
 		return -EINVAL;
@@ -466,7 +467,8 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
 	u16 cl_bpc;
 	u64 bg_ptr;
 
-	if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
+	ret = ocfs2_emergency_state(osb);
+	if (ret < 0)
 		return -EROFS;

ditto

Thanks,
Heming

Quoted 19 lines
fs/ocfs2/resize.c +0 -0
 	main_bm_inode = ocfs2_get_system_file_inode(osb,
fs/ocfs2/super.c +1 -1
index 53daa4482406..c6019d260efc 100644
@@ -2487,7 +2487,7 @@ static int ocfs2_handle_error(struct super_block *sb)
 		rv = -EIO;
 	} else { /* default option */
 		rv = -EROFS;
-		if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
+		if (sb_rdonly(sb) && ocfs2_emergency_state(osb))
 			return rv;
 
 		pr_crit("OCFS2: File system is now read-only.\n");
Signature · 1 line
2.43.0