From 9b5992564adeb83325317c28332b54f8f4bf4fcc Mon Sep 17 00:00:00 2001 From: Vijay Dhanraj Date: Wed, 5 Jun 2019 11:04:04 -0700 Subject: [PATCH] mount: Virtio-blk container rootfs mount for ACRN hypervisor 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: #573 Signed-off-by: Vijay Dhanraj --- mount.go | 27 +++++++++++++++++++++------ mount_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/mount.go b/mount.go index 50088c9788..a2d962aacd 100644 --- a/mount.go +++ b/mount.go @@ -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) } diff --git a/mount_test.go b/mount_test.go index 2d6894f66b..05b517062d 100644 --- a/mount_test.go +++ b/mount_test.go @@ -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)