Changeset 43478 in vbox for trunk/src/VBox/Main
- Timestamp:
- Oct 1, 2012 9:05:19 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r43476 r43478 1019 1019 AssertReturn(!aLocation.isEmpty(), E_INVALIDARG); 1020 1020 1021 /* Enclose the state transition NotReady->InInit->Ready */1022 AutoInitSpan autoInitSpan(this);1023 AssertReturn(autoInitSpan.isOk(), E_FAIL);1024 1025 1021 HRESULT rc = S_OK; 1026 1022 1027 unconst(m->pVirtualBox) = aVirtualBox; 1028 1029 /* there must be a storage unit */ 1030 m->state = MediumState_Created; 1031 1032 /* remember device type for correct unregistering later */ 1033 m->devType = aDeviceType; 1034 1035 /* cannot be a host drive */ 1036 m->hostDrive = false; 1037 1038 /* remember the open mode (defaults to ReadWrite) */ 1039 m->hddOpenMode = enOpenMode; 1040 1041 if (aDeviceType == DeviceType_DVD) 1042 m->type = MediumType_Readonly; 1043 else if (aDeviceType == DeviceType_Floppy) 1044 m->type = MediumType_Writethrough; 1045 1046 rc = setLocation(aLocation); 1047 if (FAILED(rc)) return rc; 1048 1049 /* get all the information about the medium from the storage unit */ 1050 if (fForceNewUuid) 1051 unconst(m->uuidImage).create(); 1052 1023 { 1024 /* Enclose the state transition NotReady->InInit->Ready */ 1025 AutoInitSpan autoInitSpan(this); 1026 AssertReturn(autoInitSpan.isOk(), E_FAIL); 1027 1028 unconst(m->pVirtualBox) = aVirtualBox; 1029 1030 /* there must be a storage unit */ 1031 m->state = MediumState_Created; 1032 1033 /* remember device type for correct unregistering later */ 1034 m->devType = aDeviceType; 1035 1036 /* cannot be a host drive */ 1037 m->hostDrive = false; 1038 1039 /* remember the open mode (defaults to ReadWrite) */ 1040 m->hddOpenMode = enOpenMode; 1041 1042 if (aDeviceType == DeviceType_DVD) 1043 m->type = MediumType_Readonly; 1044 else if (aDeviceType == DeviceType_Floppy) 1045 m->type = MediumType_Writethrough; 1046 1047 rc = setLocation(aLocation); 1048 if (FAILED(rc)) return rc; 1049 1050 /* get all the information about the medium from the storage unit */ 1051 if (fForceNewUuid) 1052 unconst(m->uuidImage).create(); 1053 1054 m->state = MediumState_Inaccessible; 1055 m->strLastAccessError = tr("Accessibility check was not yet performed"); 1056 1057 /* Confirm a successful initialization before the call to queryInfo. 1058 * Otherwise we can end up with a AutoCaller deadlock because the 1059 * medium becomes visible but is not marked as initialized. Causes 1060 * locking trouble (e.g. trying to save media registries) which is 1061 * hard to solve. */ 1062 autoInitSpan.setSucceeded(); 1063 } 1064 1065 /* we're normal code from now on, no longer init */ 1066 AutoCaller autoCaller(this); 1067 if (FAILED(autoCaller.rc())) 1068 return autoCaller.rc(); 1069 1070 /* need to call queryInfo immediately to correctly place the medium in 1071 * the respective media tree and update other information such as uuid */ 1053 1072 rc = queryInfo(fForceNewUuid /* fSetImageId */, false /* fSetParentId */); 1054 1055 1073 if (SUCCEEDED(rc)) 1056 1074 { 1075 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1076 1057 1077 /* if the storage unit is not accessible, it's not acceptable for the 1058 1078 * newly opened media so convert this into an error */ … … 1061 1081 Assert(!m->strLastAccessError.isEmpty()); 1062 1082 rc = setError(E_FAIL, "%s", m->strLastAccessError.c_str()); 1083 alock.release(); 1084 autoCaller.release(); 1085 uninit(); 1063 1086 } 1064 1087 else 1065 1088 { 1066 AssertReturn(!m->id.isEmpty(), E_FAIL); 1089 AssertStmt(!m->id.isEmpty(), 1090 alock.release(); autoCaller.release(); uninit(); return E_FAIL); 1067 1091 1068 1092 /* storage format must be detected by Medium::queryInfo if the 1069 1093 * medium is accessible */ 1070 AssertReturn(!m->strFormat.isEmpty(), E_FAIL); 1071 } 1072 } 1073 1074 /* Confirm a successful initialization when it's the case */ 1075 if (SUCCEEDED(rc)) 1076 autoInitSpan.setSucceeded(); 1094 AssertStmt(!m->strFormat.isEmpty(), 1095 alock.release(); autoCaller.release(); uninit(); return E_FAIL); 1096 } 1097 } 1098 else 1099 { 1100 /* opening this image failed, mark the object as dead */ 1101 autoCaller.release(); 1102 uninit(); 1103 } 1077 1104 1078 1105 return rc; … … 5563 5590 } 5564 5591 5592 /* set the image uuid before the below parent uuid handling code 5593 * might place it somewhere in the media tree, so that the medium 5594 * UUID is valid at this point */ 5595 alock.acquire(); 5596 if (isImport || fSetImageId) 5597 unconst(m->id) = mediumId; 5598 alock.release(); 5599 5565 5600 /* get the medium variant */ 5566 5601 unsigned uImageFlags; … … 5697 5732 treeLock.acquire(); 5698 5733 alock.acquire(); 5699 5700 if (isImport || fSetImageId)5701 unconst(m->id) = mediumId;5702 5734 5703 5735 if (success)
Note:
See TracChangeset
for help on using the changeset viewer.