Skip to content

Commit b4bbb77

Browse files
AstralBobgregkh
authored andcommitted
gfs2: init system threads before freeze lock
[ Upstream commit a28dc12 ] Patch 96b1454 ("gfs2: move freeze glock outside the make_fs_rw and _ro functions") changed the gfs2 mount sequence so that it holds the freeze lock before calling gfs2_make_fs_rw. Before this patch, gfs2_make_fs_rw called init_threads to initialize the quotad and logd threads. That is a problem if the system needs to withdraw due to IO errors early in the mount sequence, for example, while initializing the system statfs inode: 1. An IO error causes the statfs glock to not sync properly after recovery, and leaves items on the ail list. 2. The leftover items on the ail list causes its do_xmote call to fail, which makes it want to withdraw. But since the glock code cannot withdraw (because the withdraw sequence uses glocks) it relies upon the logd daemon to initiate the withdraw. 3. The withdraw can never be performed by the logd daemon because all this takes place before the logd daemon is started. This patch moves function init_threads from super.c to ops_fstype.c and it changes gfs2_fill_super to start its threads before holding the freeze lock, and if there's an error, stop its threads after releasing it. This allows the logd to run unblocked by the freeze lock. Thus, the logd daemon can perform its withdraw sequence properly. Fixes: 96b1454 ("gfs2: move freeze glock outside the make_fs_rw and _ro functions") Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ee029e3 commit b4bbb77

2 files changed

Lines changed: 48 additions & 55 deletions

File tree

‎fs/gfs2/ops_fstype.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,34 @@ void gfs2_online_uevent(struct gfs2_sbd *sdp)
10721072
kobject_uevent_env(&sdp->sd_kobj, KOBJ_ONLINE, envp);
10731073
}
10741074

1075+
static int init_threads(struct gfs2_sbd *sdp)
1076+
{
1077+
struct task_struct *p;
1078+
int error = 0;
1079+
1080+
p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
1081+
if (IS_ERR(p)) {
1082+
error = PTR_ERR(p);
1083+
fs_err(sdp, "can't start logd thread: %d\n", error);
1084+
return error;
1085+
}
1086+
sdp->sd_logd_process = p;
1087+
1088+
p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
1089+
if (IS_ERR(p)) {
1090+
error = PTR_ERR(p);
1091+
fs_err(sdp, "can't start quotad thread: %d\n", error);
1092+
goto fail;
1093+
}
1094+
sdp->sd_quotad_process = p;
1095+
return 0;
1096+
1097+
fail:
1098+
kthread_stop(sdp->sd_logd_process);
1099+
sdp->sd_logd_process = NULL;
1100+
return error;
1101+
}
1102+
10751103
/**
10761104
* gfs2_fill_super - Read in superblock
10771105
* @sb: The VFS superblock
@@ -1198,6 +1226,14 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11981226
goto fail_per_node;
11991227
}
12001228

1229+
if (!sb_rdonly(sb)) {
1230+
error = init_threads(sdp);
1231+
if (error) {
1232+
gfs2_withdraw_delayed(sdp);
1233+
goto fail_per_node;
1234+
}
1235+
}
1236+
12011237
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
12021238
if (error)
12031239
goto fail_per_node;
@@ -1207,6 +1243,12 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
12071243

12081244
gfs2_freeze_unlock(&freeze_gh);
12091245
if (error) {
1246+
if (sdp->sd_quotad_process)
1247+
kthread_stop(sdp->sd_quotad_process);
1248+
sdp->sd_quotad_process = NULL;
1249+
if (sdp->sd_logd_process)
1250+
kthread_stop(sdp->sd_logd_process);
1251+
sdp->sd_logd_process = NULL;
12101252
fs_err(sdp, "can't make FS RW: %d\n", error);
12111253
goto fail_per_node;
12121254
}

‎fs/gfs2/super.c‎

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
126126
return 0;
127127
}
128128

129-
static int init_threads(struct gfs2_sbd *sdp)
130-
{
131-
struct task_struct *p;
132-
int error = 0;
133-
134-
p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
135-
if (IS_ERR(p)) {
136-
error = PTR_ERR(p);
137-
fs_err(sdp, "can't start logd thread: %d\n", error);
138-
return error;
139-
}
140-
sdp->sd_logd_process = p;
141-
142-
p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
143-
if (IS_ERR(p)) {
144-
error = PTR_ERR(p);
145-
fs_err(sdp, "can't start quotad thread: %d\n", error);
146-
goto fail;
147-
}
148-
sdp->sd_quotad_process = p;
149-
return 0;
150-
151-
fail:
152-
kthread_stop(sdp->sd_logd_process);
153-
sdp->sd_logd_process = NULL;
154-
return error;
155-
}
156-
157129
/**
158130
* gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
159131
* @sdp: the filesystem
@@ -168,47 +140,26 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
168140
struct gfs2_log_header_host head;
169141
int error;
170142

171-
error = init_threads(sdp);
172-
if (error) {
173-
gfs2_withdraw_delayed(sdp);
174-
return error;
175-
}
176-
177143
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
178-
if (gfs2_withdrawn(sdp)) {
179-
error = -EIO;
180-
goto fail;
181-
}
144+
if (gfs2_withdrawn(sdp))
145+
return -EIO;
182146

183147
error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
184148
if (error || gfs2_withdrawn(sdp))
185-
goto fail;
149+
return error;
186150

187151
if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
188152
gfs2_consist(sdp);
189-
error = -EIO;
190-
goto fail;
153+
return -EIO;
191154
}
192155

193156
/* Initialize some head of the log stuff */
194157
sdp->sd_log_sequence = head.lh_sequence + 1;
195158
gfs2_log_pointers_init(sdp, head.lh_blkno);
196159

197160
error = gfs2_quota_init(sdp);
198-
if (error || gfs2_withdrawn(sdp))
199-
goto fail;
200-
201-
set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
202-
203-
return 0;
204-
205-
fail:
206-
if (sdp->sd_quotad_process)
207-
kthread_stop(sdp->sd_quotad_process);
208-
sdp->sd_quotad_process = NULL;
209-
if (sdp->sd_logd_process)
210-
kthread_stop(sdp->sd_logd_process);
211-
sdp->sd_logd_process = NULL;
161+
if (!error && !gfs2_withdrawn(sdp))
162+
set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
212163
return error;
213164
}
214165

0 commit comments

Comments
 (0)