X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ipc%2Futil.c;fp=ipc%2Futil.c;h=3d4b5c1d3312af6b9174c4abca98668bf661ed0d;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=65efa3774133bf37382b9d474b868dd6ce0fb0c0;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/ipc/util.c b/ipc/util.c index 65efa3774..3d4b5c1d3 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -10,10 +10,9 @@ * Manfred Spraul * Oct 2002 - One lock per IPC id. RCU ipc_free for lock-free grow_ary(). * Mingming Cao - * Mar 2006 - support for audit of ipc object properties - * Dustin Kirkland */ +#include #include #include #include @@ -28,7 +27,6 @@ #include #include #include -#include #include @@ -70,8 +68,7 @@ __initcall(ipc_init); void __init ipc_init_ids(struct ipc_ids* ids, int size) { int i; - - mutex_init(&ids->mutex); + sema_init(&ids->sem,1); if(size > IPCMNI) size = IPCMNI; @@ -141,7 +138,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header, * @ids: Identifier set * @key: The key to find * - * Requires ipc_ids.mutex locked. + * Requires ipc_ids.sem locked. * Returns the identifier if found or -1 if not. */ @@ -153,7 +150,7 @@ int ipc_findkey(struct ipc_ids* ids, key_t key) /* * rcu_dereference() is not needed here - * since ipc_ids.mutex is held + * since ipc_ids.sem is held */ for (id = 0; id <= max_id; id++) { p = ids->entries->p[id]; @@ -168,7 +165,7 @@ int ipc_findkey(struct ipc_ids* ids, key_t key) } /* - * Requires ipc_ids.mutex locked + * Requires ipc_ids.sem locked */ static int grow_ary(struct ipc_ids* ids, int newsize) { @@ -214,7 +211,7 @@ static int grow_ary(struct ipc_ids* ids, int newsize) * is returned. The list is returned in a locked state on success. * On failure the list is not locked and -1 is returned. * - * Called with ipc_ids.mutex held. + * Called with ipc_ids.sem held. */ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) @@ -225,7 +222,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) /* * rcu_dereference()() is not needed here since - * ipc_ids.mutex is held + * ipc_ids.sem is held */ for (id = 0; id < size; id++) { if(ids->entries->p[id] == NULL) @@ -261,7 +258,7 @@ found: * fed an invalid identifier. The entry is removed and internal * variables recomputed. The object associated with the identifier * is returned. - * ipc_ids.mutex and the spinlock for this ID is hold before this function + * ipc_ids.sem and the spinlock for this ID is hold before this function * is called, and remain locked on the exit. */ @@ -269,15 +266,17 @@ struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id) { struct kern_ipc_perm* p; int lid = id % SEQ_MULTIPLIER; - BUG_ON(lid >= ids->entries->size); + if(lid >= ids->entries->size) + BUG(); /* * do not need a rcu_dereference()() here to force ordering - * on Alpha, since the ipc_ids.mutex is held. + * on Alpha, since the ipc_ids.sem is held. */ p = ids->entries->p[lid]; ids->entries->p[lid] = NULL; - BUG_ON(p==NULL); + if(p==NULL) + BUG(); ids->in_use--; if (lid == ids->max_id) { @@ -468,10 +467,7 @@ void ipc_rcu_putref(void *ptr) int ipcperms (struct kern_ipc_perm *ipcp, short flag) { /* flag will most probably be 0 or S_...UGO from */ - int requested_mode, granted_mode, err; - - if (unlikely((err = audit_ipc_obj(ipcp)))) - return err; + int requested_mode, granted_mode; if (!vx_check(ipcp->xid, VX_ADMIN|VX_IDENT)) /* maybe just VX_IDENT? */ return -1; @@ -537,13 +533,13 @@ void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out) /* * So far only shm_get_stat() calls ipc_get() via shm_get(), so ipc_get() - * is called with shm_ids.mutex locked. Since grow_ary() is also called with - * shm_ids.mutex down(for Shared Memory), there is no need to add read + * is called with shm_ids.sem locked. Since grow_ary() is also called with + * shm_ids.sem down(for Shared Memory), there is no need to add read * barriers here to gurantee the writes in grow_ary() are seen in order * here (for Alpha). * - * However ipc_get() itself does not necessary require ipc_ids.mutex down. So - * if in the future ipc_get() is used by other places without ipc_ids.mutex + * However ipc_get() itself does not necessary require ipc_ids.sem down. So + * if in the future ipc_get() is used by other places without ipc_ids.sem * down, then ipc_get() needs read memery barriers as ipc_lock() does. */ struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id) @@ -674,7 +670,7 @@ static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos) * Take the lock - this will be released by the corresponding * call to stop(). */ - mutex_lock(&iface->ids->mutex); + down(&iface->ids->sem); /* pos < 0 is invalid */ if (*pos < 0) @@ -704,7 +700,7 @@ static void sysvipc_proc_stop(struct seq_file *s, void *it) ipc_unlock(ipc); /* Release the lock we took in start() */ - mutex_unlock(&iface->ids->mutex); + up(&iface->ids->sem); } static int sysvipc_proc_show(struct seq_file *s, void *it)