2002-03-11 21:42:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: How do we in general know that objects referenced in events
|
|
|
|
* have not been destroyed before we get around to handle the event ?
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:49:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2004-10-23 20:49:17 +00:00
|
|
|
#include <sys/proc.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <geom/geom.h>
|
2002-03-26 22:07:38 +00:00
|
|
|
#include <geom/geom_int.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2004-10-23 20:49:17 +00:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
2003-04-23 20:54:42 +00:00
|
|
|
TAILQ_HEAD(event_tailq_head, g_event);
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
static struct event_tailq_head g_events = TAILQ_HEAD_INITIALIZER(g_events);
|
2003-01-13 08:46:32 +00:00
|
|
|
static u_int g_pending_events;
|
2002-03-11 21:42:35 +00:00
|
|
|
static TAILQ_HEAD(,g_provider) g_doorstep = TAILQ_HEAD_INITIALIZER(g_doorstep);
|
2002-09-27 20:18:16 +00:00
|
|
|
static struct mtx g_eventlock;
|
2004-07-08 16:17:14 +00:00
|
|
|
static int g_wither_work;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2003-04-23 20:54:42 +00:00
|
|
|
#define G_N_EVENTREFS 20
|
|
|
|
|
|
|
|
struct g_event {
|
|
|
|
TAILQ_ENTRY(g_event) events;
|
|
|
|
g_event_t *func;
|
2003-04-23 21:28:27 +00:00
|
|
|
void *arg;
|
|
|
|
int flag;
|
2003-04-23 20:54:42 +00:00
|
|
|
void *ref[G_N_EVENTREFS];
|
|
|
|
};
|
|
|
|
|
2003-04-23 21:28:27 +00:00
|
|
|
#define EV_DONE 0x80000
|
|
|
|
#define EV_WAKEUP 0x40000
|
2003-05-01 19:43:52 +00:00
|
|
|
#define EV_CANCELED 0x20000
|
2010-06-08 22:40:02 +00:00
|
|
|
#define EV_INPROGRESS 0x10000
|
2003-04-23 21:28:27 +00:00
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
void
|
2002-06-09 10:57:34 +00:00
|
|
|
g_waitidle(void)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
|
2004-10-23 20:49:17 +00:00
|
|
|
g_topology_assert_not();
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
|
2005-09-04 19:14:19 +00:00
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
while (!TAILQ_EMPTY(&g_events))
|
|
|
|
msleep(&g_pending_events, &g_eventlock, PPAUSE,
|
|
|
|
"g_waitidle", hz/5);
|
|
|
|
mtx_unlock(&g_eventlock);
|
2004-10-23 20:49:17 +00:00
|
|
|
curthread->td_pflags &= ~TDP_GEOM;
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
2005-09-04 19:14:19 +00:00
|
|
|
#if 0
|
2004-11-09 23:20:50 +00:00
|
|
|
void
|
|
|
|
g_waitidlelock(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
g_topology_assert();
|
2005-09-04 19:14:19 +00:00
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
while (!TAILQ_EMPTY(&g_events)) {
|
2004-11-09 23:20:50 +00:00
|
|
|
g_topology_unlock();
|
2005-09-04 19:14:19 +00:00
|
|
|
msleep(&g_pending_events, &g_eventlock, PPAUSE,
|
|
|
|
"g_waitidlel", hz/5);
|
2004-11-09 23:20:50 +00:00
|
|
|
g_topology_lock();
|
|
|
|
}
|
2005-09-04 19:14:19 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2004-11-09 23:20:50 +00:00
|
|
|
}
|
2005-09-04 19:14:19 +00:00
|
|
|
#endif
|
2004-11-09 23:20:50 +00:00
|
|
|
|
Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility.
Extend GEOM's generic attribute query mechanism into generic disk consumers.
sys/geom/geom_disk.c:
sys/geom/geom_disk.h:
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Allow disk providers to implement a new method which can override
the default BIO_GETATTR response, d_getattr(struct bio *). This
function returns -1 if not handled, otherwise it returns 0 or an
errno to be passed to g_io_deliver().
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Don't copy the serial number to dp->d_ident anymore, as the CAM XPT
is now responsible for returning this information via
d_getattr()->(a)dagetattr()->xpt_getatr().
sys/geom/geom_dev.c:
- Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM
attribute "GEOM::physpath", if possible. If the attribute request
returns a zero-length string, ENOENT is returned.
usr.sbin/diskinfo/diskinfo.c:
- If the DIOCGPHYSPATH ioctl is successful, report physical path
data when diskinfo is executed with the '-v' option.
Submitted by: will
Reviewed by: gibbs
Sponsored by: Spectra Logic Corporation
Add generic attribute change notification support to GEOM.
sys/sys/geom/geom.h:
Add a new attrchanged method field to both g_class
and g_geom.
sys/sys/geom/geom.h:
sys/geom/geom_event.c:
- Provide the g_attr_changed() function that providers
can use to advertise attribute changes.
- Perform delivery of attribute change notifications
from a thread context via the standard GEOM event
mechanism.
sys/geom/geom_subr.c:
Inherit the attrchanged method from class to geom (class instance).
sys/geom/geom_disk.c:
Provide disk_attr_changed() to provide g_attr_changed() access
to consumers of the disk API.
sys/cam/scsi/scsi_pass.c:
sys/cam/scsi/scsi_da.c:
sys/geom/geom_dev.c:
sys/geom/geom_disk.c:
Use attribute changed events to track updates to physical path
information.
sys/cam/scsi/scsi_da.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, and
the updated buffer type references our physical path
attribute, emit a GEOM attribute changed event via the
disk_attr_changed() API.
sys/cam/scsi/scsi_pass.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, update
the physical patch devfs alias for this pass instance.
Submitted by: gibbs
Sponsored by: Spectra Logic Corporation
2011-06-14 17:10:32 +00:00
|
|
|
struct g_attrchanged_args {
|
|
|
|
struct g_provider *pp;
|
|
|
|
const char *attr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_attr_changed_event(void *arg, int flag)
|
|
|
|
{
|
|
|
|
struct g_attrchanged_args *args;
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_consumer *next_cp;
|
|
|
|
|
|
|
|
args = arg;
|
|
|
|
pp = args->pp;
|
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
if (flag != EV_CANCEL && g_shutdown == 0) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell all consumers of the change.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH_SAFE(cp, &pp->consumers, consumers, next_cp) {
|
|
|
|
if (cp->geom->attrchanged != NULL)
|
|
|
|
cp->geom->attrchanged(cp, args->attr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
g_attr_changed(struct g_provider *pp, const char *attr, int flag)
|
|
|
|
{
|
|
|
|
struct g_attrchanged_args *args;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
args = g_malloc(sizeof *args, flag);
|
|
|
|
if (args == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
args->pp = pp;
|
|
|
|
args->attr = attr;
|
|
|
|
error = g_post_event(g_attr_changed_event, args, flag, pp, NULL);
|
|
|
|
if (error != 0)
|
|
|
|
g_free(args);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
void
|
|
|
|
g_orphan_provider(struct g_provider *pp, int error)
|
|
|
|
{
|
|
|
|
|
2004-03-10 08:49:08 +00:00
|
|
|
/* G_VALID_PROVIDER(pp) We likely lack topology lock */
|
2002-03-11 21:42:35 +00:00
|
|
|
g_trace(G_T_TOPOLOGY, "g_orphan_provider(%p(%s), %d)",
|
|
|
|
pp, pp->name, error);
|
|
|
|
KASSERT(error != 0,
|
|
|
|
("g_orphan_provider(%p(%s), 0) error must be non-zero\n",
|
|
|
|
pp, pp->name));
|
2003-12-07 10:04:43 +00:00
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
pp->error = error;
|
2002-09-27 20:18:16 +00:00
|
|
|
mtx_lock(&g_eventlock);
|
2003-12-07 10:04:43 +00:00
|
|
|
KASSERT(!(pp->flags & G_PF_ORPHAN),
|
|
|
|
("g_orphan_provider(%p(%s)), already an orphan", pp, pp->name));
|
|
|
|
pp->flags |= G_PF_ORPHAN;
|
2002-03-11 21:42:35 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_doorstep, pp, orphan);
|
2002-09-27 20:18:16 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2002-03-11 21:42:35 +00:00
|
|
|
wakeup(&g_wait_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called once on each provider which the event handler
|
|
|
|
* finds on its g_doorstep.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2002-03-26 22:07:38 +00:00
|
|
|
g_orphan_register(struct g_provider *pp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_consumer *cp, *cp2;
|
2003-12-23 11:37:05 +00:00
|
|
|
int wf;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
2004-03-10 08:49:08 +00:00
|
|
|
G_VALID_PROVIDER(pp);
|
|
|
|
g_trace(G_T_TOPOLOGY, "g_orphan_register(%s)", pp->name);
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2007-09-27 20:18:34 +00:00
|
|
|
g_cancel_event(pp);
|
|
|
|
|
2003-12-23 11:37:05 +00:00
|
|
|
wf = pp->flags & G_PF_WITHER;
|
|
|
|
pp->flags &= ~G_PF_WITHER;
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
/*
|
|
|
|
* Tell all consumers the bad news.
|
2003-03-09 10:02:31 +00:00
|
|
|
* Don't be surprised if they self-destruct.
|
2002-03-11 21:42:35 +00:00
|
|
|
*/
|
|
|
|
cp = LIST_FIRST(&pp->consumers);
|
|
|
|
while (cp != NULL) {
|
|
|
|
cp2 = LIST_NEXT(cp, consumers);
|
2002-04-04 09:54:13 +00:00
|
|
|
KASSERT(cp->geom->orphan != NULL,
|
|
|
|
("geom %s has no orphan, class %s",
|
|
|
|
cp->geom->name, cp->geom->class->name));
|
|
|
|
cp->geom->orphan(cp);
|
2002-03-11 21:42:35 +00:00
|
|
|
cp = cp2;
|
|
|
|
}
|
2003-12-23 11:37:05 +00:00
|
|
|
if (LIST_EMPTY(&pp->consumers) && wf)
|
2003-10-12 11:34:35 +00:00
|
|
|
g_destroy_provider(pp);
|
2003-12-23 11:37:05 +00:00
|
|
|
else
|
|
|
|
pp->flags |= wf;
|
2003-03-16 16:29:04 +00:00
|
|
|
#ifdef notyet
|
2003-03-10 23:41:41 +00:00
|
|
|
cp = LIST_FIRST(&pp->consumers);
|
|
|
|
if (cp != NULL)
|
|
|
|
return;
|
|
|
|
if (pp->geom->flags & G_GEOM_WITHER)
|
|
|
|
g_destroy_provider(pp);
|
2003-03-16 16:29:04 +00:00
|
|
|
#endif
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-26 22:07:38 +00:00
|
|
|
one_event(void)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_event *ep;
|
|
|
|
struct g_provider *pp;
|
|
|
|
|
2010-11-22 16:47:53 +00:00
|
|
|
g_topology_assert();
|
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
TAILQ_FOREACH(pp, &g_doorstep, orphan) {
|
|
|
|
if (pp->nstart == pp->nend)
|
2002-03-11 21:42:35 +00:00
|
|
|
break;
|
2010-11-22 16:47:53 +00:00
|
|
|
}
|
|
|
|
if (pp != NULL) {
|
|
|
|
G_VALID_PROVIDER(pp);
|
|
|
|
TAILQ_REMOVE(&g_doorstep, pp, orphan);
|
|
|
|
mtx_unlock(&g_eventlock);
|
2002-03-26 22:07:38 +00:00
|
|
|
g_orphan_register(pp);
|
2010-11-22 16:47:53 +00:00
|
|
|
return (1);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2010-11-22 16:47:53 +00:00
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
ep = TAILQ_FIRST(&g_events);
|
|
|
|
if (ep == NULL) {
|
2005-09-04 19:14:19 +00:00
|
|
|
wakeup(&g_pending_events);
|
2002-03-11 21:42:35 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-06-08 22:40:02 +00:00
|
|
|
if (ep->flag & EV_INPROGRESS) {
|
|
|
|
mtx_unlock(&g_eventlock);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
ep->flag |= EV_INPROGRESS;
|
2002-09-27 20:38:36 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2003-04-23 20:25:33 +00:00
|
|
|
g_topology_assert();
|
|
|
|
ep->func(ep->arg, 0);
|
|
|
|
g_topology_assert();
|
2005-09-04 19:14:19 +00:00
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
TAILQ_REMOVE(&g_events, ep, events);
|
2010-06-08 22:40:02 +00:00
|
|
|
ep->flag &= ~EV_INPROGRESS;
|
2003-04-23 21:28:27 +00:00
|
|
|
if (ep->flag & EV_WAKEUP) {
|
|
|
|
ep->flag |= EV_DONE;
|
2010-11-03 16:19:35 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2003-04-23 21:28:27 +00:00
|
|
|
wakeup(ep);
|
|
|
|
} else {
|
2010-11-03 16:19:35 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2003-05-02 05:26:19 +00:00
|
|
|
g_free(ep);
|
2003-04-23 21:28:27 +00:00
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-26 22:07:38 +00:00
|
|
|
g_run_events()
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
2004-07-08 16:17:14 +00:00
|
|
|
int i;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2010-11-22 16:47:53 +00:00
|
|
|
for (;;) {
|
|
|
|
g_topology_lock();
|
|
|
|
while (one_event())
|
|
|
|
;
|
|
|
|
mtx_assert(&g_eventlock, MA_OWNED);
|
|
|
|
i = g_wither_work;
|
|
|
|
if (i) {
|
|
|
|
mtx_unlock(&g_eventlock);
|
|
|
|
while (i) {
|
|
|
|
i = g_wither_washer();
|
|
|
|
g_wither_work = i & 1;
|
|
|
|
i &= 2;
|
|
|
|
}
|
|
|
|
g_topology_unlock();
|
|
|
|
} else {
|
|
|
|
g_topology_unlock();
|
|
|
|
msleep(&g_wait_event, &g_eventlock, PRIBIO | PDROP,
|
2011-11-01 08:57:49 +00:00
|
|
|
"-", TAILQ_EMPTY(&g_doorstep) ? 0 : hz / 10);
|
2010-11-22 16:47:53 +00:00
|
|
|
}
|
2004-07-08 16:17:14 +00:00
|
|
|
}
|
2010-11-22 16:47:53 +00:00
|
|
|
/* NOTREACHED */
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 23:01:40 +00:00
|
|
|
void
|
2003-04-02 20:41:18 +00:00
|
|
|
g_cancel_event(void *ref)
|
2003-03-23 23:01:40 +00:00
|
|
|
{
|
|
|
|
struct g_event *ep, *epn;
|
2003-05-01 19:24:00 +00:00
|
|
|
struct g_provider *pp;
|
2003-04-02 20:41:18 +00:00
|
|
|
u_int n;
|
2003-03-23 23:01:40 +00:00
|
|
|
|
|
|
|
mtx_lock(&g_eventlock);
|
2003-05-01 19:24:00 +00:00
|
|
|
TAILQ_FOREACH(pp, &g_doorstep, orphan) {
|
|
|
|
if (pp != ref)
|
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&g_doorstep, pp, orphan);
|
|
|
|
break;
|
|
|
|
}
|
2005-09-04 19:14:19 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ep, &g_events, events, epn) {
|
2010-06-08 22:40:02 +00:00
|
|
|
if (ep->flag & EV_INPROGRESS)
|
|
|
|
continue;
|
2003-04-02 20:41:18 +00:00
|
|
|
for (n = 0; n < G_N_EVENTREFS; n++) {
|
|
|
|
if (ep->ref[n] == NULL)
|
|
|
|
break;
|
2005-09-04 19:14:19 +00:00
|
|
|
if (ep->ref[n] != ref)
|
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&g_events, ep, events);
|
|
|
|
ep->func(ep->arg, EV_CANCEL);
|
|
|
|
mtx_assert(&g_eventlock, MA_OWNED);
|
|
|
|
if (ep->flag & EV_WAKEUP) {
|
|
|
|
ep->flag |= (EV_DONE|EV_CANCELED);
|
|
|
|
wakeup(ep);
|
|
|
|
} else {
|
|
|
|
g_free(ep);
|
2003-04-02 20:41:18 +00:00
|
|
|
}
|
2005-09-04 19:14:19 +00:00
|
|
|
break;
|
2003-03-23 23:01:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-09-04 19:14:19 +00:00
|
|
|
if (TAILQ_EMPTY(&g_events))
|
|
|
|
wakeup(&g_pending_events);
|
2003-03-23 23:01:40 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
|
|
|
}
|
|
|
|
|
2003-04-23 21:28:27 +00:00
|
|
|
static int
|
2004-02-02 10:58:07 +00:00
|
|
|
g_post_event_x(g_event_t *func, void *arg, int flag, int wuflag, struct g_event **epp, va_list ap)
|
2002-09-27 20:38:36 +00:00
|
|
|
{
|
|
|
|
struct g_event *ep;
|
2003-04-02 20:41:18 +00:00
|
|
|
void *p;
|
|
|
|
u_int n;
|
2002-09-27 20:38:36 +00:00
|
|
|
|
2004-02-02 10:58:07 +00:00
|
|
|
g_trace(G_T_TOPOLOGY, "g_post_event_x(%p, %p, %d, %d)",
|
2005-05-18 21:53:08 +00:00
|
|
|
func, arg, flag, wuflag);
|
2004-02-02 10:58:07 +00:00
|
|
|
KASSERT(wuflag == 0 || wuflag == EV_WAKEUP,
|
|
|
|
("Wrong wuflag in g_post_event_x(0x%x)", wuflag));
|
2003-04-23 20:46:12 +00:00
|
|
|
ep = g_malloc(sizeof *ep, flag | M_ZERO);
|
2002-09-27 20:38:36 +00:00
|
|
|
if (ep == NULL)
|
|
|
|
return (ENOMEM);
|
2004-02-02 10:58:07 +00:00
|
|
|
ep->flag = wuflag;
|
2003-04-02 20:41:18 +00:00
|
|
|
for (n = 0; n < G_N_EVENTREFS; n++) {
|
|
|
|
p = va_arg(ap, void *);
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
|
|
|
g_trace(G_T_TOPOLOGY, " ref %p", p);
|
2003-11-18 07:54:12 +00:00
|
|
|
ep->ref[n] = p;
|
2003-04-02 20:41:18 +00:00
|
|
|
}
|
|
|
|
KASSERT(p == NULL, ("Too many references to event"));
|
2002-09-27 20:38:36 +00:00
|
|
|
ep->func = func;
|
|
|
|
ep->arg = arg;
|
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
TAILQ_INSERT_TAIL(&g_events, ep, events);
|
|
|
|
mtx_unlock(&g_eventlock);
|
2002-03-11 21:42:35 +00:00
|
|
|
wakeup(&g_wait_event);
|
2003-04-23 21:28:27 +00:00
|
|
|
if (epp != NULL)
|
|
|
|
*epp = ep;
|
2004-10-23 20:49:17 +00:00
|
|
|
curthread->td_pflags |= TDP_GEOM;
|
2003-04-23 21:28:27 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
g_post_event(g_event_t *func, void *arg, int flag, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2003-06-07 10:16:53 +00:00
|
|
|
int i;
|
2003-04-23 21:28:27 +00:00
|
|
|
|
|
|
|
KASSERT(flag == M_WAITOK || flag == M_NOWAIT,
|
|
|
|
("Wrong flag to g_post_event"));
|
2003-06-07 10:16:53 +00:00
|
|
|
va_start(ap, flag);
|
2004-02-02 10:58:07 +00:00
|
|
|
i = g_post_event_x(func, arg, flag, 0, NULL, ap);
|
2003-06-07 10:16:53 +00:00
|
|
|
va_end(ap);
|
|
|
|
return (i);
|
2003-04-23 21:28:27 +00:00
|
|
|
}
|
|
|
|
|
2004-07-08 16:17:14 +00:00
|
|
|
void
|
2010-11-22 16:47:53 +00:00
|
|
|
g_do_wither()
|
|
|
|
{
|
2004-07-08 16:17:14 +00:00
|
|
|
|
2010-11-22 16:47:53 +00:00
|
|
|
mtx_lock(&g_eventlock);
|
2004-07-08 16:17:14 +00:00
|
|
|
g_wither_work = 1;
|
2010-11-22 16:47:53 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
2004-07-08 16:17:14 +00:00
|
|
|
wakeup(&g_wait_event);
|
|
|
|
}
|
2003-04-23 21:28:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: It might actually be useful to call this function with topology held.
|
|
|
|
* XXX: This would ensure that the event gets created before anything else
|
|
|
|
* XXX: changes. At present all users have a handle on things in some other
|
|
|
|
* XXX: way, so this remains an XXX for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
g_waitfor_event(g_event_t *func, void *arg, int flag, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct g_event *ep;
|
|
|
|
int error;
|
|
|
|
|
2004-02-10 15:55:17 +00:00
|
|
|
g_topology_assert_not();
|
2003-04-23 21:28:27 +00:00
|
|
|
KASSERT(flag == M_WAITOK || flag == M_NOWAIT,
|
|
|
|
("Wrong flag to g_post_event"));
|
2003-06-07 10:16:53 +00:00
|
|
|
va_start(ap, flag);
|
2004-02-02 10:58:07 +00:00
|
|
|
error = g_post_event_x(func, arg, flag, EV_WAKEUP, &ep, ap);
|
2003-06-07 10:16:53 +00:00
|
|
|
va_end(ap);
|
2003-04-23 21:28:27 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2010-11-03 16:19:35 +00:00
|
|
|
|
|
|
|
mtx_lock(&g_eventlock);
|
|
|
|
while (!(ep->flag & EV_DONE))
|
|
|
|
msleep(ep, &g_eventlock, PRIBIO, "g_waitfor_event", hz);
|
2003-05-01 19:43:52 +00:00
|
|
|
if (ep->flag & EV_CANCELED)
|
|
|
|
error = EAGAIN;
|
2010-11-03 16:19:35 +00:00
|
|
|
mtx_unlock(&g_eventlock);
|
|
|
|
|
2003-05-02 05:26:19 +00:00
|
|
|
g_free(ep);
|
2003-05-01 19:43:52 +00:00
|
|
|
return (error);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_event_init()
|
|
|
|
{
|
|
|
|
|
2002-09-27 20:18:16 +00:00
|
|
|
mtx_init(&g_eventlock, "GEOM orphanage", NULL, MTX_DEF);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|