Documentation
¶
Overview ¶
Package nbd implements the NBD network protocol.
You can find a full description of the protocol at https://sourceforge.net/p/nbd/code/ci/master/tree/doc/proto.md
This package implements both the client and the server side of the protocol, as well as (on Linux) utilities to hook up the kernel NBD client to use a server as a block device. The protocol is split into two phases: The handshake phase, which allows the client and server to negotiate their respective capabilities and what export to use. And the transmission phase, for actually reading/writing to the block device.
The client side of the handshake is done with the Client type. Its methods can be used to list the exports a server provides and their respective capabilities. Its Go method enters transmission phase. The returned Export can then be passed to Configure (linux only) to hook it up to an NBD device (/dev/nbdX).
The server side combines both handshake and transmission phase into the Serve or ListenAndServe functions. The user is expected to implement the Device interface to serve actual reads/writes. Under linux, the Loopback function serves as a convenient way to use a given Device as a block device.
Index ¶
- func Configure(e Export, socks ...*os.File) (uint32, error)
- func ListenAndServe(ctx context.Context, network, addr string, exp ...Export) error
- func Loopback(ctx context.Context, d Device, size uint64) (idx uint32, wait func() error, err error)
- func Serve(ctx context.Context, c net.Conn, exp ...Export) error
- type BlockSizeConstraints
- type Client
- type Device
- type Errno
- type Error
- type Export
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
Configure passes the given set of sockets to the kernel to provide them as an NBD device. socks must be connected to the same server (which must support multiple connections) and be in transmission phase. It returns the device-numbers that was chosen by the kernel or any error. You can then use /dev/nbdX as a block device. Use nbdnl.Disconnect to disconnect the device once you're done with it.
This is a Linux-only API.
func ListenAndServe ¶
ListenAndServe starts listening on the given network/address and serves the given exports, the first of which will serve as the default. It starts a new goroutine for each connection. ListenAndServe only returns when ctx is cancelled or an unrecoverable error occurs. Either way, it will wait for all connections to terminate first.
func Loopback ¶
func Loopback(ctx context.Context, d Device, size uint64) (idx uint32, wait func() error, err error)
Loopback serves d on a private socket, passing the other end to the kernel to connect to an NBD device. It returns the device-number that the kernel chose. wait should be called to check for errors from serving the device. It blocks until ctx is cancelled or an error occurs (so it behaves like Serve). When ctx is cancelled, the device will be disconnected, and any error encountered while disconnecting will be returned by wait.
This is a Linux-only API.
Types ¶
type BlockSizeConstraints ¶
BlockSizeConstraints optionally specifies possible block sizes for a given export.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs the client-side of the NBD network protocol handshake and can be used to query information about the exports from a server.
func ClientHandshake ¶
ClientHandshake starts the client-side of the NBD handshake over c.
func (*Client) Go ¶
Go terminates the handshake phase of the NBD protocol, opening the export identified by exportName. If exportName is the empty string, the default export will be used. c should not be used after Go returns.
type Device ¶
type Device interface { io.ReaderAt io.WriterAt // Sync should block until all previous writes where written to persistent // storage and return any errors that occured. Sync() error }
Device is the interface that should be implemented to expose an NBD device to the network or the kernel. Errors returned should implement Error - otherwise, EIO is assumed as the error number.
type Errno ¶
type Errno uint32
Errno is an error code suitable to be sent over the wire. It mostly corresponds to syscall.Errno, though the constants in this package are specified and so are the only ones to be safe to be sent over the wire and understood by all NBD servers/clients.
Notes ¶
Bugs ¶
BlockSizeConstraints are not yet enforced by the server.
The server does not yet support FUA for direct IO.
StartTLS is not supported yet.
There is no way to declare a preferred block size for Loopback yet.
Server flags are not yet set (or used) correctly.
Structured replies are not yet supported.
CMD_TRIM is not yet supported.
Lame-duck mode (ESHUTDOWN) is not yet implemented.
CMD_WRITE_ZEROES is not yet supported.
Metadata querying is not yet supported.
FLAG_ROTATIONAL is not yet supported.
CMD_CACHE is not yet supported.