win-pvdrivers

changeset 1035:b3de9dba6fee test

Add missing code for backend initiated device removal
author James Harper <james.harper@bendigoit.com.au>
date Sun Mar 03 15:03:00 2013 +1100 (2013-03-03)
parents aa7329b5211b
children 8eda499eaed2
files xenpci/xenpci_export.c
line diff
     1.1 --- a/xenpci/xenpci_export.c	Sun Mar 03 13:50:23 2013 +1100
     1.2 +++ b/xenpci/xenpci_export.c	Sun Mar 03 15:03:00 2013 +1100
     1.3 @@ -32,6 +32,7 @@ XenPci_BackendStateCallback(char *path, 
     1.4    PCHAR err;
     1.5    PCHAR value;
     1.6    ULONG backend_state;
     1.7 +  ULONG frontend_state;
     1.8    
     1.9    FUNCTION_ENTER();
    1.10    //RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
    1.11 @@ -48,6 +49,28 @@ XenPci_BackendStateCallback(char *path, 
    1.12    FUNCTION_MSG("Read value=%s\n", value);
    1.13    backend_state = atoi(value);
    1.14    XenPci_FreeMem(value);
    1.15 +  if (backend_state == XenbusStateClosing) {
    1.16 +    /* check to see if transition to closing was initiated by backend */
    1.17 +    CHAR frontend_state_path[128];
    1.18 +    FUNCTION_MSG("backend path is closing. checking frontend path\n");
    1.19 +    RtlStringCbCopyA(frontend_state_path, ARRAY_SIZE(frontend_state_path), xppdd->path);
    1.20 +    RtlStringCbCatA(frontend_state_path, ARRAY_SIZE(frontend_state_path), "/state");
    1.21 +    err = XenBus_Read(xpdd, XBT_NIL, frontend_state_path, &value);
    1.22 +    if (err) {
    1.23 +      FUNCTION_MSG("Error %s\n", err);
    1.24 +      XenPci_FreeMem(err);
    1.25 +      FUNCTION_EXIT();
    1.26 +      return;
    1.27 +    }
    1.28 +    FUNCTION_MSG("Read value=%s\n", value);
    1.29 +    frontend_state = atoi(value);
    1.30 +    XenPci_FreeMem(value);
    1.31 +    if (frontend_state == XenbusStateConnected) {
    1.32 +      FUNCTION_MSG("initiated by backend. Requesting eject\n");
    1.33 +      /* frontend is still connected. disconnection was initiated by backend */
    1.34 +      WdfPdoRequestEject(xppdd->wdf_device);
    1.35 +    }
    1.36 +  }
    1.37    xppdd->device_callback(xppdd->device_callback_context, XN_DEVICE_CALLBACK_BACKEND_STATE, (PVOID)(ULONG_PTR)backend_state);
    1.38    FUNCTION_EXIT();
    1.39  }