Changeset 38657 in vbox
- Timestamp:
- Sep 6, 2011 2:06:56 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 73869
- Location:
- trunk/src/VBox/Storage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VD.cpp
r38621 r38657 1010 1010 int rc = VINF_SUCCESS; 1011 1011 1012 LogFlowFunc(("pDisk=%#p pDiscard=%#p cbDiscardingNew=%zu\n", 1013 pDisk, pDiscard, cbDiscardingNew)); 1014 1012 1015 while (pDiscard->cbDiscarding > cbDiscardingNew) 1013 1016 { … … 1021 1024 size_t cbLeft = pBlock->cbDiscard; 1022 1025 bool fAllocated = ASMBitTest(pBlock->pbmAllocated, idxStart); 1023 uint32_t cSectors = pBlock->cbDiscard * 8;1026 uint32_t cSectors = pBlock->cbDiscard / 512; 1024 1027 1025 1028 while (cbLeft > 0) … … 1073 1076 Assert(RT_FAILURE(rc) || pDiscard->cbDiscarding <= cbDiscardingNew); 1074 1077 1078 LogFlowFunc(("returns rc=%Rrc\n", rc)); 1075 1079 return rc; 1076 1080 } … … 1127 1131 /* Clip range to remain in the current block. */ 1128 1132 if (pBlockAbove) 1129 cbThisDiscard = RT_MIN(cbDiscard, pBlockAbove->Core.Key - (offStart + cbDiscard - 1));1133 cbThisDiscard = RT_MIN(cbDiscard, pBlockAbove->Core.KeyLast - offStart + 1); 1130 1134 else 1131 1135 cbThisDiscard = cbDiscard; 1132 1136 1133 Assert( cbThisDiscard % 512 == 0);1137 Assert(!(cbThisDiscard % 512)); 1134 1138 1135 1139 /* No block found, try to discard using the backend first. */ … … 1144 1148 if (pBlock) 1145 1149 { 1146 pBlock->Core.Key = offStart +cbPreAllocated;1147 pBlock->Core.KeyLast = offStart + cbThisDiscard + cbP reAllocated - 1;1148 pBlock->cbDiscard = cb ThisDiscard;1150 pBlock->Core.Key = offStart - cbPreAllocated; 1151 pBlock->Core.KeyLast = offStart + cbThisDiscard + cbPostAllocated - 1; 1152 pBlock->cbDiscard = cbPreAllocated + cbThisDiscard + cbPostAllocated; 1149 1153 pBlock->pbmAllocated = pbmAllocated; 1150 1154 bool fInserted = RTAvlrU64Insert(pDiscard->pTreeBlocks, &pBlock->Core); … … 1165 1169 { 1166 1170 /* Range lies partly in the block, update allocation bitmap. */ 1167 cbThisDiscard = pBlock->Core.KeyLast - offStart + 1;1171 cbThisDiscard = RT_MIN(cbDiscard, pBlock->Core.KeyLast - offStart + 1); 1168 1172 rc = VERR_VD_DISCARD_ALIGNMENT_NOT_MET; 1169 1173 } 1174 1175 Assert(cbDiscard >= cbThisDiscard); 1170 1176 1171 1177 if (rc == VERR_VD_DISCARD_ALIGNMENT_NOT_MET) … … 1212 1218 RTListNodeRemove(&pBlock->NodeLru); 1213 1219 RTListPrepend(&pDiscard->ListLru, &pBlock->NodeLru); 1220 rc = VINF_SUCCESS; 1214 1221 } 1215 1222 } 1223 1224 Assert(cbDiscard >= cbThisDiscard); 1216 1225 1217 1226 cbDiscard -= cbThisDiscard; … … 1284 1293 Assert(!(cbThisRange % 512)); 1285 1294 Assert(!((uOffset - pBlock->Core.Key) % 512)); 1295 1296 cbThisRange = RT_MIN(cbThisRange, pBlock->Core.KeyLast - uOffset + 1); 1286 1297 1287 1298 idxStart = (uOffset - pBlock->Core.Key) / 512; … … 1295 1306 cbThisRange = RT_MIN(cbThisRange, pBlock->Core.Key - uOffset); 1296 1307 } 1308 1309 Assert(cbRange >= cbThisRange); 1297 1310 1298 1311 uOffset += cbThisRange; -
trunk/src/VBox/Storage/VDI.cpp
r38647 r38657 888 888 889 889 return rc; 890 } 891 892 /** 893 * Internal: Creates a allocation bitmap from the given data. 894 * Sectors which contain only 0 are marked as unallocated and sectors with 895 * other data as allocated. 896 * 897 * @returns Pointer to the allocation bitmap or NULL on failure. 898 * @param pvData The data to create the allocation bitmap for. 899 * @param cbData Number of bytes in the buffer. 900 */ 901 static void *vdiAllocationBitmapCreate(void *pvData, size_t cbData) 902 { 903 unsigned cSectors = cbData / 512; 904 unsigned uSectorCur = 0; 905 void *pbmAllocationBitmap = NULL; 906 907 Assert(!(cbData % 512)); 908 Assert(!(cSectors % 8)); 909 910 pbmAllocationBitmap = RTMemAllocZ(cSectors / 8); 911 912 while (uSectorCur < cSectors) 913 { 914 int idxSet = ASMBitFirstSet((uint8_t *)pvData + uSectorCur * 512, cbData * 8); 915 916 if (idxSet != -1) 917 { 918 unsigned idxSectorAlloc = idxSet / 8 / 512; 919 ASMBitSet(pbmAllocationBitmap, uSectorCur + idxSectorAlloc); 920 921 uSectorCur += idxSectorAlloc + 1; 922 cbData -= (idxSectorAlloc + 1) * 512; 923 } 924 else 925 break; 926 } 927 928 return pbmAllocationBitmap; 890 929 } 891 930 … … 2560 2599 Assert(!(cbDiscard % 512)); 2561 2600 2601 AssertMsgReturn(!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY), 2602 ("Image is readonly\n"), VERR_VD_IMAGE_READ_ONLY); 2603 AssertMsgReturn( uOffset + cbDiscard <= getImageDiskSize(&pImage->Header) 2604 && cbDiscard, 2605 ("Invalid parameters uOffset=%llu cbDiscard=%zu\n", 2606 uOffset, cbDiscard), 2607 VERR_INVALID_PARAMETER); 2608 2562 2609 do 2563 2610 { … … 2669 2716 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbImage - pImage->cbTotalBlockData); 2670 2717 } 2671 else /* if (fDiscard & VD_DISCARD_MARK_UNUSED) */2718 else if (fDiscard & VD_DISCARD_MARK_UNUSED) 2672 2719 { 2673 2720 /* Write changed data to the image. */ … … 2675 2722 pbBlockData + offDiscard, cbDiscard, NULL); 2676 2723 } 2677 #if 02678 2724 else 2679 2725 { … … 2681 2727 *pcbPreAllocated = cbPreAllocated; 2682 2728 *pcbPostAllocated = cbPostAllocated; 2683 *ppbmAllocationBitmap = vd AllocationBitmapCreate(pvBlock, getImageBlockSize(&pImage->Header));2729 *ppbmAllocationBitmap = vdiAllocationBitmapCreate(pbBlockData, getImageBlockSize(&pImage->Header)); 2684 2730 if (RT_UNLIKELY(!*ppbmAllocationBitmap)) 2685 2731 rc = VERR_NO_MEMORY; … … 2687 2733 rc = VERR_VD_DISCARD_ALIGNMENT_NOT_MET; 2688 2734 } 2689 #endif2690 2735 } 2691 2736 /* else: nothing to do. */
Note:
See TracChangeset
for help on using the changeset viewer.