2004-04-30 16:08:12 +00:00
|
|
|
/*-
|
2006-09-08 10:20:44 +00:00
|
|
|
* Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
2010-02-18 23:16:19 +00:00
|
|
|
* Copyright (c) 2009-2010 The FreeBSD Foundation
|
2004-04-30 16:08:12 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2010-02-18 23:16:19 +00:00
|
|
|
* Portions of this software were developed by Pawel Jakub Dawidek
|
|
|
|
* under sponsorship from the FreeBSD Foundation.
|
|
|
|
*
|
2004-04-30 16:08:12 +00:00
|
|
|
* 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.
|
2006-02-01 12:06:01 +00:00
|
|
|
*
|
2004-04-30 16:08:12 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
|
|
|
|
*/
|
|
|
|
|
2006-09-08 10:19:24 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/linker.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <sys/queue.h>
|
2011-07-11 05:22:31 +00:00
|
|
|
#include <sys/sbuf.h>
|
2004-04-30 16:08:12 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <machine/atomic.h>
|
|
|
|
|
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/gate/g_gate.h>
|
|
|
|
|
2011-02-25 10:24:35 +00:00
|
|
|
FEATURE(geom_gate, "GEOM Gate module");
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
static MALLOC_DEFINE(M_GATE, "gg_data", "GEOM Gate Data");
|
2004-04-30 16:08:12 +00:00
|
|
|
|
|
|
|
SYSCTL_DECL(_kern_geom);
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_kern_geom, OID_AUTO, gate, CTLFLAG_RW, 0,
|
2012-07-04 20:16:28 +00:00
|
|
|
"GEOM_GATE configuration");
|
2010-02-18 23:16:19 +00:00
|
|
|
static int g_gate_debug = 0;
|
|
|
|
TUNABLE_INT("kern.geom.gate.debug", &g_gate_debug);
|
|
|
|
SYSCTL_INT(_kern_geom_gate, OID_AUTO, debug, CTLFLAG_RW, &g_gate_debug, 0,
|
2004-04-30 16:08:12 +00:00
|
|
|
"Debug level");
|
2010-02-18 23:16:19 +00:00
|
|
|
static u_int g_gate_maxunits = 256;
|
|
|
|
TUNABLE_INT("kern.geom.gate.maxunits", &g_gate_maxunits);
|
|
|
|
SYSCTL_UINT(_kern_geom_gate, OID_AUTO, maxunits, CTLFLAG_RDTUN,
|
|
|
|
&g_gate_maxunits, 0, "Maximum number of ggate devices");
|
2004-04-30 16:08:12 +00:00
|
|
|
|
|
|
|
struct g_class g_gate_class = {
|
|
|
|
.name = G_GATE_CLASS_NAME,
|
2004-08-08 07:57:53 +00:00
|
|
|
.version = G_VERSION,
|
2004-04-30 16:08:12 +00:00
|
|
|
};
|
|
|
|
|
2004-06-16 09:47:26 +00:00
|
|
|
static struct cdev *status_dev;
|
2004-04-30 16:08:12 +00:00
|
|
|
static d_ioctl_t g_gate_ioctl;
|
|
|
|
static struct cdevsw g_gate_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_ioctl = g_gate_ioctl,
|
|
|
|
.d_name = G_GATE_CTL_NAME
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
static struct g_gate_softc **g_gate_units;
|
|
|
|
static u_int g_gate_nunits;
|
|
|
|
static struct mtx g_gate_units_lock;
|
2004-04-30 16:08:12 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
g_gate_destroy(struct g_gate_softc *sc, boolean_t force)
|
|
|
|
{
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
struct bio_queue_head queue;
|
2004-04-30 16:08:12 +00:00
|
|
|
struct g_provider *pp;
|
2012-07-04 20:16:28 +00:00
|
|
|
struct g_consumer *cp;
|
2006-09-05 21:56:00 +00:00
|
|
|
struct g_geom *gp;
|
2004-04-30 16:08:12 +00:00
|
|
|
struct bio *bp;
|
|
|
|
|
|
|
|
g_topology_assert();
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_assert(&g_gate_units_lock, MA_OWNED);
|
2004-04-30 16:08:12 +00:00
|
|
|
pp = sc->sc_provider;
|
|
|
|
if (!force && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
2006-09-05 21:56:00 +00:00
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_DESTROY) == 0)
|
|
|
|
sc->sc_flags |= G_GATE_FLAG_DESTROY;
|
2004-04-30 16:08:12 +00:00
|
|
|
wakeup(sc);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2006-09-05 21:56:00 +00:00
|
|
|
gp = pp->geom;
|
|
|
|
pp->flags |= G_PF_WITHER;
|
|
|
|
g_orphan_provider(pp, ENXIO);
|
2004-04-30 16:08:12 +00:00
|
|
|
callout_drain(&sc->sc_callout);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_init(&queue);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
while ((bp = bioq_takefirst(&sc->sc_inqueue)) != NULL) {
|
2010-03-18 13:11:43 +00:00
|
|
|
sc->sc_queue_count--;
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_insert_tail(&queue, bp);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
while ((bp = bioq_takefirst(&sc->sc_outqueue)) != NULL) {
|
2010-03-18 13:11:43 +00:00
|
|
|
sc->sc_queue_count--;
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_insert_tail(&queue, bp);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2006-09-05 21:56:00 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
|
|
|
g_topology_unlock();
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
while ((bp = bioq_takefirst(&queue)) != NULL) {
|
|
|
|
G_GATE_LOGREQ(1, bp, "Request canceled.");
|
|
|
|
g_io_deliver(bp, ENXIO);
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_lock(&g_gate_units_lock);
|
2006-09-05 21:56:00 +00:00
|
|
|
/* One reference is ours. */
|
|
|
|
sc->sc_ref--;
|
2010-02-18 23:16:19 +00:00
|
|
|
while (sc->sc_ref > 0)
|
|
|
|
msleep(&sc->sc_ref, &g_gate_units_lock, 0, "gg:destroy", 0);
|
|
|
|
g_gate_units[sc->sc_unit] = NULL;
|
|
|
|
KASSERT(g_gate_nunits > 0, ("negative g_gate_nunits?"));
|
|
|
|
g_gate_nunits--;
|
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_destroy(&sc->sc_queue_mtx);
|
2006-09-05 21:56:00 +00:00
|
|
|
g_topology_lock();
|
2012-07-04 20:16:28 +00:00
|
|
|
if ((cp = sc->sc_readcons) != NULL) {
|
|
|
|
sc->sc_readcons = NULL;
|
|
|
|
(void)g_access(cp, -1, 0, 0);
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
}
|
2011-03-30 21:40:14 +00:00
|
|
|
G_GATE_DEBUG(1, "Device %s destroyed.", gp->name);
|
2006-09-05 21:56:00 +00:00
|
|
|
gp->softc = NULL;
|
|
|
|
g_wither_geom(gp, ENXIO);
|
2004-04-30 16:08:12 +00:00
|
|
|
sc->sc_provider = NULL;
|
|
|
|
free(sc, M_GATE);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_gate_access(struct g_provider *pp, int dr, int dw, int de)
|
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
|
|
|
|
if (dr <= 0 && dw <= 0 && de <= 0)
|
|
|
|
return (0);
|
|
|
|
sc = pp->geom->softc;
|
|
|
|
if (sc == NULL || (sc->sc_flags & G_GATE_FLAG_DESTROY) != 0)
|
|
|
|
return (ENXIO);
|
2004-06-27 12:56:11 +00:00
|
|
|
/* XXX: Hack to allow read-only mounts. */
|
|
|
|
#if 0
|
2004-04-30 16:08:12 +00:00
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_READONLY) != 0 && dw > 0)
|
|
|
|
return (EPERM);
|
2004-06-27 12:56:11 +00:00
|
|
|
#endif
|
2004-04-30 16:08:12 +00:00
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_WRITEONLY) != 0 && dr > 0)
|
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-04 20:16:28 +00:00
|
|
|
g_gate_queue_io(struct bio *bp)
|
2004-04-30 16:08:12 +00:00
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
|
|
|
|
sc = bp->bio_to->geom->softc;
|
|
|
|
if (sc == NULL || (sc->sc_flags & G_GATE_FLAG_DESTROY) != 0) {
|
|
|
|
g_io_deliver(bp, ENXIO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
2012-07-04 20:16:28 +00:00
|
|
|
|
GEOM has an internal mechanism to deal with ENOMEM errors returned via
g_io_deliver(). In such case it increases 'pace' counter on each ENOMEM and
reschedules the request. The 'pace' counter is decreased for each request going
down, but until 'pace' is greater than zero, GEOM will handle at most 10
requests per second. For GEOM GATE users that are proxy to local GEOM providers
(like ggatel(8) and HAST) we can end up with almost permanent slow down of GEOM
down queue. This is because once we reach GEOM GATE queue limit, we return
ENOMEM to the GEOM. This means that we have, eg. 1024 I/O requests in the GEOM
GATE queue. To make room in the queue and stop returning ENOMEM we need to
proceed the requests of course, but those requests are handled by userland
daemons that handle them by reading/writing also from/to local GEOM providers.
For example with HAST, a new requests comes to /dev/hast/data, which is GEOM
GATE provider. GEOM GATE passes the request to hastd(8) and hastd(8)
reads/writes from/to /dev/da0. Once we reach GEOM GATE queue limit, to free up
a slot in GEOM GATE queue, hastd(8) has to read/write from/to /dev/da0, but
this request will also be very slow, because GEOM now slows down all the
requests. We end up with full queue that we can unload at the speed of 10
requests per second. This simply looks like a deadlock.
Fix it by allowing userland daemons that work with both GEOM GATE and local
GEOM providers to specify unlimited queue size, so GEOM GATE will never return
ENOMEM to the GEOM.
MFC after: 1 week
2011-04-02 06:56:06 +00:00
|
|
|
if (sc->sc_queue_size > 0 && sc->sc_queue_count > sc->sc_queue_size) {
|
2005-02-12 16:19:03 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
G_GATE_LOGREQ(1, bp, "Queue full, request canceled.");
|
2010-02-18 23:16:19 +00:00
|
|
|
g_io_deliver(bp, ENOMEM);
|
2004-04-30 16:08:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-02-09 08:29:39 +00:00
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
bp->bio_driver1 = (void *)sc->sc_seq;
|
|
|
|
sc->sc_seq++;
|
2005-02-09 08:29:39 +00:00
|
|
|
sc->sc_queue_count++;
|
2004-04-30 16:08:12 +00:00
|
|
|
|
2005-02-05 00:30:08 +00:00
|
|
|
bioq_insert_tail(&sc->sc_inqueue, bp);
|
2004-04-30 16:08:12 +00:00
|
|
|
wakeup(sc);
|
2005-02-09 08:29:39 +00:00
|
|
|
|
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 20:16:28 +00:00
|
|
|
static void
|
|
|
|
g_gate_done(struct bio *cbp)
|
|
|
|
{
|
|
|
|
struct bio *pbp;
|
|
|
|
|
|
|
|
pbp = cbp->bio_parent;
|
|
|
|
if (cbp->bio_error == 0) {
|
|
|
|
pbp->bio_completed = cbp->bio_completed;
|
|
|
|
g_destroy_bio(cbp);
|
|
|
|
pbp->bio_inbed++;
|
|
|
|
g_io_deliver(pbp, 0);
|
|
|
|
} else {
|
|
|
|
/* If direct read failed, pass it through userland daemon. */
|
|
|
|
g_destroy_bio(cbp);
|
|
|
|
pbp->bio_children--;
|
|
|
|
g_gate_queue_io(pbp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_gate_start(struct bio *pbp)
|
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
|
|
|
|
sc = pbp->bio_to->geom->softc;
|
|
|
|
if (sc == NULL || (sc->sc_flags & G_GATE_FLAG_DESTROY) != 0) {
|
|
|
|
g_io_deliver(pbp, ENXIO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
G_GATE_LOGREQ(2, pbp, "Request received.");
|
|
|
|
switch (pbp->bio_cmd) {
|
|
|
|
case BIO_READ:
|
|
|
|
if (sc->sc_readcons != NULL) {
|
|
|
|
struct bio *cbp;
|
|
|
|
|
|
|
|
cbp = g_clone_bio(pbp);
|
|
|
|
if (cbp == NULL) {
|
|
|
|
g_io_deliver(pbp, ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cbp->bio_done = g_gate_done;
|
|
|
|
cbp->bio_offset = pbp->bio_offset + sc->sc_readoffset;
|
|
|
|
cbp->bio_to = sc->sc_readcons->provider;
|
|
|
|
g_io_request(cbp, sc->sc_readcons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BIO_DELETE:
|
|
|
|
case BIO_WRITE:
|
|
|
|
case BIO_FLUSH:
|
|
|
|
/* XXX: Hack to allow read-only mounts. */
|
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_READONLY) != 0) {
|
|
|
|
g_io_deliver(pbp, EPERM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BIO_GETATTR:
|
|
|
|
default:
|
|
|
|
G_GATE_LOGREQ(2, pbp, "Ignoring request.");
|
|
|
|
g_io_deliver(pbp, EOPNOTSUPP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_gate_queue_io(pbp);
|
|
|
|
}
|
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
static struct g_gate_softc *
|
2010-06-14 21:58:55 +00:00
|
|
|
g_gate_hold(int unit, const char *name)
|
2004-04-30 16:08:12 +00:00
|
|
|
{
|
2010-02-18 23:16:19 +00:00
|
|
|
struct g_gate_softc *sc = NULL;
|
|
|
|
|
|
|
|
mtx_lock(&g_gate_units_lock);
|
|
|
|
if (unit >= 0 && unit < g_gate_maxunits)
|
|
|
|
sc = g_gate_units[unit];
|
|
|
|
else if (unit == G_GATE_NAME_GIVEN) {
|
|
|
|
KASSERT(name != NULL, ("name is NULL"));
|
|
|
|
for (unit = 0; unit < g_gate_maxunits; unit++) {
|
|
|
|
if (g_gate_units[unit] == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(name,
|
|
|
|
g_gate_units[unit]->sc_provider->name) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sc = g_gate_units[unit];
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
2010-02-18 23:16:19 +00:00
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2006-09-05 21:56:00 +00:00
|
|
|
if (sc != NULL)
|
|
|
|
sc->sc_ref++;
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
return (sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_gate_release(struct g_gate_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
g_topology_assert_not();
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_lock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
sc->sc_ref--;
|
|
|
|
KASSERT(sc->sc_ref >= 0, ("Negative sc_ref for %s.", sc->sc_name));
|
2010-02-18 23:16:19 +00:00
|
|
|
if (sc->sc_ref == 0 && (sc->sc_flags & G_GATE_FLAG_DESTROY) != 0)
|
2006-09-05 21:56:00 +00:00
|
|
|
wakeup(&sc->sc_ref);
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-18 23:16:19 +00:00
|
|
|
g_gate_getunit(int unit, int *errorp)
|
2004-04-30 16:08:12 +00:00
|
|
|
{
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_assert(&g_gate_units_lock, MA_OWNED);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (unit >= 0) {
|
2010-02-18 23:16:19 +00:00
|
|
|
if (unit >= g_gate_maxunits)
|
|
|
|
*errorp = EINVAL;
|
|
|
|
else if (g_gate_units[unit] == NULL)
|
|
|
|
return (unit);
|
|
|
|
else
|
|
|
|
*errorp = EEXIST;
|
2004-04-30 16:08:12 +00:00
|
|
|
} else {
|
2010-02-18 23:16:19 +00:00
|
|
|
for (unit = 0; unit < g_gate_maxunits; unit++) {
|
|
|
|
if (g_gate_units[unit] == NULL)
|
|
|
|
return (unit);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
*errorp = ENFILE;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
return (-1);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_gate_guard(void *arg)
|
|
|
|
{
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
struct bio_queue_head queue;
|
2004-04-30 16:08:12 +00:00
|
|
|
struct g_gate_softc *sc;
|
|
|
|
struct bintime curtime;
|
|
|
|
struct bio *bp, *bp2;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
binuptime(&curtime);
|
2010-02-18 23:16:19 +00:00
|
|
|
g_gate_hold(sc->sc_unit, NULL);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_init(&queue);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
TAILQ_FOREACH_SAFE(bp, &sc->sc_inqueue.queue, bio_queue, bp2) {
|
|
|
|
if (curtime.sec - bp->bio_t0.sec < 5)
|
|
|
|
continue;
|
|
|
|
bioq_remove(&sc->sc_inqueue, bp);
|
2005-02-09 08:29:39 +00:00
|
|
|
sc->sc_queue_count--;
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_insert_tail(&queue, bp);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
TAILQ_FOREACH_SAFE(bp, &sc->sc_outqueue.queue, bio_queue, bp2) {
|
|
|
|
if (curtime.sec - bp->bio_t0.sec < 5)
|
|
|
|
continue;
|
|
|
|
bioq_remove(&sc->sc_outqueue, bp);
|
2005-02-09 08:29:39 +00:00
|
|
|
sc->sc_queue_count--;
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
bioq_insert_tail(&queue, bp);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
|
|
|
while ((bp = bioq_takefirst(&queue)) != NULL) {
|
2004-04-30 16:08:12 +00:00
|
|
|
G_GATE_LOGREQ(1, bp, "Request timeout.");
|
|
|
|
g_io_deliver(bp, EIO);
|
|
|
|
}
|
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_DESTROY) == 0) {
|
|
|
|
callout_reset(&sc->sc_callout, sc->sc_timeout * hz,
|
|
|
|
g_gate_guard, sc);
|
|
|
|
}
|
|
|
|
g_gate_release(sc);
|
|
|
|
}
|
|
|
|
|
2012-07-04 20:16:28 +00:00
|
|
|
static void
|
|
|
|
g_gate_orphan(struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
gp = cp->geom;
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
|
|
|
KASSERT(cp == sc->sc_readcons, ("cp=%p sc_readcons=%p", cp,
|
|
|
|
sc->sc_readcons));
|
|
|
|
sc->sc_readcons = NULL;
|
|
|
|
G_GATE_DEBUG(1, "Destroying read consumer on provider %s orphan.",
|
|
|
|
cp->provider->name);
|
|
|
|
(void)g_access(cp, -1, 0, 0);
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
}
|
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
static void
|
|
|
|
g_gate_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
|
|
|
|
struct g_consumer *cp, struct g_provider *pp)
|
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc == NULL || pp != NULL || cp != NULL)
|
|
|
|
return;
|
2012-08-07 18:50:33 +00:00
|
|
|
sc = g_gate_hold(sc->sc_unit, NULL);
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
2004-04-30 16:08:12 +00:00
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_READONLY) != 0) {
|
|
|
|
sbuf_printf(sb, "%s<access>%s</access>\n", indent, "read-only");
|
|
|
|
} else if ((sc->sc_flags & G_GATE_FLAG_WRITEONLY) != 0) {
|
|
|
|
sbuf_printf(sb, "%s<access>%s</access>\n", indent,
|
|
|
|
"write-only");
|
|
|
|
} else {
|
|
|
|
sbuf_printf(sb, "%s<access>%s</access>\n", indent,
|
|
|
|
"read-write");
|
|
|
|
}
|
2012-07-04 20:16:28 +00:00
|
|
|
if (sc->sc_readcons != NULL) {
|
|
|
|
sbuf_printf(sb, "%s<read_offset>%jd</read_offset>\n",
|
|
|
|
indent, (intmax_t)sc->sc_readoffset);
|
|
|
|
sbuf_printf(sb, "%s<read_provider>%s</read_provider>\n",
|
|
|
|
indent, sc->sc_readcons->provider->name);
|
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
sbuf_printf(sb, "%s<timeout>%u</timeout>\n", indent, sc->sc_timeout);
|
|
|
|
sbuf_printf(sb, "%s<info>%s</info>\n", indent, sc->sc_info);
|
|
|
|
sbuf_printf(sb, "%s<queue_count>%u</queue_count>\n", indent,
|
|
|
|
sc->sc_queue_count);
|
|
|
|
sbuf_printf(sb, "%s<queue_size>%u</queue_size>\n", indent,
|
|
|
|
sc->sc_queue_size);
|
|
|
|
sbuf_printf(sb, "%s<ref>%u</ref>\n", indent, sc->sc_ref);
|
2010-02-18 23:16:19 +00:00
|
|
|
sbuf_printf(sb, "%s<unit>%d</unit>\n", indent, sc->sc_unit);
|
2004-06-21 09:12:08 +00:00
|
|
|
g_topology_unlock();
|
2004-04-30 16:08:12 +00:00
|
|
|
g_gate_release(sc);
|
2004-06-21 09:12:08 +00:00
|
|
|
g_topology_lock();
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_gate_create(struct g_gate_ctl_create *ggio)
|
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
struct g_geom *gp;
|
2012-07-04 20:16:28 +00:00
|
|
|
struct g_provider *pp, *ropp;
|
|
|
|
struct g_consumer *cp;
|
2010-02-18 23:16:19 +00:00
|
|
|
char name[NAME_MAX];
|
|
|
|
int error = 0, unit;
|
2004-04-30 16:08:12 +00:00
|
|
|
|
2012-07-04 20:16:28 +00:00
|
|
|
if (ggio->gctl_mediasize <= 0) {
|
2004-04-30 16:08:12 +00:00
|
|
|
G_GATE_DEBUG(1, "Invalid media size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2012-07-04 20:16:28 +00:00
|
|
|
if (ggio->gctl_sectorsize <= 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid sector size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (!powerof2(ggio->gctl_sectorsize)) {
|
2004-04-30 16:08:12 +00:00
|
|
|
G_GATE_DEBUG(1, "Invalid sector size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2005-02-05 00:30:08 +00:00
|
|
|
if ((ggio->gctl_mediasize % ggio->gctl_sectorsize) != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid media size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
if ((ggio->gctl_flags & G_GATE_FLAG_READONLY) != 0 &&
|
|
|
|
(ggio->gctl_flags & G_GATE_FLAG_WRITEONLY) != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid flags.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
if (ggio->gctl_unit != G_GATE_UNIT_AUTO &&
|
|
|
|
ggio->gctl_unit != G_GATE_NAME_GIVEN &&
|
|
|
|
ggio->gctl_unit < 0) {
|
2004-04-30 16:08:12 +00:00
|
|
|
G_GATE_DEBUG(1, "Invalid unit number.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
if (ggio->gctl_unit == G_GATE_NAME_GIVEN &&
|
|
|
|
ggio->gctl_name[0] == '\0') {
|
|
|
|
G_GATE_DEBUG(1, "No device name.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
|
2012-07-28 16:30:50 +00:00
|
|
|
sc = malloc(sizeof(*sc), M_GATE, M_WAITOK | M_ZERO);
|
|
|
|
sc->sc_flags = (ggio->gctl_flags & G_GATE_USERFLAGS);
|
|
|
|
strlcpy(sc->sc_info, ggio->gctl_info, sizeof(sc->sc_info));
|
|
|
|
sc->sc_seq = 1;
|
|
|
|
bioq_init(&sc->sc_inqueue);
|
|
|
|
bioq_init(&sc->sc_outqueue);
|
|
|
|
mtx_init(&sc->sc_queue_mtx, "gg:queue", NULL, MTX_DEF);
|
|
|
|
sc->sc_queue_count = 0;
|
|
|
|
sc->sc_queue_size = ggio->gctl_maxcount;
|
|
|
|
if (sc->sc_queue_size > G_GATE_MAX_QUEUE_SIZE)
|
|
|
|
sc->sc_queue_size = G_GATE_MAX_QUEUE_SIZE;
|
|
|
|
sc->sc_timeout = ggio->gctl_timeout;
|
|
|
|
callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
|
|
|
|
|
|
|
|
mtx_lock(&g_gate_units_lock);
|
|
|
|
sc->sc_unit = g_gate_getunit(ggio->gctl_unit, &error);
|
|
|
|
if (sc->sc_unit < 0)
|
|
|
|
goto fail1;
|
|
|
|
if (ggio->gctl_unit == G_GATE_NAME_GIVEN)
|
|
|
|
snprintf(name, sizeof(name), "%s", ggio->gctl_name);
|
|
|
|
else {
|
|
|
|
snprintf(name, sizeof(name), "%s%d", G_GATE_PROVIDER_NAME,
|
|
|
|
sc->sc_unit);
|
|
|
|
}
|
|
|
|
/* Check for name collision. */
|
|
|
|
for (unit = 0; unit < g_gate_maxunits; unit++) {
|
|
|
|
if (g_gate_units[unit] == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(name, g_gate_units[unit]->sc_name) != 0)
|
|
|
|
continue;
|
|
|
|
error = EEXIST;
|
|
|
|
goto fail1;
|
|
|
|
}
|
|
|
|
sc->sc_name = name;
|
|
|
|
g_gate_units[sc->sc_unit] = sc;
|
|
|
|
g_gate_nunits++;
|
|
|
|
mtx_unlock(&g_gate_units_lock);
|
|
|
|
|
2012-07-04 20:16:28 +00:00
|
|
|
g_topology_lock();
|
|
|
|
|
|
|
|
if (ggio->gctl_readprov[0] == '\0') {
|
|
|
|
ropp = NULL;
|
|
|
|
} else {
|
|
|
|
ropp = g_provider_by_name(ggio->gctl_readprov);
|
|
|
|
if (ropp == NULL) {
|
|
|
|
G_GATE_DEBUG(1, "Provider %s doesn't exist.",
|
|
|
|
ggio->gctl_readprov);
|
2012-07-28 16:30:50 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail2;
|
2012-07-04 20:16:28 +00:00
|
|
|
}
|
|
|
|
if ((ggio->gctl_readoffset % ggio->gctl_sectorsize) != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid read offset.");
|
2012-07-28 16:30:50 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail2;
|
2012-07-04 20:16:28 +00:00
|
|
|
}
|
|
|
|
if (ggio->gctl_mediasize + ggio->gctl_readoffset >
|
|
|
|
ropp->mediasize) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid read offset or media size.");
|
2012-07-28 16:30:50 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail2;
|
2012-07-04 20:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gp = g_new_geomf(&g_gate_class, "%s", name);
|
|
|
|
gp->start = g_gate_start;
|
|
|
|
gp->access = g_gate_access;
|
|
|
|
gp->orphan = g_gate_orphan;
|
|
|
|
gp->dumpconf = g_gate_dumpconf;
|
|
|
|
gp->softc = sc;
|
|
|
|
|
|
|
|
if (ropp != NULL) {
|
|
|
|
cp = g_new_consumer(gp);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
|
2012-07-04 20:16:28 +00:00
|
|
|
error = g_attach(cp, ropp);
|
|
|
|
if (error != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Unable to attach to %s.", ropp->name);
|
2012-07-28 16:30:50 +00:00
|
|
|
goto fail3;
|
2012-07-04 20:16:28 +00:00
|
|
|
}
|
2012-07-28 16:30:50 +00:00
|
|
|
error = g_access(cp, 1, 0, 0);
|
2012-07-04 20:16:28 +00:00
|
|
|
if (error != 0) {
|
2012-07-28 16:30:50 +00:00
|
|
|
G_GATE_DEBUG(1, "Unable to access %s.", ropp->name);
|
|
|
|
g_detach(cp);
|
|
|
|
goto fail3;
|
2012-07-04 20:16:28 +00:00
|
|
|
}
|
|
|
|
sc->sc_readcons = cp;
|
|
|
|
sc->sc_readoffset = ggio->gctl_readoffset;
|
|
|
|
}
|
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
ggio->gctl_unit = sc->sc_unit;
|
2004-04-30 16:08:12 +00:00
|
|
|
|
2010-02-18 23:16:19 +00:00
|
|
|
pp = g_new_providerf(gp, "%s", name);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
|
2004-04-30 16:08:12 +00:00
|
|
|
pp->mediasize = ggio->gctl_mediasize;
|
|
|
|
pp->sectorsize = ggio->gctl_sectorsize;
|
|
|
|
sc->sc_provider = pp;
|
|
|
|
g_error_provider(pp, 0);
|
2012-07-04 20:16:28 +00:00
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
g_topology_unlock();
|
2011-03-27 19:56:55 +00:00
|
|
|
mtx_lock(&g_gate_units_lock);
|
|
|
|
sc->sc_name = sc->sc_provider->name;
|
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2011-03-30 21:40:14 +00:00
|
|
|
G_GATE_DEBUG(1, "Device %s created.", gp->name);
|
2004-04-30 16:08:12 +00:00
|
|
|
|
|
|
|
if (sc->sc_timeout > 0) {
|
|
|
|
callout_reset(&sc->sc_callout, sc->sc_timeout * hz,
|
|
|
|
g_gate_guard, sc);
|
|
|
|
}
|
|
|
|
return (0);
|
2012-07-28 16:30:50 +00:00
|
|
|
fail3:
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
g_destroy_geom(gp);
|
|
|
|
fail2:
|
|
|
|
g_topology_unlock();
|
|
|
|
mtx_lock(&g_gate_units_lock);
|
|
|
|
g_gate_units[sc->sc_unit] = NULL;
|
|
|
|
KASSERT(g_gate_nunits > 0, ("negative g_gate_nunits?"));
|
|
|
|
g_gate_nunits--;
|
|
|
|
fail1:
|
|
|
|
mtx_unlock(&g_gate_units_lock);
|
|
|
|
mtx_destroy(&sc->sc_queue_mtx);
|
|
|
|
free(sc, M_GATE);
|
|
|
|
return (error);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 20:16:28 +00:00
|
|
|
static int
|
|
|
|
g_gate_modify(struct g_gate_softc *sc, struct g_gate_ctl_modify *ggio)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((ggio->gctl_modify & GG_MODIFY_MEDIASIZE) != 0) {
|
|
|
|
if (ggio->gctl_mediasize <= 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid media size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
pp = sc->sc_provider;
|
|
|
|
if ((ggio->gctl_mediasize % pp->sectorsize) != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid media size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/* TODO */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ggio->gctl_modify & GG_MODIFY_INFO) != 0)
|
|
|
|
(void)strlcpy(sc->sc_info, ggio->gctl_info, sizeof(sc->sc_info));
|
|
|
|
|
|
|
|
cp = NULL;
|
|
|
|
|
|
|
|
if ((ggio->gctl_modify & GG_MODIFY_READPROV) != 0) {
|
|
|
|
g_topology_lock();
|
|
|
|
if (sc->sc_readcons != NULL) {
|
|
|
|
cp = sc->sc_readcons;
|
|
|
|
sc->sc_readcons = NULL;
|
|
|
|
(void)g_access(cp, -1, 0, 0);
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
}
|
|
|
|
if (ggio->gctl_readprov[0] != '\0') {
|
|
|
|
pp = g_provider_by_name(ggio->gctl_readprov);
|
|
|
|
if (pp == NULL) {
|
|
|
|
g_topology_unlock();
|
|
|
|
G_GATE_DEBUG(1, "Provider %s doesn't exist.",
|
|
|
|
ggio->gctl_readprov);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
cp = g_new_consumer(sc->sc_provider->geom);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
|
2012-07-04 20:16:28 +00:00
|
|
|
error = g_attach(cp, pp);
|
|
|
|
if (error != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Unable to attach to %s.",
|
|
|
|
pp->name);
|
|
|
|
} else {
|
|
|
|
error = g_access(cp, 1, 0, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Unable to access %s.",
|
|
|
|
pp->name);
|
|
|
|
g_detach(cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error != 0) {
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
g_topology_unlock();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cp = sc->sc_readcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ggio->gctl_modify & GG_MODIFY_READOFFSET) != 0) {
|
|
|
|
if (cp == NULL) {
|
|
|
|
G_GATE_DEBUG(1, "No read provider.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
pp = sc->sc_provider;
|
|
|
|
if ((ggio->gctl_readoffset % pp->sectorsize) != 0) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid read offset.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (pp->mediasize + ggio->gctl_readoffset >
|
|
|
|
cp->provider->mediasize) {
|
|
|
|
G_GATE_DEBUG(1, "Invalid read offset or media size.");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
sc->sc_readoffset = ggio->gctl_readoffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ggio->gctl_modify & GG_MODIFY_READPROV) != 0) {
|
|
|
|
sc->sc_readcons = cp;
|
|
|
|
g_topology_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
#define G_GATE_CHECK_VERSION(ggio) do { \
|
2005-07-08 21:08:53 +00:00
|
|
|
if ((ggio)->gctl_version != G_GATE_VERSION) { \
|
|
|
|
printf("Version mismatch %d != %d.\n", \
|
|
|
|
ggio->gctl_version, G_GATE_VERSION); \
|
2004-04-30 16:08:12 +00:00
|
|
|
return (EINVAL); \
|
2005-07-08 21:08:53 +00:00
|
|
|
} \
|
2004-04-30 16:08:12 +00:00
|
|
|
} while (0)
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
g_gate_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
|
2004-04-30 16:08:12 +00:00
|
|
|
{
|
|
|
|
struct g_gate_softc *sc;
|
|
|
|
struct bio *bp;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
G_GATE_DEBUG(4, "ioctl(%s, %lx, %p, %x, %p)", devtoname(dev), cmd, addr,
|
|
|
|
flags, td);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case G_GATE_CMD_CREATE:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_create *ggio = (void *)addr;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
2004-11-23 11:18:26 +00:00
|
|
|
error = g_gate_create(ggio);
|
2005-02-16 16:12:28 +00:00
|
|
|
/*
|
|
|
|
* Reset TDP_GEOM flag.
|
|
|
|
* There are pending events for sure, because we just created
|
|
|
|
* new provider and other classes want to taste it, but we
|
|
|
|
* cannot answer on I/O requests until we're here.
|
|
|
|
*/
|
|
|
|
td->td_pflags &= ~TDP_GEOM;
|
2004-11-23 11:18:26 +00:00
|
|
|
return (error);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2012-07-04 20:16:28 +00:00
|
|
|
case G_GATE_CMD_MODIFY:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_modify *ggio = (void *)addr;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
|
|
|
sc = g_gate_hold(ggio->gctl_unit, NULL);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
error = g_gate_modify(sc, ggio);
|
|
|
|
g_gate_release(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
case G_GATE_CMD_DESTROY:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_destroy *ggio = (void *)addr;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
2010-02-18 23:16:19 +00:00
|
|
|
sc = g_gate_hold(ggio->gctl_unit, ggio->gctl_name);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
g_topology_lock();
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_lock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
error = g_gate_destroy(sc, ggio->gctl_force);
|
|
|
|
g_topology_unlock();
|
2006-09-05 21:56:00 +00:00
|
|
|
if (error != 0)
|
|
|
|
g_gate_release(sc);
|
2004-04-30 16:08:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2005-07-08 21:08:53 +00:00
|
|
|
case G_GATE_CMD_CANCEL:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_cancel *ggio = (void *)addr;
|
|
|
|
struct bio *tbp, *lbp;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
2010-02-18 23:16:19 +00:00
|
|
|
sc = g_gate_hold(ggio->gctl_unit, ggio->gctl_name);
|
2005-07-08 21:08:53 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
lbp = NULL;
|
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
|
|
|
TAILQ_FOREACH_SAFE(bp, &sc->sc_outqueue.queue, bio_queue, tbp) {
|
|
|
|
if (ggio->gctl_seq == 0 ||
|
|
|
|
ggio->gctl_seq == (uintptr_t)bp->bio_driver1) {
|
|
|
|
G_GATE_LOGREQ(1, bp, "Request canceled.");
|
|
|
|
bioq_remove(&sc->sc_outqueue, bp);
|
|
|
|
/*
|
|
|
|
* Be sure to put requests back onto incoming
|
|
|
|
* queue in the proper order.
|
|
|
|
*/
|
|
|
|
if (lbp == NULL)
|
|
|
|
bioq_insert_head(&sc->sc_inqueue, bp);
|
|
|
|
else {
|
|
|
|
TAILQ_INSERT_AFTER(&sc->sc_inqueue.queue,
|
|
|
|
lbp, bp, bio_queue);
|
|
|
|
}
|
|
|
|
lbp = bp;
|
|
|
|
/*
|
|
|
|
* If only one request was canceled, leave now.
|
|
|
|
*/
|
|
|
|
if (ggio->gctl_seq != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
if (ggio->gctl_unit == G_GATE_NAME_GIVEN)
|
|
|
|
ggio->gctl_unit = sc->sc_unit;
|
2005-07-08 21:08:53 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
|
|
|
g_gate_release(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
2004-04-30 16:08:12 +00:00
|
|
|
case G_GATE_CMD_START:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_io *ggio = (void *)addr;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
2010-02-18 23:16:19 +00:00
|
|
|
sc = g_gate_hold(ggio->gctl_unit, NULL);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
2006-09-05 21:56:00 +00:00
|
|
|
error = 0;
|
2004-04-30 16:08:12 +00:00
|
|
|
for (;;) {
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
bp = bioq_first(&sc->sc_inqueue);
|
|
|
|
if (bp != NULL)
|
|
|
|
break;
|
2006-09-05 21:56:00 +00:00
|
|
|
if ((sc->sc_flags & G_GATE_FLAG_DESTROY) != 0) {
|
2004-04-30 16:08:12 +00:00
|
|
|
ggio->gctl_error = ECANCELED;
|
2006-09-05 21:56:00 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
|
|
|
goto start_end;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2006-09-05 21:56:00 +00:00
|
|
|
if (msleep(sc, &sc->sc_queue_mtx,
|
|
|
|
PPAUSE | PDROP | PCATCH, "ggwait", 0) != 0) {
|
2004-04-30 16:08:12 +00:00
|
|
|
ggio->gctl_error = ECANCELED;
|
2006-09-05 21:56:00 +00:00
|
|
|
goto start_end;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-03 18:06:24 +00:00
|
|
|
ggio->gctl_cmd = bp->bio_cmd;
|
2013-03-14 23:07:01 +00:00
|
|
|
if (bp->bio_cmd == BIO_WRITE &&
|
2004-04-30 16:08:12 +00:00
|
|
|
bp->bio_length > ggio->gctl_length) {
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
ggio->gctl_length = bp->bio_length;
|
|
|
|
ggio->gctl_error = ENOMEM;
|
2006-09-05 21:56:00 +00:00
|
|
|
goto start_end;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
bioq_remove(&sc->sc_inqueue, bp);
|
2005-02-09 08:29:39 +00:00
|
|
|
bioq_insert_tail(&sc->sc_outqueue, bp);
|
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
|
|
|
|
2004-05-02 17:57:49 +00:00
|
|
|
ggio->gctl_seq = (uintptr_t)bp->bio_driver1;
|
2004-04-30 16:08:12 +00:00
|
|
|
ggio->gctl_offset = bp->bio_offset;
|
|
|
|
ggio->gctl_length = bp->bio_length;
|
2005-07-08 21:08:53 +00:00
|
|
|
|
2004-04-30 16:08:12 +00:00
|
|
|
switch (bp->bio_cmd) {
|
|
|
|
case BIO_READ:
|
|
|
|
case BIO_DELETE:
|
2011-05-23 21:00:37 +00:00
|
|
|
case BIO_FLUSH:
|
2010-06-14 21:56:24 +00:00
|
|
|
break;
|
2004-04-30 16:08:12 +00:00
|
|
|
case BIO_WRITE:
|
|
|
|
error = copyout(bp->bio_data, ggio->gctl_data,
|
|
|
|
bp->bio_length);
|
|
|
|
if (error != 0) {
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
|
|
|
bioq_remove(&sc->sc_outqueue, bp);
|
2005-02-05 00:30:08 +00:00
|
|
|
bioq_insert_head(&sc->sc_inqueue, bp);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2006-09-05 21:56:00 +00:00
|
|
|
goto start_end;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-09-05 21:56:00 +00:00
|
|
|
start_end:
|
|
|
|
g_gate_release(sc);
|
|
|
|
return (error);
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
case G_GATE_CMD_DONE:
|
|
|
|
{
|
|
|
|
struct g_gate_ctl_io *ggio = (void *)addr;
|
|
|
|
|
|
|
|
G_GATE_CHECK_VERSION(ggio);
|
2010-02-18 23:16:19 +00:00
|
|
|
sc = g_gate_hold(ggio->gctl_unit, NULL);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return (ENOENT);
|
2006-09-05 21:56:00 +00:00
|
|
|
error = 0;
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
TAILQ_FOREACH(bp, &sc->sc_outqueue.queue, bio_queue) {
|
2004-05-02 17:57:49 +00:00
|
|
|
if (ggio->gctl_seq == (uintptr_t)bp->bio_driver1)
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bp != NULL) {
|
|
|
|
bioq_remove(&sc->sc_outqueue, bp);
|
2005-02-09 08:29:39 +00:00
|
|
|
sc->sc_queue_count--;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (bp == NULL) {
|
|
|
|
/*
|
|
|
|
* Request was probably canceled.
|
|
|
|
*/
|
2006-09-05 21:56:00 +00:00
|
|
|
goto done_end;
|
2004-04-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
if (ggio->gctl_error == EAGAIN) {
|
|
|
|
bp->bio_error = 0;
|
|
|
|
G_GATE_LOGREQ(1, bp, "Request desisted.");
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_lock(&sc->sc_queue_mtx);
|
|
|
|
sc->sc_queue_count++;
|
2005-02-05 00:30:08 +00:00
|
|
|
bioq_insert_head(&sc->sc_inqueue, bp);
|
2004-04-30 16:08:12 +00:00
|
|
|
wakeup(sc);
|
2005-02-09 08:29:39 +00:00
|
|
|
mtx_unlock(&sc->sc_queue_mtx);
|
2004-04-30 16:08:12 +00:00
|
|
|
} else {
|
|
|
|
bp->bio_error = ggio->gctl_error;
|
|
|
|
if (bp->bio_error == 0) {
|
|
|
|
bp->bio_completed = bp->bio_length;
|
|
|
|
switch (bp->bio_cmd) {
|
|
|
|
case BIO_READ:
|
|
|
|
error = copyin(ggio->gctl_data,
|
|
|
|
bp->bio_data, bp->bio_length);
|
|
|
|
if (error != 0)
|
|
|
|
bp->bio_error = error;
|
|
|
|
break;
|
|
|
|
case BIO_DELETE:
|
|
|
|
case BIO_WRITE:
|
2011-05-23 21:00:37 +00:00
|
|
|
case BIO_FLUSH:
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
G_GATE_LOGREQ(2, bp, "Request done.");
|
|
|
|
g_io_deliver(bp, bp->bio_error);
|
|
|
|
}
|
2006-09-05 21:56:00 +00:00
|
|
|
done_end:
|
|
|
|
g_gate_release(sc);
|
2004-04-30 16:08:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ENOIOCTL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-01 15:42:03 +00:00
|
|
|
g_gate_device(void)
|
2004-04-30 16:08:12 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
status_dev = make_dev(&g_gate_cdevsw, 0x0, UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
G_GATE_CTL_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_gate_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_init(&g_gate_units_lock, "gg_units_lock", NULL, MTX_DEF);
|
|
|
|
g_gate_units = malloc(g_gate_maxunits * sizeof(g_gate_units[0]),
|
|
|
|
M_GATE, M_WAITOK | M_ZERO);
|
|
|
|
g_gate_nunits = 0;
|
2004-07-01 15:42:03 +00:00
|
|
|
g_gate_device();
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_lock(&g_gate_units_lock);
|
|
|
|
if (g_gate_nunits > 0) {
|
|
|
|
mtx_unlock(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
2010-02-18 23:16:19 +00:00
|
|
|
mtx_unlock(&g_gate_units_lock);
|
|
|
|
mtx_destroy(&g_gate_units_lock);
|
2004-04-30 16:08:12 +00:00
|
|
|
if (status_dev != 0)
|
|
|
|
destroy_dev(status_dev);
|
2010-02-18 23:16:19 +00:00
|
|
|
free(g_gate_units, M_GATE);
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-07-15 08:26:07 +00:00
|
|
|
return (EOPNOTSUPP);
|
2004-04-30 16:08:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
static moduledata_t g_gate_module = {
|
|
|
|
G_GATE_MOD_NAME,
|
|
|
|
g_gate_modevent,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(geom_gate, g_gate_module, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
|
|
|
DECLARE_GEOM_CLASS(g_gate_class, g_gate);
|