vm

package
v0.0.0-...-7fe54d0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAgentOnlyIO

func IsAgentOnlyIO(stdout string, logger *logrus.Entry) bool

IsAgentOnlyIO checks whether Stdout target is agent only in order to allow log redirection entirely within the VM (currently cio.BinaryIO and cio.LogFile)

func VSockDial

func VSockDial(reqCtx context.Context, logger *logrus.Entry, udsPath string, port uint32) (net.Conn, error)

VSockDial attempts to connect to the Firecracker host-side vsock at the provided unix path and port. It will retry connect attempts if a temporary error is encountered (up to a fixed timeout) or the provided request is canceled.

func VSockListener

func VSockListener(ctx context.Context, logger *logrus.Entry, port uint32) (net.Listener, error)

VSockListener returns a net.Listener implementation for guest-side Firecracker vsock connections.

Types

type Dir

type Dir string

Dir represents the root of a firecracker-containerd VM directory, which holds various files, sockets and FIFOs used during VM runtime.

func ShimDir

func ShimDir(shimBaseDir, namespace, vmID string) (Dir, error)

ShimDir holds files, sockets and FIFOs scoped to a single shim managing the VM with the given VMID. It is unique per-VM and containerd namespace.

func (Dir) AddrFilePath

func (d Dir) AddrFilePath() string

AddrFilePath returns the path to the shim address file as found in the vmDir. The address file holds the abstract unix socket path at which the shim serves its API.

func (d Dir) BundleLink(containerID string) (bundle.Dir, error)

BundleLink returns the path to the symlink to the bundle dir for a given container running inside the VM of this vm dir.

func (d Dir) CreateAddressLink(containerID string) error

CreateAddressLink creates a symlink from the VM dir to the bundle dir for the shim address file. This symlink is read by containerd. CreateAddressLink assumes that CreateBundleLink has been called.

func (d Dir) CreateBundleLink(containerID string, bundleDir bundle.Dir) error

CreateBundleLink creates the BundleLink by symlinking to the provided bundle dir

func (d Dir) CreateShimLogFifoLink(containerID string) error

CreateShimLogFifoLink creates a symlink from the bundleDir of the provided container. CreateAddressLink assumes that CreateBundleLink has been called.

func (Dir) FirecrackerLogFifoPath

func (d Dir) FirecrackerLogFifoPath() string

FirecrackerLogFifoPath returns the path to the FIFO at which the firecracker VMM writes its logs

func (Dir) FirecrackerMetricsFifoPath

func (d Dir) FirecrackerMetricsFifoPath() string

FirecrackerMetricsFifoPath returns the path to the FIFO at which the firecracker VMM writes metrics

func (Dir) FirecrackerSockPath

func (d Dir) FirecrackerSockPath() string

FirecrackerSockPath returns the path to the unix socket at which the firecracker VMM services its API

func (Dir) FirecrackerSockRelPath

func (d Dir) FirecrackerSockRelPath() (string, error)

FirecrackerSockRelPath returns the path to FirecrackerSockPath relative to the current working directory

func (Dir) FirecrackerVSockPath

func (d Dir) FirecrackerVSockPath() string

FirecrackerVSockPath returns the path to the vsock unix socket that the runtime uses to communicate with the VM agent.

func (Dir) FirecrackerVSockRelPath

func (d Dir) FirecrackerVSockRelPath() (string, error)

FirecrackerVSockRelPath returns the path to FirecrackerVSockPath relative to the current working directory

func (Dir) LogFifoPath

func (d Dir) LogFifoPath() string

LogFifoPath returns the path to the FIFO for writing shim logs

func (Dir) Mkdir

func (d Dir) Mkdir() error

Mkdir will mkdir the RootPath with correct permissions, or no-op if it already exists

func (Dir) OpenLogFifo

func (d Dir) OpenLogFifo(requestCtx context.Context) (io.ReadWriteCloser, error)

OpenLogFifo opens the shim's log fifo as WriteOnly

func (Dir) RootPath

func (d Dir) RootPath() string

RootPath returns the top-level directory of the VM dir

func (Dir) WriteAddress

func (d Dir) WriteAddress(shimSocketAddress string) error

WriteAddress will write the actual address file in the VM dir.

type IOConnector

type IOConnector func(procCtx context.Context, logger *logrus.Entry) <-chan IOConnectorResult

IOConnector is function that begins initializing an IO connection (i.e. vsock, FIFO, etc.). It returns a channel that should be published to with an IOConnectorResult object once initialization is complete or an error occurs.

The return of a channel instead of plain values gives the implementation the freedom to do synchronous setup, asynchronous setup or a mix of both.

The provided context is canceled if the process fails to create/exec or when the process exits after a successful create/exec.

func FIFOConnector

func FIFOConnector(path string) IOConnector

FIFOConnector adapts containerd's fifo package to the IOConnector interface

func VSockAcceptConnector

func VSockAcceptConnector(port uint32) IOConnector

VSockAcceptConnector provides an IOConnector that establishes the connection by listening on the provided guest-side vsock port and accepting the first connection that comes in.

func VSockDialConnector

func VSockDialConnector(udsPath string, port uint32) IOConnector

VSockDialConnector returns an IOConnector for establishing vsock connections that are dialed from the host to a guest listener.

type IOConnectorPair

type IOConnectorPair struct {
	ReadConnector  IOConnector
	WriteConnector IOConnector
}

IOConnectorPair holds the read and write side of IOConnectors whose IO should be proxied.

type IOConnectorResult

type IOConnectorResult struct {
	io.ReadWriteCloser
	Err error
}

IOConnectorResult represents the result of attempting to establish an IO connection. If successful, the ReadWriteCloser should be non-nil and Err should be nil. If unsuccessful, ReadWriteCloser should be nil and Err should be non-nil.

type IOProxy

type IOProxy interface {
	// contains filtered or unexported methods
}

IOProxy is an interface to a particular implementation for initializing and copying the stdio of a process running in a VM. All its methods are unexported as they are used only internally. The interface exists just to give outside callers a choice of implementation when setting up a process.

func NewIOConnectorProxy

func NewIOConnectorProxy(stdin, stdout, stderr *IOConnectorPair) IOProxy

NewIOConnectorProxy implements the IOProxy interface for a set of IOConnectorPairs, one each for stdin, stdout and stderr. If any one of those streams does not need to be proxied, the corresponding arg should be nil.

func NewNullIOProxy

func NewNullIOProxy() IOProxy

NewNullIOProxy creates an empty IOProxy

type TaskManager

type TaskManager interface {
	// CreateTask adds a task to be managed. It creates the task using the
	// provided request/TaskService and sets up IO streams using the provided
	// IOConnectorSet.
	// If the TaskManager was shutdown by a previous call to ShutdownIfEmpty, an
	// error will be returned.
	CreateTask(context.Context, *taskAPI.CreateTaskRequest, taskAPI.TaskService, IOProxy) (*taskAPI.CreateTaskResponse, error)

	// DeleteProcess removes a task or exec being managed from the TaskManager.
	// It deletes the process from the provided TaskService using the provided
	// request. It also blocks until all IO for the task has been flushed or a
	// hardcoded timeout is hit.
	DeleteProcess(context.Context, *taskAPI.DeleteRequest, taskAPI.TaskService) (*taskAPI.DeleteResponse, error)

	// ExecProcess adds an exec process to be managed. It must be an exec for a
	// Task already managed by the TaskManager.
	// If the TaskManager was shutdown by a previous call to ShutdownIfEmpty, an
	// error will be returned.
	ExecProcess(context.Context, *taskAPI.ExecProcessRequest, taskAPI.TaskService, IOProxy) (*types.Empty, error)

	// ShutdownIfEmpty will atomically check if there are no tasks left being managed and, if so,
	// prevent any new tasks from being added going forward (future attempts will return an error).
	// If any tasks are still in the TaskManager's map, no change will be made.
	// It returns a bool indicating whether TaskManager shut down as a result of the call.
	ShutdownIfEmpty() bool
}

TaskManager manages a set of tasks, ensuring that creation, deletion and io stream handling of the task happen in a synchronized manner. It's intended to contain logic common to both the host runtime shim and VM agent (which would otherwise be duped between the two).

func NewTaskManager

func NewTaskManager(shimCtx context.Context, logger *logrus.Entry) TaskManager

NewTaskManager initializes a new TaskManager

Jump to

Keyboard shortcuts

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