Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 54790)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 54791)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2013 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -804,4 +804,8 @@
         if (machine)
         {
+            /* open an existing session for the VM */
+            CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), 1);
+            /* get the session machine */
+            CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
             /** @todo passing NULL is deprecated */
             if (a->argc < 3)
Index: /trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MachineImpl.h	(revision 54790)
+++ /trunk/src/VBox/Main/include/MachineImpl.h	(revision 54791)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2014 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -99,5 +99,6 @@
         MutableStateDep,
         MutableOrSavedStateDep,
-        OfflineStateDep
+        MutableOrRunningStateDep,
+        MutableOrSavedOrRunningStateDep,
     };
 
Index: /trunk/src/VBox/Main/src-server/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 54790)
+++ /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 54791)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2004-2014 Oracle Corporation
+ * Copyright (C) 2004-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -1025,5 +1025,5 @@
     // significantly, but play safe by not messing around while complex
     // activities are going on
-    HRESULT rc = i_checkStateDependency(MutableOrSavedStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -1065,6 +1065,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    // changing machine groups is possible while the VM is offline
-    rc = i_checkStateDependency(OfflineStateDep);
+    rc = i_checkStateDependency(MutableStateDep);
     if (FAILED(rc)) return rc;
 
@@ -2619,5 +2618,5 @@
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -2826,5 +2825,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -2980,5 +2979,5 @@
 
     /* @todo deal with running state change. */
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -3692,5 +3691,5 @@
     AutoWriteLock treeLock(&mParent->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -4256,5 +4255,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -4880,4 +4879,16 @@
     {
         AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); // hold read lock only while looking up
+
+        // For snapshots don't even think about allowing changes, extradata
+        // is global for a machine, so there is nothing snapshot specific.
+        if (i_isSnapshotMachine())
+            return setError(VBOX_E_INVALID_VM_STATE,
+                            tr("Cannot set extradata for a snapshot"));
+
+        // check if the right IMachine instance is used
+        if (!i_isSessionMachine())
+            return setError(VBOX_E_INVALID_VM_STATE,
+                            tr("Cannot set extradata for an immutable machine"));
+
         settings::StringsMap::const_iterator it = mData->pMachineConfigFile->mapExtraDataItems.find(aKey);
         if (it != mData->pMachineConfigFile->mapExtraDataItems.end())
@@ -4911,10 +4922,4 @@
         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-        if (i_isSnapshotMachine())
-        {
-            HRESULT rc = i_checkStateDependency(MutableStateDep);
-            if (FAILED(rc)) return rc;
-        }
-
         if (aValue.isEmpty())
             mData->pMachineConfigFile->mapExtraDataItems.erase(aKey);
@@ -4956,7 +4961,5 @@
     AutoWriteLock mlock(this COMMA_LOCKVAL_SRC_POS);
 
-    /* when there was auto-conversion, we want to save the file even if
-     * the VM is saved */
-    HRESULT rc = i_checkStateDependency(MutableOrSavedStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -4984,5 +4987,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT rc = i_checkStateDependency(MutableStateDep);
+    HRESULT rc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (FAILED(rc)) return rc;
 
@@ -5637,5 +5640,5 @@
     HRESULT rc = S_OK;
 
-    rc = i_checkStateDependency(MutableStateDep);
+    rc = i_checkStateDependency(MutableOrSavedStateDep);
     if (FAILED(rc)) return rc;
 
@@ -6840,5 +6843,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    HRESULT hrc = i_checkStateDependency(MutableStateDep);
+    HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (   SUCCEEDED(hrc)
         && mHWData->mAutostart.fAutostartEnabled != !!aAutostartEnabled)
@@ -6888,5 +6891,5 @@
 {
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-    HRESULT hrc = i_checkStateDependency(MutableStateDep);
+    HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
     if (SUCCEEDED(hrc))
     {
@@ -6913,5 +6916,5 @@
 {
    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-   HRESULT hrc = i_checkStateDependency(MutableStateDep);
+   HRESULT hrc = i_checkStateDependency(MutableOrSavedOrRunningStateDep);
    if (   SUCCEEDED(hrc)
        && mHWData->mAutostart.enmAutostopType != aAutostopType)
@@ -7968,7 +7971,15 @@
  *  properties when it is in the saved state.
  *
- *  When @a aDepType is OfflineStateDep, this method returns S_OK if the
- *  state is one of the 4 offline states (PoweredOff, Saved, Teleported,
- *  Aborted).
+ *  When @a aDepType is MutableOrRunningStateDep, this method returns S_OK only
+ *  if the current state of this machine object allows to change runtime
+ *  changeable settings of the machine (i.e. the machine is not registered, or
+ *  registered but either running or not running and not saved). It is useful
+ *  to call this method from Machine setters before performing any changes to
+ *  runtime changeable settings.
+ *
+ *  When @a aDepType is MutableOrSavedOrRunningStateDep, this method behaves
+ *  the same as for MutableOrRunningStateDep except that if the machine is
+ *  saved, S_OK is also returned. This is useful in setters which allow
+ *  changing runtime and saved state changeable machine properties.
  *
  *  @param aDepType     Dependency type to check.
@@ -7992,9 +8003,6 @@
         {
             if (   mData->mRegistered
-                && (   !i_isSessionMachine()  /** @todo This was just converted raw; Check if Running and
-                                                  Paused should actually be included here... (Live Migration) */
-                    || (   mData->mMachineState != MachineState_Paused
-                        && mData->mMachineState != MachineState_Running
-                        && mData->mMachineState != MachineState_Aborted
+                && (   !i_isSessionMachine()
+                    || (   mData->mMachineState != MachineState_Aborted
                         && mData->mMachineState != MachineState_Teleported
                         && mData->mMachineState != MachineState_PoweredOff
@@ -8010,9 +8018,6 @@
         {
             if (   mData->mRegistered
-                && (   !i_isSessionMachine() /** @todo This was just converted raw; Check if Running and
-                                                 Paused should actually be included here... (Live Migration) */
-                    || (   mData->mMachineState != MachineState_Paused
-                        && mData->mMachineState != MachineState_Running
-                        && mData->mMachineState != MachineState_Aborted
+                && (   !i_isSessionMachine()
+                    || (   mData->mMachineState != MachineState_Aborted
                         && mData->mMachineState != MachineState_Teleported
                         && mData->mMachineState != MachineState_Saved
@@ -8026,17 +8031,34 @@
             break;
         }
-        case OfflineStateDep:
+        case MutableOrRunningStateDep:
         {
             if (   mData->mRegistered
                 && (   !i_isSessionMachine()
-                    || (   mData->mMachineState != MachineState_PoweredOff
-                        && mData->mMachineState != MachineState_Saved
-                        && mData->mMachineState != MachineState_Aborted
+                    || (   mData->mMachineState != MachineState_Aborted
                         && mData->mMachineState != MachineState_Teleported
+                        && mData->mMachineState != MachineState_PoweredOff
+                        && !Global::IsOnline(mData->mMachineState)
                        )
                    )
                )
                 return setError(VBOX_E_INVALID_VM_STATE,
-                                tr("The machine is not offline (state is %s)"),
+                                tr("The machine is not mutable (state is %s)"),
+                                Global::stringifyMachineState(mData->mMachineState));
+            break;
+        }
+        case MutableOrSavedOrRunningStateDep:
+        {
+            if (   mData->mRegistered
+                && (   !i_isSessionMachine()
+                    || (   mData->mMachineState != MachineState_Aborted
+                        && mData->mMachineState != MachineState_Teleported
+                        && mData->mMachineState != MachineState_Saved
+                        && mData->mMachineState != MachineState_PoweredOff
+                        && !Global::IsOnline(mData->mMachineState)
+                       )
+                   )
+               )
+                return setError(VBOX_E_INVALID_VM_STATE,
+                                tr("The machine is not mutable (state is %s)"),
                                 Global::stringifyMachineState(mData->mMachineState));
             break;
