VMware {code} Community
kumars17
Contributor
Contributor

How to create a RDM disk using VI SDK?

I have a LUN from SAN visible to esx i.e. vmhba1:4:7:0, I used the code below to create the RDM disk attached to a VM using VI SDK but ti awalys fails with the error "virtual disk is either corrupted or not a supported format"

string lunuuid="0200070000600601609e212200da19c8a13681de11524149442035";

string devicename="vmhba1:4:7:0";

string dmode="persisitent";

string cmode="physicalMode";

ns2__VirtualDiskRawDiskMappingVer1BackingInfo rdmDisk;

rdmDisk.diskMode=&dmode;

rdmDisk.compatibilityMode = &cmode;

rdmDisk.lunUuid=&lunuuid;

rdmDisk.deviceName=&devicename;

rdmDisk.fileName="[storage1] lrmg200/lrmg200.vmdk";

rdmDisk.datastore=&dsRef;

bool allowGuestControl=true;

bool connected=true;

bool startconnected=true;

ns2__VirtualDeviceConnectInfo conninfo;

conninfo.allowGuestControl=allowGuestControl;

conninfo.connected=connected;

conninfo.startConnected=startconnected;

ns2__Description desc;

desc.label="Hard Disk 5";

desc.summary="abcd";

ns2__VirtualDisk newdisk;

newdisk.backing=(ns2__VirtualDiskRawDiskMappingVer1BackingInfo *)&rdmDisk;

newdisk.controllerKey=&key;

newdisk.unitNumber=&devslot;

// newdisk.connectable=&conninfo;

newdisk.key=-1;

newdisk.capacityInKB =4194304;

newdisk.deviceInfo=&desc;

ns2__VirtualDeviceConfigSpecOperation optype=ns2__VirtualDeviceConfigSpecOperation__add;

ns2__VirtualDeviceConfigSpecFileOperation fopType=ns2__VirtualDeviceConfigSpecFileOperation__create;

ns2__VirtualDeviceConfigSpec *cspec=new ns2__VirtualDeviceConfigSpec () ;

cspec->fileOperation=&fopType;

cspec->operation=&optype;

cspec->device=&newdisk;

ns2__VirtualMachineConfigSpec vmspec;

vmspec.deviceChange.push_back(cspec);

ns2__ManagedObjectReference vmRef;

vmRef.__item=vmid;

vmRef.type=&VM_NAME;

ns2__ReconfigVMRequestType addreq;

ns2_ReconfigVM_USCORETaskResponse addres;

addreq._USCOREthis=&vmRef;

addreq.spec=&vmspec;

int retCode = rmSvcConn->GetVimService()->ReconfigVM_USCORETask(&addreq, &addres);

If I go and create the backend RDM map file using vmksfstools e.g. vmkfstools --createrdmpassthru /vmfs/devices/disks/vmhba1:4:7:0 /vmfs/volumes/storage1/lrmg200/lrmg200.vmdk and comment out the line " cspec->fileOperation=&fopType;" it works fine. My problem is I don't have the privelegae to go to esx to create the passthru file first.

Shouldn't fileoperation ns2__VirtualDeviceConfigSpecFileOperation__create should create the RDM mapfile.

Reply
0 Kudos
2 Replies
storm27
Enthusiast
Enthusiast

Hi,

Refer to the below link for creating a RDM using VI SDK:

http://communities.vmware.com/message/955755#955755

Hope this helps.

-Angela-

Reply
0 Kudos
kumars17
Contributor
Contributor

I already had a look at that threa. It din't solved my problem. I think all of these sample code assume that the backing file is already created and it simply try to hot add the backing file to the VM.

Can you take a look at my sample code and see if you can figure out some thing wrong in it?

-Kumar-

Reply
0 Kudos