Documentation
¶
Overview ¶
Package nbdnl controls the Linux NBD driver via netlink.
It connects to the kernel netlink API via an unexported, lazily initialized connection. It can be used to connect any NBD server to an NBD-device (/dev/nbdX) which can then be used like a regular block device. In particular, this makes it possible to write userland block device drivers, by exposing an NBD-server over a local connection and connecting the kernel to it.
This package provides the low-level netlink protocol, which in particular requires connections to be in the transmission phase (i.e. having done the NBD handshake phase or knowning the necessary information by other means). Most users will probably want to use the nbd package, which is more convenientand also implements handshaking.
Index ¶
- Constants
- func Connect(idx uint32, socks []*os.File, size uint64, cf ClientFlags, sf ServerFlags, ...) (uint32, error)
- func Disconnect(idx uint32) error
- func Reconfigure(idx uint32, socks []*os.File, cf ClientFlags, sf ServerFlags, ...) error
- type ClientFlags
- type ConnectOption
- type DeviceStatus
- type ServerFlags
Constants ¶
const IndexAny = ^uint32(0)
IndexAny can be used to let the kernel choose a suitable device number (or create a new device if needed).
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect(idx uint32, socks []*os.File, size uint64, cf ClientFlags, sf ServerFlags, opts ...ConnectOption) (uint32, error)
Connect instructs the kernel to connect the given set of sockets to the given NBD device number. socks must be NBD connections in transmission mode. cf can be used to configure client behavior and sf to specify the set of supported operations. If idx is IndexAny, the kernel chooses a device for us or creates one, if none is available.
func Disconnect ¶
Disconnect instructs the kernel to disconnect the given device.
func Reconfigure ¶
func Reconfigure(idx uint32, socks []*os.File, cf ClientFlags, sf ServerFlags, opts ...ConnectOption) error
Reconfigure reconfigures the given device. The arguments are equivalent to Configure, except that IndexAny is invalid for Reconfigure and WithBlockSize is ignored.
Types ¶
type ClientFlags ¶
type ClientFlags uint64
ClientFlags are flags configuring client behavior.
const ( // FlagDestroyOnDisconnect tells the client to delete the nbd device on // disconnect. FlagDestroyOnDisconnect ClientFlags = 1 << iota // FlagDisconnectOnClose tells the client to disconnect the nbd device on // close by last opener. FlagDisconnectOnClose )
type ConnectOption ¶
type ConnectOption func(e *netlink.AttributeEncoder)
ConnectOption is an optional setting to configure the in-kernel NBD client.
func WithBlockSize ¶
func WithBlockSize(n uint64) ConnectOption
WithBlockSize sets the block size used by the client to n.
func WithDeadconnTimeout ¶
func WithDeadconnTimeout(d time.Duration) ConnectOption
WithDeadconnTimeout sets the timeout after which the client considers a server unreachable to d.
func WithTimeout ¶
func WithTimeout(d time.Duration) ConnectOption
WithTimeout sets the read-timeout for the NBD client to d.
type DeviceStatus ¶
DeviceStatus is the status of an NBD device.
func Status ¶
func Status(idx uint32) (DeviceStatus, error)
Status returns the status of the given NBD device.
func StatusAll ¶
func StatusAll() ([]DeviceStatus, error)
StatusAll lists all NBD devices and their corresponding status.
type ServerFlags ¶
type ServerFlags uint64
ServerFlags specify what optional features the server supports.
const ( // FlagHasFlags is set if the server supports flags. FlagHasFlags ServerFlags = 1 << 0 // FlagReadOnly is set if the export is read-only. FlagReadOnly ServerFlags = 1 << 1 // FlagSendFlush is set if the exports supports the Flush command. FlagSendFlush ServerFlags = 1 << 2 // FlagSendFUA is set if the export supports the Forced Unit Access command // flag. FlagSendFUA ServerFlags = 1 << 3 // FlagSendTrim is set if the export supports the Trim command. FlagSendTrim ServerFlags = 1 << 5 // FlagCanMulticonn is set if the export can serve multiple connections. FlagCanMulticonn ServerFlags = 1 << 8 )