md_notify.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef lint
static char _depends_on[] = "drv/md";
#endif
extern void sigintr();
extern void sigunintr();
extern int md_status;
extern md_event_queue_t *md_event_queue;
static void md_reaper();
extern void md_clear_named_service();
/* event handler stuff */
int md_reap = 0;
int md_max_notify_queue = 512;
int md_reap_off = 0; /* non-zero turns off reap */
/* don't allow module to be unloaded until all pending ops are complete */
int global_lock_wait_cnt = 0;
static int
{
/*
* if there is something waiting on it and the
* process continue on to clean this up later.
*/
if (queue->mdn_waiting)
return (1);
/*
* this pid no longer exists blow it away
* first remove any entries, then unlink it and lastly
* free it.
*/
while (element) {
}
return (0);
}
static void
{
if (!md_event_queue)
return;
} else
continue;
}
} else {
}
if (queue->mdn_waiting)
}
md_reap++;
if (md_reap > md_reap_count)
md_reaper();
}
static void
{
return;
while (next) {
/* check for long term event queue */
continue;
}
/* check to see if the pid is still alive */
/* see if queue is a "marked queue" if so destroy */
continue;
}
/* yeeeha blow this one away */
/*
* if there is something waiting on it and the
* process continue on to clean this up later.
*/
if (md_flush_queue(present)) {
continue;
}
/* remove the entry */
else
}
md_reap = 0;
}
/* ARGSUSED */
static int
{
int i;
switch (cmd) {
case MD_HALT_CLOSE:
case MD_HALT_OPEN:
case MD_HALT_DOIT:
case MD_HALT_CHECK:
return (0);
case MD_HALT_UNLOAD:
if (setno != MD_LOCAL_SET)
return (1);
if (md_event_queue == NULL) {
return (0);
}
for (i = 0; i < MD_NOTIFY_HALT_TRIES; i++) {
if (queue->mdn_waiting == 0) {
continue;
}
}
}
if (md_flush_queue(queue)) {
return (1);
}
queue_free = queue;
}
return (0);
default:
return (1);
}
}
static md_event_queue_t *
{
if (lock)
while (event_q) {
continue;
}
break;
}
if (lock)
return ((md_event_queue_t *)event_q);
}
static intptr_t
{
switch (cmd) {
case EQ_PUT:
break;
default:
return (-1);
}
return (0);
}
static int
int mode)
{
int err;
return (err);
}
/*
* md_wait_for_event:
* IOLOCK_RETURN which drops the md_ioctl_lock is called in this
* routine to enable other mdioctls to enter the kernel while this
* thread of execution waits on an event. When that event occurs, the
* stopped thread wakes and continues and md_ioctl_lock must be
* reacquired. Even though md_ioctl_lock is interruptable, we choose
* to ignore EINTR. Returning w/o acquiring md_ioctl_lock is
* catastrophic since it breaks down ioctl single threading.
*
* Return: 0 md_eventq_mx held
* EINTR md_eventq_mx no held
* Always returns with IOCTL lock held
*/
static int
{
int rval = 0;
(void) IOLOCK_RETURN(0, lockp);
/* reenable single threading of ioctls */
while (md_ioctl_lock_enter() == EINTR);
(void) notify_fillin_empty_ioctl
return (EINTR);
}
/*
* reacquire single threading ioctls. Drop eventq_mutex
* since md_ioctl_lock_enter can sleep.
*/
while (md_ioctl_lock_enter() == EINTR);
}
return (0);
}
/* ARGSUSED */
static int
{
int cmd;
char *q_name;
int err = 0;
goto out;
}
goto out;
}
goto out;
}
md_reaper();
(void) notify_fillin_empty_ioctl
goto out;
}
}
switch (cmd) {
case EQ_ON:
md_reaper();
break;
}
/* allocate and initialize queue head */
event_queue = (md_event_queue_t *)
if (event_queue == NULL) {
break;
}
event_queue->mdn_flags = 0;
event_queue->mdn_size = 0;
event_queue->mdn_waiting = 0;
credp = ddi_get_cred();
/* link into the list of event queues */
if (md_event_queue != NULL)
err = 0;
break;
case EQ_OFF:
if (md_event_queue == NULL)
return (ENOENT);
event_queue->mdn_pid = 0;
if (event_queue->mdn_waiting != 0)
/*
* force the reaper to delete this when it has no process
* waiting on it.
*/
md_reaper();
err = 0;
break;
case EQ_GET_NOWAIT:
case EQ_GET_WAIT:
if (cmd == EQ_GET_WAIT) {
goto out;
}
if (event_queue->mdn_flags &
event_queue->mdn_flags &=
if (err)
goto out;
}
event_queue->mdn_size--;
if (err)
goto out;
} else { /* no elements on queue */
if (err)
}
if (cmd == EQ_GET_NOWAIT)
goto out;
case EQ_PUT:
if (!md_event_queue) {
break;
}
err = 0;
goto out;
default:
goto out;
}
out:
return (err);
}
/*
* Turn orphaned queue off for testing purposes.
*/
static intptr_t
{
md_reap_off = 1;
return (0);
}
/*
* Turn reaping back on.
*/
static intptr_t
{
md_reap_off = 0;
return (0);
}
/*
* Return information that is used to test the notification feature.
*/
static intptr_t
{
return (0);
}
/*
* put this stuff at end so we don't have to create forward
* references for everything
*/
"Solaris Volume Manager notification module %I%"
};
static struct modlinkage modlinkage = {
};
static md_named_services_t notify_services[] = {
{notify_interface, "notify interface"},
{NULL, 0}
};
md_ops_t event_md_ops = {
NULL, /* open */
NULL, /* close */
NULL, /* strategy */
NULL, /* print */
NULL, /* dump */
NULL, /* read */
NULL, /* write */
notify_ioctl, /* event_ioctls, */
NULL, /* snarf */
notify_halt, /* halt */
NULL, /* aread */
NULL, /* awrite */
NULL, /* import set */
notify_services /* named_services */
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
int err = 0;
/*
* Don't allow the module to be unloaded while there is a thread
* of execution that is waiting for a global lock.
*/
if (global_lock_wait_cnt > 0)
return (EBUSY);
return (err);
return (err);
}
int
{
}