mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
IPC: consolidate sem_exit_ns(), msg_exit_ns() and shm_exit_ns()
sem_exit_ns(), msg_exit_ns() and shm_exit_ns() are all called when an ipc_namespace is released to free all ipcs of each type. But in fact, they do the same thing: they loop around all ipcs to free them individually by calling a specific routine. This patch proposes to consolidate this by introducing a common function, free_ipcs(), that do the job. The specific routine to call on each individual ipcs is passed as parameter. For this, these ipc-specific 'free' routines are reworked to take a generic 'struct ipc_perm' as parameter. Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net> Cc: Cedric Le Goater <clg@fr.ibm.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Nadia Derbey <Nadia.Derbey@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
ed2ddbf88c
commit
01b8b07a5d
5 changed files with 50 additions and 67 deletions
27
ipc/shm.c
27
ipc/shm.c
|
@ -83,8 +83,11 @@ void shm_init_ns(struct ipc_namespace *ns)
|
|||
* Called with shm_ids.rw_mutex (writer) and the shp structure locked.
|
||||
* Only shm_ids.rw_mutex remains locked on exit.
|
||||
*/
|
||||
static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
|
||||
static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
|
||||
{
|
||||
struct shmid_kernel *shp;
|
||||
shp = container_of(ipcp, struct shmid_kernel, shm_perm);
|
||||
|
||||
if (shp->shm_nattch){
|
||||
shp->shm_perm.mode |= SHM_DEST;
|
||||
/* Do not find it any more */
|
||||
|
@ -97,25 +100,7 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
|
|||
#ifdef CONFIG_IPC_NS
|
||||
void shm_exit_ns(struct ipc_namespace *ns)
|
||||
{
|
||||
struct shmid_kernel *shp;
|
||||
struct kern_ipc_perm *perm;
|
||||
int next_id;
|
||||
int total, in_use;
|
||||
|
||||
down_write(&shm_ids(ns).rw_mutex);
|
||||
|
||||
in_use = shm_ids(ns).in_use;
|
||||
|
||||
for (total = 0, next_id = 0; total < in_use; next_id++) {
|
||||
perm = idr_find(&shm_ids(ns).ipcs_idr, next_id);
|
||||
if (perm == NULL)
|
||||
continue;
|
||||
ipc_lock_by_ptr(perm);
|
||||
shp = container_of(perm, struct shmid_kernel, shm_perm);
|
||||
do_shm_rmid(ns, shp);
|
||||
total++;
|
||||
}
|
||||
up_write(&shm_ids(ns).rw_mutex);
|
||||
free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -832,7 +817,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
|
|||
if (err)
|
||||
goto out_unlock_up;
|
||||
|
||||
do_shm_rmid(ns, shp);
|
||||
do_shm_rmid(ns, &shp->shm_perm);
|
||||
up_write(&shm_ids(ns).rw_mutex);
|
||||
goto out;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue