VirtualBox

Changeset 54791 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Mar 16, 2015 4:04:03 PM (10 years ago)
Author:
vboxsync
Message:

Main/Machine: fix long-standing bug with setting extradata (it isn't allowed to use an immutable IMachine instance, see corresponding VBoxManage fix), and while at it fix a long-standing bug which allowed changing most settings at runtime (the i_checkStateDependency logic was broken)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r54645 r54791  
    55
    66/*
    7  * Copyright (C) 2004-2014 Oracle Corporation
     7 * Copyright (C) 2004-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    10251025    // significantly, but play safe by not messing around while complex
    10261026    // activities are going on
    1027     HRESULT rc = i_checkStateDependency(MutableOrSavedStateDep);
     1027    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    10281028    if (FAILED(rc)) return rc;
    10291029
     
    10651065    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    10661066
    1067     // changing machine groups is possible while the VM is offline
    1068     rc = i_checkStateDependency(OfflineStateDep);
     1067    rc = i_checkStateDependency(MutableStateDep);
    10691068    if (FAILED(rc)) return rc;
    10701069
     
    26192618    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    26202619
    2621     HRESULT rc = i_checkStateDependency(MutableStateDep);
     2620    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    26222621    if (FAILED(rc)) return rc;
    26232622
     
    28262825    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    28272826
    2828     HRESULT rc = i_checkStateDependency(MutableStateDep);
     2827    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    28292828    if (FAILED(rc)) return rc;
    28302829
     
    29802979
    29812980    /* @todo deal with running state change. */
    2982     HRESULT rc = i_checkStateDependency(MutableStateDep);
     2981    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    29832982    if (FAILED(rc)) return rc;
    29842983
     
    36923691    AutoWriteLock treeLock(&mParent->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    36933692
    3694     HRESULT rc = i_checkStateDependency(MutableStateDep);
     3693    HRESULT rc = i_checkStateDependency(MutableOrRunningStateDep);
    36953694    if (FAILED(rc)) return rc;
    36963695
     
    42564255    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    42574256
    4258     HRESULT rc = i_checkStateDependency(MutableStateDep);
     4257    HRESULT rc = i_checkStateDependency(MutableOrRunningStateDep);
    42594258    if (FAILED(rc)) return rc;
    42604259
     
    48804879    {
    48814880        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); // hold read lock only while looking up
     4881
     4882        // For snapshots don't even think about allowing changes, extradata
     4883        // is global for a machine, so there is nothing snapshot specific.
     4884        if (i_isSnapshotMachine())
     4885            return setError(VBOX_E_INVALID_VM_STATE,
     4886                            tr("Cannot set extradata for a snapshot"));
     4887
     4888        // check if the right IMachine instance is used
     4889        if (!i_isSessionMachine())
     4890            return setError(VBOX_E_INVALID_VM_STATE,
     4891                            tr("Cannot set extradata for an immutable machine"));
     4892
    48824893        settings::StringsMap::const_iterator it = mData->pMachineConfigFile->mapExtraDataItems.find(aKey);
    48834894        if (it != mData->pMachineConfigFile->mapExtraDataItems.end())
     
    49114922        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    49124923
    4913         if (i_isSnapshotMachine())
    4914         {
    4915             HRESULT rc = i_checkStateDependency(MutableStateDep);
    4916             if (FAILED(rc)) return rc;
    4917         }
    4918 
    49194924        if (aValue.isEmpty())
    49204925            mData->pMachineConfigFile->mapExtraDataItems.erase(aKey);
     
    49564961    AutoWriteLock mlock(this COMMA_LOCKVAL_SRC_POS);
    49574962
    4958     /* when there was auto-conversion, we want to save the file even if
    4959      * the VM is saved */
    4960     HRESULT rc = i_checkStateDependency(MutableOrSavedStateDep);
     4963    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    49614964    if (FAILED(rc)) return rc;
    49624965
     
    49844987    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    49854988
    4986     HRESULT rc = i_checkStateDependency(MutableStateDep);
     4989    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    49874990    if (FAILED(rc)) return rc;
    49884991
     
    56375640    HRESULT rc = S_OK;
    56385641
    5639     rc = i_checkStateDependency(MutableStateDep);
     5642    rc = i_checkStateDependency(MutableOrSavedStateDep);
    56405643    if (FAILED(rc)) return rc;
    56415644
     
    68406843    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    68416844
    6842     HRESULT hrc = i_checkStateDependency(MutableStateDep);
     6845    HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    68436846    if (   SUCCEEDED(hrc)
    68446847        && mHWData->mAutostart.fAutostartEnabled != !!aAutostartEnabled)
     
    68886891{
    68896892    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    6890     HRESULT hrc = i_checkStateDependency(MutableStateDep);
     6893    HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    68916894    if (SUCCEEDED(hrc))
    68926895    {
     
    69136916{
    69146917   AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    6915    HRESULT hrc = i_checkStateDependency(MutableStateDep);
     6918   HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    69166919   if (   SUCCEEDED(hrc)
    69176920       && mHWData->mAutostart.enmAutostopType != aAutostopType)
     
    79687971 *  properties when it is in the saved state.
    79697972 *
    7970  *  When @a aDepType is OfflineStateDep, this method returns S_OK if the
    7971  *  state is one of the 4 offline states (PoweredOff, Saved, Teleported,
    7972  *  Aborted).
     7973 *  When @a aDepType is MutableOrRunningStateDep, this method returns S_OK only
     7974 *  if the current state of this machine object allows to change runtime
     7975 *  changeable settings of the machine (i.e. the machine is not registered, or
     7976 *  registered but either running or not running and not saved). It is useful
     7977 *  to call this method from Machine setters before performing any changes to
     7978 *  runtime changeable settings.
     7979 *
     7980 *  When @a aDepType is MutableOrSavedOrRunningStateDep, this method behaves
     7981 *  the same as for MutableOrRunningStateDep except that if the machine is
     7982 *  saved, S_OK is also returned. This is useful in setters which allow
     7983 *  changing runtime and saved state changeable machine properties.
    79737984 *
    79747985 *  @param aDepType     Dependency type to check.
     
    79928003        {
    79938004            if (   mData->mRegistered
    7994                 && (   !i_isSessionMachine()  /** @todo This was just converted raw; Check if Running and
    7995                                                   Paused should actually be included here... (Live Migration) */
    7996                     || (   mData->mMachineState != MachineState_Paused
    7997                         && mData->mMachineState != MachineState_Running
    7998                         && mData->mMachineState != MachineState_Aborted
     8005                && (   !i_isSessionMachine()
     8006                    || (   mData->mMachineState != MachineState_Aborted
    79998007                        && mData->mMachineState != MachineState_Teleported
    80008008                        && mData->mMachineState != MachineState_PoweredOff
     
    80108018        {
    80118019            if (   mData->mRegistered
    8012                 && (   !i_isSessionMachine() /** @todo This was just converted raw; Check if Running and
    8013                                                  Paused should actually be included here... (Live Migration) */
    8014                     || (   mData->mMachineState != MachineState_Paused
    8015                         && mData->mMachineState != MachineState_Running
    8016                         && mData->mMachineState != MachineState_Aborted
     8020                && (   !i_isSessionMachine()
     8021                    || (   mData->mMachineState != MachineState_Aborted
    80178022                        && mData->mMachineState != MachineState_Teleported
    80188023                        && mData->mMachineState != MachineState_Saved
     
    80268031            break;
    80278032        }
    8028         case OfflineStateDep:
     8033        case MutableOrRunningStateDep:
    80298034        {
    80308035            if (   mData->mRegistered
    80318036                && (   !i_isSessionMachine()
    8032                     || (   mData->mMachineState != MachineState_PoweredOff
    8033                         && mData->mMachineState != MachineState_Saved
    8034                         && mData->mMachineState != MachineState_Aborted
     8037                    || (   mData->mMachineState != MachineState_Aborted
    80358038                        && mData->mMachineState != MachineState_Teleported
     8039                        && mData->mMachineState != MachineState_PoweredOff
     8040                        && !Global::IsOnline(mData->mMachineState)
    80368041                       )
    80378042                   )
    80388043               )
    80398044                return setError(VBOX_E_INVALID_VM_STATE,
    8040                                 tr("The machine is not offline (state is %s)"),
     8045                                tr("The machine is not mutable (state is %s)"),
     8046                                Global::stringifyMachineState(mData->mMachineState));
     8047            break;
     8048        }
     8049        case MutableOrSavedOrRunningStateDep:
     8050        {
     8051            if (   mData->mRegistered
     8052                && (   !i_isSessionMachine()
     8053                    || (   mData->mMachineState != MachineState_Aborted
     8054                        && mData->mMachineState != MachineState_Teleported
     8055                        && mData->mMachineState != MachineState_Saved
     8056                        && mData->mMachineState != MachineState_PoweredOff
     8057                        && !Global::IsOnline(mData->mMachineState)
     8058                       )
     8059                   )
     8060               )
     8061                return setError(VBOX_E_INVALID_VM_STATE,
     8062                                tr("The machine is not mutable (state is %s)"),
    80418063                                Global::stringifyMachineState(mData->mMachineState));
    80428064            break;
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