Skip to content

Commit

Permalink
agent: Add support for local storage
Browse files Browse the repository at this point in the history
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 kata-containers#524

Signed-off-by: Alex Price <aprice@atlassian.com>
  • Loading branch information
awprice committed Apr 8, 2019
1 parent 7ce9fa5 commit 5c65b04
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
driverSCSIType = "scsi"
driverNvdimmType = "nvdimm"
driverEphemeralType = "ephemeral"
driverLocalType = "local"
)

const (
Expand Down
11 changes: 11 additions & 0 deletions mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5c65b04

Please sign in to comment.