Prevent race condition where two threads can defer a buffer.
This commit is contained in:
parent
50408f97eb
commit
432d09fb65
|
@ -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.
|
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2008 The NetBSD Foundation, Inc.
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
|
@ -301,6 +301,10 @@ dk_start(struct dk_softc *dksc, struct buf *bp)
|
||||||
if (bp != NULL)
|
if (bp != NULL)
|
||||||
bufq_put(dksc->sc_bufq, bp);
|
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
|
* Peeking at the buffer queue and committing the operation
|
||||||
* only after success isn't atomic.
|
* only after success isn't atomic.
|
||||||
|
@ -339,6 +343,8 @@ dk_start(struct dk_softc *dksc, struct buf *bp)
|
||||||
bp = bufq_get(dksc->sc_bufq);
|
bp = bufq_get(dksc->sc_bufq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dksc->sc_busy = false;
|
||||||
|
done:
|
||||||
mutex_exit(&dksc->sc_iolock);
|
mutex_exit(&dksc->sc_iolock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||||
|
@ -48,6 +48,7 @@ struct dk_softc {
|
||||||
struct bufq_state *sc_bufq; /* buffer queue */
|
struct bufq_state *sc_bufq; /* buffer queue */
|
||||||
int sc_dtype; /* disk type */
|
int sc_dtype; /* disk type */
|
||||||
struct buf *sc_deferred; /* retry after start failed */
|
struct buf *sc_deferred; /* retry after start failed */
|
||||||
|
bool sc_busy; /* processing buffers */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* sc_flags:
|
/* sc_flags:
|
||||||
|
|
Loading…
Reference in New Issue