Changeset 21031 in vbox for trunk/src/VBox/Main/HardDiskImpl.cpp
- Timestamp:
- Jun 29, 2009 3:26:13 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HardDiskImpl.cpp
r20977 r21031 423 423 { 424 424 return setError (E_FAIL, 425 tr ("Hard disk '%ls' involved in the merge operation " 426 "has more than one child hard disk (%d)"), 425 tr ("Hard disk '%ls' involved in the merge operation has more than one child hard disk (%d)"), 427 426 aHardDisk->m.locationFull.raw(), 428 427 aHardDisk->children().size()); … … 1459 1458 && !(mm.formatObj->capabilities() & HardDiskFormatCapabilities_CreateDynamic)) 1460 1459 return setError (VBOX_E_NOT_SUPPORTED, 1461 tr ("Hard disk format '%ls' does not support dynamic storage "1462 "creation"),mm.format.raw());1460 tr ("Hard disk format '%ls' does not support dynamic storage creation"), 1461 mm.format.raw()); 1463 1462 if ( (aVariant & HardDiskVariant_Fixed) 1464 1463 && !(mm.formatObj->capabilities() & HardDiskFormatCapabilities_CreateDynamic)) 1465 1464 return setError (VBOX_E_NOT_SUPPORTED, 1466 tr ("Hard disk format '%ls' does not support fixed storage "1467 "creation"),mm.format.raw());1465 tr ("Hard disk format '%ls' does not support fixed storage creation"), 1466 mm.format.raw()); 1468 1467 1469 1468 switch (m.state) … … 1611 1610 throw target->setStateError(); 1612 1611 1613 /** @todo implement the cloning to existing media */1614 if (target->m.state == MediaState_Created)1615 throw setError (E_NOTIMPL, tr ("This cloning variant is not implemented"));1616 1617 1612 /** @todo separate out creating/locking an image chain from 1618 1613 * SessionMachine::lockMedia and use it from here too. … … 1644 1639 CheckComRCThrowRC (rc); 1645 1640 } 1646 rc = parentChain->lockImagesRead(); 1647 CheckComRCThrowRC (rc); 1641 if (target->m.state == MediaState_Created) 1642 { 1643 /* If we're cloning to an existing image the parent chain also 1644 * contains the target image, and it gets locked for writing. */ 1645 rc = parentChain->addImage(target); 1646 CheckComRCThrowRC (rc); 1647 rc = parentChain->lockImagesReadAndLastWrite(); 1648 CheckComRCThrowRC (rc); 1649 } 1650 else 1651 { 1652 rc = parentChain->lockImagesRead(); 1653 CheckComRCThrowRC (rc); 1654 } 1648 1655 1649 1656 progress.createObject(); … … 1667 1674 CheckComRCThrowRC (rc); 1668 1675 1669 /* go to Creating state before leaving the lock */ 1670 target->m.state = MediaState_Creating; 1676 if (target->m.state == MediaState_NotCreated) 1677 { 1678 /* go to Creating state before leaving the lock */ 1679 target->m.state = MediaState_Creating; 1680 } 1671 1681 1672 1682 /* task is now owned (or already deleted) by taskThread() so release it */ … … 2591 2601 { 2592 2602 return setError (VBOX_E_INVALID_OBJECT_STATE, 2593 tr ("Hard disk '%ls' is attached to a virtual machine " 2594 "with UUID {%RTuuid}. No differencing hard disks " 2595 "based on it may be created until it is detached"), 2603 tr ("Hard disk '%ls' is attached to a virtual machine with UUID {%RTuuid}. No differencing hard disks based on it may be created until it is detached"), 2596 2604 m.locationFull.raw(), it->machineId.raw()); 2597 2605 } … … 2983 2991 2984 2992 ComAssertMsgRet (!mm.formatObj->fileExtensions().empty(), 2985 ("Must be at least one extension if it is " 2986 "HardDiskFormatCapabilities_File\n"), 2993 ("Must be at least one extension if it is HardDiskFormatCapabilities_File\n"), 2987 2994 E_FAIL); 2988 2995 … … 3044 3051 if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND) 3045 3052 return setError (VBOX_E_FILE_ERROR, 3046 tr ("Could not find file for the hard disk "3047 "'%s' (%Rrc)"),locationFull.raw(), vrc);3053 tr ("Could not find file for the hard disk '%s' (%Rrc)"), 3054 locationFull.raw(), vrc); 3048 3055 else 3049 3056 return setError (VBOX_E_IPRT_ERROR, 3050 tr ("Could not get the storage format of the hard disk "3051 "'%s' (%Rrc)"),locationFull.raw(), vrc);3057 tr ("Could not get the storage format of the hard disk '%s' (%Rrc)"), 3058 locationFull.raw(), vrc); 3052 3059 } 3053 3060 … … 3297 3304 { 3298 3305 lastAccessError = Utf8StrFmt ( 3299 tr ("UUID {%RTuuid} of the hard disk '%ls' does " 3300 "not match the value {%RTuuid} stored in the " 3301 "media registry ('%ls')"), 3306 tr ("UUID {%RTuuid} of the hard disk '%ls' does not match the value {%RTuuid} stored in the media registry ('%ls')"), 3302 3307 &uuid, m.locationFull.raw(), m.id.raw(), 3303 3308 mVirtualBox->settingsFileName().raw()); … … 3349 3354 { 3350 3355 lastAccessError = Utf8StrFmt ( 3351 tr ("Parent hard disk with UUID {%RTuuid} of the " 3352 "hard disk '%ls' is not found in the media " 3353 "registry ('%ls')"), 3356 tr ("Parent hard disk with UUID {%RTuuid} of the hard disk '%ls' is not found in the media registry ('%ls')"), 3354 3357 &parentId, m.locationFull.raw(), 3355 3358 mVirtualBox->settingsFileName().raw()); … … 3380 3383 { 3381 3384 lastAccessError = Utf8StrFmt ( 3382 tr ("Hard disk '%ls' is differencing but it is not " 3383 "associated with any parent hard disk in the " 3384 "media registry ('%ls')"), 3385 tr ("Hard disk '%ls' is differencing but it is not associated with any parent hard disk in the media registry ('%ls')"), 3385 3386 m.locationFull.raw(), 3386 3387 mVirtualBox->settingsFileName().raw()); … … 3393 3394 { 3394 3395 lastAccessError = Utf8StrFmt ( 3395 tr ("Parent UUID {%RTuuid} of the hard disk '%ls' " 3396 "does not match UUID {%RTuuid} of its parent " 3397 "hard disk stored in the media registry ('%ls')"), 3396 tr ("Parent UUID {%RTuuid} of the hard disk '%ls' does not match UUID {%RTuuid} of its parent hard disk stored in the media registry ('%ls')"), 3398 3397 &parentId, m.locationFull.raw(), 3399 3398 mParent->id().raw(), … … 3433 3432 { 3434 3433 m.lastAccessError = lastAccessError; 3435 LogWarningFunc (("'%ls' is not accessible (error='%ls', " 3436 "rc=%Rhrc, vrc=%Rrc)\n", 3434 LogWarningFunc (("'%ls' is not accessible (error='%ls', rc=%Rhrc, vrc=%Rrc)\n", 3437 3435 m.locationFull.raw(), m.lastAccessError.raw(), 3438 3436 rc, vrc)); … … 3497 3495 if (mm.numCreateDiffTasks > 0) 3498 3496 return setError (E_FAIL, 3499 tr ("One or more differencing child hard disks are " 3500 "being created for the hard disk '%ls' (%u)"), 3497 tr ("One or more differencing child hard disks are being created for the hard disk '%ls' (%u)"), 3501 3498 m.locationFull.raw(), mm.numCreateDiffTasks); 3502 3499 … … 3794 3791 { 3795 3792 throw setError (E_FAIL, 3796 tr ("Could not create the hard disk storage " 3797 "unit '%s'%s"), 3793 tr ("Could not create the hard disk storage unit '%s'%s"), 3798 3794 location.raw(), that->vdError (vrc).raw()); 3799 3795 } … … 3893 3889 { 3894 3890 throw setError (E_FAIL, 3895 tr ("Could not open the hard disk storage " 3896 "unit '%s'%s"), 3891 tr ("Could not open the hard disk storage unit '%s'%s"), 3897 3892 location.raw(), that->vdError (vrc).raw()); 3898 3893 } … … 3918 3913 { 3919 3914 throw setError (E_FAIL, 3920 tr ("Could not create the differencing hard disk " 3921 "storage unit '%s'%s"), 3915 tr ("Could not create the differencing hard disk storage unit '%s'%s"), 3922 3916 targetLocation.raw(), that->vdError (vrc).raw()); 3923 3917 } … … 4360 4354 { 4361 4355 throw setError (E_FAIL, 4362 tr ("Could not open the hard disk storage " 4363 "unit '%s'%s"), 4356 tr ("Could not open the hard disk storage unit '%s'%s"), 4364 4357 Utf8Str ((*it)->m.locationFull).raw(), 4365 4358 that->vdError (vrc).raw()); … … 4373 4366 Utf8Str targetLocation (target->m.locationFull); 4374 4367 4375 Assert (target->m.state == MediaState_Creating); 4368 Assert ( target->m.state == MediaState_Creating 4369 || target->m.state == MediaState_LockedWrite); 4376 4370 Assert (that->m.state == MediaState_LockedRead); 4377 4371 Assert (parent.isNull() || parent->m.state == MediaState_LockedRead); … … 4395 4389 { 4396 4390 /* sanity check */ 4397 Assert ((*it)->m.state == MediaState_LockedRead); 4398 4399 /** Open all images in read-only mode. */ 4400 vrc = VDOpen (hdd, Utf8Str ((*it)->mm.format), 4391 Assert ( (*it)->m.state == MediaState_LockedRead 4392 || (*it)->m.state == MediaState_LockedWrite); 4393 4394 /* Open all images in appropriate mode. */ 4395 vrc = VDOpen (targetHdd, Utf8Str ((*it)->mm.format), 4401 4396 Utf8Str ((*it)->m.locationFull), 4402 VD_OPEN_FLAGS_READONLY,4397 ((*it)->m.state == MediaState_LockedWrite) ? VD_OPEN_FLAGS_NORMAL : VD_OPEN_FLAGS_READONLY, 4403 4398 (*it)->mm.vdDiskIfaces); 4404 4399 if (RT_FAILURE (vrc)) 4405 4400 { 4406 4401 throw setError (E_FAIL, 4407 tr ("Could not open the hard disk storage " 4408 "unit '%s'%s"), 4402 tr ("Could not open the hard disk storage unit '%s'%s"), 4409 4403 Utf8Str ((*it)->m.locationFull).raw(), 4410 4404 that->vdError (vrc).raw()); … … 4413 4407 4414 4408 vrc = VDCopy (hdd, VD_LAST_IMAGE, targetHdd, 4415 targetFormat, targetLocation, false, 0, 4409 targetFormat, 4410 target->m.state == MediaState_Creating ? targetLocation.raw() : (char *)NULL, 4411 false, 0, 4416 4412 task->d.variant, targetId.raw(), NULL, 4417 4413 target->mm.vdDiskIfaces, … … 4423 4419 { 4424 4420 throw setError (E_FAIL, 4425 tr ("Could not create the clone hard disk " 4426 "'%s'%s"), 4421 tr ("Could not create the clone hard disk '%s'%s"), 4427 4422 targetLocation.raw(), that->vdError (vrc).raw()); 4428 4423 } … … 4440 4435 catch (HRESULT aRC) { rc = aRC; } 4441 4436 4442 if (SUCCEEDED (rc)) 4437 /* Only do the parent changes for newly created images. */ 4438 if (target->m.state == MediaState_Creating) 4443 4439 { 4444 /* we set mParent & children() (note that thatLock is released 4445 * here), but lock VirtualBox first to follow the rule */ 4446 AutoMultiWriteLock2 alock (that->mVirtualBox->lockHandle(), 4447 that->treeLock()); 4448 4449 Assert (target->mParent.isNull()); 4450 4451 if (parent) 4440 if (SUCCEEDED (rc)) 4452 4441 { 4453 /* associate the clone with the parent and deassociate 4454 * from VirtualBox */ 4455 target->mParent = parent; 4456 parent->addDependentChild (target); 4457 target->mVirtualBox->removeDependentChild (target); 4458 4459 /* register with mVirtualBox as the last step and move to 4460 * Created state only on success (leaving an orphan file is 4461 * better than breaking media registry consistency) */ 4462 rc = parent->mVirtualBox->registerHardDisk(target); 4463 4464 if (FAILED (rc)) 4442 /* we set mParent & children() (note that thatLock is released 4443 * here), but lock VirtualBox first to follow the rule */ 4444 AutoMultiWriteLock2 alock (that->mVirtualBox->lockHandle(), 4445 that->treeLock()); 4446 4447 Assert (target->mParent.isNull()); 4448 4449 if (parent) 4465 4450 { 4466 /* break parent association on failure to register */ 4467 target->mVirtualBox->addDependentChild (target); 4468 parent->removeDependentChild (target); 4469 target->mParent.setNull(); 4451 /* associate the clone with the parent and deassociate 4452 * from VirtualBox */ 4453 target->mParent = parent; 4454 parent->addDependentChild (target); 4455 target->mVirtualBox->removeDependentChild (target); 4456 4457 /* register with mVirtualBox as the last step and move to 4458 * Created state only on success (leaving an orphan file is 4459 * better than breaking media registry consistency) */ 4460 rc = parent->mVirtualBox->registerHardDisk(target); 4461 4462 if (FAILED (rc)) 4463 { 4464 /* break parent association on failure to register */ 4465 target->mVirtualBox->addDependentChild (target); 4466 parent->removeDependentChild (target); 4467 target->mParent.setNull(); 4468 } 4470 4469 } 4470 else 4471 { 4472 /* just register */ 4473 rc = that->mVirtualBox->registerHardDisk(target); 4474 } 4475 } 4476 } 4477 4478 thatLock.maybeEnter(); 4479 4480 if (target->m.state == MediaState_Creating) 4481 { 4482 if (SUCCEEDED (rc)) 4483 { 4484 target->m.state = MediaState_Created; 4485 4486 target->m.size = size; 4487 target->mm.logicalSize = logicalSize; 4471 4488 } 4472 4489 else 4473 4490 { 4474 /* just register */ 4475 rc = that->mVirtualBox->registerHardDisk(target); 4491 /* back to NotCreated on failure */ 4492 target->m.state = MediaState_NotCreated; 4493 4494 /* reset UUID to prevent it from being reused next time */ 4495 if (generateUuid) 4496 unconst (target->m.id).clear(); 4476 4497 } 4477 }4478 4479 thatLock.maybeEnter();4480 4481 if (SUCCEEDED (rc))4482 {4483 target->m.state = MediaState_Created;4484 4485 target->m.size = size;4486 target->mm.logicalSize = logicalSize;4487 }4488 else4489 {4490 /* back to NotCreated on failure */4491 target->m.state = MediaState_NotCreated;4492 4493 /* reset UUID to prevent it from being reused next time */4494 if (generateUuid)4495 unconst (target->m.id).clear();4496 4498 } 4497 4499 … … 4538 4540 { 4539 4541 throw setError (E_FAIL, 4540 tr ("Could not delete the hard disk storage " 4541 "unit '%s'%s"), 4542 tr ("Could not delete the hard disk storage unit '%s'%s"), 4542 4543 location.raw(), that->vdError (vrc).raw()); 4543 4544 } … … 4607 4608 { 4608 4609 throw setError (E_FAIL, 4609 tr ("Could not delete the hard disk storage " 4610 "unit '%s'%s"), 4610 tr ("Could not delete the hard disk storage unit '%s'%s"), 4611 4611 location.raw(), that->vdError (vrc).raw()); 4612 4612 } … … 4619 4619 { 4620 4620 throw setError (E_FAIL, 4621 tr ("Could not open the hard disk storage " 4622 "unit '%s'%s"), 4621 tr ("Could not open the hard disk storage unit '%s'%s"), 4623 4622 parentLocation.raw(), that->vdError (vrc).raw()); 4624 4623 } … … 4641 4640 { 4642 4641 throw setError (E_FAIL, 4643 tr ("Could not create the differencing hard disk " 4644 "storage unit '%s'%s"), 4642 tr ("Could not create the differencing hard disk storage unit '%s'%s"), 4645 4643 location.raw(), that->vdError (vrc).raw()); 4646 4644 } … … 4712 4710 { 4713 4711 throw setError (E_FAIL, 4714 tr ("Could not open the hard disk storage " 4715 "unit '%s'%s"), 4712 tr ("Could not open the hard disk storage unit '%s'%s"), 4716 4713 Utf8Str ((*it)->m.locationFull).raw(), 4717 4714 that->vdError (vrc).raw());
Note:
See TracChangeset
for help on using the changeset viewer.