Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit a5a8c3d

Browse files
committed
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 <bergwolf@gmail.com>
1 parent 73016ca commit a5a8c3d

File tree

7 files changed

+10
-32
lines changed

7 files changed

+10
-32
lines changed

hypervisor/events.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ type VolumeUnmounted struct {
5050
}
5151

5252
type BlockdevInsertedEvent struct {
53-
Name string
54-
SourceType string //image or volume
5553
DeviceName string
56-
ScsiId int
5754
ScsiAddr string // pass scsi addr to hyperstart
5855
}
5956

hypervisor/libvirt/libvirt.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,6 @@ func scsiId2Addr(id int) (int, int, error) {
907907
}
908908

909909
func (lc *LibvirtContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) {
910-
name := blockInfo.Name
911-
id := blockInfo.ScsiId
912-
913910
if lc.domain == nil {
914911
glog.Error("Cannot find domain")
915912
result <- &hypervisor.DeviceFailed{
@@ -945,12 +942,9 @@ func (lc *LibvirtContext) AddDisk(ctx *hypervisor.VmContext, sourceType string,
945942
}
946943
return
947944
}
948-
target, unit, err := scsiId2Addr(id)
945+
target, unit, err := scsiId2Addr(blockInfo.ScsiId)
949946
result <- &hypervisor.BlockdevInsertedEvent{
950-
Name: name,
951-
SourceType: sourceType,
952-
DeviceName: scsiId2Name(id),
953-
ScsiId: id,
947+
DeviceName: scsiId2Name(blockInfo.ScsiId),
954948
ScsiAddr: fmt.Sprintf("%d:%d", target, unit),
955949
}
956950
}

hypervisor/qemu/qemu.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ func (qc *QemuContext) Pause(ctx *hypervisor.VmContext, pause bool) error {
222222
}
223223

224224
func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) {
225-
name := blockInfo.Name
226225
filename := blockInfo.Filename
227226
format := blockInfo.Format
228227
id := blockInfo.ScsiId
@@ -247,7 +246,7 @@ func (qc *QemuContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo
247246
}
248247
}
249248

250-
newDiskAddSession(ctx, qc, name, sourceType, filename, format, id, result)
249+
newDiskAddSession(ctx, qc, filename, format, id, result)
251250
}
252251

253252
func (qc *QemuContext) RemoveDisk(ctx *hypervisor.VmContext, blockInfo *hypervisor.DiskDescriptor, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) {

hypervisor/qemu/qmp_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package qemu
22

33
import (
44
"encoding/json"
5-
"github.com/hyperhq/runv/hypervisor"
65
"net"
76
"testing"
87
"time"
8+
9+
"github.com/hyperhq/runv/hypervisor"
910
)
1011

1112
func TestMessageParse(t *testing.T) {
@@ -261,7 +262,7 @@ func TestQmpDiskSession(t *testing.T) {
261262
}
262263

263264
info := msg.(*hypervisor.BlockdevInsertedEvent)
264-
t.Log("got block device", info.Name, info.SourceType, info.DeviceName)
265+
t.Log("got block device", info.DeviceName)
265266
}
266267

267268
func TestQmpFailOnce(t *testing.T) {
@@ -306,7 +307,7 @@ func TestQmpFailOnce(t *testing.T) {
306307
}
307308

308309
info := msg.(*hypervisor.BlockdevInsertedEvent)
309-
t.Log("got block device", info.Name, info.SourceType, info.DeviceName)
310+
t.Log("got block device", info.DeviceName)
310311
}
311312

312313
func TestQmpKeepFail(t *testing.T) {

hypervisor/qemu/qmp_wrapper.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func defaultRespond(result chan<- hypervisor.VmEvent, callback hypervisor.VmEven
3333
}
3434
}
3535

36-
func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, name, sourceType, filename, format string, id int, result chan<- hypervisor.VmEvent) {
36+
func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, filename, format string, id int, result chan<- hypervisor.VmEvent) {
3737
commands := make([]*QmpCommand, 2)
3838
commands[0] = &QmpCommand{
3939
Execute: "human-monitor-command",
@@ -53,10 +53,7 @@ func newDiskAddSession(ctx *hypervisor.VmContext, qc *QemuContext, name, sourceT
5353
qc.qmp <- &QmpSession{
5454
commands: commands,
5555
respond: defaultRespond(result, &hypervisor.BlockdevInsertedEvent{
56-
Name: name,
57-
SourceType: sourceType,
5856
DeviceName: devName,
59-
ScsiId: id,
6057
}),
6158
}
6259
}

hypervisor/vbox/vbox.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ func (vc *VBoxContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blo
279279
}
280280
devName := scsiId2Name(id)
281281
callback := &hypervisor.BlockdevInsertedEvent{
282-
Name: name,
283-
SourceType: sourceType,
284282
DeviceName: devName,
285-
ScsiId: id,
286283
}
287284

288285
glog.V(1).Infof("Disk %s (%s) add succeeded", name, filename)
@@ -461,10 +458,7 @@ func (vc *VBoxContext) LazyAddDisk(ctx *hypervisor.VmContext, name, sourceType,
461458
}
462459
devName := scsiId2Name(id)
463460
callback := &hypervisor.BlockdevInsertedEvent{
464-
Name: name,
465-
SourceType: sourceType,
466461
DeviceName: devName,
467-
ScsiId: id,
468462
}
469463
vc.mediums = append(vc.mediums, medium)
470464
vc.callbacks = append(vc.callbacks, callback)

hypervisor/xen/xen.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,11 @@ func (xc *XenContext) Stats(ctx *hypervisor.VmContext) (*types.PodStats, error)
218218
func (xc *XenContext) Close() {}
219219

220220
func (xc *XenContext) AddDisk(ctx *hypervisor.VmContext, sourceType string, blockInfo *hypervisor.DiskDescriptor, result chan<- hypervisor.VmEvent) {
221-
name := blockInfo.Name
222221
filename := blockInfo.Filename
223222
format := blockInfo.Format
224223
id := blockInfo.ScsiId
225224

226-
go diskRoutine(true, xc, ctx, name, sourceType, filename, format, id, nil, result)
225+
go diskRoutine(true, xc, ctx, sourceType, filename, format, id, nil, result)
227226
}
228227

229228
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 {
305304
}
306305

307306
func diskRoutine(add bool, xc *XenContext, ctx *hypervisor.VmContext,
308-
name, sourceType, filename, format string, id int, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) {
307+
sourceType, filename, format string, id int, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) {
309308
backend := LIBXL_DISK_BACKEND_TAP
310309
if strings.HasPrefix(filename, "/dev/") {
311310
backend = LIBXL_DISK_BACKEND_PHY
@@ -321,10 +320,7 @@ func diskRoutine(add bool, xc *XenContext, ctx *hypervisor.VmContext,
321320
if add {
322321
res = HyperxlDiskAdd(xc.driver.Ctx, uint32(xc.domId), filename, devName, LibxlDiskBackend(backend), LibxlDiskFormat(dfmt))
323322
callback = &hypervisor.BlockdevInsertedEvent{
324-
Name: name,
325-
SourceType: sourceType,
326323
DeviceName: devName,
327-
ScsiId: id,
328324
}
329325
} else {
330326
op = "remove"

0 commit comments

Comments
 (0)