History

Merge branch 'work.dcache2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull dcache and mountpoint updates from Al Viro: "Saner handling of refcounts to mountpoints. Transfer the counting reference from struct mount ->mnt_mountpoint over to struct mountpoint ->m_dentry. That allows us to get rid of the convoluted games with ordering of mount shutdowns. The cost is in teaching shrink_dcache_{parent,for_umount} to cope with mixed-filesystem shrink lists, which we'll also need for the Slab Movable Objects patchset" * 'work.dcache2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: switch the remnants of releasing the mountpoint away from fs_pin get rid of detach_mnt() make struct mountpoint bear the dentry reference to mountpoint, not struct mount Teach shrink_dcache_parent() to cope with mixed-filesystem shrink lists fs/namespace.c: shift put_mountpoint() to callers of unhash_mnt() __detach_mounts(): lookup_mountpoint() can't return ERR_PTR() anymore nfs: dget_parent() never returns NULL ceph: don't open-code the check for dead lockref

Linus Torvalds committed 7 years ago

Commit 18253e02 parents abdfd52 56cbb428 files · +172 −116Browse files

Unified · Split

8 files
  1. fs/ceph/dir.c +1 −1
  2. fs/dcache.c +83 −17
  3. fs/fs_pin.c +2 −8
  4. fs/internal.h +2 −0
  5. fs/mount.h +5 −3
  6. fs/namespace.c +77 −82
  7. fs/nfs/super.c +2 −4
  8. include/linux/fs_pin.h +0 −1
fs/ceph/dir.c+1−1
@@ -1267,7 +1267,7 @@ __dentry_leases_walk(struct ceph_mds_client *mdsc, · 1266 unmodified lines
12671267 if (!spin_trylock(&dentry->d_lock))
12681268 continue;
12691269
1270− if (dentry->d_lockref.count < 0) {
1270+ if (__lockref_is_dead(&dentry->d_lockref)) {
12711271 list_del_init(&di->lease_list);
12721272 goto next;
12731273 }
fs/dcache.c+83−17
@@ -861,6 +861,32 @@ void dput(struct dentry *dentry) · 860 unmodified lines
861861 }
862862 EXPORT_SYMBOL(dput);
863863
864+static void __dput_to_list(struct dentry *dentry, struct list_head *list)
865+__must_hold(&dentry->d_lock)
866+{
867+ if (dentry->d_flags & DCACHE_SHRINK_LIST) {
868+ /* let the owner of the list it's on deal with it */
869+ --dentry->d_lockref.count;
870+ } else {
871+ if (dentry->d_flags & DCACHE_LRU_LIST)
872+ d_lru_del(dentry);
873+ if (!--dentry->d_lockref.count)
874+ d_shrink_add(dentry, list);
875+ }
876+}
877+
878+void dput_to_list(struct dentry *dentry, struct list_head *list)
879+{
880+ rcu_read_lock();
881+ if (likely(fast_dput(dentry))) {
882+ rcu_read_unlock();
883+ return;
884+ }
885+ rcu_read_unlock();
886+ if (!retain_dentry(dentry))
887+ __dput_to_list(dentry, list);
888+ spin_unlock(&dentry->d_lock);
889+}
864890
865891 /* This must be called with d_lock held */
866892 static inline void __dget_dlock(struct dentry *dentry)
@@ -1067,7 +1093,7 @@ out: · 200 unmodified lines
10671093 return false;
10681094 }
10691095
1070−static void shrink_dentry_list(struct list_head *list)
1096+void shrink_dentry_list(struct list_head *list)
10711097 {
10721098 while (!list_empty(list)) {
10731099 struct dentry *dentry, *parent;
@@ -1089,18 +1115,9 @@ static void shrink_dentry_list(struct list_head *list) · 15 unmodified lines
10891115 rcu_read_unlock();
10901116 d_shrink_del(dentry);
10911117 parent = dentry->d_parent;
1118+ if (parent != dentry)
1119+ __dput_to_list(parent, list);
10921120 __dentry_kill(dentry);
1093− if (parent == dentry)
1094− continue;
1095− /*
1096− * We need to prune ancestors too. This is necessary to prevent
1097− * quadratic behavior of shrink_dcache_parent(), but is also
1098− * expected to be beneficial in reducing dentry cache
1099− * fragmentation.
1100− */
1101− dentry = parent;
1102− while (dentry && !lockref_put_or_lock(&dentry->d_lockref))
1103− dentry = dentry_kill(dentry);
11041121 }
11051122 }
11061123
@@ -1445,8 +1462,11 @@ out: · 338 unmodified lines
14451462
14461463 struct select_data {
14471464 struct dentry *start;
1465+ union {
1466+ long found;
1467+ struct dentry *victim;
1468+ };
14481469 struct list_head dispose;
1449− int found;
14501470 };
14511471
14521472 static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
@@ -1478,6 +1498,37 @@ out: · 25 unmodified lines
14781498 return ret;
14791499 }
14801500
1501+static enum d_walk_ret select_collect2(void *_data, struct dentry *dentry)
1502+{
1503+ struct select_data *data = _data;
1504+ enum d_walk_ret ret = D_WALK_CONTINUE;
1505+
1506+ if (data->start == dentry)
1507+ goto out;
1508+
1509+ if (dentry->d_flags & DCACHE_SHRINK_LIST) {
1510+ if (!dentry->d_lockref.count) {
1511+ rcu_read_lock();
1512+ data->victim = dentry;
1513+ return D_WALK_QUIT;
1514+ }
1515+ } else {
1516+ if (dentry->d_flags & DCACHE_LRU_LIST)
1517+ d_lru_del(dentry);
1518+ if (!dentry->d_lockref.count)
1519+ d_shrink_add(dentry, &data->dispose);
1520+ }
1521+ /*
1522+ * We can return to the caller if we have found some (this
1523+ * ensures forward progress). We'll be coming back to find
1524+ * the rest.
1525+ */
1526+ if (!list_empty(&data->dispose))
1527+ ret = need_resched() ? D_WALK_QUIT : D_WALK_NORETRY;
1528+out:
1529+ return ret;
1530+}
1531+
14811532 /**
14821533 * shrink_dcache_parent - prune dcache
14831534 * @parent: parent of entries to prune
@@ -1487,12 +1538,9 @@ out: · 3 unmodified lines
14871538 void shrink_dcache_parent(struct dentry *parent)
14881539 {
14891540 for (;;) {
1490− struct select_data data;
1541+ struct select_data data = {.start = parent};
14911542
14921543 INIT_LIST_HEAD(&data.dispose);
1493− data.start = parent;
1494− data.found = 0;
1495−
14961544 d_walk(parent, &data, select_collect);
14971545
14981546 if (!list_empty(&data.dispose)) {
@@ -1503,6 +1551,24 @@ void shrink_dcache_parent(struct dentry *parent) · 4 unmodified lines
15031551 cond_resched();
15041552 if (!data.found)
15051553 break;
1554+ data.victim = NULL;
1555+ d_walk(parent, &data, select_collect2);
1556+ if (data.victim) {
1557+ struct dentry *parent;
1558+ spin_lock(&data.victim->d_lock);
1559+ if (!shrink_lock_dentry(data.victim)) {
1560+ spin_unlock(&data.victim->d_lock);
1561+ rcu_read_unlock();
1562+ } else {
1563+ rcu_read_unlock();
1564+ parent = data.victim->d_parent;
1565+ if (parent != data.victim)
1566+ __dput_to_list(parent, &data.dispose);
1567+ __dentry_kill(data.victim);
1568+ }
1569+ }
1570+ if (!list_empty(&data.dispose))
1571+ shrink_dentry_list(&data.dispose);
15061572 }
15071573 }
15081574 EXPORT_SYMBOL(shrink_dcache_parent);
fs/fs_pin.c+2−8
@@ -19,20 +19,14 @@ void pin_remove(struct fs_pin *pin) · 18 unmodified lines
1919 spin_unlock_irq(&pin->wait.lock);
2020 }
2121
22−void pin_insert_group(struct fs_pin *pin, struct vfsmount *m, struct hlist_head *p)
22+void pin_insert(struct fs_pin *pin, struct vfsmount *m)
2323 {
2424 spin_lock(&pin_lock);
25− if (p)
26− hlist_add_head(&pin->s_list, p);
25+ hlist_add_head(&pin->s_list, &m->mnt_sb->s_pins);
2726 hlist_add_head(&pin->m_list, &real_mount(m)->mnt_pins);
2827 spin_unlock(&pin_lock);
2928 }
3029
31−void pin_insert(struct fs_pin *pin, struct vfsmount *m)
32−{
33− pin_insert_group(pin, m, &m->mnt_sb->s_pins);
34−}
35−
3630 void pin_kill(struct fs_pin *p)
3731 {
3832 wait_queue_entry_t wait;
fs/internal.h+2−0
@@ -157,6 +157,8 @@ extern long prune_dcache_sb(struct super_block *sb, struct shrink_control *sc); · 156 unmodified lines
157157 extern struct dentry *d_alloc_cursor(struct dentry *);
158158 extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
159159 extern char *simple_dname(struct dentry *, char *, int);
160+extern void dput_to_list(struct dentry *, struct list_head *);
161+extern void shrink_dentry_list(struct list_head *);
160162
161163 /*
162164 * read_write.c
fs/mount.h+5−3
@@ -58,7 +58,10 @@ struct mount { · 57 unmodified lines
5858 struct mount *mnt_master; /* slave is on master->mnt_slave_list */
5959 struct mnt_namespace *mnt_ns; /* containing namespace */
6060 struct mountpoint *mnt_mp; /* where is it mounted */
61− struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
61+ union {
62+ struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
63+ struct hlist_node mnt_umount;
64+ };
6265 struct list_head mnt_umounting; /* list entry for umount propagation */
6366 #ifdef CONFIG_FSNOTIFY
6467 struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
@@ -68,8 +71,7 @@ struct mount { · 3 unmodified lines
6871 int mnt_group_id; /* peer group identifier */
6972 int mnt_expiry_mark; /* true if marked for expiry */
7073 struct hlist_head mnt_pins;
71− struct fs_pin mnt_umount;
72− struct dentry *mnt_ex_mountpoint;
74+ struct hlist_head mnt_stuck_children;
7375 } __randomize_layout;
7476
7577 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
fs/namespace.c+77−82
@@ -70,6 +70,8 @@ static struct hlist_head *mount_hashtable __read_mostly; · 69 unmodified lines
7070 static struct hlist_head *mountpoint_hashtable __read_mostly;
7171 static struct kmem_cache *mnt_cache __read_mostly;
7272 static DECLARE_RWSEM(namespace_sem);
73+static HLIST_HEAD(unmounted); /* protected by namespace_sem */
74+static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
7375
7476 /* /sys/fs */
7577 struct kobject *fs_kobj;
@@ -170,14 +172,6 @@ unsigned int mnt_get_count(struct mount *mnt) · 94 unmodified lines
170172 #endif
171173 }
172174
173−static void drop_mountpoint(struct fs_pin *p)
174−{
175− struct mount *m = container_of(p, struct mount, mnt_umount);
176− dput(m->mnt_ex_mountpoint);
177− pin_remove(p);
178− mntput(&m->mnt);
179−}
180−
181175 static struct mount *alloc_vfsmnt(const char *name)
182176 {
183177 struct mount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
@@ -215,7 +209,7 @@ static struct mount *alloc_vfsmnt(const char *name) · 31 unmodified lines
215209 INIT_LIST_HEAD(&mnt->mnt_slave);
216210 INIT_HLIST_NODE(&mnt->mnt_mp_list);
217211 INIT_LIST_HEAD(&mnt->mnt_umounting);
218− init_fs_pin(&mnt->mnt_umount, drop_mountpoint);
212+ INIT_HLIST_HEAD(&mnt->mnt_stuck_children);
219213 }
220214 return mnt;
221215
@@ -740,7 +734,7 @@ mountpoint: · 518 unmodified lines
740734
741735 /* Add the new mountpoint to the hash table */
742736 read_seqlock_excl(&mount_lock);
743− new->m_dentry = dentry;
737+ new->m_dentry = dget(dentry);
744738 new->m_count = 1;
745739 hlist_add_head(&new->m_hash, mp_hash(dentry));
746740 INIT_HLIST_HEAD(&new->m_list);
@@ -753,7 +747,11 @@ done: · 6 unmodified lines
753747 return mp;
754748 }
755749
756−static void put_mountpoint(struct mountpoint *mp)
750+/*
751+ * vfsmount lock must be held. Additionally, the caller is responsible
752+ * for serializing calls for given disposal list.
753+ */
754+static void __put_mountpoint(struct mountpoint *mp, struct list_head *list)
757755 {
758756 if (!--mp->m_count) {
759757 struct dentry *dentry = mp->m_dentry;
@@ -761,11 +759,18 @@ static void put_mountpoint(struct mountpoint *mp) · 1 unmodified line
761759 spin_lock(&dentry->d_lock);
762760 dentry->d_flags &= ~DCACHE_MOUNTED;
763761 spin_unlock(&dentry->d_lock);
762+ dput_to_list(dentry, list);
764763 hlist_del(&mp->m_hash);
765764 kfree(mp);
766765 }
767766 }
768767
768+/* called with namespace_lock and vfsmount lock */
769+static void put_mountpoint(struct mountpoint *mp)
770+{
771+ __put_mountpoint(mp, &ex_mountpoints);
772+}
773+
769774 static inline int check_mnt(struct mount *mnt)
770775 {
771776 return mnt->mnt_ns == current->nsproxy->mnt_ns;
@@ -796,25 +801,17 @@ static void __touch_mnt_namespace(struct mnt_namespace *ns) · 24 unmodified lines
796801 /*
797802 * vfsmount lock must be held for write
798803 */
799−static void unhash_mnt(struct mount *mnt)
804+static struct mountpoint *unhash_mnt(struct mount *mnt)
800805 {
806+ struct mountpoint *mp;
801807 mnt->mnt_parent = mnt;
802808 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
803809 list_del_init(&mnt->mnt_child);
804810 hlist_del_init_rcu(&mnt->mnt_hash);
805811 hlist_del_init(&mnt->mnt_mp_list);
806− put_mountpoint(mnt->mnt_mp);
812+ mp = mnt->mnt_mp;
807813 mnt->mnt_mp = NULL;
808−}
809−
810−/*
811− * vfsmount lock must be held for write
812− */
813−static void detach_mnt(struct mount *mnt, struct path *old_path)
814−{
815− old_path->dentry = mnt->mnt_mountpoint;
816− old_path->mnt = &mnt->mnt_parent->mnt;
817− unhash_mnt(mnt);
814+ return mp;
818815 }
819816
820817 /*
@@ -822,9 +819,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path) · 1 unmodified line
822819 */
823820 static void umount_mnt(struct mount *mnt)
824821 {
825− /* old mountpoint will be dropped when we can do that */
826− mnt->mnt_ex_mountpoint = mnt->mnt_mountpoint;
827− unhash_mnt(mnt);
822+ put_mountpoint(unhash_mnt(mnt));
828823 }
829824
830825 /*
@@ -836,7 +831,7 @@ void mnt_set_mountpoint(struct mount *mnt, · 5 unmodified lines
836831 {
837832 mp->m_count++;
838833 mnt_add_count(mnt, 1); /* essentially, that's mntget */
839− child_mnt->mnt_mountpoint = dget(mp->m_dentry);
834+ child_mnt->mnt_mountpoint = mp->m_dentry;
840835 child_mnt->mnt_parent = mnt;
841836 child_mnt->mnt_mp = mp;
842837 hlist_add_head(&child_mnt->mnt_mp_list, &mp->m_list);
@@ -863,7 +858,6 @@ static void attach_mnt(struct mount *mnt, · 20 unmodified lines
863858 void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct mount *mnt)
864859 {
865860 struct mountpoint *old_mp = mnt->mnt_mp;
866− struct dentry *old_mountpoint = mnt->mnt_mountpoint;
867861 struct mount *old_parent = mnt->mnt_parent;
868862
869863 list_del_init(&mnt->mnt_child);
@@ -873,22 +867,6 @@ void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct m · 3 unmodified lines
873867 attach_mnt(mnt, parent, mp);
874868
875869 put_mountpoint(old_mp);
876−
877− /*
878− * Safely avoid even the suggestion this code might sleep or
879− * lock the mount hash by taking advantage of the knowledge that
880− * mnt_change_mountpoint will not release the final reference
881− * to a mountpoint.
882− *
883− * During mounting, the mount passed in as the parent mount will
884− * continue to use the old mountpoint and during unmounting, the
885− * old mountpoint will continue to exist until namespace_unlock,
886− * which happens well after mnt_change_mountpoint.
887− */
888− spin_lock(&old_mountpoint->d_lock);
889− old_mountpoint->d_lockref.count--;
890− spin_unlock(&old_mountpoint->d_lock);
891−
892870 mnt_add_count(old_parent, -1);
893871 }
894872
@@ -1103,19 +1081,22 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, · 208 unmodified lines
11031081
11041082 static void cleanup_mnt(struct mount *mnt)
11051083 {
1084+ struct hlist_node *p;
1085+ struct mount *m;
11061086 /*
1107− * This probably indicates that somebody messed
1108− * up a mnt_want/drop_write() pair. If this
1109− * happens, the filesystem was probably unable
1110− * to make r/w->r/o transitions.
1111− */
1112− /*
1087+ * The warning here probably indicates that somebody messed
1088+ * up a mnt_want/drop_write() pair. If this happens, the
1089+ * filesystem was probably unable to make r/w->r/o transitions.
11131090 * The locking used to deal with mnt_count decrement provides barriers,
11141091 * so mnt_get_writers() below is safe.
11151092 */
11161093 WARN_ON(mnt_get_writers(mnt));
11171094 if (unlikely(mnt->mnt_pins.first))
11181095 mnt_pin_kill(mnt);
1096+ hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) {
1097+ hlist_del(&m->mnt_umount);
1098+ mntput(&m->mnt);
1099+ }
11191100 fsnotify_vfsmount_delete(&mnt->mnt);
11201101 dput(mnt->mnt.mnt_root);
11211102 deactivate_super(mnt->mnt.mnt_sb);
@@ -1141,6 +1122,8 @@ static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput); · 19 unmodified lines
11411122
11421123 static void mntput_no_expire(struct mount *mnt)
11431124 {
1125+ LIST_HEAD(list);
1126+
11441127 rcu_read_lock();
11451128 if (likely(READ_ONCE(mnt->mnt_ns))) {
11461129 /*
@@ -1181,10 +1164,12 @@ static void mntput_no_expire(struct mount *mnt) · 34 unmodified lines
11811164 if (unlikely(!list_empty(&mnt->mnt_mounts))) {
11821165 struct mount *p, *tmp;
11831166 list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) {
1184− umount_mnt(p);
1167+ __put_mountpoint(unhash_mnt(p), &list);
1168+ hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children);
11851169 }
11861170 }
11871171 unlock_mount_hash();
1172+ shrink_dentry_list(&list);
11881173
11891174 if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
11901175 struct task_struct *task = current;
@@ -1370,22 +1355,29 @@ int may_umount(struct vfsmount *mnt) · 179 unmodified lines
13701355
13711356 EXPORT_SYMBOL(may_umount);
13721357
1373−static HLIST_HEAD(unmounted); /* protected by namespace_sem */
1374−
13751358 static void namespace_unlock(void)
13761359 {
13771360 struct hlist_head head;
1361+ struct hlist_node *p;
1362+ struct mount *m;
1363+ LIST_HEAD(list);
13781364
13791365 hlist_move_list(&unmounted, &head);
1366+ list_splice_init(&ex_mountpoints, &list);
13801367
13811368 up_write(&namespace_sem);
13821369
1370+ shrink_dentry_list(&list);
1371+
13831372 if (likely(hlist_empty(&head)))
13841373 return;
13851374
13861375 synchronize_rcu_expedited();
13871376
1388− group_pin_kill(&head);
1377+ hlist_for_each_entry_safe(m, p, &head, mnt_umount) {
1378+ hlist_del(&m->mnt_umount);
1379+ mntput(&m->mnt);
1380+ }
13891381 }
13901382
13911383 static inline void namespace_lock(void)
@@ -1472,8 +1464,6 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) · 80 unmodified lines
14721464
14731465 disconnect = disconnect_mount(p, how);
14741466
1475− pin_insert_group(&p->mnt_umount, &p->mnt_parent->mnt,
1476− disconnect ? &unmounted : NULL);
14771467 if (mnt_has_parent(p)) {
14781468 mnt_add_count(p->mnt_parent, -1);
14791469 if (!disconnect) {
@@ -1481,6 +1471,7 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) · 1 unmodified line
14811471 list_add_tail(&p->mnt_child, &p->mnt_parent->mnt_mounts);
14821472 } else {
14831473 umount_mnt(p);
1474+ hlist_add_head(&p->mnt_umount, &unmounted);
14841475 }
14851476 }
14861477 change_mnt_propagation(p, MS_PRIVATE);
@@ -1626,15 +1617,15 @@ void __detach_mounts(struct dentry *dentry) · 139 unmodified lines
16261617 namespace_lock();
16271618 lock_mount_hash();
16281619 mp = lookup_mountpoint(dentry);
1629− if (IS_ERR_OR_NULL(mp))
1620+ if (!mp)
16301621 goto out_unlock;
16311622
16321623 event++;
16331624 while (!hlist_empty(&mp->m_list)) {
16341625 mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
16351626 if (mnt->mnt.mnt_flags & MNT_UMOUNT) {
1636− hlist_add_head(&mnt->mnt_umount.s_list, &unmounted);
16371627 umount_mnt(mnt);
1628+ hlist_add_head(&mnt->mnt_umount, &unmounted);
16381629 }
16391630 else umount_tree(mnt, UMOUNT_CONNECTED);
16401631 }
@@ -2046,7 +2037,7 @@ int count_mounts(struct mnt_namespace *ns, struct mount *mnt) · 405 unmodified lines
20462037 static int attach_recursive_mnt(struct mount *source_mnt,
20472038 struct mount *dest_mnt,
20482039 struct mountpoint *dest_mp,
2049− struct path *parent_path)
2040+ bool moving)
20502041 {
20512042 struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
20522043 HLIST_HEAD(tree_list);
@@ -2064,7 +2055,7 @@ static int attach_recursive_mnt(struct mount *source_mnt, · 11 unmodified lines
20642055 return PTR_ERR(smp);
20652056
20662057 /* Is there space to add these mounts to the mount namespace? */
2067− if (!parent_path) {
2058+ if (!moving) {
20682059 err = count_mounts(ns, source_mnt);
20692060 if (err)
20702061 goto out;
@@ -2083,8 +2074,8 @@ static int attach_recursive_mnt(struct mount *source_mnt, · 12 unmodified lines
20832074 } else {
20842075 lock_mount_hash();
20852076 }
2086− if (parent_path) {
2087− detach_mnt(source_mnt, parent_path);
2077+ if (moving) {
2078+ unhash_mnt(source_mnt);
20882079 attach_mnt(source_mnt, dest_mnt, dest_mp);
20892080 touch_mnt_namespace(source_mnt->mnt_ns);
20902081 } else {
@@ -2182,7 +2173,7 @@ static int graft_tree(struct mount *mnt, struct mount *p, struct mountpoint *mp) · 91 unmodified lines
21822173 d_is_dir(mnt->mnt.mnt_root))
21832174 return -ENOTDIR;
21842175
2185− return attach_recursive_mnt(mnt, p, mp, NULL);
2176+ return attach_recursive_mnt(mnt, p, mp, false);
21862177 }
21872178
21882179 /*
@@ -2575,11 +2566,11 @@ out: · 386 unmodified lines
25752566
25762567 static int do_move_mount(struct path *old_path, struct path *new_path)
25772568 {
2578− struct path parent_path = {.mnt = NULL, .dentry = NULL};
25792569 struct mnt_namespace *ns;
25802570 struct mount *p;
25812571 struct mount *old;
2582− struct mountpoint *mp;
2572+ struct mount *parent;
2573+ struct mountpoint *mp, *old_mp;
25832574 int err;
25842575 bool attached;
25852576
@@ -2589,7 +2580,9 @@ static int do_move_mount(struct path *old_path, struct path *new_path) · 3 unmodified lines
25892580
25902581 old = real_mount(old_path->mnt);
25912582 p = real_mount(new_path->mnt);
2583+ parent = old->mnt_parent;
25922584 attached = mnt_has_parent(old);
2585+ old_mp = old->mnt_mp;
25932586 ns = old->mnt_ns;
25942587
25952588 err = -EINVAL;
@@ -2617,7 +2610,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path) · 21 unmodified lines
26172610 /*
26182611 * Don't move a mount residing in a shared parent.
26192612 */
2620− if (attached && IS_MNT_SHARED(old->mnt_parent))
2613+ if (attached && IS_MNT_SHARED(parent))
26212614 goto out;
26222615 /*
26232616 * Don't move a mount tree containing unbindable mounts to a destination
@@ -2633,18 +2626,21 @@ static int do_move_mount(struct path *old_path, struct path *new_path) · 9 unmodified lines
26332626 goto out;
26342627
26352628 err = attach_recursive_mnt(old, real_mount(new_path->mnt), mp,
2636− attached ? &parent_path : NULL);
2629+ attached);
26372630 if (err)
26382631 goto out;
26392632
26402633 /* if the mount is moved, it should no longer be expire
26412634 * automatically */
26422635 list_del_init(&old->mnt_expire);
2636+ if (attached)
2637+ put_mountpoint(old_mp);
26432638 out:
26442639 unlock_mount(mp);
26452640 if (!err) {
2646− path_put(&parent_path);
2647− if (!attached)
2641+ if (attached)
2642+ mntput_no_expire(parent);
2643+ else
26482644 free_mnt_ns(ns);
26492645 }
26502646 return err;
@@ -3589,8 +3585,8 @@ EXPORT_SYMBOL(path_is_under); · 938 unmodified lines
35893585 SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
35903586 const char __user *, put_old)
35913587 {
3592− struct path new, old, parent_path, root_parent, root;
3593− struct mount *new_mnt, *root_mnt, *old_mnt;
3588+ struct path new, old, root;
3589+ struct mount *new_mnt, *root_mnt, *old_mnt, *root_parent, *ex_parent;
35943590 struct mountpoint *old_mp, *root_mp;
35953591 int error;
35963592
@@ -3619,9 +3615,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, · 22 unmodified lines
36193615 new_mnt = real_mount(new.mnt);
36203616 root_mnt = real_mount(root.mnt);
36213617 old_mnt = real_mount(old.mnt);
3618+ ex_parent = new_mnt->mnt_parent;
3619+ root_parent = root_mnt->mnt_parent;
36223620 if (IS_MNT_SHARED(old_mnt) ||
3623− IS_MNT_SHARED(new_mnt->mnt_parent) ||
3624− IS_MNT_SHARED(root_mnt->mnt_parent))
3621+ IS_MNT_SHARED(ex_parent) ||
3622+ IS_MNT_SHARED(root_parent))
36253623 goto out4;
36263624 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
36273625 goto out4;
@@ -3638,7 +3636,6 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, · 10 unmodified lines
36383636 goto out4; /* not a mountpoint */
36393637 if (!mnt_has_parent(root_mnt))
36403638 goto out4; /* not attached */
3641− root_mp = root_mnt->mnt_mp;
36423639 if (new.mnt->mnt_root != new.dentry)
36433640 goto out4; /* not a mountpoint */
36443641 if (!mnt_has_parent(new_mnt))
@@ -3649,10 +3646,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, · 4 unmodified lines
36493646 /* make certain new is below the root */
36503647 if (!is_path_reachable(new_mnt, new.dentry, &root))
36513648 goto out4;
3652− root_mp->m_count++; /* pin it so it won't go away */
36533649 lock_mount_hash();
3654− detach_mnt(new_mnt, &parent_path);
3655− detach_mnt(root_mnt, &root_parent);
3650+ umount_mnt(new_mnt);
3651+ root_mp = unhash_mnt(root_mnt); /* we'll need its mountpoint */
36563652 if (root_mnt->mnt.mnt_flags & MNT_LOCKED) {
36573653 new_mnt->mnt.mnt_flags |= MNT_LOCKED;
36583654 root_mnt->mnt.mnt_flags &= ~MNT_LOCKED;
@@ -3660,7 +3656,8 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, · 1 unmodified line
36603656 /* mount old root on put_old */
36613657 attach_mnt(root_mnt, old_mnt, old_mp);
36623658 /* mount new_root on / */
3663− attach_mnt(new_mnt, real_mount(root_parent.mnt), root_mp);
3659+ attach_mnt(new_mnt, root_parent, root_mp);
3660+ mnt_add_count(root_parent, -1);
36643661 touch_mnt_namespace(current->nsproxy->mnt_ns);
36653662 /* A moved mount should not expire automatically */
36663663 list_del_init(&new_mnt->mnt_expire);
@@ -3670,10 +3667,8 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, · 3 unmodified lines
36703667 error = 0;
36713668 out4:
36723669 unlock_mount(old_mp);
3673− if (!error) {
3674− path_put(&root_parent);
3675− path_put(&parent_path);
3676− }
3670+ if (!error)
3671+ mntput_no_expire(ex_parent);
36773672 out3:
36783673 path_put(&root);
36793674 out2:
fs/nfs/super.c+2−4
@@ -457,10 +457,8 @@ int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) · 456 unmodified lines
457457 struct dentry *pd_dentry;
458458
459459 pd_dentry = dget_parent(dentry);
460− if (pd_dentry != NULL) {
461− nfs_zap_caches(d_inode(pd_dentry));
462− dput(pd_dentry);
463− }
460+ nfs_zap_caches(d_inode(pd_dentry));
461+ dput(pd_dentry);
464462 }
465463 nfs_free_fattr(res.fattr);
466464 if (error < 0)
include/linux/fs_pin.h+0−1
@@ -20,6 +20,5 @@ static inline void init_fs_pin(struct fs_pin *p, void (*kill)(struct fs_pin *)) · 19 unmodified lines
2020 }
2121
2222 void pin_remove(struct fs_pin *);
23−void pin_insert_group(struct fs_pin *, struct vfsmount *, struct hlist_head *);
2423 void pin_insert(struct fs_pin *, struct vfsmount *);
2524 void pin_kill(struct fs_pin *);