Index: sys/dev/fdc/fdc.c =================================================================== --- sys/dev/fdc/fdc.c +++ sys/dev/fdc/fdc.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,7 @@ struct g_geom *fd_geom; struct g_provider *fd_provider; device_t dev; + u_int ref; struct bio_queue_head fd_bq; }; @@ -1431,7 +1433,7 @@ if (ar == 0 && aw == 0 && ae == 0) { fd->options &= ~(FDOPT_NORETRY | FDOPT_NOERRLOG | FDOPT_NOERROR); - device_unbusy(fd->dev); + refcount_release(&fd->ref); return (0); } @@ -1453,13 +1455,13 @@ fd->flags &= ~FD_NEWDISK; mtx_unlock(&fdc->fdc_mtx); } - device_busy(fd->dev); + refcount_acquire(&fd->ref); busy = 1; } if (w > 0 && (fd->flags & FD_WP)) { if (busy) - device_unbusy(fd->dev); + refcount_release(&fd->ref); return (EROFS); } @@ -2070,9 +2072,9 @@ struct fd_data *fd; fd = device_get_softc(dev); + if (refcount_load(&fd->ref)) + return (EBUSY); g_waitfor_event(fd_detach_geom, fd, M_WAITOK, NULL); - while (device_get_state(dev) == DS_BUSY) - tsleep(fd, PZERO, "fdd", hz/10); callout_drain(&fd->toffhandle); return (0);