Changeset 24276 in vbox
- Timestamp:
- Nov 2, 2009 7:29:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/xml/Settings.cpp
r24274 r24276 1 1 /** @file 2 2 * 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. 3 37 */ 4 38 … … 1196 1230 } 1197 1231 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 1198 1241 /** 1199 1242 * Hardware struct constructor. … … 1202 1245 : strVersion("2"), 1203 1246 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), 1209 1248 fNestedPaging(false), 1210 1249 fVPID(false), … … 1469 1508 { 1470 1509 pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt); 1471 pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive); 1510 pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive); // settings version 1.9 1472 1511 } 1473 1512 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging"))) … … 2344 2383 2345 2384 xml::ElementNode *pelmCPU = pelmHardware->createChild("CPU"); 2385 2346 2386 xml::ElementNode *pelmHwVirtEx = pelmCPU->createChild("HardwareVirtEx"); 2347 2387 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 2349 2391 if (hw.fNestedPaging) 2350 2392 pelmCPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", hw.fNestedPaging); … … 2847 2889 void MachineConfigFile::bumpSettingsVersionIfNeeded() 2848 2890 { 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 2856 2913 if (m->sv < SettingsVersion_v1_9) 2857 2914 { … … 2859 2916 size_t cFloppies = 0; 2860 2917 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 2863 2919 for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin(); 2864 2920 it != storageMachine.llStorageControllers.end() … … 2905 2961 m->sv = SettingsVersion_v1_9; 2906 2962 } 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_92916 && ( fTeleporterEnabled2917 || uTeleporterPort2918 || !strTeleporterAddress.isEmpty()2919 || !strTeleporterPassword.isEmpty()2920 )2921 )2922 m->sv = SettingsVersion_v1_9;2923 2924 if ( m->sv < SettingsVersion_v1_92925 && !hardwareMachine.uuid.isEmpty())2926 m->sv = SettingsVersion_v1_9;2927 2963 } 2928 2964
Note:
See TracChangeset
for help on using the changeset viewer.