@@ -248,7 +248,63 @@ func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo
248248		}
249249	}
250250
251- 	newDiskAddSession (ctx , qc , filename , format , id , readonly , result )
251+ 	commands  :=  make ([]* QmpCommand , 2 )
252+ 	devName  :=  scsiId2Name (id )
253+ 	if  ! blockInfo .Dax  {
254+ 		hmp  :=  "drive_add dummy file="  +  filename  +  ",if=none,id="  +  "drive"  +  strconv .Itoa (id ) +  ",format="  +  format  +  ",cache=writeback" 
255+ 		if  readonly  {
256+ 			hmp  +=  ",readonly" 
257+ 		}
258+ 		commands [0 ] =  & QmpCommand {
259+ 			Execute : "human-monitor-command" ,
260+ 			Arguments : map [string ]interface {}{
261+ 				"command-line" : hmp ,
262+ 			},
263+ 		}
264+ 		commands [1 ] =  & QmpCommand {
265+ 			Execute : "device_add" ,
266+ 			Arguments : map [string ]interface {}{
267+ 				"driver" : "scsi-hd" , "bus" : "scsi0.0" , "scsi-id" : strconv .Itoa (id ),
268+ 				"drive" : "drive"  +  strconv .Itoa (id ), "id" : "scsi-disk"  +  strconv .Itoa (id ),
269+ 			},
270+ 		}
271+ 	} else  {
272+ 		// compose qmp commands 
273+ 		// hmp: object_add memory-backend-file,id=mem2,share=on,mem-path=/path/to/dax.img,size=10G 
274+ 		// hmp: device_add nvdimm,id=nvdimm2,memdev=mem2 
275+ 		hmp  :=  "object_add memory-backend-file,id=mem"  +  strconv .Itoa (blockInfo .PmemId ) +  ",mem-path="  +  filename 
276+ 		if  readonly  {
277+ 			hmp  +=  ",share=off" 
278+ 		} else  {
279+ 			hmp  +=  ",share=on" 
280+ 		}
281+ 		// get the size 
282+ 		fi , e  :=  os .Stat (filename )
283+ 		if  e  !=  nil  {
284+ 			result  <-  & hypervisor.DeviceFailed {}
285+ 			return 
286+ 		}
287+ 		hmp  +=  ",size="  +  strconv .FormatInt (fi .Size (), 10 )
288+ 		commands [0 ] =  & QmpCommand {
289+ 			Execute : "human-monitor-command" ,
290+ 			Arguments : map [string ]interface {}{
291+ 				"command-line" : hmp ,
292+ 			},
293+ 		}
294+ 		commands [1 ] =  & QmpCommand {
295+ 			Execute : "device_add" ,
296+ 			Arguments : map [string ]interface {}{
297+ 				"driver" : "nvdimm" , "memdev" : "mem"  +  strconv .Itoa (blockInfo .PmemId ), "id" : "nvdimm"  +  strconv .Itoa (blockInfo .PmemId ),
298+ 			},
299+ 		}
300+ 		devName  =  "pmem"  +  strconv .Itoa (blockInfo .PmemId )
301+ 	}
302+ 	qc .qmp  <-  & QmpSession {
303+ 		commands : commands ,
304+ 		respond : defaultRespond (result , & hypervisor.BlockdevInsertedEvent {
305+ 			DeviceName : devName ,
306+ 		}),
307+ 	}
252308}
253309
254310func  (qc  * QemuContext ) RemoveDisk (ctx  * hypervisor.VmContext , blockInfo  * hypervisor.DiskDescriptor , callback  hypervisor.VmEvent , result  chan <-  hypervisor.VmEvent ) {
0 commit comments