VirtualBox

Changeset 38873 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 27, 2011 8:58:22 AM (13 years ago)
Author:
vboxsync
Message:

Main: Add API to set the discard flag for harddisks

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

Legend:

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

    r38871 r38873  
    36273627  <interface
    36283628    name="IMachine" extends="$unknown"
    3629     uuid="5eaa9319-62fc-4b0a-843c-0cb1940f8a91"
     3629    uuid="5a8e9425-aa0d-4703-9f28-2353fc4ee623"
    36303630    wsmap="managed"
    36313631    >
     
    47634763    </method>
    47644764
     4765    <method name="discardDevice">
     4766      <desc>
     4767        Sets a flag in the device information which indicates that the medium
     4768        supports discarding unsused blocks (called trimming for SATA or unmap
     4769        for SCSI devices) .This may or may not be supported by a particular drive,
     4770        and is silently ignored in the latter case. At the moment only hard disks
     4771        (which is a misnomer in this context) accept this setting. Changing the
     4772        setting while the VM is running is forbidden. The device must already
     4773        exist; see <link to="IMachine::attachDevice"/> for how to attach a new
     4774        device.
     4775
     4776        The @a controllerPort and @a device parameters specify the device slot and
     4777        have have the same meaning as with <link to="IMachine::attachDevice" />.
     4778
     4779        <result name="E_INVALIDARG">
     4780          SATA device, SATA port, SCSI port out of range.
     4781        </result>
     4782        <result name="VBOX_E_INVALID_OBJECT_STATE">
     4783          Attempt to modify an unregistered virtual machine.
     4784        </result>
     4785        <result name="VBOX_E_INVALID_VM_STATE">
     4786          Invalid machine state.
     4787        </result>
     4788
     4789      </desc>
     4790      <param name="name" type="wstring" dir="in">
     4791        <desc>Name of the storage controller.</desc>
     4792      </param>
     4793      <param name="controllerPort" type="long" dir="in">
     4794        <desc>Storage controller port.</desc>
     4795      </param>
     4796      <param name="device" type="long" dir="in">
     4797        <desc>Device slot in the given port.</desc>
     4798      </param>
     4799      <param name="discard" type="boolean" dir="in">
     4800        <desc>New value for the discard device flag.</desc>
     4801      </param>
     4802    </method>
     4803
    47654804    <method name="setBandwidthGroupForDevice">
    47664805      <desc>
     
    97939832  <interface
    97949833    name="IMediumAttachment" extends="$unknown"
    9795     uuid="b5dfbb8c-7498-48c3-bf10-78fc60f064e1"
     9834    uuid="5ee464d6-0613-4331-b154-7ce12170ef9f"
    97969835    wsmap="struct"
    97979836    >
     
    1001710056    <attribute name="nonRotational" type="boolean" readonly="yes">
    1001810057      <desc>Whether the associated medium is non-rotational.</desc>
     10058    </attribute>
     10059
     10060    <attribute name="discard" type="boolean" readonly="yes">
     10061      <desc>Whether the associated medium supports discarding unused blocks.</desc>
    1001910062    </attribute>
    1002010063
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r37851 r38873  
    528528                     unsigned uMergeTarget,
    529529                     const char *pcszBwGroup,
     530                     bool fDiscard,
    530531                     IMedium *pMedium,
    531532                     MachineState_T aMachineState,
  • trunk/src/VBox/Main/include/MachineImpl.h

    r38820 r38873  
    479479    STDMETHOD(TemporaryEjectDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aTempEject);
    480480    STDMETHOD(NonRotationalDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aNonRotational);
     481    STDMETHOD(DiscardDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aDiscard);
    481482    STDMETHOD(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
    482483                                          LONG aDevice, IBandwidthGroup *aBandwidthGroup);
  • trunk/src/VBox/Main/include/MediumAttachmentImpl.h

    r38718 r38873  
    5151                 bool fTempEject,
    5252                 bool fNonRotational,
     53                 bool fDiscard,
    5354                 const Utf8Str &strBandwidthGroup);
    5455    HRESULT initCopy(Machine *aParent, MediumAttachment *aThat);
     
    6869    STDMETHOD(COMGETTER(IsEjected))(BOOL *aIsEjected);
    6970    STDMETHOD(COMGETTER(NonRotational))(BOOL *aNonRotational);
     71    STDMETHOD(COMGETTER(Discard))(BOOL *aDiscard);
    7072    STDMETHOD(COMGETTER(BandwidthGroup))(IBandwidthGroup **aBwGroup);
    7173
     
    8789    bool getTempEject() const;
    8890    bool getNonRotational() const;
     91    bool getDiscard() const;
    8992    const Utf8Str& getBandwidthGroup() const;
    9093
     
    102105    /** Must be called from under this object's write lock. */
    103106    void updateNonRotational(bool aNonRotational);
     107
     108    /** Must be called from under this object's write lock. */
     109    void updateDiscard(bool aDiscard);
    104110
    105111    /** Must be called from under this object's write lock. */
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r38702 r38873  
    28772877        BOOL fNonRotational;
    28782878        hrc = pMediumAtt->COMGETTER(NonRotational)(&fNonRotational);                        H();
     2879        BOOL fDiscard;
     2880        hrc = pMediumAtt->COMGETTER(Discard)(&fDiscard);                                    H();
    28792881
    28802882        unsigned uLUN;
     
    31743176                          uMergeTarget,
    31753177                          strBwGroup.isEmpty() ? NULL : Utf8Str(strBwGroup).c_str(),
     3178                          fDiscard,
    31763179                          pMedium,
    31773180                          aMachineState,
     
    32153218                          unsigned uMergeTarget,
    32163219                          const char *pcszBwGroup,
     3220                          bool fDiscard,
    32173221                          IMedium *pMedium,
    32183222                          MachineState_T aMachineState,
     
    34033407                if (pcszBwGroup)
    34043408                    InsertConfigString(pCfg, "BwGroup", pcszBwGroup);
     3409
     3410                if (fDiscard)
     3411                    InsertConfigInteger(pCfg, "Discard", 1);
    34053412
    34063413                /* Pass all custom parameters. */
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r38820 r38873  
    38073807                          false /* fTempEject */,
    38083808                          false /* fNonRotational */,
     3809                          false /* fDiscard */,
    38093810                          Utf8Str::Empty);
    38103811    if (FAILED(rc)) return rc;
     
    40454046                        aDevice, aControllerPort, aControllerName);
    40464047    pAttach->updateNonRotational(!!aNonRotational);
     4048
     4049    return S_OK;
     4050}
     4051
     4052STDMETHODIMP Machine::DiscardDevice(IN_BSTR aControllerName, LONG aControllerPort,
     4053                                    LONG aDevice, BOOL aDiscard)
     4054{
     4055    CheckComArgStrNotEmptyOrNull(aControllerName);
     4056
     4057    LogFlowThisFunc(("aControllerName=\"%ls\" aControllerPort=%d aDevice=%d aDiscard=%d\n",
     4058                     aControllerName, aControllerPort, aDevice, aDiscard));
     4059
     4060    AutoCaller autoCaller(this);
     4061    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     4062
     4063    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     4064
     4065    HRESULT rc = checkStateDependency(MutableStateDep);
     4066    if (FAILED(rc)) return rc;
     4067
     4068    AssertReturn(mData->mMachineState != MachineState_Saved, E_FAIL);
     4069
     4070    if (Global::IsOnlineOrTransient(mData->mMachineState))
     4071        return setError(VBOX_E_INVALID_VM_STATE,
     4072                        tr("Invalid machine state: %s"),
     4073                        Global::stringifyMachineState(mData->mMachineState));
     4074
     4075    MediumAttachment *pAttach = findAttachment(mMediaData->mAttachments,
     4076                                               aControllerName,
     4077                                               aControllerPort,
     4078                                               aDevice);
     4079    if (!pAttach)
     4080        return setError(VBOX_E_OBJECT_NOT_FOUND,
     4081                        tr("No storage device attached to device slot %d on port %d of controller '%ls'"),
     4082                        aDevice, aControllerPort, aControllerName);
     4083
     4084
     4085    setModified(IsModified_Storage);
     4086    mMediaData.backup();
     4087
     4088    AutoWriteLock attLock(pAttach COMMA_LOCKVAL_SRC_POS);
     4089
     4090    if (pAttach->getType() != DeviceType_HardDisk)
     4091        return setError(E_INVALIDARG,
     4092                        tr("Setting the discard medium flag rejected as the device attached to device slot %d on port %d of controller '%ls' is not a hard disk"),
     4093                        aDevice, aControllerPort, aControllerName);
     4094    pAttach->updateDiscard(!!aDiscard);
    40474095
    40484096    return S_OK;
     
    81848232                               dev.fTempEject,
    81858233                               dev.fNonRotational,
     8234                               dev.fDiscard,
    81868235                               pBwGroup.isNull() ? Utf8Str::Empty : pBwGroup->getName());
    81878236        if (FAILED(rc)) break;
     
    91319180            dev.fPassThrough = pAttach->getPassthrough();
    91329181            dev.fTempEject = pAttach->getTempEject();
    9133             dev.fNonRotational = pAttach->getNonRotational();
     9182            dev.fDiscard = pAttach->getDiscard();
    91349183        }
    91359184
     
    94759524                                  false /* aTempEject */,
    94769525                                  pAtt->getNonRotational(),
     9526                                  pAtt->getDiscard(),
    94779527                                  pAtt->getBandwidthGroup());
    94789528            if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp

    r38718 r38873  
    4242          fTempEject(false),
    4343          fNonRotational(false),
     44          fDiscard(false),
    4445          fImplicit(false)
    4546    { }
     
    6061    bool                fTempEject;
    6162    bool                fNonRotational;
     63    bool                fDiscard;
    6264    bool                fImplicit;
    6365};
     
    120122                               bool aTempEject,
    121123                               bool aNonRotational,
     124                               bool aDiscard,
    122125                               const Utf8Str &strBandwidthGroup)
    123126{
     
    147150    m->bd->fTempEject = aTempEject;
    148151    m->bd->fNonRotational = aNonRotational;
     152    m->bd->fDiscard = aDiscard;
    149153    m->bd->fImplicit = aImplicit;
    150154
     
    370374}
    371375
     376STDMETHODIMP MediumAttachment::COMGETTER(Discard)(BOOL *aDiscard)
     377{
     378    LogFlowThisFuncEnter();
     379
     380    CheckComArgOutPointerValid(aDiscard);
     381
     382    AutoCaller autoCaller(this);
     383    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     384
     385    AutoReadLock lock(this COMMA_LOCKVAL_SRC_POS);
     386
     387    *aDiscard = m->bd->fDiscard;
     388
     389    LogFlowThisFuncLeave();
     390    return S_OK;
     391}
     392
    372393STDMETHODIMP MediumAttachment::COMGETTER(BandwidthGroup) (IBandwidthGroup **aBwGroup)
    373394{
     
    486507}
    487508
     509bool MediumAttachment::getDiscard() const
     510{
     511    AutoReadLock lock(this COMMA_LOCKVAL_SRC_POS);
     512    return m->bd->fDiscard;
     513}
     514
    488515const Utf8Str& MediumAttachment::getBandwidthGroup() const
    489516{
     
    547574}
    548575
     576/** Must be called from under this object's write lock. */
     577void MediumAttachment::updateDiscard(bool aDiscard)
     578{
     579    Assert(isWriteLockOnCurrentThread());
     580
     581    m->bd.backup();
     582    m->bd->fDiscard = aDiscard;
     583}
     584
    549585void MediumAttachment::updateBandwidthGroup(const Utf8Str &aBandwidthGroup)
    550586{
  • trunk/src/VBox/Main/xml/Settings.cpp

    r38100 r38873  
    16931693                  && (fTempEject                == a.fTempEject)
    16941694                  && (fNonRotational            == a.fNonRotational)
     1695                  && (fDiscard                  == a.fDiscard)
    16951696                  && (lPort                     == a.lPort)
    16961697                  && (lDevice                   == a.lDevice)
     
    29892990                att.deviceType = DeviceType_HardDisk;
    29902991                pelmAttached->getAttributeValue("nonrotational", att.fNonRotational);
     2992                pelmAttached->getAttributeValue("discard", att.fDiscard);
    29912993            }
    29922994            else if (m->sv >= SettingsVersion_v1_9)
     
    42374239                    if (att.fNonRotational)
    42384240                        pelmDevice->setAttribute("nonrotational", att.fNonRotational);
     4241                    if (att.fDiscard)
     4242                        pelmDevice->setAttribute("discard", att.fDiscard);
    42394243                    break;
    42404244
     
    46034607    {
    46044608        // VirtualBox 4.0 adds HD audio, CPU priorities, fault tolerance,
    4605         // per-machine media registries, VRDE, JRockitVE, bandwidth gorups,
     4609        // per-machine media registries, VRDE, JRockitVE, bandwidth groups,
    46064610        // ICH9 chipset
    46074611        if (    hardwareMachine.audioAdapter.controllerType == AudioControllerType_HDA
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