VirtualBox

Changeset 99991 in vbox


Ignore:
Timestamp:
May 26, 2023 7:19:50 PM (20 months ago)
Author:
vboxsync
Message:

Main: reimplements resizeAndCloneTo fix. removes bypass. bugref:10090

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r99782 r99991  
    1825818258  <interface
    1825918259    name="IMedium" extends="$unknown"
    18260     uuid="ad47ad09-787b-44ab-b343-a082a3f2dfb1"
     18260    uuid="7d510820-a678-4730-a862-818dcd3fbed0"
    1826118261    wsmap="managed"
    1826218262    rest="managed"
     
    1963219632          The specified cloning variant is not supported at the moment.
    1963319633        </result>
    19634 
    19635         <note>
    19636           Method will be moved to appropriate location at the next major API release.
    19637         </note>
    1963819634      </desc>
    1963919635
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r99739 r99991  
    30173017                        ComPtr<IProgress> &aProgress)
    30183018{
    3019     /** @todo r=jack: Remove redundancy. Call Medium::resizeAndCloneTo. */
    3020 
    3021     /** @todo r=klaus The code below needs to be double checked with regard
    3022      * to lock order violations, it probably causes lock order issues related
    3023      * to the AutoCaller usage. */
    3024     ComAssertRet(aTarget != this, E_INVALIDARG);
    3025 
    3026     IMedium *aT = aTarget;
    3027     ComObjPtr<Medium> pTarget = static_cast<Medium*>(aT);
    3028     ComObjPtr<Medium> pParent;
    3029     if (aParent)
    3030     {
    3031         IMedium *aP = aParent;
    3032         pParent = static_cast<Medium*>(aP);
    3033     }
    3034 
    3035     HRESULT hrc = S_OK;
    3036     ComObjPtr<Progress> pProgress;
    3037     Medium::Task *pTask = NULL;
    3038 
    3039     try
    3040     {
    3041         // locking: we need the tree lock first because we access parent pointers
    3042         // and we need to write-lock the media involved
    3043         uint32_t    cHandles    = 3;
    3044         LockHandle* pHandles[4] = { &m->pVirtualBox->i_getMediaTreeLockHandle(),
    3045                                     this->lockHandle(),
    3046                                     pTarget->lockHandle() };
    3047         /* Only add parent to the lock if it is not null */
    3048         if (!pParent.isNull())
    3049             pHandles[cHandles++] = pParent->lockHandle();
    3050         AutoWriteLock alock(cHandles,
    3051                             pHandles
    3052                             COMMA_LOCKVAL_SRC_POS);
    3053 
    3054         if (    pTarget->m->state != MediumState_NotCreated
    3055             &&  pTarget->m->state != MediumState_Created)
    3056             throw pTarget->i_setStateError();
    3057 
    3058         /* Build the source lock list. */
    3059         MediumLockList *pSourceMediumLockList(new MediumLockList());
    3060         alock.release();
    3061         hrc = i_createMediumLockList(true /* fFailIfInaccessible */,
    3062                                      NULL /* pToLockWrite */,
    3063                                      false /* fMediumLockWriteAll */,
    3064                                      NULL,
    3065                                      *pSourceMediumLockList);
    3066         alock.acquire();
    3067         if (FAILED(hrc))
    3068         {
    3069             delete pSourceMediumLockList;
    3070             throw hrc;
    3071         }
    3072 
    3073         /* Build the target lock list (including the to-be parent chain). */
    3074         MediumLockList *pTargetMediumLockList(new MediumLockList());
    3075         alock.release();
    3076         hrc = pTarget->i_createMediumLockList(true /* fFailIfInaccessible */,
    3077                                               pTarget /* pToLockWrite */,
    3078                                               false /* fMediumLockWriteAll */,
    3079                                               pParent,
    3080                                               *pTargetMediumLockList);
    3081         alock.acquire();
    3082         if (FAILED(hrc))
    3083         {
    3084             delete pSourceMediumLockList;
    3085             delete pTargetMediumLockList;
    3086             throw hrc;
    3087         }
    3088 
    3089         alock.release();
    3090         hrc = pSourceMediumLockList->Lock();
    3091         alock.acquire();
    3092         if (FAILED(hrc))
    3093         {
    3094             delete pSourceMediumLockList;
    3095             delete pTargetMediumLockList;
    3096             throw setError(hrc,
    3097                            tr("Failed to lock source media '%s'"),
    3098                            i_getLocationFull().c_str());
    3099         }
    3100         alock.release();
    3101         hrc = pTargetMediumLockList->Lock();
    3102         alock.acquire();
    3103         if (FAILED(hrc))
    3104         {
    3105             delete pSourceMediumLockList;
    3106             delete pTargetMediumLockList;
    3107             throw setError(hrc,
    3108                            tr("Failed to lock target media '%s'"),
    3109                            pTarget->i_getLocationFull().c_str());
    3110         }
    3111 
    3112         pProgress.createObject();
    3113         hrc = pProgress->init(m->pVirtualBox,
    3114                               static_cast <IMedium *>(this),
    3115                               BstrFmt(tr("Creating clone medium '%s'"), pTarget->m->strLocationFull.c_str()).raw(),
    3116                               TRUE /* aCancelable */);
    3117         if (FAILED(hrc))
    3118         {
    3119             delete pSourceMediumLockList;
    3120             delete pTargetMediumLockList;
    3121             throw hrc;
    3122         }
    3123 
    3124         ULONG mediumVariantFlags = 0;
    3125 
    3126         if (aVariant.size())
    3127         {
    3128             for (size_t i = 0; i < aVariant.size(); i++)
    3129                 mediumVariantFlags |= (ULONG)aVariant[i];
    3130         }
    3131 
    3132         if (mediumVariantFlags & MediumVariant_Formatted)
    3133         {
    3134             delete pSourceMediumLockList;
    3135             delete pTargetMediumLockList;
    3136             throw setError(VBOX_E_NOT_SUPPORTED,
    3137                            tr("Medium variant 'formatted' applies to floppy images only"));
    3138         }
    3139 
    3140         /* setup task object to carry out the operation asynchronously */
    3141         pTask = new Medium::CloneTask(this, pProgress, pTarget,
    3142                                       (MediumVariant_T)mediumVariantFlags,
    3143                                       pParent, UINT32_MAX, UINT32_MAX,
    3144                                       pSourceMediumLockList, pTargetMediumLockList);
    3145         hrc = pTask->hrc();
    3146         AssertComRC(hrc);
    3147         if (FAILED(hrc))
    3148             throw hrc;
    3149 
    3150         if (pTarget->m->state == MediumState_NotCreated)
    3151             pTarget->m->state = MediumState_Creating;
    3152     }
    3153     catch (HRESULT hrcXcpt)
    3154     {
    3155         hrc = hrcXcpt;
    3156     }
    3157 
    3158     if (SUCCEEDED(hrc))
    3159     {
    3160         hrc = pTask->createThread();
    3161         pTask = NULL;
    3162         if (SUCCEEDED(hrc))
    3163             pProgress.queryInterfaceTo(aProgress.asOutParam());
    3164     }
    3165     else if (pTask != NULL)
    3166         delete pTask;
    3167 
    3168     return hrc;
     3019    return resizeAndCloneTo(aTarget, 0, aVariant, aParent, aProgress);
    31693020}
    31703021
     
    32323083        return hrc;
    32333084
     3085    /** @todo r=jack: check below block  for correct lock handling */
    32343086    /* If target does not exist, handle resize. */
    32353087    if (pTarget->m->state != MediumState_NotCreated && aLogicalSize > 0)
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