VirtualBox

Changeset 31180 in vbox


Ignore:
Timestamp:
Jul 28, 2010 6:11:10 PM (14 years ago)
Author:
vboxsync
Message:

Main/Medium+Main/Console+Storage: Pass a flag for the medium type "Shareable" to the image format backends so that they can treat the files appropriately.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxHDD.h

    r31098 r31180  
    169169 *  Only available if VD_CAP_ASYNC_IO is set
    170170 *  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.  */
    173172#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)
    174176/** 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)
    176178/** @}*/
    177179
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r31128 r31180  
    161161    /** Pointer to the list of data we need to keep per image. */
    162162    PVBOXIMAGE               pImages;
     163    /** Flag whether the media should allow concurrent open for writing. */
     164    bool                fShareable;
    163165    /** Flag whether a merge operation has been set up. */
    164166    bool                fMergePending;
     
    342344            if (RT_SUCCESS(rc))
    343345            {
    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,
    348355                                                         pStorageBackend->pTemplate);
    349356                if (RT_SUCCESS(rc))
     
    16341641    pThis->pDisk                        = NULL;
    16351642    pThis->fAsyncIOSupported            = false;
     1643    pThis->fShareable                   = false;
    16361644    pThis->fMergePending                = false;
    16371645    pThis->MergeCompleteMutex           = NIL_RTSEMFASTMUTEX;
     
    17021710            fValid = CFGMR3AreValuesValid(pCurNode,
    17031711                                          "Format\0Path\0"
    1704                                           "ReadOnly\0MaybeReadOnly\0TempReadOnly\0HonorZeroWrites\0"
     1712                                          "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
    17051713                                          "HostIPStack\0UseNewIo\0"
    17061714                                          "SetupMerge\0MergeSource\0MergeTarget\0");
     
    17671775                break;
    17681776            }
     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
    17691786            rc = CFGMR3QueryBoolDef(pCurNode, "UseNewIo", &fUseNewIo, false);
    17701787            if (RT_FAILURE(rc))
     
    20082025        if (pThis->fAsyncIOSupported)
    20092026            uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO;
     2027        if (pThis->fShareable)
     2028            uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE;
    20102029
    20112030        /* Try to open backend in async I/O mode first. */
  • trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp

    r30863 r31180  
    7979
    8080
    81 static int vdiFileOpen(PVDIIMAGEDESC pImage, bool fReadonly, bool fCreate)
     81static int vdiFileOpen(PVDIIMAGEDESC pImage, bool fReadonly, bool fShareable,
     82                       bool fCreate)
    8283{
    8384    int rc = VINF_SUCCESS;
    8485
    85     AssertMsg(!(fReadonly && fCreate), ("Image can't be opened readonly whilebeing created\n"));
     86    AssertMsg(!(fReadonly && fCreate), ("Image can't be opened readonly while being created\n"));
    8687
    8788#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;
    9092
    9193    if (fCreate)
     
    514516                          PCPDMMEDIAGEOMETRY pPCHSGeometry,
    515517                          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)
    518521{
    519522    int rc;
     
    580583
    581584    /* 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 */);
    583588    if (RT_FAILURE(rc))
    584589    {
     
    733738     * Open the image.
    734739     */
    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 */);
    736744    if (RT_FAILURE(rc))
    737745    {
     
    11591167
    11601168    rc = vdiCreateImage(pImage, cbSize, uImageFlags, pszComment,
    1161                         pPCHSGeometry, pLCHSGeometry, pUuid,
     1169                        pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags,
    11621170                        pfnProgress, pvUser, uPercentStart, uPercentSpan);
    11631171    if (RT_SUCCESS(rc))
  • trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp

    r30863 r31180  
    261261static int vhdLoadDynamicDisk(PVHDIMAGE pImage, uint64_t uDynamicDiskHeaderOffset);
    262262
    263 static int vhdFileOpen(PVHDIMAGE pImage, bool fReadonly, bool fCreate)
     263static int vhdFileOpen(PVHDIMAGE pImage, bool fReadonly, bool fShareable,
     264                       bool fCreate)
    264265{
    265266    int rc = VINF_SUCCESS;
     
    268269
    269270#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;
    272274
    273275    if (fCreate)
     
    729731     * Open the image.
    730732     */
    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);
    732735    if (RT_FAILURE(rc))
    733736    {
     
    10971100    vhdFileClose(pImage);
    10981101    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);
    11001104
    11011105out:
     
    19561960        pImage->pInterfaceErrorCallbacks = VDGetInterfaceError(pImage->pInterfaceError);
    19571961
    1958     rc = vhdFileOpen(pImage, false /* fReadonly */, true /* fCreate */);
     1962    rc = vhdFileOpen(pImage, false /* fReadonly */,
     1963                     !!(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE),
     1964                     true /* fCreate */);
    19591965    if (RT_FAILURE(rc))
    19601966        return vhdError(pImage, rc, RT_SRC_POS, N_("VHD: cannot create image '%s'"), pImage->pszFilename);
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r30900 r31180  
    31573157
    31583158/**
     3159 * Internal: Translate the VBoxHDD open flags to RTFile open flags.
     3160 */
     3161static 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/**
    31593174 * Internal: Open an image, constructing all necessary data structures.
    31603175 */
     
    31843199     * file were no data is stored.
    31853200     */
     3201
    31863202    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);
    31903204    if (RT_FAILURE(rc))
    31913205    {
     
    34023416                case VMDKETYPE_HOSTED_SPARSE:
    34033417                    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);
    34073419                    if (RT_FAILURE(rc))
    34083420                    {
     
    34293441                case VMDKETYPE_FLAT:
    34303442                    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);
    34343444                    if (RT_FAILURE(rc))
    34353445                    {
     
    35123522
    35133523/**
     3524 * Internal: Translate the VBoxHDD open flags to RTFile open/create flags.
     3525 */
     3526static 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/**
    35143537 * Internal: create VMDK images for raw disk/partition access.
    35153538 */
     
    35303553        /* Create raw disk descriptor file. */
    35313554        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);
    35343556        if (RT_FAILURE(rc))
    35353557            return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pImage->pszFilename);
     
    35543576        /* Open flat image, the raw disk. */
    35553577        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);
    35573580        if (RT_FAILURE(rc))
    35583581            return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not open raw disk file '%s'"), pExtent->pszFullname);
     
    35903613        /* Create raw partition descriptor file. */
    35913614        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);
    35943616        if (RT_FAILURE(rc))
    35953617            return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pImage->pszFilename);
     
    36653687                /* Create partition table flat image. */
    36663688                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),
    36683690                                  false);
    36693691                if (RT_FAILURE(rc))
     
    37003722                    /* Open flat image, the raw partition. */
    37013723                    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),
    37033725                                      false);
    37043726                    if (RT_FAILURE(rc))
     
    37733795    {
    37743796        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);
    37773798        if (RT_FAILURE(rc))
    37783799            return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new sparse descriptor file '%s'"), pImage->pszFilename);
     
    38433864        /* Create file for extent. */
    38443865        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);
    38473867        if (RT_FAILURE(rc))
    38483868            return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pExtent->pszFullname);
     
    55215541        PVMDKFILE pFile;
    55225542        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);
    55245545        AssertRC(rrc);
    55255546        if (fEmbeddedDesc)
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r31128 r31180  
    28132813
    28142814        BOOL fHostDrive = FALSE;
     2815        MediumType_T mediumType  = MediumType_Normal;
    28152816        if (pMedium)
    28162817        {
    28172818            hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive);                               H();
     2819            hrc = pMedium->COMGETTER(Type)(&mediumType);                                    H();
    28182820        }
    28192821
     
    29452947                {
    29462948                    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);
    29472957                }
    29482958
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31164 r31180  
    34823482     * location? */
    34833483    bool isImport = m->id.isEmpty();
    3484     unsigned flags = VD_OPEN_FLAGS_INFO;
     3484    unsigned uOpenFlags = VD_OPEN_FLAGS_INFO;
    34853485
    34863486    /* Note that we don't use VD_OPEN_FLAGS_READONLY when opening new
     
    34923492         || !isImport
    34933493       )
    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;
    34953499
    34963500    /* 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))
    34983502        rc = LockRead(NULL);
    34993503    else
     
    35423546                         format.c_str(),
    35433547                         location.c_str(),
    3544                          flags,
     3548                         uOpenFlags,
    35453549                         m->vdDiskIfaces);
    35463550            if (RT_FAILURE(vrc))
     
    37403744        m->preLockState = MediumState_Inaccessible;
    37413745
    3742     if (flags & VD_OPEN_FLAGS_READONLY)
     3746    if (uOpenFlags & (VD_OPEN_FLAGS_READONLY || VD_OPEN_FLAGS_SHAREABLE))
    37433747        rc = UnlockRead(NULL);
    37443748    else
     
    57135717                       || pMedium->m->state == MediumState_Deleting);
    57145718
    5715                 unsigned uOpenFlags = 0;
     5719                unsigned uOpenFlags = VD_OPEN_FLAGS_NORMAL;
    57165720
    57175721                if (   pMedium->m->state == MediumState_LockedRead
    57185722                    || pMedium->m->state == MediumState_Deleting)
    57195723                    uOpenFlags = VD_OPEN_FLAGS_READONLY;
     5724                if (pMedium->m->type == MediumType_Shareable)
     5725                    uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE;
    57205726
    57215727                /* Open the medium */
     
    60586064                            || pMedium->m->state == MediumState_LockedWrite);
    60596065
     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
    60606072                    /* Open all media in appropriate mode. */
    60616073                    vrc = VDOpen(targetHdd,
    60626074                                 pMedium->m->strFormat.c_str(),
    60636075                                 pMedium->m->strLocationFull.c_str(),
    6064                                  (pMedium->m->state == MediumState_LockedWrite) ? VD_OPEN_FLAGS_NORMAL : VD_OPEN_FLAGS_READONLY,
     6076                                 uOpenFlags,
    60656077                                 pMedium->m->vdDiskIfaces);
    60666078                    if (RT_FAILURE(vrc))
     
    64366448                    Assert(pMedium->m->state == MediumState_LockedRead);
    64376449
    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. */
    64396453                vrc = VDOpen(hdd,
    64406454                             pMedium->m->strFormat.c_str(),
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