From: sf Date: Mon, 29 May 2017 14:08:49 +0000 (+0000) Subject: sd: flush cache when closing writable FD X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3c102e39dd4a727213d3cd2193bdec3bebab0fa3;p=openbsd sd: flush cache when closing writable FD 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. ok krw@ deraadt@ --- diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 0a26c87581c..5869d6fdb17 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.272 2017/05/29 14:05:31 sf Exp $ */ +/* $OpenBSD: sd.c,v 1.273 2017/05/29 14:08:49 sf Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -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;