win-pvdrivers

changeset 452:1ac3b9d80a06

Fixed crash on restore.
author James Harper <james.harper@bendigoit.com.au>
date Thu Nov 13 17:31:57 2008 +1100 (2008-11-13)
parents 1275f2e97b60
children 2d4f85e453f3
files xenvbd/xenvbd.c
line diff
     1.1 --- a/xenvbd/xenvbd.c	Thu Nov 13 17:28:55 2008 +1100
     1.2 +++ b/xenvbd/xenvbd.c	Thu Nov 13 17:31:57 2008 +1100
     1.3 @@ -146,7 +146,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
     1.4      switch(type)
     1.5      {
     1.6      case XEN_INIT_TYPE_RING: /* frontend ring */
     1.7 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
     1.8 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
     1.9        if (strcmp(setting, "ring-ref") == 0)
    1.10        {
    1.11          xvdd->sring = (blkif_sring_t *)value;
    1.12 @@ -158,7 +158,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.13        break;
    1.14      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
    1.15      case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
    1.16 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
    1.17 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
    1.18        if (strcmp(setting, "event-channel") == 0)
    1.19        {
    1.20          /* cheat here - save the state of the ring in the topmost bits of the event-channel */
    1.21 @@ -173,7 +173,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.22        break;
    1.23      case XEN_INIT_TYPE_READ_STRING_BACK:
    1.24      case XEN_INIT_TYPE_READ_STRING_FRONT:
    1.25 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
    1.26 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
    1.27        if (strcmp(setting, "sectors") == 0)
    1.28          xvdd->total_sectors = atoi(value);
    1.29        else if (strcmp(setting, "sector-size") == 0)
    1.30 @@ -216,7 +216,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.31        }
    1.32        break;
    1.33      case XEN_INIT_TYPE_VECTORS:
    1.34 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
    1.35 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
    1.36        if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
    1.37          ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
    1.38        {
    1.39 @@ -235,11 +235,11 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.40        xvdd->grant_free = xvdd->grant_entries;
    1.41        break;
    1.42      case XEN_INIT_TYPE_STATE_PTR:
    1.43 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
    1.44 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
    1.45        xvdd->device_state = (PXENPCI_DEVICE_STATE)value;
    1.46        break;
    1.47      default:
    1.48 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
    1.49 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
    1.50        break;
    1.51      }
    1.52    }
    1.53 @@ -448,44 +448,54 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
    1.54    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    1.55  }
    1.56  
    1.57 +typedef struct {
    1.58 +  PSCSI_REQUEST_BLOCK srb;
    1.59 +  ULONG offset;
    1.60 +} mini_shadow_t;
    1.61 +
    1.62  static VOID
    1.63  XenVbd_Resume(PVOID DeviceExtension)
    1.64  {
    1.65    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
    1.66    ULONG i;
    1.67 -  blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
    1.68 -  ULONG shadow_entries;
    1.69 -  blkif_shadow_t *shadow;  
    1.70 +  mini_shadow_t shadows[MAX_SHADOW_ENTRIES];
    1.71 +  ULONG shadow_count;
    1.72  
    1.73    FUNCTION_ENTER();
    1.74    KdPrint((__DRIVER_NAME "     found device in resume state\n"));
    1.75 -  FRONT_RING_INIT(&xvdd->ring, xvdd->sring, PAGE_SIZE);
    1.76 +  //FRONT_RING_INIT(&xvdd->ring, xvdd->sring, PAGE_SIZE); what was this for???
    1.77    // re-submit srb's
    1.78    
    1.79 -  shadow_entries = 0;
    1.80 +  shadow_count = 0;
    1.81    for (i = 0; i < SHADOW_ENTRIES; i++)
    1.82    {
    1.83 -    shadow = &xvdd->shadows[i];
    1.84 -    if (shadow->srb)
    1.85 +    if (xvdd->shadows[i].srb)
    1.86      {
    1.87 -      shadows[shadow_entries++] = xvdd->shadows[i];
    1.88 -      shadow->srb = NULL;
    1.89 -    }
    1.90 +      shadows[shadow_count].srb = xvdd->shadows[i].srb;
    1.91 +      shadows[shadow_count].offset = xvdd->shadows[i].offset;
    1.92 +      shadow_count++;
    1.93 +      xvdd->shadows[i].srb = NULL;
    1.94 +    }      
    1.95    }
    1.96 -
    1.97 +KdPrint((__DRIVER_NAME "     About to call InitFromConfig\n"));
    1.98    XenVbd_InitFromConfig(xvdd);
    1.99 +KdPrint((__DRIVER_NAME "     Back from InitFromConfig\n"));
   1.100    
   1.101 -  for (i = 0; i < shadow_entries; i++)
   1.102 +  for (i = 0; i < shadow_count; i++)
   1.103    {
   1.104 -    shadow = &shadows[i];
   1.105 -    XenVbd_PutSrbOnRing(xvdd, shadow->srb, shadow->offset);
   1.106 +KdPrint((__DRIVER_NAME "     Putting on Shadow entry\n"));
   1.107 +    XenVbd_PutSrbOnRing(xvdd, shadows[i].srb, shadows[i].offset);
   1.108    }
   1.109 +KdPrint((__DRIVER_NAME "     Shadows are back on the ring\n"));
   1.110    
   1.111    xvdd->device_state->resume_state = RESUME_STATE_RUNNING;
   1.112 +
   1.113 +KdPrint((__DRIVER_NAME "     resume_state set to RESUME_STATE_RUNNING\n"));
   1.114    
   1.115    if (i == 0)
   1.116    {
   1.117      /* no requests, so we might need to tell scsiport that we can accept a new one if we deferred one earlier */
   1.118 +KdPrint((__DRIVER_NAME "     No shadows - notifying to get things started again\n"));
   1.119      ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.120    }
   1.121    FUNCTION_EXIT();
   1.122 @@ -969,9 +979,10 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.123  
   1.124    if (xvdd->device_state->resume_state != RESUME_STATE_RUNNING)
   1.125    {
   1.126 +    KdPrint((__DRIVER_NAME " --> HwScsiStartIo (Resuming)\n"));
   1.127      Srb->SrbStatus = SRB_STATUS_BUSY;
   1.128      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.129 -    //KdPrint((__DRIVER_NAME " --- HwScsiStartIo (Resuming)\n"));
   1.130 +    KdPrint((__DRIVER_NAME " <-- HwScsiStartIo (Resuming)\n"));
   1.131      return TRUE;
   1.132    }
   1.133  
   1.134 @@ -1258,13 +1269,18 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.135  static BOOLEAN DDKAPI
   1.136  XenVbd_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
   1.137  {
   1.138 +  PXENVBD_DEVICE_DATA xvdd = DeviceExtension;
   1.139 +
   1.140    UNREFERENCED_PARAMETER(DeviceExtension);
   1.141    UNREFERENCED_PARAMETER(PathId);
   1.142  
   1.143    KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
   1.144  
   1.145    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.146 -  ScsiPortNotification(NextRequest, DeviceExtension);
   1.147 +  if (xvdd->ring_detect_state == 2 && xvdd->device_state->resume_state == RESUME_STATE_RUNNING)
   1.148 +  {
   1.149 +    ScsiPortNotification(NextRequest, DeviceExtension);
   1.150 +  }
   1.151  
   1.152    KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
   1.153