]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ocfs2: convert remaining read-only checks to ocfs2_emergency_state
authorAhmet Eray Karadag <eraykrdg1@gmail.com>
Wed, 3 Dec 2025 03:34:26 +0000 (06:34 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 11 Dec 2025 00:07:43 +0000 (16:07 -0800)
Now that the centralized `ocfs2_emergency_state()` helper is available,
refactor remaining filesystem-wide checks for `ocfs2_is_soft_readonly` and
`ocfs2_is_hard_readonly` to use this new function.

To ensure strict consistency with the previous behavior and guarantee no
functional changes, the call sites continue to explicitly return -EROFS
when the emergency state is detected.  This standardizes the check logic
while preserving the existing error handling flow.

Link: https://lkml.kernel.org/r/3421641b54ad6b6e4ffca052351b518eacc1bd08.1764728893.git.eraykrdg1@gmail.com
Co-developed-by: Albin Babu Varghese <albinbabuvarghese20@gmail.com>
Signed-off-by: Albin Babu Varghese <albinbabuvarghese20@gmail.com>
Signed-off-by: Ahmet Eray Karadag <eraykrdg1@gmail.com>
Reviewed-by: Heming Zhao <heming.zhao@suse.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: David Hunter <david.hunter.linux@gmail.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Mark Fasheh <mark@fasheh.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/buffer_head_io.c
fs/ocfs2/file.c
fs/ocfs2/inode.c
fs/ocfs2/move_extents.c
fs/ocfs2/resize.c
fs/ocfs2/super.c

index 8f714406528d629f960481176108f73f05ecd763..701d27d908d4b20e6d2995c07d6ddf9f98f78e89 100644 (file)
@@ -434,7 +434,7 @@ 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)) {
+       if (unlikely(ocfs2_emergency_state(osb))) {
                ret = -EROFS;
                mlog_errno(ret);
                goto out;
index ddca292944d7061564abf99e4a30d94cd5586670..732c61599159ccb1f8fbcbb44e848f78678221d9 100644 (file)
@@ -179,7 +179,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        err = file_write_and_wait_range(file, start, end);
@@ -209,7 +209,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 (unlikely(ocfs2_emergency_state(osb)))
                return 0;
 
        if ((inode->i_flags & S_NOATIME) ||
@@ -1949,7 +1949,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        inode_lock(inode);
@@ -2713,7 +2713,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        /* Lock both files against IO */
index 61363678950370c3b40a11c40978daac1c60cc68..5986d90b007e41d116d1ccad17d4922c075c055c 100644 (file)
@@ -1623,8 +1623,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 (unlikely(ocfs2_emergency_state(OCFS2_SB(sb)))) {
                mlog(ML_ERROR,
                     "Filecheck: cannot repair dinode #%llu "
                     "on readonly filesystem\n",
index ce978a2497d9de31b223eb9084869087a6b9f8f1..99637e34d9daf895d9deb6098b3e34905014433e 100644 (file)
@@ -909,7 +909,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        inode_lock(inode);
index b0733c08ed13b1544769977daaa5742b71b8a0ce..ac3ec2c2111963a4f4edf8268a57e23436d1eb04 100644 (file)
@@ -276,7 +276,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        if (new_clusters < 0)
@@ -466,7 +466,7 @@ 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))
+       if (unlikely(ocfs2_emergency_state(osb)))
                return -EROFS;
 
        main_bm_inode = ocfs2_get_system_file_inode(osb,
index 53daa448240638f37ce8c3aceb053be5aa6bf545..c6019d260efc6e725502e7e54037d35f06b4f3ba 100644 (file)
@@ -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");