fs_pin.c 1.1 KB
Newer Older
A
Al Viro 已提交
1 2 3
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/fs_pin.h>
4
#include "internal.h"
A
Al Viro 已提交
5 6 7 8 9 10 11 12 13 14 15 16
#include "mount.h"

static DEFINE_SPINLOCK(pin_lock);

void pin_remove(struct fs_pin *pin)
{
	spin_lock(&pin_lock);
	hlist_del(&pin->m_list);
	hlist_del(&pin->s_list);
	spin_unlock(&pin_lock);
}

17
void pin_insert_group(struct fs_pin *pin, struct vfsmount *m, struct hlist_head *p)
A
Al Viro 已提交
18 19
{
	spin_lock(&pin_lock);
20 21
	if (p)
		hlist_add_head(&pin->s_list, p);
A
Al Viro 已提交
22 23 24 25
	hlist_add_head(&pin->m_list, &real_mount(m)->mnt_pins);
	spin_unlock(&pin_lock);
}

26 27 28 29 30
void pin_insert(struct fs_pin *pin, struct vfsmount *m)
{
	pin_insert_group(pin, m, &m->mnt_sb->s_pins);
}

31
void mnt_pin_kill(struct mount *m)
A
Al Viro 已提交
32 33 34 35 36
{
	while (1) {
		struct hlist_node *p;
		struct fs_pin *pin;
		rcu_read_lock();
37
		p = ACCESS_ONCE(m->mnt_pins.first);
A
Al Viro 已提交
38 39 40 41 42 43 44 45 46
		if (!p) {
			rcu_read_unlock();
			break;
		}
		pin = hlist_entry(p, struct fs_pin, m_list);
		pin->kill(pin);
	}
}

47
void group_pin_kill(struct hlist_head *p)
A
Al Viro 已提交
48 49
{
	while (1) {
50
		struct hlist_node *q;
A
Al Viro 已提交
51 52
		struct fs_pin *pin;
		rcu_read_lock();
53 54
		q = ACCESS_ONCE(p->first);
		if (!q) {
A
Al Viro 已提交
55 56 57
			rcu_read_unlock();
			break;
		}
58
		pin = hlist_entry(q, struct fs_pin, s_list);
A
Al Viro 已提交
59 60 61
		pin->kill(pin);
	}
}