qmp: Update block device deletion for newer versions of qemu

blockdev-del command has been added in qemu 2.9 to replace
x-blockdev-del command used earlier for deleting block devices.
Update ExecuteXBlockdevDel() to use this updated qmp command.

Rename ExecuteXBlockdevDel to ExecuteBlockdevDel as this no longer
executes x-block-del command for qemu>=2.9.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2017-08-30 10:56:07 -07:00
parent e74aeef1ad
commit 1fbe6c5d1d
2 changed files with 12 additions and 6 deletions

14
qmp.go
View File

@ -642,13 +642,19 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b
return q.executeCommand(ctx, "device_add", args, nil)
}
// ExecuteXBlockdevDel deletes a block device by sending a x-blockdev-del command.
// ExecuteBlockdevDel deletes a block device by sending a x-blockdev-del command
// for qemu versions < 2.9. It sends the updated blockdev-del command for qemu>=2.9.
// blockdevID is the id of the block device to be deleted. Typically, this will
// match the id passed to ExecuteBlockdevAdd. It must be a valid QMP id.
func (q *QMP) ExecuteXBlockdevDel(ctx context.Context, blockdevID string) error {
args := map[string]interface{}{
"id": blockdevID,
func (q *QMP) ExecuteBlockdevDel(ctx context.Context, blockdevID string) error {
args := map[string]interface{}{}
if q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 9) {
args["node-name"] = blockdevID
return q.executeCommand(ctx, "blockdev-del", args, nil)
}
args["id"] = blockdevID
return q.executeCommand(ctx, "x-blockdev-del", args, nil)
}

View File

@ -406,8 +406,8 @@ func TestQMPXBlockdevDel(t *testing.T) {
buf.AddCommand("x-blockdev-del", nil, "return", nil)
cfg := QMPConfig{Logger: qmpTestLogger{}}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
checkVersion(t, connectedCh)
err := q.ExecuteXBlockdevDel(context.Background(),
q.version = checkVersion(t, connectedCh)
err := q.ExecuteBlockdevDel(context.Background(),
fmt.Sprintf("drive_%s", testutil.VolumeUUID))
if err != nil {
t.Fatalf("Unexpected error %v", err)