Skip to content

Commit 7eff54d

Browse files
eraykaradagakpm00
authored andcommitted
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>
1 parent 752ba09 commit 7eff54d

6 files changed

Lines changed: 10 additions & 11 deletions

File tree

fs/ocfs2/buffer_head_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
434434
BUG_ON(buffer_jbd(bh));
435435
ocfs2_check_super_or_backup(osb->sb, bh->b_blocknr);
436436

437-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) {
437+
if (unlikely(ocfs2_emergency_state(osb))) {
438438
ret = -EROFS;
439439
mlog_errno(ret);
440440
goto out;

fs/ocfs2/file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
179179
file->f_path.dentry->d_name.name,
180180
(unsigned long long)datasync);
181181

182-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
182+
if (unlikely(ocfs2_emergency_state(osb)))
183183
return -EROFS;
184184

185185
err = file_write_and_wait_range(file, start, end);
@@ -209,7 +209,7 @@ int ocfs2_should_update_atime(struct inode *inode,
209209
struct timespec64 now;
210210
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
211211

212-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
212+
if (unlikely(ocfs2_emergency_state(osb)))
213213
return 0;
214214

215215
if ((inode->i_flags & S_NOATIME) ||
@@ -1949,7 +1949,7 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
19491949
handle_t *handle;
19501950
unsigned long long max_off = inode->i_sb->s_maxbytes;
19511951

1952-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
1952+
if (unlikely(ocfs2_emergency_state(osb)))
19531953
return -EROFS;
19541954

19551955
inode_lock(inode);
@@ -2713,7 +2713,7 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
27132713
return -EINVAL;
27142714
if (!ocfs2_refcount_tree(osb))
27152715
return -EOPNOTSUPP;
2716-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
2716+
if (unlikely(ocfs2_emergency_state(osb)))
27172717
return -EROFS;
27182718

27192719
/* Lock both files against IO */

fs/ocfs2/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,8 +1623,7 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb,
16231623
trace_ocfs2_filecheck_repair_inode_block(
16241624
(unsigned long long)bh->b_blocknr);
16251625

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)))) {
16281627
mlog(ML_ERROR,
16291628
"Filecheck: cannot repair dinode #%llu "
16301629
"on readonly filesystem\n",

fs/ocfs2/move_extents.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context)
909909
struct buffer_head *di_bh = NULL;
910910
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
911911

912-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
912+
if (unlikely(ocfs2_emergency_state(osb)))
913913
return -EROFS;
914914

915915
inode_lock(inode);

fs/ocfs2/resize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int ocfs2_group_extend(struct inode * inode, int new_clusters)
276276
u32 first_new_cluster;
277277
u64 lgd_blkno;
278278

279-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
279+
if (unlikely(ocfs2_emergency_state(osb)))
280280
return -EROFS;
281281

282282
if (new_clusters < 0)
@@ -466,7 +466,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
466466
u16 cl_bpc;
467467
u64 bg_ptr;
468468

469-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
469+
if (unlikely(ocfs2_emergency_state(osb)))
470470
return -EROFS;
471471

472472
main_bm_inode = ocfs2_get_system_file_inode(osb,

fs/ocfs2/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,7 @@ static int ocfs2_handle_error(struct super_block *sb)
24872487
rv = -EIO;
24882488
} else { /* default option */
24892489
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))
24912491
return rv;
24922492

24932493
pr_crit("OCFS2: File system is now read-only.\n");

0 commit comments

Comments
 (0)