Don't skip the cache flush until the last opening of the device is closed. Otherwise, when umounting a writable partition while a different partition is still mounted read-only, the necessary disk flush may be delayed for a very long time.
diff --git sys/scsi/sd.c sys/scsi/sd.c index 4cd0e4d13bd..37135af78a1 100644 --- sys/scsi/sd.c +++ sys/scsi/sd.c @@ -511,10 +511,11 @@ sdclose(dev_t dev, int flag, int fmt, struct proc *p) disk_closepart(&sc->sc_dk, part, fmt); - if (sc->sc_dk.dk_openmask == 0) { - if ((sc->flags & SDF_DIRTY) != 0) - sd_flush(sc, 0); + if (((flag & FWRITE) != 0 || sc->sc_dk.dk_openmask == 0) && + (sc->flags & SDF_DIRTY) != 0) + sd_flush(sc, 0); + if (sc->sc_dk.dk_openmask == 0) { if (sc->flags & SDF_DYING) { error = ENXIO; goto die;