Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
device: Assign pci address for block devices
Browse files Browse the repository at this point in the history
Introduce a new field in Drive to store the PCI address if the drive is
attached using virtio-blk.
Assign PCI address in the format bridge-addr/device-addr.
Since we need to assign the address while hotplugging, pass Drive
by address.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed May 3, 2018
1 parent dd92792 commit 718dbd2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ func (c *Container) hotplugDrive() error {
Index: driveIndex,
}

if err := c.sandbox.hypervisor.hotplugAddDevice(drive, blockDev); err != nil {
if err := c.sandbox.hypervisor.hotplugAddDevice(&drive, blockDev); err != nil {
return err
}
c.setStateHotpluggedDrive(true)
Expand All @@ -813,7 +813,7 @@ func (c *Container) removeDrive() (err error) {
c.Logger().Info("unplugging block device")

devID := makeNameID("drive", c.id)
drive := Drive{
drive := &Drive{
ID: devID,
}

Expand Down
7 changes: 5 additions & 2 deletions virtcontainers/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ type BlockDevice struct {

// Path at which the device appears inside the VM, outside of the container mount namespace
VirtPath string

// PCI Slot of the block device
PCIAddr string
}

func newBlockDevice(devInfo DeviceInfo) *BlockDevice {
Expand Down Expand Up @@ -380,7 +383,7 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) {

deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Attaching block device")

if err = h.hotplugAddDevice(drive, blockDev); err != nil {
if err = h.hotplugAddDevice(&drive, blockDev); err != nil {
return err
}

Expand All @@ -404,7 +407,7 @@ func (device BlockDevice) detach(h hypervisor) error {
if device.DeviceInfo.Hotplugged {
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Unplugging block device")

drive := Drive{
drive := &Drive{
ID: makeNameID("drive", device.DeviceInfo.ID),
}

Expand Down
7 changes: 5 additions & 2 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (q *qemu) removeDeviceFromBridge(ID string) error {
return err
}

func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error {
func (q *qemu) hotplugBlockDevice(drive *Drive, op operation) error {
defer func(qemu *qemu) {
if q.qmpMonitorCh.qmp != nil {
q.qmpMonitorCh.qmp.Shutdown()
Expand Down Expand Up @@ -621,6 +621,9 @@ func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error {
return err
}

// PCI address is in the format bridge-addr/device-addr eg. "03/02"
drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr

if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID); err != nil {
return err
}
Expand Down Expand Up @@ -700,7 +703,7 @@ func (q *qemu) hotplugVFIODevice(device VFIODevice, op operation) error {
func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operation) error {
switch devType {
case blockDev:
drive := devInfo.(Drive)
drive := devInfo.(*Drive)
return q.hotplugBlockDevice(drive, op)
case cpuDev:
vcpus := devInfo.(uint32)
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ type Drive struct {

// Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index
Index int

// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
PCIAddr string
}

// EnvVar is a key/value structure representing a command
Expand Down

0 comments on commit 718dbd2

Please sign in to comment.