diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2017-11-27 09:56:34 -0500 |
---|---|---|
committer | Bob Peterson <rpeterso@redhat.com> | 2017-11-27 11:47:22 -0500 |
commit | 8b0d7f56b97b95a442b6785027a0f80ad1ea54af (patch) | |
tree | 73a58a51514976cd9becd6ccb2d692e6582a45de | |
parent | a18c78c5f5e39978231cb30f037bdb634cd98f6c (diff) |
gfs2: Fix wrong error handling in init_gfs2_fs()
init_gfs2_fs() is calling e.g. calling unregister_shrinker() without
register_shrinker() when an error occurred during initialization.
Rename goto labels and call appropriate undo function.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
-rw-r--r-- | fs/gfs2/main.c | 90 |
1 files changed, 44 insertions, 46 deletions
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 0a89e6f7a314..2d55e2c3333c 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c | |||
@@ -93,7 +93,7 @@ static int __init init_gfs2_fs(void) | |||
93 | 93 | ||
94 | error = gfs2_glock_init(); | 94 | error = gfs2_glock_init(); |
95 | if (error) | 95 | if (error) |
96 | goto fail; | 96 | goto fail_glock; |
97 | 97 | ||
98 | error = -ENOMEM; | 98 | error = -ENOMEM; |
99 | gfs2_glock_cachep = kmem_cache_create("gfs2_glock", | 99 | gfs2_glock_cachep = kmem_cache_create("gfs2_glock", |
@@ -101,7 +101,7 @@ static int __init init_gfs2_fs(void) | |||
101 | 0, 0, | 101 | 0, 0, |
102 | gfs2_init_glock_once); | 102 | gfs2_init_glock_once); |
103 | if (!gfs2_glock_cachep) | 103 | if (!gfs2_glock_cachep) |
104 | goto fail; | 104 | goto fail_cachep1; |
105 | 105 | ||
106 | gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)", | 106 | gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)", |
107 | sizeof(struct gfs2_glock) + | 107 | sizeof(struct gfs2_glock) + |
@@ -109,7 +109,7 @@ static int __init init_gfs2_fs(void) | |||
109 | 0, 0, gfs2_init_gl_aspace_once); | 109 | 0, 0, gfs2_init_gl_aspace_once); |
110 | 110 | ||
111 | if (!gfs2_glock_aspace_cachep) | 111 | if (!gfs2_glock_aspace_cachep) |
112 | goto fail; | 112 | goto fail_cachep2; |
113 | 113 | ||
114 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", | 114 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", |
115 | sizeof(struct gfs2_inode), | 115 | sizeof(struct gfs2_inode), |
@@ -118,107 +118,105 @@ static int __init init_gfs2_fs(void) | |||
118 | SLAB_ACCOUNT, | 118 | SLAB_ACCOUNT, |
119 | gfs2_init_inode_once); | 119 | gfs2_init_inode_once); |
120 | if (!gfs2_inode_cachep) | 120 | if (!gfs2_inode_cachep) |
121 | goto fail; | 121 | goto fail_cachep3; |
122 | 122 | ||
123 | gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", | 123 | gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", |
124 | sizeof(struct gfs2_bufdata), | 124 | sizeof(struct gfs2_bufdata), |
125 | 0, 0, NULL); | 125 | 0, 0, NULL); |
126 | if (!gfs2_bufdata_cachep) | 126 | if (!gfs2_bufdata_cachep) |
127 | goto fail; | 127 | goto fail_cachep4; |
128 | 128 | ||
129 | gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd", | 129 | gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd", |
130 | sizeof(struct gfs2_rgrpd), | 130 | sizeof(struct gfs2_rgrpd), |
131 | 0, 0, NULL); | 131 | 0, 0, NULL); |
132 | if (!gfs2_rgrpd_cachep) | 132 | if (!gfs2_rgrpd_cachep) |
133 | goto fail; | 133 | goto fail_cachep5; |
134 | 134 | ||
135 | gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad", | 135 | gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad", |
136 | sizeof(struct gfs2_quota_data), | 136 | sizeof(struct gfs2_quota_data), |
137 | 0, 0, NULL); | 137 | 0, 0, NULL); |
138 | if (!gfs2_quotad_cachep) | 138 | if (!gfs2_quotad_cachep) |
139 | goto fail; | 139 | goto fail_cachep6; |
140 | 140 | ||
141 | gfs2_qadata_cachep = kmem_cache_create("gfs2_qadata", | 141 | gfs2_qadata_cachep = kmem_cache_create("gfs2_qadata", |
142 | sizeof(struct gfs2_qadata), | 142 | sizeof(struct gfs2_qadata), |
143 | 0, 0, NULL); | 143 | 0, 0, NULL); |
144 | if (!gfs2_qadata_cachep) | 144 | if (!gfs2_qadata_cachep) |
145 | goto fail; | 145 | goto fail_cachep7; |
146 | 146 | ||
147 | error = register_shrinker(&gfs2_qd_shrinker); | 147 | error = register_shrinker(&gfs2_qd_shrinker); |
148 | if (error) | 148 | if (error) |
149 | goto fail; | 149 | goto fail_shrinker; |
150 | 150 | ||
151 | error = register_filesystem(&gfs2_fs_type); | 151 | error = register_filesystem(&gfs2_fs_type); |
152 | if (error) | 152 | if (error) |
153 | goto fail; | 153 | goto fail_fs1; |
154 | 154 | ||
155 | error = register_filesystem(&gfs2meta_fs_type); | 155 | error = register_filesystem(&gfs2meta_fs_type); |
156 | if (error) | 156 | if (error) |
157 | goto fail_unregister; | 157 | goto fail_fs2; |
158 | 158 | ||
159 | error = -ENOMEM; | 159 | error = -ENOMEM; |
160 | gfs_recovery_wq = alloc_workqueue("gfs_recovery", | 160 | gfs_recovery_wq = alloc_workqueue("gfs_recovery", |
161 | WQ_MEM_RECLAIM | WQ_FREEZABLE, 0); | 161 | WQ_MEM_RECLAIM | WQ_FREEZABLE, 0); |
162 | if (!gfs_recovery_wq) | 162 | if (!gfs_recovery_wq) |
163 | goto fail_wq; | 163 | goto fail_wq1; |
164 | 164 | ||
165 | gfs2_control_wq = alloc_workqueue("gfs2_control", | 165 | gfs2_control_wq = alloc_workqueue("gfs2_control", |
166 | WQ_UNBOUND | WQ_FREEZABLE, 0); | 166 | WQ_UNBOUND | WQ_FREEZABLE, 0); |
167 | if (!gfs2_control_wq) | 167 | if (!gfs2_control_wq) |
168 | goto fail_recovery; | 168 | goto fail_wq2; |
169 | 169 | ||
170 | gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0); | 170 | gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0); |
171 | 171 | ||
172 | if (!gfs2_freeze_wq) | 172 | if (!gfs2_freeze_wq) |
173 | goto fail_control; | 173 | goto fail_wq3; |
174 | 174 | ||
175 | gfs2_page_pool = mempool_create_page_pool(64, 0); | 175 | gfs2_page_pool = mempool_create_page_pool(64, 0); |
176 | if (!gfs2_page_pool) | 176 | if (!gfs2_page_pool) |
177 | goto fail_freeze; | 177 | goto fail_mempool; |
178 | 178 | ||
179 | gfs2_register_debugfs(); | 179 | error = gfs2_register_debugfs(); |
180 | if (error) | ||
181 | goto fail_debugfs; | ||
180 | 182 | ||
181 | pr_info("GFS2 installed\n"); | 183 | pr_info("GFS2 installed\n"); |
182 | 184 | ||
183 | return 0; | 185 | return 0; |
184 | 186 | ||
185 | fail_freeze: | 187 | fail_debugfs: |
188 | mempool_destroy(gfs2_page_pool); | ||
189 | fail_mempool: | ||
186 | destroy_workqueue(gfs2_freeze_wq); | 190 | destroy_workqueue(gfs2_freeze_wq); |
187 | fail_control: | 191 | fail_wq3: |
188 | destroy_workqueue(gfs2_control_wq); | 192 | destroy_workqueue(gfs2_control_wq); |
189 | fail_recovery: | 193 | fail_wq2: |
190 | destroy_workqueue(gfs_recovery_wq); | 194 | destroy_workqueue(gfs_recovery_wq); |
191 | fail_wq: | 195 | fail_wq1: |
192 | unregister_filesystem(&gfs2meta_fs_type); | 196 | unregister_filesystem(&gfs2meta_fs_type); |
193 | fail_unregister: | 197 | fail_fs2: |
194 | unregister_filesystem(&gfs2_fs_type); | 198 | unregister_filesystem(&gfs2_fs_type); |
195 | fail: | 199 | fail_fs1: |
196 | list_lru_destroy(&gfs2_qd_lru); | ||
197 | fail_lru: | ||
198 | unregister_shrinker(&gfs2_qd_shrinker); | 200 | unregister_shrinker(&gfs2_qd_shrinker); |
201 | fail_shrinker: | ||
202 | kmem_cache_destroy(gfs2_qadata_cachep); | ||
203 | fail_cachep7: | ||
204 | kmem_cache_destroy(gfs2_quotad_cachep); | ||
205 | fail_cachep6: | ||
206 | kmem_cache_destroy(gfs2_rgrpd_cachep); | ||
207 | fail_cachep5: | ||
208 | kmem_cache_destroy(gfs2_bufdata_cachep); | ||
209 | fail_cachep4: | ||
210 | kmem_cache_destroy(gfs2_inode_cachep); | ||
211 | fail_cachep3: | ||
212 | kmem_cache_destroy(gfs2_glock_aspace_cachep); | ||
213 | fail_cachep2: | ||
214 | kmem_cache_destroy(gfs2_glock_cachep); | ||
215 | fail_cachep1: | ||
199 | gfs2_glock_exit(); | 216 | gfs2_glock_exit(); |
200 | 217 | fail_glock: | |
201 | if (gfs2_qadata_cachep) | 218 | list_lru_destroy(&gfs2_qd_lru); |
202 | kmem_cache_destroy(gfs2_qadata_cachep); | 219 | fail_lru: |
203 | |||
204 | if (gfs2_quotad_cachep) | ||
205 | kmem_cache_destroy(gfs2_quotad_cachep); | ||
206 | |||
207 | if (gfs2_rgrpd_cachep) | ||
208 | kmem_cache_destroy(gfs2_rgrpd_cachep); | ||
209 | |||
210 | if (gfs2_bufdata_cachep) | ||
211 | kmem_cache_destroy(gfs2_bufdata_cachep); | ||
212 | |||
213 | if (gfs2_inode_cachep) | ||
214 | kmem_cache_destroy(gfs2_inode_cachep); | ||
215 | |||
216 | if (gfs2_glock_aspace_cachep) | ||
217 | kmem_cache_destroy(gfs2_glock_aspace_cachep); | ||
218 | |||
219 | if (gfs2_glock_cachep) | ||
220 | kmem_cache_destroy(gfs2_glock_cachep); | ||
221 | |||
222 | gfs2_sys_uninit(); | 220 | gfs2_sys_uninit(); |
223 | return error; | 221 | return error; |
224 | } | 222 | } |