diff --git a/virtcontainers/container.go b/virtcontainers/container.go index b7a810330..49faf4169 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -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 @@ -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 { diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index aa94ed316..8e7c67aa3 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -40,7 +40,6 @@ var ( kataGuestSharedDir = "/run/kata-containers/shared/containers/" mountGuest9pTag = "kataShared" type9pFs = "9p" - devPath = "/dev" vsockSocketScheme = "vsock" kata9pDevType = "9p" kataBlkDevType = "blk" @@ -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 { diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index daa7a7d13..52142e22e 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -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.