Skip to content

Commit

Permalink
mount: Virtio-blk container rootfs mount for ACRN hypervisor
Browse files Browse the repository at this point in the history
For block devices added by acrn, virtpath is directly udpated
in storage.source and so no scanning of PCIAddr is required.
This is because, the virtio-blk device is not hot-plugged but
added during VM launch and updated later with container rootfs
using block rescan feature.

v2->v3:
1. Addressed weak match for checking storage block device.
2. Added device check for storage block device.
3. Added negative unit tests for the new code.

v1->v2:
gofmt'd the mount file.

Fixes: kata-containers#573

Signed-off-by: Vijay Dhanraj <[email protected]>
  • Loading branch information
vijaydhanraj committed Jun 12, 2019
1 parent 4d55184 commit 9b59925
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
27 changes: 21 additions & 6 deletions mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,28 @@ func virtioFSStorageHandler(storage pb.Storage, s *sandbox) (string, error) {

// virtioBlkStorageHandler handles the storage for blk driver.
func virtioBlkStorageHandler(storage pb.Storage, s *sandbox) (string, error) {
// Get the device node path based on the PCI address provided
// in Storage Source
devPath, err := getPCIDeviceName(s, storage.Source)
if err != nil {
return "", err

// If hot-plugged, get the device node path based on the PCI address else
// use the virt path provided in Storage Source
if strings.HasPrefix(storage.Source, "/dev") {

FileInfo, err := os.Stat(storage.Source)
if err != nil {
return "", err
}
// Make sure the virt path is valid
if FileInfo.Mode()&os.ModeDevice == 0 {
return "", err
}

} else {
devPath, err := getPCIDeviceName(s, storage.Source)
if err != nil {
return "", err
}

storage.Source = devPath
}
storage.Source = devPath

return commonStorageHandler(storage)
}
Expand Down
24 changes: 24 additions & 0 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ func TestVirtio9pStorageHandlerSuccessful(t *testing.T) {
assert.Nil(t, err, "storage9pDriverHandler() failed: %v", err)
}

func TestVirtioBlkStoragePathFailure(t *testing.T) {
s := &sandbox{}

storage := pb.Storage{
Source: "/home/developer/test",
}

_, err := virtioBlkStorageHandler(storage, s)
agentLog.WithError(err).Error("virtioBlkStorageHandler error")
assert.NotNil(t, err, "virtioBlkStorageHandler() should have failed")
}

func TestVirtioBlkStorageDeviceFailure(t *testing.T) {
s := &sandbox{}

storage := pb.Storage{
Source: "/dev/foo",
}

_, err := virtioBlkStorageHandler(storage, s)
agentLog.WithError(err).Error("virtioBlkStorageHandler error")
assert.NotNil(t, err, "virtioBlkStorageHandler() should have failed")
}

func TestVirtioBlkStorageHandlerSuccessful(t *testing.T) {
skipUnlessRoot(t)

Expand Down

0 comments on commit 9b59925

Please sign in to comment.