Lines Matching refs:ns

67     struct ipc_namespace *ns;

76 struct ipc_namespace *ns;
86 #define shm_ids(ns) ((ns)->ids[IPC_SHM_IDS])
93 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
98 void shm_init_ns(struct ipc_namespace *ns)
100 ns->shm_ctlmax = SHMMAX;
101 ns->shm_ctlall = SHMALL;
102 ns->shm_ctlmni = SHMMNI;
103 ns->shm_rmid_forced = 0;
104 ns->shm_tot = 0;
105 ipc_init_ids(&shm_ids(ns));
112 static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
117 WARN_ON(ns != shp->ns);
122 ipc_set_key_private(&shm_ids(ns), &shp->shm_perm);
125 shm_destroy(ns, shp);
130 void shm_exit_ns(struct ipc_namespace *ns)
132 free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
133 idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr);
134 rhashtable_destroy(&ns->ids[IPC_SHM_IDS].key_ht);
159 static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id)
161 struct kern_ipc_perm *ipcp = ipc_obtain_object_idr(&shm_ids(ns), id);
170 static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id)
172 struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&shm_ids(ns), id);
185 static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
190 ipcp = ipc_obtain_object_idr(&shm_ids(ns), id);
268 ipc_rmid(&shm_ids(s->ns), &s->shm_perm);
277 shp = shm_lock(sfd->ns, sfd->id);
309 * @ns: namespace
315 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
321 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
348 (shp->ns->shm_rmid_forced ||
363 struct ipc_namespace *ns = sfd->ns;
365 down_write(&shm_ids(ns).rwsem);
367 shp = shm_lock(ns, sfd->id);
380 shm_destroy(ns, shp);
385 up_write(&shm_ids(ns).rwsem);
388 /* Called with ns->shm_ids(ns).rwsem locked */
391 struct ipc_namespace *ns = data;
407 shm_destroy(ns, shp);
412 void shm_destroy_orphaned(struct ipc_namespace *ns)
414 down_write(&shm_ids(ns).rwsem);
415 if (shm_ids(ns).in_use) {
416 idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns);
418 up_write(&shm_ids(ns).rwsem);
426 struct ipc_namespace *ns;
445 ns = shp->ns;
452 if (!ns->shm_rmid_forced)
460 ns = get_ipc_ns_not_zero(ns);
461 if (!ns) {
490 down_write(&shm_ids(ns).rwsem);
500 shm_destroy(ns, shp);
512 up_write(&shm_ids(ns).rwsem);
513 put_ipc_ns(ns); /* paired with get_ipc_ns_not_zero */
610 put_ipc_ns(sfd->ns);
686 * @ns: namespace
691 static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
703 if (size < SHMMIN || size > ns->shm_ctlmax) {
711 if (ns->shm_tot + numpages < ns->shm_tot || ns->shm_tot + numpages > ns->shm_ctlall) {
774 error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
778 shp->ns = ns;
790 ns->shm_tot += numpages;
828 struct ipc_namespace *ns;
836 ns = current->nsproxy->ipc_ns;
842 return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
958 static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, unsigned long *swp)
966 in_use = shm_ids(ns).in_use;
972 ipc = idr_find(&shm_ids(ns).ipcs_idr, next_id);
989 static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, struct shmid64_ds *shmid64)
995 down_write(&shm_ids(ns).rwsem);
998 ipcp = ipcctl_obtain_check(ns, &shm_ids(ns), shmid, cmd, &shmid64->shm_perm, 0);
1015 do_shm_rmid(ns, ipcp);
1035 up_write(&shm_ids(ns).rwsem);
1039 static int shmctl_ipc_info(struct ipc_namespace *ns, struct shminfo64 *shminfo)
1044 shminfo->shmmni = shminfo->shmseg = ns->shm_ctlmni;
1045 shminfo->shmmax = ns->shm_ctlmax;
1046 shminfo->shmall = ns->shm_ctlall;
1048 down_read(&shm_ids(ns).rwsem);
1049 err = ipc_get_maxidx(&shm_ids(ns));
1050 up_read(&shm_ids(ns).rwsem);
1058 static int shmctl_shm_info(struct ipc_namespace *ns, struct shm_info *shm_info)
1063 down_read(&shm_ids(ns).rwsem);
1064 shm_info->used_ids = shm_ids(ns).in_use;
1065 shm_get_stat(ns, &shm_info->shm_rss, &shm_info->shm_swp);
1066 shm_info->shm_tot = ns->shm_tot;
1069 err = ipc_get_maxidx(&shm_ids(ns));
1070 up_read(&shm_ids(ns).rwsem);
1078 static int shmctl_stat(struct ipc_namespace *ns, int shmid, int cmd, struct shmid64_ds *tbuf)
1087 shp = shm_obtain_object(ns, shmid);
1093 shp = shm_obtain_object_check(ns, shmid);
1111 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) {
1163 static int shmctl_do_lock(struct ipc_namespace *ns, int shmid, int cmd)
1170 shp = shm_obtain_object_check(ns, shmid);
1190 if (!ns_capable(ns->user_ns, CAP_IPC_LOCK)) {
1243 struct ipc_namespace *ns;
1250 ns = current->nsproxy->ipc_ns;
1255 err = shmctl_ipc_info(ns, &shminfo);
1266 err = shmctl_shm_info(ns, &shm_info);
1278 err = shmctl_stat(ns, shmid, cmd, &sem64);
1293 return shmctl_down(ns, shmid, cmd, &sem64);
1296 return shmctl_do_lock(ns, shmid, cmd);
1442 struct ipc_namespace *ns;
1446 ns = current->nsproxy->ipc_ns;
1455 err = shmctl_ipc_info(ns, &shminfo);
1466 err = shmctl_shm_info(ns, &shm_info);
1478 err = shmctl_stat(ns, shmid, cmd, &sem64);
1493 return shmctl_down(ns, shmid, cmd, &sem64);
1496 return shmctl_do_lock(ns, shmid, cmd);
1540 struct ipc_namespace *ns;
1593 ns = current->nsproxy->ipc_ns;
1595 shp = shm_obtain_object_check(ns, shmid);
1602 if (ipcperms(ns, &shp->shm_perm, acc_mode)) {
1651 sfd->ns = get_ipc_ns(ns);
1693 down_write(&shm_ids(ns).rwsem);
1694 shp = shm_lock(ns, shmid);
1697 shm_destroy(ns, shp);
1701 up_write(&shm_ids(ns).rwsem);