Virtual Disk API Programming
Virtual Disk API Programming
Virtual Disk API Programming Guide Revision: 20080411 VDDK Virtual Disk Development Kit
You can find the most up-to-date technical documentation on our Web site at http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: [email protected]
2008 VMware, Inc. All rights reserved. Protected by one or more of U.S. Patent Nos. 6,397,242, 6,496,847, 6,704,925, 6,711,672, 6,725,289, 6,735,601, 6,785,886, 6,789,156, 6,795,966, 6,880,022, 6,944,699, 6,961,806, 6,961,941, 7,069,413, 7,082,598, 7,089,377, 7,111,086, 7,111,145, 7,117,481, 7,149,843, 7,155,558, 7,222,221, 7,260,815, 7,260,820, 7,269,683, 7,275,136, 7,277,998, 7,277,999, 7,278,030, 7,281,102, and 7,290,253; patents pending. VMware, the VMware boxes logo and design, Virtual SMP and VMotion are registered trademarks or trademarks of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective companies.
VMware, Inc.
Contents
AboutThisBook
1 IntroductiontotheVirtualDiskAPI 9
VirtualDiskManagement 9 WhatisManagedDisk? 9 VirtualDiskDevelopmentKit 10 VirtualDiskManagementUtilities 10 DiskMountUtility 10 VirtualDiskManagerUtility 10 VirtualDiskAPI 10 VMwareInfrastructureAPItoReadandWriteVMDK 10 VirtualDiskInternalFormat 11 SolutionsEnabledbytheVirtualDiskAPI 11 VirtualDiskLibraryFunctions 12
2 InstallingtheVirtualDiskDevelopmentKit 13
PackagingandComponents 13 SupportedPlatforms 13 ProgrammingEnvironments 13 VisualStudioonWindows 13 C++andConLinuxSystems 13 InstallingtheVirtualDiskDevelopmentKit 14 TargetSystemConnectivity 14 VMwareProducts 14 VMDKAccessandCredentials 14
3 VirtualDiskAPIFunctions 15
VirtualDiskandDataStructures 15 VMDKFileLocation 15 DiskTypes 15 PersistenceDiskModes 16 VMDKFileNaming 16 GrainDirectoriesandGrainTables 16 InternationalizationandLocalization 17 AdapterTypes 17 DataStructuresinVirtualDiskAPI 17 LibraryFunctions 18 StartUp 18 InitializetheLibrary 18 ConnecttoaWorkstationorServer 18 DiskOperations 18 CreateaNewHostedDisk 18 OpenaLocalorRemoteDisk 18 ReadSectorsFromaDisk 18 WriteSectorsToaDisk 19 CloseaLocalorRemoteDisk 19
VMware, Inc.
GetInformationAboutaDisk 19 FreeMemoryfromGetInformation 19 ErrorHandling 19 ReturnErrorDescriptionText 19 FreeErrorDescriptionText 19 MetadataHandling 19 ReadMetadataKeyfromDisk 19 GetMetadataTablefromDisk 19 WriteMetadataTabletoDisk 20 CloningaVirtualDisk 20 ComputeSpaceNeededforClone 20 CloneaDiskbyCopyingData 20 AdvancedDiskOperations 20 RenameanExistingDisk 20 GrowanExistingLocalDisk 20 DefragmentanExistingDisk 20 ShrinkanExistingLocalDisk 20 UnlinkExtentstoRemoveDisk 21 DiskChainingandRedoLogs 21 CreateChildfromParentDisk 21 AttachChildtoParentDisk 22 ShutDown 22 DisconnectfromServer 22 CleanUpandExit 22 CapabilitiesofLibraryCalls 23 SupportforHostedDisk 23 SupportforManagedDisk 23
4 VirtualDiskAPISampleCode 25
CompilingtheSampleProgram 25 VisualC++onWindows 25 SLNandVCPROJFiles 25 C++onLinuxSystems 25 Makefile 26 LibraryFilesRequired 26 UsageMessage 26 WalkThroughofSampleProgram 26 IncludeFiles 26 DefinitionsandStructures 26 DynamicLoading 27 WrapperClasses 27 CommandFunctions 27 VMXSpecification 27 DoInfo() 28 DoCreate() 28 DoRedo() 28 WritebyDoFill() 28 DoReadMetadata() 28 DoWriteMetadata() 29 DoDumpMetadata() 29 DoDump() 29 DoTestMultiThread() 29 DoClone() 29
VMware, Inc.
Contents
5 PracticalProgrammingTasks 31
ScanVMDKforVirusSignatures 31 CreatingVirtualDisks 32 CreatingLocalDisk 32 CreatingRemoteDisk 33 SpecialConsiderationforESXServer 33 WorkingwithVirtualDiskData 33 ReadingandWritingLocalDisk 33 ReadingandWritingRemoteDisk 34 DeletingaDisk(Unlink) 34 EffectsofDeletingaVirtualDisk 34 RenamingaDisk 34 EffectsofRenamingaVirtualDisk 34 WorkingwithDiskMetadata 34 ManagingChildDisks 34 CreatingRedoLogs 34 VirtualDiskinSnapshots 35 Windows2000ReadOnlyFileSystem 35 InterfacingWiththeVIXAPI 35 VirusScanallHostedDisk 36 InterfacingWithVMwareInfrastructure 36 VirusScanAllManagedDisk 36
A VirtualDiskAPIErrors 37
FindingErrorCodeDocumentation 37 AssociationWithVIXAPIErrors 37
B OpenVirtualMachineFormat 39
OVFTool 39 OVFLibrary 39
Glossary Index 43
41
VMware, Inc.
VMware, Inc.
Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisguide. Table 1. Revision History
Revision 20080411 20080131 Description SecondversionoftheVirtualDiskDevelopmentKitdocumentationfordeliverywithrelease1.0. FirstversionoftheVirtualDiskDevelopmentKitdocumentationforpartnerbetarelease.
Intended Audience
Thisguideisintendedfordeveloperswhoarecreatingapplicationsthatmanagevirtualstorage. VMwareoffersmanySDKproductsthattargetdifferentdevelopercommunities,programminglanguages, andplatforms.Tofindthem,andthemostcurrentversionofthisguide,goto http://www.vmware.com/support/pubs/sdk_pubs.html.
Online Support
YoucansubmitquestionsorpostcommentstotheDeveloperCommunitysSDKsandAPIsforum,whichis monitoredbyVMwaretechnicalsupportandproductteams.Youcanaccesstheforumat: http://communities.vmware.com/community/developer
Support Offerings
FindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds.Goto http://www.vmware.com/support/services.
VMware, Inc.
Document Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Ifyouhavecomments,sendyour feedbackto: [email protected]
VMware, Inc.
ThischapterintroducesVMwarevirtualdiskmanagementandtheVirtualDiskDevelopmentKit.
VMDK
VMDK
VMDK
VMware, Inc.
10
VMware, Inc.
VMware, Inc.
11
12
VMware, Inc.
ThischaptercoverstheprerequisitesforandinstallationoftheVirtualDiskDevelopmentKit.
Supported Platforms
YoucaninstalltheVirtualDiskDevelopmentKitonthefollowingplatforms: Windows,both32bitx86and64bitx8664processors: WindowsXP(ServicePack2) Windows2003(ServerServicePack2) WindowsVista Linux,separatepackagesfor32bitx86and64bitx8664processors: RedHatEnterpriseLinux(RHEL)5 UbuntuDesktop7.10 SUSEEnterpriseServer10(ServicePack1) FedoraCore8
Programming Environments
Youcancompilethesampleprograminthefollowingenvironments:
VMware, Inc.
13
Thiscreatesthevmware-vix-disklib-distribsubdirectory. 3 Changetothatdirectoryandruntheinstallationscriptasroot:
cd vmware-vix-disklib-distrib sudo ./vmware-install.pl
VMware Products
TheVirtualDiskDevelopmentKitsupportsthefollowingVMwareproducts: ESXServer3.0and3.5 ESXServer3iwithFoundationLicense(butnotwithBaseorCorelicense) VirtualCenterServer2.0and2.5 ESXServer2.5whenconnectingthroughVirtualCenter HostedproductsincludingWorkstation,ACE,Server,andPlayer
14
VMware, Inc.
3Vi
Disk Types
Thefollowingdisktypesaredefinedinthevirtualdisklibrary: VIXDISKLIB_DISK_MONOLITHIC_SPARSEGrowablevirtualdiskcontainedinasinglevirtualdiskfile. Thisisthedefaulttypeforhosteddisk,andtheonlysettingintheChapter 4sampleprogram. VIXDISKLIB_DISK_MONOLITHIC_FLATPreallocatedvirtualdiskcontainedinasinglevirtualdiskfile. Thistakesawhiletocreateandoccupiesalotofspace,butmightperformthebest. VIXDISKLIB_DISK_SPLIT_SPARSEGrowablevirtualdisksplitinto2GBextents(ssequence).These filesstartsmallbutcangrowto2GB,whichisthemaximumonoldfilesystems.Thistypeiscomplicated butverymanageablebecausesplitVMDKcanbedefragmented. VIXDISKLIB_DISK_SPLIT_FLATPreallocatedvirtualdisksplitinto2GBextents(fsequence).These filesstartat2GB,sotheytakeawhiletocreateandoccupyalotofspace,butavailablespaceishuge. VIXDISKLIB_DISK_VMFS_FLATPreallocatedvirtualdiskcompatiblewithESXServer3.0.Thisisthe sameasmanageddiskintroducedinVirtualDiskManagementonpage 9. VIXDISKLIB_DISK_STREAM_OPTIMIZEDMonolithicsparseandcompressedforstreaming. VIXDISKLIB_DISK_UNKNOWNDisklayoutisunknown. NOTEVMFS_SPARSEexistsbutisnotsupportedinthisreleaseoftheVirtualDiskAPI. Sparsedisksemploythecopyonwrite(COW)mechanism,inwhichvirtualdiskcontainsnodatainplaces, untilcopiedtherebyawrite.Thisoptimizationsavesstoragespace.
VMware, Inc. 15
MONOLITHIC_FLAT
<vnname>-flat.vmdk
SPLIT_SPARSE
<vmname>-s<###>.vmdk
SPLIT_FLAT
<vnname>-f<###>.vmdk
MONOLITHIC_SPARSE or SPLIT_SPARSE
<diskname>-<###>.vmdk
n/a
<vnname>Snapshot.vmsn
16
VMware, Inc.
Adapter Types
Thelibrarycanselectthefollowingadapters: VIXDISKLIB_ADAPTER_IDEVirtualdiskactslikeATA,ATAPI,PATA,SATA,andsoon.Youmightselect thisadaptertypewhenitisspecificallyrequiredbylegacysoftware. VIXDISKLIB_ADAPTER_SCSI_BUSLOGICVirtualSCSIdiskwithBuslogicadapter.Thisisthedefaulton someplatformsandisusuallyrecommendedoverIDEduetohigherperformance. VIXDISKLIB_ADAPTER_SCSI_LSILOGICVirtualSCSIdiskwithLSILogicadapter.WindowsServer2003 andmostLinuxvirtualmachinesusethistypebydefault.PerformanceisaboutthesameasBuslogic.
VixDiskLibConnectParams::VixDiskLibCredsCredentialsforeitheruserIDorsessionID: VixDiskLibConnectParams::VixDiskLibCreds::VixDiskLibUidPasswdCredsString datafieldsrepresentusernameandpasswordforauthentication. VixDiskLibConnectParams::VixDiskLibCreds::VixDiskLibSessionIdCredsString datafieldsrepresentthesessioncookie,username,andencryptedsessionkey. VixDiskLibCreateParamsPublictypesrepresentthevirtualdisk(seeDiskTypesonpage 15),the diskadapter(seeAdapterTypesonpage 17),VMwareversion(suchasWorkstation5orESXServer), andcapacityofthedisksector.
typedef typedef typedef typedef VixDiskLibDiskType diskType VixDiskLibAdapterType adapterType uint hwVersion VixDiskLibSectorType capacity
VixDiskLibGeometryPublictypesspecifydiskgeometry.Virtualdiskgeometrydoesnotnecessarily correspondwithphysicaldiskgeometry.
typedef uint32 cylinders typedef uint32 heads typedef uint32 sectors
VMware, Inc.
17
Library Functions
YoucanfindtheVixDiskLibAPIReferencebyusingaWebbrowsertoopenthedoc/index.htmlfileinthe VDDKsoftwaredistribution.Inthissection,functionsareorderedbyhowtheymightbecalled,ratherthan alphabeticallyasintheAPIreference. WhentheAPIreferencesaysthatafunctionsupportsonlyhosteddisks,itmeansvirtualdiskimageshosted byVMwareWorkstationorsimilarproducts.VirtualdiskimagesstoredonVMFSpartitionsforESXServer aremanageddisk.WhenthelibraryaccessesvirtualdiskonVMFS,allI/OgoesthroughtheESXserver, whichmanagesphysicaldiskstorage.TheVirtualDiskAPIhasnodirectaccesstoSANstorage.
Start Up
TheVixDiskLib_Init()andVixDiskLib_Connect()functionsmustappearinallvirtualdiskprograms.
AlwayscallVixDiskLib_Exit()attheendofyourprogramtodeinitialize.
AlwayscallVixDiskLib_Disconnect()beforetheendofyourprogram.
Disk Operations
Thesefunctionscreate,open,read,write,query,andclosevirtualdisk.
18
VMware, Inc.
Error Handling
Thesefunctionsenhancetheusefulnessoferrormessages.
Metadata Handling
Read Metadata Key from Disk
vixError = VixDiskLib_ReadMetadata(disk.Handle(), appGlobals.metaKey, &val[0], requiredLen, NULL);
Hereisanexampleofasimplemetadatatable.Uuidistheuniversallyuniqueidentifierforthevirtualdisk.
adapterType = buslogic geometry.sectors = 32 geometry.heads = 64 geometry.cylinders = 100 uuid = 60 00 C2 93 7b a0 3a 03-9f 22 56 c5 29 93 b7 27
VMware, Inc.
19
20
VMware, Inc.
Figure 3-1. Child Disks Created from Parent Virtual Machine Writes Here
Child3
vm.vmdk
vm-001.vmdk
Child1
vm.vmdk
vm-001.vmdk
Parent
vm.vmdk
vm-flat.vmdk
VMware, Inc.
21
Forexample,supposeyouwanttoaccesstheolderdiskimagerecordedbyChild1.Attachthehandleofnew Child1atoChild1,whichprovidesChild1asparenthandle,asshowninFigure 32.Itisnowpermissibleto open,read,andwritetheChild1avirtualdisk. Theparentchilddiskchainisefficientintermsofstoragespace,becausethechildVMDKrecordsonlythe sectorsthatchangedsincethelastVixDiskLib_CreateChild().Theparentchilddiskchainalsoprovidesa redomechanism,permittingprogrammaticaccesstoanygenerationwithVixDiskLib_Attach(). Figure 3-2. Child Disks Created from Parent Virtual Machine Writes Here
Child3
vm.vmdk
vm-001.vmdk
vm.vmdk
vm-002.vmdk
Child1a.vmdk
vm.vmdk
vm-001.vmdk
Parent
vm.vmdk
vm-flat.vmdk
Physical Disk
Shut Down
AllVirtualDiskAPIapplicationsshouldcallthesefunctionsatendofprogram.
22
VMware, Inc.
VMware, Inc.
23
24
VMware, Inc.
4Vi
IfyouinsertthatpathearlierinthePathsystemvariable,thesemicolongoesattheend. Tocompiletheprogram,findthesamplesourcevixDiskLibSample.cppatthislocation:
C:\Program Files\VMware\VMware Virtual Disk Development Kit\doc\sample\
VMware, Inc.
25
Typethemakecommandtocompile.Thenruntheapplication:
make ./vix-disklib-sample
Makefile
TheMakefilefetchesanypackagesthatarerequiredforcompilationbutarenotinstalled.
Usage Message
Runningthesampleapplicationwithoutargumentsproducesthefollowingusagemessage:
Usage: vixdisklibsample command [options] diskPath commands: -create : creates a sparse virtual disk with capacity specified by -cap -redo parentPath : creates a redo log 'diskPath' for base disk 'parentPath' -info : displays information for specified virtual disk -dump : dumps the contents of specified range of sectors in hexadecimal -fill : fills specified range of sectors with byte value specified by -val -wmeta key value : writes (key,value) entry into disk's metadata table -rmeta key : displays the value of the specified metada entry -meta : dumps all entries of the disk's metadata -clone sourcePath : clone source vmdk possibly to a remote site options: ...
Include Files
Windowsdynamiclinklibrary(DLL)declarationsareinprocess.h,whileLinuxsharedobject(.so) declarationsareindlfcn.h.Windowsoffersthetchar.hextensionforUnicodegenerictextmappings,not readilyavailableinLinux.
26
VMware, Inc.
Dynamic Loading
The#ifdefDYNAMIC_LOADINGblockislong,startingonline97andendingatline339. Thisblockcontainsfunctiondefinitionsfordynamicloading.ItalsocontainstheLoadOneFunc()procedure toobtainanyrequestedfunctionfromthedynamiclibraryandtheDynLoadDiskLib()proceduretobindit. Thisdemonstrationfeaturecouldalsobecalledruntimeloadingtodistinguishitfromdynamiclinking. TotrytheprogramwithruntimeloadingenabledonLinux,add-DDYNAMIC_LOADINGafterg++inthe Makefileandrecompile.OnWindows,defineDYNAMIC_LOADINGintheproject.
Wrapper Classes
Belowthedynamicloadingblockaretwowrapperclasses,oneforerrorcodesanddescriptivetext,andthe otherfortheconnectionhandletodisk. Theerrorwrapperappearsincatchandthrowstatementstosimplifyerrorhandlingacrossfunctions. WrapperclassVixDiskisacleanwaytoopenandcloseconnectionstodisk.Theonlytimethatlibrary functionsVixDiskLib_Open()andVixDiskLib_Close()appearelsewhere,asidefromdynamicloading,is intheCopyThread()functionneartheendofthesampleprogram.
Command Functions
Theprintusagemessageappearsnext,withoutputpartiallyshowninUsageMessageonpage 26. Nextcomesthemain()function,whichsetsdefaultsandparsescommandlineargumentstodeterminethe operationandpossiblysetoptionstochangedefaults.Dynamicloadingoccurs,ifdefined.Noticetheallzero initializationoftheVixDiskLibConnectParamsdeclaredstructure:
VixDiskLibConnectParams cnxParams = {0};
ForconnectionstoESXServer,credentialsincludingusernameandpasswordmustbecorrectlysuppliedin the-userand-passwordcommandlinearguments.Boththe-hostnameoftheESXServerandits-vm inventorypath(vmxSpec)mustbesupplied.Whenset,thesevaluespopulatethecnxParamsstructure. Initializeallconnectionparameters,especiallyvmxSpec,ortheconnectionmightbehaveunexpectedly. AcalltoVixDiskLib_Init()initializesthelibrary.Inaproductionapplication,youcansupplyappropriate log,warn,andpanicfunctionsasparameters,inplaceofNULL. AcalltoVixDiskLib_Connect()createsalibraryconnectiontodisk.IfhostcnxParams.serverNameisnull, asitiswithout-hostcommandlineargument,aconnectionismadetohosteddiskonthelocalhost.Ifserver nameisset,aconnectionismadetomanageddiskontheremoteserver. Next,anappropriatefunctioniscalledfortherequestedoperation,followedbyerrorinformationifapplicable. Finally,themain()functionclosesthelibraryconnectiontodiskandexits.
VMX Specification
OnESXserver,theVirtualMachineeXecutable(VMX)istheuserspacecomponentofvirtualinfrastructure. OnWorkstationandhostedproducts,the.vmxfilespecifiesvirtualmachineconfiguration.Inthevirtualdisk library,vmxSpeccanbeeitheraVMXfilelocator,oraninventorypathtothevirtualmachine: <vmxPathName>?dcPath=<datacenter>&dsName=<dstore> vmPath=<datacenter>/<path/to/vm> <vmxPathName>isthefullpathnameoftheVMXfile. <datacenter>istheinventorypathofthedatacenter. <dstore>isthedatastorename. HerearetwovmxSpecexamplesusingVirtualCenter;vixDiskLib.hdocumentsonlythefirst.
WinXP/WinXP.vmx?dcPath=Datacenter&dsName=Storage1 vmPath=Datacenter/vm/WinXP
VMware, Inc.
27
DoInfo()
ThisprocedurecallsVixDiskLib_GetInfo()forinformationaboutthevirtualdisk,displaysresults,andcalls VixDiskLib_FreeInfo()toreclaimmemory.Theparameterdisk.Handle()comesfromtheVixDisk wrapperclassdiscussedinWrapperClassesonpage 27. Inthisexample,thesampleprogramconnectstotheESXServernamedesx3anddisplaysvirtualdisk informationforaRedHatEnterpriseLinuxclient.ForanESXServer,pathtodiskis[storage1]followedby thevirtualmachinenameandtheVMDKfilename.
vix-diskLib-sample -info -host esx3 -user admin -password secret "[storage1]RHEL5/RHEL5.vmdk" capacity = 8388608 sectors number of links = 1 adapter type = LsiLogic SCSI BIOS geometry = 0/0/0 physical geometry = 522/255/63
DoCreate()
ThisprocedurecallsVixDiskLib_Create()toallocatevirtualdisk.AdaptertypeisSCSIunlessspecifiedas IDEonthecommandline.Sizeis100MB,unlesssetby-caponthecommandline.Becausethesectorsizeis 512bytes,thecodemultipliesappGlobals.mbsizeby2048insteadof1024.Typeisalwaysmonolithicsparse andWorkstation5.Inaproductionapplication,progressFuncandcallbackdatacanbedefinedratherthan NULL.TypethesecommandstocreateasampleVMDKfile(thefirstlineisforLinuxonly):
export LD_LIBRARY_PATH=/usr/lib/vmware-vix-disklib/lib32 vix-disklib-sample -create sample.vmdk
DoRedo()
ThisprocedurecallsVixDiskLib_CreateChild()toestablisharedolog.Achilddiskrecordsdisksectors thatchangedsincetheparentdiskorpreviouschild.Childrencanbechainedasasetofredologs. ThesampleprogramdoesnotdemonstrateuseofVixDiskLib_Attach(),whichyoucanusetoaccessalink inthediskchain.VixDiskLib_CreateChild()establishesaredolog,withthechildreplacingtheparentfor read/writeaccess.Givenapreexistingdiskchain,VixDiskLib_Attach()createsarelatedchild,oracousin youmightsay,thatislinkedintosomegenerationofthediskchain. Foradiagramoftheattachoperation,seeFigure 32,ChildDisksCreatedfromParent,onpage 22.
Write by DoFill()
ThisprocedurecallsVixDiskLib_Write()tofilladisksectorwithones(bytevalueFF)unlessotherwise specifiedby-valonthecommandline.Thedefaultistofillonlythefirstsector,butthiscanbechangedwith options-startand-countonthecommandline.
DoReadMetadata()
ThisprocedurecallsVixDiskLib_ReadMetadata()toservethe-rmetacommandlineoption.Forexample, typethiscommandtoobtaintheuniversallyuniqueidentifier:
vix-disklib-sample -rmeta uuid sample.vmdk
28
VMware, Inc.
DoWriteMetadata()
ThisprocedurecallsVixDiskLib_WriteMetadata()toservethe-wmetacommandlineoption.Forexample, youcanchangethetoolsversionfrom1to2asfollows:
vix-disklib-sample -wmeta toolsVersion 2 sample.vmdk
DoDumpMetadata()
ThisprocedurecallsVixDiskLib_GetMetadataKeys()thenVixDiskLib_ReadMetadata()toservethe -metacommandlineoption.Tworeadmetadatacallsareneededforeachkey:onetodeterminelengthofthe valuestringandanothertofillinthevalue.SeeGetMetadataTablefromDiskonpage 19. Inthefollowingexample,thesampleprogramconnectstotheESXServernamedesx3anddisplaysthe metadataoftheRedHatEnterpriseLinuxclientsvirtualdisk.ForanESXServer,pathtodiskis[storage1] followedbythevirtualmachinenameandtheVMDKfilename.
vix-diskLib-sample -meta -host esx3 -user admin -password secret "[storage1]RHEL5/RHEL5.vmdk" geometry.sectors = 63 geometry.heads = 255 geometry.cylinders = 522 adapterType = buslogic toolsVersion = 1
DoDump()
ThisprocedurecallsVixDiskLib_Read()toretrievesectorsanddisplayssectorcontentsontheoutputin hexadecimal.Thedefaultistodumponlythefirstsectornumberedzero,butyoucanchangethiswiththe -startand-countoptions.Hereisasequenceofcommandstodemonstrate:
vix-disklib-sample vix-disklib-sample vix-disklib-sample vix-disklib-sample od -c sample.vmdk -create sample.vmdk -fill -val 1 sample.vmdk -fill -val 2 -start 1 -count 1 sample.vmdk -dump -start 0 -count 2 sample.vmdk
DoTestMultiThread()
ThisprocedureemploystheWindowsthreadlibrarytomakemultiplecopiesofavirtualdiskfile.Specifythe numberofcopieswiththe-multithreadcommandlineoption.Foreachcopy,thesampleprogramcallsthe CopyThread()procedure,whichinturncallsasequenceofsixVirtualDiskAPIroutines. OnLinuxthemultithreadoptionisunimplemented.
DoClone()
ThisprocedurecallsVixDiskLib_Clone()tomakeacopyofthedataonvirtualdisk.Acallbackfunction, suppliedasthesixthparameter,displaysthepercentofcloningcompleted.Forlocalhosteddisk,theadapter typeisSCSIunlessspecifiedasIDEonthecommandline,sizeis200MB,unlesssetby-capoption,andtype ismonolithicsparse,forWorkstation5.ForanESXServer,adaptertypeistakenfrommanageddiskitself, usingtheconnectionparametersestablishedbyVixDiskLib_Connect(). ThefinalparameterTRUEmeanstooverwriteifthedestinationVMDKexists. Thecloneoptionisanexcellentbackupmethod.Oftentheclonedvirtualdiskissmaller,becauseitcanbe organizedmoreefficiently.Moreover,afullyallocatedflatfilecanbeconvertedtoasparserepresentation.
VMware, Inc.
29
30
VMware, Inc.
5Vi
VMware, Inc.
31
32
VMware, Inc.
Renaming a Disk
ThefunctiontorenamevirtualdiskfilesisVixDiskLib_Rename().Ittakestwoarguments:theoldandthe newVMDKfilenames.
vixError = VixDiskLib_Rename(oldGlobals.diskpath, newGlobals.diskpath);
34
VMware, Inc.
To re-create data for any given day 1 Locatethe<vmname>-<NNN>.vmdkredologforthedayinquestion. <NNN>isasequencenumber.Youcanidentifythisredologbyitstimestamp. 2 3 Initializethevirtualdisklibraryandopentheredologtoobtainitsparenthandle. CreateachilddiskwiththeVixDiskLib_Create()function,andattachittotheparent:
vixError = VixDiskLib_Attach(parent.Handle(), child.Handle());
Readandwritethevirtualdiskoftheattachedchild.
Windows 2000
C1
C2
C3
VMware, Inc.
35
36
VMware, Inc.
VMware, Inc.
37
VIX_E_DISK_UNSUPPORTEDDISKVERSION VIX_E_HOST_DISK_INVALID_VALUE VIX_E_HOST_DISK_SECTORSIZE VIX_E_HOST_FILE_ERROR_EOF VIX_E_HOST_NBD_HASHFILE_INIT VIX_E_HOST_NBD_HASHFILE_VOLUME VIX_E_HOST_NETBLKDEV_HANDSHAKE VIX_E_HOST_NETWORK_CONN_REFUSED VIX_E_HOST_SERVER_NOT_FOUND VIX_E_HOST_SOCKET_CREATION_ERROR VIX_E_HOST_TCP_CONN_LOST VIX_E_HOST_TCP_SOCKET_ERROR VIX_E_NOT_ALLOWED_DURING_VM_RECORDING VIX_E_NOT_ALLOWED_DURING_VM_REPLAY VIX_E_NOT_FOR_REMOTE_HOST
38
VMware, Inc.
BVi
OVF Tool
VMwarecurrentlyprovidestheOVFTool,agraphicaluserinterfacethatallowsthirdpartiestocreateOVF images.SeetheCommunitiessectionoftheVMwareWebsitefortheusersguide: http://www.vmware.com/resources/techresources/1013 AsimilarOVFpackagingmethodisincludedwithnewversionsofESXServer.
OVF Library
Atsomepoint,anOVFlibrarywillbepackagedforusewiththeVMwareVirtualDiskDevelopmentKitand otherVMwaredevelopmentplatforms.
VMware, Inc.
39
40
VMware, Inc.
Glossary
VMware, Inc.
41
42
VMware, Inc.
Index
A
access and credentials 14
O
OVF (open virtual-machine format) 39
C
code sample walk-through 26 CopyThread 27, 29 credentials and access 14
P
packaging of Virtual Disk API 13 persistent disk mode 16 platforms supported for development 13 products from VMware that are supported 14
D
datacenter path (dcpath) 27 datastore name (dsname) 27 development platforms 13 disk manager See virtual disk manager disk mount (vmware-mount) 10
R
redo logs and snapshots 10, 14, 16, 21, 34
S
sample program walk-through 26 SAN and the Virtual Disk API 9, 18 snapshot management 35 snapshots and redo logs 10, 14, 16, 21, 34 sparse VMDK 15, 16, 20, 21, 26, 28, 29, 32, 41 split VMDK 15, 16, 32, 41 SPLIT_FLAT 15, 16 SPLIT_SPARSE 15, 16 STREAM_OPTIMIZED 15 supported platforms for development 13 supported VMware products 14
E
error codes, finding explanations for 37 ESX Server 9 ESX Server and VirtualCenter 14 extent 11, 15, 20, 32, 41
F
flat VMDK 15, 16, 20, 41
G
gcc (GNU C compiler) 13
T
technical support resources 7
H
hosted disk 9, 11, 15, 18, 23, 27, 29, 33, 36, 41
U
Unicode UTF-8 support 17
I
installation on Linux 14 installation on Windows 14 internationalization (i18n) 17
V
VHD from Microsoft 14 Vim::find_entity_views 36 Vim::get_inventory_path 36 virtual disk manager (vmware-vdiskmanager) 10 VirtualCenter and ESX Server 14 Visual Studio 13 VixDiscoveryProc 36 VIXDISKLIB_ADAPTER_IDE 17, 32 VIXDISKLIB_ADAPTER_SCSI_BUSLOGIC 17, 32 VIXDISKLIB_ADAPTER_SCSI_LSILOGIC 17 VixDiskLib_Attach 12, 22, 28, 35 VixDiskLib_Clone 12, 20, 23, 29, 33 VixDiskLib_Close 12, 19, 27 VixDiskLib_Connect 12, 18, 23, 27, 29, 34 VixDiskLib_Create 12, 18, 23, 28, 32, 33, 35
43
L
Linux installation 14 localization (l10n) 17
M
managed disk 9, 11, 15, 18, 23, 29, 33, 41 monolithic VMDK 15, 16, 21, 28, 29, 32, 41 MONOLITHIC_FLAT 15, 16 MONOLITHIC_SPARSE 15, 16
N
nonpersistent disk mode 16
VMware, Inc.
Title
VixDiskLib_CreateChild 12, 21, 22, 28 VIXDISKLIB_CRED_UID 34 VixDiskLib_Defragment 12, 20, 23 VixDiskLib_Disconnect 12, 22 VIXDISKLIB_DISK_SPLIT_SPARSE 32 VixDiskLib_Exit 12, 22 VixDiskLib_FreeErrorText 12, 19 VixDiskLib_FreeInfo 12, 19, 28 VixDiskLib_GetErrorText 12, 19 VixDiskLib_GetInfo 12, 19, 28, 31, 32 VixDiskLib_GetMetadataKeys 12, 19, 29 VixDiskLib_Grow 12, 20, 23 VixDiskLib_Init 12, 18, 27, 34, 36 VixDiskLib_Open 12, 18, 27 VixDiskLib_Read 12, 18, 29, 31, 32, 33 VixDiskLib_ReadMetadata 12, 19, 28, 29 VixDiskLib_Rename 12, 20, 34 VIXDISKLIB_SECTOR_SIZE 19, 31, 33 VixDiskLib_Shrink 12, 20 VixDiskLib_SpaceNeededForClone 12, 20 VixDiskLib_Unlink 12, 21, 34 VixDiskLib_Write 12, 19, 20, 28, 33 VixDiskLib_WriteMetadata 12, 20, 29 VixHost_Connect 36 VixHost_FindItems 36 VMDK (virtual machine disk) file 9, 10, 11, 14, 15, 19, 28, 29, 31, 32, 33, 34, 36 VMFS_FLAT 15, 33 VMFS_SPARSE 15 VMX specification (vmxSpec) 27
W
walk-through of sample program 26 Windows installation 14
44
VMware, Inc.