Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ocfs2: convert remaining read-only checks to ocfs2_emergency_state

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>

authored by

Ahmet Eray Karadag and committed by
Andrew Morton
7eff54df 752ba097

+10 -11
+1 -1
fs/ocfs2/buffer_head_io.c
··· 434 434 BUG_ON(buffer_jbd(bh)); 435 435 ocfs2_check_super_or_backup(osb->sb, bh->b_blocknr); 436 436 437 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) { 437 + if (unlikely(ocfs2_emergency_state(osb))) { 438 438 ret = -EROFS; 439 439 mlog_errno(ret); 440 440 goto out;
+4 -4
fs/ocfs2/file.c
··· 179 179 file->f_path.dentry->d_name.name, 180 180 (unsigned long long)datasync); 181 181 182 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 182 + if (unlikely(ocfs2_emergency_state(osb))) 183 183 return -EROFS; 184 184 185 185 err = file_write_and_wait_range(file, start, end); ··· 209 209 struct timespec64 now; 210 210 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 211 211 212 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 212 + if (unlikely(ocfs2_emergency_state(osb))) 213 213 return 0; 214 214 215 215 if ((inode->i_flags & S_NOATIME) || ··· 1949 1949 handle_t *handle; 1950 1950 unsigned long long max_off = inode->i_sb->s_maxbytes; 1951 1951 1952 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 1952 + if (unlikely(ocfs2_emergency_state(osb))) 1953 1953 return -EROFS; 1954 1954 1955 1955 inode_lock(inode); ··· 2713 2713 return -EINVAL; 2714 2714 if (!ocfs2_refcount_tree(osb)) 2715 2715 return -EOPNOTSUPP; 2716 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 2716 + if (unlikely(ocfs2_emergency_state(osb))) 2717 2717 return -EROFS; 2718 2718 2719 2719 /* Lock both files against IO */
+1 -2
fs/ocfs2/inode.c
··· 1623 1623 trace_ocfs2_filecheck_repair_inode_block( 1624 1624 (unsigned long long)bh->b_blocknr); 1625 1625 1626 - if (ocfs2_is_hard_readonly(OCFS2_SB(sb)) || 1627 - ocfs2_is_soft_readonly(OCFS2_SB(sb))) { 1626 + if (unlikely(ocfs2_emergency_state(OCFS2_SB(sb)))) { 1628 1627 mlog(ML_ERROR, 1629 1628 "Filecheck: cannot repair dinode #%llu " 1630 1629 "on readonly filesystem\n",
+1 -1
fs/ocfs2/move_extents.c
··· 909 909 struct buffer_head *di_bh = NULL; 910 910 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 911 911 912 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 912 + if (unlikely(ocfs2_emergency_state(osb))) 913 913 return -EROFS; 914 914 915 915 inode_lock(inode);
+2 -2
fs/ocfs2/resize.c
··· 276 276 u32 first_new_cluster; 277 277 u64 lgd_blkno; 278 278 279 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 279 + if (unlikely(ocfs2_emergency_state(osb))) 280 280 return -EROFS; 281 281 282 282 if (new_clusters < 0) ··· 466 466 u16 cl_bpc; 467 467 u64 bg_ptr; 468 468 469 - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) 469 + if (unlikely(ocfs2_emergency_state(osb))) 470 470 return -EROFS; 471 471 472 472 main_bm_inode = ocfs2_get_system_file_inode(osb,
+1 -1
fs/ocfs2/super.c
··· 2487 2487 rv = -EIO; 2488 2488 } else { /* default option */ 2489 2489 rv = -EROFS; 2490 - if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb))) 2490 + if (sb_rdonly(sb) && ocfs2_emergency_state(osb)) 2491 2491 return rv; 2492 2492 2493 2493 pr_crit("OCFS2: File system is now read-only.\n");