VirtualBox

Changeset 17359 in vbox for trunk/src


Ignore:
Timestamp:
Mar 4, 2009 5:54:03 PM (16 years ago)
Author:
vboxsync
Message:

Main: Prototyped IHardDisk::autoReset and reset (including XML structure changes, backward compatible).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HardDiskImpl.cpp

    r17086 r17359  
    5959{
    6060    enum Operation { CreateDynamic, CreateFixed, CreateDiff,
    61                      Merge, Clone, Delete };
     61                     Merge, Clone, Delete, Reset };
    6262
    6363    HardDisk *that;
     
    509509 * @param aLocaiton     Storage unit location.
    510510 */
    511 HRESULT HardDisk::init(VirtualBox *aVirtualBox, CBSTR aFormat,
    512                        CBSTR aLocation)
     511HRESULT HardDisk::init (VirtualBox *aVirtualBox, CBSTR aFormat,
     512                        CBSTR aLocation)
    513513{
    514514    AssertReturn (aVirtualBox != NULL, E_FAIL);
     
    644644 *
    645645 * @param aVirtualBox   VirtualBox object.
    646  * @param aParent       Parent hard disk or NULL for a root hard disk.
     646 * @param aParent       Parent hard disk or NULL for a root (base) hard disk.
    647647 * @param aNode         <HardDisk> settings node.
    648648 *
    649649 * @note Locks VirtualBox lock for writing, treeLock() for writing.
    650650 */
    651 HRESULT HardDisk::init(VirtualBox *aVirtualBox, HardDisk *aParent,
    652                        const settings::Key &aNode)
     651HRESULT HardDisk::init (VirtualBox *aVirtualBox, HardDisk *aParent,
     652                        const settings::Key &aNode)
    653653{
    654654    using namespace settings;
     
    698698    rc = setFormat (format);
    699699    CheckComRCReturnRC (rc);
     700
     701    /* optional, only for diffs, default is false */
     702    if (aParent != NULL)
     703        mm.autoReset = aNode.value <bool> ("autoReset");
     704    else
     705        mm.autoReset = false;
    700706
    701707    /* properties (after setting the format as it populates the map). Note that
     
    976982STDMETHODIMP HardDisk::COMGETTER(LogicalSize) (ULONG64 *aLogicalSize)
    977983{
    978     if (aLogicalSize == NULL)
    979         return E_POINTER;
     984    CheckComArgOutPointerValid (aLogicalSize);
    980985
    981986    {
     
    10031008
    10041009    return root()->COMGETTER (LogicalSize) (aLogicalSize);
     1010}
     1011
     1012STDMETHODIMP HardDisk::COMGETTER(AutoReset) (BOOL *aAutoReset)
     1013{
     1014    CheckComArgOutPointerValid (aAutoReset);
     1015
     1016    AutoCaller autoCaller (this);
     1017    CheckComRCReturnRC (autoCaller.rc());
     1018
     1019    AutoReadLock alock (this);
     1020
     1021    if (mParent.isNull())
     1022        *aAutoReset = FALSE;
     1023
     1024    *aAutoReset = mm.autoReset;
     1025
     1026    return S_OK;
     1027}
     1028
     1029STDMETHODIMP HardDisk::COMSETTER(AutoReset) (BOOL aAutoReset)
     1030{
     1031    AutoCaller autoCaller (this);
     1032    CheckComRCReturnRC (autoCaller.rc());
     1033
     1034    /* VirtualBox::saveSettings() needs a write lock */
     1035    AutoMultiWriteLock2 alock (mVirtualBox, this);
     1036
     1037    if (mParent.isNull())
     1038        return setError (VBOX_E_NOT_SUPPORTED,
     1039            tr ("Hard disk '%ls' is not differencing"),
     1040            m.locationFull.raw());
     1041
     1042    if (mm.autoReset != aAutoReset)
     1043    {
     1044        mm.autoReset = aAutoReset;
     1045
     1046        return mVirtualBox->saveSettings();
     1047    }
     1048
     1049    return S_OK;
    10051050}
    10061051
     
    13941439}
    13951440
     1441STDMETHODIMP HardDisk::Reset (IProgress **aProgress)
     1442{
     1443    CheckComArgOutPointerValid (aProgress);
     1444
     1445    AutoCaller autoCaller (this);
     1446    CheckComRCReturnRC (autoCaller.rc());
     1447
     1448    AutoWriteLock alock (this);
     1449
     1450    HRESULT rc = LockWrite (NULL);
     1451    CheckComRCReturnRC (rc);
     1452
     1453    ComObjPtr <Progress> progress;
     1454
     1455    try
     1456    {
     1457        progress.createObject();
     1458        rc = progress->init (mVirtualBox, static_cast <IHardDisk *> (this),
     1459            BstrFmt (tr ("Resettng differencing hard disk '%ls'"),
     1460                     m.locationFull.raw()),
     1461            FALSE /* aCancelable */);
     1462        CheckComRCThrowRC (rc);
     1463
     1464        /* setup task object and thread to carry out the operation
     1465         * asynchronously */
     1466
     1467        std::auto_ptr <Task> task (new Task (this, progress, Task::Reset));
     1468        AssertComRCThrowRC (task->autoCaller.rc());
     1469
     1470        rc = task->startThread();
     1471        CheckComRCThrowRC (rc);
     1472
     1473        /* task is now owned (or already deleted) by taskThread() so release it */
     1474        task.release();
     1475    }
     1476    catch (HRESULT aRC)
     1477    {
     1478        rc = aRC;
     1479    }
     1480
     1481    if (FAILED (rc))
     1482    {
     1483        HRESULT rc2 = UnlockWrite (NULL);
     1484        AssertComRC (rc2);
     1485        /* Note: on success, taskThread() will unlock this */
     1486    }
     1487    else
     1488    {
     1489        /* return progress to the caller */
     1490        progress.queryInterfaceTo (aProgress);
     1491    }
     1492
     1493    return rc;
     1494}
     1495
    13961496// public methods for internal purposes only
    13971497////////////////////////////////////////////////////////////////////////////////
     
    15531653    /* required */
    15541654    diskNode.setValue <Bstr> ("format", mm.format);
     1655    /* optional, only for diffs, default is false */
     1656    if (!mParent.isNull())
     1657        diskNode.setValueOr <bool> ("autoReset", !!mm.autoReset, false);
    15551658    /* optional */
    15561659    if (!m.description.isNull())
     
    40524155        }
    40534156
     4157        case Task::Reset:
     4158        {
     4159            /// @todo
     4160
     4161            if (isAsync)
     4162            {
     4163                /* unlock ourselves when done */
     4164                HRESULT rc2 = that->UnlockWrite (NULL);
     4165                AssertComRC (rc2);
     4166            }
     4167
     4168            /* Note that in sync mode, it's the caller's responsibility to
     4169             * unlock the hard disk */
     4170
     4171            break;
     4172        }
     4173
    40544174        default:
    40554175            AssertFailedReturn (VERR_GENERAL_FAILURE);
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r17358 r17359  
    83148314  <interface
    83158315    name="IHardDisk" extends="IMedium"
    8316     uuid="244f89fe-1943-464d-baad-2efd73e5d532"
     8316    uuid="a4d391a5-e2b1-474d-824e-2ff668a92d58"
    83178317    wsmap="managed"
    83188318  >
     
    87118711    </attribute>
    87128712
     8713    <attribute name="autoReset" type="boolean">
     8714      <desc>
     8715        Whether this differencing hard disk will be automatically reset each
     8716        time a virtual machine it is attached to is powered up.
     8717
     8718        See <link to="#reset()"/> for more information about resetting
     8719        differencing hard disks.
     8720
     8721        <note>
     8722          Reading this property on a base (non-differencing) hard disk will
     8723          always <tt>false</tt>. Changing the value of this property in this
     8724          case is not supported.
     8725        </note>
     8726
     8727        <result name="VBOX_E_NOT_SUPPORTED">
     8728          This is not a differencing hard disk (when changing the attribute
     8729          value).
     8730        </result>
     8731      </desc>
     8732    </attribute>
     8733
    87138734    <!-- storage methods -->
    87148735
     
    91189139    </method>
    91199140
     9141    <!-- other methods -->
     9142
    91209143    <method name="compact">
    91219144      <desc>
     
    91259148        substantial amount of additional disk space.
    91269149
    9127         After the returned progress object reports that the operation is
    9128         successfully complete, the media state will be set back to the
    9129         current state.
    9130 
    9131         <note>
    9132           This hard disk and all its parent hard disks will be placed to <link
    9133           to="MediaState_LockedRead"/> state for the duration of this
    9134           operation.
    9135         </note>
     9150        This hard disk will be placed to <link to="MediaState_LockedWrite"/>
     9151        state and all its parent hard disks (if any) will be placed to
     9152        <link to="MediaState_LockedRead"/> state for the duration of this
     9153        operation.
     9154      </desc>
     9155      <param name="progress" type="IProgress" dir="return">
     9156        <desc>Progress object to track the operation completion.</desc>
     9157      </param>
     9158    </method>
     9159
     9160    <method name="reset">
     9161      <desc>
     9162        Starts erasing the contents of this differencing hard disk.
     9163
     9164        This operation will reset the differencing hard disk to its initial
     9165        state when it does not contain any sector data and any read operation is
     9166        redirected to its parent hard disk.
     9167
     9168        This hard disk will be placed to <link to="MediaState_LockedWrite"/>
     9169        for the duration of this operation.
     9170
     9171        <result name="VBOX_E_NOT_SUPPORTED">
     9172          This is not a differencing hard disk.
     9173        </result>
     9174        <result name="VBOX_E_INVALID_OBJECT_STATE">
     9175          Hard disk is not in <link to="MediaState_Created"/> or
     9176          <link to="MediaState_Inaccessible"/> state.
     9177        </result>
    91369178      </desc>
    91379179      <param name="progress" type="IProgress" dir="return">
  • trunk/src/VBox/Main/include/HardDiskImpl.h

    r16873 r17359  
    9797    STDMETHOD(COMGETTER(ReadOnly)) (BOOL *aReadOnly);
    9898    STDMETHOD(COMGETTER(LogicalSize)) (ULONG64 *aLogicalSize);
     99    STDMETHOD(COMGETTER(AutoReset)) (BOOL *aAutoReset);
     100    STDMETHOD(COMSETTER(AutoReset)) (BOOL aAutoReset);
    99101
    100102    // IHardDisk methods
     
    114116    STDMETHOD(FlattenTo) (IHardDisk *aTarget, IProgress **aProgress);
    115117    STDMETHOD(Compact) (IProgress **aProgress);
     118    STDMETHOD(Reset) (IProgress **aProgress);
    116119
    117120    // public methods for internal purposes only
     
    269272    struct Data
    270273    {
    271         Data() : type (HardDiskType_Normal), logicalSize (0)
     274        Data() : type (HardDiskType_Normal), logicalSize (0), autoReset (false)
    272275               , implicit (false), numCreateDiffTasks (0)
    273276               , vdProgress (NULL) , vdDiskIfaces (NULL) {}
     
    279282        uint64_t logicalSize;   /*< In MBytes. */
    280283
     284        BOOL autoReset : 1;
     285
    281286        typedef std::map <Bstr, Bstr> PropertyMap;
    282287        PropertyMap properties;
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r17075 r17359  
    263263-->
    264264
    265 <xsd:complexType name="TDiffHardDisk2">
     265<xsd:complexType name="THardDiskBase">
    266266  <xsd:sequence>
    267267    <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
     
    272272      </xsd:complexType>
    273273    </xsd:element>
    274     <xsd:element name="HardDisk" type="TDiffHardDisk2" minOccurs="0" maxOccurs="unbounded"/>
     274    <xsd:element name="HardDisk" type="TDiffHardDisk" minOccurs="0" maxOccurs="unbounded"/>
    275275  </xsd:sequence>
    276276  <xsd:attribute name="uuid" type="TNonNullUUID" use="required"/>
     
    279279</xsd:complexType>
    280280
    281 <xsd:complexType name="THardDisk2">
     281<xsd:complexType name="TDiffHardDisk">
    282282  <xsd:complexContent>
    283     <xsd:extension base="TDiffHardDisk2">
     283    <xsd:extension base="THardDiskBase">
     284      <xsd:attribute name="autoReset" type="xsd:boolean" default="false"/>
     285    </xsd:extension>
     286  </xsd:complexContent>
     287</xsd:complexType>
     288
     289<xsd:complexType name="THardDisk">
     290  <xsd:complexContent>
     291    <xsd:extension base="THardDiskBase">
    284292      <xsd:attribute name="type" use="required">
    285293        <xsd:simpleType>
     
    374382            <xsd:complexType>
    375383              <xsd:sequence>
    376                 <xsd:element name="HardDisk" type="THardDisk2" minOccurs="0" maxOccurs="unbounded"/>
     384                <xsd:element name="HardDisk" type="THardDisk" minOccurs="0" maxOccurs="unbounded"/>
    377385              </xsd:sequence>
    378386            </xsd:complexType>
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