xenstore

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: MIT Imports: 18 Imported by: 2

README

xenstore-go

Pure Golang implementation of the XenStore protocol.

Contributing

All types of contributions are welcomed, please don't hesitate to open an issue or create a pull request if you find any problems or think anything could be improved.

Documentation

Index

Constants

View Source
const (
	XsDebug xenStoreOperation = iota
	XsDirectory
	XsRead
	XsGetPermissions
	XsWatch
	XsUnWatch
	XsStartTransaction
	XsEndTransaction
	XsIntroduce
	XsRelease
	XsGetDomainPath
	XsWrite
	XsMkdir
	XsRm
	XsSetPermissions
	XsWatchEvent
	XsError
	XsIsDomainIntroduced
	XsResume
	XsSetTarget
	XsRestrict
	XsResetWatches

	XsInvalid xenStoreOperation = 0xffff

	// XenStorePathSeparator is the separator between paths in XenStore. Parts of any path sent
	// to/received from XenStore should be joined with exactly 1 instance of this string. This is
	// not platform dependent.
	XenStorePathSeparator = "/"
)
View Source
const PacketHeaderSize = unsafe.Sizeof(PacketHeader{})

Variables

View Source
var (
	NUL byte = 0x0
)

Functions

func ControlDomain

func ControlDomain() bool

ControlDomain checks whether the current Xen domain has the 'control_d' capability (will be true on Domain-0).

func Error

func Error(s string) error

Error converts a string returned from XenStore to the syscall error it represents.

func JoinXenStorePath

func JoinXenStorePath(paths ...string) string

JoinXenStorePath concatenates parts of a path together with the XenStorePathSeparator, ensuring that exactly 1 instance of the XenStorePathSeparator is used.

func RequestID

func RequestID() uint32

RequestID returns the next unique (for this session) request ID to use when contacting XenStore. RequestID synchronises access to the counter and is therefore safe to call across multiple goroutines.

func UnixSocketPath

func UnixSocketPath() string

UnixSocketPath gets the current path to the XenStore unix socket on this system

func ValidPath

func ValidPath(path string) bool

ValidPath returns a bool representing whether the provided string is a valid XenStore path.

func ValidPermissions

func ValidPermissions(permissions ...string) bool

ValidPermissions checks if a set of permission specifications for validity & returns true only if all are valid.

func ValidWatchPath

func ValidWatchPath(path string) bool

ValidWatchPath returns a bool representing whether the provided string is a valid watch path - a special case of XenStore paths.

func XenBusPath

func XenBusPath() string

XenBusPath returns the path to the XenBus device on this system

Types

type Client

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

Client is a wrapper which allows easier communication with XenStore by providing methods which allow performing normal XenStore functions with minimal effort.

func NewClient

func NewClient(t Transport) *Client

NewClient creates a new connected Client and starts the internal Router so that packets can be sent and received correctly by the Client.

func NewUnixSocketClient

func NewUnixSocketClient(path string) (*Client, error)

NewUnixSocketClient creates a new Client which will be connected to an underlying UnixSocket.

func NewXenBusClient

func NewXenBusClient(path string) (*Client, error)

NewXenBusClient creates a new Client which will be connected to an underlying XenBus device.

func (*Client) Close

func (c *Client) Close() error

Close stops the underlying Router and closes the Transport.

func (*Client) Error added in v0.2.0

func (c *Client) Error() error

func (*Client) GetDomainPath

func (c *Client) GetDomainPath(domid int) (string, error)

GetDomainPath

func (*Client) GetPermissions

func (c *Client) GetPermissions(path string) (string, error)

GetPermissions returns the currently stored permissions for a XenStore path.

func (*Client) List

func (c *Client) List(path string) ([]string, error)

List lists the descendants of path.

func (*Client) Read

func (c *Client) Read(path string) (string, error)

Read reads the contents of path from XenStore.

func (*Client) Remove

func (c *Client) Remove(path string) (string, error)

Remove removes a path from XenStore recursively

func (*Client) SetPermissions

func (c *Client) SetPermissions(path string, perms []string) (string, error)

SetPermissions sets the permissions for a path in XenStore.

func (*Client) UnWatch

func (c *Client) UnWatch(path, token string) error

UnWatch removes a previously-set watch on a XenStore path.

func (*Client) Watch

func (c *Client) Watch(path, token string) (chan *Packet, error)

Watch places a watch on a particular XenStore path

func (*Client) Write

func (c *Client) Write(path, value string) (string, error)

Write value to XenStore at path.

type Event

type Event struct {
	Path  string
	Token string
}

Event implements a XenStore event

type Packet

type Packet struct {
	Header  *PacketHeader
	Payload []byte
}

func NewPacket

func NewPacket(op xenStoreOperation, payload []byte, txid uint32) (*Packet, error)

NewPacket creates a new Packet instance for sending a payload to XenStore

func (*Packet) Check

func (p *Packet) Check() error

Checks whether the current Packet contains an error response & returns a Go error if so

func (*Packet) Pack

func (p *Packet) Pack(w io.Writer) error

func (*Packet) String added in v0.2.0

func (p *Packet) String() string

String returns a JSON representation of the packet with the payload split into all of the constituent parts.

func (*Packet) Strings added in v0.3.0

func (p *Packet) Strings() []string

Strings returns the strings of the packet with the payload split into all of the constituent parts.

func (*Packet) Unpack

func (p *Packet) Unpack(r io.Reader) error

type PacketHeader

type PacketHeader struct {
	Op     xenStoreOperation `struc:"uint32,little"`
	RqId   uint32            `struc:"uint32,little"`
	TxId   uint32            `struc:"uint32,little"`
	Length uint32            `struc:"uint32,little"`
}

func (*PacketHeader) Pack

func (h *PacketHeader) Pack(w io.Writer) error

Pack the PacketHeader struct and Write the data to an io.Writer

func (*PacketHeader) Unpack

func (h *PacketHeader) Unpack(r io.Reader) error

type ReadWriteTransport

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

ReadWriteTransport is an implementation of the Transport interface which works for any io.ReadWriteCloser..

func (*ReadWriteTransport) Close

func (r *ReadWriteTransport) Close() error

func (*ReadWriteTransport) IsOpen

func (r *ReadWriteTransport) IsOpen() bool

Check if the underlying io.ReadWriteCloser has been closed yet.

func (*ReadWriteTransport) Receive

func (r *ReadWriteTransport) Receive() (*Packet, error)

func (*ReadWriteTransport) Send

func (r *ReadWriteTransport) Send(p *Packet) error

type Router

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

Router provides a way of sending a Packet and receiving the reply in return. It does ths by intercepting all packets over a Transport and forwarding them to listeners over channels.

func NewRouter

func NewRouter(t Transport) *Router

NewRouter creates a new instance of the Router struct for Transport t with all of the correct defaults set.

func (*Router) Send

func (r *Router) Send(pkt *Packet) (chan *Packet, error)

Send sends a Packet to XenStore and returns a channel which the response Packet will be sent over when it is received.

func (*Router) Start

func (r *Router) Start() error

Start starts the Router's internal event loop.

func (*Router) Stop

func (r *Router) Stop()

Stop ends the internal event loop as soon as the next packet has been received

type Transport

type Transport interface {
	// Send a packet to the XenStore backend.
	Send(*Packet) error
	// Receive a packet from the XenStore backend.
	Receive() (*Packet, error)
	// Close if required by the underlying implementation.
	Close() error
}

Transport is an interface for sending and receiving data from XenStore.

type UnixSocketTransport

type UnixSocketTransport struct {
	*ReadWriteTransport

	Path string
}

UnixSocketTransport is an implementation of Transport which sends/receives data from XenStore using a unix socket.

func NewUnixSocketTransport

func NewUnixSocketTransport(path string) (*UnixSocketTransport, error)

NewUnixSocketTransport creates a new connected UnixSocketTransport.

type XenBusTransport

type XenBusTransport struct {
	*ReadWriteTransport

	Path string
}

XenBusTransport is an implementation of Transport which sends/receives data from XenStore using the special XenBus device on Linux (and possibly other Unix operating systems)

func NewXenBusTransport

func NewXenBusTransport(path string) (*XenBusTransport, error)

Create a new connected XenBusTransport.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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