hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/fs/autofs/root.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
34 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
45 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
5
- *
6
- * This file is part of the Linux kernel and is made available under
7
- * the terms of the GNU General Public License, version 2, or at your
8
- * option, any later version, incorporated herein by reference.
96 */
107
118 #include <linux/capability.h>
....@@ -63,38 +60,15 @@
6360 .d_release = autofs_dentry_release,
6461 };
6562
66
-static void autofs_add_active(struct dentry *dentry)
67
-{
68
- struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
69
- struct autofs_info *ino;
70
-
71
- ino = autofs_dentry_ino(dentry);
72
- if (ino) {
73
- spin_lock(&sbi->lookup_lock);
74
- if (!ino->active_count) {
75
- if (list_empty(&ino->active))
76
- list_add(&ino->active, &sbi->active_list);
77
- }
78
- ino->active_count++;
79
- spin_unlock(&sbi->lookup_lock);
80
- }
81
-}
82
-
8363 static void autofs_del_active(struct dentry *dentry)
8464 {
8565 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
8666 struct autofs_info *ino;
8767
8868 ino = autofs_dentry_ino(dentry);
89
- if (ino) {
90
- spin_lock(&sbi->lookup_lock);
91
- ino->active_count--;
92
- if (!ino->active_count) {
93
- if (!list_empty(&ino->active))
94
- list_del_init(&ino->active);
95
- }
96
- spin_unlock(&sbi->lookup_lock);
97
- }
69
+ spin_lock(&sbi->lookup_lock);
70
+ list_del_init(&ino->active);
71
+ spin_unlock(&sbi->lookup_lock);
9872 }
9973
10074 static int autofs_dir_open(struct inode *inode, struct file *file)
....@@ -275,8 +249,11 @@
275249 pr_debug("waiting for mount name=%pd\n", path->dentry);
276250 status = autofs_wait(sbi, path, NFY_MOUNT);
277251 pr_debug("mount wait done status=%d\n", status);
252
+ ino->last_used = jiffies;
253
+ return status;
278254 }
279
- ino->last_used = jiffies;
255
+ if (!(sbi->flags & AUTOFS_SBI_STRICTEXPIRE))
256
+ ino->last_used = jiffies;
280257 return status;
281258 }
282259
....@@ -510,7 +487,8 @@
510487 sbi = autofs_sbi(dir->i_sb);
511488
512489 pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
513
- current->pid, task_pgrp_nr(current), sbi->catatonic,
490
+ current->pid, task_pgrp_nr(current),
491
+ sbi->flags & AUTOFS_SBI_CATATONIC,
514492 autofs_oz_mode(sbi));
515493
516494 active = autofs_lookup_active(dentry);
....@@ -526,19 +504,22 @@
526504 if (!autofs_oz_mode(sbi) && !IS_ROOT(dentry->d_parent))
527505 return ERR_PTR(-ENOENT);
528506
529
- /* Mark entries in the root as mount triggers */
530
- if (IS_ROOT(dentry->d_parent) &&
531
- autofs_type_indirect(sbi->type))
532
- __managed_dentry_set_managed(dentry);
533
-
534507 ino = autofs_new_ino(sbi);
535508 if (!ino)
536509 return ERR_PTR(-ENOMEM);
537510
511
+ spin_lock(&sbi->lookup_lock);
512
+ spin_lock(&dentry->d_lock);
513
+ /* Mark entries in the root as mount triggers */
514
+ if (IS_ROOT(dentry->d_parent) &&
515
+ autofs_type_indirect(sbi->type))
516
+ __managed_dentry_set_managed(dentry);
538517 dentry->d_fsdata = ino;
539518 ino->dentry = dentry;
540519
541
- autofs_add_active(dentry);
520
+ list_add(&ino->active, &sbi->active_list);
521
+ spin_unlock(&sbi->lookup_lock);
522
+ spin_unlock(&dentry->d_lock);
542523 }
543524 return NULL;
544525 }
....@@ -563,7 +544,7 @@
563544 * autofs mount is catatonic but the state of an autofs
564545 * file system needs to be preserved over restarts.
565546 */
566
- if (sbi->catatonic)
547
+ if (sbi->flags & AUTOFS_SBI_CATATONIC)
567548 return -EACCES;
568549
569550 BUG_ON(!ino);
....@@ -588,10 +569,9 @@
588569 d_add(dentry, inode);
589570
590571 dget(dentry);
591
- atomic_inc(&ino->count);
572
+ ino->count++;
592573 p_ino = autofs_dentry_ino(dentry->d_parent);
593
- if (p_ino && !IS_ROOT(dentry))
594
- atomic_inc(&p_ino->count);
574
+ p_ino->count++;
595575
596576 dir->i_mtime = current_time(dir);
597577
....@@ -626,14 +606,12 @@
626606 * autofs mount is catatonic but the state of an autofs
627607 * file system needs to be preserved over restarts.
628608 */
629
- if (sbi->catatonic)
609
+ if (sbi->flags & AUTOFS_SBI_CATATONIC)
630610 return -EACCES;
631611
632
- if (atomic_dec_and_test(&ino->count)) {
633
- p_ino = autofs_dentry_ino(dentry->d_parent);
634
- if (p_ino && !IS_ROOT(dentry))
635
- atomic_dec(&p_ino->count);
636
- }
612
+ ino->count--;
613
+ p_ino = autofs_dentry_ino(dentry->d_parent);
614
+ p_ino->count--;
637615 dput(ino->dentry);
638616
639617 d_inode(dentry)->i_size = 0;
....@@ -679,7 +657,6 @@
679657
680658 static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
681659 {
682
- struct list_head *d_child;
683660 struct dentry *parent;
684661
685662 /* flags for dentrys in the root are handled elsewhere */
....@@ -692,10 +669,7 @@
692669 /* only consider parents below dentrys in the root */
693670 if (IS_ROOT(parent->d_parent))
694671 return;
695
- d_child = &dentry->d_child;
696
- /* Set parent managed if it's becoming empty */
697
- if (d_child->next == &parent->d_subdirs &&
698
- d_child->prev == &parent->d_subdirs)
672
+ if (autofs_dentry_ino(parent)->count == 2)
699673 managed_dentry_set_managed(parent);
700674 }
701675
....@@ -714,14 +688,13 @@
714688 * autofs mount is catatonic but the state of an autofs
715689 * file system needs to be preserved over restarts.
716690 */
717
- if (sbi->catatonic)
691
+ if (sbi->flags & AUTOFS_SBI_CATATONIC)
718692 return -EACCES;
719693
720
- spin_lock(&sbi->lookup_lock);
721
- if (!simple_empty(dentry)) {
722
- spin_unlock(&sbi->lookup_lock);
694
+ if (ino->count != 1)
723695 return -ENOTEMPTY;
724
- }
696
+
697
+ spin_lock(&sbi->lookup_lock);
725698 __autofs_add_expiring(dentry);
726699 d_drop(dentry);
727700 spin_unlock(&sbi->lookup_lock);
....@@ -729,11 +702,9 @@
729702 if (sbi->version < 5)
730703 autofs_clear_leaf_automount_flags(dentry);
731704
732
- if (atomic_dec_and_test(&ino->count)) {
733
- p_ino = autofs_dentry_ino(dentry->d_parent);
734
- if (p_ino && dentry->d_parent != dentry)
735
- atomic_dec(&p_ino->count);
736
- }
705
+ ino->count--;
706
+ p_ino = autofs_dentry_ino(dentry->d_parent);
707
+ p_ino->count--;
737708 dput(ino->dentry);
738709 d_inode(dentry)->i_size = 0;
739710 clear_nlink(d_inode(dentry));
....@@ -759,7 +730,7 @@
759730 * autofs mount is catatonic but the state of an autofs
760731 * file system needs to be preserved over restarts.
761732 */
762
- if (sbi->catatonic)
733
+ if (sbi->flags & AUTOFS_SBI_CATATONIC)
763734 return -EACCES;
764735
765736 pr_debug("dentry %p, creating %pd\n", dentry, dentry);
....@@ -779,10 +750,9 @@
779750 autofs_set_leaf_automount_flags(dentry);
780751
781752 dget(dentry);
782
- atomic_inc(&ino->count);
753
+ ino->count++;
783754 p_ino = autofs_dentry_ino(dentry->d_parent);
784
- if (p_ino && !IS_ROOT(dentry))
785
- atomic_inc(&p_ino->count);
755
+ p_ino->count++;
786756 inc_nlink(dir);
787757 dir->i_mtime = current_time(dir);
788758