Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/raidframe Re-work the locking mechanisms for reconst...



details:   https://anonhg.NetBSD.org/src/rev/f8d83c1f5531
branches:  trunk
changeset: 559481:f8d83c1f5531
user:      oster <oster%NetBSD.org@localhost>
date:      Thu Mar 18 16:54:54 2004 +0000

description:
Re-work the locking mechanisms for reconstruct and PSS structures
such that we don't actually hold a simplelock while we are doing
a pool_get(), but that we still effectively protecting critical code.

This should fix all of the outstanding LOCKDEBUG warnings related to
rebuilding RAID sets.

diffstat:

 sys/dev/raidframe/rf_psstatus.c    |  13 ++++++++++---
 sys/dev/raidframe/rf_psstatus.h    |  24 +++++++++++++++++++-----
 sys/dev/raidframe/rf_raid1.c       |  12 ++++++++++--
 sys/dev/raidframe/rf_reconbuffer.c |  23 +++++++++++++++++++++--
 sys/dev/raidframe/rf_reconmap.c    |  13 +++++++++++--
 sys/dev/raidframe/rf_reconmap.h    |   4 +++-
 sys/dev/raidframe/rf_reconstruct.c |  31 +++++++++++++++++++++++++++++--
 sys/dev/raidframe/rf_reconstruct.h |   7 +++++--
 sys/dev/raidframe/rf_reconutil.c   |   5 +++--
 9 files changed, 111 insertions(+), 21 deletions(-)

diffs (truncated from 385 to 300 lines):

diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_psstatus.c
--- a/sys/dev/raidframe/rf_psstatus.c   Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_psstatus.c   Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_psstatus.c,v 1.27 2004/03/08 02:25:27 oster Exp $   */
+/*     $NetBSD: rf_psstatus.c,v 1.28 2004/03/18 16:54:54 oster Exp $   */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -37,7 +37,7 @@
  *****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_psstatus.c,v 1.27 2004/03/08 02:25:27 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_psstatus.c,v 1.28 2004/03/18 16:54:54 oster Exp $");
 
 #include <dev/raidframe/raidframevar.h>
 
@@ -214,6 +214,11 @@
        RF_CallbackDesc_t *cb, *cb1;
 
        RF_LOCK_MUTEX(hdr->mutex);
+       while(hdr->lock) {
+               ltsleep(&hdr->lock, PRIBIO, "rf_racrecon", 0, &hdr->mutex);
+       }
+       hdr->lock = 1;
+       RF_UNLOCK_MUTEX(hdr->mutex);    
        for (pt = NULL, p = hdr->chain; p; pt = p, p = p->next) {
                if ((p->parityStripeID == psid) && (p->which_ru == which_ru))
                        break;
@@ -231,7 +236,9 @@
        else
                hdr->chain = p->next;
        p->next = NULL;
-
+       
+       RF_LOCK_MUTEX(hdr->mutex);
+       hdr->lock = 0;
        RF_UNLOCK_MUTEX(hdr->mutex);
 
        /* wakup anyone waiting on the parity stripe ID */
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_psstatus.h
--- a/sys/dev/raidframe/rf_psstatus.h   Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_psstatus.h   Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_psstatus.h,v 1.8 2004/03/08 02:25:27 oster Exp $    */
+/*     $NetBSD: rf_psstatus.h,v 1.9 2004/03/18 16:54:54 oster Exp $    */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -54,10 +54,22 @@
  * descriptor. Note that we use just one lock for the whole hash chain.
  */
 #define RF_HASH_PSID(_raid_,_psid_) ( (_psid_) % ((_raid_)->pssTableSize) )    /* simple hash function */
-#define RF_LOCK_PSS_MUTEX(_raidPtr, _psid) \
-  RF_LOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex)
-#define RF_UNLOCK_PSS_MUTEX(_raidPtr, _psid) \
-  RF_UNLOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex)
+#define RF_LOCK_PSS_MUTEX(_raidPtr, _psid)                                                      \
+  do {                                                                                          \
+     RF_LOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex);   \
+     while((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].lock) {           \
+          ltsleep(&(_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].lock,     \
+                 PRIBIO, "rflockpss", 0,                                                       \
+                 &(_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex);   \
+     }                                                                                          \
+     (_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].lock = 1;               \
+     RF_UNLOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex); \
+  } while (0);
+
+#define RF_UNLOCK_PSS_MUTEX(_raidPtr, _psid)                                                    \
+  RF_LOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex);      \
+  (_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].lock = 0;                  \
+  RF_UNLOCK_MUTEX((_raidPtr)->reconControl->pssTable[ RF_HASH_PSID(_raidPtr,_psid) ].mutex);
 
 struct RF_ReconParityStripeStatus_s {
        RF_StripeNum_t parityStripeID;  /* the parity stripe ID */
@@ -87,6 +99,8 @@
 
 struct RF_PSStatusHeader_s {
        RF_DECLARE_MUTEX(mutex) /* mutex for this hash chain */
+       int lock;               /* 1 if this hash chain is locked,
+                                  0 otherwise */
        RF_ReconParityStripeStatus_t *chain;    /* the hash chain */
 };
 /* masks for the "flags" field above */
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_raid1.c
--- a/sys/dev/raidframe/rf_raid1.c      Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_raid1.c      Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_raid1.c,v 1.23 2004/03/05 03:22:05 oster Exp $      */
+/*     $NetBSD: rf_raid1.c,v 1.24 2004/03/18 16:54:54 oster Exp $      */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -33,7 +33,7 @@
  *****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_raid1.c,v 1.23 2004/03/05 03:22:05 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_raid1.c,v 1.24 2004/03/18 16:54:54 oster Exp $");
 
 #include "rf_raid.h"
 #include "rf_raid1.h"
@@ -580,6 +580,11 @@
        RF_LOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
 
        RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       while(reconCtrlPtr->rb_lock) {
+               ltsleep(&reconCtrlPtr->rb_lock, PRIBIO, "reconctlcnmhs", 0, &reconCtrlPtr->rb_mutex);
+       }
+       reconCtrlPtr->rb_lock = 1;
+       RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
 
        pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable,
            rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, NULL);
@@ -681,6 +686,9 @@
 
 out:
        RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
+       RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       reconCtrlPtr->rb_lock = 0;
+       wakeup(&reconCtrlPtr->rb_lock);
        RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
 #if RF_DEBUG_RECON
        if (rf_reconbufferDebug) {
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_reconbuffer.c
--- a/sys/dev/raidframe/rf_reconbuffer.c        Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_reconbuffer.c        Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_reconbuffer.c,v 1.20 2004/03/03 13:29:00 oster Exp $        */
+/*     $NetBSD: rf_reconbuffer.c,v 1.21 2004/03/18 16:54:54 oster Exp $        */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -33,7 +33,7 @@
  ***************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_reconbuffer.c,v 1.20 2004/03/03 13:29:00 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconbuffer.c,v 1.21 2004/03/18 16:54:54 oster Exp $");
 
 #include "rf_raid.h"
 #include "rf_reconbuffer.h"
@@ -141,6 +141,11 @@
        RF_LOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
 
        RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       while(reconCtrlPtr->rb_lock) {
+               ltsleep(&reconCtrlPtr->rb_lock, PRIBIO, "reconctlcnmhs", 0, &reconCtrlPtr->rb_mutex);
+       }
+       reconCtrlPtr->rb_lock = 1;
+       RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
 
        pssPtr = rf_LookupRUStatus(raidPtr, reconCtrlPtr->pssTable, rbuf->parityStripeID, rbuf->which_ru, RF_PSS_NONE, NULL);
        RF_ASSERT(pssPtr);      /* if it didn't exist, we wouldn't have gotten
@@ -188,6 +193,9 @@
                }
                if (keep_it) {
                        RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
+                       RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+                       reconCtrlPtr->rb_lock = 0;
+                       wakeup(&reconCtrlPtr->rb_lock);
                        RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
                        rf_FreeReconBuffer(rbuf);
                        return (retcode);
@@ -278,6 +286,9 @@
 
 out:
        RF_UNLOCK_PSS_MUTEX(raidPtr, rbuf->parityStripeID);
+       RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       reconCtrlPtr->rb_lock = 0;
+       wakeup(&reconCtrlPtr->rb_lock);
        RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
        return (retcode);
 }
@@ -329,11 +340,19 @@
        RF_ReconBuffer_t *p;
 
        RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       while(reconCtrlPtr->rb_lock) {
+               ltsleep(&reconCtrlPtr->rb_lock, PRIBIO, "reconctlcnmhs", 0, &reconCtrlPtr->rb_mutex);
+       }
+       reconCtrlPtr->rb_lock = 1;
+       RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
 
        if ((p = reconCtrlPtr->fullBufferList) != NULL) {
                reconCtrlPtr->fullBufferList = p->next;
                p->next = NULL;
        }
+       RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       reconCtrlPtr->rb_lock = 0;
+       wakeup(&reconCtrlPtr->rb_lock);
        RF_UNLOCK_MUTEX(reconCtrlPtr->rb_mutex);
        return (p);
 }
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_reconmap.c
--- a/sys/dev/raidframe/rf_reconmap.c   Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_reconmap.c   Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_reconmap.c,v 1.23 2004/03/01 01:12:22 oster Exp $   */
+/*     $NetBSD: rf_reconmap.c,v 1.24 2004/03/18 16:54:54 oster Exp $   */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -34,7 +34,7 @@
  *************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_reconmap.c,v 1.23 2004/03/01 01:12:22 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconmap.c,v 1.24 2004/03/18 16:54:54 oster Exp $");
 
 #include "rf_raid.h"
 #include <sys/time.h>
@@ -142,6 +142,12 @@
        RF_ReconMapListElem_t *p, *pt;
 
        RF_LOCK_MUTEX(mapPtr->mutex);
+       while(mapPtr->lock) {
+               printf("napping...\n");
+               ltsleep(&mapPtr->lock, PRIBIO, "reconupdate", 0, &mapPtr->mutex);
+       }
+       mapPtr->lock = 1;
+       RF_UNLOCK_MUTEX(mapPtr->mutex);
        RF_ASSERT(startSector >= 0 && stopSector < mapPtr->sectorsInDisk && 
                  stopSector >= startSector);
 
@@ -168,6 +174,9 @@
                }
                startSector = RF_MIN(stopSector, last_in_RU) + 1;
        }
+       RF_LOCK_MUTEX(mapPtr->mutex);
+       mapPtr->lock = 0;
+       wakeup(&mapPtr->lock);
        RF_UNLOCK_MUTEX(mapPtr->mutex);
 }
 
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_reconmap.h
--- a/sys/dev/raidframe/rf_reconmap.h   Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_reconmap.h   Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_reconmap.h,v 1.8 2004/03/04 03:14:02 oster Exp $    */
+/*     $NetBSD: rf_reconmap.h,v 1.9 2004/03/18 16:54:54 oster Exp $    */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -54,6 +54,8 @@
        RF_ReconMapListElem_t **status; /* array of ptrs to list elements */
        struct pool elem_pool;          /* pool of RF_ReconMapListElem_t's */
        RF_DECLARE_MUTEX(mutex)
+       int lock;                       /* 1 if someone has the recon map
+                                          locked, 0 otherwise */
 };
 /* a list element */
 struct RF_ReconMapListElem_s {
diff -r 6db6da2e774b -r f8d83c1f5531 sys/dev/raidframe/rf_reconstruct.c
--- a/sys/dev/raidframe/rf_reconstruct.c        Thu Mar 18 16:51:39 2004 +0000
+++ b/sys/dev/raidframe/rf_reconstruct.c        Thu Mar 18 16:54:54 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_reconstruct.c,v 1.75 2004/03/13 02:00:15 oster Exp $        */
+/*     $NetBSD: rf_reconstruct.c,v 1.76 2004/03/18 16:54:54 oster Exp $        */
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -33,7 +33,7 @@
  ************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.75 2004/03/13 02:00:15 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.76 2004/03/18 16:54:54 oster Exp $");
 
 #include <sys/time.h>
 #include <sys/buf.h>
@@ -792,8 +792,19 @@
 
                if (rbuf->type == RF_RBUF_TYPE_FLOATING) {
                        RF_LOCK_MUTEX(raidPtr->reconControl->rb_mutex);
+                       while(raidPtr->reconControl->rb_lock) {
+                               ltsleep(&raidPtr->reconControl->rb_lock, PRIBIO, "reconctrlpre1", 0, 
+                                       &raidPtr->reconControl->rb_mutex);
+                       }
+                       raidPtr->reconControl->rb_lock = 1;
+                       RF_UNLOCK_MUTEX(raidPtr->reconControl->rb_mutex);
+
                        raidPtr->numFullReconBuffers--;
                        rf_ReleaseFloatingReconBuffer(raidPtr, rbuf);
+
+                       RF_LOCK_MUTEX(raidPtr->reconControl->rb_mutex);
+                       raidPtr->reconControl->rb_lock = 0;
+                       wakeup(&raidPtr->reconControl->rb_lock);
                        RF_UNLOCK_MUTEX(raidPtr->reconControl->rb_mutex);
                } else
                        if (rbuf->type == RF_RBUF_TYPE_FORCED)
@@ -1307,6 +1318,11 @@
 
 
        RF_LOCK_MUTEX(reconCtrlPtr->rb_mutex);
+       while(reconCtrlPtr->rb_lock) {
+               ltsleep(&reconCtrlPtr->rb_lock, PRIBIO, "reconctlcnmhs", 0, &reconCtrlPtr->rb_mutex);
+       }



Home | Main Index | Thread Index | Old Index