0001
0002 #include <linux/fs.h>
0003 #include <linux/sched.h>
0004 #include <linux/slab.h>
0005 #include "internal.h"
0006 #include "mount.h"
0007
0008 static DEFINE_SPINLOCK(pin_lock);
0009
0010 void pin_remove(struct fs_pin *pin)
0011 {
0012 spin_lock(&pin_lock);
0013 hlist_del_init(&pin->m_list);
0014 hlist_del_init(&pin->s_list);
0015 spin_unlock(&pin_lock);
0016 spin_lock_irq(&pin->wait.lock);
0017 pin->done = 1;
0018 wake_up_locked(&pin->wait);
0019 spin_unlock_irq(&pin->wait.lock);
0020 }
0021
0022 void pin_insert(struct fs_pin *pin, struct vfsmount *m)
0023 {
0024 spin_lock(&pin_lock);
0025 hlist_add_head(&pin->s_list, &m->mnt_sb->s_pins);
0026 hlist_add_head(&pin->m_list, &real_mount(m)->mnt_pins);
0027 spin_unlock(&pin_lock);
0028 }
0029
0030 void pin_kill(struct fs_pin *p)
0031 {
0032 wait_queue_entry_t wait;
0033
0034 if (!p) {
0035 rcu_read_unlock();
0036 return;
0037 }
0038 init_wait(&wait);
0039 spin_lock_irq(&p->wait.lock);
0040 if (likely(!p->done)) {
0041 p->done = -1;
0042 spin_unlock_irq(&p->wait.lock);
0043 rcu_read_unlock();
0044 p->kill(p);
0045 return;
0046 }
0047 if (p->done > 0) {
0048 spin_unlock_irq(&p->wait.lock);
0049 rcu_read_unlock();
0050 return;
0051 }
0052 __add_wait_queue(&p->wait, &wait);
0053 while (1) {
0054 set_current_state(TASK_UNINTERRUPTIBLE);
0055 spin_unlock_irq(&p->wait.lock);
0056 rcu_read_unlock();
0057 schedule();
0058 rcu_read_lock();
0059 if (likely(list_empty(&wait.entry)))
0060 break;
0061
0062 spin_lock_irq(&p->wait.lock);
0063 if (p->done > 0) {
0064 spin_unlock_irq(&p->wait.lock);
0065 break;
0066 }
0067 }
0068 rcu_read_unlock();
0069 }
0070
0071 void mnt_pin_kill(struct mount *m)
0072 {
0073 while (1) {
0074 struct hlist_node *p;
0075 rcu_read_lock();
0076 p = READ_ONCE(m->mnt_pins.first);
0077 if (!p) {
0078 rcu_read_unlock();
0079 break;
0080 }
0081 pin_kill(hlist_entry(p, struct fs_pin, m_list));
0082 }
0083 }
0084
0085 void group_pin_kill(struct hlist_head *p)
0086 {
0087 while (1) {
0088 struct hlist_node *q;
0089 rcu_read_lock();
0090 q = READ_ONCE(p->first);
0091 if (!q) {
0092 rcu_read_unlock();
0093 break;
0094 }
0095 pin_kill(hlist_entry(q, struct fs_pin, s_list));
0096 }
0097 }