Skip to content

Commit

Permalink
Merge pull request #3162 from BrianMMcClain/vcsim-nic-offset
Browse files Browse the repository at this point in the history
vcsim: apply PCI UnitNumber offset of 7 for ethernet
  • Loading branch information
dougm authored Jul 17, 2023
2 parents 3313033 + cd9446c commit 495ede3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions object/virtual_device_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,13 @@ func (l VirtualDeviceList) PickController(kind types.BaseVirtualController) type
}

// newUnitNumber returns the unit number to use for attaching a new device to the given controller.
func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int32 {
func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController, offset int) int32 {
units := make([]bool, 30)

for i := 0; i < offset; i++ {
units[i] = true
}

switch sc := c.(type) {
case types.BaseVirtualSCSIController:
// The SCSI controller sits on its own bus
Expand Down Expand Up @@ -455,7 +459,14 @@ func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c ty
d := device.GetVirtualDevice()
d.ControllerKey = c.GetVirtualController().Key
d.UnitNumber = new(int32)
*d.UnitNumber = l.newUnitNumber(c)

offset := 0
switch device.(type) {
case types.BaseVirtualEthernetCard:
offset = 7
}
*d.UnitNumber = l.newUnitNumber(c, offset)

if d.Key == 0 {
d.Key = l.newRandomKey()
}
Expand Down
2 changes: 1 addition & 1 deletion object/virtual_device_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func TestPickController(t *testing.T) {
t.Errorf("expected controller key: %d, got: %d\n", test.key, key)
}

unit := list.newUnitNumber(c)
unit := list.newUnitNumber(c, 0)
if unit != test.unit {
t.Errorf("expected unit number: %d, got: %d\n", test.unit, unit)
}
Expand Down

0 comments on commit 495ede3

Please sign in to comment.