2 * linux/ipc/namespace.c
3 * Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
8 #include <linux/ipc_namespace.h>
9 #include <linux/rcupdate.h>
10 #include <linux/nsproxy.h>
11 #include <linux/slab.h>
15 static struct ipc_namespace
*clone_ipc_ns(struct ipc_namespace
*old_ns
)
17 struct ipc_namespace
*ns
;
19 ns
= kmalloc(sizeof(struct ipc_namespace
), GFP_KERNEL
);
21 return ERR_PTR(-ENOMEM
);
31 struct ipc_namespace
*copy_ipcs(unsigned long flags
, struct ipc_namespace
*ns
)
33 struct ipc_namespace
*new_ns
;
38 if (!(flags
& CLONE_NEWIPC
))
41 new_ns
= clone_ipc_ns(ns
);
48 * free_ipcs - free all ipcs of one type
49 * @ns: the namespace to remove the ipcs from
50 * @ids: the table of ipcs to free
51 * @free: the function called to free each individual ipc
53 * Called for each kind of ipc when an ipc_namespace exits.
55 void free_ipcs(struct ipc_namespace
*ns
, struct ipc_ids
*ids
,
56 void (*free
)(struct ipc_namespace
*, struct kern_ipc_perm
*))
58 struct kern_ipc_perm
*perm
;
62 down_write(&ids
->rw_mutex
);
66 for (total
= 0, next_id
= 0; total
< in_use
; next_id
++) {
67 perm
= idr_find(&ids
->ipcs_idr
, next_id
);
70 ipc_lock_by_ptr(perm
);
74 up_write(&ids
->rw_mutex
);
77 void free_ipc_ns(struct kref
*kref
)
79 struct ipc_namespace
*ns
;
81 ns
= container_of(kref
, struct ipc_namespace
, kref
);