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.
This commit is contained in:
phk 2004-02-18 21:36:53 +00:00
parent 7ca155be2a
commit 49c92e5706
28 changed files with 335 additions and 273 deletions

View File

@ -159,7 +159,7 @@ struct cd_softc {
struct sysctl_oid *sysctl_tree;
STAILQ_HEAD(, cd_mode_params) mode_queue;
struct cd_tocdata toc;
struct disk disk;
struct disk *disk;
};
struct cd_page_sizes {
@ -498,7 +498,7 @@ cdcleanup(struct cam_periph *periph)
free(softc->changer, M_DEVBUF);
num_changers--;
}
disk_destroy(&softc->disk);
disk_destroy(softc->disk);
free(softc, M_DEVBUF);
splx(s);
}
@ -736,18 +736,21 @@ cdregister(struct cam_periph *periph, void *arg)
* WORM peripheral driver. WORM drives will also have the WORM
* driver attached to them.
*/
softc->disk.d_devstat = devstat_new_entry("cd",
softc->disk = disk_alloc();
softc->disk->d_devstat = devstat_new_entry("cd",
periph->unit_number, 0,
DEVSTAT_BS_UNAVAILABLE,
DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI,
DEVSTAT_PRIORITY_CD);
softc->disk.d_open = cdopen;
softc->disk.d_close = cdclose;
softc->disk.d_strategy = cdstrategy;
softc->disk.d_ioctl = cdioctl;
softc->disk.d_name = "cd";
disk_create(periph->unit_number, &softc->disk, 0, NULL, NULL);
softc->disk.d_drv1 = periph;
softc->disk->d_open = cdopen;
softc->disk->d_close = cdclose;
softc->disk->d_strategy = cdstrategy;
softc->disk->d_ioctl = cdioctl;
softc->disk->d_name = "cd";
softc->disk->d_unit = periph->unit_number;
softc->disk->d_drv1 = periph;
softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(softc->disk, DISK_VERSION);
/*
* Add an async callback so that we get
@ -1059,7 +1062,7 @@ cdclose(struct disk *dp)
* Since we're closing this CD, mark the blocksize as unavailable.
* It will be marked as available when the CD is opened again.
*/
softc->disk.d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
/*
* We'll check the media and toc again at the next open().
@ -1353,7 +1356,7 @@ cdrunccb(union ccb *ccb, int (*error_routine)(union ccb *ccb,
softc = (struct cd_softc *)periph->softc;
error = cam_periph_runccb(ccb, error_routine, cam_flags, sense_flags,
softc->disk.d_devstat);
softc->disk->d_devstat);
if (softc->flags & CD_FLAG_CHANGER)
cdchangerschedule(softc);
@ -1509,7 +1512,7 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
} else {
bioq_remove(&softc->bio_queue, bp);
devstat_start_transaction_bio(softc->disk.d_devstat, bp);
devstat_start_transaction_bio(softc->disk->d_devstat, bp);
scsi_read_write(&start_ccb->csio,
/*retries*/4,
@ -1665,7 +1668,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
if (softc->flags & CD_FLAG_CHANGER)
cdchangerschedule(softc);
biofinish(bp, softc->disk.d_devstat, 0);
biofinish(bp, softc->disk->d_devstat, 0);
break;
}
case CD_CCB_PROBE:
@ -2719,9 +2722,9 @@ cdcheckmedia(struct cam_periph *periph)
softc = (struct cd_softc *)periph->softc;
cdprevent(periph, PR_PREVENT);
softc->disk.d_maxsize = DFLTPHYS;
softc->disk.d_sectorsize = 0;
softc->disk.d_mediasize = 0;
softc->disk->d_maxsize = DFLTPHYS;
softc->disk->d_sectorsize = 0;
softc->disk->d_mediasize = 0;
/*
* Get the disc size and block size. If we can't get it, we don't
@ -2821,9 +2824,9 @@ cdcheckmedia(struct cam_periph *periph)
}
softc->flags |= CD_FLAG_VALID_TOC;
softc->disk.d_maxsize = DFLTPHYS;
softc->disk.d_sectorsize = softc->params.blksize;
softc->disk.d_mediasize =
softc->disk->d_maxsize = DFLTPHYS;
softc->disk->d_sectorsize = softc->params.blksize;
softc->disk->d_mediasize =
(off_t)softc->params.blksize * softc->params.disksize;
bailout:
@ -2835,9 +2838,9 @@ cdcheckmedia(struct cam_periph *periph)
* XXX problems here if some slice or partition is still
* open with the old size?
*/
if ((softc->disk.d_devstat->flags & DEVSTAT_BS_UNAVAILABLE) != 0)
softc->disk.d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
softc->disk.d_devstat->block_size = softc->params.blksize;
if ((softc->disk->d_devstat->flags & DEVSTAT_BS_UNAVAILABLE) != 0)
softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
softc->disk->d_devstat->block_size = softc->params.blksize;
return (error);
}

View File

@ -133,7 +133,7 @@ struct da_softc {
int ordered_tag_count;
int outstanding_cmds;
struct disk_params params;
struct disk disk;
struct disk *disk;
union ccb saved_ccb;
struct task sysctl_task;
struct sysctl_ctx_list sysctl_ctx;
@ -493,13 +493,13 @@ daopen(struct disk *dp)
if (error == 0) {
softc->disk.d_sectorsize = softc->params.secsize;
softc->disk.d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
softc->disk->d_sectorsize = softc->params.secsize;
softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
/* XXX: these are not actually "firmware" values, so they may be wrong */
softc->disk.d_fwsectors = softc->params.secs_per_track;
softc->disk.d_fwheads = softc->params.heads;
softc->disk.d_devstat->block_size = softc->params.secsize;
softc->disk.d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
softc->disk->d_fwsectors = softc->params.secs_per_track;
softc->disk->d_fwheads = softc->params.heads;
softc->disk->d_devstat->block_size = softc->params.secsize;
softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
}
if (error == 0) {
@ -547,7 +547,7 @@ daclose(struct disk *dp)
cam_periph_runccb(ccb, /*error_routine*/NULL, /*cam_flags*/0,
/*sense_flags*/SF_RETRY_UA,
softc->disk.d_devstat);
softc->disk->d_devstat);
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
@ -589,7 +589,7 @@ daclose(struct disk *dp)
* unavailable, since it could change when new media is
* inserted.
*/
softc->disk.d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
}
softc->flags &= ~DA_FLAG_OPEN;
@ -851,7 +851,7 @@ dacleanup(struct cam_periph *periph)
xpt_print_path(periph->path);
printf("can't remove sysctl context\n");
}
disk_destroy(&softc->disk);
disk_destroy(softc->disk);
free(softc, M_DEVBUF);
}
@ -1091,14 +1091,17 @@ daregister(struct cam_periph *periph, void *arg)
* Register this media as a disk
*/
softc->disk.d_open = daopen;
softc->disk.d_close = daclose;
softc->disk.d_strategy = dastrategy;
softc->disk.d_dump = dadump;
softc->disk.d_name = "da";
softc->disk.d_drv1 = periph;
softc->disk.d_maxsize = DFLTPHYS; /* XXX: probably not arbitrary */
disk_create(periph->unit_number, &softc->disk, 0, NULL, NULL);
softc->disk = disk_alloc();
softc->disk->d_open = daopen;
softc->disk->d_close = daclose;
softc->disk->d_strategy = dastrategy;
softc->disk->d_dump = dadump;
softc->disk->d_name = "da";
softc->disk->d_drv1 = periph;
softc->disk->d_maxsize = DFLTPHYS; /* XXX: probably not arbitrary */
softc->disk->d_unit = periph->unit_number;
softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(softc->disk, DISK_VERSION);
/*
* Add async callbacks for bus reset and
@ -1666,7 +1669,7 @@ daprevent(struct cam_periph *periph, int action)
5000);
error = cam_periph_runccb(ccb, /*error_routine*/NULL, CAM_RETRY_SELTO,
SF_RETRY_UA, softc->disk.d_devstat);
SF_RETRY_UA, softc->disk->d_devstat);
if (error == 0) {
if (action == PR_ALLOW)
@ -1712,7 +1715,7 @@ dagetcapacity(struct cam_periph *periph)
error = cam_periph_runccb(ccb, daerror,
/*cam_flags*/CAM_RETRY_SELTO,
/*sense_flags*/SF_RETRY_UA,
softc->disk.d_devstat);
softc->disk->d_devstat);
if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
cam_release_devq(ccb->ccb_h.path,
@ -1747,7 +1750,7 @@ dagetcapacity(struct cam_periph *periph)
error = cam_periph_runccb(ccb, daerror,
/*cam_flags*/CAM_RETRY_SELTO,
/*sense_flags*/SF_RETRY_UA,
softc->disk.d_devstat);
softc->disk->d_devstat);
if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
cam_release_devq(ccb->ccb_h.path,

View File

@ -78,7 +78,7 @@ static struct fla_s {
unsigned nsect;
struct doc2k_stat ds;
struct bio_queue_head bio_queue;
struct disk disk;
struct disk *disk;
dev_t dev;
} softc[8];
@ -99,10 +99,10 @@ flaopen(struct disk *dp)
}
error = doc2k_size(sc->unit, &spu, &ncyl, &nt, &ns);
sc->disk.d_sectorsize = DEV_BSIZE;
sc->disk.d_mediasize = (off_t)spu * DEV_BSIZE;
sc->disk.d_fwsectors = ns;
sc->disk.d_fwheads = nt;
sc->disk->d_sectorsize = DEV_BSIZE;
sc->disk->d_mediasize = (off_t)spu * DEV_BSIZE;
sc->disk->d_fwsectors = ns;
sc->disk->d_fwheads = nt;
return (0);
}
@ -255,14 +255,17 @@ flaattach (device_t dev)
bioq_init(&sc->bio_queue);
sc->disk.d_open = flaopen;
sc->disk.d_close = flaclose;
sc->disk.d_strategy = flastrategy;
sc->disk.d_drv1 = sc;
sc->disk.d_name = "fla";
sc->disk.d_maxsize = MAXPHYS;
sc->disk = disk_alloc();
sc->disk->d_open = flaopen;
sc->disk->d_close = flaclose;
sc->disk->d_strategy = flastrategy;
sc->disk->d_drv1 = sc;
sc->disk->d_name = "fla";
sc->disk->d_maxsize = MAXPHYS;
sc->unit = unit;
disk_create(unit, &sc->disk, DISKFLAG_CANDELETE, NULL, NULL);
sc->disk->d_unit = unit;
sc->disk->d_flags = DISKFLAG_CANDELETE | DISKFLAG_NEEDSGIANT;
disk_create(sc->disk, DISK_VERSION);
return (0);
}

View File

@ -2875,7 +2875,7 @@ aac_query_disk(struct aac_softc *sc, caddr_t uptr)
query_disk.Lun = 0;
query_disk.UnMapped = 0;
sprintf(&query_disk.diskDeviceName[0], "%s%d",
disk->ad_disk.d_name, disk->ad_disk.d_unit);
disk->ad_disk->d_name, disk->ad_disk->d_unit);
}
AAC_LOCK_RELEASE(&sc->aac_container_lock);

View File

@ -357,18 +357,20 @@ aac_disk_attach(device_t dev)
/* attach a generic disk device to ourselves */
sc->unit = device_get_unit(dev);
sc->ad_disk.d_drv1 = sc;
sc->ad_disk.d_name = "aacd";
sc->ad_disk.d_maxsize = aac_iosize_max;
sc->ad_disk.d_open = aac_disk_open;
sc->ad_disk.d_close = aac_disk_close;
sc->ad_disk.d_strategy = aac_disk_strategy;
sc->ad_disk.d_dump = aac_disk_dump;
sc->ad_disk.d_sectorsize = AAC_BLOCK_SIZE;
sc->ad_disk.d_mediasize = (off_t)sc->ad_size * AAC_BLOCK_SIZE;
sc->ad_disk.d_fwsectors = sc->ad_sectors;
sc->ad_disk.d_fwheads = sc->ad_heads;
disk_create(sc->unit, &sc->ad_disk, DISKFLAG_NOGIANT, NULL, NULL);
sc->ad_disk = disk_alloc();
sc->ad_disk->d_drv1 = sc;
sc->ad_disk->d_name = "aacd";
sc->ad_disk->d_maxsize = aac_iosize_max;
sc->ad_disk->d_open = aac_disk_open;
sc->ad_disk->d_close = aac_disk_close;
sc->ad_disk->d_strategy = aac_disk_strategy;
sc->ad_disk->d_dump = aac_disk_dump;
sc->ad_disk->d_sectorsize = AAC_BLOCK_SIZE;
sc->ad_disk->d_mediasize = (off_t)sc->ad_size * AAC_BLOCK_SIZE;
sc->ad_disk->d_fwsectors = sc->ad_sectors;
sc->ad_disk->d_fwheads = sc->ad_heads;
sc->ad_disk->d_unit = sc->unit;
disk_create(sc->ad_disk, DISK_VERSION);
return (0);
}
@ -388,7 +390,7 @@ aac_disk_detach(device_t dev)
if (sc->ad_flags & AAC_DISK_OPEN)
return(EBUSY);
disk_destroy(&sc->ad_disk);
disk_destroy(sc->ad_disk);
return(0);
}

View File

@ -125,7 +125,7 @@ struct aac_disk
device_t ad_dev;
struct aac_softc *ad_controller;
struct aac_container *ad_container;
struct disk ad_disk;
struct disk *ad_disk;
int ad_flags;
#define AAC_DISK_OPEN (1<<0)
int ad_cylinders;

View File

@ -134,10 +134,10 @@ amrd_open(struct disk *dp)
label->d_secpercyl = sc->amrd_drive->al_sectors * sc->amrd_drive->al_heads;
label->d_secperunit = sc->amrd_drive->al_size;
#else
sc->amrd_disk.d_sectorsize = AMR_BLKSIZE;
sc->amrd_disk.d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE;
sc->amrd_disk.d_fwsectors = sc->amrd_drive->al_sectors;
sc->amrd_disk.d_fwheads = sc->amrd_drive->al_heads;
sc->amrd_disk->d_sectorsize = AMR_BLKSIZE;
sc->amrd_disk->d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE;
sc->amrd_disk->d_fwsectors = sc->amrd_drive->al_sectors;
sc->amrd_disk->d_fwheads = sc->amrd_drive->al_heads;
#endif
return (0);
@ -247,13 +247,16 @@ amrd_attach(device_t dev)
sc->amrd_drive->al_size, sc->amrd_drive->al_properties & AMR_DRV_RAID_MASK,
amr_describe_code(amr_table_drvstate, AMR_DRV_CURSTATE(sc->amrd_drive->al_state)));
sc->amrd_disk.d_drv1 = sc;
sc->amrd_disk.d_maxsize = (AMR_NSEG - 1) * PAGE_SIZE;
sc->amrd_disk.d_open = amrd_open;
sc->amrd_disk.d_strategy = amrd_strategy;
sc->amrd_disk.d_name = "amrd";
sc->amrd_disk.d_dump = (dumper_t *)amrd_dump;
disk_create(sc->amrd_unit, &sc->amrd_disk, 0, NULL, NULL);
sc->amrd_disk = disk_alloc();
sc->amrd_disk->d_drv1 = sc;
sc->amrd_disk->d_maxsize = (AMR_NSEG - 1) * PAGE_SIZE;
sc->amrd_disk->d_open = amrd_open;
sc->amrd_disk->d_strategy = amrd_strategy;
sc->amrd_disk->d_name = "amrd";
sc->amrd_disk->d_dump = (dumper_t *)amrd_dump;
sc->amrd_disk->d_unit = sc->amrd_unit;
sc->amrd_disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(sc->amrd_disk, DISK_VERSION);
#ifdef FREEBSD_4
disks_registered++;
#endif
@ -268,14 +271,14 @@ amrd_detach(device_t dev)
debug_called(1);
if (sc->amrd_disk.d_flags & DISKFLAG_OPEN)
if (sc->amrd_disk->d_flags & DISKFLAG_OPEN)
return(EBUSY);
#ifdef FREEBSD_4
if (--disks_registered == 0)
cdevsw_remove(&amrddisk_cdevsw);
#else
disk_destroy(&sc->amrd_disk);
disk_destroy(sc->amrd_disk);
#endif
return(0);
}

View File

@ -253,7 +253,7 @@ struct amrd_softc
device_t amrd_dev;
struct amr_softc *amrd_controller;
struct amr_logdrive *amrd_drive;
struct disk amrd_disk;
struct disk *amrd_disk;
int amrd_unit;
};

View File

@ -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;
}

View File

@ -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 */
};

View File

@ -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;

View File

@ -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 */
};

View File

@ -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;
}

View File

@ -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 */
};

View File

@ -203,16 +203,19 @@ idad_attach(device_t dev)
drv->secperunit / ((1024 * 1024) / drv->secsize),
drv->secperunit, drv->secsize);
drv->disk.d_strategy = idad_strategy;
drv->disk.d_name = "idad";
drv->disk.d_dump = idad_dump;
drv->disk.d_sectorsize = drv->secsize;
drv->disk.d_mediasize = (off_t)drv->secperunit * drv->secsize;
drv->disk.d_fwsectors = drv->sectors;
drv->disk.d_fwheads = drv->heads;
drv->disk.d_drv1 = drv;
drv->disk.d_maxsize = DFLTPHYS; /* XXX guess? */
disk_create(drv->unit, &drv->disk, 0, NULL, NULL);
drv->disk = disk_alloc();
drv->disk->d_strategy = idad_strategy;
drv->disk->d_name = "idad";
drv->disk->d_dump = idad_dump;
drv->disk->d_sectorsize = drv->secsize;
drv->disk->d_mediasize = (off_t)drv->secperunit * drv->secsize;
drv->disk->d_fwsectors = drv->sectors;
drv->disk->d_fwheads = drv->heads;
drv->disk->d_drv1 = drv;
drv->disk->d_maxsize = DFLTPHYS; /* XXX guess? */
drv->disk->d_unit = drv->unit;
drv->disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(drv->disk, DISK_VERSION);
return (0);
}
@ -223,6 +226,6 @@ idad_detach(device_t dev)
struct idad_softc *drv;
drv = (struct idad_softc *)device_get_softc(dev);
disk_destroy(&drv->disk);
disk_destroy(drv->disk);
return (0);
}

View File

@ -170,7 +170,7 @@ struct ida_softc {
struct idad_softc {
device_t dev;
struct ida_softc *controller;
struct disk disk;
struct disk *disk;
int drive; /* per controller */
int unit; /* global */
int cylinders;

View File

@ -122,25 +122,28 @@ static int ipsd_attach(device_t dev)
dsc->sc = device_get_softc(adapter);
dsc->unit = device_get_unit(dev);
dsc->disk_number = (uintptr_t) device_get_ivars(dev);
dsc->ipsd_disk.d_drv1 = dsc;
dsc->ipsd_disk.d_name = "ipsd";
dsc->ipsd_disk.d_maxsize = IPS_MAX_IO_SIZE;
dsc->ipsd_disk.d_open = ipsd_open;
dsc->ipsd_disk.d_close = ipsd_close;
dsc->ipsd_disk.d_strategy = ipsd_strategy;
dsc->ipsd_disk = disk_alloc();
dsc->ipsd_disk->d_drv1 = dsc;
dsc->ipsd_disk->d_name = "ipsd";
dsc->ipsd_disk->d_maxsize = IPS_MAX_IO_SIZE;
dsc->ipsd_disk->d_open = ipsd_open;
dsc->ipsd_disk->d_close = ipsd_close;
dsc->ipsd_disk->d_strategy = ipsd_strategy;
totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
if ((totalsectors > 0x400000) &&
((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
dsc->ipsd_disk.d_fwheads = IPS_NORM_HEADS;
dsc->ipsd_disk.d_fwsectors = IPS_NORM_SECTORS;
dsc->ipsd_disk->d_fwheads = IPS_NORM_HEADS;
dsc->ipsd_disk->d_fwsectors = IPS_NORM_SECTORS;
} else {
dsc->ipsd_disk.d_fwheads = IPS_COMP_HEADS;
dsc->ipsd_disk.d_fwsectors = IPS_COMP_SECTORS;
dsc->ipsd_disk->d_fwheads = IPS_COMP_HEADS;
dsc->ipsd_disk->d_fwsectors = IPS_COMP_SECTORS;
}
dsc->ipsd_disk.d_sectorsize = IPS_BLKSIZE;
dsc->ipsd_disk.d_mediasize = (off_t)totalsectors * IPS_BLKSIZE;
disk_create(dsc->unit, &dsc->ipsd_disk, 0, NULL, NULL);
dsc->ipsd_disk->d_sectorsize = IPS_BLKSIZE;
dsc->ipsd_disk->d_mediasize = (off_t)totalsectors * IPS_BLKSIZE;
dsc->ipsd_disk->d_unit = dsc->unit;
dsc->ipsd_disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(dsc->ipsd_disk, DISK_VERSION);
device_printf(dev, "Logical Drive (%dMB)\n",
dsc->sc->drives[dsc->disk_number].sector_count >> 11);
@ -155,7 +158,7 @@ static int ipsd_detach(device_t dev)
dsc = (ipsdisk_softc_t *)device_get_softc(dev);
if(dsc->state & IPS_DEV_OPEN)
return (EBUSY);
disk_destroy(&dsc->ipsd_disk);
disk_destroy(dsc->ipsd_disk);
return 0;
}

View File

@ -61,6 +61,6 @@ typedef struct ipsdisk_softc {
int unit;
int disk_number;
u_int32_t state;
struct disk ipsd_disk;
struct disk *ipsd_disk;
ips_softc_t *sc;
}ipsdisk_softc_t;

View File

@ -219,30 +219,33 @@ mlxd_attach(device_t dev)
sc->mlxd_drive->ms_size / ((1024 * 1024) / MLX_BLKSIZE),
sc->mlxd_drive->ms_size, sc->mlxd_drive->ms_raidlevel, state);
sc->mlxd_disk.d_open = mlxd_open;
sc->mlxd_disk.d_close = mlxd_close;
sc->mlxd_disk.d_ioctl = mlxd_ioctl;
sc->mlxd_disk.d_strategy = mlxd_strategy;
sc->mlxd_disk.d_name = "mlxd";
sc->mlxd_disk.d_drv1 = sc;
sc->mlxd_disk.d_sectorsize = MLX_BLKSIZE;
sc->mlxd_disk.d_mediasize = MLX_BLKSIZE * (off_t)sc->mlxd_drive->ms_size;
sc->mlxd_disk.d_fwsectors = sc->mlxd_drive->ms_sectors;
sc->mlxd_disk.d_fwheads = sc->mlxd_drive->ms_heads;
sc->mlxd_disk = disk_alloc();
sc->mlxd_disk->d_open = mlxd_open;
sc->mlxd_disk->d_close = mlxd_close;
sc->mlxd_disk->d_ioctl = mlxd_ioctl;
sc->mlxd_disk->d_strategy = mlxd_strategy;
sc->mlxd_disk->d_name = "mlxd";
sc->mlxd_disk->d_unit = sc->mlxd_unit;
sc->mlxd_disk->d_drv1 = sc;
sc->mlxd_disk->d_sectorsize = MLX_BLKSIZE;
sc->mlxd_disk->d_mediasize = MLX_BLKSIZE * (off_t)sc->mlxd_drive->ms_size;
sc->mlxd_disk->d_fwsectors = sc->mlxd_drive->ms_sectors;
sc->mlxd_disk->d_fwheads = sc->mlxd_drive->ms_heads;
sc->mlxd_disk->d_flags = DISKFLAG_NEEDSGIANT;
/*
* Set maximum I/O size to the lesser of the recommended maximum and the practical
* maximum except on v2 cards where the maximum is set to 8 pages.
*/
if (sc->mlxd_controller->mlx_iftype == MLX_IFTYPE_2)
sc->mlxd_disk.d_maxsize = 8 * PAGE_SIZE;
sc->mlxd_disk->d_maxsize = 8 * PAGE_SIZE;
else {
s1 = sc->mlxd_controller->mlx_enq2->me_maxblk * MLX_BLKSIZE;
s2 = (sc->mlxd_controller->mlx_enq2->me_max_sg - 1) * PAGE_SIZE;
sc->mlxd_disk.d_maxsize = imin(s1, s2);
sc->mlxd_disk->d_maxsize = imin(s1, s2);
}
disk_create(sc->mlxd_unit, &sc->mlxd_disk, 0, NULL, NULL);
disk_create(sc->mlxd_disk, DISK_VERSION);
return (0);
}
@ -254,7 +257,7 @@ mlxd_detach(device_t dev)
debug_called(1);
disk_destroy(&sc->mlxd_disk);
disk_destroy(sc->mlxd_disk);
return(0);
}

View File

@ -228,7 +228,7 @@ struct mlxd_softc
device_t mlxd_dev;
struct mlx_softc *mlxd_controller;
struct mlx_sysdrive *mlxd_drive;
struct disk mlxd_disk;
struct disk *mlxd_disk;
int mlxd_unit;
int mlxd_flags;
#define MLXD_OPEN (1<<0) /* drive is open (can't shut down) */

View File

@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$");
struct ofwd_softc
{
device_t ofwd_dev;
struct disk ofwd_disk;
struct disk *ofwd_disk;
phandle_t ofwd_package;
ihandle_t ofwd_instance;
};
@ -203,15 +203,18 @@ ofwd_attach(device_t dev)
return (ENXIO);
}
sc->ofwd_disk.d_strategy = ofwd_strategy;
sc->ofwd_disk.d_name = "ofwd";
sc->ofwd_disk.d_sectorsize = OFWD_BLOCKSIZE;
sc->ofwd_disk.d_mediasize = (off_t)33554432 * OFWD_BLOCKSIZE;
sc->ofwd_disk.d_fwsectors = 0;
sc->ofwd_disk.d_fwheads = 0;
sc->ofwd_disk.d_drv1 = sc;
sc->ofwd_disk.d_maxsize = PAGE_SIZE;
disk_create(device_get_unit(dev), &sc->ofwd_disk, 0, NULL, NULL);
sc->ofwd_disk = disk_alloc();
sc->ofwd_disk->d_strategy = ofwd_strategy;
sc->ofwd_disk->d_name = "ofwd";
sc->ofwd_disk->d_sectorsize = OFWD_BLOCKSIZE;
sc->ofwd_disk->d_mediasize = (off_t)33554432 * OFWD_BLOCKSIZE;
sc->ofwd_disk->d_fwsectors = 0;
sc->ofwd_disk->d_fwheads = 0;
sc->ofwd_disk->d_drv1 = sc;
sc->ofwd_disk->d_maxsize = PAGE_SIZE;
sc->ofwd_disk->d_unit = device_get_unit(dev);
sc->ofwd_disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(sc->ofwd_disk, DISK_VERSION);
return (0);
}

View File

@ -56,7 +56,7 @@ struct pst_softc {
struct iop_softc *iop;
struct i2o_lct_entry *lct;
struct i2o_bsa_device *info;
struct disk disk;
struct disk *disk;
struct bio_queue_head queue;
};
@ -149,16 +149,19 @@ pst_attach(device_t dev)
bioq_init(&psc->queue);
psc->disk.d_name = "pst";
psc->disk.d_strategy = pststrategy;
psc->disk.d_maxsize = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/
psc->disk.d_drv1 = psc;
disk_create(lun, &psc->disk, DISKFLAG_NOGIANT, NULL, NULL);
psc->disk = disk_alloc();
psc->disk->d_name = "pst";
psc->disk->d_strategy = pststrategy;
psc->disk->d_maxsize = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/
psc->disk->d_drv1 = psc;
psc->disk->d_unit = lun;
psc->disk.d_sectorsize = psc->info->block_size;
psc->disk.d_mediasize = psc->info->capacity;
psc->disk.d_fwsectors = 63;
psc->disk.d_fwheads = 255;
psc->disk->d_sectorsize = psc->info->block_size;
psc->disk->d_mediasize = psc->info->capacity;
psc->disk->d_fwsectors = 63;
psc->disk->d_fwheads = 255;
disk_create(psc->disk, DISK_VERSION);
printf("pst%d: %lluMB <%.40s> [%lld/%d/%d] on %.16s\n", lun,
(unsigned long long)psc->info->capacity / (1024 * 1024),

View File

@ -252,7 +252,7 @@ struct raid_softc {
int sc_busycount; /* How many times are we opened? */
size_t sc_size; /* size of the raid device */
dev_t sc_parent; /* Parent device */
struct disk sc_disk; /* generic disk device info */
struct disk *sc_disk; /* generic disk device info */
uma_zone_t sc_cbufpool; /* component buffer pool */
RF_Raid_t *raidPtr; /* Raid information struct */
struct bio_queue_head bio_queue; /* used for the device queue */
@ -599,7 +599,7 @@ raidctlioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td)
retcode = rf_Shutdown(sc->raidPtr);
RF_THREADGROUP_WAIT_STOP(&sc->raidPtr->engine_tg);
disk_destroy(&sc->sc_disk);
disk_destroy(sc->sc_disk);
raidunlock(sc);
/* XXX Need to be able to destroy the zone */
@ -631,7 +631,7 @@ raidopen(struct disk *dp)
if ((error = raidlock(sc)) != 0)
return (error);
dp = &sc->sc_disk;
dp = sc->sc_disk;
rf_printf(1, "Opening raid device %s%d\n", dp->d_name, dp->d_unit);
@ -1276,14 +1276,17 @@ raidinit(raidPtr)
sc->sc_size = raidPtr->totalSectors;
/* Create the disk device */
sc->sc_disk.d_open = raidopen;
sc->sc_disk.d_close = raidclose;
sc->sc_disk.d_ioctl = raidioctl;
sc->sc_disk.d_strategy = raidstrategy;
sc->sc_disk.d_drv1 = sc;
sc->sc_disk.d_maxsize = DFLTPHYS;
sc->sc_disk.d_name = "raid";
disk_create(raidPtr->raidid, &sc->sc_disk, 0, NULL, NULL);
sc->sc_disk = disk_alloc();
sc->sc_disk->d_open = raidopen;
sc->sc_disk->d_close = raidclose;
sc->sc_disk->d_ioctl = raidioctl;
sc->sc_disk->d_strategy = raidstrategy;
sc->sc_disk->d_drv1 = sc;
sc->sc_disk->d_maxsize = DFLTPHYS;
sc->sc_disk->d_name = "raid";
sc->sc_disk->d_unit = raidPtr->raidid;
sc->sc_disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(sc->sc_disk, DISK_VERSION);
raidPtr->sc = sc;
return (sc);
@ -1467,7 +1470,7 @@ rf_DispatchKernelIO(queue, req)
sc = queue->raidPtr->sc;
rf_printf(3, "DispatchKernelIO %s\n", sc->sc_disk.d_name);
rf_printf(3, "DispatchKernelIO %s\n", sc->sc_disk->d_name);
bp = req->bp;
#if 1
@ -1533,8 +1536,8 @@ rf_DispatchKernelIO(queue, req)
queue->curPriority = req->priority;
rf_printf(3, "Going for %c to %s%d row %d col %d\n",
req->type, sc->sc_disk.d_name,
sc->sc_disk.d_unit, queue->row, queue->col);
req->type, sc->sc_disk->d_name,
sc->sc_disk->d_unit, queue->row, queue->col);
rf_printf(3, "sector %d count %d (%d bytes) %d\n",
(int) req->sectorOffset, (int) req->numSector,
(int) (req->numSector <<
@ -1609,7 +1612,7 @@ KernelWakeupFunc(vbp)
if (queue->raidPtr->Disks[queue->row][queue->col].status ==
rf_ds_optimal) {
rf_printf(0, "%s%d: IO Error. Marking %s as "
"failed.\n", sc->sc_disk.d_name, sc->sc_disk.d_unit,
"failed.\n", sc->sc_disk->d_name, sc->sc_disk->d_unit,
queue->raidPtr->Disks[queue->row][queue->col].devname);
queue->raidPtr->Disks[queue->row][queue->col].status =
rf_ds_failed;

View File

@ -640,7 +640,7 @@ struct twed_softc
device_t twed_dev;
struct twe_softc *twed_controller; /* parent device softc */
struct twe_drive *twed_drive; /* drive data in parent softc */
struct disk twed_disk; /* generic disk handle */
struct disk *twed_disk; /* generic disk handle */
};
/*
@ -805,19 +805,24 @@ twed_attach(device_t dev)
/* attach a generic disk device to ourselves */
sc->twed_disk.d_open = twed_open;
sc->twed_disk.d_strategy = twed_strategy;
sc->twed_disk.d_dump = (dumper_t *)twed_dump;
sc->twed_disk.d_name = "twed";
sc->twed_disk.d_drv1 = sc;
sc->twed_disk.d_maxsize = (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE;
sc->twed_disk.d_sectorsize = TWE_BLOCK_SIZE;
sc->twed_disk.d_mediasize = TWE_BLOCK_SIZE * (off_t)sc->twed_drive->td_size;
sc->twed_disk.d_fwsectors = sc->twed_drive->td_sectors;
sc->twed_disk.d_fwheads = sc->twed_drive->td_heads;
sc->twed_drive->td_sys_unit = device_get_unit(dev);
disk_create(sc->twed_drive->td_sys_unit, &sc->twed_disk, 0, NULL, NULL);
sc->twed_disk = disk_alloc();
sc->twed_disk->d_open = twed_open;
sc->twed_disk->d_strategy = twed_strategy;
sc->twed_disk->d_dump = (dumper_t *)twed_dump;
sc->twed_disk->d_name = "twed";
sc->twed_disk->d_drv1 = sc;
sc->twed_disk->d_maxsize = (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE;
sc->twed_disk->d_sectorsize = TWE_BLOCK_SIZE;
sc->twed_disk->d_mediasize = TWE_BLOCK_SIZE * (off_t)sc->twed_drive->td_size;
sc->twed_disk->d_fwsectors = sc->twed_drive->td_sectors;
sc->twed_disk->d_fwheads = sc->twed_drive->td_heads;
sc->twed_disk->d_unit = sc->twed_drive->td_sys_unit;
sc->twed_disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(sc->twed_disk, DISK_VERSION);
#ifdef FREEBSD_4
disks_registered++;
#endif
@ -837,10 +842,10 @@ twed_detach(device_t dev)
debug_called(4);
if (sc->twed_disk.d_flags & DISKFLAG_OPEN)
if (sc->twed_disk->d_flags & DISKFLAG_OPEN)
return(EBUSY);
disk_destroy(&sc->twed_disk);
disk_destroy(sc->twed_disk);
#ifdef FREEBSD_4
if (--disks_registered == 0)

View File

@ -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);
}
struct disk *
disk_alloc()
{
struct disk *dp;
dp = g_malloc(sizeof *dp, M_WAITOK | M_ZERO);
return (dp);
}
void
disk_create(int unit, struct disk *dp, int flags, void *unused __unused, void * unused2 __unused)
disk_create(struct disk *dp, int version)
{
dp->d_unit = unit;
dp->d_flags = flags;
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

View File

@ -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_ */

View File

@ -84,7 +84,7 @@ struct ssc_s {
int unit;
LIST_ENTRY(ssc_s) list;
struct bio_queue_head bio_queue;
struct disk disk;
struct disk *disk;
dev_t dev;
int busy;
int fd;
@ -174,15 +174,18 @@ ssccreate(int unit)
sc->unit = unit;
bioq_init(&sc->bio_queue);
sc->disk.d_drv1 = sc;
sc->disk.d_fwheads = 0;
sc->disk.d_fwsectors = 0;
sc->disk.d_maxsize = DFLTPHYS;
sc->disk.d_mediasize = (off_t)SSC_NSECT * DEV_BSIZE;
sc->disk.d_name = "sscdisk";
sc->disk.d_sectorsize = DEV_BSIZE;
sc->disk.d_strategy = sscstrategy;
disk_create(sc->unit, &sc->disk, 0, NULL, NULL);
sc->disk = disk_alloc();
sc->disk->d_drv1 = sc;
sc->disk->d_fwheads = 0;
sc->disk->d_fwsectors = 0;
sc->disk->d_maxsize = DFLTPHYS;
sc->disk->d_mediasize = (off_t)SSC_NSECT * DEV_BSIZE;
sc->disk->d_name = "sscdisk";
sc->disk->d_sectorsize = DEV_BSIZE;
sc->disk->d_strategy = sscstrategy;
sc->disk->d_unit = sc->unit;
sc->disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(sc->disk, DISK_VERSION);
sc->fd = fd;
if (sc->unit == 0)
sscrootready = 1;

View File

@ -184,7 +184,7 @@ struct softc {
struct diskgeom dk_dd; /* device configuration data */
struct diskslices *dk_slices; /* virtual drives */
void *dk_dmacookie; /* handle for DMA services */
struct disk disk;
struct disk *disk;
};
#define WD_COUNT_RETRIES
@ -562,12 +562,15 @@ wdattach(struct isa_device *dvp)
/*
* Register this media as a disk
*/
du->disk.d_open = wdopen;
du->disk.d_strategy = wdstrategy;
du->disk.d_drv1 = du;
du->disk.d_maxsize = 248 * 512;
du->disk.d_name = "wd";
disk_create(lunit, &du->disk, 0, NULL, NULL);
du->disk = disk_alloc();
du->disk->d_open = wdopen;
du->disk->d_strategy = wdstrategy;
du->disk->d_drv1 = du;
du->disk->d_maxsize = 248 * 512;
du->disk->d_name = "wd";
du->disk->d_unit = lunit;
du->disk->d_flags = DISKFLAG_NEEDSGIANT;
disk_create(du->disk, DISK_VERSION);
} else {
free(du, M_TEMP);
@ -1218,10 +1221,10 @@ wdopen(struct disk *dp)
du->dk_flags |= DKFL_LABELLING;
du->dk_state = WANTOPEN;
du->disk.d_sectorsize = du->dk_dd.d_secsize;
du->disk.d_mediasize = du->dk_dd.d_secperunit * du->dk_dd.d_secsize;
du->disk.d_fwsectors = du->dk_dd.d_nsectors;
du->disk.d_fwheads = du->dk_dd.d_ntracks;
du->disk->d_sectorsize = du->dk_dd.d_secsize;
du->disk->d_mediasize = du->dk_dd.d_secperunit * du->dk_dd.d_secsize;
du->disk->d_fwsectors = du->dk_dd.d_nsectors;
du->disk->d_fwheads = du->dk_dd.d_ntracks;
du->dk_flags &= ~DKFL_LABELLING;
wdsleep(du->dk_ctrlr, "wdopn2");