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

Commit

Permalink
virtcontainers: Pass the PCI address for block based rootfs
Browse files Browse the repository at this point in the history
Store the PCI address of rootfs in case the rootfs is block
based and passed using virtio-block.
This helps up get rid of prdicting the device name inside the
container for the block device. The agent will determine the device
node name using the PCI address.

Fixes #266

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed May 3, 2018
1 parent da08a65 commit 717bc4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
16 changes: 16 additions & 0 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ func (c *Container) setStateHotpluggedDrive(hotplugged bool) error {
return nil
}

func (c *Container) setContainerRootfsPCIAddr(addr string) error {
c.state.RootfsPCIAddr = addr

err := c.sandbox.storage.storeContainerResource(c.sandbox.id, c.id, stateFileType, c.state)
if err != nil {
return err
}

return nil
}

// GetAnnotations returns container's annotations
func (c *Container) GetAnnotations() map[string]string {
return c.config.Annotations
Expand Down Expand Up @@ -791,6 +802,11 @@ func (c *Container) hotplugDrive() error {
if err := c.sandbox.hypervisor.hotplugAddDevice(&drive, blockDev); err != nil {
return err
}

if drive.PCIAddr != "" {
c.setContainerRootfsPCIAddr(drive.PCIAddr)
}

c.setStateHotpluggedDrive(true)

if err := c.setStateBlockIndex(driveIndex); err != nil {
Expand Down
10 changes: 1 addition & 9 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
kataGuestSharedDir = "/run/kata-containers/shared/containers/"
mountGuest9pTag = "kataShared"
type9pFs = "9p"
devPath = "/dev"
vsockSocketScheme = "vsock"
kata9pDevType = "9p"
kataBlkDevType = "blk"
Expand Down Expand Up @@ -692,15 +691,8 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
// If virtio-scsi driver, the agent will be able to find the
// device based on the provided address.
if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock {
// driveName is the predicted virtio-block guest name (the vd* in /dev/vd*).
driveName, err := getVirtDriveName(c.state.BlockIndex)
if err != nil {
return nil, err
}
virtPath := filepath.Join(devPath, driveName)

rootfs.Driver = kataBlkDevType
rootfs.Source = virtPath
rootfs.Source = c.state.RootfsPCIAddr
} else {
scsiAddr, err := getSCSIAddress(c.state.BlockIndex)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type State struct {

// Bool to indicate if the drive for a container was hotplugged.
HotpluggedDrive bool `json:"hotpluggedDrive"`

// PCI slot at which the block device backing the container rootfs is attached.
RootfsPCIAddr string `json:"rootfsPCIAddr"`
}

// valid checks that the sandbox state is valid.
Expand Down

0 comments on commit 717bc4c

Please sign in to comment.