Documentation ¶
Overview ¶
Package blockdev articulates the QEMU block layer.
The block layer in QEMU is formulated as a node graph that describes the bidirectional flow of data to and from underlying storage. Each node in the graph processes I/O requests from the host in some way.
Example ¶
package main import ( "fmt" "github.com/gentlemanautomaton/machina/qemu/qhost/blockdev" ) func main() { // Create a node graph var graph blockdev.Graph // Add a guest OS file protocol node to the graph os := blockdev.NodeName("guest-os") osFile, err := blockdev.File{ Name: os.Child("file"), Path: blockdev.FilePath("~/guest-os.raw"), Discard: true, DetectZeroes: blockdev.DetectZeroesUnmap, }.Connect(&graph) if err != nil { panic(err) } // Add a guest OS raw format node to the graph _, err = blockdev.Raw{Name: os}.Connect(osFile) if err != nil { panic(err) } // Add a read-only guest data file protocol node to the graph data := blockdev.NodeName("guest-data") dataFile, err := blockdev.File{ Name: data.Child("file"), Path: blockdev.FilePath("~/guest-data.raw"), ReadOnly: true, }.Connect(&graph) if err != nil { panic(err) } // Add a guest OS raw format node to the graph _, err = blockdev.Raw{Name: data}.Connect(dataFile) if err != nil { panic(err) } // Print the node graph options for _, option := range graph.Options() { fmt.Println(option.String()) } }
Output: -blockdev driver=file,node-name=guest-os-file,discard=unmap,detect-zeroes=unmap,filename=~/guest-os.raw -blockdev driver=raw,node-name=guest-os,file=guest-os-file -blockdev driver=file,node-name=guest-data-file,read-only=on,filename=~/guest-data.raw -blockdev driver=raw,node-name=guest-data,file=guest-data-file
Index ¶
- Constants
- Variables
- type Cache
- type DetectZeroes
- type File
- type FileAIO
- type FileLockMode
- type FileNode
- type FilePath
- type Filter
- type FilterDriver
- type Format
- type FormatDriver
- type Graph
- type Node
- type NodeGraph
- type NodeName
- type Properties
- type Property
- type Protocol
- type ProtocolDriver
- type Raw
- type RawNode
Examples ¶
Constants ¶
const ( DetectZeroesOn = DetectZeroes("on") DetectZeroesOff = DetectZeroes("off") DetectZeroesUnmap = DetectZeroes("unmap") )
Drive discard options.
Variables ¶
var ( // ErrNodeExists is returned when an attempt is made to attach a node // with a duplicate node name to a graph. ErrNodeExists = errors.New("a node with the given node name already exists") // ErrGraphMismatch is returned when an attempt is made to attach a node // to a graph that is not associated with that graph. ErrGraphMismatch = errors.New("the node must be associated with the graph before it can be attached") )
Functions ¶
This section is empty.
Types ¶
type DetectZeroes ¶
type DetectZeroes string
DetectZeroes specifies zero-detection behavior for a node.
type File ¶
type File struct { Name NodeName Path FilePath ReadOnly bool Cache Cache Discard bool DetectZeroes DetectZeroes AIO FileAIO Locking FileLockMode }
File holds configuration for a file protocol node.
func (File) Connect ¶
Connect creates a new file protocol node with the given options and attaches it to the node graph.
The returned file protocol node is immutable and can safely be copied by value.
An error is returned if the node cannot be attached to the node graph or the file configuration is invalid.
type FileLockMode ¶
type FileLockMode string
FileLockMode identifies the file locking mode for a file.
type FileNode ¶
type FileNode struct {
// contains filtered or unexported fields
}
FileNode is a file protocol node in a block device node graph.
It implements the Protocol interface.
func (FileNode) Driver ¶
func (f FileNode) Driver() ProtocolDriver
Driver returns the name of the file protocol driver, file.
func (FileNode) Name ¶
Name returns the node name that uniquely identifies the file protocol node within its node graph.
func (FileNode) Properties ¶
func (f FileNode) Properties() Properties
Properties returns the properties of the file protocol node.
type Filter ¶
type Filter interface { Node Driver() ProtocolDriver }
Filter is a filter node in a block graph.
type FilterDriver ¶
type FilterDriver string
FilterDriver identifies a QEMU block driver used by a filter node.
type Format ¶
type Format interface { Node Driver() FormatDriver }
Format is a format node in a block graph.
type FormatDriver ¶
type FormatDriver string
FormatDriver identifies a QEMU block driver used by a format node.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is a simple implementation of a NodeGraph.
The zero-value of a graph is ready for use, but it must not be copied by value once a node has been added to it.
func (*Graph) Add ¶
Add adds the given node to the node graph.
It returns ErrNodeExists if a node with the same node name already exists in the graph.
func (*Graph) Find ¶
Find returns the node with the given node name in the graph.
It returns nil if a node with the given name is not present within the graph.
type Node ¶
type Node interface { Graph() NodeGraph Name() NodeName Properties() Properties }
Node is a node in a QEMU block device graph.
type NodeName ¶
type NodeName string
NodeName uniquely identifies a node in QEMU's block device layer.
type Properties ¶
type Properties = qemu.Parameters
Properties hold a set of QEMU block device properties.
type Protocol ¶
type Protocol interface { Node Driver() ProtocolDriver }
Protocol is a protocol node in a block graph.
type ProtocolDriver ¶
type ProtocolDriver string
ProtocolDriver identifies a QEMU block driver used by a protocol node.
type Raw ¶
type Raw struct { Name NodeName ReadOnly bool Cache Cache Discard bool DetectZeroes DetectZeroes }
Raw holds configuration for a raw format node.
func (Raw) Connect ¶
Connect creates a new raw format node with the given options and attaches it to the node graph of the source protocol node.
The returned raw format node is immutable and can safely be copied by value.
An error is returned if the node cannot be attached to the node graph or the format configuration is invalid.
type RawNode ¶
type RawNode struct {
// contains filtered or unexported fields
}
RawNode is a raw format node in a block device node graph.
func (RawNode) Driver ¶
func (r RawNode) Driver() FormatDriver
Driver returns the name of the raw format driver, raw.
func (RawNode) Properties ¶
func (r RawNode) Properties() Properties
Properties returns the properties of the raw format node.