aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/acl.c
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2014-10-13 22:42:53 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2014-11-03 19:07:33 -0500
commitbce8d1120707c06088928b2ee52a58703d74ac29 (patch)
treec9320f0274a9eabcc163f9d16dcd163ba3a304bb /fs/f2fs/acl.c
parent59a0615540812297e4ff9673de5c1269413d0c40 (diff)
f2fs: avoid deadlock on init_inode_metadata
Previously, init_inode_metadata does not hold any parent directory's inode page. So, f2fs_init_acl can grab its parent inode page without any problem. But, when we use inline_dentry, that page is grabbed during f2fs_add_link, so that we can fall into deadlock condition like below. INFO: task mknod:11006 blocked for more than 120 seconds. Tainted: G OE 3.17.0-rc1+ #13 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. mknod D ffff88003fc94580 0 11006 11004 0x00000000 ffff880007717b10 0000000000000002 ffff88003c323220 ffff880007717fd8 0000000000014580 0000000000014580 ffff88003daecb30 ffff88003c323220 ffff88003fc94e80 ffff88003ffbb4e8 ffff880007717ba0 0000000000000002 Call Trace: [<ffffffff8173dc40>] ? bit_wait+0x50/0x50 [<ffffffff8173d4cd>] io_schedule+0x9d/0x130 [<ffffffff8173dc6c>] bit_wait_io+0x2c/0x50 [<ffffffff8173da3b>] __wait_on_bit_lock+0x4b/0xb0 [<ffffffff811640a7>] __lock_page+0x67/0x70 [<ffffffff810acf50>] ? autoremove_wake_function+0x40/0x40 [<ffffffff811652cc>] pagecache_get_page+0x14c/0x1e0 [<ffffffffa029afa9>] get_node_page+0x59/0x130 [f2fs] [<ffffffffa02a63ad>] read_all_xattrs+0x24d/0x430 [f2fs] [<ffffffffa02a6ca2>] f2fs_getxattr+0x52/0xe0 [f2fs] [<ffffffffa02a7481>] f2fs_get_acl+0x41/0x2d0 [f2fs] [<ffffffff8122d847>] get_acl+0x47/0x70 [<ffffffff8122db5a>] posix_acl_create+0x5a/0x150 [<ffffffffa02a7759>] f2fs_init_acl+0x29/0xcb [f2fs] [<ffffffffa0286a8d>] init_inode_metadata+0x5d/0x340 [f2fs] [<ffffffffa029253a>] f2fs_add_inline_entry+0x12a/0x2e0 [f2fs] [<ffffffffa0286ea5>] __f2fs_add_link+0x45/0x4a0 [f2fs] [<ffffffffa028b5b6>] ? f2fs_new_inode+0x146/0x220 [f2fs] [<ffffffffa028b816>] f2fs_mknod+0x86/0xf0 [f2fs] [<ffffffff811e3ec1>] vfs_mknod+0xe1/0x160 [<ffffffff811e4b26>] SyS_mknod+0x1f6/0x200 [<ffffffff81741d7f>] tracesys+0xe1/0xe6 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/acl.c')
-rw-r--r--fs/f2fs/acl.c144
1 files changed, 138 insertions, 6 deletions
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 83b9b5a8d112..620745556828 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -162,7 +162,8 @@ fail:
162 return ERR_PTR(-EINVAL); 162 return ERR_PTR(-EINVAL);
163} 163}
164 164
165struct posix_acl *f2fs_get_acl(struct inode *inode, int type) 165static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
166 struct page *dpage)
166{ 167{
167 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT; 168 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
168 void *value = NULL; 169 void *value = NULL;
@@ -172,12 +173,13 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
172 if (type == ACL_TYPE_ACCESS) 173 if (type == ACL_TYPE_ACCESS)
173 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS; 174 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
174 175
175 retval = f2fs_getxattr(inode, name_index, "", NULL, 0); 176 retval = f2fs_getxattr(inode, name_index, "", NULL, 0, dpage);
176 if (retval > 0) { 177 if (retval > 0) {
177 value = kmalloc(retval, GFP_F2FS_ZERO); 178 value = kmalloc(retval, GFP_F2FS_ZERO);
178 if (!value) 179 if (!value)
179 return ERR_PTR(-ENOMEM); 180 return ERR_PTR(-ENOMEM);
180 retval = f2fs_getxattr(inode, name_index, "", value, retval); 181 retval = f2fs_getxattr(inode, name_index, "", value,
182 retval, dpage);
181 } 183 }
182 184
183 if (retval > 0) 185 if (retval > 0)
@@ -194,6 +196,11 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
194 return acl; 196 return acl;
195} 197}
196 198
199struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
200{
201 return __f2fs_get_acl(inode, type, NULL);
202}
203
197static int __f2fs_set_acl(struct inode *inode, int type, 204static int __f2fs_set_acl(struct inode *inode, int type,
198 struct posix_acl *acl, struct page *ipage) 205 struct posix_acl *acl, struct page *ipage)
199{ 206{
@@ -249,12 +256,137 @@ int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
249 return __f2fs_set_acl(inode, type, acl, NULL); 256 return __f2fs_set_acl(inode, type, acl, NULL);
250} 257}
251 258
252int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage) 259/*
260 * Most part of f2fs_acl_clone, f2fs_acl_create_masq, f2fs_acl_create
261 * are copied from posix_acl.c
262 */
263static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl,
264 gfp_t flags)
265{
266 struct posix_acl *clone = NULL;
267
268 if (acl) {
269 int size = sizeof(struct posix_acl) + acl->a_count *
270 sizeof(struct posix_acl_entry);
271 clone = kmemdup(acl, size, flags);
272 if (clone)
273 atomic_set(&clone->a_refcount, 1);
274 }
275 return clone;
276}
277
278static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
279{
280 struct posix_acl_entry *pa, *pe;
281 struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL;
282 umode_t mode = *mode_p;
283 int not_equiv = 0;
284
285 /* assert(atomic_read(acl->a_refcount) == 1); */
286
287 FOREACH_ACL_ENTRY(pa, acl, pe) {
288 switch(pa->e_tag) {
289 case ACL_USER_OBJ:
290 pa->e_perm &= (mode >> 6) | ~S_IRWXO;
291 mode &= (pa->e_perm << 6) | ~S_IRWXU;
292 break;
293
294 case ACL_USER:
295 case ACL_GROUP:
296 not_equiv = 1;
297 break;
298
299 case ACL_GROUP_OBJ:
300 group_obj = pa;
301 break;
302
303 case ACL_OTHER:
304 pa->e_perm &= mode | ~S_IRWXO;
305 mode &= pa->e_perm | ~S_IRWXO;
306 break;
307
308 case ACL_MASK:
309 mask_obj = pa;
310 not_equiv = 1;
311 break;
312
313 default:
314 return -EIO;
315 }
316 }
317
318 if (mask_obj) {
319 mask_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
320 mode &= (mask_obj->e_perm << 3) | ~S_IRWXG;
321 } else {
322 if (!group_obj)
323 return -EIO;
324 group_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
325 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
326 }
327
328 *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
329 return not_equiv;
330}
331
332static int f2fs_acl_create(struct inode *dir, umode_t *mode,
333 struct posix_acl **default_acl, struct posix_acl **acl,
334 struct page *dpage)
335{
336 struct posix_acl *p;
337 int ret;
338
339 if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
340 goto no_acl;
341
342 p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dpage);
343 if (IS_ERR(p)) {
344 if (p == ERR_PTR(-EOPNOTSUPP))
345 goto apply_umask;
346 return PTR_ERR(p);
347 }
348
349 if (!p)
350 goto apply_umask;
351
352 *acl = f2fs_acl_clone(p, GFP_NOFS);
353 if (!*acl)
354 return -ENOMEM;
355
356 ret = f2fs_acl_create_masq(*acl, mode);
357 if (ret < 0) {
358 posix_acl_release(*acl);
359 return -ENOMEM;
360 }
361
362 if (ret == 0) {
363 posix_acl_release(*acl);
364 *acl = NULL;
365 }
366
367 if (!S_ISDIR(*mode)) {
368 posix_acl_release(p);
369 *default_acl = NULL;
370 } else {
371 *default_acl = p;
372 }
373 return 0;
374
375apply_umask:
376 *mode &= ~current_umask();
377no_acl:
378 *default_acl = NULL;
379 *acl = NULL;
380 return 0;
381}
382
383int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage,
384 struct page *dpage)
253{ 385{
254 struct posix_acl *default_acl, *acl; 386 struct posix_acl *default_acl = NULL, *acl = NULL;
255 int error = 0; 387 int error = 0;
256 388
257 error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl); 389 error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dpage);
258 if (error) 390 if (error)
259 return error; 391 return error;
260 392