blockdevice

package
v0.0.0-...-a9d0937 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockDevice

type BlockDevice interface {
	io.ReaderAt
	io.WriterAt

	Sync() error
}

BlockDevice is an interface for interacting with a block device like storage medium. Block devices support random access reads and writes. They differ from plain files, in that their size is fixed.

Storage media tend to store data in sectors. These sectors cannot be read from and written to partially. Though the ReadAt() and WriteAt() methods provided by this interface do not require I/O to be sector aligned, not doing so may impact performance, particularly when writing.

For writes, it is suggested that data is padded with zero bytes to form full sectors. This prevents the kernel from performing reads that are needed to compute the new sector contents.

Because of caching, writes may not be applied against the underlying storage medium immediately. This can be problematic in case the order of writes matters. The Sync() function can be used to block execution until all previous writes are persisted.

func NewBlockDeviceFromConfiguration

func NewBlockDeviceFromConfiguration(configuration *pb.Configuration, mayZeroInitialize bool) (BlockDevice, int, int64, error)

NewBlockDeviceFromConfiguration creates a BlockDevice based on parameters provided in a configuration file.

func NewBlockDeviceFromDevice

func NewBlockDeviceFromDevice(path string) (BlockDevice, int, int64, error)

NewBlockDeviceFromDevice maps the entire contents of a block device into the address space of the current process. Access to the memory map is provided in the form of an io.ReaderAt/io.WriterAt.

The sector size of the block device and the total number of sectors are also returned. It may be assumed that these remain constant over the lifetime of the block device and process.

Writes may only occur at sector boundaries, as unaligned writes would cause unnecessary read operations against underlying storage.

func NewBlockDeviceFromFile

func NewBlockDeviceFromFile(path string, minimumSizeBytes int, zeroInitialize bool) (BlockDevice, int, int64, error)

NewBlockDeviceFromFile creates a BlockDevice that is backed by a regular file stored in a file system.

This approach tends to have more overhead than BlockDevices created using NewBlockDeviceFromDevice, but is often easier to set up in environments where spare disks (or the privileges needed to access those) aren't readily available.

Jump to

Keyboard shortcuts

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