Documentation ¶
Index ¶
- Constants
- func BytesToHumanReadable(b uint64) string
- func FindMaxProcessesCounts(reader FileSystem, log *logrus.Logger, progressFiles []string) (int, error)
- type BlockRange
- type DiskActionType
- type DriverConfig
- type File
- type FileBackedDevice
- func (d *FileBackedDevice) CheckSynced()
- func (d *FileBackedDevice) Connect() error
- func (d *FileBackedDevice) Disconnect()
- func (d *FileBackedDevice) DriverDisconnect()
- func (d *FileBackedDevice) EnqueueAllDirtyBlocks()
- func (d *FileBackedDevice) Finalize()
- func (d *FileBackedDevice) Flush() error
- func (d *FileBackedDevice) GetBackgroundCopyRate() uint64
- func (d *FileBackedDevice) IsFullySynced() bool
- func (d *FileBackedDevice) ProcessQueues(ctx context.Context, waitGroup *sync.WaitGroup)
- func (d *FileBackedDevice) ReadAt(p []byte, off uint64) error
- func (d *FileBackedDevice) Resume()
- func (d *FileBackedDevice) SampleRate(actionType DiskActionType, intervalMilliseconds uint64) uint64
- func (d *FileBackedDevice) SetBackgroundCopyRate(rateInBytesPerSecond uint64) bool
- func (d *FileBackedDevice) TotalSyncedBlocks() uint64
- func (d *FileBackedDevice) Trim(off, length uint64) error
- func (d *FileBackedDevice) WriteAt(p []byte, off uint64) error
- type FileBlock
- type FileSystem
- type LocalFs
- func (LocalFs) Open(name string) (File, error)
- func (LocalFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (LocalFs) ReadFile(name string) ([]byte, error)
- func (LocalFs) Remove(name string) error
- func (LocalFs) Rename(oldpath, newpath string) error
- func (LocalFs) Stat(name string) (os.FileInfo, error)
- type MockFile
- func (mf *MockFile) Close() error
- func (mf *MockFile) Fd() uintptr
- func (mf *MockFile) ReadAt(b []byte, off int64) (n int, err error)
- func (mf *MockFile) Stat() (os.FileInfo, error)
- func (mf *MockFile) Sync() error
- func (mf *MockFile) Truncate(size int64) error
- func (mf *MockFile) Write(b []byte) (n int, err error)
- func (mf *MockFile) WriteAt(b []byte, off int64) (n int, err error)
- type MockFileInfo
- type MockFs
- type QueueType
- type QueuedWriteAction
- type RangeLocker
- type ReadOnlyFile
- type SyncFile
- type SyncSource
- type WriteActionType
- type WriterQueue
- func (wq *WriterQueue) Dequeue(includeBackgroundItems bool) *QueuedWriteAction
- func (wq *WriterQueue) MakeWriteAction() *QueuedWriteAction
- func (wq *WriterQueue) PutWriteAction(wa *QueuedWriteAction)
- func (wq *WriterQueue) TryDequeue(waitMilliseconds int, includeBackgroundItems bool) *QueuedWriteAction
- func (wq *WriterQueue) TryEnqueue(wa *QueuedWriteAction, timeoutMilliseconds int) bool
Constants ¶
const BlockSize = 4096 // 4k
BlockSize is the chunk size (in bytes) that are transferred between the source and backing files
Variables ¶
This section is empty.
Functions ¶
func BytesToHumanReadable ¶
BytesToHumanReadable converts a raw byte count to a human readable value (e.g. 1024 becomes '1KB')
func FindMaxProcessesCounts ¶
func FindMaxProcessesCounts(reader FileSystem, log *logrus.Logger, progressFiles []string) (int, error)
FindMaxProcessesCounts returns the largest integer found from searching the files found at the location of each progress file path
Types ¶
type BlockRange ¶
BlockRange defines a contiguous, inclusive range of blocks
type DiskActionType ¶
type DiskActionType int
DiskActionType is an enum for read/write actions happening on a disk
const ( // BackingWrite is a write to the backing disk BackingWrite DiskActionType = 0 // BackingRead is a read to the backing disk BackingRead DiskActionType = 1 // SourceRead is a read to the source disk SourceRead DiskActionType = 2 // SourceWrite is a write to the source disk SourceWrite DiskActionType = 3 )
type DriverConfig ¶
type DriverConfig struct { Source *SyncSource Backing *SyncFile NbdFileName string ProcessFiles []string Fs FileSystem Log *logrus.Logger EnableBackgroundSync bool Resumable bool }
DriverConfig contains the needed data to construct a driver If you are using a traditional filesystem (i.e. not overwriting the source or backing file interfaces) you can use NewFileBackedDevice to construct a driver based on on-disk file names.
type File ¶
type File interface { ReadOnlyFile io.Closer io.Reader io.Seeker io.Writer io.WriterAt Stat() (os.FileInfo, error) Sync() error Truncate(size int64) error }
File provides an interface for the native file struct
type FileBackedDevice ¶
type FileBackedDevice struct { Source *SyncSource BackingFile *SyncFile SetSynced context.CancelFunc // contains filtered or unexported fields }
FileBackedDevice is the main BUSE driver object. The BUSE driver calls functions on this struct when associated read/write operations are sent from the kernel.
func New ¶
func New(config *DriverConfig) (*FileBackedDevice, error)
New constructs a FileBackedDevice with potentially overwritten source and backing file interfaces. If you are using a traditional filesystem (i.e. not overwriting the source or backing file interfaces) you can use NewFileBackedDevice to construct a driver based on on-disk file names.
func NewFileBackedDevice ¶
func NewFileBackedDevice( sourceFileName string, backingFileName string, nbdFileName string, processFiles []string, fs FileSystem, log *logrus.Logger, enableBackgroundSync bool, resumable bool, ) (*FileBackedDevice, error)
NewFileBackedDevice constructs a FileBackedDevice based on a source file
func (*FileBackedDevice) CheckSynced ¶
func (d *FileBackedDevice) CheckSynced()
CheckSynced checks if the backing file is fully synced, and if so cancels the sync cancellation context
func (*FileBackedDevice) Connect ¶
func (d *FileBackedDevice) Connect() error
Connect is a blocking function that initiates the NBD device driver
func (*FileBackedDevice) Disconnect ¶
func (d *FileBackedDevice) Disconnect()
Disconnect terminates the NBD driver connection. This call blocks while write queues are flushing, and the intent log is finalizing. Ending the program without calling disconnect will be treated as a crash for the purposes of resuming.
func (*FileBackedDevice) DriverDisconnect ¶
func (d *FileBackedDevice) DriverDisconnect()
DriverDisconnect is called by the BUSE driver in response to disconnect requests from the kernel.
func (*FileBackedDevice) EnqueueAllDirtyBlocks ¶
func (d *FileBackedDevice) EnqueueAllDirtyBlocks()
EnqueueAllDirtyBlocks adds all dirty blocks to the write queue
func (*FileBackedDevice) Finalize ¶
func (d *FileBackedDevice) Finalize()
Finalize runs any necessary cleanup tasks
func (*FileBackedDevice) Flush ¶
func (d *FileBackedDevice) Flush() error
Flush is called by the BUSE driver in response to flush requests from the kernel.
func (*FileBackedDevice) GetBackgroundCopyRate ¶
func (d *FileBackedDevice) GetBackgroundCopyRate() uint64
GetBackgroundCopyRate gets the current background copy rate
func (*FileBackedDevice) IsFullySynced ¶
func (d *FileBackedDevice) IsFullySynced() bool
IsFullySynced returns true if the backing file is ready to use directly
func (*FileBackedDevice) ProcessQueues ¶
func (d *FileBackedDevice) ProcessQueues(ctx context.Context, waitGroup *sync.WaitGroup)
ProcessQueues is a non-blocking function that begins required background processing for this FileBackedDevice. Backgrounded processes increment the provided WaitGroup, and self terminate when cancellation is signalled on the provided Context.
func (*FileBackedDevice) ReadAt ¶
func (d *FileBackedDevice) ReadAt(p []byte, off uint64) error
ReadAt is called by the BUSE driver in response to read requests from the kernel. * If there are no unsynced blocks in the range, pass through the read to the backing file * If there are unsynced blocks in the range
- Do a continuous read from source from the first unsynced block => last unsynced block
- Read any synced blocks from the backing file
- If any unsynced blocks are dirty, reconcile them using the dirty block map
- Enqueue the reconciled buffer to be flushed to disk
- Return requested data to the user
func (*FileBackedDevice) Resume ¶
func (d *FileBackedDevice) Resume()
Resume reads any on-disk block maps that were written by previous executions and initialized the write intent log
func (*FileBackedDevice) SampleRate ¶
func (d *FileBackedDevice) SampleRate(actionType DiskActionType, intervalMilliseconds uint64) uint64
SampleRate returns the rate (in bytes per second) for the given interval
func (*FileBackedDevice) SetBackgroundCopyRate ¶
func (d *FileBackedDevice) SetBackgroundCopyRate(rateInBytesPerSecond uint64) bool
SetBackgroundCopyRate sets the current background copy rate Returns whether the value was updated
func (*FileBackedDevice) TotalSyncedBlocks ¶
func (d *FileBackedDevice) TotalSyncedBlocks() uint64
TotalSyncedBlocks returns how many blocks are present on the backing file
func (*FileBackedDevice) Trim ¶
func (d *FileBackedDevice) Trim(off, length uint64) error
Trim is called by the BUSE driver in response to trim requests from the kernel.
func (*FileBackedDevice) WriteAt ¶
func (d *FileBackedDevice) WriteAt(p []byte, off uint64) error
WriteAt is called by the BUSE driver in response to write requests from the kernel. * Write requests are always passed straight to the backing file * Any blocks in the middle of a write are considered "synced" since they are fully overwritten * Any partially written blocks are recorded in the dirty block map, and enqueued to be fixed by the flush queue
type FileBlock ¶
type FileBlock struct {
// contains filtered or unexported fields
}
FileBlock holds a mutex for a block and whether it has been synced to the backing file
type FileSystem ¶
type FileSystem interface { Open(name string) (File, error) Stat(name string) (os.FileInfo, error) OpenFile(name string, flag int, perm os.FileMode) (File, error) Rename(oldpath, newpath string) error Remove(name string) error ReadFile(name string) ([]byte, error) }
FileSystem is an interface wrapper to the buildin os filesystem operations, for unit testability
type LocalFs ¶
type LocalFs struct{}
LocalFs implements FileSystem using the local disk.
type MockFile ¶
MockFile is a fake file
type MockFileInfo ¶
MockFileInfo returns fake file info
type MockFs ¶
type MockFs struct { mock.Mock FileSystem }
MockFs is a filesystem that isn't real
type QueueType ¶
type QueueType int
QueueType is an enum for the type of queue you want an action from
type QueuedWriteAction ¶
type QueuedWriteAction struct {
// contains filtered or unexported fields
}
QueuedWriteAction contains the type, affected block range, and optional data to be written to disk
type RangeLocker ¶
type RangeLocker struct {
// contains filtered or unexported fields
}
RangeLocker implements "row level" locking for ranges of elements
func NewRangeLocker ¶
func NewRangeLocker(blockRangePool *sync.Pool) *RangeLocker
NewRangeLocker returns a new RangeLocker
func (*RangeLocker) LockRange ¶
func (rl *RangeLocker) LockRange(start uint64, end uint64)
LockRange locks the range of elements defined by start and end (both inclusive). This function blocks until it can obtain an exclusive lock on the provided range
func (*RangeLocker) UnlockRange ¶
func (rl *RangeLocker) UnlockRange(start uint64, end uint64) error
UnlockRange unlocks an existing range lock, and returns error if no matching range is found
type ReadOnlyFile ¶
ReadOnlyFile provides an interface for the read functions of the native file struct
type SyncSource ¶
type SyncSource struct { File ReadOnlyFile Size uint64 }
SyncSource is a struct that points to the read-only source
type WriteActionType ¶
type WriteActionType int
WriteActionType is an enum for the type of action that can be in the writer queue
const ( // WriteData actions flush data to disk that was already read from source by a dynamic read action WriteData WriteActionType = 0 // FixDirtyBlock actions sync data from source, to fully sync blocks that were partially written on the target FixDirtyBlock WriteActionType = 1 // SyncBlock actions sync data from source and write them to the backing file SyncBlock WriteActionType = 2 )
type WriterQueue ¶
type WriterQueue struct {
// contains filtered or unexported fields
}
WriterQueue is a thin wrapper to a channel, which allows for limiting the amount of data in the channel at once
func (*WriterQueue) Dequeue ¶
func (wq *WriterQueue) Dequeue(includeBackgroundItems bool) *QueuedWriteAction
Dequeue attempts to pull an item off the queue. This method is non-blocking if the queue contains no items, this function returns nil. If includeBackgroundItems is true you _may_ also get background block sync actions.
func (*WriterQueue) MakeWriteAction ¶
func (wq *WriterQueue) MakeWriteAction() *QueuedWriteAction
MakeWriteAction constructs a QueuedWriteAction struct
func (*WriterQueue) PutWriteAction ¶
func (wq *WriterQueue) PutWriteAction(wa *QueuedWriteAction)
PutWriteAction adds a write action back to the pool
func (*WriterQueue) TryDequeue ¶
func (wq *WriterQueue) TryDequeue(waitMilliseconds int, includeBackgroundItems bool) *QueuedWriteAction
TryDequeue attempts to pull an item off the queue, if no message has arrived in waitMilliseconds this method returns nil. If includeBackgroundItems is true you _may_ also get background block sync actions
func (*WriterQueue) TryEnqueue ¶
func (wq *WriterQueue) TryEnqueue(wa *QueuedWriteAction, timeoutMilliseconds int) bool
TryEnqueue attempts to add a write action to the write queue. timeoutMilliseconds = 0 indicates that this function should block
Source Files ¶
- bandwidth_calculator.go
- bandwidth_file_manager.go
- block_map.go
- block_map_intent_logger.go
- block_map_intent_transaction.go
- block_util.go
- buse.go
- buse_types.go
- byte_pool.go
- const.go
- dirty_block_map.go
- disk_action_tracker.go
- file_backed_device.go
- mock_fs.go
- range_lock.go
- sparse_file_scanner.go
- util.go
- write_worker.go
- writer_queue.go