diff options
author | phk <phk@FreeBSD.org> | 2004-02-18 21:36:53 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-02-18 21:36:53 +0000 |
commit | 49c92e5706ab055d53ea35d401f4310fc07ff74a (patch) | |
tree | 16cf67c25fa19d01be97b31241d2c56e85a88674 /sys/geom | |
parent | 7ca155be2a4009e2ad701b61538e8376c49a7403 (diff) | |
download | FreeBSD-src-49c92e5706ab055d53ea35d401f4310fc07ff74a.zip FreeBSD-src-49c92e5706ab055d53ea35d401f4310fc07ff74a.tar.gz |
Change the disk(9) API in order to make device removal more robust.
Previously the "struct disk" were owned by the device driver and this
gave us problems when the device disappared and the users of that device
were not immediately disappearing.
Now the struct disk is allocate with a new call, disk_alloc() and owned
by geom_disk and just abandonned by the device driver when disk_create()
is called.
Unfortunately, this results in a ton of "s/\./->/" changes to device
drivers.
Since I'm doing the sweep anyway, a couple of other API improvements
have been carried out at the same time:
The Giant awareness flag has been flipped from DISKFLAG_NOGIANT to
DISKFLAG_NEEDSGIANT
A version number have been added to disk_create() so that we can detect,
report and ignore binary drivers with old ABI in the future.
Manual page update to follow shortly.
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/geom_disk.c | 54 | ||||
-rw-r--r-- | sys/geom/geom_disk.h | 8 |
2 files changed, 37 insertions, 25 deletions
diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index b539940..aee02eb 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -87,17 +87,15 @@ DECLARE_GEOM_CLASS(g_disk_class, g_disk); static void __inline g_disk_lock_giant(struct disk *dp) { - if (dp->d_flags & DISKFLAG_NOGIANT) - return; - mtx_lock(&Giant); + if (dp->d_flags & DISKFLAG_NEEDSGIANT) + mtx_lock(&Giant); } static void __inline g_disk_unlock_giant(struct disk *dp) { - if (dp->d_flags & DISKFLAG_NOGIANT) - return; - mtx_unlock(&Giant); + if (dp->d_flags & DISKFLAG_NEEDSGIANT) + mtx_unlock(&Giant); } static int @@ -110,15 +108,14 @@ g_disk_access(struct g_provider *pp, int r, int w, int e) pp->name, r, w, e); g_topology_assert(); dp = pp->geom->softc; - if (dp == NULL) { + if (dp == NULL || dp->d_destroyed) { /* * Allow decreasing access count even if disk is not * avaliable anymore. */ if (r <= 0 && w <= 0 && e <= 0) return (0); - else - return (ENXIO); + return (ENXIO); } r += pp->acr; w += pp->acw; @@ -233,7 +230,7 @@ g_disk_start(struct bio *bp) off_t off; dp = bp->bio_to->geom->softc; - if (dp == NULL) + if (dp == NULL || dp->d_destroyed) g_io_deliver(bp, ENXIO); error = EJUSTRETURN; switch(bp->bio_cmd) { @@ -358,20 +355,37 @@ g_disk_create(void *arg, int flag) static void g_disk_destroy(void *ptr, int flag) { + struct disk *dp; struct g_geom *gp; g_topology_assert(); - gp = ptr; + dp = ptr; + gp = dp->d_geom; gp->softc = NULL; g_wither_geom(gp, ENXIO); + g_free(dp); } -void -disk_create(int unit, struct disk *dp, int flags, void *unused __unused, void * unused2 __unused) +struct disk * +disk_alloc() { + struct disk *dp; + + dp = g_malloc(sizeof *dp, M_WAITOK | M_ZERO); + return (dp); +} - dp->d_unit = unit; - dp->d_flags = flags; +void +disk_create(struct disk *dp, int version) +{ + if (version != DISK_VERSION_00) { + printf("WARNING: Attempt to add disk %s%d %s", + dp->d_name, dp->d_unit, + " using incompatible ABI version of disk(9)\n"); + printf("WARNING: Ignoring disk %s%d\n", + dp->d_name, dp->d_unit); + return; + } KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy")); KASSERT(dp->d_name != NULL, ("disk_create need d_name")); KASSERT(*dp->d_name != 0, ("disk_create need d_name")); @@ -387,16 +401,10 @@ disk_create(int unit, struct disk *dp, int flags, void *unused __unused, void * void disk_destroy(struct disk *dp) { - struct g_geom *gp; g_cancel_event(dp); - gp = dp->d_geom; - if (gp == NULL) - return; - gp->softc = NULL; - devstat_remove_entry(dp->d_devstat); - g_waitfor_event(g_disk_destroy, gp, M_WAITOK, NULL, NULL); - dp->d_geom = NULL; + dp->d_destroyed = 1; + g_post_event(g_disk_destroy, dp, M_WAITOK, NULL, NULL); } static void diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h index 712e871..a94df89 100644 --- a/sys/geom/geom_disk.h +++ b/sys/geom/geom_disk.h @@ -57,6 +57,7 @@ struct disk { /* Fields which are private to geom_disk */ struct g_geom *d_geom; struct devstat *d_devstat; + int d_destroyed; /* Shared fields */ u_int d_flags; @@ -85,13 +86,16 @@ struct disk { void *d_drv1; }; -#define DISKFLAG_NOGIANT 0x1 +#define DISKFLAG_NEEDSGIANT 0x1 #define DISKFLAG_OPEN 0x2 #define DISKFLAG_CANDELETE 0x4 -void disk_create(int unit, struct disk *disk, int flags, void *unused, void *unused2); +struct disk *disk_alloc(void); +void disk_create(struct disk *disk, int version); void disk_destroy(struct disk *disk); +#define DISK_VERSION_00 0x58561059 +#define DISK_VERSION DISK_VERSION_00 #endif /* _KERNEL */ #endif /* _GEOM_GEOM_DISK_H_ */ |