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