diff options
author | Rik van Riel <riel@surriel.com> | 2013-04-30 22:15:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-01 11:12:58 -0400 |
commit | c460b662d5cae467f1c341c59b02a5c5e68fed0b (patch) | |
tree | 0cc2f44f5a0abd0a7a143d8bd57630e27bc52311 /ipc | |
parent | 16df3674efe39f3ab63e7052f1244dd3d50e7f84 (diff) |
ipc,sem: open code and rename sem_lock
Rename sem_lock() to sem_obtain_lock(), so we can introduce a sem_lock()
later that only locks the sem_array and does nothing else.
Open code the locking from ipc_lock() in sem_obtain_lock() so we can
introduce finer grained locking for the sem_array in the next patch.
[akpm@linux-foundation.org: propagate the ipc_obtain_object() errno out of sem_obtain_lock()]
Signed-off-by: Rik van Riel <riel@redhat.com>
Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Chegu Vinod <chegu_vinod@hp.com>
Cc: Emmanuel Benisty <benisty.e@gmail.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: Stanislav Kinsbursky <skinsbursky@parallels.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/sem.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -194,14 +194,31 @@ void __init sem_init (void) | |||
194 | * sem_lock_(check_) routines are called in the paths where the rw_mutex | 194 | * sem_lock_(check_) routines are called in the paths where the rw_mutex |
195 | * is not held. | 195 | * is not held. |
196 | */ | 196 | */ |
197 | static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id) | 197 | static inline struct sem_array *sem_obtain_lock(struct ipc_namespace *ns, int id) |
198 | { | 198 | { |
199 | struct kern_ipc_perm *ipcp = ipc_lock(&sem_ids(ns), id); | 199 | struct kern_ipc_perm *ipcp; |
200 | struct sem_array *sma; | ||
200 | 201 | ||
201 | if (IS_ERR(ipcp)) | 202 | rcu_read_lock(); |
202 | return (struct sem_array *)ipcp; | 203 | ipcp = ipc_obtain_object(&sem_ids(ns), id); |
204 | if (IS_ERR(ipcp)) { | ||
205 | sma = ERR_CAST(ipcp); | ||
206 | goto err; | ||
207 | } | ||
203 | 208 | ||
204 | return container_of(ipcp, struct sem_array, sem_perm); | 209 | spin_lock(&ipcp->lock); |
210 | |||
211 | /* ipc_rmid() may have already freed the ID while sem_lock | ||
212 | * was spinning: verify that the structure is still valid | ||
213 | */ | ||
214 | if (!ipcp->deleted) | ||
215 | return container_of(ipcp, struct sem_array, sem_perm); | ||
216 | |||
217 | spin_unlock(&ipcp->lock); | ||
218 | sma = ERR_PTR(-EINVAL); | ||
219 | err: | ||
220 | rcu_read_unlock(); | ||
221 | return sma; | ||
205 | } | 222 | } |
206 | 223 | ||
207 | static inline struct sem_array *sem_obtain_object(struct ipc_namespace *ns, int id) | 224 | static inline struct sem_array *sem_obtain_object(struct ipc_namespace *ns, int id) |
@@ -1593,7 +1610,7 @@ sleep_again: | |||
1593 | goto out_free; | 1610 | goto out_free; |
1594 | } | 1611 | } |
1595 | 1612 | ||
1596 | sma = sem_lock(ns, semid); | 1613 | sma = sem_obtain_lock(ns, semid); |
1597 | 1614 | ||
1598 | /* | 1615 | /* |
1599 | * Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing. | 1616 | * Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing. |