VirtualBox

Changeset 59261 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Jan 6, 2016 11:32:38 AM (9 years ago)
Author:
vboxsync
Message:

PDMAsyncCompletion: Don't return an already existing endpoint handle when a file is opened multiple times but create a new handle everytime, fixes a crash when an ISO images is attached multiple times to the same VM

Location:
trunk/src/VBox/VMM/VMMR3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PDMAsyncCompletion.cpp

    r58170 r59261  
    10541054                             STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
    10551055                             "Nanosecond resolution runtime statistics",
    1056                              "/PDM/AsyncCompletion/File/%s/TaskRun1Ns-%u-%u",
    1057                              RTPathFilename(pEndpoint->pszUri), i*100, i*100+100-1);
     1056                             "/PDM/AsyncCompletion/File/%s/%d/TaskRun1Ns-%u-%u",
     1057                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId, i*100, i*100+100-1);
    10581058
    10591059    for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesUs) && RT_SUCCESS(rc); i++)
     
    10611061                             STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
    10621062                             "Microsecond resolution runtime statistics",
    1063                              "/PDM/AsyncCompletion/File/%s/TaskRun2MicroSec-%u-%u",
    1064                              RTPathFilename(pEndpoint->pszUri), i*100, i*100+100-1);
     1063                             "/PDM/AsyncCompletion/File/%s/%d/TaskRun2MicroSec-%u-%u",
     1064                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId, i*100, i*100+100-1);
    10651065
    10661066    for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs) && RT_SUCCESS(rc); i++)
     
    10681068                             STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
    10691069                             "Milliseconds resolution runtime statistics",
    1070                              "/PDM/AsyncCompletion/File/%s/TaskRun3Ms-%u-%u",
    1071                              RTPathFilename(pEndpoint->pszUri), i*100, i*100+100-1);
     1070                             "/PDM/AsyncCompletion/File/%s/%d/TaskRun3Ms-%u-%u",
     1071                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId, i*100, i*100+100-1);
    10721072
    10731073    for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs) && RT_SUCCESS(rc); i++)
     
    10751075                             STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
    10761076                             "Second resolution runtime statistics",
    1077                              "/PDM/AsyncCompletion/File/%s/TaskRun4Sec-%u-%u",
    1078                              RTPathFilename(pEndpoint->pszUri), i*10, i*10+10-1);
     1077                             "/PDM/AsyncCompletion/File/%s/%d/TaskRun4Sec-%u-%u",
     1078                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId, i*10, i*10+10-1);
    10791079
    10801080    if (RT_SUCCESS(rc))
     
    10821082                             STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
    10831083                             "Tasks which ran more than 100sec",
    1084                              "/PDM/AsyncCompletion/File/%s/TaskRunSecGreater100Sec",
    1085                              RTPathFilename(pEndpoint->pszUri));
     1084                             "/PDM/AsyncCompletion/File/%s/%d/TaskRunSecGreater100Sec",
     1085                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    10861086
    10871087    if (RT_SUCCESS(rc))
     
    10891089                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    10901090                             "Processed I/O operations per second",
    1091                              "/PDM/AsyncCompletion/File/%s/IoOpsPerSec",
    1092                              RTPathFilename(pEndpoint->pszUri));
     1091                             "/PDM/AsyncCompletion/File/%s/%d/IoOpsPerSec",
     1092                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    10931093
    10941094    if (RT_SUCCESS(rc))
     
    10961096                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    10971097                             "Started I/O operations for this endpoint",
    1098                              "/PDM/AsyncCompletion/File/%s/IoOpsStarted",
    1099                              RTPathFilename(pEndpoint->pszUri));
     1098                             "/PDM/AsyncCompletion/File/%s/%d/IoOpsStarted",
     1099                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11001100
    11011101    if (RT_SUCCESS(rc))
     
    11031103                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11041104                             "Completed I/O operations for this endpoint",
    1105                              "/PDM/AsyncCompletion/File/%s/IoOpsCompleted",
    1106                              RTPathFilename(pEndpoint->pszUri));
     1105                             "/PDM/AsyncCompletion/File/%s/%d/IoOpsCompleted",
     1106                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11071107
    11081108    if (RT_SUCCESS(rc))
     
    11101110                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11111111                             "Number of requests with a size smaller than 512 bytes",
    1112                              "/PDM/AsyncCompletion/File/%s/ReqSizeSmaller512",
    1113                              RTPathFilename(pEndpoint->pszUri));
     1112                             "/PDM/AsyncCompletion/File/%s/%d/ReqSizeSmaller512",
     1113                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11141114
    11151115    if (RT_SUCCESS(rc))
     
    11171117                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11181118                             "Number of requests with a size between 512 bytes and 1KB",
    1119                              "/PDM/AsyncCompletion/File/%s/ReqSize512To1K",
    1120                              RTPathFilename(pEndpoint->pszUri));
     1119                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize512To1K",
     1120                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11211121
    11221122    if (RT_SUCCESS(rc))
     
    11241124                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11251125                             "Number of requests with a size between 1KB and 2KB",
    1126                              "/PDM/AsyncCompletion/File/%s/ReqSize1KTo2K",
    1127                              RTPathFilename(pEndpoint->pszUri));
     1126                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize1KTo2K",
     1127                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11281128
    11291129    if (RT_SUCCESS(rc))
     
    11311131                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11321132                             "Number of requests with a size between 2KB and 4KB",
    1133                              "/PDM/AsyncCompletion/File/%s/ReqSize2KTo4K",
    1134                              RTPathFilename(pEndpoint->pszUri));
     1133                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize2KTo4K",
     1134                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11351135
    11361136    if (RT_SUCCESS(rc))
     
    11381138                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11391139                             "Number of requests with a size between 4KB and 8KB",
    1140                              "/PDM/AsyncCompletion/File/%s/ReqSize4KTo8K",
    1141                              RTPathFilename(pEndpoint->pszUri));
     1140                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize4KTo8K",
     1141                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11421142
    11431143    if (RT_SUCCESS(rc))
     
    11451145                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11461146                             "Number of requests with a size between 8KB and 16KB",
    1147                              "/PDM/AsyncCompletion/File/%s/ReqSize8KTo16K",
    1148                              RTPathFilename(pEndpoint->pszUri));
     1147                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize8KTo16K",
     1148                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11491149
    11501150    if (RT_SUCCESS(rc))
     
    11521152                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11531153                             "Number of requests with a size between 16KB and 32KB",
    1154                              "/PDM/AsyncCompletion/File/%s/ReqSize16KTo32K",
    1155                              RTPathFilename(pEndpoint->pszUri));
     1154                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize16KTo32K",
     1155                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11561156
    11571157    if (RT_SUCCESS(rc))
     
    11591159                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11601160                             "Number of requests with a size between 32KB and 64KB",
    1161                              "/PDM/AsyncCompletion/File/%s/ReqSize32KTo64K",
    1162                              RTPathFilename(pEndpoint->pszUri));
     1161                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize32KTo64K",
     1162                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11631163
    11641164    if (RT_SUCCESS(rc))
     
    11661166                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11671167                             "Number of requests with a size between 64KB and 128KB",
    1168                              "/PDM/AsyncCompletion/File/%s/ReqSize64KTo128K",
    1169                              RTPathFilename(pEndpoint->pszUri));
     1168                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize64KTo128K",
     1169                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11701170
    11711171    if (RT_SUCCESS(rc))
     
    11731173                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11741174                             "Number of requests with a size between 128KB and 256KB",
    1175                              "/PDM/AsyncCompletion/File/%s/ReqSize128KTo256K",
    1176                              RTPathFilename(pEndpoint->pszUri));
     1175                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize128KTo256K",
     1176                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11771177
    11781178    if (RT_SUCCESS(rc))
     
    11801180                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11811181                             "Number of requests with a size between 256KB and 512KB",
    1182                              "/PDM/AsyncCompletion/File/%s/ReqSize256KTo512K",
    1183                              RTPathFilename(pEndpoint->pszUri));
     1182                             "/PDM/AsyncCompletion/File/%s/%d/ReqSize256KTo512K",
     1183                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11841184
    11851185    if (RT_SUCCESS(rc))
     
    11871187                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11881188                             "Number of requests with a size over 512KB",
    1189                              "/PDM/AsyncCompletion/File/%s/ReqSizeOver512K",
    1190                              RTPathFilename(pEndpoint->pszUri));
     1189                             "/PDM/AsyncCompletion/File/%s/%d/ReqSizeOver512K",
     1190                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11911191
    11921192    if (RT_SUCCESS(rc))
     
    11941194                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    11951195                             "Number of requests which size is not aligned to 512 bytes",
    1196                              "/PDM/AsyncCompletion/File/%s/ReqsUnaligned512",
    1197                              RTPathFilename(pEndpoint->pszUri));
     1196                             "/PDM/AsyncCompletion/File/%s/%d/ReqsUnaligned512",
     1197                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    11981198
    11991199    if (RT_SUCCESS(rc))
     
    12011201                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    12021202                             "Number of requests which size is not aligned to 4KB",
    1203                              "/PDM/AsyncCompletion/File/%s/ReqsUnaligned4K",
    1204                              RTPathFilename(pEndpoint->pszUri));
     1203                             "/PDM/AsyncCompletion/File/%s/%d/ReqsUnaligned4K",
     1204                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    12051205
    12061206    if (RT_SUCCESS(rc))
     
    12081208                             STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    12091209                             "Number of requests which size is not aligned to 8KB",
    1210                              "/PDM/AsyncCompletion/File/%s/ReqsUnaligned8K",
    1211                              RTPathFilename(pEndpoint->pszUri));
     1210                             "/PDM/AsyncCompletion/File/%s/%d/ReqsUnaligned8K",
     1211                             RTPathFilename(pEndpoint->pszUri), pEndpoint->iStatId);
    12121212
    12131213    return rc;
     
    13771377
    13781378
    1379 static PPDMASYNCCOMPLETIONENDPOINT
    1380 pdmR3AsyncCompletionFindEndpointWithUri(PPDMASYNCCOMPLETIONEPCLASS pEndpointClass, const char *pszUri)
     1379static unsigned
     1380pdmR3AsyncCompletionGetStatId(PPDMASYNCCOMPLETIONEPCLASS pEndpointClass, const char *pszUri)
    13811381{
    13821382    PPDMASYNCCOMPLETIONENDPOINT pEndpoint = pEndpointClass->pEndpointsHead;
     1383    const char *pszFilename = RTPathFilename(pszUri);
     1384    unsigned iStatId = 0;
    13831385
    13841386    while (pEndpoint)
    13851387    {
    1386         if (!RTStrCmp(pEndpoint->pszUri, pszUri))
    1387             return pEndpoint;
     1388        if (   !RTStrCmp(RTPathFilename(pEndpoint->pszUri), pszFilename)
     1389            && pEndpoint->iStatId >= iStatId)
     1390            iStatId = pEndpoint->iStatId + 1;
    13881391
    13891392        pEndpoint = pEndpoint->pNext;
    13901393    }
    13911394
    1392     return NULL;
    1393 }
    1394 
     1395    return iStatId;
     1396}
    13951397
    13961398/**
     
    14271429    AssertMsg(pEndpointClass, ("File endpoint class was not initialized\n"));
    14281430
    1429     /* Search for a already opened endpoint for this file. */
    1430     pEndpoint = pdmR3AsyncCompletionFindEndpointWithUri(pEndpointClass, pszFilename);
    1431     if (pEndpoint)
    1432     {
    1433         /* Endpoint found. */
    1434         pEndpoint->cUsers++;
    1435 
    1436         *ppEndpoint = pEndpoint;
    1437         return VINF_SUCCESS;
    1438     }
    1439 
    14401431    /* Create an endpoint. */
    14411432    int rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_ASYNC_COMPLETION,
     
    14501441        pEndpoint->pTemplate         = pTemplate;
    14511442        pEndpoint->pszUri            = RTStrDup(pszFilename);
    1452         pEndpoint->cUsers            = 1;
     1443        pEndpoint->iStatId           = pdmR3AsyncCompletionGetStatId(pEndpointClass, pszFilename);
    14531444        pEndpoint->pBwMgr            = NULL;
    14541445
     
    14861477                    return VINF_SUCCESS;
    14871478                }
     1479                else
     1480                    pEndpointClass->pEndpointOps->pfnEpClose(pEndpoint);
    14881481
    14891482                if (pEndpointClass->fGatherAdvancedStatistics)
     
    15131506    AssertReturnVoid(VALID_PTR(pEndpoint));
    15141507
    1515     pEndpoint->cUsers--;
    1516 
    1517     /* If the last user closed the endpoint we will free it. */
    1518     if (!pEndpoint->cUsers)
    1519     {
    1520         PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pEndpoint->pEpClass;
    1521         PVM pVM = pEndpointClass->pVM;
    1522 
    1523         pEndpointClass->pEndpointOps->pfnEpClose(pEndpoint);
    1524 
    1525         /* Drop reference from the template. */
    1526         ASMAtomicDecU32(&pEndpoint->pTemplate->cUsed);
    1527 
    1528         /* Unlink the endpoint from the list. */
    1529         int rc = RTCritSectEnter(&pEndpointClass->CritSect);
    1530         AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
    1531 
    1532         PPDMASYNCCOMPLETIONENDPOINT pEndpointNext = pEndpoint->pNext;
    1533         PPDMASYNCCOMPLETIONENDPOINT pEndpointPrev = pEndpoint->pPrev;
    1534 
    1535         if (pEndpointPrev)
    1536             pEndpointPrev->pNext = pEndpointNext;
    1537         else
    1538             pEndpointClass->pEndpointsHead = pEndpointNext;
    1539         if (pEndpointNext)
    1540             pEndpointNext->pPrev = pEndpointPrev;
    1541 
    1542         pEndpointClass->cEndpoints--;
    1543 
    1544         rc = RTCritSectLeave(&pEndpointClass->CritSect);
    1545         AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
    1546 
    1547         if (pEndpointClass->fGatherAdvancedStatistics)
    1548             pdmR3AsyncCompletionStatisticsDeregister(pEndpoint);
    1549 
    1550         RTStrFree(pEndpoint->pszUri);
    1551         MMR3HeapFree(pEndpoint);
    1552     }
     1508    PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pEndpoint->pEpClass;
     1509    PVM pVM = pEndpointClass->pVM;
     1510
     1511    pEndpointClass->pEndpointOps->pfnEpClose(pEndpoint);
     1512
     1513    /* Drop reference from the template. */
     1514    ASMAtomicDecU32(&pEndpoint->pTemplate->cUsed);
     1515
     1516    /* Unlink the endpoint from the list. */
     1517    int rc = RTCritSectEnter(&pEndpointClass->CritSect);
     1518    AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
     1519
     1520    PPDMASYNCCOMPLETIONENDPOINT pEndpointNext = pEndpoint->pNext;
     1521    PPDMASYNCCOMPLETIONENDPOINT pEndpointPrev = pEndpoint->pPrev;
     1522
     1523    if (pEndpointPrev)
     1524        pEndpointPrev->pNext = pEndpointNext;
     1525    else
     1526        pEndpointClass->pEndpointsHead = pEndpointNext;
     1527    if (pEndpointNext)
     1528        pEndpointNext->pPrev = pEndpointPrev;
     1529
     1530    pEndpointClass->cEndpoints--;
     1531
     1532    rc = RTCritSectLeave(&pEndpointClass->CritSect);
     1533    AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
     1534
     1535    if (pEndpointClass->fGatherAdvancedStatistics)
     1536        pdmR3AsyncCompletionStatisticsDeregister(pEndpoint);
     1537
     1538    RTStrFree(pEndpoint->pszUri);
     1539    MMR3HeapFree(pEndpoint);
    15531540}
    15541541
  • trunk/src/VBox/VMM/VMMR3/PDMAsyncCompletionFile.cpp

    r58126 r59261  
    11031103                       STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS,
    11041104                       STAMUNIT_TICKS_PER_CALL, "Time taken to read from the endpoint",
    1105                        "/PDM/AsyncCompletion/File/%s/Read", RTPathFilename(pEpFile->Core.pszUri));
     1105                       "/PDM/AsyncCompletion/File/%s/%d/Read", RTPathFilename(pEpFile->Core.pszUri), pEpFile->Core.iStatId);
    11061106
    11071107        STAMR3RegisterF(pEpClassFile->Core.pVM, &pEpFile->StatWrite,
    11081108                       STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS,
    11091109                       STAMUNIT_TICKS_PER_CALL, "Time taken to write to the endpoint",
    1110                        "/PDM/AsyncCompletion/File/%s/Write", RTPathFilename(pEpFile->Core.pszUri));
     1110                       "/PDM/AsyncCompletion/File/%s/%d/Write", RTPathFilename(pEpFile->Core.pszUri), pEpFile->Core.iStatId);
    11111111    }
    11121112#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette