win-pvdrivers

changeset 1052:5bb1f345e06a 0.11.0.404

add timeout for xennet init
author James Harper <james.harper@bendigoit.com.au>
date Tue May 21 16:10:03 2013 +1000 (2013-05-21)
parents ca993d6b5539
children 013c44008e93
files xennet/xennet.c xennet/xennet_common.c
line diff
     1.1 --- a/xennet/xennet.c	Tue May 21 16:09:35 2013 +1000
     1.2 +++ b/xennet/xennet.c	Tue May 21 16:10:03 2013 +1000
     1.3 @@ -268,7 +268,10 @@ XenNet_Initialize(NDIS_HANDLE adapter_ha
     1.4  
     1.5    NdisCloseConfiguration(config_handle);
     1.6  
     1.7 -  XenNet_Connect(xi, FALSE);
     1.8 +  status = XenNet_Connect(xi, FALSE);
     1.9 +  if (!NT_SUCCESS(status)) {
    1.10 +    goto err;
    1.11 +  }
    1.12  
    1.13    if (!xi->backend_sg_supported)
    1.14      xi->backend_gso_value = min(xi->backend_gso_value, PAGE_SIZE - MAX_PKT_HEADER_LENGTH);
     2.1 --- a/xennet/xennet_common.c	Tue May 21 16:09:35 2013 +1000
     2.2 +++ b/xennet/xennet_common.c	Tue May 21 16:10:03 2013 +1000
     2.3 @@ -354,6 +354,7 @@ XenNet_Connect(PVOID context, BOOLEAN su
     2.4    ULONG octet;
     2.5    PCHAR tmp_string;
     2.6    ULONG tmp_ulong;
     2.7 +  LARGE_INTEGER timeout;
     2.8  
     2.9    if (!suspend) {
    2.10      xi->handle = XnOpenDevice(xi->pdo, XenNet_DeviceCallback, xi);
    2.11 @@ -376,7 +377,8 @@ XenNet_Connect(PVOID context, BOOLEAN su
    2.12        if (xi->backend_state == XenbusStateClosed) {
    2.13          status = XnWriteInt32(xi->handle, XN_BASE_FRONTEND, "state", XenbusStateInitialising);
    2.14        }
    2.15 -      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, NULL);
    2.16 +      timeout.QuadPart = -10 * 1000 * 1000; /* 1 second */
    2.17 +      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, &timeout);
    2.18      }
    2.19      if (xi->backend_state != XenbusStateInitialising && xi->backend_state != XenbusStateInitWait && xi->backend_state != XenbusStateInitialised) {
    2.20        FUNCTION_MSG("Backend state timeout\n");
    2.21 @@ -480,7 +482,8 @@ XenNet_Connect(PVOID context, BOOLEAN su
    2.22  
    2.23      for (i = 0; i <= 5 && xi->backend_state != XenbusStateConnected; i++) {
    2.24        FUNCTION_MSG("Waiting for XenbusStateConnected\n");
    2.25 -      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, NULL);
    2.26 +      timeout.QuadPart = -10 * 1000 * 1000; /* 1 second */
    2.27 +      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, &timeout);
    2.28      }
    2.29      if (xi->backend_state != XenbusStateConnected) {
    2.30        FUNCTION_MSG("Backend state timeout\n");
    2.31 @@ -499,6 +502,7 @@ NTSTATUS
    2.32  XenNet_Disconnect(PVOID context, BOOLEAN suspend) {
    2.33    struct xennet_info *xi = (struct xennet_info *)context;
    2.34    //PFN_NUMBER pfn;
    2.35 +  LARGE_INTEGER timeout;
    2.36    NTSTATUS status;
    2.37  
    2.38    if (xi->device_state != DEVICE_STATE_ACTIVE && xi->device_state != DEVICE_STATE_INACTIVE) {
    2.39 @@ -511,12 +515,14 @@ XenNet_Disconnect(PVOID context, BOOLEAN
    2.40      status = XnWriteInt32(xi->handle, XN_BASE_FRONTEND, "state", XenbusStateClosing);
    2.41      while (xi->backend_state != XenbusStateClosing && xi->backend_state != XenbusStateClosed) {
    2.42        FUNCTION_MSG("Waiting for XenbusStateClosing/Closed\n");
    2.43 -      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, NULL);
    2.44 +      timeout.QuadPart = -10 * 1000 * 1000; /* 1 second */
    2.45 +      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, &timeout);
    2.46      }
    2.47      status = XnWriteInt32(xi->handle, XN_BASE_FRONTEND, "state", XenbusStateClosed);
    2.48      while (xi->backend_state != XenbusStateClosed) {
    2.49        FUNCTION_MSG("Waiting for XenbusStateClosed\n");
    2.50 -      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, NULL);
    2.51 +      timeout.QuadPart = -10 * 1000 * 1000; /* 1 second */
    2.52 +      KeWaitForSingleObject(&xi->backend_event, Executive, KernelMode, FALSE, &timeout);
    2.53      }
    2.54      XnUnbindEvent(xi->handle, xi->event_channel);
    2.55      
    2.56 @@ -541,6 +547,7 @@ VOID
    2.57  XenNet_DeviceCallback(PVOID context, ULONG callback_type, PVOID value) {
    2.58    struct xennet_info *xi = (struct xennet_info *)context;
    2.59    ULONG state;
    2.60 +  NTSTATUS status;
    2.61    
    2.62    FUNCTION_ENTER();
    2.63    switch (callback_type) {
    2.64 @@ -561,7 +568,8 @@ XenNet_DeviceCallback(PVOID context, ULO
    2.65    case XN_DEVICE_CALLBACK_RESUME:
    2.66      FUNCTION_MSG("XN_DEVICE_CALLBACK_RESUME");
    2.67      xi->device_state = DEVICE_STATE_INITIALISING;
    2.68 -    XenNet_Connect(xi, TRUE);
    2.69 +    status = XenNet_Connect(xi, TRUE);
    2.70 +    // TODO: what to do here if not success?
    2.71      if (xi->device_state != DEVICE_STATE_INACTIVE) {
    2.72        xi->device_state = DEVICE_STATE_ACTIVE;
    2.73      }