Back to home page

LXR

 
 

    


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