summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Fritsch <sf@cvs.openbsd.org>2017-05-29 14:08:50 +0000
committerStefan Fritsch <sf@cvs.openbsd.org>2017-05-29 14:08:50 +0000
commitc39c3aea481a2d9ebeaf9876732f190a0ab559fd (patch)
tree7ddffe774dbdab1b9a46a24bf05b124cfef74810
parentf4d37800595ef62f944a7168c1ce6e5cabdd3e4e (diff)
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@
-rw-r--r--sys/scsi/sd.c9
1 files changed, 5 insertions, 4 deletions
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;