Documentation
¶
Overview ¶
Package fsutil provides utilities for implementing vfs.FileDescriptionImpl and vfs.FilesystemImpl.
Index ¶
- func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, ...) error
- func SyncDirtyAll(ctx context.Context, cache *FileRangeSet, dirty *DirtySet, max uint64, ...) error
- type DirtyInfo
- type FileRangeSetFunctions
- func (FileRangeSetFunctions) ClearValue(_ *uint64)
- func (FileRangeSetFunctions) MaxKey() uint64
- func (FileRangeSetFunctions) Merge(mr1 memmap.MappableRange, frstart1 uint64, _ memmap.MappableRange, ...) (uint64, bool)
- func (FileRangeSetFunctions) MinKey() uint64
- func (FileRangeSetFunctions) Split(mr memmap.MappableRange, frstart uint64, split uint64) (uint64, uint64)
- type FrameRefSegInfo
- type FrameRefSetFunctions
- func (FrameRefSetFunctions) ClearValue(val *FrameRefSegInfo)
- func (FrameRefSetFunctions) MaxKey() uint64
- func (FrameRefSetFunctions) Merge(_ memmap.FileRange, val1 FrameRefSegInfo, _ memmap.FileRange, ...) (FrameRefSegInfo, bool)
- func (FrameRefSetFunctions) MinKey() uint64
- func (FrameRefSetFunctions) Split(_ memmap.FileRange, val FrameRefSegInfo, _ uint64) (FrameRefSegInfo, FrameRefSegInfo)
- type MmapCachedFile
- func (f *MmapCachedFile) AddMapping(ar hostarch.AddrRange, offset uint64)
- func (f *MmapCachedFile) DataFD(fr memmap.FileRange) (int, error)
- func (f *MmapCachedFile) DecRef(fr memmap.FileRange)
- func (f *MmapCachedFile) FD() int
- func (f *MmapCachedFile) IncRef(fr memmap.FileRange, memCgID uint32)
- func (f *MmapCachedFile) MapInternal(fr memmap.FileRange, at hostarch.AccessType) (safemem.BlockSeq, error)
- func (f *MmapCachedFile) MappableRelease()
- func (f *MmapCachedFile) RegenerateMappings() error
- func (f *MmapCachedFile) RemoveMapping(ar hostarch.AddrRange, offset uint64)
- func (f *MmapCachedFile) SetFD(fd int)
- type MmapFile
- type MmapFileRefs
- type MmapNoInternalFile
- type MmapPreciseFile
- func (f *MmapPreciseFile) DataFD(fr memmap.FileRange) (int, error)
- func (f *MmapPreciseFile) DecRef(fr memmap.FileRange)
- func (f *MmapPreciseFile) FD() int
- func (f *MmapPreciseFile) IncRef(fr memmap.FileRange, memCgID uint32)
- func (f *MmapPreciseFile) MapInternal(fr memmap.FileRange, at hostarch.AccessType) (safemem.BlockSeq, error)
- func (f *MmapPreciseFile) MappableRelease()
- func (f *MmapPreciseFile) MemoryType() hostarch.MemoryType
- func (f *MmapPreciseFile) RequireAddrEqualsFileOffset()
- func (f *MmapPreciseFile) SetFD(fd int)
- func (f *MmapPreciseFile) SetMemType(mt hostarch.MemoryType)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SyncDirty ¶
func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, dirty *DirtySet, max uint64, mem memmap.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error
SyncDirty passes pages in the range mr that are stored in cache and identified as dirty to writeAt, updating dirty to reflect successful writes. If writeAt returns a successful partial write, SyncDirty will call it repeatedly until all bytes have been written. max is the true size of the cached object; offsets beyond max will not be passed to writeAt, even if they are marked dirty.
func SyncDirtyAll ¶
func SyncDirtyAll(ctx context.Context, cache *FileRangeSet, dirty *DirtySet, max uint64, mem memmap.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error
SyncDirtyAll passes all pages stored in cache identified as dirty to writeAt, updating dirty to reflect successful writes. If writeAt returns a successful partial write, SyncDirtyAll will call it repeatedly until all bytes have been written. max is the true size of the cached object; offsets beyond max will not be passed to writeAt, even if they are marked dirty.
Types ¶
type DirtyInfo ¶
type DirtyInfo struct {
// Keep is true if the represented offset is concurrently writable, such
// that writing the data for that offset back to the source does not
// guarantee that the offset is clean (since it may be concurrently
// rewritten after the writeback).
Keep bool
}
DirtyInfo is the value type of DirtySet, and represents information about a Mappable offset that is dirty (the cached data for that offset is newer than its source).
+stateify savable
type FileRangeSetFunctions ¶
type FileRangeSetFunctions struct{}
FileRangeSetFunctions implements segment.Functions for FileRangeSet.
func (FileRangeSetFunctions) ClearValue ¶
func (FileRangeSetFunctions) ClearValue(_ *uint64)
ClearValue implements segment.Functions.ClearValue.
func (FileRangeSetFunctions) MaxKey ¶
func (FileRangeSetFunctions) MaxKey() uint64
MaxKey implements segment.Functions.MaxKey.
func (FileRangeSetFunctions) Merge ¶
func (FileRangeSetFunctions) Merge(mr1 memmap.MappableRange, frstart1 uint64, _ memmap.MappableRange, frstart2 uint64) (uint64, bool)
Merge implements segment.Functions.Merge.
func (FileRangeSetFunctions) MinKey ¶
func (FileRangeSetFunctions) MinKey() uint64
MinKey implements segment.Functions.MinKey.
func (FileRangeSetFunctions) Split ¶
func (FileRangeSetFunctions) Split(mr memmap.MappableRange, frstart uint64, split uint64) (uint64, uint64)
Split implements segment.Functions.Split.
type FrameRefSegInfo ¶
type FrameRefSegInfo struct {
// contains filtered or unexported fields
}
FrameRefSegInfo holds reference count and memory cgroup id of the segment.
+stateify savable
type FrameRefSetFunctions ¶
type FrameRefSetFunctions struct{}
FrameRefSetFunctions implements segment.Functions for FrameRefSet.
func (FrameRefSetFunctions) ClearValue ¶
func (FrameRefSetFunctions) ClearValue(val *FrameRefSegInfo)
ClearValue implements segment.Functions.ClearValue.
func (FrameRefSetFunctions) MaxKey ¶
func (FrameRefSetFunctions) MaxKey() uint64
MaxKey implements segment.Functions.MaxKey.
func (FrameRefSetFunctions) Merge ¶
func (FrameRefSetFunctions) Merge(_ memmap.FileRange, val1 FrameRefSegInfo, _ memmap.FileRange, val2 FrameRefSegInfo) (FrameRefSegInfo, bool)
Merge implements segment.Functions.Merge.
func (FrameRefSetFunctions) MinKey ¶
func (FrameRefSetFunctions) MinKey() uint64
MinKey implements segment.Functions.MinKey.
func (FrameRefSetFunctions) Split ¶
func (FrameRefSetFunctions) Split(_ memmap.FileRange, val FrameRefSegInfo, _ uint64) (FrameRefSegInfo, FrameRefSegInfo)
Split implements segment.Functions.Split.
type MmapCachedFile ¶
type MmapCachedFile struct {
memmap.DefaultMemoryType
memmap.NoBufferedIOFallback
// contains filtered or unexported fields
}
MmapCachedFile implements MmapFile. It differs from MmapPreciseFile in the following notable ways:
- MmapCachedFile tracks referenced pages as host page cache usage in sentry memory accounting. (This is the "cache" referred to by the name of MmapCachedFile.) The AddMapping and RemoveMapping methods manipulate reference counts without memory accounting.
- MmapCachedFile creates sentry mappings of referenced pages at aligned units called "chunks", to expedite mapping reference counting and lookup.
SetFD must be called on zero-value MmapCachedFiles before first use.
+stateify savable
func (*MmapCachedFile) AddMapping ¶
func (f *MmapCachedFile) AddMapping(ar hostarch.AddrRange, offset uint64)
AddMapping is called by implementations of memmap.Mappable.AddMapping to increment the reference count on the pages mapped by ar, starting at the given file offset, without affecting memory accounting. This is not needed for correctness, but ensures that mappings of those pages will be maintained if all references obtained using IncRef are dropped. The reference must be released using RemoveMapping when no longer needed.
AddMapping may be called on pages without an existing reference as long as f.MappableRelease() has not been called.
Preconditions: As for memmap.Mappable.AddMapping.
func (*MmapCachedFile) DataFD ¶
func (f *MmapCachedFile) DataFD(fr memmap.FileRange) (int, error)
DataFD implements memmap.File.DataFD.
func (*MmapCachedFile) DecRef ¶
func (f *MmapCachedFile) DecRef(fr memmap.FileRange)
DecRef implements memmap.File.DecRef.
func (*MmapCachedFile) IncRef ¶
func (f *MmapCachedFile) IncRef(fr memmap.FileRange, memCgID uint32)
IncRef implements memmap.File.IncRef.
func (*MmapCachedFile) MapInternal ¶
func (f *MmapCachedFile) MapInternal(fr memmap.FileRange, at hostarch.AccessType) (safemem.BlockSeq, error)
MapInternal implements memmap.File.MapInternal.
func (*MmapCachedFile) MappableRelease ¶
func (f *MmapCachedFile) MappableRelease()
MappableRelease implements MmapFile.MappableRelease.
func (*MmapCachedFile) RegenerateMappings ¶
func (f *MmapCachedFile) RegenerateMappings() error
RegenerateMappings must be called when the file description mapped by f changes, to replace existing mappings of the previous file description.
Preconditions:
- f.MappableRelease() is not called concurrently with, or before, f.RegenerateMappings().
func (*MmapCachedFile) RemoveMapping ¶
func (f *MmapCachedFile) RemoveMapping(ar hostarch.AddrRange, offset uint64)
RemoveMapping is called by implementations of memmap.Mappable.RemoveMapping to release page references acquired by AddMapping.
Preconditions: As for memmap.Mappable.RemoveMapping.
func (*MmapCachedFile) SetFD ¶
func (f *MmapCachedFile) SetFD(fd int)
SetFD implements MmapFile.SetFD.
It is legal to call SetFD on a MmapCachedFile more than once; however, after the first call to SetFD that passes a non-negative fd, all calls to SetFD must pass the same fd.
type MmapFile ¶
type MmapFile interface {
memmap.File
// SetFD sets the file descriptor represented by the MmapFile. It must be
// called on zero-value (implementations of) MmapFile before first use. If
// fd >= 0, the MmapFile takes ownership of the file descriptor fd, i.e. fd
// will be closed when the MmapFile is no longer in use. If fd < 0,
// MapInternal and DataFD can never succeed, but the MmapFile is
// nevertheless a valid memmap.File.
//
// After save/restore, the file descriptor is reset to -1, and SetFD may be
// called to set it again before first post-restore use.
//
// Preconditions: MappableRelease has never been called.
SetFD(fd int)
// MappableRelease is called by the memmap.Mappable that is the nominal
// owner of the represented file descriptor, to indicate that the Mappable
// is being destroyed. The MmapFile retains ownership of the file
// descriptor, and remains a valid memmap.File, until all page references
// are dropped.
MappableRelease()
}
A MmapFile implements memmap.File by owning a host file descriptor on behalf of an implementation of memmap.Mappable.
type MmapFileRefs ¶
type MmapFileRefs struct {
// Closer.Close is called when MappableRelease has been called and all page
// references have been released.
Closer io.Closer
// contains filtered or unexported fields
}
MmapFileRefs provides reference counting for implementations of MmapFile that don't unmap pages with zero references, and consequently don't need to keep track of per-page reference counts.
+stateify savable
func (*MmapFileRefs) DecRef ¶
func (r *MmapFileRefs) DecRef(fr memmap.FileRange)
DecRef implements memmap.File.DecRef.
func (*MmapFileRefs) IncRef ¶
func (r *MmapFileRefs) IncRef(fr memmap.FileRange, memCgID uint32)
IncRef implements memmap.File.IncRef.
func (*MmapFileRefs) MappableRelease ¶
func (r *MmapFileRefs) MappableRelease()
MappableRelease implements MmapFile.MappableRelease.
type MmapNoInternalFile ¶
type MmapNoInternalFile struct {
memmap.NoMapInternal
MmapFileRefs
// contains filtered or unexported fields
}
MmapNoInternalFile implements MmapFile by causing calls to MapInternal to fail. The File may still be mapped into platform.AddressSpaces, i.e. application address spaces, except on platform/kvm.
MmapFileRefs.Closer must be set to MmapNoInternalFile.Close before calling MmapNoInternalFile.MappableRelease.
MmapNoInternalFile is used for device files that are not mappable into the sentry for esoteric reasons (which should be documented for each such file), and for device files for which sentry mapping has not been tested (but might work with MmapPreciseFile, or a custom implementation of memmap.File).
+stateify savable
func (*MmapNoInternalFile) Close ¶
func (f *MmapNoInternalFile) Close() error
Close implements io.Closer.Close for f.MmapFileRefs.Closer.
func (*MmapNoInternalFile) DataFD ¶
func (f *MmapNoInternalFile) DataFD(fr memmap.FileRange) (int, error)
DataFD implements memmap.File.DataFD.
func (*MmapNoInternalFile) SetFD ¶
func (f *MmapNoInternalFile) SetFD(fd int)
SetFD implements MmapFile.SetFD.
type MmapPreciseFile ¶
type MmapPreciseFile struct {
memmap.NoBufferedIOFallback
// contains filtered or unexported fields
}
MmapPreciseFile implements MmapFile. It differs from MmapCachedFile in the following notable ways:
- MmapPreciseFile does not track referenced pages in sentry memory accounting.
- MmapPreciseFile creates sentry mappings of referenced pages at exact page boundaries specified in a file range.
SetFD must be called on zero-value MmapPreciseFiles before first use.
+stateify savable
func (*MmapPreciseFile) DataFD ¶
func (f *MmapPreciseFile) DataFD(fr memmap.FileRange) (int, error)
DataFD implements memmap.File.DataFD.
func (*MmapPreciseFile) DecRef ¶
func (f *MmapPreciseFile) DecRef(fr memmap.FileRange)
DecRef implements memmap.File.DecRef.
func (*MmapPreciseFile) IncRef ¶
func (f *MmapPreciseFile) IncRef(fr memmap.FileRange, memCgID uint32)
IncRef implements memmap.File.IncRef.
func (*MmapPreciseFile) MapInternal ¶
func (f *MmapPreciseFile) MapInternal(fr memmap.FileRange, at hostarch.AccessType) (safemem.BlockSeq, error)
MapInternal implements memmap.File.MapInternal.
func (*MmapPreciseFile) MappableRelease ¶
func (f *MmapPreciseFile) MappableRelease()
MappableRelease implements MmapFile.MappableRelease.
func (*MmapPreciseFile) MemoryType ¶
func (f *MmapPreciseFile) MemoryType() hostarch.MemoryType
MemoryType implements memmap.File.MemoryType.
func (*MmapPreciseFile) RequireAddrEqualsFileOffset ¶
func (f *MmapPreciseFile) RequireAddrEqualsFileOffset()
RequireAddrEqualsFileOffset causes the MmapPreciseFile to map the host file descriptor at addresses equal to the corresponding file offsets. If used, it must be called before first use of the MmapPreciseFile.
func (*MmapPreciseFile) SetFD ¶
func (f *MmapPreciseFile) SetFD(fd int)
SetFD implements MmapFile.SetFD.
func (*MmapPreciseFile) SetMemType ¶
func (f *MmapPreciseFile) SetMemType(mt hostarch.MemoryType)
SetMemType sets the value returned by MemoryType. If used, it must be called before first use of the MmapPreciseFile.