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

Commit

Permalink
virtcontainers: Add support for updating virtio-blk based container r…
Browse files Browse the repository at this point in the history
…ootfs

Thist patch adds the following,
1. ACRN only supports virtio-blk and so the rootfs for the VM
sits at /dev/vda. So to get the container rootfs increment the
globalIndex by 1.
2. ACRN doesn't hot-plug container rootfs (but uses blkrescan) to
update the container rootfs. So the agent can be provided the virtpath
rather than the PCIaddr avoiding unneccessary rescaning to find the
virthpath.

Fixes: #1778

Signed-off-by: Vijay Dhanraj <[email protected]>
  • Loading branch information
vijaydhanraj committed Jun 9, 2019
1 parent 7a0a087 commit 898556c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions virtcontainers/device/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
package api

import (
"github.com/sirupsen/logrus"

"github.com/kata-containers/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/sirupsen/logrus"
)

var devLogger = logrus.WithField("subsystem", "device")
Expand All @@ -36,6 +35,7 @@ type DeviceReceiver interface {
// this is only for virtio-blk and virtio-scsi support
GetAndSetSandboxBlockIndex() (int, error)
DecrementSandboxBlockIndex() error
GetHypervisorType() string

// this is for appending device to hypervisor boot params
AppendDevice(Device) error
Expand Down
12 changes: 11 additions & 1 deletion virtcontainers/device/drivers/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ func (device *BlockDevice) Attach(devReceiver api.DeviceReceiver) (err error) {

switch customOptions["block-driver"] {
case "virtio-blk":
globalIdx = index

hypervisor := devReceiver.GetHypervisorType()

if hypervisor == "acrn" {
//With ACRN the rootfs for the VM itself
//sits at /dev/vda and consumes the first index.
globalIdx = index + 1
} else {
globalIdx = index
}

case "virtio-mmio":
//With firecracker the rootfs for the VM itself
//sits at /dev/vda and consumes the first index.
Expand Down
12 changes: 8 additions & 4 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"syscall"
"time"

"github.com/gogo/protobuf/proto"
aTypes "github.com/kata-containers/agent/pkg/types"
kataclient "github.com/kata-containers/agent/protocols/client"
"github.com/kata-containers/agent/protocols/grpc"
Expand All @@ -30,10 +31,8 @@ import (
"github.com/kata-containers/runtime/virtcontainers/store"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
opentracing "github.com/opentracing/opentracing-go"

"github.com/gogo/protobuf/proto"
"github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"
Expand Down Expand Up @@ -1084,7 +1083,12 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat
rootfs.Source = blockDrive.VirtPath
} else if sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock {
rootfs.Driver = kataBlkDevType
rootfs.Source = blockDrive.PCIAddr
if blockDrive.PCIAddr == "" {
rootfs.Source = blockDrive.VirtPath
} else {
rootfs.Source = blockDrive.PCIAddr
}

} else {
rootfs.Driver = kataSCSIDevType
rootfs.Source = blockDrive.SCSIAddr
Expand Down
17 changes: 11 additions & 6 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import (
"syscall"

"github.com/containernetworking/plugins/pkg/ns"
specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"

"github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
Expand All @@ -34,6 +28,11 @@ import (
"github.com/kata-containers/runtime/virtcontainers/store"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)

const (
Expand Down Expand Up @@ -1842,3 +1841,9 @@ func (s *Sandbox) calculateSandboxCPUs() uint32 {
}
return utils.CalculateVCpusFromMilliCpus(mCPU)
}

// GetHypervisorType is used for getting Hypervisor name currently used.
// Sandbox implement DeviceReceiver interface from device/api/interface.go
func (s *Sandbox) GetHypervisorType() string {
return string(s.config.HypervisorType)
}

0 comments on commit 898556c

Please sign in to comment.