vpath

package
v3.0.0-rc49 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package vpath is a helper package easing the expansion of a virtual path like vol1/etc/nginx.conf to a host path like /srv/svc1data.ns1.vol.clu1/etc/nginx.conf

A path is written in one of three forms:

/etc/nginx.conf            a path of the node
vol1/etc/nginx.conf        a path in the vol object vol1, of the namespace
volume#1:/etc/nginx.conf   a path in a resource of the object: a volume,
                           or a filesystem, under its mount point

A vol name is a hostname, which holds no '#', so a reference before the ':' holding one is a resource id, and the forms never mean one another.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Devpath

func Devpath(ctx context.Context, from, s, namespace string, resolver Resolver) (string, error)

Devpath returns the device of the node one element of a device keyword names, as Devpaths does, for a keyword naming a single device: a resource id must name a resource exposing one.

func Devpaths

func Devpaths(ctx context.Context, from, s, namespace string, resolver Resolver) ([]string, error)

Devpaths returns the devices of the node one element of a device keyword names:

/dev/sdb    a device of the node
/srv/f.img  a loop file, the device it is attached to
data        a vol of the namespace, the device it exposes
disk#1      a resource of the object, the devices it exposes, as a disk
            or a volume does

from is the id of the resource whose keyword is resolved, which a resource id may not name, directly or through the devices of the resources it names. A resource exposing no device, as one that is not started, is an ErrAccess, as a vol that is not available is.

func DevpathsOf

func DevpathsOf(ctx context.Context, from string, elements []string, namespace string, resolver Resolver) ([]string, error)

DevpathsOf returns the devices of the node the elements of a device list keyword name, as Devpaths does, in a new list.

func HostDevpath

func HostDevpath(ctx context.Context, s string, namespace string) (string, error)

HostDevpath returns host device path for a volume translation rules: INPUT VOL OUTPUT COMMENT /path /dev/sda1 loop dev /dev/sda1 /dev/sda1 host full path myvol myvol /dev/sda1 vol dev path in host

func HostDevpaths

func HostDevpaths(ctx context.Context, l []string, namespace string) ([]string, error)

HostDevpaths applies the HostDevpath function to each path of the input list, and returns the results in a new list: the input is often a keyword value, which must keep naming the vols rather than the devices they exposed once.

func HostPath

func HostPath(ctx context.Context, s string, namespace string) (string, error)

HostPath expand a volume-relative path to a host full path.

Example:

INPUT VOL OUTPUT COMMENT /path /path host full path myvol/path myvol /srv/myvol/path vol head relative path

func HostPathAndVol

func HostPathAndVol(ctx context.Context, s string, namespace string) (hostPath string, vol object.Vol, err error)

HostPathAndVol expand a volume-relative path to a host full path. It returns the host full path and the associated object volume if defined.

Example:

INPUT VOL host path COMMENT /path nil /path host full path myvol/path myvol /srv/myvol/path vol head relative path

func HostPaths

func HostPaths(ctx context.Context, l []string, namespace string) ([]string, error)

HostPaths applies the HostPath function to each path of the input list

func IsResourceRef

func IsResourceRef(s string) bool

IsResourceRef says whether the reference before the ':' of a path is the id of a resource of the object, as volume#1 in volume#1:/etc/nginx. A path of the node starts with a '/', and a vol name holds no '#'.

func ResolveHostPath

func ResolveHostPath(ctx context.Context, s string, namespace string, resolver Resolver) (string, error)

ResolveHostPath expands a path, in any of its forms, to a path of the node.

Types

type ErrAccess

type ErrAccess struct {
	Path  naming.Path
	RID   string
	Avail status.T
}

ErrAccess is the error of a path in a vol or a resource that is not available here.

func (ErrAccess) Error

func (t ErrAccess) Error() string

type Resolver

type Resolver interface {
	ResourceByID(string) resource.Driver
}

Resolver finds the resources of the object a path is written in.

func ResolverOf

func ResolverOf(o any) Resolver

ResolverOf returns the resolver of the resources of an object, nil when it has none.

type Target

type Target struct {
	// HostPath is the path on the node.
	HostPath string

	// Head is the mount point of the vol or the resource the path is
	// in, and empty for a path of the node.
	Head string

	// Vol is the vol the path is in, nil for a path of the node, or of
	// a resource that is no volume.
	Vol object.Vol
}

Target is what a path resolves to.

func Locate

func Locate(ctx context.Context, s string, namespace string, resolver Resolver) (Target, error)

Locate expands a path as Resolve does, whether the vol or the resource it is in is available here or not. It is for the path something was done to while it was, as an export to undo once the volume went down, and not for a path to read or write.

func Resolve

func Resolve(ctx context.Context, s string, namespace string, resolver Resolver) (Target, error)

Resolve expands a path to the path of the node it names, and says the mount point and the vol it is in.

A path in a resource of the object needs the resolver of the object, the resources being its own. The resource must hold a mount point, as a volume or a filesystem does, and be available here.

Jump to

Keyboard shortcuts

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