diff options
-rw-r--r-- | fs/ceph/super.c | 15 | ||||
-rw-r--r-- | fs/dcache.c | 80 | ||||
-rw-r--r-- | fs/ext4/super.c | 13 | ||||
-rw-r--r-- | fs/isofs/inode.c | 7 | ||||
-rw-r--r-- | include/linux/dcache.h | 1 |
5 files changed, 63 insertions, 53 deletions
diff --git a/fs/ceph/super.c b/fs/ceph/super.c index 11bd0fc4853f..48f61a12af66 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c | |||
@@ -636,19 +636,26 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc, | |||
636 | req->r_num_caps = 2; | 636 | req->r_num_caps = 2; |
637 | err = ceph_mdsc_do_request(mdsc, NULL, req); | 637 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
638 | if (err == 0) { | 638 | if (err == 0) { |
639 | struct inode *inode = req->r_target_inode; | ||
640 | req->r_target_inode = NULL; | ||
639 | dout("open_root_inode success\n"); | 641 | dout("open_root_inode success\n"); |
640 | if (ceph_ino(req->r_target_inode) == CEPH_INO_ROOT && | 642 | if (ceph_ino(inode) == CEPH_INO_ROOT && |
641 | fsc->sb->s_root == NULL) { | 643 | fsc->sb->s_root == NULL) { |
642 | root = d_alloc_root(req->r_target_inode); | 644 | root = d_alloc_root(inode); |
645 | if (!root) { | ||
646 | iput(inode); | ||
647 | root = ERR_PTR(-ENOMEM); | ||
648 | goto out; | ||
649 | } | ||
643 | ceph_init_dentry(root); | 650 | ceph_init_dentry(root); |
644 | } else { | 651 | } else { |
645 | root = d_obtain_alias(req->r_target_inode); | 652 | root = d_obtain_alias(inode); |
646 | } | 653 | } |
647 | req->r_target_inode = NULL; | ||
648 | dout("open_root_inode success, root dentry is %p\n", root); | 654 | dout("open_root_inode success, root dentry is %p\n", root); |
649 | } else { | 655 | } else { |
650 | root = ERR_PTR(err); | 656 | root = ERR_PTR(err); |
651 | } | 657 | } |
658 | out: | ||
652 | ceph_mdsc_put_request(req); | 659 | ceph_mdsc_put_request(req); |
653 | return root; | 660 | return root; |
654 | } | 661 | } |
diff --git a/fs/dcache.c b/fs/dcache.c index 9791b1e7eee4..3c6d3113a255 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -276,15 +276,15 @@ static void dentry_lru_prune(struct dentry *dentry) | |||
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | static void dentry_lru_move_tail(struct dentry *dentry) | 279 | static void dentry_lru_move_list(struct dentry *dentry, struct list_head *list) |
280 | { | 280 | { |
281 | spin_lock(&dcache_lru_lock); | 281 | spin_lock(&dcache_lru_lock); |
282 | if (list_empty(&dentry->d_lru)) { | 282 | if (list_empty(&dentry->d_lru)) { |
283 | list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); | 283 | list_add_tail(&dentry->d_lru, list); |
284 | dentry->d_sb->s_nr_dentry_unused++; | 284 | dentry->d_sb->s_nr_dentry_unused++; |
285 | dentry_stat.nr_unused++; | 285 | dentry_stat.nr_unused++; |
286 | } else { | 286 | } else { |
287 | list_move_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); | 287 | list_move_tail(&dentry->d_lru, list); |
288 | } | 288 | } |
289 | spin_unlock(&dcache_lru_lock); | 289 | spin_unlock(&dcache_lru_lock); |
290 | } | 290 | } |
@@ -770,14 +770,18 @@ static void shrink_dentry_list(struct list_head *list) | |||
770 | } | 770 | } |
771 | 771 | ||
772 | /** | 772 | /** |
773 | * __shrink_dcache_sb - shrink the dentry LRU on a given superblock | 773 | * prune_dcache_sb - shrink the dcache |
774 | * @sb: superblock to shrink dentry LRU. | 774 | * @sb: superblock |
775 | * @count: number of entries to prune | 775 | * @count: number of entries to try to free |
776 | * @flags: flags to control the dentry processing | 776 | * |
777 | * Attempt to shrink the superblock dcache LRU by @count entries. This is | ||
778 | * done when we need more memory an called from the superblock shrinker | ||
779 | * function. | ||
777 | * | 780 | * |
778 | * If flags contains DCACHE_REFERENCED reference dentries will not be pruned. | 781 | * This function may fail to free any resources if all the dentries are in |
782 | * use. | ||
779 | */ | 783 | */ |
780 | static void __shrink_dcache_sb(struct super_block *sb, int count, int flags) | 784 | void prune_dcache_sb(struct super_block *sb, int count) |
781 | { | 785 | { |
782 | struct dentry *dentry; | 786 | struct dentry *dentry; |
783 | LIST_HEAD(referenced); | 787 | LIST_HEAD(referenced); |
@@ -796,13 +800,7 @@ relock: | |||
796 | goto relock; | 800 | goto relock; |
797 | } | 801 | } |
798 | 802 | ||
799 | /* | 803 | if (dentry->d_flags & DCACHE_REFERENCED) { |
800 | * If we are honouring the DCACHE_REFERENCED flag and the | ||
801 | * dentry has this flag set, don't free it. Clear the flag | ||
802 | * and put it back on the LRU. | ||
803 | */ | ||
804 | if (flags & DCACHE_REFERENCED && | ||
805 | dentry->d_flags & DCACHE_REFERENCED) { | ||
806 | dentry->d_flags &= ~DCACHE_REFERENCED; | 804 | dentry->d_flags &= ~DCACHE_REFERENCED; |
807 | list_move(&dentry->d_lru, &referenced); | 805 | list_move(&dentry->d_lru, &referenced); |
808 | spin_unlock(&dentry->d_lock); | 806 | spin_unlock(&dentry->d_lock); |
@@ -822,23 +820,6 @@ relock: | |||
822 | } | 820 | } |
823 | 821 | ||
824 | /** | 822 | /** |
825 | * prune_dcache_sb - shrink the dcache | ||
826 | * @sb: superblock | ||
827 | * @nr_to_scan: number of entries to try to free | ||
828 | * | ||
829 | * Attempt to shrink the superblock dcache LRU by @nr_to_scan entries. This is | ||
830 | * done when we need more memory an called from the superblock shrinker | ||
831 | * function. | ||
832 | * | ||
833 | * This function may fail to free any resources if all the dentries are in | ||
834 | * use. | ||
835 | */ | ||
836 | void prune_dcache_sb(struct super_block *sb, int nr_to_scan) | ||
837 | { | ||
838 | __shrink_dcache_sb(sb, nr_to_scan, DCACHE_REFERENCED); | ||
839 | } | ||
840 | |||
841 | /** | ||
842 | * shrink_dcache_sb - shrink dcache for a superblock | 823 | * shrink_dcache_sb - shrink dcache for a superblock |
843 | * @sb: superblock | 824 | * @sb: superblock |
844 | * | 825 | * |
@@ -1092,7 +1073,7 @@ EXPORT_SYMBOL(have_submounts); | |||
1092 | * drop the lock and return early due to latency | 1073 | * drop the lock and return early due to latency |
1093 | * constraints. | 1074 | * constraints. |
1094 | */ | 1075 | */ |
1095 | static int select_parent(struct dentry * parent) | 1076 | static int select_parent(struct dentry *parent, struct list_head *dispose) |
1096 | { | 1077 | { |
1097 | struct dentry *this_parent; | 1078 | struct dentry *this_parent; |
1098 | struct list_head *next; | 1079 | struct list_head *next; |
@@ -1114,12 +1095,11 @@ resume: | |||
1114 | 1095 | ||
1115 | spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); | 1096 | spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); |
1116 | 1097 | ||
1117 | /* | 1098 | /* |
1118 | * move only zero ref count dentries to the end | 1099 | * move only zero ref count dentries to the dispose list. |
1119 | * of the unused list for prune_dcache | ||
1120 | */ | 1100 | */ |
1121 | if (!dentry->d_count) { | 1101 | if (!dentry->d_count) { |
1122 | dentry_lru_move_tail(dentry); | 1102 | dentry_lru_move_list(dentry, dispose); |
1123 | found++; | 1103 | found++; |
1124 | } else { | 1104 | } else { |
1125 | dentry_lru_del(dentry); | 1105 | dentry_lru_del(dentry); |
@@ -1181,14 +1161,13 @@ rename_retry: | |||
1181 | * | 1161 | * |
1182 | * Prune the dcache to remove unused children of the parent dentry. | 1162 | * Prune the dcache to remove unused children of the parent dentry. |
1183 | */ | 1163 | */ |
1184 | |||
1185 | void shrink_dcache_parent(struct dentry * parent) | 1164 | void shrink_dcache_parent(struct dentry * parent) |
1186 | { | 1165 | { |
1187 | struct super_block *sb = parent->d_sb; | 1166 | LIST_HEAD(dispose); |
1188 | int found; | 1167 | int found; |
1189 | 1168 | ||
1190 | while ((found = select_parent(parent)) != 0) | 1169 | while ((found = select_parent(parent, &dispose)) != 0) |
1191 | __shrink_dcache_sb(sb, found, 0); | 1170 | shrink_dentry_list(&dispose); |
1192 | } | 1171 | } |
1193 | EXPORT_SYMBOL(shrink_dcache_parent); | 1172 | EXPORT_SYMBOL(shrink_dcache_parent); |
1194 | 1173 | ||
@@ -1461,6 +1440,23 @@ struct dentry * d_alloc_root(struct inode * root_inode) | |||
1461 | } | 1440 | } |
1462 | EXPORT_SYMBOL(d_alloc_root); | 1441 | EXPORT_SYMBOL(d_alloc_root); |
1463 | 1442 | ||
1443 | struct dentry *d_make_root(struct inode *root_inode) | ||
1444 | { | ||
1445 | struct dentry *res = NULL; | ||
1446 | |||
1447 | if (root_inode) { | ||
1448 | static const struct qstr name = { .name = "/", .len = 1 }; | ||
1449 | |||
1450 | res = __d_alloc(root_inode->i_sb, &name); | ||
1451 | if (res) | ||
1452 | d_instantiate(res, root_inode); | ||
1453 | else | ||
1454 | iput(root_inode); | ||
1455 | } | ||
1456 | return res; | ||
1457 | } | ||
1458 | EXPORT_SYMBOL(d_make_root); | ||
1459 | |||
1464 | static struct dentry * __d_find_any_alias(struct inode *inode) | 1460 | static struct dentry * __d_find_any_alias(struct inode *inode) |
1465 | { | 1461 | { |
1466 | struct dentry *alias; | 1462 | struct dentry *alias; |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 64e2529ae9bb..ed3ce82e2de4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -3733,10 +3733,12 @@ no_journal: | |||
3733 | } | 3733 | } |
3734 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { | 3734 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { |
3735 | ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck"); | 3735 | ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck"); |
3736 | iput(root); | ||
3736 | goto failed_mount4; | 3737 | goto failed_mount4; |
3737 | } | 3738 | } |
3738 | sb->s_root = d_alloc_root(root); | 3739 | sb->s_root = d_alloc_root(root); |
3739 | if (!sb->s_root) { | 3740 | if (!sb->s_root) { |
3741 | iput(root); | ||
3740 | ext4_msg(sb, KERN_ERR, "get root dentry failed"); | 3742 | ext4_msg(sb, KERN_ERR, "get root dentry failed"); |
3741 | ret = -ENOMEM; | 3743 | ret = -ENOMEM; |
3742 | goto failed_mount4; | 3744 | goto failed_mount4; |
@@ -3773,7 +3775,7 @@ no_journal: | |||
3773 | if (err) { | 3775 | if (err) { |
3774 | ext4_msg(sb, KERN_ERR, "failed to initialize system " | 3776 | ext4_msg(sb, KERN_ERR, "failed to initialize system " |
3775 | "zone (%d)", err); | 3777 | "zone (%d)", err); |
3776 | goto failed_mount4; | 3778 | goto failed_mount4a; |
3777 | } | 3779 | } |
3778 | 3780 | ||
3779 | ext4_ext_init(sb); | 3781 | ext4_ext_init(sb); |
@@ -3830,13 +3832,14 @@ cantfind_ext4: | |||
3830 | failed_mount7: | 3832 | failed_mount7: |
3831 | ext4_unregister_li_request(sb); | 3833 | ext4_unregister_li_request(sb); |
3832 | failed_mount6: | 3834 | failed_mount6: |
3833 | ext4_ext_release(sb); | ||
3834 | failed_mount5: | ||
3835 | ext4_mb_release(sb); | 3835 | ext4_mb_release(sb); |
3836 | failed_mount5: | ||
3837 | ext4_ext_release(sb); | ||
3836 | ext4_release_system_zone(sb); | 3838 | ext4_release_system_zone(sb); |
3837 | failed_mount4: | 3839 | failed_mount4a: |
3838 | iput(root); | 3840 | dput(sb->s_root); |
3839 | sb->s_root = NULL; | 3841 | sb->s_root = NULL; |
3842 | failed_mount4: | ||
3840 | ext4_msg(sb, KERN_ERR, "mount failed"); | 3843 | ext4_msg(sb, KERN_ERR, "mount failed"); |
3841 | destroy_workqueue(EXT4_SB(sb)->dio_unwritten_wq); | 3844 | destroy_workqueue(EXT4_SB(sb)->dio_unwritten_wq); |
3842 | failed_mount_wq: | 3845 | failed_mount_wq: |
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c index 7b99f5f460be..bd62c76fb5df 100644 --- a/fs/isofs/inode.c +++ b/fs/isofs/inode.c | |||
@@ -948,8 +948,11 @@ root_found: | |||
948 | 948 | ||
949 | /* get the root dentry */ | 949 | /* get the root dentry */ |
950 | s->s_root = d_alloc_root(inode); | 950 | s->s_root = d_alloc_root(inode); |
951 | if (!(s->s_root)) | 951 | if (!(s->s_root)) { |
952 | goto out_no_root; | 952 | iput(inode); |
953 | error = -ENOMEM; | ||
954 | goto out_no_inode; | ||
955 | } | ||
953 | 956 | ||
954 | kfree(opt.iocharset); | 957 | kfree(opt.iocharset); |
955 | 958 | ||
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index ed9f74f6c519..a47bda5f76db 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -249,6 +249,7 @@ extern int d_invalidate(struct dentry *); | |||
249 | 249 | ||
250 | /* only used at mount-time */ | 250 | /* only used at mount-time */ |
251 | extern struct dentry * d_alloc_root(struct inode *); | 251 | extern struct dentry * d_alloc_root(struct inode *); |
252 | extern struct dentry * d_make_root(struct inode *); | ||
252 | 253 | ||
253 | /* <clickety>-<click> the ramfs-type tree */ | 254 | /* <clickety>-<click> the ramfs-type tree */ |
254 | extern void d_genocide(struct dentry *); | 255 | extern void d_genocide(struct dentry *); |