mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-23 14:08:31 +00:00
qemu: Update blockdev-add qmp command to support newer qemu versions
With qemu 2.9, the qmp block-dev command was updated from: { "execute": "blockdev-add", "arguments": { "options": { ... } } } to: { "execute": "blockdev-add", "arguments": { ... } } Also, instead of id, blockdev-add now requires a node-name for the root node(https://wiki.qemu.org/index.php/ChangeLog/2.9) Store the version information with QMPStart and use that to issue qmp command for adding block devices in the correct format. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
d4f77103be
commit
25a2dc8f6e
34
qmp.go
34
qmp.go
@ -127,6 +127,7 @@ type QMP struct {
|
|||||||
cfg QMPConfig
|
cfg QMPConfig
|
||||||
connectedCh chan<- *QMPVersion
|
connectedCh chan<- *QMPVersion
|
||||||
disconnectedCh chan struct{}
|
disconnectedCh chan struct{}
|
||||||
|
version *QMPVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// QMPVersion contains the version number and the capabailities of a QEMU
|
// QMPVersion contains the version number and the capabailities of a QEMU
|
||||||
@ -533,7 +534,6 @@ func QMPStart(ctx context.Context, socket string, cfg QMPConfig, disconnectedCh
|
|||||||
|
|
||||||
connectedCh := make(chan *QMPVersion)
|
connectedCh := make(chan *QMPVersion)
|
||||||
|
|
||||||
var version *QMPVersion
|
|
||||||
q := startQMPLoop(conn, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(conn, cfg, connectedCh, disconnectedCh)
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@ -542,13 +542,13 @@ func QMPStart(ctx context.Context, socket string, cfg QMPConfig, disconnectedCh
|
|||||||
return nil, nil, fmt.Errorf("Canceled by caller")
|
return nil, nil, fmt.Errorf("Canceled by caller")
|
||||||
case <-disconnectedCh:
|
case <-disconnectedCh:
|
||||||
return nil, nil, fmt.Errorf("Lost connection to VM")
|
return nil, nil, fmt.Errorf("Lost connection to VM")
|
||||||
case version = <-connectedCh:
|
case q.version = <-connectedCh:
|
||||||
if version == nil {
|
if q.version == nil {
|
||||||
return nil, nil, fmt.Errorf("Failed to find QMP version information")
|
return nil, nil, fmt.Errorf("Failed to find QMP version information")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return q, version, nil
|
return q, q.version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown closes the domain socket used to monitor a QEMU instance and
|
// Shutdown closes the domain socket used to monitor a QEMU instance and
|
||||||
@ -602,16 +602,26 @@ func (q *QMP) ExecuteQuit(ctx context.Context) error {
|
|||||||
// used to name the device. As this identifier will be passed directly to QMP,
|
// used to name the device. As this identifier will be passed directly to QMP,
|
||||||
// it must obey QMP's naming rules, e,g., it must start with a letter.
|
// it must obey QMP's naming rules, e,g., it must start with a letter.
|
||||||
func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID string) error {
|
func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID string) error {
|
||||||
args := map[string]interface{}{
|
var args map[string]interface{}
|
||||||
"options": map[string]interface{}{
|
|
||||||
"driver": "raw",
|
blockdevArgs := map[string]interface{}{
|
||||||
"file": map[string]interface{}{
|
"driver": "raw",
|
||||||
"driver": "file",
|
"file": map[string]interface{}{
|
||||||
"filename": device,
|
"driver": "file",
|
||||||
},
|
"filename": device,
|
||||||
"id": blockdevID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 9) {
|
||||||
|
blockdevArgs["node-name"] = blockdevID
|
||||||
|
args = blockdevArgs
|
||||||
|
} else {
|
||||||
|
blockdevArgs["id"] = blockdevID
|
||||||
|
args = map[string]interface{}{
|
||||||
|
"options": blockdevArgs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return q.executeCommand(ctx, "blockdev-add", args, nil)
|
return q.executeCommand(ctx, "blockdev-add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ func (b *qmpTestCommandBuffer) Write(p []byte) (int, error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkVersion(t *testing.T, connectedCh <-chan *QMPVersion) {
|
func checkVersion(t *testing.T, connectedCh <-chan *QMPVersion) *QMPVersion {
|
||||||
var version *QMPVersion
|
var version *QMPVersion
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
@ -233,6 +233,8 @@ func checkVersion(t *testing.T, connectedCh <-chan *QMPVersion) {
|
|||||||
t.Fatal("Invalid capabilities")
|
t.Fatal("Invalid capabilities")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that a QMP Loop can be started and shutdown.
|
// Checks that a QMP Loop can be started and shutdown.
|
||||||
@ -356,7 +358,7 @@ func TestQMPBlockdevAdd(t *testing.T) {
|
|||||||
buf.AddCommand("blockdev-add", nil, "return", nil)
|
buf.AddCommand("blockdev-add", nil, "return", nil)
|
||||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
checkVersion(t, connectedCh)
|
q.version = checkVersion(t, connectedCh)
|
||||||
err := q.ExecuteBlockdevAdd(context.Background(), "/dev/rbd0",
|
err := q.ExecuteBlockdevAdd(context.Background(), "/dev/rbd0",
|
||||||
fmt.Sprintf("drive_%s", testutil.VolumeUUID))
|
fmt.Sprintf("drive_%s", testutil.VolumeUUID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user