Changeset 31180 in vbox
- Timestamp:
- Jul 28, 2010 6:11:10 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
include/VBox/VBoxHDD.h (modified) (1 diff)
-
src/VBox/Devices/Storage/DrvVD.cpp (modified) (6 diffs)
-
src/VBox/Devices/Storage/VDIHDDCore.cpp (modified) (5 diffs)
-
src/VBox/Devices/Storage/VHDHDDCore.cpp (modified) (5 diffs)
-
src/VBox/Devices/Storage/VmdkHDDCore.cpp (modified) (13 diffs)
-
src/VBox/Main/ConsoleImpl2.cpp (modified) (2 diffs)
-
src/VBox/Main/MediumImpl.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxHDD.h
r31098 r31180 169 169 * Only available if VD_CAP_ASYNC_IO is set 170 170 * Check with VDIsAsynchonousIoSupported wether 171 * asynchronous I/O is really supported for this file. 172 */ 171 * asynchronous I/O is really supported for this file. */ 173 172 #define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4) 173 /** Allow sharing of the image for writable images. May be ignored if the 174 * format backend doesn't support this type of concurrent access. */ 175 #define VD_OPEN_FLAGS_SHAREABLE RT_BIT(5) 174 176 /** Mask of valid flags. */ 175 #define VD_OPEN_FLAGS_MASK (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO )177 #define VD_OPEN_FLAGS_MASK (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE) 176 178 /** @}*/ 177 179 -
trunk/src/VBox/Devices/Storage/DrvVD.cpp
r31128 r31180 161 161 /** Pointer to the list of data we need to keep per image. */ 162 162 PVBOXIMAGE pImages; 163 /** Flag whether the media should allow concurrent open for writing. */ 164 bool fShareable; 163 165 /** Flag whether a merge operation has been set up. */ 164 166 bool fMergePending; … … 342 344 if (RT_SUCCESS(rc)) 343 345 { 344 rc = PDMR3AsyncCompletionEpCreateForFile(&pStorageBackend->pEndpoint, pszLocation, 345 uOpenFlags & VD_INTERFACEASYNCIO_OPEN_FLAGS_READONLY 346 ? PDMACEP_FILE_FLAGS_READ_ONLY | PDMACEP_FILE_FLAGS_CACHING 347 : PDMACEP_FILE_FLAGS_CACHING, 346 uint32_t fFlags = uOpenFlags & VD_INTERFACEASYNCIO_OPEN_FLAGS_READONLY 347 ? PDMACEP_FILE_FLAGS_READ_ONLY | PDMACEP_FILE_FLAGS_CACHING 348 : 0; 349 if (pThis->fShareable) 350 fFlags |= PDMACEP_FILE_FLAGS_DONT_LOCK; 351 else 352 fFlags |= PDMACEP_FILE_FLAGS_CACHING; 353 rc = PDMR3AsyncCompletionEpCreateForFile(&pStorageBackend->pEndpoint, 354 pszLocation, fFlags, 348 355 pStorageBackend->pTemplate); 349 356 if (RT_SUCCESS(rc)) … … 1634 1641 pThis->pDisk = NULL; 1635 1642 pThis->fAsyncIOSupported = false; 1643 pThis->fShareable = false; 1636 1644 pThis->fMergePending = false; 1637 1645 pThis->MergeCompleteMutex = NIL_RTSEMFASTMUTEX; … … 1702 1710 fValid = CFGMR3AreValuesValid(pCurNode, 1703 1711 "Format\0Path\0" 1704 "ReadOnly\0MaybeReadOnly\0TempReadOnly\0 HonorZeroWrites\0"1712 "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0" 1705 1713 "HostIPStack\0UseNewIo\0" 1706 1714 "SetupMerge\0MergeSource\0MergeTarget\0"); … … 1767 1775 break; 1768 1776 } 1777 1778 rc = CFGMR3QueryBoolDef(pCurNode, "Shareable", &pThis->fShareable, false); 1779 if (RT_FAILURE(rc)) 1780 { 1781 rc = PDMDRV_SET_ERROR(pDrvIns, rc, 1782 N_("DrvVD: Configuration error: Querying \"Shareable\" as boolean failed")); 1783 break; 1784 } 1785 1769 1786 rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false); 1770 1787 if (RT_FAILURE(rc)) … … 2008 2025 if (pThis->fAsyncIOSupported) 2009 2026 uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO; 2027 if (pThis->fShareable) 2028 uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE; 2010 2029 2011 2030 /* Try to open backend in async I/O mode first. */ -
trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp
r30863 r31180 79 79 80 80 81 static int vdiFileOpen(PVDIIMAGEDESC pImage, bool fReadonly, bool fCreate) 81 static int vdiFileOpen(PVDIIMAGEDESC pImage, bool fReadonly, bool fShareable, 82 bool fCreate) 82 83 { 83 84 int rc = VINF_SUCCESS; 84 85 85 AssertMsg(!(fReadonly && fCreate), ("Image can't be opened readonly while being created\n"));86 AssertMsg(!(fReadonly && fCreate), ("Image can't be opened readonly while being created\n")); 86 87 87 88 #ifndef VBOX_WITH_NEW_IO_CODE 88 uint32_t fOpen = fReadonly ? RTFILE_O_READ | RTFILE_O_DENY_NONE 89 : RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE; 89 uint32_t fDeny = fReadonly | fShareable ? RTFILE_O_DENY_NONE : RTFILE_O_DENY_WRITE; 90 uint32_t fOpen = fReadonly ? RTFILE_O_READ : RTFILE_O_READWRITE; 91 fOpen |= fDeny; 90 92 91 93 if (fCreate) … … 514 516 PCPDMMEDIAGEOMETRY pPCHSGeometry, 515 517 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, 516 PFNVDPROGRESS pfnProgress, void *pvUser, 517 unsigned uPercentStart, unsigned uPercentSpan) 518 unsigned uOpenFlags, PFNVDPROGRESS pfnProgress, 519 void *pvUser, unsigned uPercentStart, 520 unsigned uPercentSpan) 518 521 { 519 522 int rc; … … 580 583 581 584 /* Create image file. */ 582 rc = vdiFileOpen(pImage, false /* fReadonly */, true /* fCreate */); 585 rc = vdiFileOpen(pImage, false /* fReadonly */, 586 !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE), 587 true /* fCreate */); 583 588 if (RT_FAILURE(rc)) 584 589 { … … 733 738 * Open the image. 734 739 */ 735 rc = vdiFileOpen(pImage, !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), false /* fCreate */); 740 rc = vdiFileOpen(pImage, 741 !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), 742 !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE), 743 false /* fCreate */); 736 744 if (RT_FAILURE(rc)) 737 745 { … … 1159 1167 1160 1168 rc = vdiCreateImage(pImage, cbSize, uImageFlags, pszComment, 1161 pPCHSGeometry, pLCHSGeometry, pUuid, 1169 pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, 1162 1170 pfnProgress, pvUser, uPercentStart, uPercentSpan); 1163 1171 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp
r30863 r31180 261 261 static int vhdLoadDynamicDisk(PVHDIMAGE pImage, uint64_t uDynamicDiskHeaderOffset); 262 262 263 static int vhdFileOpen(PVHDIMAGE pImage, bool fReadonly, bool fCreate) 263 static int vhdFileOpen(PVHDIMAGE pImage, bool fReadonly, bool fShareable, 264 bool fCreate) 264 265 { 265 266 int rc = VINF_SUCCESS; … … 268 269 269 270 #ifndef VBOX_WITH_NEW_IO_CODE 270 uint32_t fOpen = fReadonly ? RTFILE_O_READ | RTFILE_O_DENY_NONE 271 : RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE; 271 uint32_t fDeny = fReadonly | fShareable ? RTFILE_O_DENY_NONE : RTFILE_O_DENY_WRITE; 272 uint32_t fOpen = fReadonly ? RTFILE_O_READ : RTFILE_O_READWRITE; 273 fOpen |= fDeny; 272 274 273 275 if (fCreate) … … 729 731 * Open the image. 730 732 */ 731 int rc = vhdFileOpen(pImage, !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), false); 733 int rc = vhdFileOpen(pImage, !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), 734 !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE), false); 732 735 if (RT_FAILURE(rc)) 733 736 { … … 1097 1100 vhdFileClose(pImage); 1098 1101 pImage->uOpenFlags = uOpenFlags; 1099 rc = vhdFileOpen(pImage, !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), false); 1102 rc = vhdFileOpen(pImage, !!(uOpenFlags & VD_OPEN_FLAGS_READONLY), 1103 !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE), false); 1100 1104 1101 1105 out: … … 1956 1960 pImage->pInterfaceErrorCallbacks = VDGetInterfaceError(pImage->pInterfaceError); 1957 1961 1958 rc = vhdFileOpen(pImage, false /* fReadonly */, true /* fCreate */); 1962 rc = vhdFileOpen(pImage, false /* fReadonly */, 1963 !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE), 1964 true /* fCreate */); 1959 1965 if (RT_FAILURE(rc)) 1960 1966 return vhdError(pImage, rc, RT_SRC_POS, N_("VHD: cannot create image '%s'"), pImage->pszFilename); -
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r30900 r31180 3157 3157 3158 3158 /** 3159 * Internal: Translate the VBoxHDD open flags to RTFile open flags. 3160 */ 3161 static uint32_t vmdkFileOpenFlags(unsigned uOpenFlags) 3162 { 3163 uint32_t fDeny = uOpenFlags & (VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_SHAREABLE) 3164 ? RTFILE_O_DENY_NONE 3165 : RTFILE_O_DENY_WRITE; 3166 uint32_t fOpen = uOpenFlags & VD_OPEN_FLAGS_READONLY 3167 ? RTFILE_O_READ 3168 : RTFILE_O_READWRITE; 3169 fOpen |= RTFILE_O_OPEN | fDeny; 3170 return fOpen; 3171 } 3172 3173 /** 3159 3174 * Internal: Open an image, constructing all necessary data structures. 3160 3175 */ … … 3184 3199 * file were no data is stored. 3185 3200 */ 3201 3186 3202 rc = vmdkFileOpen(pImage, &pFile, pImage->pszFilename, 3187 uOpenFlags & VD_OPEN_FLAGS_READONLY 3188 ? RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE 3189 : RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, false); 3203 vmdkFileOpenFlags(uOpenFlags), false); 3190 3204 if (RT_FAILURE(rc)) 3191 3205 { … … 3402 3416 case VMDKETYPE_HOSTED_SPARSE: 3403 3417 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3404 uOpenFlags & VD_OPEN_FLAGS_READONLY 3405 ? RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE 3406 : RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, false); 3418 vmdkFileOpenFlags(uOpenFlags), false); 3407 3419 if (RT_FAILURE(rc)) 3408 3420 { … … 3429 3441 case VMDKETYPE_FLAT: 3430 3442 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3431 uOpenFlags & VD_OPEN_FLAGS_READONLY 3432 ? RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE 3433 : RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, true); 3443 vmdkFileOpenFlags(uOpenFlags), true); 3434 3444 if (RT_FAILURE(rc)) 3435 3445 { … … 3512 3522 3513 3523 /** 3524 * Internal: Translate the VBoxHDD open flags to RTFile open/create flags. 3525 */ 3526 static uint32_t vmdkFileCreateFlags(unsigned uOpenFlags) 3527 { 3528 uint32_t fDeny = uOpenFlags & VD_OPEN_FLAGS_SHAREABLE 3529 ? RTFILE_O_DENY_NONE 3530 : RTFILE_O_DENY_WRITE; 3531 uint32_t fOpen = RTFILE_O_READWRITE | RTFILE_O_NOT_CONTENT_INDEXED; 3532 fOpen |= RTFILE_O_CREATE | fDeny; 3533 return fOpen; 3534 } 3535 3536 /** 3514 3537 * Internal: create VMDK images for raw disk/partition access. 3515 3538 */ … … 3530 3553 /* Create raw disk descriptor file. */ 3531 3554 rc = vmdkFileOpen(pImage, &pImage->pFile, pImage->pszFilename, 3532 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_NOT_CONTENT_INDEXED, 3533 false); 3555 vmdkFileCreateFlags(pImage->uOpenFlags), false); 3534 3556 if (RT_FAILURE(rc)) 3535 3557 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pImage->pszFilename); … … 3554 3576 /* Open flat image, the raw disk. */ 3555 3577 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3556 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, false); 3578 vmdkFileOpenFlags(pImage->uOpenFlags & ~VD_OPEN_FLAGS_READONLY), 3579 false); 3557 3580 if (RT_FAILURE(rc)) 3558 3581 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not open raw disk file '%s'"), pExtent->pszFullname); … … 3590 3613 /* Create raw partition descriptor file. */ 3591 3614 rc = vmdkFileOpen(pImage, &pImage->pFile, pImage->pszFilename, 3592 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_NOT_CONTENT_INDEXED, 3593 false); 3615 vmdkFileCreateFlags(pImage->uOpenFlags), false); 3594 3616 if (RT_FAILURE(rc)) 3595 3617 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pImage->pszFilename); … … 3665 3687 /* Create partition table flat image. */ 3666 3688 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3667 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_NOT_CONTENT_INDEXED,3689 vmdkFileCreateFlags(pImage->uOpenFlags), 3668 3690 false); 3669 3691 if (RT_FAILURE(rc)) … … 3700 3722 /* Open flat image, the raw partition. */ 3701 3723 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3702 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE,3724 vmdkFileOpenFlags(pImage->uOpenFlags & ~VD_OPEN_FLAGS_READONLY), 3703 3725 false); 3704 3726 if (RT_FAILURE(rc)) … … 3773 3795 { 3774 3796 rc = vmdkFileOpen(pImage, &pImage->pFile, pImage->pszFilename, 3775 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_NOT_CONTENT_INDEXED, 3776 false); 3797 vmdkFileCreateFlags(pImage->uOpenFlags), false); 3777 3798 if (RT_FAILURE(rc)) 3778 3799 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new sparse descriptor file '%s'"), pImage->pszFilename); … … 3843 3864 /* Create file for extent. */ 3844 3865 rc = vmdkFileOpen(pImage, &pExtent->pFile, pExtent->pszFullname, 3845 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_NOT_CONTENT_INDEXED, 3846 false); 3866 vmdkFileCreateFlags(pImage->uOpenFlags), false); 3847 3867 if (RT_FAILURE(rc)) 3848 3868 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pExtent->pszFullname); … … 5521 5541 PVMDKFILE pFile; 5522 5542 rrc = vmdkFileOpen(pImage, &pFile, pszOldDescName, 5523 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, false); 5543 vmdkFileOpenFlags(VD_OPEN_FLAGS_NORMAL), 5544 false); 5524 5545 AssertRC(rrc); 5525 5546 if (fEmbeddedDesc) -
trunk/src/VBox/Main/ConsoleImpl2.cpp
r31128 r31180 2813 2813 2814 2814 BOOL fHostDrive = FALSE; 2815 MediumType_T mediumType = MediumType_Normal; 2815 2816 if (pMedium) 2816 2817 { 2817 2818 hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive); H(); 2819 hrc = pMedium->COMGETTER(Type)(&mediumType); H(); 2818 2820 } 2819 2821 … … 2945 2947 { 2946 2948 InsertConfigInteger(pCfg, "TempReadOnly", 1); 2949 } 2950 2951 /* Flag for opening the medium for sharing between VMs. This 2952 * is done at the moment only for the first (and only) medium 2953 * in the chain, as shared media can have no diffs. */ 2954 if (mediumType == MediumType_Shareable) 2955 { 2956 InsertConfigInteger(pCfg, "Shareable", 1); 2947 2957 } 2948 2958 -
trunk/src/VBox/Main/MediumImpl.cpp
r31164 r31180 3482 3482 * location? */ 3483 3483 bool isImport = m->id.isEmpty(); 3484 unsigned flags = VD_OPEN_FLAGS_INFO;3484 unsigned uOpenFlags = VD_OPEN_FLAGS_INFO; 3485 3485 3486 3486 /* Note that we don't use VD_OPEN_FLAGS_READONLY when opening new … … 3492 3492 || !isImport 3493 3493 ) 3494 flags |= VD_OPEN_FLAGS_READONLY; 3494 uOpenFlags |= VD_OPEN_FLAGS_READONLY; 3495 3496 /* Open shareable medium with the appropriate flags */ 3497 if (m->type == MediumType_Shareable) 3498 uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE; 3495 3499 3496 3500 /* Lock the medium, which makes the behavior much more consistent */ 3497 if ( flags & VD_OPEN_FLAGS_READONLY)3501 if (uOpenFlags & (VD_OPEN_FLAGS_READONLY || VD_OPEN_FLAGS_SHAREABLE)) 3498 3502 rc = LockRead(NULL); 3499 3503 else … … 3542 3546 format.c_str(), 3543 3547 location.c_str(), 3544 flags,3548 uOpenFlags, 3545 3549 m->vdDiskIfaces); 3546 3550 if (RT_FAILURE(vrc)) … … 3740 3744 m->preLockState = MediumState_Inaccessible; 3741 3745 3742 if ( flags & VD_OPEN_FLAGS_READONLY)3746 if (uOpenFlags & (VD_OPEN_FLAGS_READONLY || VD_OPEN_FLAGS_SHAREABLE)) 3743 3747 rc = UnlockRead(NULL); 3744 3748 else … … 5713 5717 || pMedium->m->state == MediumState_Deleting); 5714 5718 5715 unsigned uOpenFlags = 0;5719 unsigned uOpenFlags = VD_OPEN_FLAGS_NORMAL; 5716 5720 5717 5721 if ( pMedium->m->state == MediumState_LockedRead 5718 5722 || pMedium->m->state == MediumState_Deleting) 5719 5723 uOpenFlags = VD_OPEN_FLAGS_READONLY; 5724 if (pMedium->m->type == MediumType_Shareable) 5725 uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE; 5720 5726 5721 5727 /* Open the medium */ … … 6058 6064 || pMedium->m->state == MediumState_LockedWrite); 6059 6065 6066 unsigned uOpenFlags = VD_OPEN_FLAGS_NORMAL; 6067 if (pMedium->m->state != MediumState_LockedWrite) 6068 uOpenFlags = VD_OPEN_FLAGS_READONLY; 6069 if (pMedium->m->type == MediumType_Shareable) 6070 uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE; 6071 6060 6072 /* Open all media in appropriate mode. */ 6061 6073 vrc = VDOpen(targetHdd, 6062 6074 pMedium->m->strFormat.c_str(), 6063 6075 pMedium->m->strLocationFull.c_str(), 6064 (pMedium->m->state == MediumState_LockedWrite) ? VD_OPEN_FLAGS_NORMAL : VD_OPEN_FLAGS_READONLY,6076 uOpenFlags, 6065 6077 pMedium->m->vdDiskIfaces); 6066 6078 if (RT_FAILURE(vrc)) … … 6436 6448 Assert(pMedium->m->state == MediumState_LockedRead); 6437 6449 6438 /** Open all media but last in read-only mode. */ 6450 /* Open all media but last in read-only mode. Do not handle 6451 * shareable media, as compaction and sharing are mutually 6452 * exclusive. */ 6439 6453 vrc = VDOpen(hdd, 6440 6454 pMedium->m->strFormat.c_str(),
Note:
See TracChangeset
for help on using the changeset viewer.

