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

Configure Feed

Select the types of activity you want to include in your feed.

introduce a flag for explicitly marking persistently pinned dentries

Some filesystems use a kinda-sorta controlled dentry refcount leak to pin
dentries of created objects in dcache (and undo it when removing those).
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.

Here we
* introduce the new flag
* teach shrink_dcache_for_umount() to handle it (i.e. remove
and drop refcount on anything that survives to umount with that flag
still set)
* teach kill_litter_super() that anything with that flag does
*not* need to be unpinned.

Next commits will add primitives for maintaing that flag and convert the
common helpers to those. After that - a long series of per-filesystem
patches converting to those primitives.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 8a210cac 1552ddc7

+23 -5
+22 -5
fs/dcache.c
··· 1511 1511 return ret; 1512 1512 } 1513 1513 1514 + static enum d_walk_ret select_collect_umount(void *_data, struct dentry *dentry) 1515 + { 1516 + if (dentry->d_flags & DCACHE_PERSISTENT) { 1517 + dentry->d_flags &= ~DCACHE_PERSISTENT; 1518 + dentry->d_lockref.count--; 1519 + } 1520 + return select_collect(_data, dentry); 1521 + } 1522 + 1514 1523 static enum d_walk_ret select_collect2(void *_data, struct dentry *dentry) 1515 1524 { 1516 1525 struct select_data *data = _data; ··· 1548 1539 } 1549 1540 1550 1541 /** 1551 - * shrink_dcache_parent - prune dcache 1542 + * shrink_dcache_tree - prune dcache 1552 1543 * @parent: parent of entries to prune 1544 + * @for_umount: true if we want to unpin the persistent ones 1553 1545 * 1554 1546 * Prune the dcache to remove unused children of the parent dentry. 1555 1547 */ 1556 - void shrink_dcache_parent(struct dentry *parent) 1548 + static void shrink_dcache_tree(struct dentry *parent, bool for_umount) 1557 1549 { 1558 1550 for (;;) { 1559 1551 struct select_data data = {.start = parent}; 1560 1552 1561 1553 INIT_LIST_HEAD(&data.dispose); 1562 - d_walk(parent, &data, select_collect); 1554 + d_walk(parent, &data, 1555 + for_umount ? select_collect_umount : select_collect); 1563 1556 1564 1557 if (!list_empty(&data.dispose)) { 1565 1558 shrink_dentry_list(&data.dispose); ··· 1585 1574 if (!list_empty(&data.dispose)) 1586 1575 shrink_dentry_list(&data.dispose); 1587 1576 } 1577 + } 1578 + 1579 + void shrink_dcache_parent(struct dentry *parent) 1580 + { 1581 + shrink_dcache_tree(parent, false); 1588 1582 } 1589 1583 EXPORT_SYMBOL(shrink_dcache_parent); 1590 1584 ··· 1617 1601 1618 1602 static void do_one_tree(struct dentry *dentry) 1619 1603 { 1620 - shrink_dcache_parent(dentry); 1604 + shrink_dcache_tree(dentry, true); 1621 1605 d_walk(dentry, dentry, umount_check); 1622 1606 d_drop(dentry); 1623 1607 dput(dentry); ··· 3127 3111 { 3128 3112 struct dentry *root = data; 3129 3113 if (dentry != root) { 3130 - if (d_unhashed(dentry) || !dentry->d_inode) 3114 + if (d_unhashed(dentry) || !dentry->d_inode || 3115 + dentry->d_flags & DCACHE_PERSISTENT) 3131 3116 return D_WALK_SKIP; 3132 3117 3133 3118 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
+1
include/linux/dcache.h
··· 225 225 DCACHE_PAR_LOOKUP = BIT(24), /* being looked up (with parent locked shared) */ 226 226 DCACHE_DENTRY_CURSOR = BIT(25), 227 227 DCACHE_NORCU = BIT(26), /* No RCU delay for freeing */ 228 + DCACHE_PERSISTENT = BIT(27) 228 229 }; 229 230 230 231 #define DCACHE_MANAGED_DENTRY \