Make POSIX message queues a kernel module.

This commit is contained in:
rmind 2009-07-19 02:50:44 +00:00
parent 029f6c41a7
commit 7512d1e720
10 changed files with 127 additions and 32 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: module.mi,v 1.9 2009/07/18 21:32:52 reinoud Exp $
# $NetBSD: module.mi,v 1.10 2009/07/19 02:50:44 rmind Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -57,6 +57,8 @@
./@MODULEDIR@/mfs/mfs.kmod base-kernel-modules
./@MODULEDIR@/miniroot base-kernel-modules
./@MODULEDIR@/miniroot/miniroot.kmod base-kernel-modules
./@MODULEDIR@/mqueue base-kernel-modules
./@MODULEDIR@/mqueue/mqueue.kmod base-kernel-modules
./@MODULEDIR@/msdos base-kernel-modules
./@MODULEDIR@/msdos/msdos.kmod base-kernel-modules
./@MODULEDIR@/nfs base-kernel-modules

View File

@ -1,4 +1,4 @@
# $NetBSD: GENERIC,v 1.935 2009/07/18 16:31:42 reinoud Exp $
# $NetBSD: GENERIC,v 1.936 2009/07/19 02:50:44 rmind Exp $
#
# GENERIC machine description file
#
@ -22,7 +22,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
#ident "GENERIC-$Revision: 1.935 $"
#ident "GENERIC-$Revision: 1.936 $"
maxusers 64 # estimated number of users
@ -97,7 +97,8 @@ options SYSVMSG # System V-like message queues
options SYSVSEM # System V-like semaphores
options SYSVSHM # System V-like memory sharing
#options P1003_1B_SEMAPHORE # p1003.1b semaphore support
no options AIO # POSIX AIO, built as a module
no options AIO # POSIX asynchronous I/O, built as a module
no options MQUEUE # POSIX messsage queues, built as a module
options MODULAR # new style module framework

View File

@ -11,7 +11,8 @@ options EXEC_SCRIPT # exec #! scripts
options COREDUMP
options P1003_1B_SEMAPHORE # p1003.1b semaphore support
options AIO # POSIX AIO, built as a module
options AIO # POSIX asynchronous I/O, built as a module
options MQUEUE # POSIX messsage queues, built as a module
options COMPAT_OSSAUDIO # OSS (Voxware) audio driver compatibility
options COMPAT_SVR4 # binary compatibility with SVR4

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.392 2009/07/17 23:31:51 ad Exp $ */
/* $NetBSD: init_main.c,v 1.393 2009/07/19 02:50:44 rmind Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.392 2009/07/17 23:31:51 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.393 2009/07/19 02:50:44 rmind Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@ -159,7 +159,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.392 2009/07/17 23:31:51 ad Exp $");
#include <sys/uuid.h>
#include <sys/extent.h>
#include <sys/disk.h>
#include <sys/mqueue.h>
#include <sys/msgbuf.h>
#include <sys/module.h>
#include <sys/event.h>
@ -430,9 +429,6 @@ main(void)
/* Initialize kqueue. */
kqueue_init();
/* Initialize message queues. */
mqueue_sysinit();
/* Initialize the system monitor subsystems. */
#if NSYSMON_TASKQ > 0
sysmon_task_queue_preinit();

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_stub.c,v 1.18 2009/02/13 22:41:04 apb Exp $ */
/* $NetBSD: kern_stub.c,v 1.19 2009/07/19 02:50:44 rmind Exp $ */
/*-
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.18 2009/02/13 22:41:04 apb Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_stub.c,v 1.19 2009/07/19 02:50:44 rmind Exp $");
#include "opt_ptrace.h"
#include "opt_ktrace.h"
@ -205,6 +205,16 @@ sys_nomodule(struct lwp *l, const void *v, register_t *retval)
{ SYS___aio_suspend50, "aio" },
{ SYS_aio_write, "aio" },
{ SYS_lio_listio, "aio" },
{ SYS_mq_open, "mqueue" },
{ SYS_mq_close, "mqueue" },
{ SYS_mq_unlink, "mqueue" },
{ SYS_mq_getattr, "mqueue" },
{ SYS_mq_setattr, "mqueue" },
{ SYS_mq_notify, "mqueue" },
{ SYS_mq_send, "mqueue" },
{ SYS_mq_receive, "mqueue" },
{ SYS___mq_timedsend50, "mqueue" },
{ SYS___mq_timedreceive50, "mqueue" },
{ SYS_compat_43_fstat43, "compat" },
{ SYS_compat_43_lstat43, "compat" },
{ SYS_compat_43_oaccept, "compat" },

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_mqueue.c,v 1.23 2009/07/19 02:26:49 rmind Exp $ */
/* $NetBSD: sys_mqueue.c,v 1.24 2009/07/19 02:50:44 rmind Exp $ */
/*
* Copyright (c) 2007-2009 Mindaugas Rasiukevicius <rmind at NetBSD org>
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.23 2009/07/19 02:26:49 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.24 2009/07/19 02:50:44 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.23 2009/07/19 02:26:49 rmind Exp $"
#include <sys/kmem.h>
#include <sys/lwp.h>
#include <sys/mqueue.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/pool.h>
#include <sys/poll.h>
@ -66,16 +67,19 @@ __KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.23 2009/07/19 02:26:49 rmind Exp $"
#include <sys/signalvar.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/syscall.h>
#include <sys/syscallvar.h>
#include <sys/syscallargs.h>
#include <sys/systm.h>
#include <sys/unistd.h>
#include <miscfs/genfs/genfs.h>
MODULE(MODULE_CLASS_MISC, mqueue, NULL);
/* System-wide limits. */
static u_int mq_open_max = MQ_OPEN_MAX;
static u_int mq_prio_max = MQ_PRIO_MAX;
static u_int mq_max_msgsize = 16 * MQ_DEF_MSGSIZE;
static u_int mq_def_maxmsg = 32;
@ -83,6 +87,8 @@ static kmutex_t mqlist_mtx;
static pool_cache_t mqmsg_cache;
static LIST_HEAD(, mqueue) mqueue_head;
static int mqueue_sysinit(void);
static int mqueue_sysfini(bool);
static int mq_poll_fop(file_t *, int);
static int mq_stat_fop(file_t *, struct stat *);
static int mq_close_fop(file_t *);
@ -99,17 +105,86 @@ static const struct fileops mqops = {
.fo_drain = fnullop_drain,
};
static const struct syscall_package mqueue_syscalls[] = {
{ SYS_mq_open, 0, (sy_call_t *)sys_mq_open },
{ SYS_mq_close, 0, (sy_call_t *)sys_mq_close },
{ SYS_mq_unlink, 0, (sy_call_t *)sys_mq_unlink },
{ SYS_mq_getattr, 0, (sy_call_t *)sys_mq_getattr },
{ SYS_mq_setattr, 0, (sy_call_t *)sys_mq_setattr },
{ SYS_mq_notify, 0, (sy_call_t *)sys_mq_notify },
{ SYS_mq_send, 0, (sy_call_t *)sys_mq_send },
{ SYS_mq_receive, 0, (sy_call_t *)sys_mq_receive },
{ SYS___mq_timedsend50, 0, (sy_call_t *)sys___mq_timedsend50 },
{ SYS___mq_timedreceive50, 0, (sy_call_t *)sys___mq_timedreceive50 },
{ 0, 0, NULL }
};
/*
* Initialize POSIX message queue subsystem.
* Initialisation and unloading of POSIX message queue subsystem.
*/
void
static int
mqueue_sysinit(void)
{
int error;
mqmsg_cache = pool_cache_init(MQ_DEF_MSGSIZE, coherency_unit,
0, 0, "mqmsgpl", NULL, IPL_NONE, NULL, NULL, NULL);
mutex_init(&mqlist_mtx, MUTEX_DEFAULT, IPL_NONE);
LIST_INIT(&mqueue_head);
error = syscall_establish(NULL, mqueue_syscalls);
if (error) {
(void)mqueue_sysfini(false);
}
return error;
}
static int
mqueue_sysfini(bool interface)
{
if (interface) {
int error;
bool inuse;
/* Stop syscall activity. */
error = syscall_disestablish(NULL, mqueue_syscalls);
if (error)
return error;
/*
* Check if there are any message queues in use.
* TODO: We shall support forced unload.
*/
mutex_enter(&mqlist_mtx);
inuse = !LIST_EMPTY(&mqueue_head);
mutex_exit(&mqlist_mtx);
if (inuse) {
error = syscall_establish(NULL, mqueue_syscalls);
KASSERT(error == 0);
return EBUSY;
}
}
mutex_destroy(&mqlist_mtx);
pool_cache_destroy(mqmsg_cache);
return 0;
}
/*
* Module interface.
*/
static int
mqueue_modcmd(modcmd_t cmd, void *arg)
{
switch (cmd) {
case MODULE_CMD_INIT:
return mqueue_sysinit();
case MODULE_CMD_FINI:
return mqueue_sysfini(true);
default:
return ENOTTY;
}
}
/*

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.227 2009/05/15 15:51:27 pooka Exp $
$NetBSD: syscalls.master,v 1.228 2009/07/19 02:50:44 rmind Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@ -501,20 +501,20 @@
unsigned int *value); }
255 STD MODULAR { int|sys||_ksem_destroy(intptr_t id); }
256 UNIMPL sys__ksem_timedwait
257 STD { mqd_t|sys||mq_open(const char * name, int oflag, \
257 STD MODULAR { mqd_t|sys||mq_open(const char * name, int oflag, \
mode_t mode, struct mq_attr *attr); }
258 STD { int|sys||mq_close(mqd_t mqdes); }
259 STD { int|sys||mq_unlink(const char *name); }
260 STD { int|sys||mq_getattr(mqd_t mqdes, \
258 STD MODULAR { int|sys||mq_close(mqd_t mqdes); }
259 STD MODULAR { int|sys||mq_unlink(const char *name); }
260 STD MODULAR { int|sys||mq_getattr(mqd_t mqdes, \
struct mq_attr *mqstat); }
261 STD { int|sys||mq_setattr(mqd_t mqdes, \
261 STD MODULAR { int|sys||mq_setattr(mqd_t mqdes, \
const struct mq_attr *mqstat, \
struct mq_attr *omqstat); }
262 STD { int|sys||mq_notify(mqd_t mqdes, \
262 STD MODULAR { int|sys||mq_notify(mqd_t mqdes, \
const struct sigevent *notification); }
263 STD { int|sys||mq_send(mqd_t mqdes, const char *msg_ptr, \
263 STD MODULAR { int|sys||mq_send(mqd_t mqdes, const char *msg_ptr, \
size_t msg_len, unsigned msg_prio); }
264 STD { ssize_t|sys||mq_receive(mqd_t mqdes, char *msg_ptr, \
264 STD MODULAR { ssize_t|sys||mq_receive(mqd_t mqdes, char *msg_ptr, \
size_t msg_len, unsigned *msg_prio); }
265 COMPAT_50 MODULAR { int|sys||mq_timedsend(mqd_t mqdes, \
const char *msg_ptr, size_t msg_len, \
@ -835,11 +835,11 @@
431 STD { int|sys|50|__sigtimedwait(const sigset_t *set, \
siginfo_t *info, \
struct timespec *timeout); }
432 STD { int|sys|50|mq_timedsend(mqd_t mqdes, \
432 STD MODULAR { int|sys|50|mq_timedsend(mqd_t mqdes, \
const char *msg_ptr, size_t msg_len, \
unsigned msg_prio, \
const struct timespec *abs_timeout); }
433 STD { ssize_t|sys|50|mq_timedreceive(mqd_t mqdes, \
433 STD MODULAR { ssize_t|sys|50|mq_timedreceive(mqd_t mqdes, \
char *msg_ptr, size_t msg_len, unsigned *msg_prio, \
const struct timespec *abs_timeout); }
434 STD { int|sys|50|_lwp_park(const struct timespec *ts, \

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.30 2009/07/18 16:31:42 reinoud Exp $
# $NetBSD: Makefile,v 1.31 2009/07/19 02:50:44 rmind Exp $
# For all platforms
@ -25,6 +25,7 @@ SUBDIR+= ksem
SUBDIR+= layerfs
SUBDIR+= lfs
SUBDIR+= mfs
SUBDIR+= mqueue
SUBDIR+= msdos
SUBDIR+= nfs
SUBDIR+= nfsserver

View File

@ -0,0 +1,10 @@
# $NetBSD: Makefile,v 1.1 2009/07/19 02:50:44 rmind Exp $
#
.include "../Makefile.inc"
.PATH: ${S}/kern
KMOD= mqueue
SRCS= sys_mqueue.c
.include <bsd.kmodule.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: mqueue.h,v 1.9 2009/07/19 02:26:49 rmind Exp $ */
/* $NetBSD: mqueue.h,v 1.10 2009/07/19 02:50:44 rmind Exp $ */
/*
* Copyright (c) 2007-2009 Mindaugas Rasiukevicius <rmind at NetBSD org>
@ -108,7 +108,6 @@ struct mq_msg {
};
/* Prototypes */
void mqueue_sysinit(void);
void mqueue_print_list(void (*pr)(const char *, ...));
int abstimeout2timo(struct timespec *, int *);
int mq_send1(lwp_t *, mqd_t, const char *, size_t, unsigned, int);