VirtualBox

Changeset 73740 in vbox


Ignore:
Timestamp:
Aug 17, 2018 4:52:08 PM (6 years ago)
Author:
vboxsync
Message:

Main: bugref:8612: add implementaion of Machine::applyDefault() in case of new vm creation.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/user_VBoxManage.xml

    r73664 r73740  
    666666      if it is assigned to a VM group membership. By default, a unique
    667667      uuid within the appropriate namespace is automatically generated.
     668    </para>
     669
     670    <para>
     671      If the <computeroutput>--default</computeroutput> option is used,
     672      default hardware configuration for specified guest operation
     673      system will be applied. By default, VM is created with minimal
     674      hardware.
    668675    </para>
    669676
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r73716 r73740  
    478478                     "                            [--basefolder <path>]\n"
    479479                     "                            [--uuid <uuid>]\n"
     480                     "                            [--default]\n"
    480481                     "\n", SEP);
    481482
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r73664 r73740  
    195195    { "--register",       'r', RTGETOPT_REQ_NOTHING },
    196196    { "-register",        'r', RTGETOPT_REQ_NOTHING },
     197    { "--default",        'd', RTGETOPT_REQ_NOTHING },
     198    { "-default",         'd', RTGETOPT_REQ_NOTHING },
    197199};
    198200
     
    205207    Bstr bstrUuid;
    206208    bool fRegister = false;
     209    bool fDefault = false;
     210    /* TBD. Now not used */
     211    Bstr bstrDefaultFlags;
    207212    com::SafeArray<BSTR> groups;
    208213
     
    239244            case 'r':   // --register
    240245                fRegister = true;
     246                break;
     247
     248            case 'd':   // --default
     249                fDefault = true;
    241250                break;
    242251
     
    278287        {
    279288            CHECK_ERROR_BREAK(a->virtualBox, RegisterMachine(machine));
     289        }
     290        if (fDefault)
     291        {
     292            /* ApplyDefaults assumes the machine is already registered */
     293            CHECK_ERROR_BREAK(machine, ApplyDefaults(bstrDefaultFlags.raw()));
     294            CHECK_ERROR_BREAK(machine, SaveSettings());
    280295        }
    281296        Bstr uuid;
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r73589 r73740  
    4646#include "SystemPropertiesImpl.h"
    4747#include "MachineImplMoveVM.h"
     48#include "ExtPackManagerImpl.h"
    4849
    4950// generated header
     
    1527915280HRESULT Machine::applyDefaults(const com::Utf8Str &aFlags)
    1528015281{
     15282    /* it's assumed the machine already registered. If not, it's a problem of the caller */
     15283
     15284    AutoCaller autoCaller(this);
     15285    AssertComRCReturn(autoCaller.rc(),autoCaller.rc());
     15286
     15287    HRESULT rc = S_OK;
     15288
     15289    /* get usb device filters from host, before any writes occurred to avoid deadlock */
     15290    ComPtr<IUSBDeviceFilters> usbDeviceFilters;
     15291    rc = getUSBDeviceFilters(usbDeviceFilters);
     15292    if (FAILED(rc)) return rc;
     15293
    1528115294    NOREF(aFlags);
    15282     ReturnComNotImplemented();
     15295    com::Utf8Str  osTypeId;
     15296    ComObjPtr<GuestOSType> osType = NULL;
     15297
     15298    /* Get the guest os type as a string from the VB. */
     15299    rc = getOSTypeId(osTypeId);
     15300    if (FAILED(rc)) return rc;
     15301
     15302    /* Get the os type obj that coresponds, can be used to get
     15303     * the defaults for this guest OS. */
     15304    rc = mParent->i_findGuestOSType(Bstr(osTypeId), osType);
     15305    if (FAILED(rc)) return rc;
     15306
     15307    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     15308
     15309    /* Let the OS type select 64-bit ness. */
     15310    mHWData->mLongMode = osType->i_is64Bit()
     15311                       ? settings::Hardware::LongMode_Enabled : settings::Hardware::LongMode_Disabled;
     15312
     15313    /* Apply network adapters defaults */
     15314    for (ULONG slot = 0; slot < mNetworkAdapters.size(); ++slot)
     15315        mNetworkAdapters[slot]->i_applyDefaults(osType);
     15316
     15317    /* Apply serial port defaults */
     15318    for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); ++slot)
     15319        mSerialPorts[slot]->i_applyDefaults(osType);
     15320
     15321    /* Apply parallel port defaults  - not OS dependent*/
     15322    for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); ++slot)
     15323        mParallelPorts[slot]->i_applyDefaults();
     15324
     15325
     15326    /* Let the OS type enable the X2APIC */
     15327    mHWData->mX2APIC = osType->i_recommendedX2APIC();
     15328
     15329    /* This one covers IOAPICEnabled. */
     15330    mBIOSSettings->i_applyDefaults(osType);
     15331
     15332    /* Initialize default BIOS settings here */
     15333    mHWData->mAPIC = osType->i_recommendedIOAPIC();
     15334    mHWData->mHWVirtExEnabled = osType->i_recommendedVirtEx();
     15335
     15336    rc = osType->COMGETTER(RecommendedRAM)(&mHWData->mMemorySize);
     15337    if (FAILED(rc)) return rc;
     15338
     15339    rc = osType->COMGETTER(RecommendedVRAM)(&mHWData->mVRAMSize);
     15340    if (FAILED(rc)) return rc;
     15341
     15342    rc = osType->COMGETTER(Recommended2DVideoAcceleration)(&mHWData->mAccelerate2DVideoEnabled);
     15343    if (FAILED(rc)) return rc;
     15344
     15345    rc = osType->COMGETTER(Recommended3DAcceleration)(&mHWData->mAccelerate3DEnabled);
     15346    if (FAILED(rc)) return rc;
     15347
     15348    rc = osType->COMGETTER(RecommendedFirmware)(&mHWData->mFirmwareType);
     15349    if (FAILED(rc)) return rc;
     15350
     15351    rc = osType->COMGETTER(RecommendedPAE)(&mHWData->mPAEEnabled);
     15352    if (FAILED(rc)) return rc;
     15353
     15354    rc = osType->COMGETTER(RecommendedHPET)(&mHWData->mHPETEnabled);
     15355    if (FAILED(rc)) return rc;
     15356
     15357    BOOL mRTCUseUTC;
     15358    rc = osType->COMGETTER(RecommendedRTCUseUTC)(&mRTCUseUTC);
     15359    if (FAILED(rc)) return rc;
     15360
     15361    setRTCUseUTC(mRTCUseUTC);
     15362    if (FAILED(rc)) return rc;
     15363
     15364    rc = osType->COMGETTER(RecommendedChipset)(&mHWData->mChipsetType);
     15365    if (FAILED(rc)) return rc;
     15366
     15367    rc = osType->COMGETTER(RecommendedTFReset)(&mHWData->mTripleFaultReset);
     15368    if (FAILED(rc)) return rc;
     15369
     15370    /* Audio stuff. */
     15371    AudioCodecType_T audioCodec;
     15372    rc = osType->COMGETTER(RecommendedAudioCodec)(&audioCodec);
     15373    if (FAILED(rc)) return rc;
     15374
     15375    rc = mAudioAdapter->COMSETTER(AudioCodec)(audioCodec);
     15376    if (FAILED(rc)) return rc;
     15377
     15378    AudioControllerType_T audioController;
     15379    rc = osType->COMGETTER(RecommendedAudioController)(&audioController);
     15380    if (FAILED(rc)) return rc;
     15381
     15382    rc = mAudioAdapter->COMSETTER(AudioController)(audioController);
     15383    if (FAILED(rc)) return rc;
     15384
     15385    rc = mAudioAdapter->COMSETTER(Enabled)(true);
     15386    if (FAILED(rc)) return rc;
     15387
     15388    rc = mAudioAdapter->COMSETTER(EnabledOut)(true);
     15389    if (FAILED(rc)) return rc;
     15390
     15391    /* Storage Controllers */
     15392    StorageControllerType_T hdStorageControllerType;
     15393    StorageBus_T hdStorageBusType;
     15394    StorageControllerType_T dvdStorageControllerType;
     15395    StorageBus_T dvdStorageBusType;
     15396    BOOL         recommendedFloppy;
     15397    ComPtr<IStorageController> floppyController;
     15398    ComPtr<IStorageController> hdController;
     15399    ComPtr<IStorageController> dvdController;
     15400    Utf8Str strFloppyName, strDVDName, strHDName;
     15401
     15402    /* GUI auto generates these - not accesible here - so hardware, at least for now. */
     15403    strFloppyName = Bstr("Floppy 1").raw();
     15404    strDVDName = Bstr("DVD 1").raw();
     15405    strHDName = Bstr("HDD 1").raw();
     15406
     15407    /* Floppy recommended? add one. */
     15408    rc = osType->COMGETTER(RecommendedFloppy(&recommendedFloppy));
     15409    if (FAILED(rc)) return rc;
     15410    if (recommendedFloppy)
     15411    {
     15412        rc = addStorageController(strFloppyName,
     15413                                  StorageBus_Floppy,
     15414                                  floppyController);
     15415        if (FAILED(rc)) return rc;
     15416    }
     15417
     15418    /* Setup one DVD storage controller. */
     15419    rc = osType->COMGETTER(RecommendedDVDStorageController)(&dvdStorageControllerType);
     15420    if (FAILED(rc)) return rc;
     15421
     15422    rc = osType->COMGETTER(RecommendedDVDStorageBus)(&dvdStorageBusType);
     15423    if (FAILED(rc)) return rc;
     15424
     15425    rc = addStorageController(strDVDName,
     15426                              dvdStorageBusType,
     15427                              dvdController);
     15428    if (FAILED(rc)) return rc;
     15429
     15430    rc = dvdController->COMSETTER(ControllerType)(dvdStorageControllerType);
     15431    if (FAILED(rc)) return rc;
     15432
     15433    /* Setup one HDD storage controller. */
     15434    rc = osType->COMGETTER(RecommendedHDStorageController)(&hdStorageControllerType);
     15435    if (FAILED(rc)) return rc;
     15436
     15437    rc = osType->COMGETTER(RecommendedHDStorageBus)(&hdStorageBusType);
     15438    if (FAILED(rc)) return rc;
     15439
     15440    if (hdStorageBusType != dvdStorageBusType && hdStorageControllerType != dvdStorageControllerType)
     15441    {
     15442       rc = addStorageController(strHDName,
     15443                                 hdStorageBusType,
     15444                                 hdController);
     15445       if (FAILED(rc)) return rc;
     15446
     15447       rc = hdController->COMSETTER(ControllerType)(hdStorageControllerType);
     15448       if (FAILED(rc)) return rc;
     15449    }
     15450    else
     15451    {
     15452        /* The HD controller is the same as DVD: */
     15453        hdController = dvdController;
     15454        strHDName = Bstr("DVD 1").raw();
     15455    }
     15456
     15457    /* Limit the AHCI port count if it's used because windows has trouble with
     15458     * too many ports and other guest (OS X in particular) may take extra long
     15459     * boot: */
     15460
     15461    // pParent = static_cast<Medium*>(aP)
     15462    IStorageController  *temp = hdController;
     15463    ComObjPtr<StorageController> storageController;
     15464    storageController = static_cast<StorageController *>(temp);
     15465
     15466    // tempHDController = aHDController;
     15467    if (hdStorageControllerType  == StorageControllerType_IntelAhci)
     15468        storageController->COMSETTER(PortCount)(1 + (dvdStorageControllerType == StorageControllerType_IntelAhci));
     15469    else if (dvdStorageControllerType == StorageControllerType_IntelAhci)
     15470        storageController->COMSETTER(PortCount)(1);
     15471
     15472    /* USB stuff */
     15473
     15474    bool ohciEnabled = false;
     15475
     15476    ComPtr<IUSBController> usbController;
     15477    BOOL recommendedUSB3;
     15478    BOOL recommendedUSB;
     15479    BOOL usbProxyAvailable;
     15480
     15481    getUSBProxyAvailable(&usbProxyAvailable);
     15482    if (FAILED(rc)) return rc;
     15483
     15484    rc = osType->COMGETTER(RecommendedUSB3)(&recommendedUSB3);
     15485    if (FAILED(rc)) return rc;
     15486    rc = osType->COMGETTER(RecommendedUSB)(&recommendedUSB);
     15487    if (FAILED(rc)) return rc;
     15488
     15489    if (!usbDeviceFilters.isNull() && recommendedUSB3 && usbProxyAvailable)
     15490    {
     15491        /* USB 3.0 is only available if the proper ExtPack is installed. */
     15492        ExtPackManager *aManager = mParent->i_getExtPackManager();
     15493        if (aManager->i_isExtPackUsable(ORACLE_PUEL_EXTPACK_NAME))
     15494        {
     15495            rc = addUSBController("XHCI", USBControllerType_XHCI, usbController);
     15496            if (FAILED(rc)) return rc;
     15497
     15498            /* xHci includes OHCI */
     15499            ohciEnabled = true;
     15500        }
     15501    }
     15502    if (   !ohciEnabled
     15503        && !usbDeviceFilters.isNull() && recommendedUSB && usbProxyAvailable)
     15504    {
     15505        rc = addUSBController("OHCI", USBControllerType_OHCI, usbController);
     15506        if (FAILED(rc)) return rc;
     15507        ohciEnabled = true;
     15508
     15509        /* USB 2.0 is only available if the proper ExtPack is installed.
     15510         * Note. Configuring EHCI here and providing messages about
     15511         * the missing extpack isn't exactly clean, but it is a
     15512         * necessary evil to patch over legacy compatability issues
     15513          * introduced by the new distribution model. */
     15514        ExtPackManager *manager = mParent->i_getExtPackManager();
     15515        if (manager->i_isExtPackUsable(ORACLE_PUEL_EXTPACK_NAME))
     15516        {
     15517            rc = addUSBController("EHCI", USBControllerType_EHCI, usbController);
     15518            if (FAILED(rc)) return rc;
     15519        }
     15520    }
     15521
     15522    /* Set recommended human interface device types: */
     15523    BOOL recommendedUSBHID;
     15524    rc = osType->COMGETTER(RecommendedUSBHID)(&recommendedUSBHID);
     15525    if (FAILED(rc)) return rc;
     15526
     15527    if (recommendedUSBHID)
     15528    {
     15529        mHWData->mKeyboardHIDType = KeyboardHIDType_USBKeyboard;
     15530        mHWData->mPointingHIDType = PointingHIDType_USBMouse;
     15531        if (!ohciEnabled && !usbDeviceFilters.isNull())
     15532        {
     15533            rc = addUSBController("OHCI", USBControllerType_OHCI, usbController);
     15534            if (FAILED(rc)) return rc;
     15535        }
     15536    }
     15537
     15538    BOOL recommendedUSBTablet;
     15539    rc = osType->COMGETTER(RecommendedUSBTablet)(&recommendedUSBTablet);
     15540    if (FAILED(rc)) return rc;
     15541
     15542    if (recommendedUSBTablet)
     15543    {
     15544        mHWData->mPointingHIDType = PointingHIDType_USBTablet;
     15545        if (!ohciEnabled && !usbDeviceFilters.isNull())
     15546        {
     15547            rc = addUSBController("OHCI", USBControllerType_OHCI, usbController);
     15548            if (FAILED(rc)) return rc;
     15549        }
     15550    }
     15551    return S_OK;
    1528315552}
    1528415553
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