Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Prevent race condition where two threads can defer a...



details:   https://anonhg.NetBSD.org/src/rev/cc36a2c726e9
branches:  trunk
changeset: 340219:cc36a2c726e9
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Fri Aug 28 05:49:31 2015 +0000

description:
Prevent race condition where two threads can defer a buffer.

diffstat:

 sys/dev/dksubr.c |  10 ++++++++--
 sys/dev/dkvar.h  |   3 ++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diffs (55 lines):

diff -r 469da45573bb -r cc36a2c726e9 sys/dev/dksubr.c
--- a/sys/dev/dksubr.c  Fri Aug 28 03:55:15 2015 +0000
+++ b/sys/dev/dksubr.c  Fri Aug 28 05:49:31 2015 +0000
@@ -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 @@
        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 @@
                bp = bufq_get(dksc->sc_bufq);
        }
 
+       dksc->sc_busy = false;
+done:
        mutex_exit(&dksc->sc_iolock);
 }
 
diff -r 469da45573bb -r cc36a2c726e9 sys/dev/dkvar.h
--- a/sys/dev/dkvar.h   Fri Aug 28 03:55:15 2015 +0000
+++ b/sys/dev/dkvar.h   Fri Aug 28 05:49:31 2015 +0000
@@ -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 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:



Home | Main Index | Thread Index | Old Index