- Timestamp:
- Jun 27, 2007 2:45:20 PM (18 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HardDiskImpl.cpp
r3093 r3317 33 33 #include <iprt/cpputils.h> 34 34 #include <VBox/VBoxHDD.h> 35 #include <VBox/VBoxHDD-new.h>36 35 #include <VBox/err.h> 37 36 … … 485 484 486 485 /* create the hard disk creation thread, pass operation data */ 487 int vrc = RTThreadCreate (NULL, HVirtualDiskImage:: vdiTaskThread,486 int vrc = RTThreadCreate (NULL, HVirtualDiskImage::VDITaskThread, 488 487 (void *) task, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 489 488 0, "VDITask"); … … 1062 1061 AssertReturn (*aLocation, E_INVALIDARG); 1063 1062 1064 HRESULT rc = S_OK; 1063 static const struct 1064 { 1065 HardDiskStorageType_T type; 1066 const char *ext; 1067 } 1068 storageTypes[] = 1069 { 1070 { HardDiskStorageType_VMDKImage, ".vmdk" }, 1071 { HardDiskStorageType_VirtualDiskImage, ".vdi" }, 1072 }; 1065 1073 1066 1074 /* try to guess the probe order by extension */ 1075 size_t first = -1; 1067 1076 Utf8Str loc = aLocation; 1068 1077 char *ext = RTPathExt (loc); 1069 1078 1070 HardDiskStorageType_T order [2]; 1071 size_t cOrder = ELEMENTS (order); 1072 1073 if (RTPathCompare (ext, ".vmdk") == 0) 1074 { 1075 /// @todo This is a hack. The proper solution would be to save the 1076 /// error info from the first try and restore that if everything fails. 1077 /// That way a non-working VMDK will get a proper VMDK diagnostics 1078 /// message and not some incomprehensible VDI error. 1079 order [0] = HardDiskStorageType_VMDKImage; 1080 cOrder = 1; 1081 } 1082 else 1083 { 1084 order [0] = HardDiskStorageType_VirtualDiskImage; 1085 order [1] = HardDiskStorageType_VMDKImage; 1086 } 1087 1088 for (size_t i = 0; i < cOrder; ++ i) 1089 { 1090 switch (order [i]) 1079 for (size_t i = 0; i < ELEMENTS (storageTypes); ++ i) 1080 { 1081 if (RTPathCompare (ext, storageTypes [i].ext) == 0) 1082 { 1083 first = i; 1084 break; 1085 } 1086 } 1087 1088 HRESULT rc = S_OK; 1089 1090 HRESULT firstRC = S_OK; 1091 com::ErrorInfoKeeper firstErr (true /* aIsNull */); 1092 1093 for (size_t i = 0; i < ELEMENTS (storageTypes); ++ i) 1094 { 1095 size_t j = first == -1 ? i : i == 0 ? first : i == first ? 0 : i; 1096 switch (storageTypes [j].type) 1091 1097 { 1092 1098 case HardDiskStorageType_VirtualDiskImage: … … 1118 1124 default: 1119 1125 { 1120 ComAssertComRCRetRC (E_FAIL);1126 AssertComRCReturnRC (E_FAIL); 1121 1127 } 1122 1128 } 1123 } 1124 1125 return rc; 1129 1130 Assert (FAILED (rc)); 1131 1132 /* remember the first encountered error */ 1133 if (j == first) 1134 { 1135 firstRC = rc; 1136 firstErr.fetch(); 1137 } 1138 } 1139 1140 if (first != -1) 1141 { 1142 Assert (FAILED (firstRC)); 1143 /* firstErr will restore the error info upon destruction */ 1144 return firstRC; 1145 } 1146 1147 /* There was no exact extension match; chances are high that an error we 1148 * got after probing is useless. Use a generic error message instead. */ 1149 1150 firstErr.forget(); 1151 1152 return setError (E_FAIL, 1153 tr ("Could not recognize the format of the hard disk '%ls'. " 1154 "Either the given format is not supported or hard disk data " 1155 "is corrupt"), 1156 aLocation); 1126 1157 } 1127 1158 … … 2599 2630 2600 2631 /* create the hard disk creation thread, pass operation data */ 2601 vrc = RTThreadCreate (NULL, vdiTaskThread, (void *) task, 0,2632 vrc = RTThreadCreate (NULL, VDITaskThread, (void *) task, 0, 2602 2633 RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, "VDITask"); 2603 2634 ComAssertMsgRC (vrc, ("Could not create a thread (%Vrc)", vrc)); … … 2618 2649 2619 2650 /* static */ 2620 DECLCALLBACK(int) HVirtualDiskImage:: vdiTaskThread (RTTHREAD thread, void *pvUser)2651 DECLCALLBACK(int) HVirtualDiskImage::VDITaskThread (RTTHREAD thread, void *pvUser) 2621 2652 { 2622 2653 VDITask *task = static_cast <VDITask *> (pvUser); 2623 2654 AssertReturn (task, VERR_GENERAL_FAILURE); 2624 2655 2625 LogFlow (("vdiTaskThread(): operation=%d, size=%llu\n", 2626 task->operation, task->size)); 2656 LogFlowFunc (("operation=%d, size=%llu\n", task->operation, task->size)); 2627 2657 2628 2658 VDIIMAGETYPE type = (VDIIMAGETYPE) 0; … … 2675 2705 } 2676 2706 2677 LogFlow (("vdiTaskThread():rc=%08X\n", rc));2707 LogFlowFunc (("rc=%08X\n", rc)); 2678 2708 2679 2709 AutoLock alock (task->vdi); … … 3313 3343 mActualSize = 0; 3314 3344 3345 /* initialize the container */ 3346 int vrc = VDCreate ("VMDK", VDError, this, &mContainer); 3347 ComAssertRCRet (vrc, E_FAIL); 3348 3315 3349 return S_OK; 3316 3350 } … … 3318 3352 void HVMDKImage::FinalRelease() 3319 3353 { 3354 if (mContainer != NULL) 3355 VDDestroy (mContainer); 3356 3320 3357 HardDisk::FinalRelease(); 3321 3358 } … … 3918 3955 } 3919 3956 3920 DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL,3921 const char *pszFormat, va_list va)3922 {3923 /// @todo pass the error message to the operation initiator3924 }3925 3926 3957 /** 3927 3958 * Helper to query information about the VDI hard disk. … … 3963 3994 Bstr errMsg; 3964 3995 3965 PVBOXHDD hdd = NULL; 3996 /* reset any previous error report from VDError() */ 3997 mLastVDError.setNull(); 3966 3998 3967 3999 do 3968 4000 { 3969 4001 Guid id, parentId; 3970 3971 /// @todo make PVBOXHDD a member variable and init/destroy it upon3972 /// image creation/deletion instead of doing that here every time.3973 3974 vrc = VDCreate ("VMDK", VDError, NULL, &hdd);3975 if (VBOX_FAILURE (vrc))3976 break;3977 4002 3978 4003 /// @todo changed from VD_OPEN_FLAGS_READONLY to VD_OPEN_FLAGS_NORMAL, … … 3981 4006 /// obviously. This of course changes locking behavior, but for now 3982 4007 /// this is acceptable. A better solution needs to be found later. 3983 vrc = VDOpen ( hdd, filePath, VD_OPEN_FLAGS_NORMAL);4008 vrc = VDOpen (mContainer, filePath, VD_OPEN_FLAGS_NORMAL); 3984 4009 if (VBOX_FAILURE (vrc)) 3985 4010 break; 3986 4011 3987 vrc = VDGetUuid ( hdd, 0, id.ptr());4012 vrc = VDGetUuid (mContainer, 0, id.ptr()); 3988 4013 if (VBOX_FAILURE (vrc)) 3989 4014 break; 3990 vrc = VDGetParentUuid ( hdd, 0, parentId.ptr());4015 vrc = VDGetParentUuid (mContainer, 0, parentId.ptr()); 3991 4016 if (VBOX_FAILURE (vrc)) 3992 4017 break; … … 4055 4080 if (!mParent) 4056 4081 { 4057 uint64_t size = VDGetSize ( hdd);4082 uint64_t size = VDGetSize (mContainer); 4058 4083 /* convert to MBytes */ 4059 4084 mSize = size / 1024 / 1024; … … 4062 4087 while (0); 4063 4088 4064 if (hdd) 4065 VDDestroy (hdd); 4089 VDCloseAll (mContainer); 4066 4090 4067 4091 /* enter the lock again */ … … 4081 4105 if (!errMsg.isNull()) 4082 4106 *aAccessError = errMsg; 4107 else if (!mLastVDError.isNull()) 4108 *aAccessError = mLastVDError; 4083 4109 else if (VBOX_FAILURE (vrc)) 4084 4110 *aAccessError = Utf8StrFmt ( … … 4110 4136 } 4111 4137 4138 /* cleanup the last error report from VDError() */ 4139 mLastVDError.setNull(); 4140 4112 4141 return rc; 4113 4142 } … … 4131 4160 4132 4161 /* static */ 4133 DECLCALLBACK(int) HVMDKImage:: vdiTaskThread (RTTHREAD thread, void *pvUser)4162 DECLCALLBACK(int) HVMDKImage::VDITaskThread (RTTHREAD thread, void *pvUser) 4134 4163 { 4135 4164 AssertMsgFailed (("Not implemented")); … … 4137 4166 4138 4167 /// @todo (r=dmik) later 4139 // Use code from HVirtualDiskImage::vdiTaskThread as an example. 4140 } 4168 // Use code from HVirtualDiskImage::VDITaskThread as an example. 4169 } 4170 4171 /* static */ 4172 DECLCALLBACK(void) HVMDKImage::VDError (void *pvUser, int rc, RT_SRC_POS_DECL, 4173 const char *pszFormat, va_list va) 4174 { 4175 HVMDKImage *that = static_cast <HVMDKImage *> (pvUser); 4176 AssertReturnVoid (that != NULL); 4177 4178 /// @todo pass the error message to the operation initiator 4179 Utf8Str err = Utf8StrFmt (pszFormat, va); 4180 if (VBOX_FAILURE (rc)) 4181 err = Utf8StrFmt ("%s (%Vrc)", err.raw(), rc); 4182 4183 if (that->mLastVDError.isNull()) 4184 that->mLastVDError = err; 4185 else 4186 that->mLastVDError = Utf8StrFmt 4187 ("%s.\n%s", that->mLastVDError.raw(), err.raw()); 4188 } 4189 -
trunk/src/VBox/Main/include/HardDiskImpl.h
r2981 r3317 27 27 28 28 #include <VBox/cfgldr.h> 29 #include <VBox/VBoxHDD-new.h> 29 30 30 31 #include <iprt/semaphore.h> … … 296 297 297 298 /** VDI asynchronous operation thread function */ 298 static DECLCALLBACK(int) vdiTaskThread (RTTHREAD thread, void *pvUser);299 static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser); 299 300 300 301 enum State … … 508 509 509 510 /** VDI asynchronous operation thread function */ 510 static DECLCALLBACK(int) vdiTaskThread (RTTHREAD thread, void *pvUser); 511 static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser); 512 513 static DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL, 514 const char *pszFormat, va_list va); 511 515 512 516 enum State … … 531 535 Bstr mFilePathFull; 532 536 537 PVBOXHDD mContainer; 538 539 Utf8Str mLastVDError; 540 533 541 friend class HardDisk; 534 542 };
Note:
See TracChangeset
for help on using the changeset viewer.