Changeset 54438 in vbox for trunk/src/VBox/Main
- Timestamp:
- Feb 24, 2015 11:09:17 AM (10 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/idl/VirtualBox.xidl
r54266 r54438 1820 1820 <interface 1821 1821 name="IVirtualBox" extends="$unknown" 1822 uuid=" 5e67bc8a-5f8f-11e4-aa15-123b93f75cba"1822 uuid="3afa096e-2cad-4cb0-aba2-47fe3fc62bd8" 1823 1823 wsmap="managed" 1824 1824 > … … 2359 2359 a "DVD" device type, this is ignored and read-only mode is always assumed.</desc> 2360 2360 </param> 2361 <param name="forceNewUuid" type="boolean" dir="in">2362 <desc>Allows the caller to request a completely new medium UUID for2363 the image which is to be opened. Useful if one intends to open an exact2364 copy of a previously opened image, as this would normally fail due to2365 the duplicate UUID.</desc>2366 </param>2367 2361 <param name="aDeviceTypeType" type="DeviceType" dir="in"> 2368 2362 <desc> 2369 2363 Must be one of "HardDisk", "DVD" or "Floppy". 2370 </desc>2371 </param>2372 <param name="medium" type="IMedium" dir="return">2373 <desc>Created medium object.</desc>2374 </param>2375 </method>2376 2377 <method name="createHardDisk">2378 <desc>2379 Creates a new base medium object that will use the given storage2380 format and location for medium data.2381 2382 The actual storage unit is not created by this method. In order to2383 do it, and before you are able to attach the created medium to2384 virtual machines, you must call one of the following methods to2385 allocate a format-specific storage unit at the specified location:2386 <ul>2387 <li><link to="IMedium::createBaseStorage"/></li>2388 <li><link to="IMedium::createDiffStorage"/></li>2389 </ul>2390 2391 Some medium attributes, such as <link to="IMedium::id"/>, may2392 remain uninitialized until the medium storage unit is successfully2393 created by one of the above methods.2394 2395 After the storage unit is successfully created, it will be2396 accessible through the <link to="#openMedium"/> method and can2397 be found in the <link to="#hardDisks"/> array.2398 2399 The list of all storage formats supported by this VirtualBox2400 installation can be obtained using2401 <link to="ISystemProperties::mediumFormats"/>. If the @a format2402 attribute is empty or @c null then the default storage format2403 specified by <link to="ISystemProperties::defaultHardDiskFormat"/> will2404 be used for creating a storage unit of the medium.2405 2406 Note that the format of the location string is storage format specific.2407 See <link to="IMedium::location"/> and IMedium for more details.2408 2409 <result name="VBOX_E_OBJECT_NOT_FOUND">2410 @a format identifier is invalid. See2411 <link to="ISystemProperties::mediumFormats"/>.2412 </result>2413 <result name="VBOX_E_FILE_ERROR">2414 @a location is a not valid file name (for file-based formats only).2415 </result>2416 </desc>2417 <param name="format" type="wstring" dir="in">2418 <desc>2419 Identifier of the storage format to use for the new medium.2420 </desc>2421 </param>2422 <param name="location" type="wstring" dir="in">2423 <desc>2424 Location of the storage unit for the new medium.2425 2364 </desc> 2426 2365 </param> … … 9202 9141 Keep in mind that the medium format identifier 9203 9142 (<link to="IMediumFormat::id"/>) used in other API calls like 9204 <link to="IVirtualBox::create HardDisk"/> to refer to a particular9143 <link to="IVirtualBox::createMedium"/> to refer to a particular 9205 9144 medium format is a case-insensitive string. This means that, for 9206 9145 example, all of the following strings: … … 9225 9164 The medium format set by this attribute is used by VirtualBox 9226 9165 when the medium format was not specified explicitly. One example is 9227 <link to="IVirtualBox::create HardDisk"/> with the empty9166 <link to="IVirtualBox::createMedium"/> with the empty 9228 9167 format argument. A more complex example is implicit creation of 9229 9168 differencing media when taking a snapshot of a virtual machine: … … 9249 9188 <link to="#mediumFormats"/>, 9250 9189 <link to="IMediumFormat::id"/>, 9251 <link to="IVirtualBox::create HardDisk"/>9190 <link to="IVirtualBox::createMedium"/> 9252 9191 </see> 9253 9192 </desc> … … 13518 13457 Existing media are opened using <link to="IVirtualBox::openMedium"/>; 13519 13458 new hard disk media can be created with the VirtualBox API using the 13520 <link to="IVirtualBox::create HardDisk"/> method. Differencing hard13459 <link to="IVirtualBox::createMedium"/> method. Differencing hard 13521 13460 disks (see below) are usually implicitly created by VirtualBox as 13522 13461 needed, but may also be created explicitly using <link to="#createDiffStorage"/>. … … 14846 14785 Each medium format is identified by a string represented by the 14847 14786 <link to="#id"/> attribute. This string is used in calls like 14848 <link to="IVirtualBox::create HardDisk"/> to specify the desired14787 <link to="IVirtualBox::createMedium"/> to specify the desired 14849 14788 format. 14850 14789 … … 14870 14809 This string is used in methods of other interfaces where it is necessary 14871 14810 to specify a medium format, such as 14872 <link to="IVirtualBox::create HardDisk"/>.14811 <link to="IVirtualBox::createMedium"/>. 14873 14812 </desc> 14874 14813 </attribute> -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r53354 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 217 217 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult); 218 218 void i_copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget); 219 HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType,219 HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, 220 220 AutoWriteLock &mediaTreeLock); 221 221 HRESULT i_unregisterMedium(Medium *pMedium); … … 295 295 std::vector<MachineState_T> &aStates); 296 296 HRESULT createAppliance(ComPtr<IAppliance> &aAppliance); 297 HRESULT createHardDisk(const com::Utf8Str &aFormat,298 const com::Utf8Str &aLocation,299 ComPtr<IMedium> &aMedium);300 297 HRESULT createMedium(const com::Utf8Str &aFormat, 301 298 const com::Utf8Str &aLocation, 302 299 AccessMode_T aAccessMode, 303 BOOL aForceNewUuid,304 300 DeviceType_T aDeviceType, 305 301 ComPtr<IMedium> &aMedium); -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r53354 r54438 5 5 6 6 /* 7 * Copyright (C) 2008-201 4Oracle Corporation7 * Copyright (C) 2008-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 2521 2521 2522 2522 /* Now create an empty hard disk. */ 2523 rc = mVirtualBox->CreateHardDisk(Bstr(strTrgFormat).raw(), 2524 Bstr(*strTargetPath).raw(), 2525 ComPtr<IMedium>(pTargetHD).asOutParam()); 2523 rc = mVirtualBox->CreateMedium(Bstr(strTrgFormat).raw(), 2524 Bstr(*strTargetPath).raw(), 2525 AccessMode_ReadWrite, DeviceType_HardDisk, 2526 ComPtr<IMedium>(pTargetHD).asOutParam()); 2526 2527 if (FAILED(rc)) throw rc; 2527 2528 -
trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp
r53354 r54438 5 5 6 6 /* 7 * Copyright (C) 2011-201 4Oracle Corporation7 * Copyright (C) 2011-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 1252 1252 AutoWriteLock tlock(p->mParent->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 1253 1253 rc = p->mParent->i_registerMedium(pTarget, &pTarget, 1254 DeviceType_HardDisk,1255 1254 tlock); 1256 1255 if (FAILED(rc)) throw rc; -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r53739 r54438 5 5 6 6 /* 7 * Copyright (C) 2008-201 4Oracle Corporation7 * Copyright (C) 2008-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 883 883 * storage unit. 884 884 * 885 * This gets called by VirtualBox::Create HardDisk() in which case uuidMachineRegistry885 * This gets called by VirtualBox::CreateMedium() in which case uuidMachineRegistry 886 886 * is empty since starting with VirtualBox 4.0, we no longer add opened media to a 887 887 * registry automatically (this is deferred until the medium is attached to a machine). … … 975 975 } 976 976 977 rc = m->pVirtualBox->i_registerMedium(this, &pMedium, aDeviceType,treeLock);977 rc = m->pVirtualBox->i_registerMedium(this, &pMedium, treeLock); 978 978 Assert(this == pMedium || FAILED(rc)); 979 979 } … … 1280 1280 const settings::Medium &med = *it; 1281 1281 1282 ComObjPtr<Medium> p HD;1283 p HD.createObject();1284 rc = p HD->init(aVirtualBox,1285 this, // parent1286 aDeviceType,1287 uuidMachineRegistry,1288 med, // child data1289 strMachineFolder);1282 ComObjPtr<Medium> pMedium; 1283 pMedium.createObject(); 1284 rc = pMedium->init(aVirtualBox, 1285 this, // parent 1286 aDeviceType, 1287 uuidMachineRegistry, 1288 med, // child data 1289 strMachineFolder); 1290 1290 if (FAILED(rc)) break; 1291 1291 1292 1292 AutoWriteLock treeLock(aVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 1293 1293 1294 rc = m->pVirtualBox->i_registerMedium(p HD, &pHD, DeviceType_HardDisk, treeLock);1294 rc = m->pVirtualBox->i_registerMedium(pMedium, &pMedium, treeLock); 1295 1295 if (FAILED(rc)) break; 1296 1296 } … … 2380 2380 2381 2381 if ( (mediumVariantFlags & MediumVariant_Fixed) 2382 && !(m->formatObj->i_getCapabilities() & MediumFormatCapabilities_Create Dynamic))2382 && !(m->formatObj->i_getCapabilities() & MediumFormatCapabilities_CreateFixed)) 2383 2383 throw setError(VBOX_E_NOT_SUPPORTED, 2384 2384 tr("Medium format '%s' does not support fixed storage creation"), … … 5942 5942 { 5943 5943 /* Note that we need to de-associate ourselves from the parent to let 5944 * unregisterMedium() properly save the registry */5944 * VirtualBox::i_unregisterMedium() properly save the registry */ 5945 5945 5946 5946 /* we modify mParent and access children */ … … 6695 6695 { 6696 6696 id.create(); 6697 /* VirtualBox:: registerMedium() will need UUID */6697 /* VirtualBox::i_registerMedium() will need UUID */ 6698 6698 unconst(m->id) = id; 6699 6699 } … … 6738 6738 task.mVDOperationIfaces); 6739 6739 if (RT_FAILURE(vrc)) 6740 throw setError(VBOX_E_FILE_ERROR, 6741 tr("Could not create the medium storage unit '%s'%s"), 6742 location.c_str(), i_vdError(vrc).c_str()); 6740 { 6741 if (vrc == VERR_VD_INVALID_TYPE) 6742 throw setError(VBOX_E_FILE_ERROR, 6743 tr("Parameters for creating the medium storage unit '%s' are invalid%s"), 6744 location.c_str(), i_vdError(vrc).c_str()); 6745 else 6746 throw setError(VBOX_E_FILE_ERROR, 6747 tr("Could not create the medium storage unit '%s'%s"), 6748 location.c_str(), i_vdError(vrc).c_str()); 6749 } 6743 6750 6744 6751 size = VDGetFileSize(hdd, 0); … … 6762 6769 AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); 6763 6770 ComObjPtr<Medium> pMedium; 6764 rc = m->pVirtualBox->i_registerMedium(this, &pMedium, DeviceType_HardDisk,treeLock);6771 rc = m->pVirtualBox->i_registerMedium(this, &pMedium, treeLock); 6765 6772 Assert(this == pMedium); 6766 6773 } … … 6833 6840 { 6834 6841 targetId.create(); 6835 /* VirtualBox:: registerMedium() will need UUID */6842 /* VirtualBox::i_registerMedium() will need UUID */ 6836 6843 unconst(pTarget->m->id) = targetId; 6837 6844 } … … 6911 6918 task.mVDOperationIfaces); 6912 6919 if (RT_FAILURE(vrc)) 6913 throw setError(VBOX_E_FILE_ERROR, 6914 tr("Could not create the differencing medium storage unit '%s'%s"), 6915 targetLocation.c_str(), i_vdError(vrc).c_str()); 6920 { 6921 if (vrc == VERR_VD_INVALID_TYPE) 6922 throw setError(VBOX_E_FILE_ERROR, 6923 tr("Parameters for creating the differencing medium storage unit '%s' are invalid%s"), 6924 targetLocation.c_str(), i_vdError(vrc).c_str()); 6925 else 6926 throw setError(VBOX_E_FILE_ERROR, 6927 tr("Could not create the differencing medium storage unit '%s'%s"), 6928 targetLocation.c_str(), i_vdError(vrc).c_str()); 6929 } 6916 6930 6917 6931 size = VDGetFileSize(hdd, VD_LAST_IMAGE); … … 6949 6963 * better than breaking media registry consistency) */ 6950 6964 ComObjPtr<Medium> pMedium; 6951 mrc = m->pVirtualBox->i_registerMedium(pTarget, &pMedium, DeviceType_HardDisk,treeLock);6965 mrc = m->pVirtualBox->i_registerMedium(pTarget, &pMedium, treeLock); 6952 6966 Assert(pTarget == pMedium); 6953 6967 … … 7184 7198 ComObjPtr<Medium> pMedium; 7185 7199 rc2 = m->pVirtualBox->i_registerMedium(pTarget, &pMedium, 7186 DeviceType_HardDisk,7187 7200 treeLock); 7188 7201 AssertComRC(rc2); … … 7534 7547 ComObjPtr<Medium> pMedium; 7535 7548 mrc = pParent->m->pVirtualBox->i_registerMedium(pTarget, &pMedium, 7536 DeviceType_HardDisk,7537 7549 treeLock); 7538 7550 Assert( FAILED(mrc) … … 7550 7562 ComObjPtr<Medium> pMedium; 7551 7563 mrc = m->pVirtualBox->i_registerMedium(pTarget, &pMedium, 7552 DeviceType_HardDisk,7553 7564 treeLock); 7554 7565 Assert( FAILED(mrc) … … 7781 7792 task.mVDOperationIfaces); 7782 7793 if (RT_FAILURE(vrc)) 7783 throw setError(VBOX_E_FILE_ERROR, 7784 tr("Could not create the differencing medium storage unit '%s'%s"), 7785 location.c_str(), i_vdError(vrc).c_str()); 7794 { 7795 if (vrc == VERR_VD_INVALID_TYPE) 7796 throw setError(VBOX_E_FILE_ERROR, 7797 tr("Parameters for creating the differencing medium storage unit '%s' are invalid%s"), 7798 location.c_str(), i_vdError(vrc).c_str()); 7799 else 7800 throw setError(VBOX_E_FILE_ERROR, 7801 tr("Could not create the differencing medium storage unit '%s'%s"), 7802 location.c_str(), i_vdError(vrc).c_str()); 7803 } 7786 7804 7787 7805 size = VDGetFileSize(hdd, VD_LAST_IMAGE); … … 8324 8342 ComObjPtr<Medium> pMedium; 8325 8343 mrc = pParent->m->pVirtualBox->i_registerMedium(this, &pMedium, 8326 DeviceType_HardDisk,8327 8344 treeLock); 8328 8345 Assert(this == pMedium); … … 8338 8355 eik.restore(); 8339 8356 ComObjPtr<Medium> pMedium; 8340 mrc = m->pVirtualBox->i_registerMedium(this, &pMedium, DeviceType_HardDisk,treeLock);8357 mrc = m->pVirtualBox->i_registerMedium(this, &pMedium, treeLock); 8341 8358 Assert(this == pMedium); 8342 8359 eik.fetch(); -
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r52615 r54438 6 6 7 7 /* 8 * Copyright (C) 2006-201 4Oracle Corporation8 * Copyright (C) 2006-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 3445 3445 3446 3446 // then, register again 3447 rc = mParent->i_registerMedium(pDeleteRec->mpTarget, &pDeleteRec->mpTarget, DeviceType_HardDisk,treeLock);3447 rc = mParent->i_registerMedium(pDeleteRec->mpTarget, &pDeleteRec->mpTarget, treeLock); 3448 3448 AssertComRC(rc); 3449 3449 } -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r54276 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 677 677 if (FAILED(rc)) return rc; 678 678 679 rc = i_registerMedium(pHardDisk, &pHardDisk, DeviceType_HardDisk,treeLock);679 rc = i_registerMedium(pHardDisk, &pHardDisk, treeLock); 680 680 if (FAILED(rc)) return rc; 681 681 } … … 697 697 if (FAILED(rc)) return rc; 698 698 699 rc = i_registerMedium(pImage, &pImage, DeviceType_DVD,treeLock);699 rc = i_registerMedium(pImage, &pImage, treeLock); 700 700 if (FAILED(rc)) return rc; 701 701 } … … 717 717 if (FAILED(rc)) return rc; 718 718 719 rc = i_registerMedium(pImage, &pImage, DeviceType_Floppy,treeLock);719 rc = i_registerMedium(pImage, &pImage, treeLock); 720 720 if (FAILED(rc)) return rc; 721 721 } … … 1735 1735 } 1736 1736 1737 HRESULT VirtualBox::createHardDisk(const com::Utf8Str &aFormat,1738 const com::Utf8Str &aLocation,1739 ComPtr<IMedium> &aMedium)1740 {1741 /* we don't access non-const data members so no need to lock */1742 HRESULT rc = createMedium(aFormat, aLocation, AccessMode_ReadWrite, TRUE, DeviceType_HardDisk, aMedium);1743 1744 return rc;1745 }1746 1747 1737 HRESULT VirtualBox::createMedium(const com::Utf8Str &aFormat, 1748 1738 const com::Utf8Str &aLocation, 1749 1739 AccessMode_T aAccessMode, 1750 BOOL aForceNewUuid,1751 1740 DeviceType_T aDeviceType, 1752 1741 ComPtr<IMedium> &aMedium) 1753 1742 { 1754 NOREF(aForceNewUuid); 1755 NOREF(aAccessMode); 1743 NOREF(aAccessMode); /**< @todo r=klaus make use of access mode */ 1756 1744 1757 1745 HRESULT rc = S_OK; … … 1867 1855 if (SUCCEEDED(rc)) 1868 1856 { 1869 rc = i_registerMedium(pMedium, &pMedium, aDeviceType,treeLock);1857 rc = i_registerMedium(pMedium, &pMedium, treeLock); 1870 1858 1871 1859 treeLock.release(); … … 4206 4194 * to an unavoidable race there was a duplicate Medium object 4207 4195 * created. 4208 * @param argType Either DeviceType_HardDisk, DeviceType_DVD or DeviceType_Floppy.4209 4196 * @param mediaTreeLock Reference to the AutoWriteLock holding the media tree 4210 4197 * lock, necessary to release it in the right spot. … … 4213 4200 HRESULT VirtualBox::i_registerMedium(const ComObjPtr<Medium> &pMedium, 4214 4201 ComObjPtr<Medium> *ppMedium, 4215 DeviceType_T argType,4216 4202 AutoWriteLock &mediaTreeLock) 4217 4203 { … … 4230 4216 const char *pszDevType = NULL; 4231 4217 ObjectsList<Medium> *pall = NULL; 4232 switch (argType) 4218 DeviceType_T devType; 4219 { 4220 AutoReadLock mediumLock(pMedium COMMA_LOCKVAL_SRC_POS); 4221 devType = pMedium->i_getDeviceType(); 4222 } 4223 switch (devType) 4233 4224 { 4234 4225 case DeviceType_HardDisk: … … 4245 4236 break; 4246 4237 default: 4247 AssertMsgFailedReturn(("invalid device type %d", argType), E_INVALIDARG);4238 AssertMsgFailedReturn(("invalid device type %d", devType), E_INVALIDARG); 4248 4239 } 4249 4240 … … 4284 4275 4285 4276 // store all hard disks (even differencing images) in the map 4286 if ( argType == DeviceType_HardDisk)4277 if (devType == DeviceType_HardDisk) 4287 4278 m->mapHardDisks[id] = pMedium; 4288 4279 -
trunk/src/VBox/Main/testcase/tstMediumLock.cpp
r48955 r54438 7 7 8 8 /* 9 * Copyright (C) 2013 Oracle Corporation9 * Copyright (C) 2013-2015 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 108 108 { 109 109 RTTestSub(hTest, "Creating temp hard disk medium"); 110 TEST_COM_SUCCESS(hTest, pVirtualBox->Create HardDisk(Bstr("VDI").raw(), Bstr(szPathTemp).raw(), pMedium.asOutParam()), "create medium");110 TEST_COM_SUCCESS(hTest, pVirtualBox->CreateMedium(Bstr("VDI").raw(), Bstr(szPathTemp).raw(), AccessMode_ReadWrite, DeviceType_HardDisk, pMedium.asOutParam()), "create medium"); 111 111 if (!pMedium.isNull()) 112 112 { -
trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp
r50339 r54438 8 8 9 9 /* 10 * Copyright (C) 2006-201 4Oracle Corporation10 * Copyright (C) 2006-2015 Oracle Corporation 11 11 * 12 12 * This file is part of VirtualBox Open Source Edition (OSE), as … … 291 291 */ 292 292 nsCOMPtr<IMedium> hardDisk = 0; 293 rc = virtualBox->CreateHardDisk(NS_LITERAL_STRING("VDI").get(), 294 NS_LITERAL_STRING("/tmp/TestHardDisk.vdi").get(), 295 getter_AddRefs(hardDisk)); 293 rc = virtualBox->CreateMedium(NS_LITERAL_STRING("VDI").get(), 294 NS_LITERAL_STRING("/tmp/TestHardDisk.vdi").get(), 295 AccessMode_ReadWrite, DeviceType_HardDisk, 296 getter_AddRefs(hardDisk)); 296 297 if (NS_FAILED(rc)) 297 298 {
Note:
See TracChangeset
for help on using the changeset viewer.