VirtualBox

Changeset 24276 in vbox


Ignore:
Timestamp:
Nov 2, 2009 7:29:27 PM (15 years ago)
Author:
vboxsync
Message:

Main: settings version bump fixes, and documentation what the rules actually are.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r24274 r24276  
    11/** @file
    22 * Settings File Manipulation API.
     3 *
     4 * Two classes, MainConfigFile and MachineConfigFile, represent the VirtualBox.xml and
     5 * machine XML files. They share a common ancestor class, ConfigFileBase, which shares
     6 * functionality such as talking to the XML back-end classes and settings version management.
     7 *
     8 * Rules for introducing new settings: If an element or attribute is introduced that was not
     9 * present before VirtualBox 3.1, then settings version checks need to be introduced. The
     10 * settings version for VirtualBox 3.1 is 1.9; see the SettingsVersion enumeration in
     11 * src/VBox/Main/idl/VirtualBox.xidl for details about which version was used when.
     12 *
     13 * The settings versions checks are necessary because VirtualBox 3.1 no longer automatically
     14 * converts XML settings files but only if necessary, that is, if settings are present that
     15 * the old format does not support. If we write an element or attribute to a settings file
     16 * of an older version, then an old VirtualBox (before 3.1) will attempt to validate it
     17 * with XML schema, and that will certainly fail.
     18 *
     19 * So, to introduce a new setting:
     20 *
     21 *   1) Make sure the constructor of corresponding settings structure has a proper default.
     22 *
     23 *   2) In the settings reader method, try to read the setting; if it's there, great, if not,
     24 *      the default value will have been set by the constructor.
     25 *
     26 *   3) In the settings writer method, write the setting _only_ if the current settings
     27 *      version (stored in m->sv) is high enough. That is, for VirtualBox 3.1, write it
     28 *      only if (m->sv >= SettingsVersion_v1_9).
     29 *
     30 *   4) In MachineConfigFile::bumpSettingsVersionIfNeeded(), check if the new setting has
     31 *      a non-default value (i.e. that differs from the constructor). If so, bump the
     32 *      settings version to the current version so the settings writer (3) can write out
     33 *      the non-default value properly.
     34 *
     35 *      So far a corresponding method for MainConfigFile has not been necessary since there
     36 *      have been no incompatible changes yet.
    337 */
    438
     
    11961230}
    11971231
     1232// use a define for the platform-dependent default value of
     1233// hwvirt exclusivity, since we'll need to check that value
     1234// in bumpSettingsVersionIfNeeded()
     1235#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
     1236    #define HWVIRTEXCLUSIVEDEFAULT false
     1237#else
     1238    #define HWVIRTEXCLUSIVEDEFAULT true
     1239#endif
     1240
    11981241/**
    11991242 * Hardware struct constructor.
     
    12021245        : strVersion("2"),
    12031246          fHardwareVirt(true),
    1204 #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
    1205           fHardwareVirtExclusive(false),
    1206 #else
    1207           fHardwareVirtExclusive(true),
    1208 #endif
     1247          fHardwareVirtExclusive(HWVIRTEXCLUSIVEDEFAULT),
    12091248          fNestedPaging(false),
    12101249          fVPID(false),
     
    14691508            {
    14701509                pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt);
    1471                 pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive);
     1510                pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive);        // settings version 1.9
    14721511            }
    14731512            if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging")))
     
    23442383
    23452384    xml::ElementNode *pelmCPU      = pelmHardware->createChild("CPU");
     2385
    23462386    xml::ElementNode *pelmHwVirtEx = pelmCPU->createChild("HardwareVirtEx");
    23472387    pelmHwVirtEx->setAttribute("enabled", hw.fHardwareVirt);
    2348     pelmHwVirtEx->setAttribute("exclusive", hw.fHardwareVirtExclusive);
     2388    if (m->sv >= SettingsVersion_v1_9)
     2389        pelmHwVirtEx->setAttribute("exclusive", hw.fHardwareVirtExclusive);
     2390
    23492391    if (hw.fNestedPaging)
    23502392        pelmCPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", hw.fNestedPaging);
     
    28472889void MachineConfigFile::bumpSettingsVersionIfNeeded()
    28482890{
    2849     if (m->sv < SettingsVersion_v1_8)
    2850     {
    2851         // "accelerate 2d video" requires settings version 1.8
    2852         if (hardwareMachine.fAccelerate2DVideo)
    2853             m->sv = SettingsVersion_v1_8;
    2854     }
    2855 
     2891    // "accelerate 2d video" requires settings version 1.8
     2892    if (    (m->sv < SettingsVersion_v1_8)
     2893         && (hardwareMachine.fAccelerate2DVideo)
     2894       )
     2895        m->sv = SettingsVersion_v1_8;
     2896
     2897    // all the following require settings version 1.9
     2898    if (    (m->sv < SettingsVersion_v1_9)
     2899         && (    (hardwareMachine.firmwareType == FirmwareType_EFI)
     2900              || (hardwareMachine.fHardwareVirtExclusive != HWVIRTEXCLUSIVEDEFAULT)
     2901              || fTeleporterEnabled
     2902              || uTeleporterPort
     2903              || !strTeleporterAddress.isEmpty()
     2904              || !strTeleporterPassword.isEmpty()
     2905              || !hardwareMachine.uuid.isEmpty()
     2906            )
     2907        )
     2908        m->sv = SettingsVersion_v1_9;
     2909
     2910    // settings version 1.9 is also required if there is not exactly one DVD
     2911    // or more than one floppy drive present or the DVD is not at the secondary
     2912    // master; this check is a bit more complicated
    28562913    if (m->sv < SettingsVersion_v1_9)
    28572914    {
     
    28592916        size_t cFloppies = 0;
    28602917
    2861         // if there is more than one DVD or floppy or the DVD attachment is not
    2862         // at the old IDE default, then we need 1.9
     2918        // need to run thru all the storage controllers to figure this out
    28632919        for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin();
    28642920             it != storageMachine.llStorageControllers.end()
     
    29052961            m->sv = SettingsVersion_v1_9;
    29062962    }
    2907 
    2908     if (    (m->sv < SettingsVersion_v1_9)
    2909          && (hardwareMachine.firmwareType == FirmwareType_EFI)
    2910        )
    2911     {
    2912         m->sv = SettingsVersion_v1_9;
    2913     }
    2914 
    2915     if (    m->sv < SettingsVersion_v1_9
    2916         &&  (   fTeleporterEnabled
    2917              || uTeleporterPort
    2918              || !strTeleporterAddress.isEmpty()
    2919              || !strTeleporterPassword.isEmpty()
    2920             )
    2921        )
    2922         m->sv = SettingsVersion_v1_9;
    2923 
    2924     if (    m->sv < SettingsVersion_v1_9
    2925         &&  !hardwareMachine.uuid.isEmpty())
    2926         m->sv = SettingsVersion_v1_9;
    29272963}
    29282964
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