Skip to content

Commit a28dc12

Browse files
committed
gfs2: init system threads before freeze lock
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>
1 parent dc7674e commit a28dc12

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
@@ -1089,6 +1089,34 @@ void gfs2_online_uevent(struct gfs2_sbd *sdp)
10891089
kobject_uevent_env(&sdp->sd_kobj, KOBJ_ONLINE, envp);
10901090
}
10911091

1092+
static int init_threads(struct gfs2_sbd *sdp)
1093+
{
1094+
struct task_struct *p;
1095+
int error = 0;
1096+
1097+
p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
1098+
if (IS_ERR(p)) {
1099+
error = PTR_ERR(p);
1100+
fs_err(sdp, "can't start logd thread: %d\n", error);
1101+
return error;
1102+
}
1103+
sdp->sd_logd_process = p;
1104+
1105+
p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
1106+
if (IS_ERR(p)) {
1107+
error = PTR_ERR(p);
1108+
fs_err(sdp, "can't start quotad thread: %d\n", error);
1109+
goto fail;
1110+
}
1111+
sdp->sd_quotad_process = p;
1112+
return 0;
1113+
1114+
fail:
1115+
kthread_stop(sdp->sd_logd_process);
1116+
sdp->sd_logd_process = NULL;
1117+
return error;
1118+
}
1119+
10921120
/**
10931121
* gfs2_fill_super - Read in superblock
10941122
* @sb: The VFS superblock
@@ -1217,6 +1245,14 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
12171245
goto fail_per_node;
12181246
}
12191247

1248+
if (!sb_rdonly(sb)) {
1249+
error = init_threads(sdp);
1250+
if (error) {
1251+
gfs2_withdraw_delayed(sdp);
1252+
goto fail_per_node;
1253+
}
1254+
}
1255+
12201256
error = gfs2_freeze_lock(sdp, &freeze_gh, 0);
12211257
if (error)
12221258
goto fail_per_node;
@@ -1226,6 +1262,12 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
12261262

12271263
gfs2_freeze_unlock(&freeze_gh);
12281264
if (error) {
1265+
if (sdp->sd_quotad_process)
1266+
kthread_stop(sdp->sd_quotad_process);
1267+
sdp->sd_quotad_process = NULL;
1268+
if (sdp->sd_logd_process)
1269+
kthread_stop(sdp->sd_logd_process);
1270+
sdp->sd_logd_process = NULL;
12291271
fs_err(sdp, "can't make FS RW: %d\n", error);
12301272
goto fail_per_node;
12311273
}

‎fs/gfs2/super.c‎

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -119,34 +119,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
119119
return 0;
120120
}
121121

122-
static int init_threads(struct gfs2_sbd *sdp)
123-
{
124-
struct task_struct *p;
125-
int error = 0;
126-
127-
p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
128-
if (IS_ERR(p)) {
129-
error = PTR_ERR(p);
130-
fs_err(sdp, "can't start logd thread: %d\n", error);
131-
return error;
132-
}
133-
sdp->sd_logd_process = p;
134-
135-
p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
136-
if (IS_ERR(p)) {
137-
error = PTR_ERR(p);
138-
fs_err(sdp, "can't start quotad thread: %d\n", error);
139-
goto fail;
140-
}
141-
sdp->sd_quotad_process = p;
142-
return 0;
143-
144-
fail:
145-
kthread_stop(sdp->sd_logd_process);
146-
sdp->sd_logd_process = NULL;
147-
return error;
148-
}
149-
150122
/**
151123
* gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
152124
* @sdp: the filesystem
@@ -161,47 +133,26 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
161133
struct gfs2_log_header_host head;
162134
int error;
163135

164-
error = init_threads(sdp);
165-
if (error) {
166-
gfs2_withdraw_delayed(sdp);
167-
return error;
168-
}
169-
170136
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
171-
if (gfs2_withdrawn(sdp)) {
172-
error = -EIO;
173-
goto fail;
174-
}
137+
if (gfs2_withdrawn(sdp))
138+
return -EIO;
175139

176140
error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
177141
if (error || gfs2_withdrawn(sdp))
178-
goto fail;
142+
return error;
179143

180144
if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
181145
gfs2_consist(sdp);
182-
error = -EIO;
183-
goto fail;
146+
return -EIO;
184147
}
185148

186149
/* Initialize some head of the log stuff */
187150
sdp->sd_log_sequence = head.lh_sequence + 1;
188151
gfs2_log_pointers_init(sdp, head.lh_blkno);
189152

190153
error = gfs2_quota_init(sdp);
191-
if (error || gfs2_withdrawn(sdp))
192-
goto fail;
193-
194-
set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
195-
196-
return 0;
197-
198-
fail:
199-
if (sdp->sd_quotad_process)
200-
kthread_stop(sdp->sd_quotad_process);
201-
sdp->sd_quotad_process = NULL;
202-
if (sdp->sd_logd_process)
203-
kthread_stop(sdp->sd_logd_process);
204-
sdp->sd_logd_process = NULL;
154+
if (!error && !gfs2_withdrawn(sdp))
155+
set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
205156
return error;
206157
}
207158

0 commit comments

Comments
 (0)