From 0b7ed341e106c1583e873116529015d2ae042fd0 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Wed, 18 Feb 2004 21:36:53 +0000 Subject: 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. --- sys/dev/ata/atapi-fd.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'sys/dev/ata/atapi-fd.c') diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index be31d10f1cb9..0cba39acb1d7 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; } -- cgit v1.3