vm

package
v0.0.0-...-6b2d232 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLocalMountIdentifier

func AddLocalMountIdentifier(mnt mount.Mount) mount.Mount

AddLocalMountIdentifier adds an identifier to a mount so that it can be detected by IsLocalMount. This is intended to be used by cooperating snapshotters to mark mounts as inside the VM so they can be plumbed at the proper points inside/outside the VM.

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 IsLocalMount

func IsLocalMount(mount *types.Mount) bool

IsLocalMount returns true if the mount source is inside the VM as opposed to the default assumption that the mount source is a block device on the host.

func StripLocalMountIdentifier

func StripLocalMountIdentifier(mnt *types.Mount) *types.Mount

StripLocalMountIdentifier removes the identifier that signals that a mount is inside the VM. This is used before passing the mount information to runc

func UpdateUserInSpec

func UpdateUserInSpec(ctx context.Context, specData []byte, rootfsMount mount.Mount) ([]byte, error)

UpdateUserInSpec modifies a serialized json spec object with user information from inside the container. If the client used firecrackeroci.WithVMLocalImageConfig or firecrackeroci.WithVMLocalUser, this method will do the mapping between username -> uid, group name -> gid, and lookup additional groups for the user. This is used to split where the user configures a spec via containerd's oci methods in the client from where the data is actually present (from the agent inside the VM)

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 ReadFIFOConnector

func ReadFIFOConnector(path string) IOConnector

ReadFIFOConnector returns a FIFO which is open for reading

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(timeout time.Duration, udsPath string, port uint32) IOConnector

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

func WriteFIFOConnector

func WriteFIFOConnector(path string) IOConnector

WriteFIFOConnector returns a FIFO which is open for writing

type IOConnectorPair

type IOConnectorPair struct {
	ReadConnector  IOConnector
	WriteConnector IOConnector
}

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

func InputPair

func InputPair(src uint32, dest string) *IOConnectorPair

InputPair returns an IOConnectorPair from the given vsock port to the FIFO file.

func OutputPair

func OutputPair(src string, dest uint32) *IOConnectorPair

OutputPair returns an IOConnectorPair from the given FIFO to the vsock port.

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 {

	// Close the proxy.
	Close()

	// IsOpen returns true if the proxy hasn't been closed.
	IsOpen() bool
	// 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

	// AttachIO attaches the given IO proxy to a task or exec.
	AttachIO(context.Context, string, string, IOProxy) error

	// IsProxyOpen returns true if the given task or exec has an IO proxy
	// which hasn't been closed.
	IsProxyOpen(string, string) (bool, error)
}

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