- Timestamp:
- Jan 18, 2010 11:29:39 AM (15 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MediumImpl.cpp
r25860 r25882 4865 4865 } 4866 4866 4867 HRESULT Medium::taskThreadCreateBase(Task &task, void *pvdOperationIfaces) 4868 { 4869 PVDINTERFACE vdOperationIfaces = (PVDINTERFACE)pvdOperationIfaces; 4870 4871 HRESULT rc = S_OK; 4872 4873 /* The lock is also used as a signal from the task initiator (which 4874 * releases it only after RTThreadCreate()) that we can start the job */ 4875 AutoWriteLock thisLock(this COMMA_LOCKVAL_SRC_POS); 4876 4877 /* these parameters we need after creation */ 4878 uint64_t size = 0, logicalSize = 0; 4879 4880 /* The object may request a specific UUID (through a special form of 4881 * the setLocation() argument). Otherwise we have to generate it */ 4882 Guid id = m->id; 4883 bool generateUuid = id.isEmpty(); 4884 if (generateUuid) 4885 { 4886 id.create(); 4887 /* VirtualBox::registerHardDisk() will need UUID */ 4888 unconst(m->id) = id; 4889 } 4890 4891 try 4892 { 4893 PVBOXHDD hdd; 4894 int vrc = VDCreate(m->vdDiskIfaces, &hdd); 4895 ComAssertRCThrow(vrc, E_FAIL); 4896 4897 Utf8Str format(m->strFormat); 4898 Utf8Str location(m->strLocationFull); 4899 /* uint64_t capabilities = */ m->formatObj->capabilities(); 4900 4901 /* unlock before the potentially lengthy operation */ 4902 Assert(m->state == MediumState_Creating); 4903 thisLock.leave(); 4904 4905 try 4906 { 4907 /* ensure the directory exists */ 4908 rc = VirtualBox::ensureFilePathExists(location); 4909 if (FAILED(rc)) throw rc; 4910 4911 PDMMEDIAGEOMETRY geo = { 0 }; /* auto-detect */ 4912 4913 vrc = VDCreateBase(hdd, 4914 format.c_str(), 4915 location.c_str(), 4916 task.d.size * _1M, 4917 task.d.variant, 4918 NULL, 4919 &geo, 4920 &geo, 4921 id.raw(), 4922 VD_OPEN_FLAGS_NORMAL, 4923 NULL, 4924 vdOperationIfaces); 4925 if (RT_FAILURE(vrc)) 4926 { 4927 throw setError(E_FAIL, 4928 tr("Could not create the hard disk storage unit '%s'%s"), 4929 location.raw(), vdError(vrc).raw()); 4930 } 4931 4932 size = VDGetFileSize(hdd, 0); 4933 logicalSize = VDGetSize(hdd, 0) / _1M; 4934 } 4935 catch (HRESULT aRC) { rc = aRC; } 4936 4937 VDDestroy(hdd); 4938 } 4939 catch (HRESULT aRC) { rc = aRC; } 4940 4941 if (SUCCEEDED(rc)) 4942 { 4943 /* register with mVirtualBox as the last step and move to 4944 * Created state only on success (leaving an orphan file is 4945 * better than breaking media registry consistency) */ 4946 rc = m->pVirtualBox->registerHardDisk(this); 4947 } 4948 4949 thisLock.maybeEnter(); 4950 4951 if (SUCCEEDED(rc)) 4952 { 4953 m->state = MediumState_Created; 4954 4955 m->size = size; 4956 m->logicalSize = logicalSize; 4957 } 4958 else 4959 { 4960 /* back to NotCreated on failure */ 4961 m->state = MediumState_NotCreated; 4962 4963 /* reset UUID to prevent it from being reused next time */ 4964 if (generateUuid) 4965 unconst(m->id).clear(); 4966 } 4967 4968 return rc; 4969 } 4970 4971 4867 4972 /** 4868 4973 * Thread function for time-consuming tasks. … … 4876 4981 DECLCALLBACK(int) Medium::taskThread(RTTHREAD thread, void *pvUser) 4877 4982 { 4878 std::auto_ptr <Task> task(static_cast <Task*>(pvUser));4983 std::auto_ptr<Task> task(static_cast<Task*>(pvUser)); 4879 4984 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 4880 4985 … … 4914 5019 4915 5020 case Task::CreateBase: 4916 { 4917 /* The lock is also used as a signal from the task initiator (which 4918 * releases it only after RTThreadCreate()) that we can start the job */ 4919 AutoWriteLock thatLock(that COMMA_LOCKVAL_SRC_POS); 4920 4921 /* these parameters we need after creation */ 4922 uint64_t size = 0, logicalSize = 0; 4923 4924 /* The object may request a specific UUID (through a special form of 4925 * the setLocation() argument). Otherwise we have to generate it */ 4926 Guid id = that->m->id; 4927 bool generateUuid = id.isEmpty(); 4928 if (generateUuid) 4929 { 4930 id.create(); 4931 /* VirtualBox::registerHardDisk() will need UUID */ 4932 unconst(that->m->id) = id; 4933 } 4934 4935 try 4936 { 4937 PVBOXHDD hdd; 4938 int vrc = VDCreate(that->m->vdDiskIfaces, &hdd); 4939 ComAssertRCThrow(vrc, E_FAIL); 4940 4941 Utf8Str format(that->m->strFormat); 4942 Utf8Str location(that->m->strLocationFull); 4943 /* uint64_t capabilities = */ that->m->formatObj->capabilities(); 4944 4945 /* unlock before the potentially lengthy operation */ 4946 Assert(that->m->state == MediumState_Creating); 4947 thatLock.leave(); 4948 4949 try 4950 { 4951 /* ensure the directory exists */ 4952 rc = VirtualBox::ensureFilePathExists(location); 4953 if (FAILED(rc)) throw rc; 4954 4955 PDMMEDIAGEOMETRY geo = { 0 }; /* auto-detect */ 4956 4957 vrc = VDCreateBase(hdd, format.c_str(), location.c_str(), 4958 task->d.size * _1M, 4959 task->d.variant, 4960 NULL, &geo, &geo, id.raw(), 4961 VD_OPEN_FLAGS_NORMAL, 4962 NULL, vdOperationIfaces); 4963 if (RT_FAILURE(vrc)) 4964 { 4965 throw setError(E_FAIL, 4966 tr("Could not create the hard disk storage unit '%s'%s"), 4967 location.raw(), that->vdError(vrc).raw()); 4968 } 4969 4970 size = VDGetFileSize(hdd, 0); 4971 logicalSize = VDGetSize(hdd, 0) / _1M; 4972 } 4973 catch (HRESULT aRC) { rc = aRC; } 4974 4975 VDDestroy(hdd); 4976 } 4977 catch (HRESULT aRC) { rc = aRC; } 4978 4979 if (SUCCEEDED(rc)) 4980 { 4981 /* register with mVirtualBox as the last step and move to 4982 * Created state only on success (leaving an orphan file is 4983 * better than breaking media registry consistency) */ 4984 rc = that->m->pVirtualBox->registerHardDisk(that); 4985 } 4986 4987 thatLock.maybeEnter(); 4988 4989 if (SUCCEEDED(rc)) 4990 { 4991 that->m->state = MediumState_Created; 4992 4993 that->m->size = size; 4994 that->m->logicalSize = logicalSize; 4995 } 4996 else 4997 { 4998 /* back to NotCreated on failure */ 4999 that->m->state = MediumState_NotCreated; 5000 5001 /* reset UUID to prevent it from being reused next time */ 5002 if (generateUuid) 5003 unconst(that->m->id).clear(); 5004 } 5005 5006 break; 5007 } 5021 rc = that->taskThreadCreateBase(*task, (void*)vdOperationIfaces); 5022 break; 5008 5023 5009 5024 //////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/include/MediumImpl.h
r25256 r25882 306 306 char *pszValue, size_t cchValue); 307 307 308 static DECLCALLBACK(int) taskThread(RTTHREAD thread, void *pvUser);309 310 308 struct Task; 311 309 friend struct Task; 310 311 HRESULT taskThreadCreateBase(Task &task, void *pvdOperationIfaces); 312 313 static DECLCALLBACK(int) taskThread(RTTHREAD thread, void *pvUser); 312 314 313 315 struct Data; // opaque data struct, defined in MediumImpl.cpp
Note:
See TracChangeset
for help on using the changeset viewer.