VirtualBox

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


Ignore:
Timestamp:
Mar 4, 2021 12:49:43 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143044
Message:

NAT/Net: Refuse to modify NATNetwork when an instance of it is
running. Use existing infrastructure that keeps track of the number
of VMs that use any given natnet (though it's exposes to natnet in a
somewhat haphazard way). bugref:9909.

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

Legend:

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

    r87948 r87949  
    149149
    150150
     151HRESULT NATNetwork::setErrorBusy()
     152{
     153    return setError(E_FAIL,
     154               "Unable to change settings"
     155               " while NATNetwork instance is running");
     156}
     157
     158
    151159HRESULT NATNetwork::i_loadSettings(const settings::NATNetwork &data)
    152160{
     
    212220        return setError(E_INVALIDARG,
    213221                        tr("Network name cannot be empty"));
    214     {
     222
     223    {
     224        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     225        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     226            return setErrorBusy();
     227
     228        /** @todo r=uwe who ensures there's no other network with that name? */
     229
    215230        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    216231        if (aNetworkName == m->s.strNetworkName)
     
    219234        m->s.strNetworkName = aNetworkName;
    220235    }
     236
     237
    221238    AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
    222239    HRESULT rc = m->pVirtualBox->i_saveSettings();
     
    296313
    297314    {
     315        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     316        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     317            return setErrorBusy();
     318
    298319        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    299320
     
    377398{
    378399    {
     400        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     401        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     402            return setErrorBusy();
     403
    379404        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    380405
     
    440465
    441466    {
     467        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     468        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     469            return setErrorBusy();
     470
    442471        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    443472
     
    475504{
    476505    {
     506        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     507        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     508            return setErrorBusy();
     509
    477510        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    478511
     
    612645{
    613646    {
     647        AutoReadLock alockNatNetList(m->pVirtualBox->i_getNatNetLock() COMMA_LOCKVAL_SRC_POS);
     648        if (m->pVirtualBox->i_isNatNetStarted(m->s.strNetworkName))
     649            return setErrorBusy();
     650
    614651        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    615652
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r86908 r87949  
    34653465
    34663466
     3467/*
     3468 * Export this to NATNetwork so that its setters can refuse to change
     3469 * essential network settings when an VBoxNatNet instance is running.
     3470 */
     3471RWLockHandle *VirtualBox::i_getNatNetLock() const
     3472{
     3473    return spMtxNatNetworkNameToRefCountLock;
     3474}
     3475
     3476
     3477/*
     3478 * Export this to NATNetwork so that its setters can refuse to change
     3479 * essential network settings when an VBoxNatNet instance is running.
     3480 * The caller is expected to hold a read lock on i_getNatNetLock().
     3481 */
     3482bool VirtualBox::i_isNatNetStarted(const Utf8Str &aNetworkName) const
     3483{
     3484    return sNatNetworkNameToRefCount[aNetworkName] > 0;
     3485}
     3486
     3487
    34673488void VirtualBox::i_onCloudProviderListChanged(BOOL aRegistered)
    34683489{
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