Home | History | Annotate | Download | only in kern

Lines Matching refs:mq

92 	.fo_name = "mq",
122 mqueue_t *mq;
130 mq = arg1;
132 if (kauth_cred_geteuid(cred) == mq->mq_euid)
223 mqueue_destroy(struct mqueue *mq)
231 while ((msg = TAILQ_FIRST(&mq->mq_head[i])) != NULL) {
232 TAILQ_REMOVE(&mq->mq_head[i], msg, msg_queue);
237 if (mq->mq_name) {
238 kmem_free(mq->mq_name, MQ_NAMELEN);
240 seldestroy(&mq->mq_rsel);
241 seldestroy(&mq->mq_wsel);
242 cv_destroy(&mq->mq_send_cv);
243 cv_destroy(&mq->mq_recv_cv);
244 mutex_destroy(&mq->mq_mtx);
245 kmem_free(mq, sizeof(struct mqueue));
256 mqueue_t *mq;
260 LIST_FOREACH(mq, &mqueue_head, mq_list) {
261 if (strncmp(mq->mq_name, name, MQ_NAMELEN) == 0) {
262 mutex_enter(&mq->mq_mtx);
263 return mq;
279 mqueue_t *mq;
294 mq = fp->f_mqueue;
295 mutex_enter(&mq->mq_mtx);
297 *mqret = mq;
307 mqueue_linear_insert(struct mqueue *mq, struct mq_msg *msg)
311 TAILQ_FOREACH(mit, &mq->mq_head[MQ_PQRESQ], msg_queue) {
316 TAILQ_INSERT_TAIL(&mq->mq_head[MQ_PQRESQ], msg, msg_queue);
325 struct mqueue *mq = fp->f_mqueue;
329 mutex_enter(&mq->mq_mtx);
330 st->st_mode = mq->mq_mode;
331 st->st_uid = mq->mq_euid;
332 st->st_gid = mq->mq_egid;
333 st->st_atimespec = mq->mq_atime;
334 st->st_mtimespec = mq->mq_mtime;
335 st->st_ctimespec = st->st_birthtimespec = mq->mq_btime;
338 mutex_exit(&mq->mq_mtx);
346 struct mqueue *mq = fp->f_mqueue;
350 mutex_enter(&mq->mq_mtx);
351 mqattr = &mq->mq_attrib;
357 selrecord(curlwp, &mq->mq_rsel);
364 selrecord(curlwp, &mq->mq_wsel);
366 mutex_exit(&mq->mq_mtx);
375 mqueue_t *mq = fp->f_mqueue;
378 mutex_enter(&mq->mq_mtx);
379 KASSERT(mq->mq_refcnt > 0);
380 if (--mq->mq_refcnt == 0) {
382 destroy = (mq->mq_attrib.mq_flags & MQ_UNLINKED) != 0;
384 mutex_exit(&mq->mq_mtx);
387 mqueue_destroy(mq);
394 mqueue_access(mqueue_t *mq, int access, kauth_cred_t cred)
405 if (genfs_can_access(NULL, cred, mq->mq_euid, mq->mq_egid,
406 mq->mq_mode, NULL, accmode)) {
418 mqueue_t *mq;
440 mq = kmem_zalloc(sizeof(mqueue_t), KM_SLEEP);
442 mutex_init(&mq->mq_mtx, MUTEX_DEFAULT, IPL_NONE);
443 cv_init(&mq->mq_send_cv, "mqsendcv");
444 cv_init(&mq->mq_recv_cv, "mqrecvcv");
446 TAILQ_INIT(&mq->mq_head[i]);
448 selinit(&mq->mq_rsel);
449 selinit(&mq->mq_wsel);
450 mq->mq_name = name;
451 mq->mq_refcnt = 1;
454 memcpy(&mq->mq_attrib, attr, sizeof(struct mq_attr));
456 memset(&mq->mq_attrib, 0, sizeof(struct mq_attr));
457 mq->mq_attrib.mq_maxmsg = mq_def_maxmsg;
458 mq->mq_attrib.mq_msgsize = MQ_DEF_MSGSIZE - sizeof(struct mq_msg);
462 mq->mq_attrib.mq_flags = (O_MASK & oflag);
465 mq->mq_mode = ((mode & ~cwdi->cwdi_cmask) & ALLPERMS) & ~S_ISTXT;
466 mq->mq_euid = kauth_cred_geteuid(l->l_cred);
467 mq->mq_egid = kauth_cred_getegid(l->l_cred);
469 *mqret = mq;
482 struct mqueue *mq, *mq_new = NULL;
524 mq = mqueue_lookup(name);
525 if (mq) {
526 KASSERT(mutex_owned(&mq->mq_mtx));
531 mutex_exit(&mq->mq_mtx);
537 if (mqueue_access(mq, fp->f_flag, l->l_cred) != 0) {
538 mutex_exit(&mq->mq_mtx);
544 mq->mq_refcnt++;
545 mutex_exit(&mq->mq_mtx);
556 mq = mq_new;
557 getnanotime(&mq->mq_btime);
558 mq->mq_atime = mq->mq_mtime = mq->mq_btime;
564 LIST_INSERT_HEAD(&mqueue_head, mq, mq_list);
570 KASSERT(mq != NULL);
571 fp->f_mqueue = mq;
633 struct mqueue *mq;
639 error = mqueue_get(mqdes, FREAD, &mq);
643 getnanotime(&mq->mq_atime);
644 mqattr = &mq->mq_attrib;
672 error = cv_timedwait_sig(&mq->mq_send_cv, &mq->mq_mtx, t);
684 msg = TAILQ_FIRST(&mq->mq_head[MQ_PQRESQ]);
686 idx = ffs(mq->mq_bitmap);
687 msg = TAILQ_FIRST(&mq->mq_head[idx]);
692 TAILQ_REMOVE(&mq->mq_head[idx], msg, msg_queue);
695 if (__predict_true(idx) && TAILQ_EMPTY(&mq->mq_head[idx])) {
697 mq->mq_bitmap &= ~(1U << --idx);
702 cv_signal(&mq->mq_recv_cv);
705 selnotify(&mq->mq_wsel, POLLOUT | POLLWRNORM, 0);
707 mutex_exit(&mq->mq_mtx);
787 struct mqueue *mq;
821 error = mqueue_get(mqdes, FWRITE, &mq);
826 getnanotime(&mq->mq_mtime);
827 mqattr = &mq->mq_attrib;
851 error = cv_timedwait_sig(&mq->mq_recv_cv, &mq->mq_mtx, t);
867 TAILQ_INSERT_TAIL(&mq->mq_head[idx], msg, msg_queue);
868 mq->mq_bitmap |= (1U << --idx);
870 mqueue_linear_insert(mq, msg);
874 if (mqattr->mq_curmsgs == 0 && mq->mq_notify_proc &&
876 mq->mq_sig_notify.sigev_notify == SIGEV_SIGNAL) {
879 ksi.ksi_signo = mq->mq_sig_notify.sigev_signo;
881 ksi.ksi_value = mq->mq_sig_notify.sigev_value;
883 notify = mq->mq_notify_proc;
884 mq->mq_notify_proc = NULL;
889 cv_signal(&mq->mq_send_cv);
892 selnotify(&mq->mq_rsel, POLLIN | POLLRDNORM, 0);
894 mutex_exit(&mq->mq_mtx);
959 struct mqueue *mq;
974 error = mqueue_get(SCARG(uap, mqdes), 0, &mq);
980 if (mq->mq_notify_proc == NULL) {
981 memcpy(&mq->mq_sig_notify, &sig,
983 mq->mq_notify_proc = l->l_proc;
990 mq->mq_notify_proc = NULL;
992 mutex_exit(&mq->mq_mtx);
1006 struct mqueue *mq;
1010 error = mqueue_get(SCARG(uap, mqdes), 0, &mq);
1014 memcpy(&attr, &mq->mq_attrib, sizeof(struct mq_attr));
1015 mutex_exit(&mq->mq_mtx);
1030 struct mqueue *mq;
1039 error = mqueue_get(SCARG(uap, mqdes), 0, &mq);
1046 memcpy(&attr, &mq->mq_attrib, sizeof(struct mq_attr));
1051 mq->mq_attrib.mq_flags |= O_NONBLOCK;
1053 mq->mq_attrib.mq_flags &= ~O_NONBLOCK;
1055 mutex_exit(&mq->mq_mtx);
1077 mqueue_t *mq;
1090 mq = mqueue_lookup(name);
1091 if (mq == NULL) {
1095 KASSERT(mutex_owned(&mq->mq_mtx));
1098 if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MQUEUE, 0, mq,
1100 mutex_exit(&mq->mq_mtx);
1106 LIST_REMOVE(mq, mq_list);
1107 refcnt = mq->mq_refcnt;
1110 mq->mq_attrib.mq_flags |= MQ_UNLINKED;
1114 cv_broadcast(&mq->mq_send_cv);
1115 cv_broadcast(&mq->mq_recv_cv);
1117 selnotify(&mq->mq_rsel, POLLHUP, 0);
1118 selnotify(&mq->mq_wsel, POLLHUP, 0);
1120 mutex_exit(&mq->mq_mtx);
1128 mqueue_destroy(mq);
1203 struct mqueue *mq;
1209 LIST_FOREACH(mq, &mqueue_head, mq_list) {
1211 mq->mq_name, mq, mq->mq_mode,
1212 mq->mq_attrib.mq_flags, mq->mq_refcnt,
1213 mq->mq_attrib.mq_maxmsg, mq->mq_attrib.mq_msgsize,
1214 mq->mq_attrib.mq_curmsgs);