From ffc06e6bc40eed80e80646fcf16be6efa4807024 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Thu, 28 Jun 2018 15:11:13 +0100 Subject: [PATCH 1/3] qemu,qmp: Add staticcheck to travis and fix errors This commit enables staticcheck in the travis builds and fixes the existing errors detected by staticcheck. There was one type of error repeated in qemu.go in which the type of some constants was not explicitly specified. Signed-off-by: Mark Ryan --- .travis.yml | 2 +- qemu/qemu.go | 56 +++++++++++++++++++++++++++------------------------- qemu/qmp.go | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03a39421f..fb5bc4419 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,4 @@ before_install: script: - go env - $GOPATH/bin/goveralls -v -service=travis-ci - - gometalinter --tests --vendor --disable-all --enable=misspell --enable=vet --enable=ineffassign --enable=gofmt --enable=gocyclo --cyclo-over=15 --enable=golint --enable=errcheck --enable=deadcode ./... + - gometalinter --tests --vendor --disable-all --enable=misspell --enable=vet --enable=ineffassign --enable=gofmt --enable=gocyclo --cyclo-over=15 --enable=golint --enable=errcheck --enable=deadcode --enable=staticcheck ./... diff --git a/qemu/qemu.go b/qemu/qemu.go index 41381d80e..831608af3 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -63,25 +63,25 @@ const ( NVDIMM DeviceDriver = "nvdimm" // Virtio9P is the 9pfs device driver. - Virtio9P = "virtio-9p-pci" + Virtio9P DeviceDriver = "virtio-9p-pci" // VirtioNet is the virt-io networking device driver. - VirtioNet = "virtio-net" + VirtioNet DeviceDriver = "virtio-net" // VirtioNetPCI is the virt-io pci networking device driver. - VirtioNetPCI = "virtio-net-pci" + VirtioNetPCI DeviceDriver = "virtio-net-pci" // VirtioSerial is the serial device driver. - VirtioSerial = "virtio-serial-pci" + VirtioSerial DeviceDriver = "virtio-serial-pci" // VirtioBlock is the block device driver. - VirtioBlock = "virtio-blk" + VirtioBlock DeviceDriver = "virtio-blk" // Console is the console device driver. - Console = "virtconsole" + Console DeviceDriver = "virtconsole" // VirtioSerialPort is the serial port device driver. - VirtioSerialPort = "virtserialport" + VirtioSerialPort DeviceDriver = "virtserialport" ) // ObjectType is a string representing a qemu object type. @@ -168,10 +168,10 @@ const ( Local FSDriver = "local" // Handle is the handle qemu filesystem driver. - Handle = "handle" + Handle FSDriver = "handle" // Proxy is the proxy qemu filesystem driver. - Proxy = "proxy" + Proxy FSDriver = "proxy" ) const ( @@ -179,13 +179,13 @@ const ( None SecurityModelType = "none" // PassThrough uses the same credentials on both the host and guest. - PassThrough = "passthrough" + PassThrough SecurityModelType = "passthrough" // MappedXattr stores some files attributes as extended attributes. - MappedXattr = "mapped-xattr" + MappedXattr SecurityModelType = "mapped-xattr" // MappedFile stores some files attributes in the .virtfs directory. - MappedFile = "mapped-file" + MappedFile SecurityModelType = "mapped-file" ) // FSDevice represents a qemu filesystem configuration. @@ -256,19 +256,19 @@ const ( Pipe CharDeviceBackend = "pipe" // Socket creates a 2 way stream socket (TCP or Unix). - Socket = "socket" + Socket CharDeviceBackend = "socket" // CharConsole sends traffic from the guest to QEMU's standard output. - CharConsole = "console" + CharConsole CharDeviceBackend = "console" // Serial sends traffic from the guest to a serial device on the host. - Serial = "serial" + Serial CharDeviceBackend = "serial" // TTY is an alias for Serial. - TTY = "tty" + TTY CharDeviceBackend = "tty" // PTY creates a new pseudo-terminal on the host and connect to it. - PTY = "pty" + PTY CharDeviceBackend = "pty" ) // CharDevice represents a qemu character device. @@ -345,19 +345,19 @@ const ( TAP NetDeviceType = "tap" // MACVTAP is a macvtap networking device type. - MACVTAP = "macvtap" + MACVTAP NetDeviceType = "macvtap" // IPVTAP is a ipvtap virtual networking device type. - IPVTAP = "ipvtap" + IPVTAP NetDeviceType = "ipvtap" // VETHTAP is a veth-tap virtual networking device type. - VETHTAP = "vethtap" + VETHTAP NetDeviceType = "vethtap" // VFIO is a direct assigned PCI device or PCI VF - VFIO = "VFIO" + VFIO NetDeviceType = "VFIO" // VHOSTUSER is a vhost-user port (socket) - VHOSTUSER = "vhostuser" + VHOSTUSER NetDeviceType = "vhostuser" ) // QemuNetdevParam converts to the QEMU -netdev parameter notation @@ -634,7 +634,7 @@ const ( NoInterface BlockDeviceInterface = "none" // SCSI represents a SCSI block device interface. - SCSI = "scsi" + SCSI BlockDeviceInterface = "scsi" ) const ( @@ -642,7 +642,7 @@ const ( Threads BlockDeviceAIO = "threads" // Native is the pthread asynchronous I/O implementation. - Native = "native" + Native BlockDeviceAIO = "native" ) const ( @@ -967,7 +967,9 @@ type VSOCKDevice struct { const ( // MinimalGuestCID is the smallest valid context ID for a guest. MinimalGuestCID uint32 = 3 +) +const ( // VhostVSOCKPCI is the VSOCK vhost device type. VhostVSOCKPCI = "vhost-vsock-pci" @@ -1010,7 +1012,7 @@ const ( UTC RTCBaseType = "utc" // LocalTime is the local base time for qemu RTC. - LocalTime = "localtime" + LocalTime RTCBaseType = "localtime" ) const ( @@ -1018,7 +1020,7 @@ const ( Host RTCClock = "host" // VM is for using the guest clock as a reference - VM = "vm" + VM RTCClock = "vm" ) const ( @@ -1026,7 +1028,7 @@ const ( Slew RTCDriftFix = "slew" // NoDriftFix means we don't want/need to fix qemu's RTC drift. - NoDriftFix = "none" + NoDriftFix RTCDriftFix = "none" ) // RTC represents a qemu Real Time Clock configuration. diff --git a/qemu/qmp.go b/qemu/qmp.go index 37334e99e..814a7dd50 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -415,7 +415,7 @@ func (q *QMP) mainLoop() { close(q.disconnectedCh) }() - version := []byte{} + var version []byte var cmdDoneCh <-chan struct{} DONE: From 430e72c63b835038a7471e9d909f5b68faad173d Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Thu, 28 Jun 2018 15:56:27 +0100 Subject: [PATCH 2/3] qemu,qmp: Enable gas security checker This commit enables the gas security checker on govmm builds. The security checker has signalled 4 issues all of which I've checked and have determined to be non issues. These issues are disabled by this commit. Signed-off-by: Mark Ryan --- .travis.yml | 2 +- qemu/image.go | 2 ++ qemu/qemu.go | 1 + qemu/qmp.go | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fb5bc4419..f23679412 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,4 @@ before_install: script: - go env - $GOPATH/bin/goveralls -v -service=travis-ci - - gometalinter --tests --vendor --disable-all --enable=misspell --enable=vet --enable=ineffassign --enable=gofmt --enable=gocyclo --cyclo-over=15 --enable=golint --enable=errcheck --enable=deadcode --enable=staticcheck ./... + - gometalinter --tests --vendor --disable-all --enable=misspell --enable=vet --enable=ineffassign --enable=gofmt --enable=gocyclo --cyclo-over=15 --enable=golint --enable=errcheck --enable=deadcode --enable=staticcheck -enable=gas ./... diff --git a/qemu/image.go b/qemu/image.go index 4f064c681..352659adb 100644 --- a/qemu/image.go +++ b/qemu/image.go @@ -45,9 +45,11 @@ func CreateCloudInitISO(ctx context.Context, scratchDir, isoPath string, userDataPath := path.Join(dataDirPath, "user_data") defer func() { + /* #nosec */ _ = os.RemoveAll(configDrivePath) }() + /* #nosec */ err := os.MkdirAll(dataDirPath, 0755) if err != nil { return fmt.Errorf("Unable to create config drive directory %s : %v", diff --git a/qemu/qemu.go b/qemu/qemu.go index 831608af3..d14661094 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -1652,6 +1652,7 @@ func LaunchCustomQemu(ctx context.Context, path string, params []string, fds []* path = "qemu-system-x86_64" } + /* #nosec */ cmd := exec.Command(path, params...) if len(fds) > 0 { logger.Infof("Adding extra file %v", fds) diff --git a/qemu/qmp.go b/qemu/qmp.go index 814a7dd50..a66ef2930 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -409,6 +409,7 @@ func (q *QMP) mainLoop() { if q.cfg.EventCh != nil { close(q.cfg.EventCh) } + /* #nosec */ _ = q.conn.Close() _ = <-fromVMCh failOutstandingCommands(cmdQueue) From 4ca232ecdf15216bb26484911b54f434dd6d09cc Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Thu, 28 Jun 2018 16:05:00 +0100 Subject: [PATCH 3/3] qmp_test: Fix Warning and Error level logs This commit fixes an issue with the log handlers defined by qmp_test. The issue was picked up by the latest version of go vet on go tip. qemu/qmp_test.go:56::error: missing ... in args forwarded to printf-like function (vet) qemu/qmp_test.go:60::error: missing ... in args forwarded to printf-like function (vet) Signed-off-by: Mark Ryan --- qemu/qmp_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index f5b472d74..2abb196c0 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -53,11 +53,11 @@ func (l qmpTestLogger) Infof(format string, v ...interface{}) { } func (l qmpTestLogger) Warningf(format string, v ...interface{}) { - l.Infof(format, v) + l.Infof(format, v...) } func (l qmpTestLogger) Errorf(format string, v ...interface{}) { - l.Infof(format, v) + l.Infof(format, v...) } type qmpTestCommand struct {