diff options
Diffstat (limited to 'fs/dcache.c')
-rw-r--r-- | fs/dcache.c | 315 |
1 files changed, 125 insertions, 190 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 37f72ee5bf7c..be18598c7fd7 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -344,6 +344,24 @@ void d_drop(struct dentry *dentry) | |||
344 | EXPORT_SYMBOL(d_drop); | 344 | EXPORT_SYMBOL(d_drop); |
345 | 345 | ||
346 | /* | 346 | /* |
347 | * d_clear_need_lookup - drop a dentry from cache and clear the need lookup flag | ||
348 | * @dentry: dentry to drop | ||
349 | * | ||
350 | * This is called when we do a lookup on a placeholder dentry that needed to be | ||
351 | * looked up. The dentry should have been hashed in order for it to be found by | ||
352 | * the lookup code, but now needs to be unhashed while we do the actual lookup | ||
353 | * and clear the DCACHE_NEED_LOOKUP flag. | ||
354 | */ | ||
355 | void d_clear_need_lookup(struct dentry *dentry) | ||
356 | { | ||
357 | spin_lock(&dentry->d_lock); | ||
358 | __d_drop(dentry); | ||
359 | dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | ||
360 | spin_unlock(&dentry->d_lock); | ||
361 | } | ||
362 | EXPORT_SYMBOL(d_clear_need_lookup); | ||
363 | |||
364 | /* | ||
347 | * Finish off a dentry we've decided to kill. | 365 | * Finish off a dentry we've decided to kill. |
348 | * dentry->d_lock must be held, returns with it unlocked. | 366 | * dentry->d_lock must be held, returns with it unlocked. |
349 | * If ref is non-zero, then decrement the refcount too. | 367 | * If ref is non-zero, then decrement the refcount too. |
@@ -432,8 +450,13 @@ repeat: | |||
432 | if (d_unhashed(dentry)) | 450 | if (d_unhashed(dentry)) |
433 | goto kill_it; | 451 | goto kill_it; |
434 | 452 | ||
435 | /* Otherwise leave it cached and ensure it's on the LRU */ | 453 | /* |
436 | dentry->d_flags |= DCACHE_REFERENCED; | 454 | * If this dentry needs lookup, don't set the referenced flag so that it |
455 | * is more likely to be cleaned up by the dcache shrinker in case of | ||
456 | * memory pressure. | ||
457 | */ | ||
458 | if (!d_need_lookup(dentry)) | ||
459 | dentry->d_flags |= DCACHE_REFERENCED; | ||
437 | dentry_lru_add(dentry); | 460 | dentry_lru_add(dentry); |
438 | 461 | ||
439 | dentry->d_count--; | 462 | dentry->d_count--; |
@@ -526,10 +549,6 @@ repeat: | |||
526 | */ | 549 | */ |
527 | rcu_read_lock(); | 550 | rcu_read_lock(); |
528 | ret = dentry->d_parent; | 551 | ret = dentry->d_parent; |
529 | if (!ret) { | ||
530 | rcu_read_unlock(); | ||
531 | goto out; | ||
532 | } | ||
533 | spin_lock(&ret->d_lock); | 552 | spin_lock(&ret->d_lock); |
534 | if (unlikely(ret != dentry->d_parent)) { | 553 | if (unlikely(ret != dentry->d_parent)) { |
535 | spin_unlock(&ret->d_lock); | 554 | spin_unlock(&ret->d_lock); |
@@ -540,7 +559,6 @@ repeat: | |||
540 | BUG_ON(!ret->d_count); | 559 | BUG_ON(!ret->d_count); |
541 | ret->d_count++; | 560 | ret->d_count++; |
542 | spin_unlock(&ret->d_lock); | 561 | spin_unlock(&ret->d_lock); |
543 | out: | ||
544 | return ret; | 562 | return ret; |
545 | } | 563 | } |
546 | EXPORT_SYMBOL(dget_parent); | 564 | EXPORT_SYMBOL(dget_parent); |
@@ -720,13 +738,11 @@ static void shrink_dentry_list(struct list_head *list) | |||
720 | * | 738 | * |
721 | * If flags contains DCACHE_REFERENCED reference dentries will not be pruned. | 739 | * If flags contains DCACHE_REFERENCED reference dentries will not be pruned. |
722 | */ | 740 | */ |
723 | static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags) | 741 | static void __shrink_dcache_sb(struct super_block *sb, int count, int flags) |
724 | { | 742 | { |
725 | /* called from prune_dcache() and shrink_dcache_parent() */ | ||
726 | struct dentry *dentry; | 743 | struct dentry *dentry; |
727 | LIST_HEAD(referenced); | 744 | LIST_HEAD(referenced); |
728 | LIST_HEAD(tmp); | 745 | LIST_HEAD(tmp); |
729 | int cnt = *count; | ||
730 | 746 | ||
731 | relock: | 747 | relock: |
732 | spin_lock(&dcache_lru_lock); | 748 | spin_lock(&dcache_lru_lock); |
@@ -754,7 +770,7 @@ relock: | |||
754 | } else { | 770 | } else { |
755 | list_move_tail(&dentry->d_lru, &tmp); | 771 | list_move_tail(&dentry->d_lru, &tmp); |
756 | spin_unlock(&dentry->d_lock); | 772 | spin_unlock(&dentry->d_lock); |
757 | if (!--cnt) | 773 | if (!--count) |
758 | break; | 774 | break; |
759 | } | 775 | } |
760 | cond_resched_lock(&dcache_lru_lock); | 776 | cond_resched_lock(&dcache_lru_lock); |
@@ -764,83 +780,22 @@ relock: | |||
764 | spin_unlock(&dcache_lru_lock); | 780 | spin_unlock(&dcache_lru_lock); |
765 | 781 | ||
766 | shrink_dentry_list(&tmp); | 782 | shrink_dentry_list(&tmp); |
767 | |||
768 | *count = cnt; | ||
769 | } | 783 | } |
770 | 784 | ||
771 | /** | 785 | /** |
772 | * prune_dcache - shrink the dcache | 786 | * prune_dcache_sb - shrink the dcache |
773 | * @count: number of entries to try to free | 787 | * @nr_to_scan: number of entries to try to free |
774 | * | 788 | * |
775 | * Shrink the dcache. This is done when we need more memory, or simply when we | 789 | * Attempt to shrink the superblock dcache LRU by @nr_to_scan entries. This is |
776 | * need to unmount something (at which point we need to unuse all dentries). | 790 | * done when we need more memory an called from the superblock shrinker |
791 | * function. | ||
777 | * | 792 | * |
778 | * This function may fail to free any resources if all the dentries are in use. | 793 | * This function may fail to free any resources if all the dentries are in |
794 | * use. | ||
779 | */ | 795 | */ |
780 | static void prune_dcache(int count) | 796 | void prune_dcache_sb(struct super_block *sb, int nr_to_scan) |
781 | { | 797 | { |
782 | struct super_block *sb, *p = NULL; | 798 | __shrink_dcache_sb(sb, nr_to_scan, DCACHE_REFERENCED); |
783 | int w_count; | ||
784 | int unused = dentry_stat.nr_unused; | ||
785 | int prune_ratio; | ||
786 | int pruned; | ||
787 | |||
788 | if (unused == 0 || count == 0) | ||
789 | return; | ||
790 | if (count >= unused) | ||
791 | prune_ratio = 1; | ||
792 | else | ||
793 | prune_ratio = unused / count; | ||
794 | spin_lock(&sb_lock); | ||
795 | list_for_each_entry(sb, &super_blocks, s_list) { | ||
796 | if (list_empty(&sb->s_instances)) | ||
797 | continue; | ||
798 | if (sb->s_nr_dentry_unused == 0) | ||
799 | continue; | ||
800 | sb->s_count++; | ||
801 | /* Now, we reclaim unused dentrins with fairness. | ||
802 | * We reclaim them same percentage from each superblock. | ||
803 | * We calculate number of dentries to scan on this sb | ||
804 | * as follows, but the implementation is arranged to avoid | ||
805 | * overflows: | ||
806 | * number of dentries to scan on this sb = | ||
807 | * count * (number of dentries on this sb / | ||
808 | * number of dentries in the machine) | ||
809 | */ | ||
810 | spin_unlock(&sb_lock); | ||
811 | if (prune_ratio != 1) | ||
812 | w_count = (sb->s_nr_dentry_unused / prune_ratio) + 1; | ||
813 | else | ||
814 | w_count = sb->s_nr_dentry_unused; | ||
815 | pruned = w_count; | ||
816 | /* | ||
817 | * We need to be sure this filesystem isn't being unmounted, | ||
818 | * otherwise we could race with generic_shutdown_super(), and | ||
819 | * end up holding a reference to an inode while the filesystem | ||
820 | * is unmounted. So we try to get s_umount, and make sure | ||
821 | * s_root isn't NULL. | ||
822 | */ | ||
823 | if (down_read_trylock(&sb->s_umount)) { | ||
824 | if ((sb->s_root != NULL) && | ||
825 | (!list_empty(&sb->s_dentry_lru))) { | ||
826 | __shrink_dcache_sb(sb, &w_count, | ||
827 | DCACHE_REFERENCED); | ||
828 | pruned -= w_count; | ||
829 | } | ||
830 | up_read(&sb->s_umount); | ||
831 | } | ||
832 | spin_lock(&sb_lock); | ||
833 | if (p) | ||
834 | __put_super(p); | ||
835 | count -= pruned; | ||
836 | p = sb; | ||
837 | /* more work left to do? */ | ||
838 | if (count <= 0) | ||
839 | break; | ||
840 | } | ||
841 | if (p) | ||
842 | __put_super(p); | ||
843 | spin_unlock(&sb_lock); | ||
844 | } | 799 | } |
845 | 800 | ||
846 | /** | 801 | /** |
@@ -1215,45 +1170,13 @@ void shrink_dcache_parent(struct dentry * parent) | |||
1215 | int found; | 1170 | int found; |
1216 | 1171 | ||
1217 | while ((found = select_parent(parent)) != 0) | 1172 | while ((found = select_parent(parent)) != 0) |
1218 | __shrink_dcache_sb(sb, &found, 0); | 1173 | __shrink_dcache_sb(sb, found, 0); |
1219 | } | 1174 | } |
1220 | EXPORT_SYMBOL(shrink_dcache_parent); | 1175 | EXPORT_SYMBOL(shrink_dcache_parent); |
1221 | 1176 | ||
1222 | /* | ||
1223 | * Scan `sc->nr_slab_to_reclaim' dentries and return the number which remain. | ||
1224 | * | ||
1225 | * We need to avoid reentering the filesystem if the caller is performing a | ||
1226 | * GFP_NOFS allocation attempt. One example deadlock is: | ||
1227 | * | ||
1228 | * ext2_new_block->getblk->GFP->shrink_dcache_memory->prune_dcache-> | ||
1229 | * prune_one_dentry->dput->dentry_iput->iput->inode->i_sb->s_op->put_inode-> | ||
1230 | * ext2_discard_prealloc->ext2_free_blocks->lock_super->DEADLOCK. | ||
1231 | * | ||
1232 | * In this case we return -1 to tell the caller that we baled. | ||
1233 | */ | ||
1234 | static int shrink_dcache_memory(struct shrinker *shrink, | ||
1235 | struct shrink_control *sc) | ||
1236 | { | ||
1237 | int nr = sc->nr_to_scan; | ||
1238 | gfp_t gfp_mask = sc->gfp_mask; | ||
1239 | |||
1240 | if (nr) { | ||
1241 | if (!(gfp_mask & __GFP_FS)) | ||
1242 | return -1; | ||
1243 | prune_dcache(nr); | ||
1244 | } | ||
1245 | |||
1246 | return (dentry_stat.nr_unused / 100) * sysctl_vfs_cache_pressure; | ||
1247 | } | ||
1248 | |||
1249 | static struct shrinker dcache_shrinker = { | ||
1250 | .shrink = shrink_dcache_memory, | ||
1251 | .seeks = DEFAULT_SEEKS, | ||
1252 | }; | ||
1253 | |||
1254 | /** | 1177 | /** |
1255 | * d_alloc - allocate a dcache entry | 1178 | * __d_alloc - allocate a dcache entry |
1256 | * @parent: parent of entry to allocate | 1179 | * @sb: filesystem it will belong to |
1257 | * @name: qstr of the name | 1180 | * @name: qstr of the name |
1258 | * | 1181 | * |
1259 | * Allocates a dentry. It returns %NULL if there is insufficient memory | 1182 | * Allocates a dentry. It returns %NULL if there is insufficient memory |
@@ -1261,7 +1184,7 @@ static struct shrinker dcache_shrinker = { | |||
1261 | * copied and the copy passed in may be reused after this call. | 1184 | * copied and the copy passed in may be reused after this call. |
1262 | */ | 1185 | */ |
1263 | 1186 | ||
1264 | struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | 1187 | struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) |
1265 | { | 1188 | { |
1266 | struct dentry *dentry; | 1189 | struct dentry *dentry; |
1267 | char *dname; | 1190 | char *dname; |
@@ -1291,8 +1214,8 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | |||
1291 | spin_lock_init(&dentry->d_lock); | 1214 | spin_lock_init(&dentry->d_lock); |
1292 | seqcount_init(&dentry->d_seq); | 1215 | seqcount_init(&dentry->d_seq); |
1293 | dentry->d_inode = NULL; | 1216 | dentry->d_inode = NULL; |
1294 | dentry->d_parent = NULL; | 1217 | dentry->d_parent = dentry; |
1295 | dentry->d_sb = NULL; | 1218 | dentry->d_sb = sb; |
1296 | dentry->d_op = NULL; | 1219 | dentry->d_op = NULL; |
1297 | dentry->d_fsdata = NULL; | 1220 | dentry->d_fsdata = NULL; |
1298 | INIT_HLIST_BL_NODE(&dentry->d_hash); | 1221 | INIT_HLIST_BL_NODE(&dentry->d_hash); |
@@ -1300,36 +1223,47 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | |||
1300 | INIT_LIST_HEAD(&dentry->d_subdirs); | 1223 | INIT_LIST_HEAD(&dentry->d_subdirs); |
1301 | INIT_LIST_HEAD(&dentry->d_alias); | 1224 | INIT_LIST_HEAD(&dentry->d_alias); |
1302 | INIT_LIST_HEAD(&dentry->d_u.d_child); | 1225 | INIT_LIST_HEAD(&dentry->d_u.d_child); |
1303 | 1226 | d_set_d_op(dentry, dentry->d_sb->s_d_op); | |
1304 | if (parent) { | ||
1305 | spin_lock(&parent->d_lock); | ||
1306 | /* | ||
1307 | * don't need child lock because it is not subject | ||
1308 | * to concurrency here | ||
1309 | */ | ||
1310 | __dget_dlock(parent); | ||
1311 | dentry->d_parent = parent; | ||
1312 | dentry->d_sb = parent->d_sb; | ||
1313 | d_set_d_op(dentry, dentry->d_sb->s_d_op); | ||
1314 | list_add(&dentry->d_u.d_child, &parent->d_subdirs); | ||
1315 | spin_unlock(&parent->d_lock); | ||
1316 | } | ||
1317 | 1227 | ||
1318 | this_cpu_inc(nr_dentry); | 1228 | this_cpu_inc(nr_dentry); |
1319 | 1229 | ||
1320 | return dentry; | 1230 | return dentry; |
1321 | } | 1231 | } |
1232 | |||
1233 | /** | ||
1234 | * d_alloc - allocate a dcache entry | ||
1235 | * @parent: parent of entry to allocate | ||
1236 | * @name: qstr of the name | ||
1237 | * | ||
1238 | * Allocates a dentry. It returns %NULL if there is insufficient memory | ||
1239 | * available. On a success the dentry is returned. The name passed in is | ||
1240 | * copied and the copy passed in may be reused after this call. | ||
1241 | */ | ||
1242 | struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | ||
1243 | { | ||
1244 | struct dentry *dentry = __d_alloc(parent->d_sb, name); | ||
1245 | if (!dentry) | ||
1246 | return NULL; | ||
1247 | |||
1248 | spin_lock(&parent->d_lock); | ||
1249 | /* | ||
1250 | * don't need child lock because it is not subject | ||
1251 | * to concurrency here | ||
1252 | */ | ||
1253 | __dget_dlock(parent); | ||
1254 | dentry->d_parent = parent; | ||
1255 | list_add(&dentry->d_u.d_child, &parent->d_subdirs); | ||
1256 | spin_unlock(&parent->d_lock); | ||
1257 | |||
1258 | return dentry; | ||
1259 | } | ||
1322 | EXPORT_SYMBOL(d_alloc); | 1260 | EXPORT_SYMBOL(d_alloc); |
1323 | 1261 | ||
1324 | struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name) | 1262 | struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name) |
1325 | { | 1263 | { |
1326 | struct dentry *dentry = d_alloc(NULL, name); | 1264 | struct dentry *dentry = __d_alloc(sb, name); |
1327 | if (dentry) { | 1265 | if (dentry) |
1328 | dentry->d_sb = sb; | ||
1329 | d_set_d_op(dentry, dentry->d_sb->s_d_op); | ||
1330 | dentry->d_parent = dentry; | ||
1331 | dentry->d_flags |= DCACHE_DISCONNECTED; | 1266 | dentry->d_flags |= DCACHE_DISCONNECTED; |
1332 | } | ||
1333 | return dentry; | 1267 | return dentry; |
1334 | } | 1268 | } |
1335 | EXPORT_SYMBOL(d_alloc_pseudo); | 1269 | EXPORT_SYMBOL(d_alloc_pseudo); |
@@ -1499,13 +1433,9 @@ struct dentry * d_alloc_root(struct inode * root_inode) | |||
1499 | if (root_inode) { | 1433 | if (root_inode) { |
1500 | static const struct qstr name = { .name = "/", .len = 1 }; | 1434 | static const struct qstr name = { .name = "/", .len = 1 }; |
1501 | 1435 | ||
1502 | res = d_alloc(NULL, &name); | 1436 | res = __d_alloc(root_inode->i_sb, &name); |
1503 | if (res) { | 1437 | if (res) |
1504 | res->d_sb = root_inode->i_sb; | ||
1505 | d_set_d_op(res, res->d_sb->s_d_op); | ||
1506 | res->d_parent = res; | ||
1507 | d_instantiate(res, root_inode); | 1438 | d_instantiate(res, root_inode); |
1508 | } | ||
1509 | } | 1439 | } |
1510 | return res; | 1440 | return res; |
1511 | } | 1441 | } |
@@ -1566,13 +1496,11 @@ struct dentry *d_obtain_alias(struct inode *inode) | |||
1566 | if (res) | 1496 | if (res) |
1567 | goto out_iput; | 1497 | goto out_iput; |
1568 | 1498 | ||
1569 | tmp = d_alloc(NULL, &anonstring); | 1499 | tmp = __d_alloc(inode->i_sb, &anonstring); |
1570 | if (!tmp) { | 1500 | if (!tmp) { |
1571 | res = ERR_PTR(-ENOMEM); | 1501 | res = ERR_PTR(-ENOMEM); |
1572 | goto out_iput; | 1502 | goto out_iput; |
1573 | } | 1503 | } |
1574 | tmp->d_parent = tmp; /* make sure dput doesn't croak */ | ||
1575 | |||
1576 | 1504 | ||
1577 | spin_lock(&inode->i_lock); | 1505 | spin_lock(&inode->i_lock); |
1578 | res = __d_find_any_alias(inode); | 1506 | res = __d_find_any_alias(inode); |
@@ -1584,8 +1512,6 @@ struct dentry *d_obtain_alias(struct inode *inode) | |||
1584 | 1512 | ||
1585 | /* attach a disconnected dentry */ | 1513 | /* attach a disconnected dentry */ |
1586 | spin_lock(&tmp->d_lock); | 1514 | spin_lock(&tmp->d_lock); |
1587 | tmp->d_sb = inode->i_sb; | ||
1588 | d_set_d_op(tmp, tmp->d_sb->s_d_op); | ||
1589 | tmp->d_inode = inode; | 1515 | tmp->d_inode = inode; |
1590 | tmp->d_flags |= DCACHE_DISCONNECTED; | 1516 | tmp->d_flags |= DCACHE_DISCONNECTED; |
1591 | list_add(&tmp->d_alias, &inode->i_dentry); | 1517 | list_add(&tmp->d_alias, &inode->i_dentry); |
@@ -1626,6 +1552,9 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) | |||
1626 | { | 1552 | { |
1627 | struct dentry *new = NULL; | 1553 | struct dentry *new = NULL; |
1628 | 1554 | ||
1555 | if (IS_ERR(inode)) | ||
1556 | return ERR_CAST(inode); | ||
1557 | |||
1629 | if (inode && S_ISDIR(inode->i_mode)) { | 1558 | if (inode && S_ISDIR(inode->i_mode)) { |
1630 | spin_lock(&inode->i_lock); | 1559 | spin_lock(&inode->i_lock); |
1631 | new = __d_find_alias(inode, 1); | 1560 | new = __d_find_alias(inode, 1); |
@@ -1708,29 +1637,22 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, | |||
1708 | } | 1637 | } |
1709 | 1638 | ||
1710 | /* | 1639 | /* |
1711 | * Negative dentry: instantiate it unless the inode is a directory and | 1640 | * We are going to instantiate this dentry, unhash it and clear the |
1712 | * already has a dentry. | 1641 | * lookup flag so we can do that. |
1713 | */ | 1642 | */ |
1714 | spin_lock(&inode->i_lock); | 1643 | if (unlikely(d_need_lookup(found))) |
1715 | if (!S_ISDIR(inode->i_mode) || list_empty(&inode->i_dentry)) { | 1644 | d_clear_need_lookup(found); |
1716 | __d_instantiate(found, inode); | ||
1717 | spin_unlock(&inode->i_lock); | ||
1718 | security_d_instantiate(found, inode); | ||
1719 | return found; | ||
1720 | } | ||
1721 | 1645 | ||
1722 | /* | 1646 | /* |
1723 | * In case a directory already has a (disconnected) entry grab a | 1647 | * Negative dentry: instantiate it unless the inode is a directory and |
1724 | * reference to it, move it in place and use it. | 1648 | * already has a dentry. |
1725 | */ | 1649 | */ |
1726 | new = list_entry(inode->i_dentry.next, struct dentry, d_alias); | 1650 | new = d_splice_alias(inode, found); |
1727 | __dget(new); | 1651 | if (new) { |
1728 | spin_unlock(&inode->i_lock); | 1652 | dput(found); |
1729 | security_d_instantiate(found, inode); | 1653 | found = new; |
1730 | d_move(new, found); | 1654 | } |
1731 | iput(inode); | 1655 | return found; |
1732 | dput(found); | ||
1733 | return new; | ||
1734 | 1656 | ||
1735 | err_out: | 1657 | err_out: |
1736 | iput(inode); | 1658 | iput(inode); |
@@ -1813,8 +1735,6 @@ seqretry: | |||
1813 | tname = dentry->d_name.name; | 1735 | tname = dentry->d_name.name; |
1814 | i = dentry->d_inode; | 1736 | i = dentry->d_inode; |
1815 | prefetch(tname); | 1737 | prefetch(tname); |
1816 | if (i) | ||
1817 | prefetch(i); | ||
1818 | /* | 1738 | /* |
1819 | * This seqcount check is required to ensure name and | 1739 | * This seqcount check is required to ensure name and |
1820 | * len are loaded atomically, so as not to walk off the | 1740 | * len are loaded atomically, so as not to walk off the |
@@ -2213,14 +2133,15 @@ static void dentry_unlock_parents_for_move(struct dentry *dentry, | |||
2213 | * The hash value has to match the hash queue that the dentry is on.. | 2133 | * The hash value has to match the hash queue that the dentry is on.. |
2214 | */ | 2134 | */ |
2215 | /* | 2135 | /* |
2216 | * d_move - move a dentry | 2136 | * __d_move - move a dentry |
2217 | * @dentry: entry to move | 2137 | * @dentry: entry to move |
2218 | * @target: new dentry | 2138 | * @target: new dentry |
2219 | * | 2139 | * |
2220 | * Update the dcache to reflect the move of a file name. Negative | 2140 | * Update the dcache to reflect the move of a file name. Negative |
2221 | * dcache entries should not be moved in this way. | 2141 | * dcache entries should not be moved in this way. Caller hold |
2142 | * rename_lock. | ||
2222 | */ | 2143 | */ |
2223 | void d_move(struct dentry * dentry, struct dentry * target) | 2144 | static void __d_move(struct dentry * dentry, struct dentry * target) |
2224 | { | 2145 | { |
2225 | if (!dentry->d_inode) | 2146 | if (!dentry->d_inode) |
2226 | printk(KERN_WARNING "VFS: moving negative dcache entry\n"); | 2147 | printk(KERN_WARNING "VFS: moving negative dcache entry\n"); |
@@ -2228,8 +2149,6 @@ void d_move(struct dentry * dentry, struct dentry * target) | |||
2228 | BUG_ON(d_ancestor(dentry, target)); | 2149 | BUG_ON(d_ancestor(dentry, target)); |
2229 | BUG_ON(d_ancestor(target, dentry)); | 2150 | BUG_ON(d_ancestor(target, dentry)); |
2230 | 2151 | ||
2231 | write_seqlock(&rename_lock); | ||
2232 | |||
2233 | dentry_lock_for_move(dentry, target); | 2152 | dentry_lock_for_move(dentry, target); |
2234 | 2153 | ||
2235 | write_seqcount_begin(&dentry->d_seq); | 2154 | write_seqcount_begin(&dentry->d_seq); |
@@ -2275,6 +2194,20 @@ void d_move(struct dentry * dentry, struct dentry * target) | |||
2275 | spin_unlock(&target->d_lock); | 2194 | spin_unlock(&target->d_lock); |
2276 | fsnotify_d_move(dentry); | 2195 | fsnotify_d_move(dentry); |
2277 | spin_unlock(&dentry->d_lock); | 2196 | spin_unlock(&dentry->d_lock); |
2197 | } | ||
2198 | |||
2199 | /* | ||
2200 | * d_move - move a dentry | ||
2201 | * @dentry: entry to move | ||
2202 | * @target: new dentry | ||
2203 | * | ||
2204 | * Update the dcache to reflect the move of a file name. Negative | ||
2205 | * dcache entries should not be moved in this way. | ||
2206 | */ | ||
2207 | void d_move(struct dentry *dentry, struct dentry *target) | ||
2208 | { | ||
2209 | write_seqlock(&rename_lock); | ||
2210 | __d_move(dentry, target); | ||
2278 | write_sequnlock(&rename_lock); | 2211 | write_sequnlock(&rename_lock); |
2279 | } | 2212 | } |
2280 | EXPORT_SYMBOL(d_move); | 2213 | EXPORT_SYMBOL(d_move); |
@@ -2302,7 +2235,7 @@ struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2) | |||
2302 | * This helper attempts to cope with remotely renamed directories | 2235 | * This helper attempts to cope with remotely renamed directories |
2303 | * | 2236 | * |
2304 | * It assumes that the caller is already holding | 2237 | * It assumes that the caller is already holding |
2305 | * dentry->d_parent->d_inode->i_mutex and the inode->i_lock | 2238 | * dentry->d_parent->d_inode->i_mutex, inode->i_lock and rename_lock |
2306 | * | 2239 | * |
2307 | * Note: If ever the locking in lock_rename() changes, then please | 2240 | * Note: If ever the locking in lock_rename() changes, then please |
2308 | * remember to update this too... | 2241 | * remember to update this too... |
@@ -2317,11 +2250,6 @@ static struct dentry *__d_unalias(struct inode *inode, | |||
2317 | if (alias->d_parent == dentry->d_parent) | 2250 | if (alias->d_parent == dentry->d_parent) |
2318 | goto out_unalias; | 2251 | goto out_unalias; |
2319 | 2252 | ||
2320 | /* Check for loops */ | ||
2321 | ret = ERR_PTR(-ELOOP); | ||
2322 | if (d_ancestor(alias, dentry)) | ||
2323 | goto out_err; | ||
2324 | |||
2325 | /* See lock_rename() */ | 2253 | /* See lock_rename() */ |
2326 | ret = ERR_PTR(-EBUSY); | 2254 | ret = ERR_PTR(-EBUSY); |
2327 | if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex)) | 2255 | if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex)) |
@@ -2331,7 +2259,7 @@ static struct dentry *__d_unalias(struct inode *inode, | |||
2331 | goto out_err; | 2259 | goto out_err; |
2332 | m2 = &alias->d_parent->d_inode->i_mutex; | 2260 | m2 = &alias->d_parent->d_inode->i_mutex; |
2333 | out_unalias: | 2261 | out_unalias: |
2334 | d_move(alias, dentry); | 2262 | __d_move(alias, dentry); |
2335 | ret = alias; | 2263 | ret = alias; |
2336 | out_err: | 2264 | out_err: |
2337 | spin_unlock(&inode->i_lock); | 2265 | spin_unlock(&inode->i_lock); |
@@ -2416,15 +2344,24 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode) | |||
2416 | alias = __d_find_alias(inode, 0); | 2344 | alias = __d_find_alias(inode, 0); |
2417 | if (alias) { | 2345 | if (alias) { |
2418 | actual = alias; | 2346 | actual = alias; |
2419 | /* Is this an anonymous mountpoint that we could splice | 2347 | write_seqlock(&rename_lock); |
2420 | * into our tree? */ | 2348 | |
2421 | if (IS_ROOT(alias)) { | 2349 | if (d_ancestor(alias, dentry)) { |
2350 | /* Check for loops */ | ||
2351 | actual = ERR_PTR(-ELOOP); | ||
2352 | } else if (IS_ROOT(alias)) { | ||
2353 | /* Is this an anonymous mountpoint that we | ||
2354 | * could splice into our tree? */ | ||
2422 | __d_materialise_dentry(dentry, alias); | 2355 | __d_materialise_dentry(dentry, alias); |
2356 | write_sequnlock(&rename_lock); | ||
2423 | __d_drop(alias); | 2357 | __d_drop(alias); |
2424 | goto found; | 2358 | goto found; |
2359 | } else { | ||
2360 | /* Nope, but we must(!) avoid directory | ||
2361 | * aliasing */ | ||
2362 | actual = __d_unalias(inode, dentry, alias); | ||
2425 | } | 2363 | } |
2426 | /* Nope, but we must(!) avoid directory aliasing */ | 2364 | write_sequnlock(&rename_lock); |
2427 | actual = __d_unalias(inode, dentry, alias); | ||
2428 | if (IS_ERR(actual)) | 2365 | if (IS_ERR(actual)) |
2429 | dput(alias); | 2366 | dput(alias); |
2430 | goto out_nolock; | 2367 | goto out_nolock; |
@@ -3030,8 +2967,6 @@ static void __init dcache_init(void) | |||
3030 | */ | 2967 | */ |
3031 | dentry_cache = KMEM_CACHE(dentry, | 2968 | dentry_cache = KMEM_CACHE(dentry, |
3032 | SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); | 2969 | SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); |
3033 | |||
3034 | register_shrinker(&dcache_shrinker); | ||
3035 | 2970 | ||
3036 | /* Hash may have been set up in dcache_init_early */ | 2971 | /* Hash may have been set up in dcache_init_early */ |
3037 | if (!hashdist) | 2972 | if (!hashdist) |