Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pull-persistency' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull persistent dentry infrastructure and conversion from Al Viro:
"Some filesystems use a kinda-sorta controlled dentry refcount leak to
pin dentries of created objects in dcache (and undo it when removing
those). A reference is grabbed and not released, but it's not actually
_stored_ anywhere.

That works, but it's hard to follow and verify; among other things, we
have no way to tell _which_ of the increments is intended to be an
unpaired one. Worse, on removal we need to decide whether the
reference had already been dropped, which can be non-trivial if that
removal is on umount and we need to figure out if this dentry is
pinned due to e.g. unlink() not done. Usually that is handled by using
kill_litter_super() as ->kill_sb(), but there are open-coded special
cases of the same (consider e.g. /proc/self).

Things get simpler if we introduce a new dentry flag
(DCACHE_PERSISTENT) marking those "leaked" dentries. Having it set
claims responsibility for +1 in refcount.

The end result this series is aiming for:

- get these unbalanced dget() and dput() replaced with new primitives
that would, in addition to adjusting refcount, set and clear
persistency flag.

- instead of having kill_litter_super() mess with removing the
remaining "leaked" references (e.g. for all tmpfs files that hadn't
been removed prior to umount), have the regular
shrink_dcache_for_umount() strip DCACHE_PERSISTENT of all dentries,
dropping the corresponding reference if it had been set. After that
kill_litter_super() becomes an equivalent of kill_anon_super().

Doing that in a single step is not feasible - it would affect too many
places in too many filesystems. It has to be split into a series.

This work has really started early in 2024; quite a few preliminary
pieces have already gone into mainline. This chunk is finally getting
to the meat of that stuff - infrastructure and most of the conversions
to it.

Some pieces are still sitting in the local branches, but the bulk of
that stuff is here"

* tag 'pull-persistency' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (54 commits)
d_make_discardable(): warn if given a non-persistent dentry
kill securityfs_recursive_remove()
convert securityfs
get rid of kill_litter_super()
convert rust_binderfs
convert nfsctl
convert rpc_pipefs
convert hypfs
hypfs: swich hypfs_create_u64() to returning int
hypfs: switch hypfs_create_str() to returning int
hypfs: don't pin dentries twice
convert gadgetfs
gadgetfs: switch to simple_remove_by_name()
convert functionfs
functionfs: switch to simple_remove_by_name()
functionfs: fix the open/removal races
functionfs: need to cancel ->reset_work in ->kill_sb()
functionfs: don't bother with ffs->ref in ffs_data_{opened,closed}()
functionfs: don't abuse ffs_data_closed() on fs shutdown
convert selinuxfs
...

+648 -833
+7
Documentation/filesystems/porting.rst
··· 1327 1327 dentry and doesn't provide a replacement, it also unlocks the parent. 1328 1328 Consequently the return value from vfs_mkdir() can be passed to 1329 1329 end_creating() and the parent will be unlocked precisely when necessary. 1330 + 1331 + --- 1332 + 1333 + **mandatory** 1334 + 1335 + kill_litter_super() is gone; convert to DCACHE_PERSISTENT use (as all 1336 + in-tree filesystems have done).
+7 -10
arch/powerpc/platforms/cell/spufs/inode.c
··· 127 127 inode->i_fop = fops; 128 128 inode->i_size = size; 129 129 inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx); 130 - d_add(dentry, inode); 130 + d_make_persistent(dentry, inode); 131 131 out: 132 132 return ret; 133 133 } ··· 163 163 return -ENOMEM; 164 164 ret = spufs_new_file(dir->d_sb, dentry, files->ops, 165 165 files->mode & mode, files->size, ctx); 166 - if (ret) { 167 - dput(dentry); 166 + dput(dentry); 167 + if (ret) 168 168 return ret; 169 - } 170 169 files++; 171 170 } 172 171 return 0; ··· 240 241 241 242 inode_lock(inode); 242 243 243 - dget(dentry); 244 244 inc_nlink(dir); 245 245 inc_nlink(inode); 246 246 247 - d_instantiate(dentry, inode); 247 + d_make_persistent(dentry, inode); 248 248 249 249 if (flags & SPU_CREATE_NOSCHED) 250 250 ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents, ··· 466 468 inode->i_op = &simple_dir_inode_operations; 467 469 inode->i_fop = &simple_dir_operations; 468 470 469 - d_instantiate(dentry, inode); 470 - dget(dentry); 471 471 inc_nlink(dir); 472 - inc_nlink(d_inode(dentry)); 472 + inc_nlink(inode); 473 + d_make_persistent(dentry, inode); 473 474 return ret; 474 475 475 476 out_iput: ··· 755 758 .name = "spufs", 756 759 .init_fs_context = spufs_init_fs_context, 757 760 .parameters = spufs_fs_parameters, 758 - .kill_sb = kill_litter_super, 761 + .kill_sb = kill_anon_super, 759 762 }; 760 763 MODULE_ALIAS_FS("spufs"); 761 764
+2 -4
arch/s390/hypfs/hypfs.h
··· 22 22 23 23 extern struct dentry *hypfs_mkdir(struct dentry *parent, const char *name); 24 24 25 - extern struct dentry *hypfs_create_u64(struct dentry *dir, const char *name, 26 - __u64 value); 25 + extern int hypfs_create_u64(struct dentry *dir, const char *name, __u64 value); 27 26 28 - extern struct dentry *hypfs_create_str(struct dentry *dir, const char *name, 29 - char *string); 27 + extern int hypfs_create_str(struct dentry *dir, const char *name, char *string); 30 28 31 29 /* LPAR Hypervisor */ 32 30 extern int hypfs_diag_init(void);
+21 -39
arch/s390/hypfs/hypfs_diag_fs.c
··· 203 203 { 204 204 struct dentry *cpu_dir; 205 205 char buffer[TMP_SIZE]; 206 - void *rc; 206 + int rc; 207 207 208 208 snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_get_info_type(), 209 209 cpu_info)); ··· 213 213 rc = hypfs_create_u64(cpu_dir, "mgmtime", 214 214 cpu_info__acc_time(diag204_get_info_type(), cpu_info) - 215 215 cpu_info__lp_time(diag204_get_info_type(), cpu_info)); 216 - if (IS_ERR(rc)) 217 - return PTR_ERR(rc); 216 + if (rc) 217 + return rc; 218 218 rc = hypfs_create_u64(cpu_dir, "cputime", 219 219 cpu_info__lp_time(diag204_get_info_type(), cpu_info)); 220 - if (IS_ERR(rc)) 221 - return PTR_ERR(rc); 220 + if (rc) 221 + return rc; 222 222 if (diag204_get_info_type() == DIAG204_INFO_EXT) { 223 223 rc = hypfs_create_u64(cpu_dir, "onlinetime", 224 224 cpu_info__online_time(diag204_get_info_type(), 225 225 cpu_info)); 226 - if (IS_ERR(rc)) 227 - return PTR_ERR(rc); 226 + if (rc) 227 + return rc; 228 228 } 229 229 diag224_idx2name(cpu_info__ctidx(diag204_get_info_type(), cpu_info), buffer); 230 - rc = hypfs_create_str(cpu_dir, "type", buffer); 231 - return PTR_ERR_OR_ZERO(rc); 230 + return hypfs_create_str(cpu_dir, "type", buffer); 232 231 } 233 232 234 233 static void *hypfs_create_lpar_files(struct dentry *systems_dir, void *part_hdr) ··· 262 263 { 263 264 struct dentry *cpu_dir; 264 265 char buffer[TMP_SIZE]; 265 - void *rc; 266 + int rc; 266 267 267 268 snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_get_info_type(), 268 269 cpu_info)); ··· 271 272 return PTR_ERR(cpu_dir); 272 273 rc = hypfs_create_u64(cpu_dir, "mgmtime", 273 274 phys_cpu__mgm_time(diag204_get_info_type(), cpu_info)); 274 - if (IS_ERR(rc)) 275 - return PTR_ERR(rc); 275 + if (rc) 276 + return rc; 276 277 diag224_idx2name(phys_cpu__ctidx(diag204_get_info_type(), cpu_info), buffer); 277 - rc = hypfs_create_str(cpu_dir, "type", buffer); 278 - return PTR_ERR_OR_ZERO(rc); 278 + return hypfs_create_str(cpu_dir, "type", buffer); 279 279 } 280 280 281 281 static void *hypfs_create_phys_files(struct dentry *parent_dir, void *phys_hdr) ··· 313 315 return rc; 314 316 315 317 systems_dir = hypfs_mkdir(root, "systems"); 316 - if (IS_ERR(systems_dir)) { 317 - rc = PTR_ERR(systems_dir); 318 - goto err_out; 319 - } 318 + if (IS_ERR(systems_dir)) 319 + return PTR_ERR(systems_dir); 320 320 time_hdr = (struct x_info_blk_hdr *)buffer; 321 321 part_hdr = time_hdr + info_blk_hdr__size(diag204_get_info_type()); 322 322 for (i = 0; i < info_blk_hdr__npar(diag204_get_info_type(), time_hdr); i++) { 323 323 part_hdr = hypfs_create_lpar_files(systems_dir, part_hdr); 324 - if (IS_ERR(part_hdr)) { 325 - rc = PTR_ERR(part_hdr); 326 - goto err_out; 327 - } 324 + if (IS_ERR(part_hdr)) 325 + return PTR_ERR(part_hdr); 328 326 } 329 327 if (info_blk_hdr__flags(diag204_get_info_type(), time_hdr) & 330 328 DIAG204_LPAR_PHYS_FLG) { 331 329 ptr = hypfs_create_phys_files(root, part_hdr); 332 - if (IS_ERR(ptr)) { 333 - rc = PTR_ERR(ptr); 334 - goto err_out; 335 - } 330 + if (IS_ERR(ptr)) 331 + return PTR_ERR(ptr); 336 332 } 337 333 hyp_dir = hypfs_mkdir(root, "hyp"); 338 - if (IS_ERR(hyp_dir)) { 339 - rc = PTR_ERR(hyp_dir); 340 - goto err_out; 341 - } 342 - ptr = hypfs_create_str(hyp_dir, "type", "LPAR Hypervisor"); 343 - if (IS_ERR(ptr)) { 344 - rc = PTR_ERR(ptr); 345 - goto err_out; 346 - } 347 - rc = 0; 348 - 349 - err_out: 350 - return rc; 334 + if (IS_ERR(hyp_dir)) 335 + return PTR_ERR(hyp_dir); 336 + return hypfs_create_str(hyp_dir, "type", "LPAR Hypervisor"); 351 337 } 352 338 353 339 /* Diagnose 224 functions */
+8 -13
arch/s390/hypfs/hypfs_vm_fs.c
··· 19 19 20 20 #define ATTRIBUTE(dir, name, member) \ 21 21 do { \ 22 - void *rc; \ 23 - rc = hypfs_create_u64(dir, name, member); \ 24 - if (IS_ERR(rc)) \ 25 - return PTR_ERR(rc); \ 22 + int rc = hypfs_create_u64(dir, name, member); \ 23 + if (rc) \ 24 + return rc; \ 26 25 } while (0) 27 26 28 27 static int hypfs_vm_create_guest(struct dentry *systems_dir, ··· 84 85 85 86 int hypfs_vm_create_files(struct dentry *root) 86 87 { 87 - struct dentry *dir, *file; 88 + struct dentry *dir; 88 89 struct diag2fc_data *data; 89 90 unsigned int count = 0; 90 91 int rc, i; ··· 99 100 rc = PTR_ERR(dir); 100 101 goto failed; 101 102 } 102 - file = hypfs_create_str(dir, "type", "z/VM Hypervisor"); 103 - if (IS_ERR(file)) { 104 - rc = PTR_ERR(file); 103 + rc = hypfs_create_str(dir, "type", "z/VM Hypervisor"); 104 + if (rc) 105 105 goto failed; 106 - } 107 106 108 107 /* physical cpus */ 109 108 dir = hypfs_mkdir(root, "cpus"); ··· 109 112 rc = PTR_ERR(dir); 110 113 goto failed; 111 114 } 112 - file = hypfs_create_u64(dir, "count", data->lcpus); 113 - if (IS_ERR(file)) { 114 - rc = PTR_ERR(file); 115 + rc = hypfs_create_u64(dir, "count", data->lcpus); 116 + if (rc) 115 117 goto failed; 116 - } 117 118 118 119 /* guests */ 119 120 dir = hypfs_mkdir(root, "systems");
+27 -55
arch/s390/hypfs/inode.c
··· 60 60 61 61 static void hypfs_add_dentry(struct dentry *dentry) 62 62 { 63 - dentry->d_fsdata = hypfs_last_dentry; 64 - hypfs_last_dentry = dentry; 65 - } 66 - 67 - static void hypfs_remove(struct dentry *dentry) 68 - { 69 - struct dentry *parent; 70 - 71 - parent = dentry->d_parent; 72 - inode_lock(d_inode(parent)); 73 - if (simple_positive(dentry)) { 74 - if (d_is_dir(dentry)) 75 - simple_rmdir(d_inode(parent), dentry); 76 - else 77 - simple_unlink(d_inode(parent), dentry); 63 + if (IS_ROOT(dentry->d_parent)) { 64 + dentry->d_fsdata = hypfs_last_dentry; 65 + hypfs_last_dentry = dentry; 78 66 } 79 - d_drop(dentry); 80 - dput(dentry); 81 - inode_unlock(d_inode(parent)); 82 67 } 83 68 84 - static void hypfs_delete_tree(struct dentry *root) 69 + static void hypfs_delete_tree(void) 85 70 { 86 71 while (hypfs_last_dentry) { 87 - struct dentry *next_dentry; 88 - next_dentry = hypfs_last_dentry->d_fsdata; 89 - hypfs_remove(hypfs_last_dentry); 72 + struct dentry *next_dentry = hypfs_last_dentry->d_fsdata; 73 + simple_recursive_removal(hypfs_last_dentry, NULL); 90 74 hypfs_last_dentry = next_dentry; 91 75 } 92 76 } ··· 167 183 rc = -EBUSY; 168 184 goto out; 169 185 } 170 - hypfs_delete_tree(sb->s_root); 186 + hypfs_delete_tree(); 171 187 if (machine_is_vm()) 172 188 rc = hypfs_vm_create_files(sb->s_root); 173 189 else 174 190 rc = hypfs_diag_create_files(sb->s_root); 175 191 if (rc) { 176 192 pr_err("Updating the hypfs tree failed\n"); 177 - hypfs_delete_tree(sb->s_root); 193 + hypfs_delete_tree(); 178 194 goto out; 179 195 } 180 196 hypfs_update_update(sb); ··· 309 325 { 310 326 struct hypfs_sb_info *sb_info = sb->s_fs_info; 311 327 312 - if (sb->s_root) 313 - hypfs_delete_tree(sb->s_root); 314 - if (sb_info && sb_info->update_file) 315 - hypfs_remove(sb_info->update_file); 316 - kfree(sb->s_fs_info); 317 - sb->s_fs_info = NULL; 318 - kill_litter_super(sb); 328 + hypfs_last_dentry = NULL; 329 + kill_anon_super(sb); 330 + kfree(sb_info); 319 331 } 320 332 321 333 static struct dentry *hypfs_create_file(struct dentry *parent, const char *name, ··· 320 340 struct dentry *dentry; 321 341 struct inode *inode; 322 342 323 - inode_lock(d_inode(parent)); 324 - dentry = lookup_noperm(&QSTR(name), parent); 325 - if (IS_ERR(dentry)) { 326 - dentry = ERR_PTR(-ENOMEM); 327 - goto fail; 328 - } 343 + dentry = simple_start_creating(parent, name); 344 + if (IS_ERR(dentry)) 345 + return ERR_PTR(-ENOMEM); 329 346 inode = hypfs_make_inode(parent->d_sb, mode); 330 347 if (!inode) { 331 - dput(dentry); 332 - dentry = ERR_PTR(-ENOMEM); 333 - goto fail; 348 + simple_done_creating(dentry); 349 + return ERR_PTR(-ENOMEM); 334 350 } 335 351 if (S_ISREG(mode)) { 336 352 inode->i_fop = &hypfs_file_ops; ··· 341 365 } else 342 366 BUG(); 343 367 inode->i_private = data; 344 - d_instantiate(dentry, inode); 345 - dget(dentry); 346 - fail: 347 - inode_unlock(d_inode(parent)); 348 - return dentry; 368 + d_make_persistent(dentry, inode); 369 + simple_done_creating(dentry); 370 + return dentry; // borrowed 349 371 } 350 372 351 373 struct dentry *hypfs_mkdir(struct dentry *parent, const char *name) ··· 371 397 return dentry; 372 398 } 373 399 374 - struct dentry *hypfs_create_u64(struct dentry *dir, 375 - const char *name, __u64 value) 400 + int hypfs_create_u64(struct dentry *dir, const char *name, __u64 value) 376 401 { 377 402 char *buffer; 378 403 char tmp[TMP_SIZE]; ··· 380 407 snprintf(tmp, TMP_SIZE, "%llu\n", (unsigned long long int)value); 381 408 buffer = kstrdup(tmp, GFP_KERNEL); 382 409 if (!buffer) 383 - return ERR_PTR(-ENOMEM); 410 + return -ENOMEM; 384 411 dentry = 385 412 hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE); 386 413 if (IS_ERR(dentry)) { 387 414 kfree(buffer); 388 - return ERR_PTR(-ENOMEM); 415 + return -ENOMEM; 389 416 } 390 417 hypfs_add_dentry(dentry); 391 - return dentry; 418 + return 0; 392 419 } 393 420 394 - struct dentry *hypfs_create_str(struct dentry *dir, 395 - const char *name, char *string) 421 + int hypfs_create_str(struct dentry *dir, const char *name, char *string) 396 422 { 397 423 char *buffer; 398 424 struct dentry *dentry; 399 425 400 426 buffer = kmalloc(strlen(string) + 2, GFP_KERNEL); 401 427 if (!buffer) 402 - return ERR_PTR(-ENOMEM); 428 + return -ENOMEM; 403 429 sprintf(buffer, "%s\n", string); 404 430 dentry = 405 431 hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE); 406 432 if (IS_ERR(dentry)) { 407 433 kfree(buffer); 408 - return ERR_PTR(-ENOMEM); 434 + return -ENOMEM; 409 435 } 410 436 hypfs_add_dentry(dentry); 411 - return dentry; 437 + return 0; 412 438 } 413 439 414 440 static const struct file_operations hypfs_file_ops = {
+33 -88
drivers/android/binder/rust_binderfs.c
··· 178 178 } 179 179 180 180 root = sb->s_root; 181 - inode_lock(d_inode(root)); 182 - 183 - /* look it up */ 184 - dentry = lookup_noperm(&QSTR(req->name), root); 181 + dentry = simple_start_creating(root, req->name); 185 182 if (IS_ERR(dentry)) { 186 - inode_unlock(d_inode(root)); 187 183 ret = PTR_ERR(dentry); 188 184 goto err; 189 185 } 190 186 191 - if (d_really_is_positive(dentry)) { 192 - /* already exists */ 193 - dput(dentry); 194 - inode_unlock(d_inode(root)); 195 - ret = -EEXIST; 196 - goto err; 197 - } 198 - 199 187 inode->i_private = device; 200 - d_instantiate(dentry, inode); 188 + d_make_persistent(dentry, inode); 189 + 201 190 fsnotify_create(root->d_inode, dentry); 202 - inode_unlock(d_inode(root)); 191 + simple_done_creating(dentry); 203 192 204 193 return 0; 205 194 ··· 461 472 return ret; 462 473 } 463 474 464 - static struct dentry *binderfs_create_dentry(struct dentry *parent, 465 - const char *name) 466 - { 467 - struct dentry *dentry; 468 - 469 - dentry = lookup_noperm(&QSTR(name), parent); 470 - if (IS_ERR(dentry)) 471 - return dentry; 472 - 473 - /* Return error if the file/dir already exists. */ 474 - if (d_really_is_positive(dentry)) { 475 - dput(dentry); 476 - return ERR_PTR(-EEXIST); 477 - } 478 - 479 - return dentry; 480 - } 481 - 482 475 void rust_binderfs_remove_file(struct dentry *dentry) 483 476 { 484 - struct inode *parent_inode; 485 - 486 - parent_inode = d_inode(dentry->d_parent); 487 - inode_lock(parent_inode); 488 - if (simple_positive(dentry)) { 489 - dget(dentry); 490 - simple_unlink(parent_inode, dentry); 491 - d_delete(dentry); 492 - dput(dentry); 493 - } 494 - inode_unlock(parent_inode); 477 + simple_recursive_removal(dentry, NULL); 495 478 } 496 479 497 480 static struct dentry *rust_binderfs_create_file(struct dentry *parent, const char *name, ··· 471 510 void *data) 472 511 { 473 512 struct dentry *dentry; 474 - struct inode *new_inode, *parent_inode; 475 - struct super_block *sb; 513 + struct inode *new_inode; 476 514 477 - parent_inode = d_inode(parent); 478 - inode_lock(parent_inode); 479 - 480 - dentry = binderfs_create_dentry(parent, name); 481 - if (IS_ERR(dentry)) 482 - goto out; 483 - 484 - sb = parent_inode->i_sb; 485 - new_inode = binderfs_make_inode(sb, S_IFREG | 0444); 486 - if (!new_inode) { 487 - dput(dentry); 488 - dentry = ERR_PTR(-ENOMEM); 489 - goto out; 490 - } 491 - 515 + new_inode = binderfs_make_inode(parent->d_sb, S_IFREG | 0444); 516 + if (!new_inode) 517 + return ERR_PTR(-ENOMEM); 492 518 new_inode->i_fop = fops; 493 519 new_inode->i_private = data; 494 - d_instantiate(dentry, new_inode); 495 - fsnotify_create(parent_inode, dentry); 496 520 497 - out: 498 - inode_unlock(parent_inode); 521 + dentry = simple_start_creating(parent, name); 522 + if (IS_ERR(dentry)) { 523 + iput(new_inode); 524 + return dentry; 525 + } 526 + 527 + d_make_persistent(dentry, new_inode); 528 + fsnotify_create(parent->d_inode, dentry); 529 + simple_done_creating(dentry); 499 530 return dentry; 500 531 } 501 532 ··· 509 556 const char *name) 510 557 { 511 558 struct dentry *dentry; 512 - struct inode *new_inode, *parent_inode; 513 - struct super_block *sb; 559 + struct inode *new_inode; 514 560 515 - parent_inode = d_inode(parent); 516 - inode_lock(parent_inode); 517 - 518 - dentry = binderfs_create_dentry(parent, name); 519 - if (IS_ERR(dentry)) 520 - goto out; 521 - 522 - sb = parent_inode->i_sb; 523 - new_inode = binderfs_make_inode(sb, S_IFDIR | 0755); 524 - if (!new_inode) { 525 - dput(dentry); 526 - dentry = ERR_PTR(-ENOMEM); 527 - goto out; 528 - } 561 + new_inode = binderfs_make_inode(parent->d_sb, S_IFDIR | 0755); 562 + if (!new_inode) 563 + return ERR_PTR(-ENOMEM); 529 564 530 565 new_inode->i_fop = &simple_dir_operations; 531 566 new_inode->i_op = &simple_dir_inode_operations; 532 567 533 - set_nlink(new_inode, 2); 534 - d_instantiate(dentry, new_inode); 535 - inc_nlink(parent_inode); 536 - fsnotify_mkdir(parent_inode, dentry); 568 + dentry = simple_start_creating(parent, name); 569 + if (IS_ERR(dentry)) { 570 + iput(new_inode); 571 + return dentry; 572 + } 537 573 538 - out: 539 - inode_unlock(parent_inode); 574 + inc_nlink(parent->d_inode); 575 + set_nlink(new_inode, 2); 576 + d_make_persistent(dentry, new_inode); 577 + fsnotify_mkdir(parent->d_inode, dentry); 578 + simple_done_creating(dentry); 540 579 return dentry; 541 580 } 542 581 ··· 747 802 * During inode eviction struct binderfs_info is needed. 748 803 * So first wipe the super_block then free struct binderfs_info. 749 804 */ 750 - kill_litter_super(sb); 805 + kill_anon_super(sb); 751 806 752 807 if (info && info->ipc_ns) 753 808 put_ipc_ns(info->ipc_ns);
+19 -63
drivers/android/binderfs.c
··· 183 183 } 184 184 185 185 root = sb->s_root; 186 - inode_lock(d_inode(root)); 187 - 188 - /* look it up */ 189 - dentry = lookup_noperm(&QSTR(name), root); 186 + dentry = simple_start_creating(root, name); 190 187 if (IS_ERR(dentry)) { 191 - inode_unlock(d_inode(root)); 192 188 ret = PTR_ERR(dentry); 193 189 goto err; 194 190 } 195 - 196 - if (d_really_is_positive(dentry)) { 197 - /* already exists */ 198 - dput(dentry); 199 - inode_unlock(d_inode(root)); 200 - ret = -EEXIST; 201 - goto err; 202 - } 203 - 204 191 inode->i_private = device; 205 - d_instantiate(dentry, inode); 192 + d_make_persistent(dentry, inode); 206 193 fsnotify_create(root->d_inode, dentry); 207 - inode_unlock(d_inode(root)); 194 + simple_done_creating(dentry); 208 195 209 196 binder_add_device(device); 210 197 ··· 397 410 if (!device) 398 411 return -ENOMEM; 399 412 400 - /* If we have already created a binder-control node, return. */ 401 - if (info->control_dentry) { 402 - ret = 0; 403 - goto out; 404 - } 405 - 406 413 ret = -ENOMEM; 407 414 inode = new_inode(sb); 408 415 if (!inode) ··· 432 451 433 452 inode->i_private = device; 434 453 info->control_dentry = dentry; 435 - d_add(dentry, inode); 454 + d_make_persistent(dentry, inode); 455 + dput(dentry); 436 456 437 457 return 0; 438 458 ··· 463 481 return ret; 464 482 } 465 483 466 - static struct dentry *binderfs_create_dentry(struct dentry *parent, 467 - const char *name) 468 - { 469 - struct dentry *dentry; 470 - 471 - dentry = lookup_noperm(&QSTR(name), parent); 472 - if (IS_ERR(dentry)) 473 - return dentry; 474 - 475 - /* Return error if the file/dir already exists. */ 476 - if (d_really_is_positive(dentry)) { 477 - dput(dentry); 478 - return ERR_PTR(-EEXIST); 479 - } 480 - 481 - return dentry; 482 - } 483 - 484 484 struct dentry *binderfs_create_file(struct dentry *parent, const char *name, 485 485 const struct file_operations *fops, 486 486 void *data) ··· 472 508 struct super_block *sb; 473 509 474 510 parent_inode = d_inode(parent); 475 - inode_lock(parent_inode); 476 511 477 - dentry = binderfs_create_dentry(parent, name); 512 + dentry = simple_start_creating(parent, name); 478 513 if (IS_ERR(dentry)) 479 - goto out; 514 + return dentry; 480 515 481 516 sb = parent_inode->i_sb; 482 517 new_inode = binderfs_make_inode(sb, S_IFREG | 0444); 483 518 if (!new_inode) { 484 - dput(dentry); 485 - dentry = ERR_PTR(-ENOMEM); 486 - goto out; 519 + simple_done_creating(dentry); 520 + return ERR_PTR(-ENOMEM); 487 521 } 488 522 489 523 new_inode->i_fop = fops; 490 524 new_inode->i_private = data; 491 - d_instantiate(dentry, new_inode); 525 + d_make_persistent(dentry, new_inode); 492 526 fsnotify_create(parent_inode, dentry); 493 - 494 - out: 495 - inode_unlock(parent_inode); 496 - return dentry; 527 + simple_done_creating(dentry); 528 + return dentry; // borrowed 497 529 } 498 530 499 531 static struct dentry *binderfs_create_dir(struct dentry *parent, ··· 500 540 struct super_block *sb; 501 541 502 542 parent_inode = d_inode(parent); 503 - inode_lock(parent_inode); 504 543 505 - dentry = binderfs_create_dentry(parent, name); 544 + dentry = simple_start_creating(parent, name); 506 545 if (IS_ERR(dentry)) 507 - goto out; 546 + return dentry; 508 547 509 548 sb = parent_inode->i_sb; 510 549 new_inode = binderfs_make_inode(sb, S_IFDIR | 0755); 511 550 if (!new_inode) { 512 - dput(dentry); 513 - dentry = ERR_PTR(-ENOMEM); 514 - goto out; 551 + simple_done_creating(dentry); 552 + return ERR_PTR(-ENOMEM); 515 553 } 516 554 517 555 new_inode->i_fop = &simple_dir_operations; 518 556 new_inode->i_op = &simple_dir_inode_operations; 519 557 520 558 set_nlink(new_inode, 2); 521 - d_instantiate(dentry, new_inode); 559 + d_make_persistent(dentry, new_inode); 522 560 inc_nlink(parent_inode); 523 561 fsnotify_mkdir(parent_inode, dentry); 524 - 525 - out: 526 - inode_unlock(parent_inode); 562 + simple_done_creating(dentry); 527 563 return dentry; 528 564 } 529 565 ··· 735 779 * During inode eviction struct binderfs_info is needed. 736 780 * So first wipe the super_block then free struct binderfs_info. 737 781 */ 738 - kill_litter_super(sb); 782 + kill_anon_super(sb); 739 783 740 784 if (info && info->ipc_ns) 741 785 put_ipc_ns(info->ipc_ns);
+1 -1
drivers/base/devtmpfs.c
··· 70 70 #else 71 71 .init_fs_context = ramfs_init_fs_context, 72 72 #endif 73 - .kill_sb = kill_litter_super, 73 + .kill_sb = kill_anon_super, 74 74 }; 75 75 76 76 /* Simply take a ref on the existing mount */
+12 -12
drivers/misc/ibmasm/ibmasmfs.c
··· 97 97 .drop_inode = inode_just_drop, 98 98 }; 99 99 100 - static const struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations; 101 - 102 100 static struct file_system_type ibmasmfs_type = { 103 101 .owner = THIS_MODULE, 104 102 .name = "ibmasmfs", 105 103 .init_fs_context = ibmasmfs_init_fs_context, 106 - .kill_sb = kill_litter_super, 104 + .kill_sb = kill_anon_super, 107 105 }; 108 106 MODULE_ALIAS_FS("ibmasmfs"); 109 107 ··· 120 122 return -ENOMEM; 121 123 122 124 root->i_op = &simple_dir_inode_operations; 123 - root->i_fop = ibmasmfs_dir_ops; 125 + root->i_fop = &simple_dir_operations; 124 126 125 127 sb->s_root = d_make_root(root); 126 128 if (!sb->s_root) ··· 142 144 return ret; 143 145 } 144 146 145 - static struct dentry *ibmasmfs_create_file(struct dentry *parent, 147 + static int ibmasmfs_create_file(struct dentry *parent, 146 148 const char *name, 147 149 const struct file_operations *fops, 148 150 void *data, ··· 153 155 154 156 dentry = d_alloc_name(parent, name); 155 157 if (!dentry) 156 - return NULL; 158 + return -ENOMEM; 157 159 158 160 inode = ibmasmfs_make_inode(parent->d_sb, S_IFREG | mode); 159 161 if (!inode) { 160 162 dput(dentry); 161 - return NULL; 163 + return -ENOMEM; 162 164 } 163 165 164 166 inode->i_fop = fops; 165 167 inode->i_private = data; 166 168 167 - d_add(dentry, inode); 168 - return dentry; 169 + d_make_persistent(dentry, inode); 170 + dput(dentry); 171 + return 0; 169 172 } 170 173 171 174 static struct dentry *ibmasmfs_create_dir(struct dentry *parent, ··· 186 187 } 187 188 188 189 inode->i_op = &simple_dir_inode_operations; 189 - inode->i_fop = ibmasmfs_dir_ops; 190 + inode->i_fop = &simple_dir_operations; 190 191 191 - d_add(dentry, inode); 192 - return dentry; 192 + d_make_persistent(dentry, inode); 193 + dput(dentry); 194 + return dentry; // borrowed 193 195 } 194 196 195 197 int ibmasmfs_register(void)
+86 -58
drivers/usb/gadget/function/f_fs.c
··· 160 160 struct ffs_data *ffs; 161 161 struct ffs_ep *ep; /* P: ffs->eps_lock */ 162 162 163 - struct dentry *dentry; 164 - 165 163 /* 166 164 * Buffer for holding data from partial reads which may happen since 167 165 * we’re rounding user read requests to a multiple of a max packet size. ··· 269 271 }; 270 272 271 273 static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 272 - static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 274 + static void ffs_epfiles_destroy(struct super_block *sb, 275 + struct ffs_epfile *epfiles, unsigned count); 273 276 274 - static struct dentry * 275 - ffs_sb_create_file(struct super_block *sb, const char *name, void *data, 276 - const struct file_operations *fops); 277 + static int ffs_sb_create_file(struct super_block *sb, const char *name, 278 + void *data, const struct file_operations *fops); 277 279 278 280 /* Devices management *******************************************************/ 279 281 ··· 638 640 639 641 static int ffs_ep0_open(struct inode *inode, struct file *file) 640 642 { 641 - struct ffs_data *ffs = inode->i_private; 643 + struct ffs_data *ffs = inode->i_sb->s_fs_info; 644 + int ret; 642 645 643 - if (ffs->state == FFS_CLOSING) 644 - return -EBUSY; 646 + /* Acquire mutex */ 647 + ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); 648 + if (ret < 0) 649 + return ret; 645 650 646 - file->private_data = ffs; 647 651 ffs_data_opened(ffs); 652 + if (ffs->state == FFS_CLOSING) { 653 + ffs_data_closed(ffs); 654 + mutex_unlock(&ffs->mutex); 655 + return -EBUSY; 656 + } 657 + mutex_unlock(&ffs->mutex); 658 + file->private_data = ffs; 648 659 649 660 return stream_open(inode, file); 650 661 } ··· 1200 1193 static int 1201 1194 ffs_epfile_open(struct inode *inode, struct file *file) 1202 1195 { 1203 - struct ffs_epfile *epfile = inode->i_private; 1196 + struct ffs_data *ffs = inode->i_sb->s_fs_info; 1197 + struct ffs_epfile *epfile; 1198 + int ret; 1204 1199 1205 - if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) 1200 + /* Acquire mutex */ 1201 + ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); 1202 + if (ret < 0) 1203 + return ret; 1204 + 1205 + if (!atomic_inc_not_zero(&ffs->opened)) { 1206 + mutex_unlock(&ffs->mutex); 1206 1207 return -ENODEV; 1208 + } 1209 + /* 1210 + * we want the state to be FFS_ACTIVE; FFS_ACTIVE alone is 1211 + * not enough, though - we might have been through FFS_CLOSING 1212 + * and back to FFS_ACTIVE, with our file already removed. 1213 + */ 1214 + epfile = smp_load_acquire(&inode->i_private); 1215 + if (unlikely(ffs->state != FFS_ACTIVE || !epfile)) { 1216 + mutex_unlock(&ffs->mutex); 1217 + ffs_data_closed(ffs); 1218 + return -ENODEV; 1219 + } 1220 + mutex_unlock(&ffs->mutex); 1207 1221 1208 1222 file->private_data = epfile; 1209 - ffs_data_opened(epfile->ffs); 1210 - 1211 1223 return stream_open(inode, file); 1212 1224 } 1213 1225 ··· 1358 1332 static int 1359 1333 ffs_epfile_release(struct inode *inode, struct file *file) 1360 1334 { 1361 - struct ffs_epfile *epfile = inode->i_private; 1335 + struct ffs_epfile *epfile = file->private_data; 1362 1336 struct ffs_dmabuf_priv *priv, *tmp; 1363 1337 struct ffs_data *ffs = epfile->ffs; 1364 1338 ··· 1892 1866 } 1893 1867 1894 1868 /* Create "regular" file */ 1895 - static struct dentry *ffs_sb_create_file(struct super_block *sb, 1896 - const char *name, void *data, 1897 - const struct file_operations *fops) 1869 + static int ffs_sb_create_file(struct super_block *sb, const char *name, 1870 + void *data, const struct file_operations *fops) 1898 1871 { 1899 1872 struct ffs_data *ffs = sb->s_fs_info; 1900 1873 struct dentry *dentry; 1901 1874 struct inode *inode; 1902 1875 1903 - dentry = d_alloc_name(sb->s_root, name); 1904 - if (!dentry) 1905 - return NULL; 1906 - 1907 1876 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); 1908 - if (!inode) { 1909 - dput(dentry); 1910 - return NULL; 1877 + if (!inode) 1878 + return -ENOMEM; 1879 + dentry = simple_start_creating(sb->s_root, name); 1880 + if (IS_ERR(dentry)) { 1881 + iput(inode); 1882 + return PTR_ERR(dentry); 1911 1883 } 1912 1884 1913 - d_add(dentry, inode); 1914 - return dentry; 1885 + d_make_persistent(dentry, inode); 1886 + 1887 + simple_done_creating(dentry); 1888 + return 0; 1915 1889 } 1916 1890 1917 1891 /* Super block */ ··· 1954 1928 return -ENOMEM; 1955 1929 1956 1930 /* EP0 file */ 1957 - if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) 1958 - return -ENOMEM; 1959 - 1960 - return 0; 1931 + return ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations); 1961 1932 } 1962 1933 1963 1934 enum { ··· 2094 2071 return 0; 2095 2072 } 2096 2073 2074 + static void ffs_data_reset(struct ffs_data *ffs); 2075 + 2097 2076 static void 2098 2077 ffs_fs_kill_sb(struct super_block *sb) 2099 2078 { 2100 - kill_litter_super(sb); 2101 - if (sb->s_fs_info) 2102 - ffs_data_closed(sb->s_fs_info); 2079 + kill_anon_super(sb); 2080 + if (sb->s_fs_info) { 2081 + struct ffs_data *ffs = sb->s_fs_info; 2082 + ffs->state = FFS_CLOSING; 2083 + ffs_data_reset(ffs); 2084 + // no configfs accesses from that point on, 2085 + // so no further schedule_work() is possible 2086 + cancel_work_sync(&ffs->reset_work); 2087 + ffs_data_put(ffs); 2088 + } 2103 2089 } 2104 2090 2105 2091 static struct file_system_type ffs_fs_type = { ··· 2146 2114 /* ffs_data and ffs_function construction and destruction code **************/ 2147 2115 2148 2116 static void ffs_data_clear(struct ffs_data *ffs); 2149 - static void ffs_data_reset(struct ffs_data *ffs); 2150 2117 2151 2118 static void ffs_data_get(struct ffs_data *ffs) 2152 2119 { ··· 2154 2123 2155 2124 static void ffs_data_opened(struct ffs_data *ffs) 2156 2125 { 2157 - refcount_inc(&ffs->ref); 2158 2126 if (atomic_add_return(1, &ffs->opened) == 1 && 2159 2127 ffs->state == FFS_DEACTIVATED) { 2160 2128 ffs->state = FFS_CLOSING; ··· 2178 2148 2179 2149 static void ffs_data_closed(struct ffs_data *ffs) 2180 2150 { 2181 - struct ffs_epfile *epfiles; 2182 - unsigned long flags; 2183 - 2184 2151 if (atomic_dec_and_test(&ffs->opened)) { 2185 2152 if (ffs->no_disconnect) { 2153 + struct ffs_epfile *epfiles; 2154 + unsigned long flags; 2155 + 2186 2156 ffs->state = FFS_DEACTIVATED; 2187 2157 spin_lock_irqsave(&ffs->eps_lock, flags); 2188 2158 epfiles = ffs->epfiles; ··· 2191 2161 flags); 2192 2162 2193 2163 if (epfiles) 2194 - ffs_epfiles_destroy(epfiles, 2164 + ffs_epfiles_destroy(ffs->sb, epfiles, 2195 2165 ffs->eps_count); 2196 2166 2197 2167 if (ffs->setup_state == FFS_SETUP_PENDING) ··· 2201 2171 ffs_data_reset(ffs); 2202 2172 } 2203 2173 } 2204 - if (atomic_read(&ffs->opened) < 0) { 2205 - ffs->state = FFS_CLOSING; 2206 - ffs_data_reset(ffs); 2207 - } 2208 - 2209 - ffs_data_put(ffs); 2210 2174 } 2211 2175 2212 2176 static struct ffs_data *ffs_data_new(const char *dev_name) ··· 2250 2226 * copy of epfile will save us from use-after-free. 2251 2227 */ 2252 2228 if (epfiles) { 2253 - ffs_epfiles_destroy(epfiles, ffs->eps_count); 2229 + ffs_epfiles_destroy(ffs->sb, epfiles, ffs->eps_count); 2254 2230 ffs->epfiles = NULL; 2255 2231 } 2256 2232 ··· 2347 2323 { 2348 2324 struct ffs_epfile *epfile, *epfiles; 2349 2325 unsigned i, count; 2326 + int err; 2350 2327 2351 2328 count = ffs->eps_count; 2352 2329 epfiles = kcalloc(count, sizeof(*epfiles), GFP_KERNEL); ··· 2364 2339 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); 2365 2340 else 2366 2341 sprintf(epfile->name, "ep%u", i); 2367 - epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, 2368 - epfile, 2369 - &ffs_epfile_operations); 2370 - if (!epfile->dentry) { 2371 - ffs_epfiles_destroy(epfiles, i - 1); 2372 - return -ENOMEM; 2342 + err = ffs_sb_create_file(ffs->sb, epfile->name, 2343 + epfile, &ffs_epfile_operations); 2344 + if (err) { 2345 + ffs_epfiles_destroy(ffs->sb, epfiles, i - 1); 2346 + return err; 2373 2347 } 2374 2348 } 2375 2349 ··· 2376 2352 return 0; 2377 2353 } 2378 2354 2379 - static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) 2355 + static void clear_one(struct dentry *dentry) 2356 + { 2357 + smp_store_release(&dentry->d_inode->i_private, NULL); 2358 + } 2359 + 2360 + static void ffs_epfiles_destroy(struct super_block *sb, 2361 + struct ffs_epfile *epfiles, unsigned count) 2380 2362 { 2381 2363 struct ffs_epfile *epfile = epfiles; 2364 + struct dentry *root = sb->s_root; 2382 2365 2383 2366 for (; count; --count, ++epfile) { 2384 2367 BUG_ON(mutex_is_locked(&epfile->mutex)); 2385 - if (epfile->dentry) { 2386 - simple_recursive_removal(epfile->dentry, NULL); 2387 - epfile->dentry = NULL; 2388 - } 2368 + simple_remove_by_name(root, epfile->name, clear_one); 2389 2369 } 2390 2370 2391 2371 kfree(epfiles);
+23 -26
drivers/usb/gadget/legacy/inode.c
··· 150 150 void *buf; 151 151 wait_queue_head_t wait; 152 152 struct super_block *sb; 153 - struct dentry *dentry; 154 153 155 154 /* except this scratch i/o buffer for ep0 */ 156 155 u8 rbuf[RBUF_SIZE]; ··· 207 208 struct usb_endpoint_descriptor desc, hs_desc; 208 209 struct list_head epfiles; 209 210 wait_queue_head_t wait; 210 - struct dentry *dentry; 211 211 }; 212 212 213 213 static inline void get_ep (struct ep_data *data) ··· 1559 1561 spin_lock_irq (&dev->lock); 1560 1562 while (!list_empty(&dev->epfiles)) { 1561 1563 struct ep_data *ep; 1562 - struct dentry *dentry; 1563 1564 1564 1565 /* break link to FS */ 1565 1566 ep = list_first_entry (&dev->epfiles, struct ep_data, epfiles); 1566 1567 list_del_init (&ep->epfiles); 1567 1568 spin_unlock_irq (&dev->lock); 1568 - 1569 - dentry = ep->dentry; 1570 - ep->dentry = NULL; 1571 1569 1572 1570 /* break link to controller */ 1573 1571 mutex_lock(&ep->lock); ··· 1575 1581 mutex_unlock(&ep->lock); 1576 1582 1577 1583 wake_up (&ep->wait); 1578 - put_ep (ep); 1579 1584 1580 1585 /* break link to dcache */ 1581 - simple_recursive_removal(dentry, NULL); 1586 + simple_remove_by_name(dev->sb->s_root, ep->name, NULL); 1587 + 1588 + put_ep (ep); 1582 1589 1583 1590 spin_lock_irq (&dev->lock); 1584 1591 } ··· 1587 1592 } 1588 1593 1589 1594 1590 - static struct dentry * 1591 - gadgetfs_create_file (struct super_block *sb, char const *name, 1595 + static int gadgetfs_create_file (struct super_block *sb, char const *name, 1592 1596 void *data, const struct file_operations *fops); 1593 1597 1594 1598 static int activate_ep_files (struct dev_data *dev) 1595 1599 { 1596 1600 struct usb_ep *ep; 1597 1601 struct ep_data *data; 1602 + int err; 1598 1603 1599 1604 gadget_for_each_ep (ep, dev->gadget) { 1600 1605 ··· 1617 1622 if (!data->req) 1618 1623 goto enomem1; 1619 1624 1620 - data->dentry = gadgetfs_create_file (dev->sb, data->name, 1625 + err = gadgetfs_create_file (dev->sb, data->name, 1621 1626 data, &ep_io_operations); 1622 - if (!data->dentry) 1627 + if (err) 1623 1628 goto enomem2; 1624 1629 list_add_tail (&data->epfiles, &dev->epfiles); 1625 1630 } ··· 1983 1988 /* creates in fs root directory, so non-renamable and non-linkable. 1984 1989 * so inode and dentry are paired, until device reconfig. 1985 1990 */ 1986 - static struct dentry * 1987 - gadgetfs_create_file (struct super_block *sb, char const *name, 1991 + static int gadgetfs_create_file (struct super_block *sb, char const *name, 1988 1992 void *data, const struct file_operations *fops) 1989 1993 { 1990 1994 struct dentry *dentry; 1991 1995 struct inode *inode; 1992 1996 1993 - dentry = d_alloc_name(sb->s_root, name); 1994 - if (!dentry) 1995 - return NULL; 1996 - 1997 1997 inode = gadgetfs_make_inode (sb, data, fops, 1998 1998 S_IFREG | (default_perm & S_IRWXUGO)); 1999 - if (!inode) { 2000 - dput(dentry); 2001 - return NULL; 1999 + if (!inode) 2000 + return -ENOMEM; 2001 + 2002 + dentry = simple_start_creating(sb->s_root, name); 2003 + if (IS_ERR(dentry)) { 2004 + iput(inode); 2005 + return PTR_ERR(dentry); 2002 2006 } 2003 - d_add (dentry, inode); 2004 - return dentry; 2007 + 2008 + d_make_persistent(dentry, inode); 2009 + 2010 + simple_done_creating(dentry); 2011 + return 0; 2005 2012 } 2006 2013 2007 2014 static const struct super_operations gadget_fs_operations = { ··· 2056 2059 goto Enomem; 2057 2060 2058 2061 dev->sb = sb; 2059 - dev->dentry = gadgetfs_create_file(sb, CHIP, dev, &ep0_operations); 2060 - if (!dev->dentry) { 2062 + rc = gadgetfs_create_file(sb, CHIP, dev, &ep0_operations); 2063 + if (rc) { 2061 2064 put_dev(dev); 2062 2065 goto Enomem; 2063 2066 } ··· 2099 2102 gadgetfs_kill_sb (struct super_block *sb) 2100 2103 { 2101 2104 mutex_lock(&sb_mutex); 2102 - kill_litter_super (sb); 2105 + kill_anon_super (sb); 2103 2106 if (the_device) { 2104 2107 put_dev (the_device); 2105 2108 the_device = NULL;
+1 -1
drivers/xen/xenfs/super.c
··· 88 88 .owner = THIS_MODULE, 89 89 .name = "xenfs", 90 90 .init_fs_context = xenfs_init_fs_context, 91 - .kill_sb = kill_litter_super, 91 + .kill_sb = kill_anon_super, 92 92 }; 93 93 MODULE_ALIAS_FS("xenfs"); 94 94
+1 -1
fs/autofs/inode.c
··· 55 55 } 56 56 57 57 pr_debug("shutting down\n"); 58 - kill_litter_super(sb); 58 + kill_anon_super(sb); 59 59 if (sbi) 60 60 kfree_rcu(sbi, rcu); 61 61 }
+4 -7
fs/autofs/root.c
··· 602 602 } 603 603 inode->i_private = cp; 604 604 inode->i_size = size; 605 - d_add(dentry, inode); 606 605 607 - dget(dentry); 606 + d_make_persistent(dentry, inode); 608 607 p_ino = autofs_dentry_ino(dentry->d_parent); 609 608 p_ino->count++; 610 609 ··· 630 631 static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry) 631 632 { 632 633 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb); 633 - struct autofs_info *ino = autofs_dentry_ino(dentry); 634 634 struct autofs_info *p_ino; 635 635 636 636 p_ino = autofs_dentry_ino(dentry->d_parent); 637 637 p_ino->count--; 638 - dput(ino->dentry); 638 + d_make_discardable(dentry); 639 639 640 640 d_inode(dentry)->i_size = 0; 641 641 clear_nlink(d_inode(dentry)); ··· 716 718 717 719 p_ino = autofs_dentry_ino(dentry->d_parent); 718 720 p_ino->count--; 719 - dput(ino->dentry); 721 + d_make_discardable(dentry); 720 722 d_inode(dentry)->i_size = 0; 721 723 clear_nlink(d_inode(dentry)); 722 724 ··· 746 748 inode = autofs_get_inode(dir->i_sb, S_IFDIR | mode); 747 749 if (!inode) 748 750 return ERR_PTR(-ENOMEM); 749 - d_add(dentry, inode); 750 751 751 752 if (sbi->version < 5) 752 753 autofs_set_leaf_automount_flags(dentry); 753 754 754 - dget(dentry); 755 + d_make_persistent(dentry, inode); 755 756 p_ino = autofs_dentry_ino(dentry->d_parent); 756 757 p_ino->count++; 757 758 inc_nlink(dir);
+32 -37
fs/binfmt_misc.c
··· 765 765 766 766 /* /register */ 767 767 768 + /* add to filesystem */ 769 + static int add_entry(Node *e, struct super_block *sb) 770 + { 771 + struct dentry *dentry = simple_start_creating(sb->s_root, e->name); 772 + struct inode *inode; 773 + struct binfmt_misc *misc; 774 + 775 + if (IS_ERR(dentry)) 776 + return PTR_ERR(dentry); 777 + 778 + inode = bm_get_inode(sb, S_IFREG | 0644); 779 + if (unlikely(!inode)) { 780 + simple_done_creating(dentry); 781 + return -ENOMEM; 782 + } 783 + 784 + refcount_set(&e->users, 1); 785 + e->dentry = dentry; 786 + inode->i_private = e; 787 + inode->i_fop = &bm_entry_operations; 788 + 789 + d_make_persistent(dentry, inode); 790 + misc = i_binfmt_misc(inode); 791 + write_lock(&misc->entries_lock); 792 + list_add(&e->list, &misc->entries); 793 + write_unlock(&misc->entries_lock); 794 + simple_done_creating(dentry); 795 + return 0; 796 + } 797 + 768 798 static ssize_t bm_register_write(struct file *file, const char __user *buffer, 769 799 size_t count, loff_t *ppos) 770 800 { 771 801 Node *e; 772 - struct inode *inode; 773 802 struct super_block *sb = file_inode(file)->i_sb; 774 - struct dentry *root = sb->s_root, *dentry; 775 - struct binfmt_misc *misc; 776 803 int err = 0; 777 804 struct file *f = NULL; 778 805 ··· 827 800 e->interp_file = f; 828 801 } 829 802 830 - inode_lock(d_inode(root)); 831 - dentry = lookup_noperm(&QSTR(e->name), root); 832 - err = PTR_ERR(dentry); 833 - if (IS_ERR(dentry)) 834 - goto out; 835 - 836 - err = -EEXIST; 837 - if (d_really_is_positive(dentry)) 838 - goto out2; 839 - 840 - inode = bm_get_inode(sb, S_IFREG | 0644); 841 - 842 - err = -ENOMEM; 843 - if (!inode) 844 - goto out2; 845 - 846 - refcount_set(&e->users, 1); 847 - e->dentry = dget(dentry); 848 - inode->i_private = e; 849 - inode->i_fop = &bm_entry_operations; 850 - 851 - d_instantiate(dentry, inode); 852 - misc = i_binfmt_misc(inode); 853 - write_lock(&misc->entries_lock); 854 - list_add(&e->list, &misc->entries); 855 - write_unlock(&misc->entries_lock); 856 - 857 - err = 0; 858 - out2: 859 - dput(dentry); 860 - out: 861 - inode_unlock(d_inode(root)); 862 - 803 + err = add_entry(e, sb); 863 804 if (err) { 864 805 if (f) { 865 806 exe_file_allow_write_access(f); ··· 1022 1027 .name = "binfmt_misc", 1023 1028 .init_fs_context = bm_init_fs_context, 1024 1029 .fs_flags = FS_USERNS_MOUNT, 1025 - .kill_sb = kill_litter_super, 1030 + .kill_sb = kill_anon_super, 1026 1031 }; 1027 1032 MODULE_ALIAS_FS("binfmt_misc"); 1028 1033
+8 -2
fs/configfs/dir.c
··· 400 400 401 401 configfs_remove_dirent(d); 402 402 403 - if (d_really_is_positive(d)) 404 - simple_rmdir(d_inode(parent),d); 403 + if (d_really_is_positive(d)) { 404 + if (likely(simple_empty(d))) { 405 + __simple_rmdir(d_inode(parent),d); 406 + dput(d); 407 + } else { 408 + pr_warn("remove_dir (%pd): attributes remain", d); 409 + } 410 + } 405 411 406 412 pr_debug(" o %pd removing done (%d)\n", d, d_count(d)); 407 413
+2 -1
fs/configfs/inode.c
··· 211 211 dget_dlock(dentry); 212 212 __d_drop(dentry); 213 213 spin_unlock(&dentry->d_lock); 214 - simple_unlink(d_inode(parent), dentry); 214 + __simple_unlink(d_inode(parent), dentry); 215 + dput(dentry); 215 216 } else 216 217 spin_unlock(&dentry->d_lock); 217 218 }
+1 -1
fs/configfs/mount.c
··· 116 116 .owner = THIS_MODULE, 117 117 .name = "configfs", 118 118 .init_fs_context = configfs_init_fs_context, 119 - .kill_sb = kill_litter_super, 119 + .kill_sb = kill_anon_super, 120 120 }; 121 121 MODULE_ALIAS_FS("configfs"); 122 122
+72 -39
fs/dcache.c
··· 870 870 return false; 871 871 } 872 872 873 + static void finish_dput(struct dentry *dentry) 874 + __releases(dentry->d_lock) 875 + __releases(RCU) 876 + { 877 + while (lock_for_kill(dentry)) { 878 + rcu_read_unlock(); 879 + dentry = __dentry_kill(dentry); 880 + if (!dentry) 881 + return; 882 + if (retain_dentry(dentry, true)) { 883 + spin_unlock(&dentry->d_lock); 884 + return; 885 + } 886 + rcu_read_lock(); 887 + } 888 + rcu_read_unlock(); 889 + spin_unlock(&dentry->d_lock); 890 + } 873 891 874 892 /* 875 893 * This is dput ··· 925 907 rcu_read_unlock(); 926 908 return; 927 909 } 928 - while (lock_for_kill(dentry)) { 929 - rcu_read_unlock(); 930 - dentry = __dentry_kill(dentry); 931 - if (!dentry) 932 - return; 933 - if (retain_dentry(dentry, true)) { 934 - spin_unlock(&dentry->d_lock); 935 - return; 936 - } 937 - rcu_read_lock(); 938 - } 939 - rcu_read_unlock(); 940 - spin_unlock(&dentry->d_lock); 910 + finish_dput(dentry); 941 911 } 942 912 EXPORT_SYMBOL(dput); 913 + 914 + void d_make_discardable(struct dentry *dentry) 915 + { 916 + spin_lock(&dentry->d_lock); 917 + WARN_ON(!(dentry->d_flags & DCACHE_PERSISTENT)); 918 + dentry->d_flags &= ~DCACHE_PERSISTENT; 919 + dentry->d_lockref.count--; 920 + rcu_read_lock(); 921 + finish_dput(dentry); 922 + } 923 + EXPORT_SYMBOL(d_make_discardable); 943 924 944 925 static void to_shrink_list(struct dentry *dentry, struct list_head *list) 945 926 __must_hold(&dentry->d_lock) ··· 1529 1512 return ret; 1530 1513 } 1531 1514 1515 + static enum d_walk_ret select_collect_umount(void *_data, struct dentry *dentry) 1516 + { 1517 + if (dentry->d_flags & DCACHE_PERSISTENT) { 1518 + dentry->d_flags &= ~DCACHE_PERSISTENT; 1519 + dentry->d_lockref.count--; 1520 + } 1521 + return select_collect(_data, dentry); 1522 + } 1523 + 1532 1524 static enum d_walk_ret select_collect2(void *_data, struct dentry *dentry) 1533 1525 { 1534 1526 struct select_data *data = _data; ··· 1566 1540 } 1567 1541 1568 1542 /** 1569 - * shrink_dcache_parent - prune dcache 1543 + * shrink_dcache_tree - prune dcache 1570 1544 * @parent: parent of entries to prune 1545 + * @for_umount: true if we want to unpin the persistent ones 1571 1546 * 1572 1547 * Prune the dcache to remove unused children of the parent dentry. 1573 1548 */ 1574 - void shrink_dcache_parent(struct dentry *parent) 1549 + static void shrink_dcache_tree(struct dentry *parent, bool for_umount) 1575 1550 { 1576 1551 for (;;) { 1577 1552 struct select_data data = {.start = parent}; 1578 1553 1579 1554 INIT_LIST_HEAD(&data.dispose); 1580 - d_walk(parent, &data, select_collect); 1555 + d_walk(parent, &data, 1556 + for_umount ? select_collect_umount : select_collect); 1581 1557 1582 1558 if (!list_empty(&data.dispose)) { 1583 1559 shrink_dentry_list(&data.dispose); ··· 1603 1575 if (!list_empty(&data.dispose)) 1604 1576 shrink_dentry_list(&data.dispose); 1605 1577 } 1578 + } 1579 + 1580 + void shrink_dcache_parent(struct dentry *parent) 1581 + { 1582 + shrink_dcache_tree(parent, false); 1606 1583 } 1607 1584 EXPORT_SYMBOL(shrink_dcache_parent); 1608 1585 ··· 1635 1602 1636 1603 static void do_one_tree(struct dentry *dentry) 1637 1604 { 1638 - shrink_dcache_parent(dentry); 1605 + shrink_dcache_tree(dentry, true); 1639 1606 d_walk(dentry, dentry, umount_check); 1640 1607 d_drop(dentry); 1641 1608 dput(dentry); ··· 1957 1924 unsigned add_flags = d_flags_for_inode(inode); 1958 1925 WARN_ON(d_in_lookup(dentry)); 1959 1926 1960 - spin_lock(&dentry->d_lock); 1961 1927 /* 1962 1928 * The negative counter only tracks dentries on the LRU. Don't dec if 1963 1929 * d_lru is on another list. ··· 1969 1937 __d_set_inode_and_type(dentry, inode, add_flags); 1970 1938 raw_write_seqcount_end(&dentry->d_seq); 1971 1939 fsnotify_update_flags(dentry); 1972 - spin_unlock(&dentry->d_lock); 1973 1940 } 1974 1941 1975 1942 /** ··· 1992 1961 if (inode) { 1993 1962 security_d_instantiate(entry, inode); 1994 1963 spin_lock(&inode->i_lock); 1964 + spin_lock(&entry->d_lock); 1995 1965 __d_instantiate(entry, inode); 1966 + spin_unlock(&entry->d_lock); 1996 1967 spin_unlock(&inode->i_lock); 1997 1968 } 1998 1969 } ··· 2013 1980 lockdep_annotate_inode_mutex_key(inode); 2014 1981 security_d_instantiate(entry, inode); 2015 1982 spin_lock(&inode->i_lock); 1983 + spin_lock(&entry->d_lock); 2016 1984 __d_instantiate(entry, inode); 1985 + spin_unlock(&entry->d_lock); 2017 1986 WARN_ON(!(inode_state_read(inode) & I_NEW)); 2018 1987 inode_state_clear(inode, I_NEW | I_CREATING); 2019 1988 inode_wake_up_bit(inode, __I_NEW); ··· 2777 2742 } 2778 2743 EXPORT_SYMBOL(d_add); 2779 2744 2745 + struct dentry *d_make_persistent(struct dentry *dentry, struct inode *inode) 2746 + { 2747 + WARN_ON(!hlist_unhashed(&dentry->d_u.d_alias)); 2748 + WARN_ON(!inode); 2749 + security_d_instantiate(dentry, inode); 2750 + spin_lock(&inode->i_lock); 2751 + spin_lock(&dentry->d_lock); 2752 + __d_instantiate(dentry, inode); 2753 + dentry->d_flags |= DCACHE_PERSISTENT; 2754 + dget_dlock(dentry); 2755 + if (d_unhashed(dentry)) 2756 + __d_rehash(dentry); 2757 + spin_unlock(&dentry->d_lock); 2758 + spin_unlock(&inode->i_lock); 2759 + return dentry; 2760 + } 2761 + EXPORT_SYMBOL(d_make_persistent); 2762 + 2780 2763 static void swap_names(struct dentry *dentry, struct dentry *target) 2781 2764 { 2782 2765 if (unlikely(dname_external(target))) { ··· 3163 3110 return subdir; 3164 3111 } 3165 3112 EXPORT_SYMBOL(is_subdir); 3166 - 3167 - static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry) 3168 - { 3169 - struct dentry *root = data; 3170 - if (dentry != root) { 3171 - if (d_unhashed(dentry) || !dentry->d_inode) 3172 - return D_WALK_SKIP; 3173 - 3174 - if (!(dentry->d_flags & DCACHE_GENOCIDE)) { 3175 - dentry->d_flags |= DCACHE_GENOCIDE; 3176 - dentry->d_lockref.count--; 3177 - } 3178 - } 3179 - return D_WALK_CONTINUE; 3180 - } 3181 - 3182 - void d_genocide(struct dentry *parent) 3183 - { 3184 - d_walk(parent, parent, d_genocide_kill); 3185 - } 3186 3113 3187 3114 void d_mark_tmpfile(struct file *file, struct inode *inode) 3188 3115 {
+8 -24
fs/debugfs/inode.c
··· 329 329 .name = "debugfs", 330 330 .init_fs_context = debugfs_init_fs_context, 331 331 .parameters = debugfs_param_specs, 332 - .kill_sb = kill_litter_super, 332 + .kill_sb = kill_anon_super, 333 333 }; 334 334 MODULE_ALIAS_FS("debugfs"); 335 335 ··· 405 405 406 406 static struct dentry *debugfs_failed_creating(struct dentry *dentry) 407 407 { 408 - inode_unlock(d_inode(dentry->d_parent)); 409 - dput(dentry); 408 + simple_done_creating(dentry); 410 409 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 411 410 return ERR_PTR(-ENOMEM); 412 411 } 413 412 414 413 static struct dentry *debugfs_end_creating(struct dentry *dentry) 415 414 { 416 - inode_unlock(d_inode(dentry->d_parent)); 417 - return dentry; 415 + simple_done_creating(dentry); 416 + return dentry; // borrowed 418 417 } 419 418 420 419 static struct dentry *__debugfs_create_file(const char *name, umode_t mode, ··· 433 434 if (IS_ERR(dentry)) 434 435 return dentry; 435 436 436 - if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { 437 - debugfs_failed_creating(dentry); 438 - return ERR_PTR(-EPERM); 439 - } 440 - 441 437 inode = debugfs_get_inode(dentry->d_sb); 442 438 if (unlikely(!inode)) { 443 439 pr_err("out of free dentries, can not create file '%s'\n", ··· 450 456 DEBUGFS_I(inode)->raw = real_fops; 451 457 DEBUGFS_I(inode)->aux = (void *)aux; 452 458 453 - d_instantiate(dentry, inode); 459 + d_make_persistent(dentry, inode); 454 460 fsnotify_create(d_inode(dentry->d_parent), dentry); 455 461 return debugfs_end_creating(dentry); 456 462 } ··· 578 584 if (IS_ERR(dentry)) 579 585 return dentry; 580 586 581 - if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { 582 - debugfs_failed_creating(dentry); 583 - return ERR_PTR(-EPERM); 584 - } 585 - 586 587 inode = debugfs_get_inode(dentry->d_sb); 587 588 if (unlikely(!inode)) { 588 589 pr_err("out of free dentries, can not create directory '%s'\n", ··· 591 602 592 603 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 593 604 inc_nlink(inode); 594 - d_instantiate(dentry, inode); 605 + d_make_persistent(dentry, inode); 595 606 inc_nlink(d_inode(dentry->d_parent)); 596 607 fsnotify_mkdir(d_inode(dentry->d_parent), dentry); 597 608 return debugfs_end_creating(dentry); ··· 620 631 if (IS_ERR(dentry)) 621 632 return dentry; 622 633 623 - if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { 624 - debugfs_failed_creating(dentry); 625 - return ERR_PTR(-EPERM); 626 - } 627 - 628 634 inode = debugfs_get_inode(dentry->d_sb); 629 635 if (unlikely(!inode)) { 630 636 pr_err("out of free dentries, can not create automount '%s'\n", ··· 633 649 DEBUGFS_I(inode)->automount = f; 634 650 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 635 651 inc_nlink(inode); 636 - d_instantiate(dentry, inode); 652 + d_make_persistent(dentry, inode); 637 653 inc_nlink(d_inode(dentry->d_parent)); 638 654 fsnotify_mkdir(d_inode(dentry->d_parent), dentry); 639 655 return debugfs_end_creating(dentry); ··· 688 704 inode->i_mode = S_IFLNK | S_IRWXUGO; 689 705 inode->i_op = &debugfs_symlink_inode_operations; 690 706 inode->i_link = link; 691 - d_instantiate(dentry, inode); 707 + d_make_persistent(dentry, inode); 692 708 return debugfs_end_creating(dentry); 693 709 } 694 710 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
+21 -36
fs/devpts/inode.c
··· 102 102 struct ida allocated_ptys; 103 103 struct pts_mount_opts mount_opts; 104 104 struct super_block *sb; 105 - struct dentry *ptmx_dentry; 105 + struct inode *ptmx_inode; // borrowed 106 106 }; 107 107 108 108 static inline struct pts_fs_info *DEVPTS_SB(struct super_block *sb) ··· 259 259 static int mknod_ptmx(struct super_block *sb, struct fs_context *fc) 260 260 { 261 261 int mode; 262 - int rc = -ENOMEM; 263 262 struct dentry *dentry; 264 263 struct inode *inode; 265 264 struct dentry *root = sb->s_root; ··· 267 268 kuid_t ptmx_uid = current_fsuid(); 268 269 kgid_t ptmx_gid = current_fsgid(); 269 270 270 - inode_lock(d_inode(root)); 271 - 272 - /* If we have already created ptmx node, return */ 273 - if (fsi->ptmx_dentry) { 274 - rc = 0; 275 - goto out; 276 - } 277 - 278 - dentry = d_alloc_name(root, "ptmx"); 279 - if (!dentry) { 271 + dentry = simple_start_creating(root, "ptmx"); 272 + if (IS_ERR(dentry)) { 280 273 pr_err("Unable to alloc dentry for ptmx node\n"); 281 - goto out; 274 + return PTR_ERR(dentry); 282 275 } 283 276 284 277 /* ··· 278 287 */ 279 288 inode = new_inode(sb); 280 289 if (!inode) { 290 + simple_done_creating(dentry); 281 291 pr_err("Unable to alloc inode for ptmx node\n"); 282 - dput(dentry); 283 - goto out; 292 + return -ENOMEM; 284 293 } 285 294 286 295 inode->i_ino = 2; ··· 290 299 init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); 291 300 inode->i_uid = ptmx_uid; 292 301 inode->i_gid = ptmx_gid; 302 + fsi->ptmx_inode = inode; 293 303 294 - d_add(dentry, inode); 304 + d_make_persistent(dentry, inode); 295 305 296 - fsi->ptmx_dentry = dentry; 297 - rc = 0; 298 - out: 299 - inode_unlock(d_inode(root)); 300 - return rc; 306 + simple_done_creating(dentry); 307 + 308 + return 0; 301 309 } 302 310 303 311 static void update_ptmx_mode(struct pts_fs_info *fsi) 304 312 { 305 - struct inode *inode; 306 - if (fsi->ptmx_dentry) { 307 - inode = d_inode(fsi->ptmx_dentry); 308 - inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode; 309 - } 313 + fsi->ptmx_inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode; 310 314 } 311 315 312 316 static int devpts_reconfigure(struct fs_context *fc) ··· 447 461 if (fsi) 448 462 ida_destroy(&fsi->allocated_ptys); 449 463 kfree(fsi); 450 - kill_litter_super(sb); 464 + kill_anon_super(sb); 451 465 } 452 466 453 467 static struct file_system_type devpts_fs_type = { ··· 520 534 sprintf(s, "%d", index); 521 535 522 536 dentry = d_alloc_name(root, s); 523 - if (dentry) { 524 - dentry->d_fsdata = priv; 525 - d_add(dentry, inode); 526 - fsnotify_create(d_inode(root), dentry); 527 - } else { 537 + if (!dentry) { 528 538 iput(inode); 529 - dentry = ERR_PTR(-ENOMEM); 539 + return ERR_PTR(-ENOMEM); 530 540 } 531 - 532 - return dentry; 541 + dentry->d_fsdata = priv; 542 + d_make_persistent(dentry, inode); 543 + fsnotify_create(d_inode(root), dentry); 544 + dput(dentry); 545 + return dentry; // borrowed 533 546 } 534 547 535 548 /** ··· 558 573 drop_nlink(dentry->d_inode); 559 574 d_drop(dentry); 560 575 fsnotify_unlink(d_inode(dentry->d_parent), dentry); 561 - dput(dentry); /* d_alloc_name() in devpts_pty_new() */ 576 + d_make_discardable(dentry); 562 577 } 563 578 564 579 static int __init init_devpts_fs(void)
+2 -5
fs/efivarfs/inode.c
··· 113 113 114 114 inode->i_private = var; 115 115 116 - d_instantiate(dentry, inode); 117 - dget(dentry); 116 + d_make_persistent(dentry, inode); 118 117 119 118 return 0; 120 119 } ··· 125 126 if (efivar_entry_delete(var)) 126 127 return -EINVAL; 127 128 128 - drop_nlink(d_inode(dentry)); 129 - dput(dentry); 130 - return 0; 129 + return simple_unlink(dir, dentry); 131 130 }; 132 131 133 132 const struct inode_operations efivarfs_dir_inode_operations = {
+3 -2
fs/efivarfs/super.c
··· 278 278 inode->i_private = entry; 279 279 i_size_write(inode, size + sizeof(__u32)); /* attributes + data */ 280 280 inode_unlock(inode); 281 - d_add(dentry, inode); 281 + d_make_persistent(dentry, inode); 282 + dput(dentry); 282 283 283 284 return 0; 284 285 ··· 523 522 struct efivarfs_fs_info *sfi = sb->s_fs_info; 524 523 525 524 blocking_notifier_chain_unregister(&efivar_ops_nh, &sfi->nb); 526 - kill_litter_super(sb); 525 + kill_anon_super(sb); 527 526 528 527 kfree(sfi); 529 528 }
+19 -17
fs/fuse/control.c
··· 205 205 206 206 static struct dentry *fuse_ctl_add_dentry(struct dentry *parent, 207 207 struct fuse_conn *fc, 208 - const char *name, 209 - int mode, int nlink, 208 + const char *name, int mode, 210 209 const struct inode_operations *iop, 211 210 const struct file_operations *fop) 212 211 { ··· 231 232 if (iop) 232 233 inode->i_op = iop; 233 234 inode->i_fop = fop; 234 - set_nlink(inode, nlink); 235 + if (S_ISDIR(mode)) { 236 + inc_nlink(d_inode(parent)); 237 + inc_nlink(inode); 238 + } 235 239 inode->i_private = fc; 236 - d_add(dentry, inode); 240 + d_make_persistent(dentry, inode); 241 + dput(dentry); 237 242 243 + /* 244 + * We are returning a borrowed reference here - it's only good while 245 + * fuse_mutex is held. Actually it's d_make_persistent() return 246 + * value... 247 + */ 238 248 return dentry; 239 249 } 240 250 ··· 260 252 return 0; 261 253 262 254 parent = fuse_control_sb->s_root; 263 - inc_nlink(d_inode(parent)); 264 255 sprintf(name, "%u", fc->dev); 265 - parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2, 256 + parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 266 257 &simple_dir_inode_operations, 267 258 &simple_dir_operations); 268 259 if (!parent) 269 260 goto err; 270 261 271 - if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 1, 262 + if (!fuse_ctl_add_dentry(parent, fc, "waiting", S_IFREG | 0400, 272 263 NULL, &fuse_ctl_waiting_ops) || 273 - !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 1, 264 + !fuse_ctl_add_dentry(parent, fc, "abort", S_IFREG | 0200, 274 265 NULL, &fuse_ctl_abort_ops) || 275 266 !fuse_ctl_add_dentry(parent, fc, "max_background", S_IFREG | 0600, 276 - 1, NULL, &fuse_conn_max_background_ops) || 267 + NULL, &fuse_conn_max_background_ops) || 277 268 !fuse_ctl_add_dentry(parent, fc, "congestion_threshold", 278 - S_IFREG | 0600, 1, NULL, 269 + S_IFREG | 0600, NULL, 279 270 &fuse_conn_congestion_threshold_ops)) 280 271 goto err; 281 272 ··· 296 289 */ 297 290 void fuse_ctl_remove_conn(struct fuse_conn *fc) 298 291 { 299 - struct dentry *dentry; 300 292 char name[32]; 301 293 302 294 if (!fuse_control_sb || fc->no_control) 303 295 return; 304 296 305 297 sprintf(name, "%u", fc->dev); 306 - dentry = lookup_noperm_positive_unlocked(&QSTR(name), fuse_control_sb->s_root); 307 - if (!IS_ERR(dentry)) { 308 - simple_recursive_removal(dentry, remove_one); 309 - dput(dentry); // paired with lookup_noperm_positive_unlocked() 310 - } 298 + simple_remove_by_name(fuse_control_sb->s_root, name, remove_one); 311 299 } 312 300 313 301 static int fuse_ctl_fill_super(struct super_block *sb, struct fs_context *fsc) ··· 352 350 fuse_control_sb = NULL; 353 351 mutex_unlock(&fuse_mutex); 354 352 355 - kill_litter_super(sb); 353 + kill_anon_super(sb); 356 354 } 357 355 358 356 static struct file_system_type fuse_ctl_fs_type = {
+5 -7
fs/hugetlbfs/inode.c
··· 994 994 if (!inode) 995 995 return -ENOSPC; 996 996 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 997 - d_instantiate(dentry, inode); 998 - dget(dentry);/* Extra count - pin the dentry in core */ 997 + d_make_persistent(dentry, inode); 999 998 return 0; 1000 999 } 1001 1000 ··· 1041 1042 if (inode) { 1042 1043 int l = strlen(symname)+1; 1043 1044 error = page_symlink(inode, symname, l); 1044 - if (!error) { 1045 - d_instantiate(dentry, inode); 1046 - dget(dentry); 1047 - } else 1045 + if (!error) 1046 + d_make_persistent(dentry, inode); 1047 + else 1048 1048 iput(inode); 1049 1049 } 1050 1050 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); ··· 1500 1502 .name = "hugetlbfs", 1501 1503 .init_fs_context = hugetlbfs_init_fs_context, 1502 1504 .parameters = hugetlb_fs_parameters, 1503 - .kill_sb = kill_litter_super, 1505 + .kill_sb = kill_anon_super, 1504 1506 .fs_flags = FS_ALLOW_IDMAP, 1505 1507 }; 1506 1508
-1
fs/internal.h
··· 230 230 extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *); 231 231 extern struct dentry *__d_lookup_rcu(const struct dentry *parent, 232 232 const struct qstr *name, unsigned *seq); 233 - extern void d_genocide(struct dentry *); 234 233 235 234 /* 236 235 * pipe.c
+43 -9
fs/libfs.c
··· 630 630 if (callback) 631 631 callback(victim); 632 632 fsnotify_delete(inode, d_inode(victim), victim); 633 - dput(victim); // unpin it 633 + d_make_discardable(victim); 634 634 } 635 635 if (victim == dentry) { 636 636 inode_set_mtime_to_ts(inode, ··· 654 654 return __simple_recursive_removal(dentry, callback, false); 655 655 } 656 656 EXPORT_SYMBOL(simple_recursive_removal); 657 + 658 + void simple_remove_by_name(struct dentry *parent, const char *name, 659 + void (*callback)(struct dentry *)) 660 + { 661 + struct dentry *dentry; 662 + 663 + dentry = lookup_noperm_positive_unlocked(&QSTR(name), parent); 664 + if (!IS_ERR(dentry)) { 665 + simple_recursive_removal(dentry, callback); 666 + dput(dentry); // paired with lookup_noperm_positive_unlocked() 667 + } 668 + } 669 + EXPORT_SYMBOL(simple_remove_by_name); 657 670 658 671 /* caller holds parent directory with I_MUTEX_PARENT */ 659 672 void locked_recursive_removal(struct dentry *dentry, ··· 765 752 inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); 766 753 inc_nlink(inode); 767 754 ihold(inode); 768 - dget(dentry); 769 - d_instantiate(dentry, inode); 755 + d_make_persistent(dentry, inode); 770 756 return 0; 771 757 } 772 758 EXPORT_SYMBOL(simple_link); ··· 791 779 } 792 780 EXPORT_SYMBOL(simple_empty); 793 781 794 - int simple_unlink(struct inode *dir, struct dentry *dentry) 782 + void __simple_unlink(struct inode *dir, struct dentry *dentry) 795 783 { 796 784 struct inode *inode = d_inode(dentry); 797 785 798 786 inode_set_mtime_to_ts(dir, 799 787 inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); 800 788 drop_nlink(inode); 801 - dput(dentry); 789 + } 790 + EXPORT_SYMBOL(__simple_unlink); 791 + 792 + void __simple_rmdir(struct inode *dir, struct dentry *dentry) 793 + { 794 + drop_nlink(d_inode(dentry)); 795 + __simple_unlink(dir, dentry); 796 + drop_nlink(dir); 797 + } 798 + EXPORT_SYMBOL(__simple_rmdir); 799 + 800 + int simple_unlink(struct inode *dir, struct dentry *dentry) 801 + { 802 + __simple_unlink(dir, dentry); 803 + d_make_discardable(dentry); 802 804 return 0; 803 805 } 804 806 EXPORT_SYMBOL(simple_unlink); ··· 822 796 if (!simple_empty(dentry)) 823 797 return -ENOTEMPTY; 824 798 825 - drop_nlink(d_inode(dentry)); 826 - simple_unlink(dir, dentry); 827 - drop_nlink(dir); 799 + __simple_rmdir(dir, dentry); 800 + d_make_discardable(dentry); 828 801 return 0; 829 802 } 830 803 EXPORT_SYMBOL(simple_rmdir); ··· 1091 1066 simple_inode_init_ts(inode); 1092 1067 inode->i_fop = files->ops; 1093 1068 inode->i_ino = i; 1094 - d_add(dentry, inode); 1069 + d_make_persistent(dentry, inode); 1070 + dput(dentry); 1095 1071 } 1096 1072 return 0; 1097 1073 } ··· 2338 2312 return start_dirop(parent, &qname, LOOKUP_CREATE | LOOKUP_EXCL); 2339 2313 } 2340 2314 EXPORT_SYMBOL(simple_start_creating); 2315 + 2316 + /* parent must have been held exclusive since simple_start_creating() */ 2317 + void simple_done_creating(struct dentry *child) 2318 + { 2319 + inode_unlock(child->d_parent->d_inode); 2320 + dput(child); 2321 + } 2322 + EXPORT_SYMBOL(simple_done_creating);
+9 -9
fs/nfsd/nfsctl.c
··· 1137 1137 inode->i_private = ncl; 1138 1138 kref_get(&ncl->cl_ref); 1139 1139 } 1140 - d_instantiate(dentry, inode); 1140 + d_make_persistent(dentry, inode); 1141 1141 inc_nlink(dir); 1142 1142 fsnotify_mkdir(dir, dentry); 1143 - inode_unlock(dir); 1144 - return dentry; 1143 + simple_done_creating(dentry); 1144 + return dentry; // borrowed 1145 1145 } 1146 1146 1147 1147 #if IS_ENABLED(CONFIG_SUNRPC_GSS) ··· 1170 1170 inode->i_link = (char *)content; 1171 1171 inode->i_size = strlen(content); 1172 1172 1173 - d_instantiate(dentry, inode); 1173 + d_make_persistent(dentry, inode); 1174 1174 fsnotify_create(dir, dentry); 1175 - inode_unlock(dir); 1175 + simple_done_creating(dentry); 1176 1176 } 1177 1177 #else 1178 1178 static inline void _nfsd_symlink(struct dentry *parent, const char *name, ··· 1228 1228 kref_get(&ncl->cl_ref); 1229 1229 inode->i_fop = files->ops; 1230 1230 inode->i_private = ncl; 1231 - d_instantiate(dentry, inode); 1231 + d_make_persistent(dentry, inode); 1232 1232 fsnotify_create(dir, dentry); 1233 1233 if (fdentries) 1234 - fdentries[i] = dentry; 1235 - inode_unlock(dir); 1234 + fdentries[i] = dentry; // borrowed 1235 + simple_done_creating(dentry); 1236 1236 } 1237 1237 return 0; 1238 1238 } ··· 1346 1346 1347 1347 nfsd_shutdown_threads(net); 1348 1348 1349 - kill_litter_super(sb); 1349 + kill_anon_super(sb); 1350 1350 put_net(net); 1351 1351 } 1352 1352
+3 -5
fs/ocfs2/dlmfs/dlmfs.c
··· 441 441 ip->ip_conn = conn; 442 442 443 443 inc_nlink(dir); 444 - d_instantiate(dentry, inode); 445 - dget(dentry); /* Extra count - pin the dentry in core */ 444 + d_make_persistent(dentry, inode); 446 445 447 446 status = 0; 448 447 bail: ··· 479 480 goto bail; 480 481 } 481 482 482 - d_instantiate(dentry, inode); 483 - dget(dentry); /* Extra count - pin the dentry in core */ 483 + d_make_persistent(dentry, inode); 484 484 bail: 485 485 return status; 486 486 } ··· 572 574 static struct file_system_type dlmfs_fs_type = { 573 575 .owner = THIS_MODULE, 574 576 .name = "ocfs2_dlmfs", 575 - .kill_sb = kill_litter_super, 577 + .kill_sb = kill_anon_super, 576 578 .init_fs_context = dlmfs_init_fs_context, 577 579 }; 578 580 MODULE_ALIAS_FS("ocfs2_dlmfs");
+2 -4
fs/proc/base.c
··· 3578 3578 return 0; 3579 3579 3580 3580 if (pos == TGID_OFFSET - 2) { 3581 - struct inode *inode = d_inode(fs_info->proc_self); 3582 - if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK)) 3581 + if (!dir_emit(ctx, "self", 4, self_inum, DT_LNK)) 3583 3582 return 0; 3584 3583 ctx->pos = pos = pos + 1; 3585 3584 } 3586 3585 if (pos == TGID_OFFSET - 1) { 3587 - struct inode *inode = d_inode(fs_info->proc_thread_self); 3588 - if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK)) 3586 + if (!dir_emit(ctx, "thread-self", 11, thread_self_inum, DT_LNK)) 3589 3587 return 0; 3590 3588 ctx->pos = pos = pos + 1; 3591 3589 }
+1
fs/proc/internal.h
··· 373 373 extern struct proc_dir_entry proc_root; 374 374 375 375 extern void proc_self_init(void); 376 + extern unsigned self_inum, thread_self_inum; 376 377 377 378 /* 378 379 * task_[no]mmu.c
+4 -10
fs/proc/root.c
··· 347 347 { 348 348 struct proc_fs_info *fs_info = proc_sb_info(sb); 349 349 350 - if (!fs_info) { 351 - kill_anon_super(sb); 352 - return; 353 - } 354 - 355 - dput(fs_info->proc_self); 356 - dput(fs_info->proc_thread_self); 357 - 358 350 kill_anon_super(sb); 359 - put_pid_ns(fs_info->pid_ns); 360 - kfree_rcu(fs_info, rcu); 351 + if (fs_info) { 352 + put_pid_ns(fs_info->pid_ns); 353 + kfree_rcu(fs_info, rcu); 354 + } 361 355 } 362 356 363 357 static struct file_system_type proc_fs_type = {
+3 -7
fs/proc/self.c
··· 31 31 .get_link = proc_self_get_link, 32 32 }; 33 33 34 - static unsigned self_inum __ro_after_init; 34 + unsigned self_inum __ro_after_init; 35 35 36 36 int proc_setup_self(struct super_block *s) 37 37 { 38 38 struct inode *root_inode = d_inode(s->s_root); 39 - struct proc_fs_info *fs_info = proc_sb_info(s); 40 39 struct dentry *self; 41 40 int ret = -ENOMEM; 42 41 ··· 50 51 inode->i_uid = GLOBAL_ROOT_UID; 51 52 inode->i_gid = GLOBAL_ROOT_GID; 52 53 inode->i_op = &proc_self_inode_operations; 53 - d_add(self, inode); 54 + d_make_persistent(self, inode); 54 55 ret = 0; 55 - } else { 56 - dput(self); 57 56 } 57 + dput(self); 58 58 } 59 59 inode_unlock(root_inode); 60 60 61 61 if (ret) 62 62 pr_err("proc_fill_super: can't allocate /proc/self\n"); 63 - else 64 - fs_info->proc_self = self; 65 63 66 64 return ret; 67 65 }
+3 -8
fs/proc/thread_self.c
··· 31 31 .get_link = proc_thread_self_get_link, 32 32 }; 33 33 34 - static unsigned thread_self_inum __ro_after_init; 34 + unsigned thread_self_inum __ro_after_init; 35 35 36 36 int proc_setup_thread_self(struct super_block *s) 37 37 { 38 38 struct inode *root_inode = d_inode(s->s_root); 39 - struct proc_fs_info *fs_info = proc_sb_info(s); 40 39 struct dentry *thread_self; 41 40 int ret = -ENOMEM; 42 41 ··· 50 51 inode->i_uid = GLOBAL_ROOT_UID; 51 52 inode->i_gid = GLOBAL_ROOT_GID; 52 53 inode->i_op = &proc_thread_self_inode_operations; 53 - d_add(thread_self, inode); 54 + d_make_persistent(thread_self, inode); 54 55 ret = 0; 55 - } else { 56 - dput(thread_self); 57 56 } 57 + dput(thread_self); 58 58 } 59 59 inode_unlock(root_inode); 60 60 61 61 if (ret) 62 62 pr_err("proc_fill_super: can't allocate /proc/thread-self\n"); 63 - else 64 - fs_info->proc_thread_self = thread_self; 65 - 66 63 return ret; 67 64 } 68 65
+4 -3
fs/pstore/inode.c
··· 373 373 if (!dentry) 374 374 return -ENOMEM; 375 375 376 - private->dentry = dentry; 376 + private->dentry = dentry; // borrowed 377 377 private->record = record; 378 378 inode->i_size = private->total_size = size; 379 379 inode->i_private = private; ··· 382 382 inode_set_mtime_to_ts(inode, 383 383 inode_set_ctime_to_ts(inode, record->time)); 384 384 385 - d_add(dentry, no_free_ptr(inode)); 385 + d_make_persistent(dentry, no_free_ptr(inode)); 386 + dput(dentry); 386 387 387 388 list_add(&(no_free_ptr(private))->list, &records_list); 388 389 ··· 466 465 guard(mutex)(&pstore_sb_lock); 467 466 WARN_ON(pstore_sb && pstore_sb != sb); 468 467 469 - kill_litter_super(sb); 468 + kill_anon_super(sb); 470 469 pstore_sb = NULL; 471 470 472 471 guard(mutex)(&records_list_lock);
+3 -5
fs/ramfs/inode.c
··· 110 110 goto out; 111 111 } 112 112 113 - d_instantiate(dentry, inode); 114 - dget(dentry); /* Extra count - pin the dentry in core */ 113 + d_make_persistent(dentry, inode); 115 114 error = 0; 116 115 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 117 116 } ··· 153 154 154 155 error = page_symlink(inode, symname, l); 155 156 if (!error) { 156 - d_instantiate(dentry, inode); 157 - dget(dentry); 157 + d_make_persistent(dentry, inode); 158 158 inode_set_mtime_to_ts(dir, 159 159 inode_set_ctime_current(dir)); 160 160 } else ··· 311 313 void ramfs_kill_sb(struct super_block *sb) 312 314 { 313 315 kfree(sb->s_fs_info); 314 - kill_litter_super(sb); 316 + kill_anon_super(sb); 315 317 } 316 318 317 319 static struct file_system_type ramfs_fs_type = {
-8
fs/super.c
··· 1292 1292 } 1293 1293 EXPORT_SYMBOL(kill_anon_super); 1294 1294 1295 - void kill_litter_super(struct super_block *sb) 1296 - { 1297 - if (sb->s_root) 1298 - d_genocide(sb->s_root); 1299 - kill_anon_super(sb); 1300 - } 1301 - EXPORT_SYMBOL(kill_litter_super); 1302 - 1303 1295 int set_anon_super_fc(struct super_block *sb, struct fs_context *fc) 1304 1296 { 1305 1297 return set_anon_super(sb, NULL);
+4 -3
fs/tracefs/event_inode.c
··· 757 757 const struct eventfs_entry *entries, 758 758 int size, void *data) 759 759 { 760 - struct dentry *dentry = tracefs_start_creating(name, parent); 760 + struct dentry *dentry; 761 761 struct eventfs_root_inode *rei; 762 762 struct eventfs_inode *ei; 763 763 struct tracefs_inode *ti; ··· 768 768 if (security_locked_down(LOCKDOWN_TRACEFS)) 769 769 return NULL; 770 770 771 + dentry = tracefs_start_creating(name, parent); 771 772 if (IS_ERR(dentry)) 772 773 return ERR_CAST(dentry); 773 774 ··· 823 822 * something not worth much. Keeping directory links at 1 824 823 * tells userspace not to trust the link number. 825 824 */ 826 - d_instantiate(dentry, inode); 825 + d_make_persistent(dentry, inode); 827 826 /* The dentry of the "events" parent does keep track though */ 828 827 inc_nlink(dentry->d_parent->d_inode); 829 828 fsnotify_mkdir(dentry->d_parent->d_inode, dentry); ··· 910 909 * and destroyed dynamically. 911 910 */ 912 911 d_invalidate(dentry); 913 - dput(dentry); 912 + d_make_discardable(dentry); 914 913 }
+6 -7
fs/tracefs/inode.c
··· 538 538 .name = "tracefs", 539 539 .init_fs_context = tracefs_init_fs_context, 540 540 .parameters = tracefs_param_specs, 541 - .kill_sb = kill_litter_super, 541 + .kill_sb = kill_anon_super, 542 542 }; 543 543 MODULE_ALIAS_FS("tracefs"); 544 544 ··· 571 571 572 572 struct dentry *tracefs_failed_creating(struct dentry *dentry) 573 573 { 574 - inode_unlock(d_inode(dentry->d_parent)); 575 - dput(dentry); 574 + simple_done_creating(dentry); 576 575 simple_release_fs(&tracefs_mount, &tracefs_mount_count); 577 576 return NULL; 578 577 } 579 578 580 579 struct dentry *tracefs_end_creating(struct dentry *dentry) 581 580 { 582 - inode_unlock(d_inode(dentry->d_parent)); 583 - return dentry; 581 + simple_done_creating(dentry); 582 + return dentry; // borrowed 584 583 } 585 584 586 585 /* Find the inode that this will use for default */ ··· 660 661 inode->i_private = data; 661 662 inode->i_uid = d_inode(dentry->d_parent)->i_uid; 662 663 inode->i_gid = d_inode(dentry->d_parent)->i_gid; 663 - d_instantiate(dentry, inode); 664 + d_make_persistent(dentry, inode); 664 665 fsnotify_create(d_inode(dentry->d_parent), dentry); 665 666 return tracefs_end_creating(dentry); 666 667 } ··· 691 692 692 693 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 693 694 inc_nlink(inode); 694 - d_instantiate(dentry, inode); 695 + d_make_persistent(dentry, inode); 695 696 inc_nlink(d_inode(dentry->d_parent)); 696 697 fsnotify_mkdir(d_inode(dentry->d_parent), dentry); 697 698 return tracefs_end_creating(dentry);
+3 -1
include/linux/dcache.h
··· 198 198 DCACHE_REFERENCED = BIT(6), /* Recently used, don't discard. */ 199 199 DCACHE_DONTCACHE = BIT(7), /* Purge from memory on final dput() */ 200 200 DCACHE_CANT_MOUNT = BIT(8), 201 - DCACHE_GENOCIDE = BIT(9), 202 201 DCACHE_SHRINK_LIST = BIT(10), 203 202 DCACHE_OP_WEAK_REVALIDATE = BIT(11), 204 203 /* ··· 224 225 DCACHE_PAR_LOOKUP = BIT(24), /* being looked up (with parent locked shared) */ 225 226 DCACHE_DENTRY_CURSOR = BIT(25), 226 227 DCACHE_NORCU = BIT(26), /* No RCU delay for freeing */ 228 + DCACHE_PERSISTENT = BIT(27) 227 229 }; 228 230 229 231 #define DCACHE_MANAGED_DENTRY \ ··· 610 610 } 611 611 612 612 void set_default_d_op(struct super_block *, const struct dentry_operations *); 613 + struct dentry *d_make_persistent(struct dentry *, struct inode *); 614 + void d_make_discardable(struct dentry *dentry); 613 615 614 616 #endif /* __LINUX_DCACHE_H */
+5 -1
include/linux/fs.h
··· 2310 2310 void generic_shutdown_super(struct super_block *sb); 2311 2311 void kill_block_super(struct super_block *sb); 2312 2312 void kill_anon_super(struct super_block *sb); 2313 - void kill_litter_super(struct super_block *sb); 2314 2313 void deactivate_super(struct super_block *sb); 2315 2314 void deactivate_locked_super(struct super_block *sb); 2316 2315 int set_anon_super(struct super_block *s, void *data); ··· 3190 3191 extern int simple_link(struct dentry *, struct inode *, struct dentry *); 3191 3192 extern int simple_unlink(struct inode *, struct dentry *); 3192 3193 extern int simple_rmdir(struct inode *, struct dentry *); 3194 + extern void __simple_unlink(struct inode *, struct dentry *); 3195 + extern void __simple_rmdir(struct inode *, struct dentry *); 3193 3196 void simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry, 3194 3197 struct inode *new_dir, struct dentry *new_dentry); 3195 3198 extern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, ··· 3200 3199 struct dentry *, struct inode *, struct dentry *, 3201 3200 unsigned int); 3202 3201 extern void simple_recursive_removal(struct dentry *, 3202 + void (*callback)(struct dentry *)); 3203 + extern void simple_remove_by_name(struct dentry *, const char *, 3203 3204 void (*callback)(struct dentry *)); 3204 3205 extern void locked_recursive_removal(struct dentry *, 3205 3206 void (*callback)(struct dentry *)); ··· 3232 3229 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 3233 3230 extern void simple_release_fs(struct vfsmount **mount, int *count); 3234 3231 struct dentry *simple_start_creating(struct dentry *, const char *); 3232 + void simple_done_creating(struct dentry *); 3235 3233 3236 3234 extern ssize_t simple_read_from_buffer(void __user *to, size_t count, 3237 3235 loff_t *ppos, const void *from, size_t available);
-2
include/linux/proc_fs.h
··· 66 66 67 67 struct proc_fs_info { 68 68 struct pid_namespace *pid_ns; 69 - struct dentry *proc_self; /* For /proc/self */ 70 - struct dentry *proc_thread_self; /* For /proc/thread-self */ 71 69 kgid_t pid_gid; 72 70 enum proc_hidepid hide_pid; 73 71 enum proc_pidonly pidonly;
-2
include/linux/security.h
··· 2257 2257 2258 2258 #endif 2259 2259 2260 - #define securityfs_recursive_remove securityfs_remove 2261 - 2262 2260 #ifdef CONFIG_BPF_SYSCALL 2263 2261 union bpf_attr; 2264 2262 struct bpf_map;
+1 -1
init/do_mounts.c
··· 508 508 struct file_system_type rootfs_fs_type = { 509 509 .name = "rootfs", 510 510 .init_fs_context = rootfs_init_fs_context, 511 - .kill_sb = kill_litter_super, 511 + .kill_sb = kill_anon_super, 512 512 }; 513 513 514 514 void __init init_rootfs(void)
+3 -9
ipc/mqueue.c
··· 599 599 dir->i_size += DIRENT_SIZE; 600 600 simple_inode_init_ts(dir); 601 601 602 - d_instantiate(dentry, inode); 603 - dget(dentry); 602 + d_make_persistent(dentry, inode); 604 603 return 0; 605 604 out_unlock: 606 605 spin_unlock(&mq_lock); ··· 616 617 617 618 static int mqueue_unlink(struct inode *dir, struct dentry *dentry) 618 619 { 619 - struct inode *inode = d_inode(dentry); 620 - 621 - simple_inode_init_ts(dir); 622 620 dir->i_size -= DIRENT_SIZE; 623 - drop_nlink(inode); 624 - dput(dentry); 625 - return 0; 621 + return simple_unlink(dir, dentry); 626 622 } 627 623 628 624 /* ··· 1619 1625 static struct file_system_type mqueue_fs_type = { 1620 1626 .name = "mqueue", 1621 1627 .init_fs_context = mqueue_init_fs_context, 1622 - .kill_sb = kill_litter_super, 1628 + .kill_sb = kill_anon_super, 1623 1629 .fs_flags = FS_USERNS_MOUNT, 1624 1630 }; 1625 1631
+5 -10
kernel/bpf/inode.c
··· 144 144 static void bpf_dentry_finalize(struct dentry *dentry, struct inode *inode, 145 145 struct inode *dir) 146 146 { 147 - d_instantiate(dentry, inode); 148 - dget(dentry); 147 + d_make_persistent(dentry, inode); 149 148 150 149 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 151 150 } ··· 419 420 struct dentry *dentry; 420 421 int ret; 421 422 422 - inode_lock(parent->d_inode); 423 - dentry = lookup_noperm(&QSTR(name), parent); 424 - if (IS_ERR(dentry)) { 425 - inode_unlock(parent->d_inode); 423 + dentry = simple_start_creating(parent, name); 424 + if (IS_ERR(dentry)) 426 425 return PTR_ERR(dentry); 427 - } 428 426 ret = bpf_mkobj_ops(dentry, mode, link, &bpf_link_iops, 429 427 &bpf_iter_fops); 430 - dput(dentry); 431 - inode_unlock(parent->d_inode); 428 + simple_done_creating(dentry); 432 429 return ret; 433 430 } 434 431 ··· 1075 1080 { 1076 1081 struct bpf_mount_opts *opts = sb->s_fs_info; 1077 1082 1078 - kill_litter_super(sb); 1083 + kill_anon_super(sb); 1079 1084 kfree(opts); 1080 1085 } 1081 1086
+8 -30
mm/shmem.c
··· 3878 3878 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 3879 3879 inode_inc_iversion(dir); 3880 3880 3881 - if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) 3882 - d_add(dentry, inode); 3883 - else 3884 - d_instantiate(dentry, inode); 3885 - 3886 - dget(dentry); /* Extra count - pin the dentry in core */ 3881 + d_make_persistent(dentry, inode); 3887 3882 return error; 3888 3883 3889 3884 out_iput: ··· 3939 3944 struct dentry *dentry) 3940 3945 { 3941 3946 struct inode *inode = d_inode(old_dentry); 3942 - int ret = 0; 3947 + int ret; 3943 3948 3944 3949 /* 3945 3950 * No ordinary (disk based) filesystem counts links as inodes; ··· 3951 3956 if (inode->i_nlink) { 3952 3957 ret = shmem_reserve_inode(inode->i_sb, NULL); 3953 3958 if (ret) 3954 - goto out; 3959 + return ret; 3955 3960 } 3956 3961 3957 3962 ret = simple_offset_add(shmem_get_offset_ctx(dir), dentry); 3958 3963 if (ret) { 3959 3964 if (inode->i_nlink) 3960 3965 shmem_free_inode(inode->i_sb, 0); 3961 - goto out; 3966 + return ret; 3962 3967 } 3963 3968 3964 3969 dir->i_size += BOGO_DIRENT_SIZE; 3965 - inode_set_mtime_to_ts(dir, 3966 - inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); 3967 3970 inode_inc_iversion(dir); 3968 - inc_nlink(inode); 3969 - ihold(inode); /* New dentry reference */ 3970 - dget(dentry); /* Extra pinning count for the created dentry */ 3971 - if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) 3972 - d_add(dentry, inode); 3973 - else 3974 - d_instantiate(dentry, inode); 3975 - out: 3976 - return ret; 3971 + return simple_link(old_dentry, dir, dentry); 3977 3972 } 3978 3973 3979 3974 static int shmem_unlink(struct inode *dir, struct dentry *dentry) ··· 3976 3991 simple_offset_remove(shmem_get_offset_ctx(dir), dentry); 3977 3992 3978 3993 dir->i_size -= BOGO_DIRENT_SIZE; 3979 - inode_set_mtime_to_ts(dir, 3980 - inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); 3981 3994 inode_inc_iversion(dir); 3982 - drop_nlink(inode); 3983 - dput(dentry); /* Undo the count from "create" - does all the work */ 3995 + simple_unlink(dir, dentry); 3984 3996 3985 3997 /* 3986 3998 * For now, VFS can't deal with case-insensitive negative dentries, so ··· 4132 4150 dir->i_size += BOGO_DIRENT_SIZE; 4133 4151 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 4134 4152 inode_inc_iversion(dir); 4135 - if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) 4136 - d_add(dentry, inode); 4137 - else 4138 - d_instantiate(dentry, inode); 4139 - dget(dentry); 4153 + d_make_persistent(dentry, inode); 4140 4154 return 0; 4141 4155 4142 4156 out_remove_offset: ··· 5332 5354 #ifdef CONFIG_TMPFS 5333 5355 .parameters = shmem_fs_parameters, 5334 5356 #endif 5335 - .kill_sb = kill_litter_super, 5357 + .kill_sb = kill_anon_super, 5336 5358 .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, 5337 5359 }; 5338 5360
+12 -15
net/sunrpc/rpc_pipe.c
··· 536 536 537 537 inode = rpc_get_inode(dir->i_sb, S_IFREG | mode); 538 538 if (unlikely(!inode)) { 539 - dput(dentry); 540 - inode_unlock(dir); 539 + simple_done_creating(dentry); 541 540 return -ENOMEM; 542 541 } 543 542 inode->i_ino = iunique(dir->i_sb, 100); 544 543 if (i_fop) 545 544 inode->i_fop = i_fop; 546 545 rpc_inode_setowner(inode, private); 547 - d_instantiate(dentry, inode); 546 + d_make_persistent(dentry, inode); 548 547 fsnotify_create(dir, dentry); 549 - inode_unlock(dir); 548 + simple_done_creating(dentry); 550 549 return 0; 551 550 } 552 551 ··· 562 563 563 564 inode = rpc_get_inode(dir->i_sb, S_IFDIR | mode); 564 565 if (unlikely(!inode)) { 565 - dput(dentry); 566 - inode_unlock(dir); 566 + simple_done_creating(dentry); 567 567 return ERR_PTR(-ENOMEM); 568 568 } 569 569 570 570 inode->i_ino = iunique(dir->i_sb, 100); 571 571 inc_nlink(dir); 572 - d_instantiate(dentry, inode); 572 + d_make_persistent(dentry, inode); 573 573 fsnotify_mkdir(dir, dentry); 574 - inode_unlock(dir); 574 + simple_done_creating(dentry); 575 575 576 - return dentry; 576 + return dentry; // borrowed 577 577 } 578 578 579 579 static int rpc_populate(struct dentry *parent, ··· 655 657 656 658 inode = rpc_get_inode(dir->i_sb, umode); 657 659 if (unlikely(!inode)) { 658 - dput(dentry); 659 - inode_unlock(dir); 660 + simple_done_creating(dentry); 660 661 err = -ENOMEM; 661 662 goto failed; 662 663 } ··· 665 668 rpci->private = private; 666 669 rpci->pipe = pipe; 667 670 rpc_inode_setowner(inode, private); 668 - d_instantiate(dentry, inode); 669 - pipe->dentry = dentry; 671 + pipe->dentry = dentry; // borrowed 672 + d_make_persistent(dentry, inode); 670 673 fsnotify_create(dir, dentry); 671 - inode_unlock(dir); 674 + simple_done_creating(dentry); 672 675 return 0; 673 676 674 677 failed: ··· 1203 1206 sb); 1204 1207 mutex_unlock(&sn->pipefs_sb_lock); 1205 1208 out: 1206 - kill_litter_super(sb); 1209 + kill_anon_super(sb); 1207 1210 put_net(net); 1208 1211 } 1209 1212
+9 -4
security/apparmor/apparmorfs.c
··· 359 359 dir = d_inode(dentry->d_parent); 360 360 dentry = start_removing_dentry(dentry->d_parent, dentry); 361 361 if (!IS_ERR(dentry) && simple_positive(dentry)) { 362 - if (d_is_dir(dentry)) 363 - simple_rmdir(dir, dentry); 364 - else 365 - simple_unlink(dir, dentry); 362 + if (d_is_dir(dentry)) { 363 + if (!WARN_ON(!simple_empty(dentry))) { 364 + __simple_rmdir(dir, dentry); 365 + dput(dentry); 366 + } 367 + } else { 368 + __simple_unlink(dir, dentry); 369 + dput(dentry); 370 + } 366 371 d_delete(dentry); 367 372 } 368 373 end_removing(dentry);
+13 -22
security/inode.c
··· 72 72 .owner = THIS_MODULE, 73 73 .name = "securityfs", 74 74 .init_fs_context = securityfs_init_fs_context, 75 - .kill_sb = kill_litter_super, 75 + .kill_sb = kill_anon_super, 76 76 }; 77 77 78 78 /** ··· 129 129 parent = mount->mnt_root; 130 130 } 131 131 132 + inode = new_inode(parent->d_sb); 133 + if (unlikely(!inode)) { 134 + dentry = ERR_PTR(-ENOMEM); 135 + goto out; 136 + } 137 + 132 138 dir = d_inode(parent); 133 139 134 - inode_lock(dir); 135 - dentry = lookup_noperm(&QSTR(name), parent); 136 - if (IS_ERR(dentry)) 140 + dentry = simple_start_creating(parent, name); 141 + if (IS_ERR(dentry)) { 142 + iput(inode); 137 143 goto out; 138 - 139 - if (d_really_is_positive(dentry)) { 140 - error = -EEXIST; 141 - goto out1; 142 144 } 143 - 144 - inode = new_inode(dir->i_sb); 145 - if (!inode) { 146 - error = -ENOMEM; 147 - goto out1; 148 - } 149 - 150 145 inode->i_ino = get_next_ino(); 151 146 inode->i_mode = mode; 152 147 simple_inode_init_ts(inode); ··· 157 162 } else { 158 163 inode->i_fop = fops; 159 164 } 160 - d_instantiate(dentry, inode); 161 - inode_unlock(dir); 162 - return dentry; 165 + d_make_persistent(dentry, inode); 166 + simple_done_creating(dentry); 167 + return dentry; // borrowed 163 168 164 - out1: 165 - dput(dentry); 166 - dentry = ERR_PTR(error); 167 169 out: 168 - inode_unlock(dir); 169 170 if (pinned) 170 171 simple_release_fs(&mount, &mount_count); 171 172 return dentry;
+78 -107
security/selinux/selinuxfs.c
··· 76 76 struct dentry *class_dir; 77 77 unsigned long last_class_ino; 78 78 bool policy_opened; 79 - struct dentry *policycap_dir; 80 79 unsigned long last_ino; 81 80 struct super_block *sb; 82 81 }; ··· 117 118 118 119 #define BOOL_DIR_NAME "booleans" 119 120 #define CLASS_DIR_NAME "class" 120 - #define POLICYCAP_DIR_NAME "policy_capabilities" 121 121 122 122 #define TMPBUFLEN 12 123 123 static ssize_t sel_read_enforce(struct file *filp, char __user *buf, ··· 1209 1211 return ret; 1210 1212 } 1211 1213 1214 + static struct dentry *sel_attach(struct dentry *parent, const char *name, 1215 + struct inode *inode) 1216 + { 1217 + struct dentry *dentry = d_alloc_name(parent, name); 1218 + if (unlikely(!dentry)) { 1219 + iput(inode); 1220 + return ERR_PTR(-ENOMEM); 1221 + } 1222 + d_make_persistent(dentry, inode); 1223 + dput(dentry); 1224 + return dentry; 1225 + } 1226 + 1227 + static int sel_attach_file(struct dentry *parent, const char *name, 1228 + struct inode *inode) 1229 + { 1230 + struct dentry *dentry = sel_attach(parent, name, inode); 1231 + return PTR_ERR_OR_ZERO(dentry); 1232 + } 1233 + 1212 1234 static ssize_t sel_read_bool(struct file *filep, char __user *buf, 1213 1235 size_t count, loff_t *ppos) 1214 1236 { ··· 1388 1370 *bool_num = num; 1389 1371 *bool_pending_names = names; 1390 1372 1391 - for (i = 0; i < num; i++) { 1392 - struct dentry *dentry; 1373 + for (i = 0; !ret && i < num; i++) { 1393 1374 struct inode *inode; 1394 1375 struct inode_security_struct *isec; 1395 1376 ssize_t len; ··· 1399 1382 ret = -ENAMETOOLONG; 1400 1383 break; 1401 1384 } 1402 - dentry = d_alloc_name(bool_dir, names[i]); 1403 - if (!dentry) { 1404 - ret = -ENOMEM; 1405 - break; 1406 - } 1407 1385 1408 1386 inode = sel_make_inode(bool_dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR); 1409 1387 if (!inode) { 1410 - dput(dentry); 1411 1388 ret = -ENOMEM; 1412 1389 break; 1413 1390 } ··· 1419 1408 isec->initialized = LABEL_INITIALIZED; 1420 1409 inode->i_fop = &sel_bool_ops; 1421 1410 inode->i_ino = i|SEL_BOOL_INO_OFFSET; 1422 - d_add(dentry, inode); 1411 + 1412 + ret = sel_attach_file(bool_dir, names[i], inode); 1423 1413 } 1424 1414 out: 1425 1415 free_page((unsigned long)page); ··· 1605 1593 struct super_block *sb = dir->d_sb; 1606 1594 struct selinux_fs_info *fsi = sb->s_fs_info; 1607 1595 unsigned int i; 1596 + int err = 0; 1608 1597 static const struct tree_descr files[] = { 1609 1598 { "cache_threshold", 1610 1599 &sel_avc_cache_threshold_ops, S_IRUGO|S_IWUSR }, ··· 1615 1602 #endif 1616 1603 }; 1617 1604 1618 - for (i = 0; i < ARRAY_SIZE(files); i++) { 1605 + for (i = 0; !err && i < ARRAY_SIZE(files); i++) { 1619 1606 struct inode *inode; 1620 - struct dentry *dentry; 1621 - 1622 - dentry = d_alloc_name(dir, files[i].name); 1623 - if (!dentry) 1624 - return -ENOMEM; 1625 1607 1626 1608 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode); 1627 - if (!inode) { 1628 - dput(dentry); 1609 + if (!inode) 1629 1610 return -ENOMEM; 1630 - } 1631 1611 1632 1612 inode->i_fop = files[i].ops; 1633 1613 inode->i_ino = ++fsi->last_ino; 1634 - d_add(dentry, inode); 1614 + 1615 + err = sel_attach_file(dir, files[i].name, inode); 1635 1616 } 1636 1617 1637 - return 0; 1618 + return err; 1638 1619 } 1639 1620 1640 1621 static int sel_make_ss_files(struct dentry *dir) ··· 1636 1629 struct super_block *sb = dir->d_sb; 1637 1630 struct selinux_fs_info *fsi = sb->s_fs_info; 1638 1631 unsigned int i; 1632 + int err = 0; 1639 1633 static const struct tree_descr files[] = { 1640 1634 { "sidtab_hash_stats", &sel_sidtab_hash_stats_ops, S_IRUGO }, 1641 1635 }; 1642 1636 1643 - for (i = 0; i < ARRAY_SIZE(files); i++) { 1637 + for (i = 0; !err && i < ARRAY_SIZE(files); i++) { 1644 1638 struct inode *inode; 1645 - struct dentry *dentry; 1646 - 1647 - dentry = d_alloc_name(dir, files[i].name); 1648 - if (!dentry) 1649 - return -ENOMEM; 1650 1639 1651 1640 inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode); 1652 - if (!inode) { 1653 - dput(dentry); 1641 + if (!inode) 1654 1642 return -ENOMEM; 1655 - } 1656 1643 1657 1644 inode->i_fop = files[i].ops; 1658 1645 inode->i_ino = ++fsi->last_ino; 1659 - d_add(dentry, inode); 1646 + 1647 + err = sel_attach_file(dir, files[i].name, inode); 1660 1648 } 1661 1649 1662 - return 0; 1650 + return err; 1663 1651 } 1664 1652 1665 1653 static ssize_t sel_read_initcon(struct file *file, char __user *buf, ··· 1682 1680 static int sel_make_initcon_files(struct dentry *dir) 1683 1681 { 1684 1682 unsigned int i; 1683 + int err = 0; 1685 1684 1686 - for (i = 1; i <= SECINITSID_NUM; i++) { 1687 - struct inode *inode; 1688 - struct dentry *dentry; 1685 + for (i = 1; !err && i <= SECINITSID_NUM; i++) { 1689 1686 const char *s = security_get_initial_sid_context(i); 1687 + struct inode *inode; 1690 1688 1691 1689 if (!s) 1692 1690 continue; 1693 - dentry = d_alloc_name(dir, s); 1694 - if (!dentry) 1695 - return -ENOMEM; 1696 1691 1697 1692 inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); 1698 - if (!inode) { 1699 - dput(dentry); 1693 + if (!inode) 1700 1694 return -ENOMEM; 1701 - } 1702 1695 1703 1696 inode->i_fop = &sel_initcon_ops; 1704 1697 inode->i_ino = i|SEL_INITCON_INO_OFFSET; 1705 - d_add(dentry, inode); 1698 + err = sel_attach_file(dir, s, inode); 1706 1699 } 1707 1700 1708 - return 0; 1701 + return err; 1709 1702 } 1710 1703 1711 1704 static inline unsigned long sel_class_to_ino(u16 class) ··· 1782 1785 if (rc) 1783 1786 return rc; 1784 1787 1785 - for (i = 0; i < nperms; i++) { 1788 + for (i = 0; !rc && i < nperms; i++) { 1786 1789 struct inode *inode; 1787 - struct dentry *dentry; 1788 1790 1789 - rc = -ENOMEM; 1790 - dentry = d_alloc_name(dir, perms[i]); 1791 - if (!dentry) 1792 - goto out; 1793 - 1794 - rc = -ENOMEM; 1795 1791 inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); 1796 1792 if (!inode) { 1797 - dput(dentry); 1798 - goto out; 1793 + rc = -ENOMEM; 1794 + break; 1799 1795 } 1800 1796 1801 1797 inode->i_fop = &sel_perm_ops; 1802 1798 /* i+1 since perm values are 1-indexed */ 1803 1799 inode->i_ino = sel_perm_to_ino(classvalue, i + 1); 1804 - d_add(dentry, inode); 1800 + 1801 + rc = sel_attach_file(dir, perms[i], inode); 1805 1802 } 1806 - rc = 0; 1807 - out: 1808 1803 for (i = 0; i < nperms; i++) 1809 1804 kfree(perms[i]); 1810 1805 kfree(perms); ··· 1811 1822 struct selinux_fs_info *fsi = sb->s_fs_info; 1812 1823 struct dentry *dentry = NULL; 1813 1824 struct inode *inode = NULL; 1814 - 1815 - dentry = d_alloc_name(dir, "index"); 1816 - if (!dentry) 1817 - return -ENOMEM; 1825 + int err; 1818 1826 1819 1827 inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); 1820 - if (!inode) { 1821 - dput(dentry); 1828 + if (!inode) 1822 1829 return -ENOMEM; 1823 - } 1824 1830 1825 1831 inode->i_fop = &sel_class_ops; 1826 1832 inode->i_ino = sel_class_to_ino(index); 1827 - d_add(dentry, inode); 1833 + 1834 + err = sel_attach_file(dir, "index", inode); 1835 + if (err) 1836 + return err; 1828 1837 1829 1838 dentry = sel_make_dir(dir, "perms", &fsi->last_class_ino); 1830 1839 if (IS_ERR(dentry)) ··· 1870 1883 return rc; 1871 1884 } 1872 1885 1873 - static int sel_make_policycap(struct selinux_fs_info *fsi) 1886 + static int sel_make_policycap(struct dentry *dir) 1874 1887 { 1888 + struct super_block *sb = dir->d_sb; 1875 1889 unsigned int iter; 1876 - struct dentry *dentry = NULL; 1877 1890 struct inode *inode = NULL; 1891 + int err = 0; 1878 1892 1879 - for (iter = 0; iter <= POLICYDB_CAP_MAX; iter++) { 1893 + for (iter = 0; !err && iter <= POLICYDB_CAP_MAX; iter++) { 1894 + const char *name; 1895 + 1880 1896 if (iter < ARRAY_SIZE(selinux_policycap_names)) 1881 - dentry = d_alloc_name(fsi->policycap_dir, 1882 - selinux_policycap_names[iter]); 1897 + name = selinux_policycap_names[iter]; 1883 1898 else 1884 - dentry = d_alloc_name(fsi->policycap_dir, "unknown"); 1899 + name = "unknown"; 1885 1900 1886 - if (dentry == NULL) 1901 + inode = sel_make_inode(sb, S_IFREG | 0444); 1902 + if (!inode) 1887 1903 return -ENOMEM; 1888 - 1889 - inode = sel_make_inode(fsi->sb, S_IFREG | 0444); 1890 - if (inode == NULL) { 1891 - dput(dentry); 1892 - return -ENOMEM; 1893 - } 1894 1904 1895 1905 inode->i_fop = &sel_policycap_ops; 1896 1906 inode->i_ino = iter | SEL_POLICYCAP_INO_OFFSET; 1897 - d_add(dentry, inode); 1907 + err = sel_attach_file(dir, name, inode); 1898 1908 } 1899 1909 1900 - return 0; 1910 + return err; 1901 1911 } 1902 1912 1903 1913 static struct dentry *sel_make_dir(struct dentry *dir, const char *name, 1904 1914 unsigned long *ino) 1905 1915 { 1906 - struct dentry *dentry = d_alloc_name(dir, name); 1907 1916 struct inode *inode; 1908 1917 1909 - if (!dentry) 1910 - return ERR_PTR(-ENOMEM); 1911 - 1912 1918 inode = sel_make_inode(dir->d_sb, S_IFDIR | S_IRUGO | S_IXUGO); 1913 - if (!inode) { 1914 - dput(dentry); 1919 + if (!inode) 1915 1920 return ERR_PTR(-ENOMEM); 1916 - } 1917 1921 1918 1922 inode->i_op = &simple_dir_inode_operations; 1919 1923 inode->i_fop = &simple_dir_operations; 1920 1924 inode->i_ino = ++(*ino); 1921 1925 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 1922 1926 inc_nlink(inode); 1923 - d_add(dentry, inode); 1924 1927 /* bump link count on parent directory, too */ 1925 1928 inc_nlink(d_inode(dir)); 1926 1929 1927 - return dentry; 1930 + return sel_attach(dir, name, inode); 1928 1931 } 1929 1932 1930 1933 static int reject_all(struct mnt_idmap *idmap, struct inode *inode, int mask) ··· 1947 1970 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 1948 1971 inc_nlink(inode); 1949 1972 inode_lock(sb->s_root->d_inode); 1950 - d_add(dentry, inode); 1973 + d_make_persistent(dentry, inode); 1951 1974 inc_nlink(sb->s_root->d_inode); 1952 1975 inode_unlock(sb->s_root->d_inode); 1953 - return dentry; 1976 + dput(dentry); 1977 + return dentry; // borrowed 1954 1978 } 1955 1979 1956 1980 #define NULL_FILE_NAME "null" ··· 2004 2026 } 2005 2027 2006 2028 ret = -ENOMEM; 2007 - dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME); 2008 - if (!dentry) 2009 - goto err; 2010 - 2011 - ret = -ENOMEM; 2012 2029 inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO); 2013 - if (!inode) { 2014 - dput(dentry); 2030 + if (!inode) 2015 2031 goto err; 2016 - } 2017 2032 2018 2033 inode->i_ino = ++fsi->last_ino; 2019 2034 isec = selinux_inode(inode); ··· 2015 2044 isec->initialized = LABEL_INITIALIZED; 2016 2045 2017 2046 init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, MKDEV(MEM_MAJOR, 3)); 2018 - d_add(dentry, inode); 2047 + ret = sel_attach_file(sb->s_root, NULL_FILE_NAME, inode); 2048 + if (ret) 2049 + goto err; 2019 2050 2020 2051 dentry = sel_make_dir(sb->s_root, "avc", &fsi->last_ino); 2021 2052 if (IS_ERR(dentry)) { ··· 2056 2083 goto err; 2057 2084 } 2058 2085 2059 - fsi->policycap_dir = sel_make_dir(sb->s_root, POLICYCAP_DIR_NAME, 2060 - &fsi->last_ino); 2061 - if (IS_ERR(fsi->policycap_dir)) { 2062 - ret = PTR_ERR(fsi->policycap_dir); 2063 - fsi->policycap_dir = NULL; 2086 + dentry = sel_make_dir(sb->s_root, "policy_capabilities", &fsi->last_ino); 2087 + if (IS_ERR(dentry)) { 2088 + ret = PTR_ERR(dentry); 2064 2089 goto err; 2065 2090 } 2066 2091 2067 - ret = sel_make_policycap(fsi); 2092 + ret = sel_make_policycap(dentry); 2068 2093 if (ret) { 2069 2094 pr_err("SELinux: failed to load policy capabilities\n"); 2070 2095 goto err; ··· 2094 2123 static void sel_kill_sb(struct super_block *sb) 2095 2124 { 2096 2125 selinux_fs_info_free(sb); 2097 - kill_litter_super(sb); 2126 + kill_anon_super(sb); 2098 2127 } 2099 2128 2100 2129 static struct file_system_type sel_fs_type = {
+1 -1
security/smack/smackfs.c
··· 2960 2960 static struct file_system_type smk_fs_type = { 2961 2961 .name = "smackfs", 2962 2962 .init_fs_context = smk_init_fs_context, 2963 - .kill_sb = kill_litter_super, 2963 + .kill_sb = kill_anon_super, 2964 2964 }; 2965 2965 2966 2966 static struct vfsmount *smackfs_mount;