summaryrefslogtreecommitdiffstats
path: root/sys/dev/amr/amr.c
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-08-02 14:28:40 +0000
committerattilio <attilio@FreeBSD.org>2009-08-02 14:28:40 +0000
commit7f42e47a67ad2835fbc404253f835223020256d4 (patch)
treec00d808d1df8000c2086c86613be9ec8536a5e28 /sys/dev/amr/amr.c
parentea03af42ccd07d2533707afe4d1ba08f34bdb2e9 (diff)
downloadFreeBSD-src-7f42e47a67ad2835fbc404253f835223020256d4.zip
FreeBSD-src-7f42e47a67ad2835fbc404253f835223020256d4.tar.gz
Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures, device states and devclass flags. It is necessary to hold it when all such datas are accessed. For the other operations, softc locking should ensure enough protection to avoid races. Newbus lock is automatically held when virtual operations on the device and bus are invoked when loading the driver or when the suspend/resume take place. For other 'spourious' operations trying to access/modify the newbus topology, newbus lock needs to be automatically acquired and dropped. For the moment Giant is also acquired in some key point (modules subsystem) in order to avoid problems before the 8.0 release as module handlers could make assumptions about it. This Giant locking should go just after the release happens. Please keep in mind that the public interface can be expanded in order to provide more support, if there are really necessities at some point and also some bugs could arise as long as the patch needs a bit of further testing. Bump __FreeBSD_version in order to reflect the newbus lock introduction. Reviewed by: ed, hps, jhb, imp, mav, scottl No answer by: ariff, thompsa, yongari Tested by: pho, G. Trematerra <giovanni dot trematerra at gmail dot com>, Brandon Gooch <jamesbrandongooch at gmail dot com> Sponsored by: Yahoo! Incorporated Approved by: re (ksmith)
Diffstat (limited to 'sys/dev/amr/amr.c')
-rw-r--r--sys/dev/amr/amr.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/sys/dev/amr/amr.c b/sys/dev/amr/amr.c
index 2061fcc..688b2df 100644
--- a/sys/dev/amr/amr.c
+++ b/sys/dev/amr/amr.c
@@ -90,6 +90,10 @@ __FBSDID("$FreeBSD$");
SYSCTL_NODE(_hw, OID_AUTO, amr, CTLFLAG_RD, 0, "AMR driver parameters");
+/*
+ * In order to get rid of Giant, amr_state should be protected by
+ * a proper softc lock for the cdev operations.
+ */
static d_open_t amr_open;
static d_close_t amr_close;
static d_ioctl_t amr_ioctl;
@@ -312,9 +316,11 @@ amr_startup(void *arg)
config_intrhook_disestablish(&sc->amr_ich);
sc->amr_ich.ich_func = NULL;
+ newbus_xlock();
/* get up-to-date drive information */
if (amr_query_controller(sc)) {
device_printf(sc->amr_dev, "can't scan controller for drives\n");
+ newbus_xunlock();
return;
}
@@ -347,6 +353,7 @@ amr_startup(void *arg)
/* interrupts will be enabled before we do anything more */
sc->amr_state |= AMR_STATE_INTEN;
+ newbus_xunlock();
/*
* Start the timeout routine.
@@ -434,7 +441,11 @@ static int
amr_open(struct cdev *dev, int flags, int fmt, struct thread *td)
{
int unit = dev2unit(dev);
- struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
+ struct amr_softc *sc;
+
+ newbus_slock();
+ sc = devclass_get_softc(devclass_find("amr"), unit);
+ newbus_sunlock();
debug_called(1);
@@ -490,7 +501,11 @@ static int
amr_close(struct cdev *dev, int flags, int fmt, struct thread *td)
{
int unit = dev2unit(dev);
- struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
+ struct amr_softc *sc;
+
+ newbus_slock();
+ sc = devclass_get_softc(devclass_find("amr"), unit);
+ newbus_sunlock();
debug_called(1);
@@ -507,6 +522,7 @@ amr_rescan_drives(struct cdev *dev)
struct amr_softc *sc = (struct amr_softc *)dev->si_drv1;
int i, error = 0;
+ newbus_xlock();
sc->amr_state |= AMR_STATE_REMAP_LD;
while (sc->amr_busyslots) {
device_printf(sc->amr_dev, "idle controller\n");
@@ -530,6 +546,7 @@ amr_rescan_drives(struct cdev *dev)
sc->amr_drive[i].al_disk = 0;
}
}
+ newbus_xunlock();
shutdown_out:
amr_startup(sc);
@@ -805,7 +822,9 @@ amr_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, struct threa
struct amr_linux_ioctl ali;
int adapter, error;
+ newbus_slock();
devclass = devclass_find("amr");
+ newbus_sunlock();
if (devclass == NULL)
return (ENOENT);
OpenPOWER on IntegriCloud