Skip to content

Commit a602e83

Browse files
AstralBobgregkh
authored andcommitted
gfs2: move freeze glock outside the make_fs_rw and _ro functions
[ Upstream commit 96b1454 ] Before this patch, sister functions gfs2_make_fs_rw and gfs2_make_fs_ro locked (held) the freeze glock by calling gfs2_freeze_lock and gfs2_freeze_unlock. The problem is, not all the callers of gfs2_make_fs_ro should be doing this. The three callers of gfs2_make_fs_ro are: remount (gfs2_reconfigure), signal_our_withdraw, and unmount (gfs2_put_super). But when unmounting the file system we can get into the following circular lock dependency: deactivate_super down_write(&s->s_umount); <-------------------------------------- s_umount deactivate_locked_super gfs2_kill_sb kill_block_super generic_shutdown_super gfs2_put_super gfs2_make_fs_ro gfs2_glock_nq_init sd_freeze_gl freeze_go_sync if (freeze glock in SH) freeze_super (vfs) down_write(&sb->s_umount); <------- s_umount This patch moves the hold of the freeze glock outside the two sister rw/ro functions to their callers, but it doesn't request the glock from gfs2_put_super, thus eliminating the circular dependency. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 49787b1 commit a602e83

3 files changed

Lines changed: 33 additions & 39 deletions

File tree

‎fs/gfs2/ops_fstype.c‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
10841084
int silent = fc->sb_flags & SB_SILENT;
10851085
struct gfs2_sbd *sdp;
10861086
struct gfs2_holder mount_gh;
1087+
struct gfs2_holder freeze_gh;
10871088
int error;
10881089

10891090
sdp = init_sbd(sb);
@@ -1195,23 +1196,18 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11951196
goto fail_per_node;
11961197
}
11971198

1198-
if (sb_rdonly(sb)) {
1199-
struct gfs2_holder freeze_gh;
1199+
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
1200+
if (error)
1201+
goto fail_per_node;
12001202

1201-
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
1202-
if (error) {
1203-
fs_err(sdp, "can't make FS RO: %d\n", error);
1204-
goto fail_per_node;
1205-
}
1206-
gfs2_freeze_unlock(&freeze_gh);
1207-
} else {
1203+
if (!sb_rdonly(sb))
12081204
error = gfs2_make_fs_rw(sdp);
1209-
if (error) {
1210-
fs_err(sdp, "can't make FS RW: %d\n", error);
1211-
goto fail_per_node;
1212-
}
1213-
}
12141205

1206+
gfs2_freeze_unlock(&freeze_gh);
1207+
if (error) {
1208+
fs_err(sdp, "can't make FS RW: %d\n", error);
1209+
goto fail_per_node;
1210+
}
12151211
gfs2_glock_dq_uninit(&mount_gh);
12161212
gfs2_online_uevent(sdp);
12171213
return 0;
@@ -1512,6 +1508,12 @@ static int gfs2_reconfigure(struct fs_context *fc)
15121508
fc->sb_flags |= SB_RDONLY;
15131509

15141510
if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) {
1511+
struct gfs2_holder freeze_gh;
1512+
1513+
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
1514+
if (error)
1515+
return -EINVAL;
1516+
15151517
if (fc->sb_flags & SB_RDONLY) {
15161518
error = gfs2_make_fs_ro(sdp);
15171519
if (error)
@@ -1521,6 +1523,7 @@ static int gfs2_reconfigure(struct fs_context *fc)
15211523
if (error)
15221524
errorfc(fc, "unable to remount read-write");
15231525
}
1526+
gfs2_freeze_unlock(&freeze_gh);
15241527
}
15251528
sdp->sd_args = *newargs;
15261529

‎fs/gfs2/super.c‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,13 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
165165
{
166166
struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
167167
struct gfs2_glock *j_gl = ip->i_gl;
168-
struct gfs2_holder freeze_gh;
169168
struct gfs2_log_header_host head;
170169
int error;
171170

172171
error = init_threads(sdp);
173172
if (error)
174173
return error;
175174

176-
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
177-
if (error)
178-
goto fail_threads;
179-
180175
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
181176
if (gfs2_withdrawn(sdp)) {
182177
error = -EIO;
@@ -203,13 +198,9 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
203198

204199
set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
205200

206-
gfs2_freeze_unlock(&freeze_gh);
207-
208201
return 0;
209202

210203
fail:
211-
gfs2_freeze_unlock(&freeze_gh);
212-
fail_threads:
213204
if (sdp->sd_quotad_process)
214205
kthread_stop(sdp->sd_quotad_process);
215206
sdp->sd_quotad_process = NULL;
@@ -609,21 +600,9 @@ static void gfs2_dirty_inode(struct inode *inode, int flags)
609600

610601
int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
611602
{
612-
struct gfs2_holder freeze_gh;
613603
int error = 0;
614604
int log_write_allowed = test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
615605

616-
gfs2_holder_mark_uninitialized(&freeze_gh);
617-
if (sdp->sd_freeze_gl &&
618-
!gfs2_glock_is_locked_by_me(sdp->sd_freeze_gl)) {
619-
error = gfs2_freeze_lock(sdp, &freeze_gh,
620-
log_write_allowed ? 0 : LM_FLAG_TRY);
621-
if (error == GLR_TRYFAILED)
622-
error = 0;
623-
if (error && !gfs2_withdrawn(sdp))
624-
return error;
625-
}
626-
627606
gfs2_flush_delete_work(sdp);
628607
if (!log_write_allowed && current == sdp->sd_quotad_process)
629608
fs_warn(sdp, "The quotad daemon is withdrawing.\n");
@@ -652,8 +631,6 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
652631
atomic_read(&sdp->sd_reserving_log) == 0,
653632
HZ * 5);
654633
}
655-
gfs2_freeze_unlock(&freeze_gh);
656-
657634
gfs2_quota_cleanup(sdp);
658635

659636
if (!log_write_allowed)

‎fs/gfs2/util.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp)
123123
struct gfs2_inode *ip = GFS2_I(inode);
124124
struct gfs2_glock *i_gl = ip->i_gl;
125125
u64 no_formal_ino = ip->i_no_formal_ino;
126+
int log_write_allowed = test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
126127
int ret = 0;
127128
int tries;
128129

@@ -143,8 +144,21 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp)
143144
* therefore we need to clear SDF_JOURNAL_LIVE manually.
144145
*/
145146
clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
146-
if (!sb_rdonly(sdp->sd_vfs))
147-
ret = gfs2_make_fs_ro(sdp);
147+
if (!sb_rdonly(sdp->sd_vfs)) {
148+
struct gfs2_holder freeze_gh;
149+
150+
gfs2_holder_mark_uninitialized(&freeze_gh);
151+
if (sdp->sd_freeze_gl &&
152+
!gfs2_glock_is_locked_by_me(sdp->sd_freeze_gl)) {
153+
ret = gfs2_freeze_lock(sdp, &freeze_gh,
154+
log_write_allowed ? 0 : LM_FLAG_TRY);
155+
if (ret == GLR_TRYFAILED)
156+
ret = 0;
157+
}
158+
if (!ret)
159+
ret = gfs2_make_fs_ro(sdp);
160+
gfs2_freeze_unlock(&freeze_gh);
161+
}
148162

149163
if (sdp->sd_lockstruct.ls_ops->lm_lock == NULL) { /* lock_nolock */
150164
if (!ret)

0 commit comments

Comments
 (0)