win-pvdrivers

changeset 553:ee8236b44af3

Better behaviour on non-qemu hide mode.
author James Harper <james.harper@bendigoit.com.au>
date Sat Mar 28 10:09:12 2009 +1100 (2009-03-28)
parents 069658b9c8ee
children 2447875396d0
files xenvbd/xenvbd.c
line diff
     1.1 --- a/xenvbd/xenvbd.c	Sat Mar 28 10:08:23 2009 +1100
     1.2 +++ b/xenvbd/xenvbd.c	Sat Mar 28 10:09:12 2009 +1100
     1.3 @@ -227,11 +227,11 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
     1.4        break;
     1.5      }
     1.6    }
     1.7 -  if (xvdd->device_type == XENVBD_DEVICETYPE_UNKNOWN
     1.8 -    || xvdd->sring == NULL
     1.9 -    || xvdd->event_channel == 0
    1.10 -    || xvdd->total_sectors == 0
    1.11 -    || xvdd->bytes_per_sector == 0)
    1.12 +  if (!xvdd->inactive && (xvdd->device_type == XENVBD_DEVICETYPE_UNKNOWN
    1.13 +      || xvdd->sring == NULL
    1.14 +      || xvdd->event_channel == 0
    1.15 +      || xvdd->total_sectors == 0
    1.16 +      || xvdd->bytes_per_sector == 0))
    1.17    {
    1.18      KdPrint((__DRIVER_NAME "     Missing settings\n"));
    1.19      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    1.20 @@ -244,34 +244,24 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.21    
    1.22    if (xvdd->inactive)
    1.23      KdPrint((__DRIVER_NAME "     Device is inactive\n"));
    1.24 -  
    1.25 -  if (xvdd->device_type == XENVBD_DEVICETYPE_CDROM)
    1.26 +  else
    1.27    {
    1.28 -    /* CD/DVD drives must have bytes_per_sector = 2048. */
    1.29 -    xvdd->bytes_per_sector = 2048;
    1.30 -  }
    1.31 -
    1.32 -  /* for some reason total_sectors is measured in 512 byte sectors always, so correct this to be in bytes_per_sectors */
    1.33 -#ifdef __MINGW32__
    1.34 -  /* mingw can't divide, so shift instead (assumes bps is ^2 and at least 512) */
    1.35 -  {
    1.36 -    ULONG num_512_byte_sectors = xvdd->bytes_per_sector / 512;
    1.37 -    ULONG index;
    1.38 +    if (xvdd->device_type == XENVBD_DEVICETYPE_CDROM)
    1.39 +    {
    1.40 +      /* CD/DVD drives must have bytes_per_sector = 2048. */
    1.41 +      xvdd->bytes_per_sector = 2048;
    1.42 +    }
    1.43  
    1.44 -    bit_scan_forward(&index, num_512_byte_sectors);
    1.45 -    xvdd->total_sectors <<= index-1;
    1.46 -  }
    1.47 -#else
    1.48 -  xvdd->total_sectors /= xvdd->bytes_per_sector / 512;
    1.49 -#endif
    1.50 +    /* for some reason total_sectors is measured in 512 byte sectors always, so correct this to be in bytes_per_sectors */
    1.51 +    xvdd->total_sectors /= xvdd->bytes_per_sector / 512;
    1.52  
    1.53 -
    1.54 -  xvdd->shadow_free = 0;
    1.55 -  memset(xvdd->shadows, 0, sizeof(blkif_shadow_t) * SHADOW_ENTRIES);
    1.56 -  for (i = 0; i < SHADOW_ENTRIES; i++)
    1.57 -  {
    1.58 -    xvdd->shadows[i].req.id = i;
    1.59 -    put_shadow_on_freelist(xvdd, &xvdd->shadows[i]);
    1.60 +    xvdd->shadow_free = 0;
    1.61 +    memset(xvdd->shadows, 0, sizeof(blkif_shadow_t) * SHADOW_ENTRIES);
    1.62 +    for (i = 0; i < SHADOW_ENTRIES; i++)
    1.63 +    {
    1.64 +      xvdd->shadows[i].req.id = i;
    1.65 +      put_shadow_on_freelist(xvdd, &xvdd->shadows[i]);
    1.66 +    }
    1.67    }
    1.68    
    1.69    return SP_RETURN_FOUND;
    1.70 @@ -431,37 +421,6 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
    1.71    //FUNCTION_EXIT();
    1.72  }
    1.73  
    1.74 -#if 0
    1.75 -static VOID
    1.76 -XenVbd_Resume(PVOID DeviceExtension)
    1.77 -{
    1.78 -  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
    1.79 -  ULONG i;
    1.80 -
    1.81 -  FUNCTION_ENTER();
    1.82 -  KdPrint((__DRIVER_NAME "     found device in resume state\n"));
    1.83 -  //FRONT_RING_INIT(&xvdd->ring, xvdd->sring, PAGE_SIZE); what was this for???
    1.84 -  // re-submit srb's
    1.85 -  
    1.86 -KdPrint((__DRIVER_NAME "     About to call InitFromConfig\n"));
    1.87 -  XenVbd_InitFromConfig(xvdd);
    1.88 -KdPrint((__DRIVER_NAME "     Back from InitFromConfig\n"));
    1.89 -  
    1.90 -  
    1.91 -  xvdd->device_state->resume_state = RESUME_STATE_RUNNING;
    1.92 -
    1.93 -KdPrint((__DRIVER_NAME "     resume_state set to RESUME_STATE_RUNNING\n"));
    1.94 -  
    1.95 -  if (i == 0)
    1.96 -  {
    1.97 -    /* no requests, so we might need to tell scsiport that we can accept a new one if we deferred one earlier */
    1.98 -KdPrint((__DRIVER_NAME "     No shadows - notifying to get things started again\n"));
    1.99 -    ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.100 -  }
   1.101 -  FUNCTION_EXIT();
   1.102 -}
   1.103 -#endif
   1.104 -
   1.105  static ULONG DDKAPI
   1.106  XenVbd_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
   1.107  {
   1.108 @@ -477,7 +436,20 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   1.109  
   1.110    FUNCTION_ENTER(); 
   1.111    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.112 +  KdPrint((__DRIVER_NAME "     xvdd = %p\n", xvdd));
   1.113  
   1.114 +  {
   1.115 +  int i;
   1.116 +  for (i = 0; i < sizeof(XENVBD_DEVICE_DATA); i++)
   1.117 +  {
   1.118 +    if (((PUCHAR)xvdd)[i])
   1.119 +    {
   1.120 +      KdPrint((__DRIVER_NAME "     DeviceExtension is not zeroed!!!\n"));
   1.121 +      break;
   1.122 +    }
   1.123 +  }
   1.124 +  }
   1.125 +  RtlZeroMemory(xvdd, sizeof(XENVBD_DEVICE_DATA));
   1.126    *Again = FALSE;
   1.127  
   1.128    KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   1.129 @@ -550,56 +522,66 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   1.130    return SP_RETURN_FOUND;
   1.131  }
   1.132  
   1.133 -static BOOLEAN DDKAPI
   1.134 +static VOID
   1.135 +XenVbd_StartRingDetection(PXENVBD_DEVICE_DATA xvdd)
   1.136 +{
   1.137 +  blkif_request_t *req;
   1.138 +  int i;
   1.139 +  int notify;
   1.140 +
   1.141 +  xvdd->ring_detect_state = 0;
   1.142 +  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   1.143 +  req->operation = 0xff;
   1.144 +  req->nr_segments = 0;
   1.145 +  for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
   1.146 +  {
   1.147 +    req->seg[i].gref = 0; //0xffffffff;
   1.148 +    req->seg[i].first_sect = 0; //0xff;
   1.149 +    req->seg[i].last_sect = 0; //0xff;
   1.150 +  }
   1.151 +  xvdd->ring.req_prod_pvt++;
   1.152 +
   1.153 +  req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   1.154 +  req->operation = 0xff;
   1.155 +  req->nr_segments = 0;
   1.156 +  for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
   1.157 +  {
   1.158 +    req->seg[i].gref = 0; //0xffffffff;
   1.159 +    req->seg[i].first_sect = 0; //0xff;
   1.160 +    req->seg[i].last_sect = 0; //0xff;
   1.161 +  }
   1.162 +  xvdd->ring.req_prod_pvt++;
   1.163 +
   1.164 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xvdd->ring, notify);
   1.165 +  if (notify)
   1.166 +    xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
   1.167 +}
   1.168 +
   1.169 +static BOOLEAN
   1.170  XenVbd_HwScsiInitialize(PVOID DeviceExtension)
   1.171  {
   1.172    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   1.173 -  blkif_request_t *req;
   1.174 -  int i;
   1.175 -  int notify;
   1.176    
   1.177    FUNCTION_ENTER();
   1.178    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.179 +  KdPrint((__DRIVER_NAME "     dump_mode = %d\n", dump_mode));
   1.180  
   1.181 -  if (!dump_mode)
   1.182 +  if (!xvdd->inactive)
   1.183    {
   1.184 -    req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   1.185 -    req->operation = 0xff;
   1.186 -    req->nr_segments = 0;
   1.187 -    for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
   1.188 -    {
   1.189 -      req->seg[i].gref = 0; //0xffffffff;
   1.190 -      req->seg[i].first_sect = 0; //0xff;
   1.191 -      req->seg[i].last_sect = 0; //0xff;
   1.192 -    }
   1.193 -    xvdd->ring.req_prod_pvt++;
   1.194 -
   1.195 -    req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
   1.196 -    req->operation = 0xff;
   1.197 -    req->nr_segments = 0;
   1.198 -    for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
   1.199 +    if (!dump_mode)
   1.200      {
   1.201 -      req->seg[i].gref = 0; //0xffffffff;
   1.202 -      req->seg[i].first_sect = 0; //0xff;
   1.203 -      req->seg[i].last_sect = 0; //0xff;
   1.204 +      XenVbd_StartRingDetection(xvdd);
   1.205      }
   1.206 -    xvdd->ring.req_prod_pvt++;
   1.207 -
   1.208 -    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xvdd->ring, notify);
   1.209 -    if (notify)
   1.210 -      xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
   1.211 -    xvdd->ring_detect_state = 0;
   1.212 +    else
   1.213 +    {
   1.214 +      if (xvdd->cached_use_other)
   1.215 +      {
   1.216 +        xvdd->ring.nr_ents = BLK_OTHER_RING_SIZE;
   1.217 +        xvdd->use_other = TRUE;
   1.218 +      }
   1.219 +      xvdd->ring_detect_state = 2;
   1.220 +    }
   1.221    }
   1.222 -  else
   1.223 -  {
   1.224 -    if (xvdd->cached_use_other)
   1.225 -    {
   1.226 -      xvdd->ring.nr_ents = BLK_OTHER_RING_SIZE;
   1.227 -      xvdd->use_other = TRUE;
   1.228 -    }
   1.229 -    xvdd->ring_detect_state = 2;
   1.230 -  }
   1.231 -  
   1.232    FUNCTION_EXIT();
   1.233  
   1.234    return TRUE;
   1.235 @@ -1258,14 +1240,14 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.236        ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.237      break;
   1.238    case SRB_FUNCTION_FLUSH:
   1.239 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   1.240 +    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH %p, xvdd->shadow_free = %d\n", Srb, xvdd->shadow_free));
   1.241      Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.242      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.243      if (xvdd->device_state->suspend_resume_state_pdo == SR_STATE_RUNNING)
   1.244        ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.245      break;
   1.246    case SRB_FUNCTION_SHUTDOWN:
   1.247 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_SHUTDOWN %p\n", Srb));
   1.248 +    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_SHUTDOWN %p, xvdd->shadow_free = %d\n", Srb, xvdd->shadow_free));
   1.249      Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.250      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.251      if (xvdd->device_state->suspend_resume_state_pdo == SR_STATE_RUNNING)
   1.252 @@ -1324,12 +1306,11 @@ XenVbd_HwScsiAdapterState(PVOID DeviceEx
   1.253  static SCSI_ADAPTER_CONTROL_STATUS DDKAPI
   1.254  XenVbd_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
   1.255  {
   1.256 +  PXENVBD_DEVICE_DATA xvdd = DeviceExtension;
   1.257    SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
   1.258    PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
   1.259    //KIRQL OldIrql;
   1.260  
   1.261 -  UNREFERENCED_PARAMETER(DeviceExtension);
   1.262 -
   1.263    FUNCTION_ENTER();
   1.264    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.265  
   1.266 @@ -1349,7 +1330,12 @@ XenVbd_HwScsiAdapterControl(PVOID Device
   1.267      break;
   1.268    case ScsiRestartAdapter:
   1.269      KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   1.270 -    break;
   1.271 +    XenVbd_InitFromConfig(xvdd);
   1.272 +    if (!xvdd->inactive)
   1.273 +      XenVbd_StartRingDetection(xvdd);
   1.274 +    //if (xvdd->use_other)
   1.275 +    //  xvdd->ring.nr_ents = BLK_OTHER_RING_SIZE;
   1.276 +   break;
   1.277    case ScsiSetBootConfig:
   1.278      KdPrint((__DRIVER_NAME "     ScsiSetBootConfig\n"));
   1.279      break;
   1.280 @@ -1434,6 +1420,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   1.281      IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC), PAGE_SIZE, &driver_extension);
   1.282      ptr = driver_extension;
   1.283      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RUN, NULL, NULL, NULL);
   1.284 +    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_MATCH_FRONT, "device-type", "disk", UlongToPtr(XEN_INIT_MATCH_TYPE_IF_NOT_MATCH|XEN_INIT_MATCH_TYPE_SET_INACTIVE|XEN_INIT_MATCH_TYPE_DONT_CONFIG));
   1.285      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL, NULL);
   1.286      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL, NULL);
   1.287      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "device-type", NULL, NULL);