win-pvdrivers

changeset 404:1a1ddc1beba6

implemented mutex's in xenbus. Looks like this broke save/restore somewhere though...
author James Harper <james.harper@bendigoit.com.au>
date Mon Jul 21 15:45:14 2008 +1000 (2008-07-21)
parents abdcb860cfdf
children 4fee03f012ee
files xenpci/xenbus.c xenpci/xenpci.h
line diff
     1.1 --- a/xenpci/xenbus.c	Mon Jul 21 11:47:29 2008 +1000
     1.2 +++ b/xenpci/xenbus.c	Mon Jul 21 15:45:14 2008 +1000
     1.3 @@ -36,6 +36,7 @@ XenBus_WatchThreadProc(PVOID StartContex
     1.4  static DDKAPI BOOLEAN
     1.5  XenBus_Interrupt(PKINTERRUPT Interrupt, PVOID ServiceContext);
     1.6  
     1.7 +/* called with xenbus_mutex held */
     1.8  static int allocate_xenbus_id(PXENPCI_DEVICE_DATA xpdd)
     1.9  {
    1.10    static int probe;
    1.11 @@ -73,6 +74,7 @@ static int allocate_xenbus_id(PXENPCI_DE
    1.12    return o_probe;
    1.13  }
    1.14  
    1.15 +/* called with xenbus_mutex held */
    1.16  static void release_xenbus_id(PXENPCI_DEVICE_DATA xpdd, int id)
    1.17  {
    1.18    KIRQL old_irql;
    1.19 @@ -120,6 +122,7 @@ static void memcpy_from_ring(const void 
    1.20    memcpy(dest + c1, ring, c2);
    1.21  }
    1.22  
    1.23 +/* called with xenbus_mutex held */
    1.24  static void xb_write(
    1.25    PXENPCI_DEVICE_DATA xpdd,
    1.26    int type,
    1.27 @@ -193,6 +196,7 @@ static void xb_write(
    1.28    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    1.29  }
    1.30  
    1.31 +/* called with xenbus_mutex held */
    1.32  static struct xsd_sockmsg *
    1.33  xenbus_msg_reply(
    1.34    PXENPCI_DEVICE_DATA xpdd,
    1.35 @@ -218,6 +222,10 @@ xenbus_msg_reply(
    1.36    return xpdd->req_info[id].Reply;
    1.37  }
    1.38  
    1.39 +/*
    1.40 +Called at PASSIVE_LEVEL
    1.41 +Acquires the mutex
    1.42 +*/
    1.43  char *
    1.44  XenBus_Read(
    1.45    PVOID Context,
    1.46 @@ -235,7 +243,11 @@ XenBus_Read(
    1.47  
    1.48    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    1.49  
    1.50 +  // get mutex or wait for mutex to be acquired
    1.51 +  
    1.52 +  ExAcquireFastMutex(&xpdd->xenbus_mutex);
    1.53    rep = xenbus_msg_reply(xpdd, XS_READ, xbt, req, ARRAY_SIZE(req));
    1.54 +  ExReleaseFastMutex(&xpdd->xenbus_mutex);
    1.55    msg = errmsg(rep);
    1.56    if (msg) {
    1.57      *value = NULL;
    1.58 @@ -252,6 +264,10 @@ XenBus_Read(
    1.59    return NULL;
    1.60  }
    1.61  
    1.62 +/*
    1.63 +Called at PASSIVE_LEVEL
    1.64 +Acquires the mutex
    1.65 +*/
    1.66  char *
    1.67  XenBus_Write(
    1.68    PVOID Context,
    1.69 @@ -271,7 +287,9 @@ XenBus_Write(
    1.70  
    1.71    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    1.72  
    1.73 +  ExAcquireFastMutex(&xpdd->xenbus_mutex);
    1.74    rep = xenbus_msg_reply(xpdd, XS_WRITE, xbt, req, ARRAY_SIZE(req));
    1.75 +  ExReleaseFastMutex(&xpdd->xenbus_mutex);
    1.76    msg = errmsg(rep);
    1.77    if (msg)
    1.78      return msg;
    1.79 @@ -327,6 +345,7 @@ XenBus_Init(PXENPCI_DEVICE_DATA xpdd)
    1.80    ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
    1.81  
    1.82    KeInitializeSpinLock(&xpdd->WatchLock);
    1.83 +  ExInitializeFastMutex(&xpdd->xenbus_mutex);
    1.84  
    1.85    for (i = 0; i < MAX_WATCH_ENTRIES; i++)
    1.86    {
    1.87 @@ -569,6 +588,10 @@ XenBus_WatchThreadProc(PVOID StartContex
    1.88    }
    1.89  }    
    1.90  
    1.91 +/*
    1.92 +Called at PASSIVE_LEVEL
    1.93 +Acquires the mutex
    1.94 +*/
    1.95  static char *
    1.96  XenBus_SendAddWatch(
    1.97    PVOID Context,
    1.98 @@ -589,7 +612,10 @@ XenBus_SendAddWatch(
    1.99    req[1].data = Token;
   1.100    req[1].len = (ULONG)strlen(Token) + 1;
   1.101  
   1.102 +  ExAcquireFastMutex(&xpdd->xenbus_mutex);
   1.103    rep = xenbus_msg_reply(xpdd, XS_WATCH, xbt, req, ARRAY_SIZE(req));
   1.104 +  ExReleaseFastMutex(&xpdd->xenbus_mutex);
   1.105 +
   1.106    msg = errmsg(rep);
   1.107    if (!msg)
   1.108      ExFreePoolWithTag(rep, XENPCI_POOL_TAG);
     2.1 --- a/xenpci/xenpci.h	Mon Jul 21 11:47:29 2008 +1000
     2.2 +++ b/xenpci/xenpci.h	Mon Jul 21 15:45:14 2008 +1000
     2.3 @@ -216,6 +216,7 @@ typedef struct {
     2.4    XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
     2.5  
     2.6    KSPIN_LOCK WatchLock;
     2.7 +  FAST_MUTEX xenbus_mutex;
     2.8    KSPIN_LOCK grant_lock;
     2.9  
    2.10    //KGUARDED_MUTEX WatchHandlerMutex;