Files
kata-containers/virtcontainers/store/backend.go
Samuel Ortiz 2ecffda170 virtcontainers: store: Add a ItemLock API
The ItemLock API allows for taking shared and exclusive locks on all
items.
For virtcontainers, this is specialized into taking locks on the Lock
item, and will be used for sandbox locking.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-02-06 14:19:18 +01:00

59 lines
1.2 KiB
Go

// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package store
import (
"context"
"fmt"
)
type backendType string
const (
filesystemBackend backendType = "filesystem"
)
const (
filesystemScheme string = "file"
)
func schemeToBackendType(scheme string) (backendType, error) {
switch scheme {
case filesystemScheme:
return filesystemBackend, nil
}
return "", fmt.Errorf("Unsupported scheme %s", scheme)
}
func newBackend(scheme string) (backend, error) {
t, err := schemeToBackendType(scheme)
if err != nil {
return nil, err
}
switch t {
case filesystemBackend:
return &filesystem{}, nil
}
return nil, fmt.Errorf("Unsupported scheme %s", scheme)
}
type backend interface {
new(ctx context.Context, path string, host string) error
delete() error
load(item Item, data interface{}) error
store(item Item, data interface{}) error
// raw creates a raw Store item. A raw item is one that is
// not defined through the Item enum.
// The caller gets an item URL back and handles it directly,
// outside of the top level Store API.
raw(id string) (string, error)
lock(item Item, exclusive bool) (string, error)
unlock(item Item, token string) error
}