nbd

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2016 License: Apache-2.0, MIT Imports: 6 Imported by: 0

README

nbd

Golang Linux Network Block Device as a local block device in user space.

Documentation

Overview

Package nbd uses the Linux NBD layer to emulate a block device in user space

Index

Constants

View Source
const (
	// Defined in <linux/fs.h>:
	BLKROSET = 4701
	// Defined in <linux/nbd.h>:
	NBD_SET_SOCK        = 43776
	NBD_SET_BLKSIZE     = 43777
	NBD_SET_SIZE        = 43778
	NBD_DO_IT           = 43779
	NBD_CLEAR_SOCK      = 43780
	NBD_CLEAR_QUE       = 43781
	NBD_PRINT_DEBUG     = 43782
	NBD_SET_SIZE_BLOCKS = 43783
	NBD_DISCONNECT      = 43784
	NBD_SET_TIMEOUT     = 43785
	NBD_SET_FLAGS       = 43786
	// enum
	NBD_CMD_READ  = 0
	NBD_CMD_WRITE = 1
	NBD_CMD_DISC  = 2
	NBD_CMD_FLUSH = 3
	NBD_CMD_TRIM  = 4
	// values for flags field
	NBD_FLAG_HAS_FLAGS  = (1 << 0) // nbd-server supports flags
	NBD_FLAG_READ_ONLY  = (1 << 1) // device is read-only
	NBD_FLAG_SEND_FLUSH = (1 << 2) // can flush writeback cache
	NBD_FLAG_SEND_FUA   = (1 << 3) // Send FUA (Force Unit Access)
	NBD_FLAG_ROTATIONAL = (1 << 4) // Use elevator algorithm - rotational media
	NBD_FLAG_SEND_TRIM  = (1 << 5) // Send TRIM (discard)

	// These are sent over the network in the request/reply magic fields
	NBD_REQUEST_MAGIC = 0x25609513
	NBD_REPLY_MAGIC   = 0x67446698
)

Variables

This section is empty.

Functions

func FindDevice

func FindDevice() (dev string, err error)

connect the network block device

Types

type Device

type Device interface {
	ReadAt(b []byte, off int64) (n int, err error)
	WriteAt(b []byte, off int64) (n int, err error)
	Sync() error
	Trim(off, len int64) error
}

Device interface is a subset of os.File.

type NBD

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

func Create

func Create(device Device, size int64, blocksize int64) *NBD

func (*NBD) Close

func (nbd *NBD) Close() error

func (*NBD) ConnectDevice

func (nbd *NBD) ConnectDevice(dev string) (outdev string, err error)

func (*NBD) GetSize

func (nbd *NBD) GetSize() int64

get the size of the NBD

func (*NBD) IsConnected

func (nbd *NBD) IsConnected() bool

return true if connected

func (*NBD) Serve

func (nbd *NBD) Serve() (err error)

func (*NBD) Size

func (nbd *NBD) Size(size int64, blocksize int64) (err error)

set the size of the NBD

Jump to

Keyboard shortcuts

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