1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/sched.h>
4 #include <linux/slab.h>
8 static DEFINE_SPINLOCK(pin_lock
);
10 void pin_remove(struct fs_pin
*pin
)
13 hlist_del_init(&pin
->m_list
);
14 hlist_del_init(&pin
->s_list
);
15 spin_unlock(&pin_lock
);
16 spin_lock_irq(&pin
->wait
.lock
);
18 wake_up_locked(&pin
->wait
);
19 spin_unlock_irq(&pin
->wait
.lock
);
22 void pin_insert(struct fs_pin
*pin
, struct vfsmount
*m
)
25 hlist_add_head(&pin
->s_list
, &m
->mnt_sb
->s_pins
);
26 hlist_add_head(&pin
->m_list
, &real_mount(m
)->mnt_pins
);
27 spin_unlock(&pin_lock
);
30 void pin_kill(struct fs_pin
*p
)
32 wait_queue_entry_t wait
;
39 spin_lock_irq(&p
->wait
.lock
);
40 if (likely(!p
->done
)) {
42 spin_unlock_irq(&p
->wait
.lock
);
48 spin_unlock_irq(&p
->wait
.lock
);
52 __add_wait_queue(&p
->wait
, &wait
);
54 set_current_state(TASK_UNINTERRUPTIBLE
);
55 spin_unlock_irq(&p
->wait
.lock
);
59 if (likely(list_empty(&wait
.entry
)))
61 /* OK, we know p couldn't have been freed yet */
62 spin_lock_irq(&p
->wait
.lock
);
64 spin_unlock_irq(&p
->wait
.lock
);
71 void mnt_pin_kill(struct mount
*m
)
76 p
= READ_ONCE(m
->mnt_pins
.first
);
81 pin_kill(hlist_entry(p
, struct fs_pin
, m_list
));
85 void group_pin_kill(struct hlist_head
*p
)
90 q
= READ_ONCE(p
->first
);
95 pin_kill(hlist_entry(q
, struct fs_pin
, s_list
));