storage

package
v1.4.1-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCorruptImageStore = errors.New("Corrupt image store")

Functions

func GetExporters

func GetExporters() []string

GetExporters returns the set of known importers.

func GetImporters

func GetImporters() []string

GetImporters returns the set of known importers.

func Init

Init performs basic initialization, including population of storage.Config

func IsErrImageInUse

func IsErrImageInUse(err error) bool

func IsErrVolumeInUse

func IsErrVolumeInUse(err error) bool

func Label

func Label(ID string) string

given an ID, compute the volume's label

func RegisterExporter

func RegisterExporter(op trace.Operation, store string, e Exporter)

RegisterExporter registers the specified exporter against the provided store for later retrieval.

func RegisterImporter

func RegisterImporter(op trace.Operation, store string, i Importer)

RegisterImporter registers the specified importer against the provided store for later retrieval.

Types

type Configuration

type Configuration struct {
	// Turn on debug logging
	DebugLevel int `vic:"0.1" scope:"read-only" key:"init/diagnostics/debug"`

	// Port Layer - storage
	config.Storage `vic:"0.1" scope:"read-only" key:"storage"`

	// ContainerView
	// https://pubs.vmware.com/vsphere-6-0/index.jsp#com.vmware.wssdk.apiref.doc/vim.view.ContainerView.html
	ContainerView *view.ContainerView
}

Configuration is a slice of the VCH config that is relevant to the exec part of the port layer

var Config Configuration

type DataSink

type DataSink interface {
	// Close releases all resources associated with this sink. Shared resources should be reference counted.
	io.Closer

	// Import performs an import of the tar stream to the source held by this DataSink.  This is single use; once
	// the export has completed it should not be assumed that the sink remains functional.
	//
	// spec: specifies which files will be included/excluded in the import and allows for path rebasing/stripping
	// tarStream: the tar stream to from which to import data
	Import(op trace.Operation, spec *archive.FilterSpec, tarStream io.ReadCloser) error

	// Sink returns the mechanism by which the data sink is accessed
	// Examples:
	//     vmdk mounted locally: *os.File
	//     nfs volume:  		 XDR-client
	//     via guesttools:  	 toolbox client
	Sink() interface{}
}

DataSink defines the methods for importing data to a specific storage element from a tar stream

type DataSource

type DataSource interface {
	// Close releases all resources associated with this source. Shared resources should be reference counted.
	io.Closer

	// Export performs an export of the specified files, returning the data as a tar stream. This is single use; once
	// the export has completed it should not be assumed that the source remains functional.
	//
	// spec: specifies which files will be included/excluded in the export and allows for path rebasing/stripping
	// data: if true the actual file data is included, if false only the file headers are present
	Export(op trace.Operation, spec *archive.FilterSpec, data bool) (io.ReadCloser, error)

	// Source returns the mechanism by which the data source is accessed
	// Examples:
	//     vmdk mounted locally: *os.File
	//     nfs volume:  		 XDR-client
	//     via guesttools:  	 toolbox client
	Source() interface{}

	// Stat stats the filesystem target indicated by the last entry in the given Filterspecs inclusion map
	Stat(op trace.Operation, spec *archive.FilterSpec) (*FileStat, error)
}

DataSource defines the methods for exporting data from a specific storage element as a tar stream

type Disk

type Disk interface {
	// Path to this disk on the VCH
	MountPath() (string, error)

	// Path to the disk on the datastore
	DiskPath() url.URL
}

type ErrImageInUse

type ErrImageInUse struct {
	Msg string
}

func (*ErrImageInUse) Error

func (e *ErrImageInUse) Error() string

type ErrVolumeInUse

type ErrVolumeInUse struct {
	Msg string
}

func (*ErrVolumeInUse) Error

func (e *ErrVolumeInUse) Error() string

type Exporter

type Exporter interface {
	// Export allows direct construction and invocation of a data source for the specified ID.
	Export(op trace.Operation, id, ancestor string, spec *archive.FilterSpec, data bool) (io.ReadCloser, error)

	// NewDataSource constructs a data source for the specified ID within the context of the Exporter. This is a single
	// use source which may hold resources until Closed.
	NewDataSource(op trace.Operation, id string) (DataSource, error)
}

Exporter defines the methods needed to read data from a storage element, optionally diff with an ancestor. This shoiuld be implemented by the various store types.

func GetExporter

func GetExporter(store string) (Exporter, bool)

GetExporter retrieves an exporter registered with the provided store. Will return nil, false if the store is not found.

type FileStat

type FileStat struct {
	LinkTarget string
	Mode       uint32
	Name       string
	Size       int64
	ModTime    time.Time
}

type Image

type Image struct {
	// ID is the identifier for this layer.  Usually a SHA
	ID string

	// SelfLink is the URL for this layer.  Filled in by the runtime.
	SelfLink *url.URL

	// ParentLink is the URL for the parent.  It's the VMDK this snapshot inherits from.
	ParentLink *url.URL

	// Store is the URL for the image store the image can be found on.
	Store *url.URL

	// Metadata associated with the image.
	Metadata map[string][]byte

	// Disk is the underlying disk implementation
	Disk *disk.VirtualDisk
}

Image is the handle to identify an image layer on the backing store. The URI namespace used to identify the Image in the storage layer has the following path scheme:

`/storage/<image store identifier, usually the vch uuid>/<image id>`

func Parse

func Parse(u *url.URL) (*Image, error)

func (*Image) Copy

func (i *Image) Copy() index.Element

func (*Image) Parent

func (i *Image) Parent() string

Returns a link to the parent. Returns link to self if there is no parent

func (*Image) Self

func (i *Image) Self() string

Returns the Selflink of the image

type ImageStorer

type ImageStorer interface {

	// CreateImageStore creates a location to store images and creates a root
	// disk which serves as the parent of all layers.
	//
	// storeName - The name of the image store to be created.  This must be
	// unique.
	//
	// Returns the URL of the created store
	CreateImageStore(op trace.Operation, storeName string) (*url.URL, error)

	// DeleteImageStore is used to cleanup the image store.  This can only be
	// called once there are no images left in the image store.
	DeleteImageStore(op trace.Operation, storeName string) error

	// Gets the url to an image store via name
	GetImageStore(op trace.Operation, storeName string) (*url.URL, error)

	// ListImageStores lists the available image stores
	ListImageStores(op trace.Operation) ([]*url.URL, error)

	// WriteImage creates a new image layer from the given parent.  Eg
	// parentImage + newLayer = new Image built from parent
	//
	// parent - The parent image to create the new image from.
	// ID - textual ID for the image to be written
	// meta - metadata associated with the image
	// sum - expected sha266 sum of the image content.
	// r - the image tar to be written
	WriteImage(op trace.Operation, parent *Image, ID string, meta map[string][]byte, sum string, r io.Reader) (*Image, error)

	// GetImage queries the image store for the specified image.
	//
	// store - The image store to query name - The name of the image (optional)
	// ID - textual ID for the image to be retrieved
	GetImage(op trace.Operation, store *url.URL, ID string) (*Image, error)

	// ListImages returns a list of Images given a list of image IDs, or all
	// images in the image store if no param is passed.
	ListImages(op trace.Operation, store *url.URL, IDs []string) ([]*Image, error)

	// DeleteImage deletes an image from the image store.  If the image is in
	// use either by way of inheritance or because it's attached to a
	// container, this will return an error.
	DeleteImage(op trace.Operation, image *Image) (*Image, error)

	Resolver
	Importer
	Exporter
}

ImageStorer is an interface to store images in the Image Store

type Importer

type Importer interface {
	// Import allows direct construction and invocation of a data sink for the specified ID.
	Import(op trace.Operation, id string, spec *archive.FilterSpec, tarStream io.ReadCloser) error

	// NewDataSink constructs a data sink for the specified ID within the context of the Importer. This is a single
	// use sink which may hold resources until Closed.
	NewDataSink(op trace.Operation, id string) (DataSink, error)
}

Importer defines the methods needed to write data into a storage element. This should be implemented by the various store types.

func GetImporter

func GetImporter(store string) (Importer, bool)

GetImporter retrieves an importer registered with the provided store. Will return nil, false if the store is not found.

type MountDataSink

type MountDataSink struct {
	Path  *os.File
	Clean func()
	// contains filtered or unexported fields
}

MountDataSink implements the DataSink interface for mounted devices This is a single use mechanism and will be tidied up on exit from MountDataSink.Import

func NewMountDataSink

func NewMountDataSink(op trace.Operation, path *os.File, cleanup func()) *MountDataSink

NewMountDataSink creates a new data sink associated with a specific mount, with the mount point being the path argument. The cleanup function is invoked once the import is complete.

func (*MountDataSink) Close

func (m *MountDataSink) Close() error

func (*MountDataSink) Import

func (m *MountDataSink) Import(op trace.Operation, spec *archive.FilterSpec, data io.ReadCloser) error

Import writes `data` to the data source associated with this DataSource This will call MountDataSink.Close on exit, irrespective of success or error

func (*MountDataSink) Sink

func (m *MountDataSink) Sink() interface{}

Sink returns the data source associated with the DataSink

type MountDataSource

type MountDataSource struct {
	Path  *os.File
	Clean func()
	// contains filtered or unexported fields
}

MountDataSource implements the DataSource interface for mounted devices

func NewMountDataSource

func NewMountDataSource(op trace.Operation, path *os.File, cleanup func()) *MountDataSource

NewMountDataSource creates a new data source associated with a specific mount, with the mount point being the path argument. The cleanup function is invoked with the Close of the ReadCloser from Export, or explicitly

func (*MountDataSource) Close

func (m *MountDataSource) Close() error

func (*MountDataSource) Export

func (m *MountDataSource) Export(op trace.Operation, spec *archive.FilterSpec, data bool) (io.ReadCloser, error)

Export reads data from the associated data source and returns it as a tar archive

func (*MountDataSource) Source

func (m *MountDataSource) Source() interface{}

Source returns the data source associated with the DataSource

func (*MountDataSource) Stat

Stat stats the filesystem target indicated by the last entry in the given Filterspecs inclusion map

type NameLookupCache

type NameLookupCache struct {

	// The image store implementation.  This mutates the actual disk images.
	DataStore ImageStorer
	// contains filtered or unexported fields
}

NameLookupCache the global view of all of the image stores. To avoid unnecessary lookups, the image cache keeps an in memory map of the store URI to the map of images on disk.

func NewLookupCache

func NewLookupCache(ds ImageStorer) *NameLookupCache

func (*NameLookupCache) CreateImageStore

func (c *NameLookupCache) CreateImageStore(op trace.Operation, storeName string) (*url.URL, error)

func (*NameLookupCache) DeleteBranch

func (c *NameLookupCache) DeleteBranch(op trace.Operation, image *Image, keepNodes []*url.URL) ([]*Image, error)

DeleteBranch deletes a branch of images, starting from nodeID, up to the first node with degree greater than 1. keepNodes is the array of images to keep (and their branches).

func (*NameLookupCache) DeleteImage

func (c *NameLookupCache) DeleteImage(op trace.Operation, image *Image) (*Image, error)

DeleteImage deletes an image from the image store. If it is in use or is being inheritted from, then this will return an error.

func (*NameLookupCache) Export

func (c *NameLookupCache) Export(op trace.Operation, store *url.URL, id, ancestor string, spec *archive.FilterSpec, data bool) (io.ReadCloser, error)

func (*NameLookupCache) GetImage

func (c *NameLookupCache) GetImage(op trace.Operation, store *url.URL, ID string) (*Image, error)

GetImage gets the specified image from the given store by retreiving it from the cache.

func (*NameLookupCache) GetImageStore

func (c *NameLookupCache) GetImageStore(op trace.Operation, storeName string) (*url.URL, error)

GetImageStore checks to see if a named image store exists and returns the URL to it if so or error.

func (*NameLookupCache) Import

func (c *NameLookupCache) Import(op trace.Operation, store *url.URL, diskID string, spec *archive.FilterSpec, tarStream io.ReadCloser) error

func (*NameLookupCache) ListImageStores

func (c *NameLookupCache) ListImageStores(op trace.Operation) ([]*url.URL, error)

ListImageStores returns a list of strings representing all existing image stores

func (*NameLookupCache) ListImages

func (c *NameLookupCache) ListImages(op trace.Operation, store *url.URL, IDs []string) ([]*Image, error)

ListImages returns a list of Images for a list of IDs, or all if no IDs are passed

func (*NameLookupCache) NewDataSource

func (c *NameLookupCache) NewDataSource(op trace.Operation, id string) (DataSource, error)

func (*NameLookupCache) Owners

func (c *NameLookupCache) Owners(op trace.Operation, url *url.URL, filter func(vm *mo.VirtualMachine) bool) ([]*vm.VirtualMachine, error)

func (*NameLookupCache) URL

func (c *NameLookupCache) URL(op trace.Operation, id string) (*url.URL, error)

func (*NameLookupCache) WriteImage

func (c *NameLookupCache) WriteImage(op trace.Operation, parent *Image, ID string, meta map[string][]byte, sum string, r io.Reader) (*Image, error)

type ProxyReadCloser

type ProxyReadCloser struct {
	io.ReadCloser
	Closer func() error
}

ProxyReadCloser is a read closer that provides for wrapping the Close with a custom Close call. The original ReadCloser.Close function will be invoked after the custom call. Errors from the custom call with be ignored.

func (*ProxyReadCloser) Close

func (p *ProxyReadCloser) Close() error

type Resolver

type Resolver interface {
	// URL returns a url to the data source representing `id`
	// For historic reasons this is not the same URL that other parts of the storage component use, but an actual
	// URL suited for locating the storage element without having additional precursor knowledge.
	URL(op trace.Operation, id string) (*url.URL, error)

	// Owners returns a list of VMs that are using the resource specified by `url`
	Owners(op trace.Operation, url *url.URL, filter func(vm *mo.VirtualMachine) bool) ([]*vm.VirtualMachine, error)
}

Resolver defines methods for mapping ids to URLS, and urls to owners of that device

type Volume

type Volume struct {
	// Identifies the volume
	ID string

	// Label is the computed label of the Volume.  This is set by the runtime.
	Label string

	// The volumestore the volume lives on. (e.g the datastore + vch + configured vol directory)
	Store *url.URL

	// Metadata the volume is included with.  Is persisted along side the volume vmdk.
	Info map[string][]byte

	// Namespace in the storage layer to look up this volume.
	SelfLink *url.URL

	// Backing device
	Device Disk

	CopyMode executor.CopyMode
}

Volume is the handle to identify a volume on the backing store. The URI namespace used to identify the Volume in the storage layer has the following path scheme:

`/storage/volumes/<volume store identifier, usually the vch uuid>/<volume id>`

func NewVolume

func NewVolume(store *url.URL, ID string, info map[string][]byte, device Disk, copyMode executor.CopyMode) (*Volume, error)

NewVolume creates a Volume

func (*Volume) Parse

func (v *Volume) Parse(u *url.URL) error

type VolumeExistsError

type VolumeExistsError struct {
	Msg string
}

VolumeExistsError : custom error type for when a create operation targets and already occupied ID

func (VolumeExistsError) Error

func (e VolumeExistsError) Error() string

type VolumeLookupCache

type VolumeLookupCache struct {
	// contains filtered or unexported fields
}

VolumeLookupCache caches Volume references to volumes in the system.

func NewVolumeLookupCache

func NewVolumeLookupCache(op trace.Operation) *VolumeLookupCache

func (*VolumeLookupCache) AddStore

func (v *VolumeLookupCache) AddStore(op trace.Operation, storeName string, vs VolumeStorer) (*url.URL, error)

AddStore adds a volumestore by name. The url returned is the service url to the volume store.

func (*VolumeLookupCache) Export

func (v *VolumeLookupCache) Export(op trace.Operation, id, ancestor string, spec *archive.FilterSpec, data bool) (io.ReadCloser, error)

Export is a fake store export so that we can do a late lookup of the actual store - this is a work around for the fact that the store URL isn't available in useful form outside of the volumeCache

func (*VolumeLookupCache) GetVolumeStore

func (v *VolumeLookupCache) GetVolumeStore(op trace.Operation, storeName string) (*url.URL, error)

func (*VolumeLookupCache) Import

func (v *VolumeLookupCache) Import(op trace.Operation, id string, spec *archive.FilterSpec, tarStream io.ReadCloser) error

Import is a fake store import so that we can do a late lookup of the actual store - this is a work around for the fact that the store URL isn't available in useful form outside of the volumeCache

func (*VolumeLookupCache) NewDataSink

func (v *VolumeLookupCache) NewDataSink(op trace.Operation, id string) (DataSink, error)

func (*VolumeLookupCache) NewDataSource

func (v *VolumeLookupCache) NewDataSource(op trace.Operation, id string) (DataSource, error)

func (*VolumeLookupCache) VolumeCreate

func (v *VolumeLookupCache) VolumeCreate(op trace.Operation, ID string, store *url.URL, capacityKB uint64, info map[string][]byte) (*Volume, error)

func (*VolumeLookupCache) VolumeDestroy

func (v *VolumeLookupCache) VolumeDestroy(op trace.Operation, ID string) error

func (*VolumeLookupCache) VolumeGet

func (v *VolumeLookupCache) VolumeGet(op trace.Operation, ID string) (*Volume, error)

func (*VolumeLookupCache) VolumeStoresList

func (v *VolumeLookupCache) VolumeStoresList(op trace.Operation) ([]string, error)

VolumeStoresList returns a list of volume store names

func (*VolumeLookupCache) VolumesList

func (v *VolumeLookupCache) VolumesList(op trace.Operation) ([]*Volume, error)

type VolumeStoreNotFoundError

type VolumeStoreNotFoundError struct {
	Msg string
}

VolumeStoreNotFoundError : custom error type for when we fail to find a target volume store

func (VolumeStoreNotFoundError) Error

func (e VolumeStoreNotFoundError) Error() string

type VolumeStorer

type VolumeStorer interface {
	// Creates a volume on the given volume store, of the given size, with the given metadata.
	VolumeCreate(op trace.Operation, ID string, store *url.URL, capacityKB uint64, info map[string][]byte) (*Volume, error)

	// Destroys a volume
	VolumeDestroy(op trace.Operation, vol *Volume) error

	// Lists all volumes
	VolumesList(op trace.Operation) ([]*Volume, error)

	// The interfaces necessary for Import and Export
	Resolver
	Importer
	Exporter
}

VolumeStorer is an interface to create, remove, enumerate, and get Volumes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL