Module Name: src Committed By: mlelstv Date: Fri Aug 28 05:49:31 UTC 2015
Modified Files: src/sys/dev: dksubr.c dkvar.h Log Message: Prevent race condition where two threads can defer a buffer. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sys/dev/dksubr.c cvs rdiff -u -r1.22 -r1.23 src/sys/dev/dkvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/dksubr.c diff -u src/sys/dev/dksubr.c:1.74 src/sys/dev/dksubr.c:1.75 --- src/sys/dev/dksubr.c:1.74 Thu Aug 27 05:51:50 2015 +++ src/sys/dev/dksubr.c Fri Aug 28 05:49:31 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dksubr.c,v 1.74 2015/08/27 05:51:50 mlelstv Exp $ */ +/* $NetBSD: dksubr.c,v 1.75 2015/08/28 05:49:31 mlelstv Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.74 2015/08/27 05:51:50 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.75 2015/08/28 05:49:31 mlelstv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -301,6 +301,10 @@ dk_start(struct dk_softc *dksc, struct b if (bp != NULL) bufq_put(dksc->sc_bufq, bp); + if (dksc->sc_busy) + goto done; + dksc->sc_busy = true; + /* * Peeking at the buffer queue and committing the operation * only after success isn't atomic. @@ -339,6 +343,8 @@ dk_start(struct dk_softc *dksc, struct b bp = bufq_get(dksc->sc_bufq); } + dksc->sc_busy = false; +done: mutex_exit(&dksc->sc_iolock); } Index: src/sys/dev/dkvar.h diff -u src/sys/dev/dkvar.h:1.22 src/sys/dev/dkvar.h:1.23 --- src/sys/dev/dkvar.h:1.22 Thu Aug 27 05:51:50 2015 +++ src/sys/dev/dkvar.h Fri Aug 28 05:49:31 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dkvar.h,v 1.22 2015/08/27 05:51:50 mlelstv Exp $ */ +/* $NetBSD: dkvar.h,v 1.23 2015/08/28 05:49:31 mlelstv Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -48,6 +48,7 @@ struct dk_softc { struct bufq_state *sc_bufq; /* buffer queue */ int sc_dtype; /* disk type */ struct buf *sc_deferred; /* retry after start failed */ + bool sc_busy; /* processing buffers */ }; /* sc_flags: