From 5c65b04781ce74b22cb7186ad6778df69b0d1908 Mon Sep 17 00:00:00 2001 From: Alex Price Date: Fri, 5 Apr 2019 11:55:26 +1100 Subject: [PATCH] agent: Add support for local storage Local storage is just a directory created inside the VM. This will use whatever the storage driver is for the container rootfs. This will normally be 9p, but in some cases could be device mapper. In this case the directory will benefit from the improved performance of device mapper. Fixes #524 Signed-off-by: Alex Price --- device.go | 1 + mount.go | 11 +++++++++++ mount_test.go | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/device.go b/device.go index d5e8c53738..98a2c27f88 100644 --- a/device.go +++ b/device.go @@ -31,6 +31,7 @@ const ( driverSCSIType = "scsi" driverNvdimmType = "nvdimm" driverEphemeralType = "ephemeral" + driverLocalType = "local" ) const ( diff --git a/mount.go b/mount.go index 7b74b1f258..01ae3bc1d4 100644 --- a/mount.go +++ b/mount.go @@ -198,6 +198,7 @@ var storageHandlerList = map[string]storageHandler{ driverMmioBlkType: virtioMmioBlkStorageHandler, driverSCSIType: virtioSCSIStorageHandler, driverEphemeralType: ephemeralStorageHandler, + driverLocalType: localStorageHandler, } func ephemeralStorageHandler(storage pb.Storage, s *sandbox) (string, error) { @@ -215,6 +216,16 @@ func ephemeralStorageHandler(storage pb.Storage, s *sandbox) (string, error) { return "", nil } +func localStorageHandler(storage pb.Storage, s *sandbox) (string, error) { + s.Lock() + defer s.Unlock() + newStorage := s.setSandboxStorage(storage.MountPoint) + if newStorage { + return "", os.MkdirAll(storage.MountPoint, os.ModePerm) + } + return "", nil +} + // virtio9pStorageHandler handles the storage for 9p driver. func virtio9pStorageHandler(storage pb.Storage, s *sandbox) (string, error) { return commonStorageHandler(storage) diff --git a/mount_test.go b/mount_test.go index db66a3bece..84231c1843 100644 --- a/mount_test.go +++ b/mount_test.go @@ -48,6 +48,21 @@ func TestEphemeralStorageHandlerSuccessful(t *testing.T) { assert.Nil(t, err, "ephemeralStorageHandler() failed: %v", err) } +func TestLocalStorageHandlerSuccessful(t *testing.T) { + skipUnlessRoot(t) + + storage, err := createSafeAndFakeStorage() + if err != nil { + t.Fatal(err) + } + defer syscall.Unmount(storage.MountPoint, 0) + defer os.RemoveAll(storage.MountPoint) + + sbs := make(map[string]*sandboxStorage) + _, err = localStorageHandler(storage, &sandbox{storages: sbs}) + assert.Nil(t, err, "localStorageHandler() failed: %v", err) +} + func TestVirtio9pStorageHandlerSuccessful(t *testing.T) { skipUnlessRoot(t)