From f1829d078ac966f62a5feb8303e63f5c09247ff0 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Mon, 10 Sep 2018 13:27:20 -0500 Subject: [PATCH] vendor: Update govmm Changes: - qemu/qmp: support query-memory-devices qmp command. - qemu: Add virtio RNG device. Signed-off-by: Jose Carlos Venegas Munoz --- Gopkg.lock | 4 +- Gopkg.toml | 2 +- vendor/github.com/intel/govmm/qemu/qemu.go | 60 ++++++++++++++++++++++ vendor/github.com/intel/govmm/qemu/qmp.go | 40 +++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 083f6c9f0d..dad0bb45d9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -123,11 +123,11 @@ revision = "3520598351bb3500a49ae9563f5539666ae0a27c" [[projects]] - digest = "1:052c0d6d677c7a3f12d8f83e0a1ce20a896cc206782b035f380249d23bf1265d" + digest = "1:7434a85a1d6c2bf64f322087ec7a7f84ab9e971179bef7b95deabaf0e3f7c126" name = "github.com/intel/govmm" packages = ["qemu"] pruneopts = "NUT" - revision = "1a16b5f98f133796f9c5e9b6ae3aa6d786cff9b1" + revision = "e2c716433e444017507e3587ce071868fd164380" [[projects]] digest = "1:01c37fcb6e2a1fe1321a97faaef74c66ac531ea292ca3f929b7189cc400b1d47" diff --git a/Gopkg.toml b/Gopkg.toml index 792aff599c..5491364d24 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -52,7 +52,7 @@ [[constraint]] name = "github.com/intel/govmm" - revision = "1a16b5f98f133796f9c5e9b6ae3aa6d786cff9b1" + revision = "e2c716433e444017507e3587ce071868fd164380" [[constraint]] name = "github.com/kata-containers/agent" diff --git a/vendor/github.com/intel/govmm/qemu/qemu.go b/vendor/github.com/intel/govmm/qemu/qemu.go index d2f27f51dc..c883de53a3 100644 --- a/vendor/github.com/intel/govmm/qemu/qemu.go +++ b/vendor/github.com/intel/govmm/qemu/qemu.go @@ -85,6 +85,9 @@ const ( // VHostVSockPCI is the vhost vsock pci driver. VHostVSockPCI DeviceDriver = "vhost-vsock-pci" + + // VirtioRng is the paravirtualized RNG device driver. + VirtioRng DeviceDriver = "virtio-rng" ) // ObjectType is a string representing a qemu object type. @@ -1017,6 +1020,63 @@ func (vsock VSOCKDevice) QemuParams(config *Config) []string { return qemuParams } +// RngDevice represents a random number generator device. +type RngDevice struct { + // ID is the device ID + ID string + // Filename is entropy source on the host + Filename string + // MaxBytes is the bytes allowed to guest to get from the host’s entropy per period + MaxBytes uint + // Period is duration of a read period in seconds + Period uint +} + +// Valid returns true if the RngDevice structure is valid and complete. +func (v RngDevice) Valid() bool { + if v.ID == "" { + return false + } + + return true +} + +// QemuParams returns the qemu parameters built out of the RngDevice. +func (v RngDevice) QemuParams(_ *Config) []string { + var qemuParams []string + + //-object rng-random,filename=/dev/hwrng,id=rng0 + var objectParams []string + //-device virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000 + var deviceParams []string + + objectParams = append(objectParams, "rng-random") + objectParams = append(objectParams, "id="+v.ID) + + deviceParams = append(deviceParams, string(VirtioRng)) + deviceParams = append(deviceParams, "rng="+v.ID) + + if v.Filename != "" { + objectParams = append(objectParams, "filename="+v.Filename) + } + + if v.MaxBytes > 0 { + deviceParams = append(deviceParams, fmt.Sprintf("max-bytes=%d", v.MaxBytes)) + } + + if v.Period > 0 { + deviceParams = append(deviceParams, fmt.Sprintf("period=%d", v.Period)) + } + + qemuParams = append(qemuParams, "-object") + qemuParams = append(qemuParams, strings.Join(objectParams, ",")) + + qemuParams = append(qemuParams, "-device") + qemuParams = append(qemuParams, strings.Join(deviceParams, ",")) + + return qemuParams +} + // RTCBaseType is the qemu RTC base time type. type RTCBaseType string diff --git a/vendor/github.com/intel/govmm/qemu/qmp.go b/vendor/github.com/intel/govmm/qemu/qmp.go index 58b8924fda..addf4b2fa6 100644 --- a/vendor/github.com/intel/govmm/qemu/qmp.go +++ b/vendor/github.com/intel/govmm/qemu/qmp.go @@ -160,6 +160,24 @@ type HotpluggableCPU struct { QOMPath string `json:"qom-path"` } +// MemoryDevicesData cotains the data describes a memory device +type MemoryDevicesData struct { + Slot int `json:"slot"` + Node int `json:"node"` + Addr uint64 `json:"addr"` + Memdev string `json:"memdev"` + ID string `json:"id"` + Hotpluggable bool `json:"hotpluggable"` + Hotplugged bool `json:"hotplugged"` + Size uint64 `json:"size"` +} + +// MemoryDevices represents memory devices of vm +type MemoryDevices struct { + Data MemoryDevicesData `json:"data"` + Type string `json:"type"` +} + func (q *QMP) readLoop(fromVMCh chan<- []byte) { scanner := bufio.NewScanner(q.conn) for scanner.Scan() { @@ -989,6 +1007,28 @@ func (q *QMP) ExecSetMigrateArguments(ctx context.Context, url string) error { return q.executeCommand(ctx, "migrate", args, nil) } +// ExecQueryMemoryDevices returns a slice with the list of memory devices +func (q *QMP) ExecQueryMemoryDevices(ctx context.Context) ([]MemoryDevices, error) { + response, err := q.executeCommandWithResponse(ctx, "query-memory-devices", nil, nil, nil) + if err != nil { + return nil, err + } + + // convert response to json + data, err := json.Marshal(response) + if err != nil { + return nil, fmt.Errorf("Unable to extract memory devices information: %v", err) + } + + var memoryDevices []MemoryDevices + // convert json to []MemoryDevices + if err = json.Unmarshal(data, &memoryDevices); err != nil { + return nil, fmt.Errorf("unable to convert json to memory devices: %v", err) + } + + return memoryDevices, nil +} + // ExecHotplugMemory adds size of MiB memory to the guest func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string, size int) error { args := map[string]interface{}{