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/dev/ata | |
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/dev/ata')
-rw-r--r-- | sys/dev/ata/ata-disk.c | 30 | ||||
-rw-r--r-- | sys/dev/ata/ata-disk.h | 2 | ||||
-rw-r--r-- | sys/dev/ata/ata-raid.c | 43 | ||||
-rw-r--r-- | sys/dev/ata/ata-raid.h | 2 | ||||
-rw-r--r-- | sys/dev/ata/atapi-fd.c | 30 | ||||
-rw-r--r-- | sys/dev/ata/atapi-fd.h | 2 |
6 files changed, 58 insertions, 51 deletions
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c index 25b9ef9..504049f 100644 --- a/sys/dev/ata/ata-disk.c +++ b/sys/dev/ata/ata-disk.c @@ -131,20 +131,22 @@ ad_attach(struct ata_device *atadev) ad_config(atadev); /* lets create the disk device */ - adp->disk.d_open = adopen; - adp->disk.d_strategy = adstrategy; - adp->disk.d_dump = addump; - adp->disk.d_name = "ad"; - adp->disk.d_drv1 = adp; + adp->disk = disk_alloc(); + adp->disk->d_open = adopen; + adp->disk->d_strategy = adstrategy; + adp->disk->d_dump = addump; + adp->disk->d_name = "ad"; + adp->disk->d_drv1 = adp; if (atadev->channel->dma) - adp->disk.d_maxsize = atadev->channel->dma->max_iosize; + adp->disk->d_maxsize = atadev->channel->dma->max_iosize; else - adp->disk.d_maxsize = DFLTPHYS; - adp->disk.d_sectorsize = DEV_BSIZE; - adp->disk.d_mediasize = DEV_BSIZE * (off_t)adp->total_secs; - adp->disk.d_fwsectors = adp->sectors; - adp->disk.d_fwheads = adp->heads; - disk_create(adp->lun, &adp->disk, DISKFLAG_NOGIANT, NULL, NULL); + adp->disk->d_maxsize = DFLTPHYS; + adp->disk->d_sectorsize = DEV_BSIZE; + adp->disk->d_mediasize = DEV_BSIZE * (off_t)adp->total_secs; + adp->disk->d_fwsectors = adp->sectors; + adp->disk->d_fwheads = adp->heads; + adp->disk->d_unit = adp->lun; + disk_create(adp->disk, DISK_VERSION); /* announce we are here */ ad_print(adp); @@ -167,7 +169,7 @@ ad_detach(struct ata_device *atadev) mtx_lock(&adp->queue_mtx); bioq_flush(&adp->queue, NULL, ENXIO); mtx_unlock(&adp->queue_mtx); - disk_destroy(&adp->disk); + disk_destroy(adp->disk); ata_prtdev(atadev, "WARNING - removed from configuration\n"); ata_free_name(atadev); ata_free_lun(&adp_lun_map, adp->lun); @@ -208,7 +210,7 @@ adopen(struct disk *dp) { struct ad_softc *adp = dp->d_drv1; - if (adp->device->flags & ATA_D_DETACHING) + if (adp == NULL || adp->device->flags & ATA_D_DETACHING) return ENXIO; return 0; } diff --git a/sys/dev/ata/ata-disk.h b/sys/dev/ata/ata-disk.h index 1373fd2..778169c 100644 --- a/sys/dev/ata/ata-disk.h +++ b/sys/dev/ata/ata-disk.h @@ -47,5 +47,5 @@ struct ad_softc { struct mtx queue_mtx; /* queue lock */ struct bio_queue_head queue; /* head of request queue */ - struct disk disk; /* disklabel/slice stuff */ + struct disk *disk; /* disklabel/slice stuff */ }; diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c index ba720af..be57886d 100644 --- a/sys/dev/ata/ata-raid.c +++ b/sys/dev/ata/ata-raid.c @@ -177,16 +177,19 @@ ar_attach_raid(struct ar_softc *rdp, int update) int disk; ar_config_changed(rdp, update); - rdp->disk.d_strategy = arstrategy; - rdp->disk.d_dump = ardump; - rdp->disk.d_name = "ar"; - rdp->disk.d_sectorsize = DEV_BSIZE; - rdp->disk.d_mediasize = (off_t)rdp->total_sectors * DEV_BSIZE; - rdp->disk.d_fwsectors = rdp->sectors; - rdp->disk.d_fwheads = rdp->heads; - rdp->disk.d_maxsize = 128 * DEV_BSIZE; - rdp->disk.d_drv1 = rdp; - disk_create(rdp->lun, &rdp->disk, 0, NULL, NULL); + rdp->disk = disk_alloc(); + rdp->disk->d_strategy = arstrategy; + rdp->disk->d_dump = ardump; + rdp->disk->d_name = "ar"; + rdp->disk->d_sectorsize = DEV_BSIZE; + rdp->disk->d_mediasize = (off_t)rdp->total_sectors * DEV_BSIZE; + rdp->disk->d_fwsectors = rdp->sectors; + rdp->disk->d_fwheads = rdp->heads; + rdp->disk->d_maxsize = 128 * DEV_BSIZE; + rdp->disk->d_drv1 = rdp; + rdp->disk->d_unit = rdp->lun; + rdp->disk->d_flags = DISKFLAG_NEEDSGIANT; + disk_create(rdp->disk, DISK_VERSION); printf("ar%d: %lluMB <ATA ", rdp->lun, (unsigned long long) (rdp->total_sectors / ((1024L * 1024L) / DEV_BSIZE))); @@ -457,7 +460,7 @@ ata_raid_delete(int array) ar_promise_write_conf(rdp); else ar_highpoint_write_conf(rdp); - disk_destroy(&rdp->disk); + disk_destroy(rdp->disk); free(rdp, M_AR); ar_table[array] = NULL; return 0; @@ -538,7 +541,7 @@ ardump(void *arg, void *virtual, vm_offset_t physical, if (length == 0) { for (drv = 0; drv < rdp->total_disks; drv++) { if (rdp->disks[drv].flags & AR_DF_ONLINE) { - ap = &AD_SOFTC(rdp->disks[drv])->disk; + ap = AD_SOFTC(rdp->disks[drv])->disk; (void) ap->d_dump(ap, NULL, 0, 0, 0); } } @@ -603,7 +606,7 @@ ardump(void *arg, void *virtual, vm_offset_t physical, case AR_F_SPAN: case AR_F_RAID0: if (rdp->disks[drv].flags & AR_DF_ONLINE) { - ap = &AD_SOFTC(rdp->disks[drv])->disk; + ap = AD_SOFTC(rdp->disks[drv])->disk; error1 = ap->d_dump(ap, vdata, pdata, (off_t) lba * DEV_BSIZE, chunk * DEV_BSIZE); @@ -618,7 +621,7 @@ ardump(void *arg, void *virtual, vm_offset_t physical, if ((rdp->disks[drv].flags & AR_DF_ONLINE) || ((rdp->flags & AR_F_REBUILDING) && (rdp->disks[drv].flags & AR_DF_SPARE))) { - ap = &AD_SOFTC(rdp->disks[drv])->disk; + ap = AD_SOFTC(rdp->disks[drv])->disk; error1 = ap->d_dump(ap, vdata, pdata, (off_t) lba * DEV_BSIZE, chunk * DEV_BSIZE); @@ -627,7 +630,7 @@ ardump(void *arg, void *virtual, vm_offset_t physical, if ((rdp->disks[drv + rdp->width].flags & AR_DF_ONLINE) || ((rdp->flags & AR_F_REBUILDING) && (rdp->disks[drv + rdp->width].flags & AR_DF_SPARE))) { - ap = &AD_SOFTC(rdp->disks[drv + rdp->width])->disk; + ap = AD_SOFTC(rdp->disks[drv + rdp->width])->disk; error2 = ap->d_dump(ap, vdata, pdata, (off_t) lba * DEV_BSIZE, chunk * DEV_BSIZE); @@ -739,7 +742,7 @@ arstrategy(struct bio *bp) biodone(bp); return; } - buf1->bp.bio_disk = &AD_SOFTC(rdp->disks[buf1->drive])->disk; + buf1->bp.bio_disk = AD_SOFTC(rdp->disks[buf1->drive])->disk; AR_STRATEGY((struct bio *)buf1); break; @@ -827,7 +830,7 @@ arstrategy(struct bio *bp) buf2->mirror = buf1; buf2->drive = buf1->drive + rdp->width; buf2->bp.bio_disk = - &AD_SOFTC(rdp->disks[buf2->drive])->disk; + AD_SOFTC(rdp->disks[buf2->drive])->disk; AR_STRATEGY((struct bio *)buf2); rdp->disks[buf2->drive].last_lba = buf2->bp.bio_pblkno + chunk; @@ -836,7 +839,7 @@ arstrategy(struct bio *bp) buf1->drive = buf1->drive + rdp->width; } } - buf1->bp.bio_disk = &AD_SOFTC(rdp->disks[buf1->drive])->disk; + buf1->bp.bio_disk = AD_SOFTC(rdp->disks[buf1->drive])->disk; AR_STRATEGY((struct bio *)buf1); rdp->disks[buf1->drive].last_lba = buf1->bp.bio_pblkno + chunk; break; @@ -881,7 +884,7 @@ ar_done(struct bio *bp) buf->drive = buf->drive + rdp->width; else buf->drive = buf->drive - rdp->width; - buf->bp.bio_disk = &AD_SOFTC(rdp->disks[buf->drive])->disk; + buf->bp.bio_disk = AD_SOFTC(rdp->disks[buf->drive])->disk; buf->bp.bio_flags = buf->org->bio_flags; buf->bp.bio_error = 0; AR_STRATEGY((struct bio *)buf); @@ -1629,7 +1632,7 @@ ar_rw(struct ad_softc *adp, u_int32_t lba, int count, caddr_t data, int flags) if (!(bp = (struct bio *)malloc(sizeof(struct bio), M_AR, M_NOWAIT|M_ZERO))) return 1; - bp->bio_disk = &adp->disk; + bp->bio_disk = adp->disk; bp->bio_data = data; bp->bio_pblkno = lba; bp->bio_bcount = count; diff --git a/sys/dev/ata/ata-raid.h b/sys/dev/ata/ata-raid.h index 9af598e..9c71fa3 100644 --- a/sys/dev/ata/ata-raid.h +++ b/sys/dev/ata/ata-raid.h @@ -79,7 +79,7 @@ struct ar_softc { int offset; /* offset from start of disk */ u_int64_t lock_start; /* start of locked area for rebuild */ u_int64_t lock_end; /* end of locked area for rebuild */ - struct disk disk; /* disklabel/slice stuff */ + struct disk *disk; /* disklabel/slice stuff */ struct proc *pid; /* rebuilder process id */ }; diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index be31d10..0cba39a 100644 --- a/sys/dev/ata/atapi-fd.c +++ b/sys/dev/ata/atapi-fd.c @@ -96,19 +96,21 @@ afd_attach(struct ata_device *atadev) atadev->flags |= ATA_D_MEDIA_CHANGED; /* lets create the disk device */ - fdp->disk.d_open = afd_open; - fdp->disk.d_close = afd_close; + fdp->disk = disk_alloc(); + fdp->disk->d_open = afd_open; + fdp->disk->d_close = afd_close; #ifdef notyet - fdp->disk.d_ioctl = afd_ioctl; + fdp->disk->d_ioctl = afd_ioctl; #endif - fdp->disk.d_strategy = afdstrategy; - fdp->disk.d_name = "afd"; - fdp->disk.d_drv1 = fdp; + fdp->disk->d_strategy = afdstrategy; + fdp->disk->d_name = "afd"; + fdp->disk->d_drv1 = fdp; if (atadev->channel->dma) - fdp->disk.d_maxsize = atadev->channel->dma->max_iosize; + fdp->disk->d_maxsize = atadev->channel->dma->max_iosize; else - fdp->disk.d_maxsize = DFLTPHYS; - disk_create(fdp->lun, &fdp->disk, DISKFLAG_NOGIANT, NULL, NULL); + fdp->disk->d_maxsize = DFLTPHYS; + fdp->disk->d_unit = fdp->lun; + disk_create(fdp->disk, DISK_VERSION); /* announce we are here */ afd_describe(fdp); @@ -122,7 +124,7 @@ afd_detach(struct ata_device *atadev) mtx_lock(&fdp->queue_mtx); bioq_flush(&fdp->queue, NULL, ENXIO); mtx_unlock(&fdp->queue_mtx); - disk_destroy(&fdp->disk); + disk_destroy(fdp->disk); ata_prtdev(atadev, "WARNING - removed from configuration\n"); ata_free_name(atadev); ata_free_lun(&afd_lun_map, fdp->lun); @@ -233,11 +235,11 @@ afd_open(struct disk *dp) fdp->device->flags &= ~ATA_D_MEDIA_CHANGED; - fdp->disk.d_sectorsize = fdp->cap.sector_size; - fdp->disk.d_mediasize = (off_t)fdp->cap.sector_size * fdp->cap.sectors * + fdp->disk->d_sectorsize = fdp->cap.sector_size; + fdp->disk->d_mediasize = (off_t)fdp->cap.sector_size * fdp->cap.sectors * fdp->cap.heads * fdp->cap.cylinders; - fdp->disk.d_fwsectors = fdp->cap.sectors; - fdp->disk.d_fwheads = fdp->cap.heads; + fdp->disk->d_fwsectors = fdp->cap.sectors; + fdp->disk->d_fwheads = fdp->cap.heads; return 0; } diff --git a/sys/dev/ata/atapi-fd.h b/sys/dev/ata/atapi-fd.h index 90223f4..e51d1c3 100644 --- a/sys/dev/ata/atapi-fd.h +++ b/sys/dev/ata/atapi-fd.h @@ -74,6 +74,6 @@ struct afd_softc { struct mtx queue_mtx; /* queue lock */ struct bio_queue_head queue; /* queue of i/o requests */ struct afd_cappage cap; /* capabilities page info */ - struct disk disk; /* virtual drives */ + struct disk *disk; /* virtual drives */ }; |