Documentation ¶
Index ¶
- Constants
- func AllocateAligned(size int) []byte
- func FailPointFileHashMatch() bool
- func FoldFile(childFileName, parentFileName string, ops FileHandlingOperations) error
- func GetFileLayout(ctx context.Context, file FileIoProcessor) (<-chan FileInterval, <-chan error, error)
- func HashData(data []byte) ([]byte, error)
- func HashFileInterval(file FileIoProcessor, dataInterval Interval) ([]byte, error)
- func PruneFile(parentFileName, childFileName string, ops FileHandlingOperations) error
- func ReadDataInterval(rw ReaderWriterAt, dataInterval Interval) ([]byte, error)
- func SetFailPointFileHashMatch(fail bool)
- func SyncContent(sourceName string, rw ReaderWriterAt, fileSize int64, remote string, ...) (err error)
- func SyncFile(localPath string, remote string, httpClientTimeout int, ...) error
- func SyncLocalFile(sourceFilePath, targetFilePath string) error
- func WriteDataInterval(file FileIoProcessor, dataInterval Interval, data []byte) error
- type BufferedFileIoProcessor
- func (file *BufferedFileIoProcessor) Close() error
- func (file *BufferedFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
- func (file *BufferedFileIoProcessor) GetFieMap() *FiemapFile
- func (file *BufferedFileIoProcessor) GetFile() *os.File
- func (file *BufferedFileIoProcessor) Size() (int64, error)
- func (file *BufferedFileIoProcessor) UnmapAt(length uint32, offset int64) (int, error)
- type DataSyncClient
- type DirectFileIoProcessor
- func (file *DirectFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
- func (file *DirectFileIoProcessor) GetFieMap() *FiemapFile
- func (file *DirectFileIoProcessor) GetFile() *os.File
- func (file *DirectFileIoProcessor) ReadAt(data []byte, offset int64) (int, error)
- func (file *DirectFileIoProcessor) Size() (int64, error)
- func (file *DirectFileIoProcessor) UnmapAt(length uint32, offset int64) (int, error)
- func (file *DirectFileIoProcessor) WriteAt(data []byte, offset int64) (int, error)
- type Extent
- type FiemapFile
- func (f FiemapFile) Fallocate(offset int64, length int64) error
- func (f FiemapFile) Fiemap(size uint32) (uint32, []Extent, syscall.Errno)
- func (f FiemapFile) FiemapRegion(numExts uint32, start uint64, length uint64) (uint32, []Extent, syscall.Errno)
- func (f FiemapFile) PunchHole(offset int64, length int64) error
- type FileHandlingOperations
- type FileInterval
- type FileIntervalKind
- type FileIoProcessor
- type Interval
- type ReaderWriterAt
Constants ¶
const ( FiemapSize = 32 // sizeof(struct fiemap) ExtentSize = 56 // sizeof(struct Extent) // FS_IOC_FIEMAP is defined in <linux/fs.h>: FS_IOC_FIEMAP = 3223348747 // FIEMAP_MAX_OFFSET Defined in <linux/fiemap.h>: FIEMAP_MAX_OFFSET = ^uint64(0) FIEMAP_FLAG_SYNC = 0x0001 // sync file data before map FIEMAP_FLAG_XATTR = 0x0002 // map extended attribute tree FIEMAP_FLAG_CACHE = 0x0004 // request caching of the extents FIEMAP_FLAGS_COMPAT = (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR) FIEMAP_EXTENT_LAST = 0x0001 // Last extent in file. FIEMAP_EXTENT_UNKNOWN = 0x0002 // Data location unknown. FIEMAP_EXTENT_DELALLOC = 0x0004 // Location still pending. Sets EXTENT_UNKNOWN. FIEMAP_EXTENT_ENCODED = 0x0008 // Data can not be read while fs is unmounted FIEMAP_EXTENT_DATA_ENCRYPTED = 0x0080 // Data is encrypted by fs. Sets EXTENT_NO_BYPASS. FIEMAP_EXTENT_NOT_ALIGNED = 0x0100 // Extent offsets may not be block aligned. FIEMAP_EXTENT_DATA_INLINE = 0x0200 // Data mixed with metadata. Sets EXTENT_NOT_ALIGNED. FIEMAP_EXTENT_DATA_TAIL = 0x0400 // Multiple files in block. Sets EXTENT_NOT_ALIGNED. FIEMAP_EXTENT_UNWRITTEN = 0x0800 // Space allocated, but no data (i.e. zero). FIEMAP_EXTENT_MERGED = 0x1000 // File does not natively support extents. Result merged for efficiency. FIEMAP_EXTENT_SHARED = 0x2000 // Space shared with other files. // FALLOC_FL_KEEP_SIZE Defined in <linux/falloc.h>: FALLOC_FL_KEEP_SIZE = 0x01 // default is extend size FALLOC_FL_PUNCH_HOLE = 0x02 // de-allocates range FALLOC_FL_NO_HIDE_STAE = 0x04 // reserved codepoint )
const (
// BlockSize sic
BlockSize = alignment
)
const ( // Blocks : block size in bytes Blocks int64 = 4 << 10 // 4k )
Variables ¶
This section is empty.
Functions ¶
func AllocateAligned ¶
AllocateAligned returns []byte of size aligned to alignment
func FailPointFileHashMatch ¶
func FailPointFileHashMatch() bool
FailPointFileHashMatch returns true if this failpoint is set, clears the failpoint
func FoldFile ¶
func FoldFile(childFileName, parentFileName string, ops FileHandlingOperations) error
FoldFile folds child snapshot data into its parent
func GetFileLayout ¶
func GetFileLayout(ctx context.Context, file FileIoProcessor) (<-chan FileInterval, <-chan error, error)
func HashFileInterval ¶
func HashFileInterval(file FileIoProcessor, dataInterval Interval) ([]byte, error)
func PruneFile ¶
func PruneFile(parentFileName, childFileName string, ops FileHandlingOperations) error
PruneFile removes the overlapping chunks from the parent snapshot based on its child volume head
func ReadDataInterval ¶
func ReadDataInterval(rw ReaderWriterAt, dataInterval Interval) ([]byte, error)
func SetFailPointFileHashMatch ¶
func SetFailPointFileHashMatch(fail bool)
SetFailPointFileHashMatch simulates file hash match failure
func SyncContent ¶
func SyncFile ¶
func SyncFile(localPath string, remote string, httpClientTimeout int, directIO, fastSync bool) error
SyncFile synchronizes local file to remote host
func SyncLocalFile ¶
SyncLocalFile syncs a local file from sourceFilePath to targetFilePath. It ensures the file size is a multiple of the Block constant before syncing.
func WriteDataInterval ¶
func WriteDataInterval(file FileIoProcessor, dataInterval Interval, data []byte) error
Types ¶
type BufferedFileIoProcessor ¶
type BufferedFileIoProcessor struct {
*FiemapFile
}
func NewBufferedFileIoProcessorByFP ¶
func NewBufferedFileIoProcessorByFP(fp *os.File) *BufferedFileIoProcessor
func (*BufferedFileIoProcessor) Close ¶
func (file *BufferedFileIoProcessor) Close() error
func (*BufferedFileIoProcessor) GetDataLayout ¶
func (file *BufferedFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
func (*BufferedFileIoProcessor) GetFieMap ¶
func (file *BufferedFileIoProcessor) GetFieMap() *FiemapFile
func (*BufferedFileIoProcessor) GetFile ¶
func (file *BufferedFileIoProcessor) GetFile() *os.File
func (*BufferedFileIoProcessor) Size ¶
func (file *BufferedFileIoProcessor) Size() (int64, error)
type DataSyncClient ¶
type DataSyncClient interface {
// contains filtered or unexported methods
}
type DirectFileIoProcessor ¶
type DirectFileIoProcessor struct {
*FiemapFile
}
func NewDirectFileIoProcessorByFP ¶
func NewDirectFileIoProcessorByFP(fp *os.File) *DirectFileIoProcessor
func (*DirectFileIoProcessor) GetDataLayout ¶
func (file *DirectFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
func (*DirectFileIoProcessor) GetFieMap ¶
func (file *DirectFileIoProcessor) GetFieMap() *FiemapFile
func (*DirectFileIoProcessor) GetFile ¶
func (file *DirectFileIoProcessor) GetFile() *os.File
func (*DirectFileIoProcessor) ReadAt ¶
func (file *DirectFileIoProcessor) ReadAt(data []byte, offset int64) (int, error)
ReadAt read into unaligned data buffer via direct I/O Use AllocateAligned to avoid extra data buffer copy
func (*DirectFileIoProcessor) Size ¶
func (file *DirectFileIoProcessor) Size() (int64, error)
type Extent ¶
type Extent struct { Logical uint64 // logical offset in bytes for the start of the extent from the beginning of the file Physical uint64 // physical offset in bytes for the start of the extent from the beginning of the disk Length uint64 // length in bytes for this extent Reserved64 [2]uint64 Flags uint32 // FIEMAP_EXTENT_* flags for this extent Reserved [3]uint32 }
Extent : based on struct fiemap_extent from <linux/fiemap.h>
func GetFiemapExtents ¶
func GetFiemapExtents(file FileIoProcessor) ([]Extent, error)
func GetFiemapRegionExts ¶
func GetFiemapRegionExts(file FileIoProcessor, interval Interval, extCount int) ([]Extent, error)
type FiemapFile ¶
FiemapFile creates a new type by wrapping up os.File
func NewFiemapFile ¶
func NewFiemapFile(f *os.File) *FiemapFile
NewFiemapFile : return a new FiemapFile
func (FiemapFile) Fallocate ¶
func (f FiemapFile) Fallocate(offset int64, length int64) error
Fallocate : allocate using fallocate
func (FiemapFile) FiemapRegion ¶
type FileHandlingOperations ¶
type FileInterval ¶
type FileInterval struct { Kind FileIntervalKind Interval }
FileInterval describes either sparse data Interval or a hole
func (FileInterval) String ¶
func (i FileInterval) String() string
type FileIntervalKind ¶
type FileIntervalKind int
FileIntervalKind distinguishes between data and hole
const ( SparseData FileIntervalKind = 1 + iota SparseHole SparseIgnore // ignore file interval (equal src vs dst part) )
Sparse file Interval types
type FileIoProcessor ¶
type FileIoProcessor interface { // File I/O methods for direct or bufferend I/O ReadAt(data []byte, offset int64) (int, error) WriteAt(data []byte, offset int64) (int, error) UnmapAt(length uint32, offset int64) (int, error) GetFile() *os.File GetFieMap() *FiemapFile GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error) Close() error Sync() error Truncate(size int64) error Seek(offset int64, whence int) (ret int64, err error) Name() string Stat() (os.FileInfo, error) }