Hi,
Is there a com library available for the VDDK SDK? VMware did that for the VixSDK afaik.
I am currently coding .NET. If there is no .NET wrapper for VDDK, does anybody have any recommendations on how to implement communication between C and .NET programs!?
Tos2k
Take a look at http://communities.vmware.com/docs/DOC-9510.
What functionality are you looking for?
Take a look at http://communities.vmware.com/docs/DOC-9510.
What functionality are you looking for?
Thanks for your reply. Cant you describe what funtions are implemented and what is not? There is no documentation around that wrapper, but I found connect and disklib_read functions, which is what I basically was looking for.
Is it correct that I can do a connect to an ESX and do some reads and writes to unlocked vmdk files from .NET with the wrapper you provided?
Thx.
Tos2k
This is the 1.0 VDDK wrapper, also take a look at _native.vb. Any incomplete p/invokes marked with "n/a" are incomplete.
Yes you should be able to do that on a remote ESX. module1.vb of vddkNativeTest project is actually set up to connect to an ESXi server.
What are you trying to read and write?
Hi!
Thanks for your help. I have not been using the wrapper actively yet, but I will soon.
I want to read and write changes in vmdk files.
Tos2k
Just random stream changes?
Changes between copies, not to say for backup purposes...
Tos2k
Hi!
To connect to an ESX host, do I need ConnectEx then? Could not find that function in the wrapper. I just thought that Connect wont do it?
Tos2k
With 1.1 you might have to , I think some things have changed. I can help with p/invoke if you want. What is the connect sequence with 1.1?
So why not do a bindiff on the two VMDK files at the the host level?
Looks like you should be ok with just Connect.
http://www.vmware.com/support/developer/vddk/vddk11_api_programming.pdf
List Available Transport Methods
The VixDiskLib_ListTransportModes() function returns the currently supported transport methods as a
colon‐separated string value, currently “file:san:hotadd:nbd” where nbd indicates LAN transport. When
available, SSL encrypted NBD transport is shown as nbdssl.
printf("Transport methods: %s\n", VixDiskLib_ListTransportModes());
The default transport priority over the network is san:hotadd:nbdssl:nbd assuming all are available.
Updating Applications for Advanced Transport
To update your applications for advanced transport, follow these steps:
1 Find all instances of VixDiskLib_Connect().
2 Except for instances specific to hosted disk, change all these to VixDiskLib_ConnectEx().
3 Likewise, change VixDiskLib_Init() to VixDiskLib_InitEx() and be sure you call it only once.
4 Add parameters in the middle:
a TRUE for high performance read‐only access, FALSE for read/write access.
b Snapshot MoRef, if applicable.
c NULL to accept transport method defaults (recommended).
5 Find VixDiskLib_Disconnect() near the end of program, and for safety add a VixDiskLib_Cleanup()
call immediately afterwards.
6 Compile with the new flexible‐transport‐enabled version of VixDiskLib.
Thanks for your investigations!!
Cant you please post a sample .NET code snippet using your wrapper that shows how to use that correctly?
what I have so long is:
VddkWrapper._native.VixDiskLibGenericLogFunc loginfo, logwarn, logpanic; loginfo = new VddkWrapper._native.VixDiskLibGenericLogFunc(); logwarn = new VddkWrapper._native.VixDiskLibGenericLogFunc(); logpanic = new VddkWrapper._native.VixDiskLibGenericLogFunc(); VddkWrapper._native.VixDiskLib_Init(VddkWrapper._native.VIXDISKLIB_VERSION_MAJOR, VddkWrapper._native.VIXDISKLIB_VERSION_MINOR, loginfo, logwarn, logpanic, "C:\\Program Files\\VMware\\VMware Virtual Disk Development Kit"); VddkWrapper._native.VixDiskLibConnectParams parms = new VddkWrapper._native.VixDiskLibConnectParams(); parms.creds = new VddkWrapper._native.VixDiskLibCreds(); parms.creds.uid.userName = "<user>"; parms.creds.uid.password = "<pass>"; parms.serverName = "<esx>"; IntPtr conn = new IntPtr(); VddkWrapper._native.VixDiskLib_Connect(ref parms, ref conn);
I have no clue on how to:
1) override the log methods
2) how to prepare the connect params, when trying to read an vmdk file on an ESX
3) I have no clue on how to handle connections
4) in addition i get the following error at where I do the Init call:
Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at VddkWrapper._native.VixDiskLib_Init(UInt32 majorVersion, UInt32 minorVersi on, VixDiskLibGenericLogFunc logInfo, VixDiskLibGenericLogFunc logWarn, VixDiskL ibGenericLogFunc logPanic, String libDir) at DeltaTest.Program.Main(String[] args) in C:\tomato\DeltaTest\Program.cs:li ne 19 C:\tomato\DeltaTest\bin\Debug>
after copying vixDiskLib.dll in my app dir.
Thanks, Tos2k
Don't worry about the log methods for now, the needed callbacks are not implemented in the wrapper. First of all, all contents of "C:\program files\Vmware\VMware Virtual Disk Development Kit\lib" need to be copied over to your "application\bin\Debug" folder and not just the one DLL.
Also, when you specify the VixDiskLibConnectParams.Servername, use the server's IP address or FQDN (esx.mydomain.com). For some reason hostnames do not work well with vmware's sdks. Also, specify VixDiskLibConnectParams.port = 443.
Starting with the VixDiskLib_Connect function you're working with pointers:
Dim connPtr As IntPtr = Marshal.AllocHGlobal(8) Dim diskPtr As IntPtr = Marshal.AllocHGlobal(8)
Above code allocates unmanaged memory for use with your managed code (.NET).
So,
VixDiskLib_Connect(cnxParamsUID, connPtr)
should return a non-null IntPtr (connPtr), so should VixDiskLib_Open.
A VMDK file on a remote ESX is defined with "[datastore_name] path/to/vm.vmdk"
In your debugging make sure you test for any VIX Errors returned by the Connect or Open functions and call VixDiskLib_Close(diskPtr) and VixDiskLib_Disconnect(connPtr). Or wrap your code in a try/catch and finally try to Close and Disconnect when your code fails.
Try again with the vddkNativeTest project code... Let's see if you can successfully connect to ESX first. Post the returned values of _Init and _Connect if it keeps failing.
This should work to connect:
Dim err As Integer = 0 Dim connPtr As IntPtr = Marshal.AllocHGlobal(8) Dim diskPtr As IntPtr = Marshal.AllocHGlobal(8) try Dim currentDisk As String = "[datastore1] VM2/VM2.vmdk" err = VixDiskLib_Init(1, 0, Nothing, Nothing, Nothing, Nothing) Dim cnxParamsUID As New VixDiskLibConnectParams cnxParamsUID.serverName = "server IP or FQDN here" cnxParamsUID.credType = VixDiskLibCredType.VIXDISKLIB_CRED_UID cnxParamsUID.creds.uid.userName = "user" cnxParamsUID.creds.uid.password = "pass" cnxParamsUID.port = 443 err = VixDiskLib_Connect(cnxParamsUID, connPtr) catch ex as exception try err = VixDiskLib_Disconnect(connPtr) catch ex1 as exception end try end try
I really hope you can help me to get me up and running on that
VddkWrapper._native.VixDiskLibGenericLogFunc loginfo, logwarn, logpanic; loginfo = new VddkWrapper._native.VixDiskLibGenericLogFunc(); logwarn = new VddkWrapper._native.VixDiskLibGenericLogFunc(); logpanic = new VddkWrapper._native.VixDiskLibGenericLogFunc(); VddkWrapper._native.VixDiskLib_Init(1,0, loginfo, logwarn, logpanic, null); VddkWrapper._native.VixDiskLibConnectParams parms = new VddkWrapper._native.VixDiskLibConnectParams(); parms.creds = new VddkWrapper._native.VixDiskLibCreds(); parms.credType = uint.Parse(VddkWrapper._native.VixDiskLibCredType.VIXDISKLIB_CRED_UID.ToString()); parms.creds.uid.userName = "<usr>"; parms.creds.uid.password = "<pass>"; parms.serverName = "<ESXip>"; IntPtr conn = System.Runtime.InteropServices.Marshal.AllocHGlobal(8); IntPtr disk = System.Runtime.InteropServices.Marshal.AllocHGlobal(8); VddkWrapper._native.VixDiskLib_Connect(ref parms, ref conn);
For VixDiskLib_Init it is not allowed to pass "null"... Maybe some wrapper issues?
Line parms.credType = uint.Parse(VddkWrapper._native.VixDiskLibCredType.VIXDISKLIB_CRED_UID.ToString()); seems to suffer from wrapper issues too!?
Error is still the same:
Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at VddkWrapper._native.VixDiskLib_Init(UInt32 majorVersion, UInt32 minorVersi on, VixDiskLibGenericLogFunc logInfo, VixDiskLibGenericLogFunc logWarn, VixDiskL ibGenericLogFunc logPanic, String libDir) at DeltaTest.Program.Main(String[] args) in C:\tomato\DeltaTest\Program.cs:li ne 19
even if I copy all stuff from "bin" dir to my app dir... I can upload my whole app dir, if you like!?
Tos2k
I am playing around with the sample provided from you: vddkNativeTest
it comes up with the same error here for me at the VixDiskLib_Init:
C:\Tools\vddk_wrapper\bin>vddkNativeTest.exe ---start exception caught: 0 : System.BadImageFormatException: An attempt was made to l oad a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at VddkWrapper._native.VixDiskLib_Init(UInt32 majorVersion, UInt32 minorVersi on, VixDiskLibGenericLogFunc logInfo, VixDiskLibGenericLogFunc logWarn, VixDiskL ibGenericLogFunc logPanic, String libDir) at vddkNativeTest.Module1.Main() in C:\Tools\vddk_wrapper\Console\vddkNativeT est\Module1.vb:line 33 -----Finished-----
any ideas?? Are you sure I downloaded the latest version of the wrapper!? Something else that could be missing!? Running on win 7 64bit
Please help...
Tos2k
Check out http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx
Are you building the app 64bit or 32bit? Try one or the other. The nativeVDDKtest project might also have to be changed over to 64 or 32bit. Also, you are using VDDK 1.1 correct?
I wonder if the init call needs 1 for the minor version instead of 0, since we are at 1.1 now.
vddkWrapper.Dll and vddkNativeTest.exe are being compiled Any Cpu or 64bit. You're calling x86 vddk libs so that will not work. Do you see the vddk64.zip file in the vddk/bin folder? Try using the files inside of that zip file with your project.
I now ran the 64 bit version of vixDiskLib.dll an get the following error:
exception caught: 0 : System.AccessViolationException: Attempted to read or wr ite protected memory. This is often an indication that other memory is corrupt. at VddkWrapper._native.VixDiskLib_Init(UInt32 majorVersion, UInt32 minorVersi on, VixDiskLibGenericLogFunc logInfo, VixDiskLibGenericLogFunc logWarn, VixDiskL ibGenericLogFunc logPanic, String libDir) at vddkNativeTest.Module1.Main() in C:\Tools\vddk_wrapper\Console\vddkNativeT est\Module1.vb:line 33
When I ran the whole thing with 32 bit dlls on a 32bit OS things seem to work.
Tos2k
Ok, you have two options now: either modify the p/invoke signatures to work with 64 bit (e.g. int32 becomes int64, etc), or modify the vddkNativeTest and the wrapper to compile x86 and run against the 32 bit vddk dlls.
Hi.
Not that easy
modify the vddkNativeTest and the wrapper to compile x86 and run against the 32 bit vddk dlls
What exactly needs to be done? I never had any troubles to run my compiled code (different other projects) on my machine, as on other 32 bit machines!?
What will that error message say?
** INFO: TicketResolveHostName: Resolved to 192.168.73.230. ** INFO: VixDiskLibVim: TicketLogin ** INFO: VixDiskLibVim: TicketLogout [NFC ERROR] NfcNewAuthdConnectionEx: Failed to connect to peer. Error: Cannot co nnect to host 192.168.73.230: No connection could be made because the target mac hine actively refused it exception caught: 0 : System.OverflowException: Arithmetic operation resulted in an overflow. at vddkNativeTest.Module1.Main() disc 0
Tos2k