X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fdcookies.c;h=8749339bf4f6c5ed45cdaf37239751c4d05663d4;hb=d05022d21468c6f4ad219d77f060606021836676;hp=277ef25dff5433037d8bb345416394d0264661f1;hpb=daddc0d38b3571bed170afa273a49a0eba090c1e;p=linux-2.6.git diff --git a/fs/dcookies.c b/fs/dcookies.c index 277ef25df..8749339bf 100644 --- a/fs/dcookies.c +++ b/fs/dcookies.c @@ -13,14 +13,17 @@ */ #include +#include #include #include #include #include +#include #include #include #include #include +#include #include /* The dcookies are allocated from a kmem_cache and @@ -34,10 +37,10 @@ struct dcookie_struct { }; static LIST_HEAD(dcookie_users); -static DECLARE_MUTEX(dcookie_sem); -static kmem_cache_t * dcookie_cache; -static struct list_head * dcookie_hashtable; -static size_t hash_size; +static DEFINE_MUTEX(dcookie_mutex); +static kmem_cache_t *dcookie_cache __read_mostly; +static struct list_head *dcookie_hashtable __read_mostly; +static size_t hash_size __read_mostly; static inline int is_live(void) { @@ -60,7 +63,7 @@ static size_t dcookie_hash(unsigned long dcookie) static struct dcookie_struct * find_dcookie(unsigned long dcookie) { - struct dcookie_struct * found = 0; + struct dcookie_struct *found = NULL; struct dcookie_struct * dcs; struct list_head * pos; struct list_head * list; @@ -93,12 +96,10 @@ static struct dcookie_struct * alloc_dcookie(struct dentry * dentry, if (!dcs) return NULL; - atomic_inc(&dentry->d_count); - atomic_inc(&vfsmnt->mnt_count); dentry->d_cookie = dcs; - dcs->dentry = dentry; - dcs->vfsmnt = vfsmnt; + dcs->dentry = dget(dentry); + dcs->vfsmnt = mntget(vfsmnt); hash_dcookie(dcs); return dcs; @@ -114,7 +115,7 @@ int get_dcookie(struct dentry * dentry, struct vfsmount * vfsmnt, int err = 0; struct dcookie_struct * dcs; - down(&dcookie_sem); + mutex_lock(&dcookie_mutex); if (!is_live()) { err = -EINVAL; @@ -134,7 +135,7 @@ int get_dcookie(struct dentry * dentry, struct vfsmount * vfsmnt, *cookie = dcookie_value(dcs); out: - up(&dcookie_sem); + mutex_unlock(&dcookie_mutex); return err; } @@ -142,7 +143,7 @@ out: /* And here is where the userspace process can look up the cookie value * to retrieve the path. */ -asmlinkage long sys_lookup_dcookie(u64 cookie64, char * buf, size_t len) +asmlinkage long sys_lookup_dcookie(u64 cookie64, char __user * buf, size_t len) { unsigned long cookie = (unsigned long)cookie64; int err = -EINVAL; @@ -157,7 +158,7 @@ asmlinkage long sys_lookup_dcookie(u64 cookie64, char * buf, size_t len) if (!capable(CAP_SYS_ADMIN)) return -EPERM; - down(&dcookie_sem); + mutex_lock(&dcookie_mutex); if (!is_live()) { err = -EINVAL; @@ -192,7 +193,7 @@ asmlinkage long sys_lookup_dcookie(u64 cookie64, char * buf, size_t len) out_free: kfree(kbuf); out: - up(&dcookie_sem); + mutex_unlock(&dcookie_mutex); return err; } @@ -290,7 +291,7 @@ struct dcookie_user * dcookie_register(void) { struct dcookie_user * user; - down(&dcookie_sem); + mutex_lock(&dcookie_mutex); user = kmalloc(sizeof(struct dcookie_user), GFP_KERNEL); if (!user) @@ -302,7 +303,7 @@ struct dcookie_user * dcookie_register(void) list_add(&user->next, &dcookie_users); out: - up(&dcookie_sem); + mutex_unlock(&dcookie_mutex); return user; out_free: kfree(user); @@ -313,7 +314,7 @@ out_free: void dcookie_unregister(struct dcookie_user * user) { - down(&dcookie_sem); + mutex_lock(&dcookie_mutex); list_del(&user->next); kfree(user); @@ -321,7 +322,7 @@ void dcookie_unregister(struct dcookie_user * user) if (!is_live()) dcookie_exit(); - up(&dcookie_sem); + mutex_unlock(&dcookie_mutex); } EXPORT_SYMBOL_GPL(dcookie_register);