From a5a8c3d395036ad24d8db220ee2fe8fbb03549f0 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Thu, 27 Apr 2017 18:06:28 +0800 Subject: [PATCH] clean up BlockdevInsertedEvent name, source type and scsiId are all set and passed by callers. It does not make sense to simply pass them back. Signed-off-by: Peng Tao --- hypervisor/events.go | 3 --- hypervisor/libvirt/libvirt.go | 10 ++-------- hypervisor/qemu/qemu.go | 3 +-- hypervisor/qemu/qmp_test.go | 7 ++++--- hypervisor/qemu/qmp_wrapper.go | 5 +---- hypervisor/vbox/vbox.go | 6 ------ hypervisor/xen/xen.go | 8 ++------ 7 files changed, 10 insertions(+), 32 deletions(-) diff --git a/hypervisor/events.go b/hypervisor/events.go index 9ccdff16..e250d4e2 100644 --- a/hypervisor/events.go +++ b/hypervisor/events.go @@ -50,10 +50,7 @@ type VolumeUnmounted struct { } type BlockdevInsertedEvent struct { - Name string - SourceType string //image or volume DeviceName string - ScsiId int ScsiAddr string // pass scsi addr to hyperstart } diff --git a/hypervisor/libvirt/libvirt.go b/hypervisor/libvirt/libvirt.go index a143008a..71e577f9 100644 --- a/hypervisor/libvirt/libvirt.go +++ b/hypervisor/libvirt/libvirt.go @@ -907,9 +907,6 @@ func scsiId2Addr(id int) (int, int, error) { } func (lc *LibvirtContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) { - name := blockInfo.Name - id := blockInfo.ScsiId - if lc.domain == nil { glog.Error("Cannot find domain") result <- &hypervisor.DeviceFailed{ @@ -945,12 +942,9 @@ func (lc *LibvirtContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, } return } - target, unit, err := scsiId2Addr(id) + target, unit, err := scsiId2Addr(blockInfo.ScsiId) result <- &hypervisor.BlockdevInsertedEvent{ - Name: name, - SourceType: sourceType, - DeviceName: scsiId2Name(id), - ScsiId: id, + DeviceName: scsiId2Name(blockInfo.ScsiId), ScsiAddr: fmt.Sprintf("%d:%d", target, unit), } } diff --git a/hypervisor/qemu/qemu.go b/hypervisor/qemu/qemu.go index 52ce10e4..21a0a493 100644 --- a/hypervisor/qemu/qemu.go +++ b/hypervisor/qemu/qemu.go @@ -222,7 +222,6 @@ func (qc *QemuContext) Pause(ctx *hypervisor.VmContext, pause bool) error { } func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) { - name := blockInfo.Name filename := blockInfo.Filename format := blockInfo.Format id := blockInfo.ScsiId @@ -247,7 +246,7 @@ func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo } } - newDiskAddSession(ctx, qc, name, sourceType, filename, format, id, result) + newDiskAddSession(ctx, qc, filename, format, id, result) } func (qc *QemuContext) RemoveDisk(ctx *hypervisor.VmContext, blockInfo *hypervisor.DiskDescriptor, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) { diff --git a/hypervisor/qemu/qmp_test.go b/hypervisor/qemu/qmp_test.go index c5c8f706..3d41ee45 100644 --- a/hypervisor/qemu/qmp_test.go +++ b/hypervisor/qemu/qmp_test.go @@ -2,10 +2,11 @@ package qemu import ( "encoding/json" - "github.com/hyperhq/runv/hypervisor" "net" "testing" "time" + + "github.com/hyperhq/runv/hypervisor" ) func TestMessageParse(t *testing.T) { @@ -261,7 +262,7 @@ func TestQmpDiskSession(t *testing.T) { } info := msg.(*hypervisor.BlockdevInsertedEvent) - t.Log("got block device", info.Name, info.SourceType, info.DeviceName) + t.Log("got block device", info.DeviceName) } func TestQmpFailOnce(t *testing.T) { @@ -306,7 +307,7 @@ func TestQmpFailOnce(t *testing.T) { } info := msg.(*hypervisor.BlockdevInsertedEvent) - t.Log("got block device", info.Name, info.SourceType, info.DeviceName) + t.Log("got block device", info.DeviceName) } func TestQmpKeepFail(t *testing.T) { diff --git a/hypervisor/qemu/qmp_wrapper.go b/hypervisor/qemu/qmp_wrapper.go index c78f7ce3..791262d8 100644 --- a/hypervisor/qemu/qmp_wrapper.go +++ b/hypervisor/qemu/qmp_wrapper.go @@ -33,7 +33,7 @@ func defaultRespond(result chan<- hypervisor.VmEvent, callback hypervisor.VmEven } } -func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, name, sourceType, filename, format string, id int, result chan<- hypervisor.VmEvent) { +func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, filename, format string, id int, result chan<- hypervisor.VmEvent) { commands := make([]*QmpCommand, 2) commands[0] = &QmpCommand{ Execute: "human-monitor-command", @@ -53,10 +53,7 @@ func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, name, sourceT qc.qmp <- &QmpSession{ commands: commands, respond: defaultRespond(result, &hypervisor.BlockdevInsertedEvent{ - Name: name, - SourceType: sourceType, DeviceName: devName, - ScsiId: id, }), } } diff --git a/hypervisor/vbox/vbox.go b/hypervisor/vbox/vbox.go index c6a3c7bc..1d282543 100644 --- a/hypervisor/vbox/vbox.go +++ b/hypervisor/vbox/vbox.go @@ -279,10 +279,7 @@ func (vc *VBoxContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo } devName := scsiId2Name(id) callback := &hypervisor.BlockdevInsertedEvent{ - Name: name, - SourceType: sourceType, DeviceName: devName, - ScsiId: id, } glog.V(1).Infof("Disk %s (%s) add succeeded", name, filename) @@ -461,10 +458,7 @@ func (vc *VBoxContext) LazyAddDisk(ctx *hypervisor.VmContext, name, sourceType, } devName := scsiId2Name(id) callback := &hypervisor.BlockdevInsertedEvent{ - Name: name, - SourceType: sourceType, DeviceName: devName, - ScsiId: id, } vc.mediums = append(vc.mediums, medium) vc.callbacks = append(vc.callbacks, callback) diff --git a/hypervisor/xen/xen.go b/hypervisor/xen/xen.go index df83997a..62c0c412 100644 --- a/hypervisor/xen/xen.go +++ b/hypervisor/xen/xen.go @@ -218,12 +218,11 @@ func (xc *XenContext) Stats(ctx *hypervisor.VmContext) (*types.PodStats, error) func (xc *XenContext) Close() {} func (xc *XenContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) { - name := blockInfo.Name filename := blockInfo.Filename format := blockInfo.Format id := blockInfo.ScsiId - go diskRoutine(true, xc, ctx, name, sourceType, filename, format, id, nil, result) + go diskRoutine(true, xc, ctx, sourceType, filename, format, id, nil, result) } func (xc *XenContext) RemoveDisk(ctx *hypervisor.VmContext, blockInfo *hypervisor.DiskDescriptor, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) { @@ -305,7 +304,7 @@ func (xd *XenDriver) SupportVmSocket() bool { } func diskRoutine(add bool, xc *XenContext, ctx *hypervisor.VmContext, - name, sourceType, filename, format string, id int, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) { + sourceType, filename, format string, id int, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) { backend := LIBXL_DISK_BACKEND_TAP if strings.HasPrefix(filename, "/dev/") { backend = LIBXL_DISK_BACKEND_PHY @@ -321,10 +320,7 @@ func diskRoutine(add bool, xc *XenContext, ctx *hypervisor.VmContext, if add { res = HyperxlDiskAdd(xc.driver.Ctx, uint32(xc.domId), filename, devName, LibxlDiskBackend(backend), LibxlDiskFormat(dfmt)) callback = &hypervisor.BlockdevInsertedEvent{ - Name: name, - SourceType: sourceType, DeviceName: devName, - ScsiId: id, } } else { op = "remove"