win-pvdrivers

changeset 1008:2b8784b1a034

xenvbd scsiport now working
author James Harper <james.harper@bendigoit.com.au>
date Sun Feb 10 23:15:05 2013 +1100 (2013-02-10)
parents 4cda50fe71d5
children 4fe62602bc18
files xenvbd_common/common.h xenvbd_common/common_miniport.h xenvbd_filter/sources xenvbd_filter/xenvbd_filter.c xenvbd_scsiport/common.h xenvbd_scsiport/xenvbd.c xenvbd_scsiport/xenvbd.inx
line diff
     1.1 --- a/xenvbd_common/common.h	Sun Feb 10 23:14:05 2013 +1100
     1.2 +++ b/xenvbd_common/common.h	Sun Feb 10 23:15:05 2013 +1100
     1.3 @@ -66,4 +66,3 @@ typedef struct {
     1.4    LARGE_INTEGER ring_submit_time;
     1.5    #endif
     1.6  } blkif_shadow_t;
     1.7 -
     2.1 --- a/xenvbd_common/common_miniport.h	Sun Feb 10 23:14:05 2013 +1100
     2.2 +++ b/xenvbd_common/common_miniport.h	Sun Feb 10 23:15:05 2013 +1100
     2.3 @@ -47,8 +47,8 @@ get_shadow_from_freelist(PXENVBD_DEVICE_
     2.4      return NULL;
     2.5    }
     2.6    xvdd->shadow_free--;
     2.7 -  if (xvdd->shadow_free < xvdd->shadow_min_free)
     2.8 -    xvdd->shadow_min_free = xvdd->shadow_free;
     2.9 +  //if (xvdd->shadow_free < xvdd->shadow_min_free)
    2.10 +  //  xvdd->shadow_min_free = xvdd->shadow_free;
    2.11    return &xvdd->shadows[xvdd->shadow_free_list[xvdd->shadow_free]];
    2.12  }
    2.13  
    2.14 @@ -172,8 +172,7 @@ XenVbd_MakeAutoSense(PXENVBD_DEVICE_DATA
    2.15  
    2.16  /* called with StartIo lock held */
    2.17  static VOID
    2.18 -XenVbd_HandleEvent(PXENVBD_DEVICE_DATA xvdd)
    2.19 -{
    2.20 +XenVbd_HandleEvent(PXENVBD_DEVICE_DATA xvdd) {
    2.21    PSCSI_REQUEST_BLOCK srb;
    2.22    RING_IDX i, rp;
    2.23    ULONG j;
    2.24 @@ -193,13 +192,14 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    2.25        rep = XenVbd_GetResponse(xvdd, i);
    2.26        shadow = &xvdd->shadows[rep->id & SHADOW_ID_ID_MASK];
    2.27        if (shadow->reset) {
    2.28 -        KdPrint((__DRIVER_NAME "     discarding reset shadow\n"));
    2.29 +        /* the srb's here have already been returned */
    2.30 +        FUNCTION_MSG("discarding reset shadow\n");
    2.31          for (j = 0; j < shadow->req.nr_segments; j++) {
    2.32            XnEndAccess(xvdd->handle,
    2.33              shadow->req.seg[j].gref, FALSE, xvdd->grant_tag);
    2.34          }
    2.35        } else if (dump_mode && !(rep->id & SHADOW_ID_DUMP_FLAG)) {
    2.36 -        KdPrint((__DRIVER_NAME "     discarding stale (non-dump-mode) shadow\n"));
    2.37 +        FUNCTION_MSG("discarding stale (non-dump-mode) shadow\n");
    2.38        } else {
    2.39          srb = shadow->srb;
    2.40          NT_ASSERT(srb);
    2.41 @@ -226,7 +226,7 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    2.42            XnEndAccess(xvdd->handle, shadow->req.seg[j].gref, FALSE, xvdd->grant_tag);
    2.43          }
    2.44          srb_entry->outstanding_requests--;
    2.45 -        if (!srb_entry->outstanding_requests && srb_entry->offset == srb_entry->length) {
    2.46 +        if (srb_entry->outstanding_requests == 0 && srb_entry->offset == srb_entry->length) {
    2.47            if (srb_entry->error) {
    2.48              srb->SrbStatus = SRB_STATUS_ERROR;
    2.49              srb->ScsiStatus = 0x02;
    2.50 @@ -236,38 +236,41 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    2.51            }
    2.52            //FUNCTION_MSG("Completing Srb = %p\n", srb);
    2.53            SxxxPortNotification(RequestComplete, xvdd, srb);
    2.54 -          SxxxPortNotification(NextLuRequest, xvdd, 0, 0, 0);
    2.55          }
    2.56        }
    2.57        put_shadow_on_freelist(xvdd, shadow);
    2.58      }
    2.59  
    2.60      xvdd->ring.rsp_cons = i;
    2.61 -    if (i != xvdd->ring.req_prod_pvt) {
    2.62 -      RING_FINAL_CHECK_FOR_RESPONSES(&xvdd->ring, more_to_do);
    2.63 +    if (i == xvdd->ring.req_prod_pvt) {
    2.64 +      /* all possible requests complete - can't have more responses than requests */
    2.65 +      more_to_do = FALSE;
    2.66 +      xvdd->ring.sring->rsp_event = i + 1;
    2.67      } else {
    2.68 -      xvdd->ring.sring->rsp_event = i + 1;
    2.69 -      more_to_do = FALSE;
    2.70 +      more_to_do = RING_HAS_UNCONSUMED_RESPONSES(&xvdd->ring);
    2.71 +      if (!more_to_do) {
    2.72 +        xvdd->ring.sring->rsp_event = i + max(1, (SHADOW_ENTRIES - xvdd->shadow_free) / 2);
    2.73 +        more_to_do = RING_HAS_UNCONSUMED_RESPONSES(&xvdd->ring);
    2.74 +      }
    2.75      }
    2.76    }
    2.77  
    2.78 +#if 0
    2.79    if (dump_mode || xvdd->device_state == DEVICE_STATE_ACTIVE) {
    2.80      XenVbd_ProcessSrbList(xvdd);
    2.81 -  } else if (xvdd->shadow_free == SHADOW_ENTRIES) {
    2.82 -    FUNCTION_MSG("ring now empty - scheduling workitem for disconnect\n");
    2.83 +  } else
    2.84 +#endif
    2.85 +  if (xvdd->device_state != DEVICE_STATE_ACTIVE && xvdd->shadow_free == SHADOW_ENTRIES) {
    2.86 +    FUNCTION_MSG("ring now empty - comleting disconnect\n");
    2.87      XenVbd_CompleteDisconnect(xvdd);
    2.88 -    //IoQueueWorkItem(xvdd->disconnect_workitem, XenVbd_DisconnectWorkItem, DelayedWorkQueue, xvdd);
    2.89    }
    2.90 -  //if (dump_mode)
    2.91 -  //FUNCTION_EXIT();
    2.92    return;
    2.93  }
    2.94  
    2.95  /* called with StartIoLock held */
    2.96  /* returns TRUE if something was put on the ring and notify might be required */
    2.97  static BOOLEAN
    2.98 -XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb)
    2.99 -{
   2.100 +XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb) {
   2.101    srb_list_entry_t *srb_entry = srb->SrbExtension;
   2.102    /* sector_number and block_count are the adjusted-to-512-byte-sector values */
   2.103    ULONGLONG sector_number;
   2.104 @@ -455,8 +458,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   2.105  
   2.106  
   2.107  static ULONG
   2.108 -XenVbd_FillModePage(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb)
   2.109 -{
   2.110 +XenVbd_FillModePage(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb) {
   2.111    PMODE_PARAMETER_HEADER parameter_header = NULL;
   2.112    PMODE_PARAMETER_HEADER10 parameter_header10 = NULL;
   2.113    PMODE_PARAMETER_BLOCK param_block;
   2.114 @@ -477,8 +479,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.115  
   2.116    //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.117    
   2.118 -  switch (srb->Cdb[0])
   2.119 -  {
   2.120 +  switch (srb->Cdb[0]) {
   2.121    case SCSIOP_MODE_SENSE:
   2.122      cdb_llbaa = FALSE;
   2.123      cdb_dbd = (BOOLEAN)!!(srb->Cdb[1] & 8);
   2.124 @@ -487,8 +488,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.125      parameter_header = (PMODE_PARAMETER_HEADER)&buffer[offset];
   2.126      parameter_header->MediumType = 0;
   2.127      parameter_header->DeviceSpecificParameter = 0;
   2.128 -    if (xvdd->device_mode == XENVBD_DEVICEMODE_READ)
   2.129 -    {
   2.130 +    if (xvdd->device_mode == XENVBD_DEVICEMODE_READ) {
   2.131        KdPrint((__DRIVER_NAME " Mode sense to a read only disk.\n"));
   2.132        parameter_header->DeviceSpecificParameter |= MODE_DSP_WRITE_PROTECT; 
   2.133      }
   2.134 @@ -514,20 +514,15 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.135      return FALSE;
   2.136    }  
   2.137    
   2.138 -  if (!cdb_dbd)
   2.139 -  {
   2.140 +  if (!cdb_dbd) {
   2.141      param_block = (PMODE_PARAMETER_BLOCK)&buffer[offset];
   2.142 -    if (xvdd->device_type == XENVBD_DEVICETYPE_DISK)
   2.143 -    {
   2.144 -      if (xvdd->total_sectors >> 32) 
   2.145 -      {
   2.146 +    if (xvdd->device_type == XENVBD_DEVICETYPE_DISK) {
   2.147 +      if (xvdd->total_sectors >> 32) {
   2.148          param_block->DensityCode = 0xff;
   2.149          param_block->NumberOfBlocks[0] = 0xff;
   2.150          param_block->NumberOfBlocks[1] = 0xff;
   2.151          param_block->NumberOfBlocks[2] = 0xff;
   2.152 -      }
   2.153 -      else
   2.154 -      {
   2.155 +      } else {
   2.156          param_block->DensityCode = (UCHAR)((xvdd->total_sectors >> 24) & 0xff);
   2.157          param_block->NumberOfBlocks[0] = (UCHAR)((xvdd->total_sectors >> 16) & 0xff);
   2.158          param_block->NumberOfBlocks[1] = (UCHAR)((xvdd->total_sectors >> 8) & 0xff);
   2.159 @@ -549,8 +544,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.160      parameter_header10->BlockDescriptorLength[1] = (UCHAR)(offset - sizeof(MODE_PARAMETER_HEADER10));
   2.161      break;
   2.162    }
   2.163 -  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_FORMAT_DEVICE || cdb_page_code == MODE_SENSE_RETURN_ALL))
   2.164 -  {
   2.165 +  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_FORMAT_DEVICE || cdb_page_code == MODE_SENSE_RETURN_ALL)) {
   2.166      valid_page = TRUE;
   2.167      format_page = (PMODE_FORMAT_PAGE)&buffer[offset];
   2.168      format_page->PageCode = MODE_PAGE_FORMAT_DEVICE;
   2.169 @@ -565,8 +559,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.170      format_page->SoftSectorFormating = TRUE;
   2.171      offset += sizeof(MODE_FORMAT_PAGE);
   2.172    }
   2.173 -  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_CACHING || cdb_page_code == MODE_SENSE_RETURN_ALL))
   2.174 -  {
   2.175 +  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_CACHING || cdb_page_code == MODE_SENSE_RETURN_ALL)) {
   2.176      PMODE_CACHING_PAGE caching_page;
   2.177      valid_page = TRUE;
   2.178      caching_page = (PMODE_CACHING_PAGE)&buffer[offset];
   2.179 @@ -575,8 +568,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.180      // caching_page-> // all zeros is just fine... maybe
   2.181      offset += sizeof(MODE_CACHING_PAGE);
   2.182    }
   2.183 -  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_MEDIUM_TYPES || cdb_page_code == MODE_SENSE_RETURN_ALL))
   2.184 -  {
   2.185 +  if (xvdd->device_type == XENVBD_DEVICETYPE_DISK && (cdb_page_code == MODE_PAGE_MEDIUM_TYPES || cdb_page_code == MODE_SENSE_RETURN_ALL)) {
   2.186      PUCHAR medium_types_page;
   2.187      valid_page = TRUE;
   2.188      medium_types_page = &buffer[offset];
   2.189 @@ -590,8 +582,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.190      medium_types_page[7] = 0;
   2.191      offset += 8;
   2.192    }
   2.193 -  switch (srb->Cdb[0])
   2.194 -  {
   2.195 +  switch (srb->Cdb[0]) {
   2.196    case SCSIOP_MODE_SENSE:
   2.197      parameter_header->ModeDataLength = (UCHAR)(offset - 1);
   2.198      break;
   2.199 @@ -601,8 +592,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   2.200      break;
   2.201    }
   2.202  
   2.203 -  if (!valid_page && cdb_page_code != MODE_SENSE_RETURN_ALL)
   2.204 -  {
   2.205 +  if (!valid_page && cdb_page_code != MODE_SENSE_RETURN_ALL) {
   2.206      srb->SrbStatus = SRB_STATUS_ERROR;
   2.207    }
   2.208    else if(offset < srb->DataTransferLength)
   2.209 @@ -639,12 +629,13 @@ XenVbd_ResetBus(PXENVBD_DEVICE_DATA xvdd
   2.210  
   2.211    /* It appears that the StartIo spinlock is already held at this point */
   2.212  
   2.213 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.214 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   2.215  
   2.216    xvdd->aligned_buffer_in_use = FALSE;
   2.217    
   2.218    InitializeListHead(&srb_reset_list);
   2.219    
   2.220 +  /* add all queued srbs to the list */
   2.221    while((list_entry = RemoveHeadList(&xvdd->srb_list)) != &xvdd->srb_list) {
   2.222      #if DBG
   2.223      srb_list_entry_t *srb_entry = CONTAINING_RECORD(list_entry, srb_list_entry_t, list_entry);
   2.224 @@ -653,6 +644,7 @@ XenVbd_ResetBus(PXENVBD_DEVICE_DATA xvdd
   2.225      InsertTailList(&srb_reset_list, list_entry);
   2.226    }
   2.227    
   2.228 +  /* add any in-flight srbs that aren't already on the list (could be multiple shadows per srb if it's been broken up */
   2.229    for (i = 0; i < MAX_SHADOW_ENTRIES; i++) {
   2.230      if (xvdd->shadows[i].srb) {
   2.231        srb_list_entry_t *srb_entry = xvdd->shadows[i].srb->SrbExtension;
   2.232 @@ -661,7 +653,7 @@ XenVbd_ResetBus(PXENVBD_DEVICE_DATA xvdd
   2.233            break;
   2.234        }
   2.235        if (list_entry == &srb_reset_list) {
   2.236 -        KdPrint((__DRIVER_NAME "     adding in-flight SRB %p to reset list\n", srb_entry->srb));
   2.237 +        FUNCTION_MSG("adding in-flight SRB %p to reset list\n", srb_entry->srb);
   2.238          InsertTailList(&srb_reset_list, &srb_entry->list_entry);
   2.239        }
   2.240        /* set reset here so that the interrupt won't do anything with the srb but will dispose of the shadow entry correctly */
   2.241 @@ -673,8 +665,9 @@ XenVbd_ResetBus(PXENVBD_DEVICE_DATA xvdd
   2.242  
   2.243    while((list_entry = RemoveHeadList(&srb_reset_list)) != &srb_reset_list) {
   2.244      srb_list_entry_t *srb_entry = CONTAINING_RECORD(list_entry, srb_list_entry_t, list_entry);
   2.245 +    srb_entry->outstanding_requests = 0;
   2.246      srb_entry->srb->SrbStatus = SRB_STATUS_BUS_RESET;
   2.247 -    KdPrint((__DRIVER_NAME "     completing SRB %p with status SRB_STATUS_BUS_RESET\n", srb_entry->srb));
   2.248 +    FUNCTION_MSG("completing SRB %p with status SRB_STATUS_BUS_RESET\n", srb_entry->srb);
   2.249      SxxxPortNotification(RequestComplete, xvdd, srb_entry->srb);
   2.250    }
   2.251  
   2.252 @@ -703,6 +696,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.253    PSCSI_REQUEST_BLOCK srb;
   2.254    srb_list_entry_t *srb_entry;
   2.255    PSRB_IO_CONTROL sic;
   2.256 +  ULONG prev_offset;
   2.257  
   2.258    if (xvdd->device_state != DEVICE_STATE_ACTIVE) {
   2.259      FUNCTION_MSG("Not yet active - state = %d\n", xvdd->device_state);
   2.260 @@ -711,6 +705,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.261  
   2.262    while(!xvdd->aligned_buffer_in_use && xvdd->shadow_free && (srb_entry = (srb_list_entry_t *)RemoveHeadList(&xvdd->srb_list)) != (srb_list_entry_t *)&xvdd->srb_list) {
   2.263      srb = srb_entry->srb;
   2.264 +    prev_offset = srb_entry->offset;
   2.265      if (xvdd->device_state == DEVICE_STATE_INACTIVE) {
   2.266        /* need to check again as may have been initialising when this srb was put on the list */
   2.267        FUNCTION_MSG("Inactive Device (in ProcessSrbList)\n");
   2.268 @@ -721,8 +716,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.269  
   2.270      data_transfer_length = srb->DataTransferLength;
   2.271      
   2.272 -    switch (srb->Function)
   2.273 -    {
   2.274 +    switch (srb->Function) {
   2.275      case SRB_FUNCTION_EXECUTE_SCSI:
   2.276        cdb = (PCDB)srb->Cdb;
   2.277  
   2.278 @@ -1234,6 +1228,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.279      case SRB_FUNCTION_RESET_DEVICE:
   2.280      case SRB_FUNCTION_RESET_LOGICAL_UNIT:
   2.281        /* the path doesn't matter here - only ever one device*/
   2.282 +      FUNCTION_MSG("SRB_FUNCTION_RESET_XXX\n");
   2.283        XenVbd_ResetBus(xvdd, 0);
   2.284        srb->SrbStatus = SRB_STATUS_SUCCESS;
   2.285        SxxxPortNotification(RequestComplete, xvdd, srb);    
   2.286 @@ -1255,6 +1250,11 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.287        SxxxPortNotification(RequestComplete, xvdd, srb);
   2.288        break;
   2.289      }
   2.290 +    if ((PLIST_ENTRY)srb_entry == xvdd->srb_list.Flink && srb_entry->offset == prev_offset) {
   2.291 +      FUNCTION_MSG("Same entry\n");
   2.292 +      /* same entry was put back onto the head of the list so we can't progress */
   2.293 +      break;
   2.294 +    }
   2.295    }
   2.296    if (notify) {
   2.297      notify = FALSE;
   2.298 @@ -1265,4 +1265,3 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   2.299    }
   2.300    return;
   2.301  }
   2.302 -
     3.1 --- a/xenvbd_filter/sources	Sun Feb 10 23:14:05 2013 +1100
     3.2 +++ b/xenvbd_filter/sources	Sun Feb 10 23:15:05 2013 +1100
     3.3 @@ -1,5 +1,5 @@
     3.4  !INCLUDE "..\common.inc"
     3.5 -TARGETNAME=xenvbd_filter
     3.6 +TARGETNAME=xenvbdfilter
     3.7  INF_NAME=xenvbd_filter
     3.8  TARGETTYPE=DRIVER
     3.9  KMDF_VERSION_MAJOR=1
     4.1 --- a/xenvbd_filter/xenvbd_filter.c	Sun Feb 10 23:14:05 2013 +1100
     4.2 +++ b/xenvbd_filter/xenvbd_filter.c	Sun Feb 10 23:15:05 2013 +1100
     4.3 @@ -25,7 +25,6 @@ DRIVER_INITIALIZE DriverEntry;
     4.4  
     4.5  static EVT_WDF_DRIVER_UNLOAD XenVbd_EvtDriverUnload;
     4.6  static EVT_WDF_DRIVER_DEVICE_ADD XenVbd_EvtDeviceAdd;
     4.7 -//static EVT_WDF_DEVICE_USAGE_NOTIFICATION XenVbd_EvtDeviceUsageNotification;
     4.8  
     4.9  static VOID XenVbd_DeviceCallback(PVOID context, ULONG callback_type, PVOID value);
    4.10  static VOID XenVbd_HandleEventDIRQL(PVOID context);
    4.11 @@ -34,6 +33,8 @@ static VOID XenVbd_StartRing(PXENVBD_DEV
    4.12  
    4.13  #include "../xenvbd_common/common_xen.h"
    4.14  
    4.15 +static VOID XenVbd_SendEvent(WDFDEVICE device);
    4.16 +
    4.17  static VOID
    4.18  XenVbd_StopRing(PXENVBD_DEVICE_DATA xvdd, BOOLEAN suspend) {
    4.19    PXENVBD_FILTER_DATA xvfd = (PXENVBD_FILTER_DATA)xvdd->xvfd;
    4.20 @@ -53,6 +54,7 @@ XenVbd_StopRing(PXENVBD_DEVICE_DATA xvdd
    4.21  
    4.22      RtlZeroMemory(&stack, sizeof(IO_STACK_LOCATION));
    4.23      stack.MajorFunction = IRP_MJ_SCSI;
    4.24 +    stack.MinorFunction = IRP_MN_SCSI_CLASS;
    4.25      stack.Parameters.Scsi.Srb = &srb;
    4.26  
    4.27      RtlZeroMemory(&srb, SCSI_REQUEST_BLOCK_SIZE);
    4.28 @@ -143,28 +145,25 @@ XenVbd_StartRing(PXENVBD_DEVICE_DATA xvd
    4.29  }
    4.30  
    4.31  static VOID
    4.32 -XenVbd_RequestComplete(WDFREQUEST request, WDFIOTARGET target, PWDF_REQUEST_COMPLETION_PARAMS params, WDFCONTEXT context) {
    4.33 +XenVbd_SendRequestComplete(WDFREQUEST request, WDFIOTARGET target, PWDF_REQUEST_COMPLETION_PARAMS params, WDFCONTEXT context) {
    4.34    NTSTATUS status;
    4.35    PSCSI_REQUEST_BLOCK srb = context;
    4.36  
    4.37    UNREFERENCED_PARAMETER(target);
    4.38    UNREFERENCED_PARAMETER(params);
    4.39    UNREFERENCED_PARAMETER(context);
    4.40 -  
    4.41 +
    4.42    status = WdfRequestGetStatus(request);
    4.43 -  if (status) {
    4.44 -    FUNCTION_MSG("Request Status = %08x\n", status);
    4.45 -    FUNCTION_MSG("SRB Status = %08x\n", srb->SrbStatus);
    4.46 +  if (status != 0 || srb->SrbStatus != SRB_STATUS_SUCCESS) {
    4.47 +    FUNCTION_MSG("Request Status = %08x, SRB Status = %08x\n", status, srb->SrbStatus);
    4.48    }
    4.49    ExFreePoolWithTag(context, XENVBD_POOL_TAG);
    4.50    WdfObjectDelete(request);
    4.51  }
    4.52  
    4.53  static VOID
    4.54 -XenVbd_EvtDpcEvent(WDFDPC dpc) {
    4.55 -  WDFDEVICE device = WdfDpcGetParentObject(dpc);
    4.56 +XenVbd_SendEvent(WDFDEVICE device) {
    4.57    PXENVBD_FILTER_DATA xvfd = GetXvfd(device);
    4.58 -  //PXENVBD_FILTER_DATA xvfd = (PXENVBD_FILTER_DATA)xvdd->xvfd;
    4.59    NTSTATUS status;
    4.60    WDFREQUEST request;
    4.61    WDF_REQUEST_SEND_OPTIONS send_options;
    4.62 @@ -172,21 +171,14 @@ XenVbd_EvtDpcEvent(WDFDPC dpc) {
    4.63    PUCHAR buf;
    4.64    PSCSI_REQUEST_BLOCK srb;
    4.65    PSRB_IO_CONTROL sic;
    4.66 -  
    4.67 -  //FUNCTION_ENTER();
    4.68 +
    4.69    status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES, xvfd->wdf_target, &request);
    4.70 -  //FUNCTION_MSG("WdfRequestCreate = %08x\n", status);
    4.71  
    4.72 -  buf = ExAllocatePoolWithTag(NonPagedPool, sizeof(SRB_IO_CONTROL) + sizeof(SCSI_REQUEST_BLOCK), XENVBD_POOL_TAG);
    4.73 -  RtlZeroMemory(buf, sizeof(SRB_IO_CONTROL) + sizeof(SCSI_REQUEST_BLOCK));
    4.74 +  buf = ExAllocatePoolWithTag(NonPagedPool, sizeof(SCSI_REQUEST_BLOCK) + sizeof(SRB_IO_CONTROL), XENVBD_POOL_TAG);
    4.75 +  RtlZeroMemory(buf, sizeof(SCSI_REQUEST_BLOCK) + sizeof(SRB_IO_CONTROL));
    4.76    srb = (PSCSI_REQUEST_BLOCK)(buf);
    4.77    sic = (PSRB_IO_CONTROL)(buf + sizeof(SCSI_REQUEST_BLOCK));
    4.78    
    4.79 -  sic->HeaderLength = sizeof(SRB_IO_CONTROL);
    4.80 -  memcpy(sic->Signature, XENVBD_CONTROL_SIG, 8);
    4.81 -  sic->Timeout = 60;
    4.82 -  sic->ControlCode = XENVBD_CONTROL_EVENT;
    4.83 -
    4.84    srb->Length = sizeof(SCSI_REQUEST_BLOCK);
    4.85    srb->SrbFlags = SRB_FLAGS_BYPASS_FROZEN_QUEUE | SRB_FLAGS_NO_QUEUE_FREEZE;
    4.86    srb->PathId = 0;
    4.87 @@ -195,28 +187,40 @@ XenVbd_EvtDpcEvent(WDFDPC dpc) {
    4.88    srb->OriginalRequest = WdfRequestWdmGetIrp(request);
    4.89    srb->Function = SRB_FUNCTION_IO_CONTROL;
    4.90    srb->DataBuffer = sic;
    4.91 +  srb->DataTransferLength = sizeof(SCSI_REQUEST_BLOCK) + sizeof(SRB_IO_CONTROL);
    4.92 +  srb->TimeOutValue = (ULONG)-1;
    4.93    
    4.94 +  sic->HeaderLength = sizeof(SRB_IO_CONTROL);
    4.95 +  memcpy(sic->Signature, XENVBD_CONTROL_SIG, 8);
    4.96 +  sic->Timeout = (ULONG)-1;
    4.97 +  sic->ControlCode = XENVBD_CONTROL_EVENT;
    4.98 +
    4.99    RtlZeroMemory(&stack, sizeof(IO_STACK_LOCATION));
   4.100    stack.MajorFunction = IRP_MJ_SCSI;
   4.101 +  stack.MinorFunction = IRP_MN_SCSI_CLASS;
   4.102    stack.Parameters.Scsi.Srb = srb;
   4.103  
   4.104    WdfRequestWdmFormatUsingStackLocation(request, &stack);
   4.105 -  WdfRequestSetCompletionRoutine(request, XenVbd_RequestComplete, srb);
   4.106 +  WdfRequestSetCompletionRoutine(request, XenVbd_SendRequestComplete, buf);
   4.107    
   4.108 -  WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_IGNORE_TARGET_STATE);
   4.109 +  WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, 0); //WDF_REQUEST_SEND_OPTION_IGNORE_TARGET_STATE);
   4.110    if (!WdfRequestSend(request, xvfd->wdf_target, &send_options)) {
   4.111 -    FUNCTION_MSG("Request was _NOT_ sent\n");
   4.112 +    FUNCTION_MSG("Error sending request\n");
   4.113    }
   4.114 -  //FUNCTION_EXIT();
   4.115  }
   4.116  
   4.117  static VOID
   4.118 +XenVbd_EvtDpcEvent(WDFDPC dpc) {
   4.119 +  WDFDEVICE device = WdfDpcGetParentObject(dpc);
   4.120 +
   4.121 +  XenVbd_SendEvent(device);
   4.122 +}  
   4.123 +
   4.124 +static VOID
   4.125  XenVbd_HandleEventDIRQL(PVOID context) {
   4.126    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)context;
   4.127    PXENVBD_FILTER_DATA xvfd = (PXENVBD_FILTER_DATA)xvdd->xvfd;
   4.128 -  //FUNCTION_ENTER();
   4.129    WdfDpcEnqueue(xvfd->dpc);
   4.130 -  //FUNCTION_EXIT();
   4.131  }
   4.132  
   4.133  static NTSTATUS
   4.134 @@ -232,7 +236,7 @@ XenVbd_EvtDeviceD0Entry(WDFDEVICE device
   4.135    return status;
   4.136  }
   4.137  
   4.138 -NTSTATUS
   4.139 +static NTSTATUS
   4.140  XenVbd_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state) {
   4.141    PXENVBD_FILTER_DATA xvfd = GetXvfd(device);
   4.142    NTSTATUS status;
   4.143 @@ -244,27 +248,6 @@ XenVbd_EvtDeviceD0Exit(WDFDEVICE device,
   4.144    return status;
   4.145  }
   4.146  
   4.147 -VOID
   4.148 -XenVbd_EvtIoInternalDeviceControl(WDFQUEUE queue, WDFREQUEST request, size_t output_buffer_length, size_t input_buffer_length, ULONG io_control_code) {
   4.149 -  PXENVBD_FILTER_DATA xvfd = GetXvfd(WdfIoQueueGetDevice(queue));
   4.150 -  WDF_REQUEST_SEND_OPTIONS options;
   4.151 -  NTSTATUS status;
   4.152 -
   4.153 -  UNREFERENCED_PARAMETER(output_buffer_length);
   4.154 -  UNREFERENCED_PARAMETER(input_buffer_length);
   4.155 -  UNREFERENCED_PARAMETER(io_control_code);
   4.156 -
   4.157 -  FUNCTION_ENTER();
   4.158 -  FUNCTION_MSG("io_control_code = %d / %x\n", io_control_code, io_control_code);
   4.159 -  WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
   4.160 -  if (!WdfRequestSend(request, xvfd->wdf_target, &options)) {
   4.161 -    status = WdfRequestGetStatus(request);
   4.162 -    WdfRequestComplete(request, status);
   4.163 -  }
   4.164 -  FUNCTION_EXIT();
   4.165 -  return;
   4.166 -}
   4.167 -
   4.168  static NTSTATUS
   4.169  XenVbd_IoCompletion_START_DEVICE(PDEVICE_OBJECT device, PIRP irp, PVOID context) {
   4.170    UNREFERENCED_PARAMETER(device);
   4.171 @@ -286,16 +269,18 @@ XenVbd_EvtDeviceWdmIrpPreprocess_START_D
   4.172  
   4.173    FUNCTION_ENTER();
   4.174  
   4.175 +  /*
   4.176 +  Pass down the xvdd area as a memory resource. This gives xenvbd the data in a known place
   4.177 +  and also satisifies the scsiport requirement for a memory resource
   4.178 +  */
   4.179    IoCopyCurrentIrpStackLocationToNext(irp);
   4.180    stack = IoGetNextIrpStackLocation(irp);
   4.181 -  FUNCTION_MSG("stack->Parameters.StartDevice.AllocatedResources = %p\n", stack->Parameters.StartDevice.AllocatedResources);
   4.182 -  FUNCTION_MSG("stack->Parameters.StartDevice.AllocatedResourcesTranslated = %p\n", stack->Parameters.StartDevice.AllocatedResourcesTranslated);
   4.183  
   4.184    crl = ExAllocatePoolWithTag(NonPagedPool,
   4.185            FIELD_OFFSET(CM_RESOURCE_LIST, List) +
   4.186            FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   4.187            FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   4.188 -          sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR), XENVBD_POOL_TAG);
   4.189 +          sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1, XENVBD_POOL_TAG);
   4.190    if (!crl) {
   4.191      // TODO: Fail this correctly
   4.192    }
   4.193 @@ -327,42 +312,24 @@ static NTSTATUS
   4.194  XenVbd_EvtDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init) {
   4.195    PXENVBD_FILTER_DATA xvfd;
   4.196    NTSTATUS status;
   4.197 -  //WDF_CHILD_LIST_CONFIG child_list_config;
   4.198    WDFDEVICE device;
   4.199 -  //UNICODE_STRING reference;
   4.200    WDF_OBJECT_ATTRIBUTES device_attributes;
   4.201 -  //PNP_BUS_INFORMATION pbi;
   4.202    WDF_PNPPOWER_EVENT_CALLBACKS pnp_power_callbacks;
   4.203 -  //WDF_INTERRUPT_CONFIG interrupt_config;
   4.204 -  //WDF_OBJECT_ATTRIBUTES file_attributes;
   4.205 -  //WDF_FILEOBJECT_CONFIG file_config;
   4.206 -  WDF_IO_QUEUE_CONFIG queue_config;
   4.207 -  //WDFCOLLECTION veto_devices;
   4.208 -  //WDFKEY param_key;
   4.209 -  //DECLARE_CONST_UNICODE_STRING(veto_devices_name, L"veto_devices");
   4.210 -  //WDF_DEVICE_POWER_CAPABILITIES power_capabilities;
   4.211    WDF_DPC_CONFIG dpc_config;
   4.212    WDF_OBJECT_ATTRIBUTES oa;
   4.213    UCHAR pnp_minor_functions[] = { IRP_MN_START_DEVICE };
   4.214 -  //int i;
   4.215    
   4.216    UNREFERENCED_PARAMETER(driver);
   4.217  
   4.218    FUNCTION_ENTER();
   4.219  
   4.220 +  WdfDeviceInitSetDeviceType(device_init, FILE_DEVICE_UNKNOWN);
   4.221 +
   4.222    WdfFdoInitSetFilter(device_init);
   4.223  
   4.224 -  WdfDeviceInitSetDeviceType(device_init, FILE_DEVICE_UNKNOWN);
   4.225 -
   4.226    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnp_power_callbacks);
   4.227    pnp_power_callbacks.EvtDeviceD0Entry = XenVbd_EvtDeviceD0Entry;
   4.228 -  //pnp_power_callbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenVbd_EvtDeviceD0EntryPostInterruptsEnabled;
   4.229    pnp_power_callbacks.EvtDeviceD0Exit = XenVbd_EvtDeviceD0Exit;
   4.230 -  //pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenVbd_EvtDeviceD0ExitPreInterruptsDisabled;
   4.231 -  //pnp_power_callbacks.EvtDevicePrepareHardware = XenVbd_EvtDevicePrepareHardware;
   4.232 -  //pnp_power_callbacks.EvtDeviceReleaseHardware = XenVbd_EvtDeviceReleaseHardware;
   4.233 -  //pnp_power_callbacks.EvtDeviceQueryRemove = XenVbd_EvtDeviceQueryRemove;
   4.234 -  //pnp_power_callbacks.EvtDeviceUsageNotification = XenVbd_EvtDeviceUsageNotification;
   4.235    WdfDeviceInitSetPnpPowerEventCallbacks(device_init, &pnp_power_callbacks);
   4.236  
   4.237    status = WdfDeviceInitAssignWdmIrpPreprocessCallback(device_init, XenVbd_EvtDeviceWdmIrpPreprocess_START_DEVICE,
   4.238 @@ -396,33 +363,12 @@ XenVbd_EvtDeviceAdd(WDFDRIVER driver, PW
   4.239    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFileHibernation, TRUE);
   4.240    WdfDeviceSetSpecialFileSupport(device, WdfSpecialFileDump, TRUE);
   4.241  
   4.242 -  WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queue_config, WdfIoQueueDispatchParallel);
   4.243 -  queue_config.PowerManaged = WdfFalse;
   4.244 -  queue_config.EvtIoInternalDeviceControl = XenVbd_EvtIoInternalDeviceControl;
   4.245 -  status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xvfd->io_queue);
   4.246 -  if (!NT_SUCCESS(status)) {
   4.247 -    FUNCTION_MSG("Error creating queue 0x%x\n", status);
   4.248 -    return status;
   4.249 -  }
   4.250 -  
   4.251    FUNCTION_EXIT();
   4.252    return status;
   4.253  }
   4.254  
   4.255  NTSTATUS
   4.256 -XenHide_EvtDevicePrepareHardware(WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
   4.257 -{
   4.258 -  UNREFERENCED_PARAMETER(device);
   4.259 -  UNREFERENCED_PARAMETER(resources_raw);
   4.260 -  UNREFERENCED_PARAMETER(resources_translated);
   4.261 -  FUNCTION_ENTER();
   4.262 -  FUNCTION_EXIT();
   4.263 -  return STATUS_UNSUCCESSFUL;
   4.264 -}
   4.265 -
   4.266 -NTSTATUS
   4.267 -DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   4.268 -{
   4.269 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
   4.270    NTSTATUS status;
   4.271    WDF_DRIVER_CONFIG config;
   4.272    WDFDRIVER driver;
     5.1 --- a/xenvbd_scsiport/common.h	Sun Feb 10 23:14:05 2013 +1100
     5.2 +++ b/xenvbd_scsiport/common.h	Sun Feb 10 23:15:05 2013 +1100
     5.3 @@ -56,7 +56,7 @@ struct {
     5.4    blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
     5.5    USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
     5.6    USHORT shadow_free;
     5.7 -  USHORT shadow_min_free;
     5.8 +  //USHORT shadow_min_free;
     5.9    ULONG grant_tag;
    5.10    LIST_ENTRY srb_list;
    5.11    BOOLEAN aligned_buffer_in_use;
     6.1 --- a/xenvbd_scsiport/xenvbd.c	Sun Feb 10 23:14:05 2013 +1100
     6.2 +++ b/xenvbd_scsiport/xenvbd.c	Sun Feb 10 23:15:05 2013 +1100
     6.3 @@ -38,18 +38,30 @@ static ULONG dump_mode_errors = 0;
     6.4  #define StorPortAcquireSpinLock(...) {}
     6.5  #define StorPortReleaseSpinLock(...) {}
     6.6  
     6.7 -#define SxxxPortNotification(NotificationType, DeviceExtension, ...) \
     6.8 -{ \
     6.9 -  if (NotificationType == RequestComplete) ((PXENVBD_SCSIPORT_DATA)((PXENVBD_DEVICE_DATA)DeviceExtension)->xvsd)->outstanding--; \
    6.10 -  ScsiPortNotification(NotificationType, ((PXENVBD_DEVICE_DATA)DeviceExtension)->xvsd, __VA_ARGS__); \
    6.11 +#define SxxxPortNotification(NotificationType, DeviceExtension, ...) XenVbd_Notification##NotificationType(DeviceExtension, __VA_ARGS__)
    6.12 +
    6.13 +VOID
    6.14 +XenVbd_NotificationRequestComplete(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb) {
    6.15 +  PXENVBD_SCSIPORT_DATA xvsd = (PXENVBD_SCSIPORT_DATA)xvdd->xvsd;
    6.16 +  srb_list_entry_t *srb_entry = srb->SrbExtension;
    6.17 +  if (srb_entry->outstanding_requests != 0) {
    6.18 +    FUNCTION_MSG("srb outstanding_requests = %d\n", srb_entry->outstanding_requests);
    6.19 +  }
    6.20 +  xvsd->outstanding--;
    6.21 +  ScsiPortNotification(RequestComplete, xvsd, srb);
    6.22 +}
    6.23 +
    6.24 +VOID
    6.25 +XenVbd_NotificationNextLuRequest(PXENVBD_DEVICE_DATA xvdd, UCHAR PathId, UCHAR TargetId, UCHAR Lun) {
    6.26 +  ScsiPortNotification(NextLuRequest, xvdd->xvsd, PathId, TargetId, Lun);
    6.27  }
    6.28  
    6.29  #include "..\xenvbd_common\common_miniport.h"
    6.30  
    6.31 +
    6.32  /* called in non-dump mode */
    6.33  static ULONG
    6.34 -XenVbd_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
    6.35 -{
    6.36 +XenVbd_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again) {
    6.37    //NTSTATUS status;
    6.38    PXENVBD_SCSIPORT_DATA xvsd = (PXENVBD_SCSIPORT_DATA)DeviceExtension;
    6.39    PXENVBD_DEVICE_DATA xvdd;
    6.40 @@ -63,6 +75,13 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
    6.41    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.42    KdPrint((__DRIVER_NAME "     xvsd = %p\n", xvsd));
    6.43  
    6.44 +  if (dump_mode) {
    6.45 +    if (xvsd->xvdd->device_state != DEVICE_STATE_ACTIVE) {
    6.46 +      /* if we are not connected to the ring when we start dump mode then there is nothing we can do */
    6.47 +      FUNCTION_MSG("Cannot connect backend in dump mode - state = %d\n", xvsd->xvdd->device_state);
    6.48 +      return SP_RETURN_ERROR;
    6.49 +    }
    6.50 +  }
    6.51    if (ConfigInfo->NumberOfAccessRanges != 1) {
    6.52      FUNCTION_MSG("NumberOfAccessRanges wrong\n");
    6.53      FUNCTION_EXIT();
    6.54 @@ -125,8 +144,7 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
    6.55  
    6.56  /* Called at PASSIVE_LEVEL for non-dump mode */
    6.57  static BOOLEAN
    6.58 -XenVbd_HwScsiInitialize(PVOID DeviceExtension)
    6.59 -{
    6.60 +XenVbd_HwScsiInitialize(PVOID DeviceExtension) {
    6.61    PXENVBD_SCSIPORT_DATA xvsd = (PXENVBD_SCSIPORT_DATA)DeviceExtension;
    6.62    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)xvsd->xvdd;
    6.63    ULONG i;
    6.64 @@ -162,6 +180,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    6.65  {
    6.66    PXENVBD_SCSIPORT_DATA xvsd = DeviceExtension;
    6.67    XenVbd_HandleEvent(xvsd->xvdd);
    6.68 +  //SxxxPortNotification(NextLuRequest, xvdd, 0, 0, 0);
    6.69    return TRUE;
    6.70  }
    6.71  
    6.72 @@ -185,14 +204,14 @@ XenVbd_CompleteDisconnect(PXENVBD_DEVICE
    6.73  }
    6.74  
    6.75  static BOOLEAN
    6.76 -XenVbd_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK srb)
    6.77 -{
    6.78 +XenVbd_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK srb) {
    6.79    PXENVBD_SCSIPORT_DATA xvsd = DeviceExtension;
    6.80    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)xvsd->xvdd;
    6.81    PSRB_IO_CONTROL sic;
    6.82  
    6.83 -  //FUNCTION_ENTER();
    6.84 -  //FUNCTION_MSG("HwScsiStartIo Srb = %p, PathId = %d, TargetId = %d, Lun = %d\n", srb, srb->PathId, srb->TargetId, srb->Lun);
    6.85 +  if ((LONG)xvsd->outstanding < 0) {
    6.86 +    FUNCTION_MSG("HwScsiStartIo outstanding = %d\n", xvsd->outstanding);
    6.87 +  }
    6.88    if (srb->PathId != 0 || srb->TargetId != 0 || srb->Lun != 0) {
    6.89      FUNCTION_MSG("HwScsiStartIo (Out of bounds - PathId = %d, TargetId = %d, Lun = %d)\n", srb->PathId, srb->TargetId, srb->Lun);
    6.90      srb->SrbStatus = SRB_STATUS_NO_DEVICE;
    6.91 @@ -201,23 +220,26 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
    6.92      sic = srb->DataBuffer;
    6.93      switch(sic->ControlCode) {
    6.94      case XENVBD_CONTROL_EVENT:
    6.95 -      XenVbd_HandleEvent(xvdd);
    6.96        srb->SrbStatus = SRB_STATUS_SUCCESS;
    6.97        ScsiPortNotification(RequestComplete, xvsd, srb);
    6.98 +      break;
    6.99      case XENVBD_CONTROL_STOP:
   6.100        if (xvdd->shadow_free == SHADOW_ENTRIES) {
   6.101          srb->SrbStatus = SRB_STATUS_SUCCESS;
   6.102          ScsiPortNotification(RequestComplete, xvsd, srb);
   6.103 +        FUNCTION_MSG("CONTROL_STOP done\n");
   6.104        } else {
   6.105          xvsd->stop_srb = srb;
   6.106 +        FUNCTION_MSG("CONTROL_STOP pended\n");
   6.107        }
   6.108        break;
   6.109      case XENVBD_CONTROL_START:
   6.110 -      XenVbd_ProcessSrbList(xvdd);
   6.111 +      // we might need to reload a few things here...
   6.112 +      ScsiPortNotification(RequestComplete, xvsd, srb);
   6.113        break;
   6.114      default:
   6.115        FUNCTION_MSG("XENVBD_CONTROL_%d\n", sic->ControlCode);
   6.116 -      srb->SrbStatus = SRB_STATUS_SUCCESS;
   6.117 +      srb->SrbStatus = SRB_STATUS_ERROR;
   6.118        ScsiPortNotification(RequestComplete, xvsd, srb);
   6.119        break;
   6.120      }
   6.121 @@ -228,15 +250,16 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   6.122    } else {
   6.123      xvsd->outstanding++;
   6.124      XenVbd_PutSrbOnList(xvdd, srb);
   6.125 -    XenVbd_ProcessSrbList(xvdd);
   6.126    }
   6.127 -  /* need 2 spare slots - 1 for EVENT and one for STOP/START */
   6.128 +  XenVbd_HandleEvent(xvdd); /* drain the ring */
   6.129 +  XenVbd_ProcessSrbList(xvdd); /* put new requests on */
   6.130 +  XenVbd_HandleEvent(xvdd); /* drain the ring again and also set event based on requests just added */
   6.131 +  /* need 2 spare slots - 1 for EVENT and 1 for STOP/START */
   6.132    if (xvsd->outstanding < 30) {
   6.133 -    ScsiPortNotification(NextLuRequest, xvsd, srb->PathId, srb->TargetId, srb->Lun);
   6.134 +    ScsiPortNotification(NextLuRequest, xvsd, 0, 0, 0);
   6.135    } else {
   6.136      ScsiPortNotification(NextRequest, xvsd);
   6.137    }
   6.138 -  //FUNCTION_EXIT();
   6.139    return TRUE;
   6.140  }
   6.141  
   6.142 @@ -247,7 +270,6 @@ XenVbd_HwScsiAdapterControl(PVOID Device
   6.143    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)xvsd->xvdd;
   6.144    SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
   6.145    PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
   6.146 -  //KIRQL OldIrql;
   6.147  
   6.148    FUNCTION_ENTER();
   6.149    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   6.150 @@ -273,8 +295,7 @@ XenVbd_HwScsiAdapterControl(PVOID Device
   6.151      break;
   6.152    case ScsiRestartAdapter:
   6.153      KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   6.154 -    if (xvdd->device_state == DEVICE_STATE_INACTIVE)
   6.155 -    {
   6.156 +    if (xvdd->device_state == DEVICE_STATE_INACTIVE) {
   6.157        KdPrint((__DRIVER_NAME "     inactive - nothing to do\n"));
   6.158        break;
   6.159      }
   6.160 @@ -304,6 +325,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   6.161    
   6.162    /* RegistryPath == NULL when we are invoked as a crash dump driver */
   6.163    if (!RegistryPath) {
   6.164 +    KdPrint((__DRIVER_NAME "     IRQL = %d (if you can read this we aren't in dump mode)\n", KeGetCurrentIrql()));
   6.165      dump_mode = TRUE;
   6.166      // TODO: what if hibernate and not dump?
   6.167      XnDumpModeHookDebugPrint();
     7.1 --- a/xenvbd_scsiport/xenvbd.inx	Sun Feb 10 23:14:05 2013 +1100
     7.2 +++ b/xenvbd_scsiport/xenvbd.inx	Sun Feb 10 23:15:05 2013 +1100
     7.3 @@ -15,33 +15,33 @@ ExcludeFromSelect=*
     7.4  %XenGplPv%=XenGplPv,NT$ARCH$
     7.5  
     7.6  [XenGplPv.NT$ARCH$]
     7.7 -%XenVbd.DRVDESC%=XenVbdScsiPort_Inst, XEN\VBD
     7.8 +%XenVbd.DRVDESC%=XenVbd_Inst, XEN\VBD
     7.9  
    7.10  [XenGplPv]
    7.11 -%XenVbd.DRVDESC%=XenVbdScsiPort_Inst, XEN\VBD
    7.12 +%XenVbd.DRVDESC%=XenVbd_Inst, XEN\VBD
    7.13  
    7.14 -[XenVbdScsiPort_Inst.NT]
    7.15 -CopyFiles=XenVbdScsiPort.CopyFiles
    7.16 +[XenVbd_Inst.NT]
    7.17 +CopyFiles=XenVbd.CopyFiles
    7.18  
    7.19 -[XenVbdScsiPort.CopyFiles]
    7.20 +[XenVbd.CopyFiles]
    7.21  xenvbd.sys,,0x00001000 ; COPYFLG_REPLACE_BOOT_FILE
    7.22 -xenvbd_filter.sys,,0x00001000 ; COPYFLG_REPLACE_BOOT_FILE
    7.23 +xenvbdfilter.sys,,0x00001000 ; COPYFLG_REPLACE_BOOT_FILE
    7.24  
    7.25 -[XenVbdScsiPort_Inst.HW]
    7.26 -AddReg=XenvbdScsiPort_HW_AddReg
    7.27 +[XenVbd_Inst.NT.HW]
    7.28 +AddReg=XenVbd_HW_AddReg
    7.29  
    7.30 -[XenVbdScsiPort_Inst.NT.Services]
    7.31 -AddService=XenVbdScsiPort,2,XenVbdScsiPort_Service, XenVbdScsiPort_EventLog
    7.32 +[XenVbd_Inst.NT.Services]
    7.33 +AddService=XenVbd,2,XenVbd_Service, XenVbd_EventLog
    7.34  AddService=XenVbdFilter,,XenVbdFilter_Service
    7.35  
    7.36 -[XenVbdScsiPort_Service]
    7.37 -DisplayName    = %XenVbdScsiPort.SVCDESC%
    7.38 +[XenVbd_Service]
    7.39 +DisplayName    = %XenVbd.SVCDESC%
    7.40  ServiceType    = 1
    7.41  StartType      = 0
    7.42  ErrorControl   = 1
    7.43  LoadOrderGroup = System Bus Extender
    7.44  ServiceBinary  = %12%\xenvbd.sys
    7.45 -AddReg = XenVbdScsiPort_Service_AddReg
    7.46 +AddReg = XenVbd_Service_AddReg
    7.47  
    7.48  [XenVbdFilter_Service]
    7.49  DisplayName    = %XenVbdFilter.SVCDESC%
    7.50 @@ -49,13 +49,13 @@ ServiceType    = 1
    7.51  StartType      = 0
    7.52  ErrorControl   = 1
    7.53  LoadOrderGroup = System Bus Extender
    7.54 -ServiceBinary  = %12%\xenvbd_filter.sys
    7.55 +ServiceBinary  = %12%\xenvbdfilter.sys
    7.56  AddReg = XenVbdFilter_Service_AddReg
    7.57  
    7.58 -[XenVbdScsiPort_HW_AddReg]
    7.59 +[XenVbd_HW_AddReg]
    7.60  HKR,,"UpperFilters", 0x00010000, "XenVbdFilter"
    7.61  
    7.62 -[XenVbdScsiPort_Service_AddReg]
    7.63 +[XenVbd_Service_AddReg]
    7.64  HKR,"Parameters\PnpInterface", "15", 0x00010001, 0x00000001
    7.65  ; hide Qemu IDE in XenPCI
    7.66  HKLM,"SYSTEM\CurrentControlSet\Services\XenPCI\Parameters", "hide_devices", 0x00010008, "#vbd#"
    7.67 @@ -69,16 +69,16 @@ HKLM,"SYSTEM\CurrentControlSet\Services\
    7.68  [XenVbdFilter_Service_AddReg]
    7.69  HKR,"Parameters\PnpInterface", "15", 0x00010001, 0x00000001
    7.70  
    7.71 -[XenVbdScsiPort_EventLog]
    7.72 -AddReg = XenVbdScsiPort_EventLog_AddReg
    7.73 +[XenVbd_EventLog]
    7.74 +AddReg = XenVbd_EventLog_AddReg
    7.75  
    7.76 -[XenVbdScsiPort_EventLog_AddReg]
    7.77 +[XenVbd_EventLog_AddReg]
    7.78  HKR,,EventMessageFile,0x00020000,"%SystemRoot%\System32\IoLogMsg.dll;%SystemRoot%\System32\drivers\XenVbd.sys"
    7.79  HKR,,TypesSupported,0x00010001,7
    7.80  
    7.81  [SourceDisksFiles]
    7.82  xenvbd.sys=1
    7.83 -xenvbd_filter.sys=1
    7.84 +xenvbdfilter.sys=1
    7.85  
    7.86  [SourceDisksNames]
    7.87  1 = %DISK_NAME%
    7.88 @@ -86,7 +86,7 @@ 1 = %DISK_NAME%
    7.89  [Strings]
    7.90  XenGplPv = "Xen GPL PV Driver Developers"
    7.91  XenVbd.DRVDESC = "Xen Block Device Driver"
    7.92 -XenVbdScsiPort.SVCDESC = "Xen Block Device Driver"
    7.93 +XenVbd.SVCDESC = "Xen Block Device Driver"
    7.94  XenVbdFilter.SVCDESC = "Xen Block Device Filter"
    7.95  DISK_NAME = "Xen Block Device Driver Install Disk"
    7.96  FLG_ADDREG_TYPE_DWORD = 0x00010001