fsutil

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

README

This package provides utilities for implementing virtual filesystem objects.

[TOC]

Page cache

CachingInodeOperations implements a page cache for files that cannot use the host page cache. Normally these are files that store their data in a remote filesystem. This also applies to files that are accessed on a platform that does not support directly memory mapping host file descriptors (e.g. the ptrace platform).

An CachingInodeOperations buffers regions of a single file into memory. It is owned by an fs.Inode, the in-memory representation of a file (all open file descriptors are backed by an fs.Inode). The fs.Inode provides operations for reading memory into an CachingInodeOperations, to represent the contents of the file in-memory, and for writing memory out, to relieve memory pressure on the kernel and to synchronize in-memory changes to filesystems.

An CachingInodeOperations enables readable and/or writable memory access to file content. Files can be mapped shared or private, see mmap(2). When a file is mapped shared, changes to the file via write(2) and truncate(2) are reflected in the shared memory region. Conversely, when the shared memory region is modified, changes to the file are visible via read(2). Multiple shared mappings of the same file are coherent with each other. This is consistent with Linux.

When a file is mapped private, updates to the mapped memory are not visible to other memory mappings. Updates to the mapped memory are also not reflected in the file content as seen by read(2). If the file is changed after a private mapping is created, for instance by write(2), the change to the file may or may not be reflected in the private mapping. This is consistent with Linux.

An CachingInodeOperations keeps track of ranges of memory that were modified (or "dirtied"). When the file is explicitly synced via fsync(2), only the dirty ranges are written out to the filesystem. Any error returned indicates a failure to write all dirty memory of an CachingInodeOperations to the filesystem. In this case the filesystem may be in an inconsistent state. The same operation can be performed on the shared memory itself using msync(2). If neither fsync(2) nor msync(2) is performed, then the dirty memory is written out in accordance with the CachingInodeOperations eviction strategy (see below) and there is no guarantee that memory will be written out successfully in full.

Memory allocation and eviction

An CachingInodeOperations implements the following allocation and eviction strategy:

  • Memory is allocated and brought up to date with the contents of a file when a region of mapped memory is accessed (or "faulted on").

  • Dirty memory is written out to filesystems when an fsync(2) or msync(2) operation is performed on a memory mapped file, for all memory mapped files when saved, and/or when there are no longer any memory mappings of a range of a file, see munmap(2). As the latter implies, in the absence of a panic or SIGKILL, dirty memory is written out for all memory mapped files when an application exits.

  • Memory is freed when there are no longer any memory mappings of a range of a file (e.g. when an application exits). This behavior is consistent with Linux for shared memory that has been locked via mlock(2).

Notably, memory is not allocated for read(2) or write(2) operations. This means that reads and writes to the file are only accelerated by an CachingInodeOperations if the file being read or written has been memory mapped and if the shared memory has been accessed at the region being read or written. This diverges from Linux which buffers memory into a page cache on read(2) proactively (i.e. readahead) and delays writing it out to filesystems on write(2) (i.e. writeback). The absence of these optimizations is not visible to applications beyond less than optimal performance when repeatedly reading and/or writing to same region of a file. See Future Work for plans to implement these optimizations.

Additionally, memory held by CachingInodeOperationss is currently unbounded in size. An CachingInodeOperations does not write out dirty memory and free it under system memory pressure. This can cause pathological memory usage.

When memory is written back, an CachingInodeOperations may write regions of shared memory that were never modified. This is due to the strategy of minimizing page faults (see below) and handling only a subset of memory write faults. In the absence of an application or sentry crash, it is guaranteed that if a region of shared memory was written to, it is written back to a filesystem.

Life of a shared memory mapping

A file is memory mapped via mmap(2). For example, if A is an address, an application may execute:

mmap(A, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

This creates a shared mapping of fd that reflects 4k of the contents of fd starting at offset 0, accessible at address A. This in turn creates a virtual memory area region ("vma") which indicates that [A, A+0x1000) is now a valid address range for this application to access.

At this point, memory has not been allocated in the file's CachingInodeOperations. It is also the case that the address range [A, A+0x1000) has not been mapped on the host on behalf of the application. If the application then tries to modify 8 bytes of the shared memory:

char buffer[] = "aaaaaaaa";
memcpy(A, buffer, 8);

The host then sends a SIGSEGV to the sentry because the address range [A, A+8) is not mapped on the host. The SIGSEGV indicates that the memory was accessed writable. The sentry looks up the vma associated with [A, A+8), finds the file that was mapped and its CachingInodeOperations. It then calls CachingInodeOperations.MapInto which allocates memory to back [A, A+8). It may choose to allocate more memory (i.e. do "readahead") to minimize subsequent faults.

Memory that is allocated comes from a host tmpfs file (see filemem.FileMem). The host tmpfs file memory is brought up to date with the contents of the mapped file on its filesystem. The region of the host tmpfs file that reflects the mapped file is then mapped into the host address space of the application so that subsequent memory accesses do not repeatedly generate a SIGSEGV.

The range that was allocated, including any extra memory allocation to minimize faults, is marked dirty due to the write fault. This overcounts dirty memory if the extra memory allocated is never modified.

To make the scenario more interesting, imagine that this application spawns another process and maps the same file in the exact same way:

mmap(A, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

Imagine that this process then tries to modify the file again but with only 4 bytes:

char buffer[] = "bbbb";
memcpy(A, buffer, 4);

Since the first process has already mapped and accessed the same region of the file writable, CachingInodeOperations.MapInto is called but re-maps the memory that has already been allocated (because the host mapping can be invalidated at any time) rather than allocating new memory. The address range [A, A+0x1000) reflects the same cached view of the file as the first process sees. For example, reading 8 bytes from the file from either process via read(2) starting at offset 0 returns a consistent "bbbbaaaa".

When this process no longer needs the shared memory, it may do:

munmap(A, 0x1000);

At this point, the modified memory cached by the CachingInodeOperations is not written back to the file because it is still in use by the first process that mapped it. When the first process also does:

munmap(A, 0x1000);

Then the last memory mapping of the file at the range [0, 0x1000) is gone. The file's CachingInodeOperations then starts writing back memory marked dirty to the file on its filesystem. Once writing completes, regardless of whether it was successful, the CachingInodeOperations frees the memory cached at the range [0, 0x1000).

Subsequent read(2) or write(2) operations on the file go directly to the filesystem since there no longer exists memory for it in its CachingInodeOperations.

Future Work

Page cache

The sentry does not yet implement the readahead and writeback optimizations for read(2) and write(2) respectively. To do so, on read(2) and/or write(2) the sentry must ensure that memory is allocated in a page cache to read or write into. However, the sentry cannot boundlessly allocate memory. If it did, the host would eventually OOM-kill the sentry+application process. This means that the sentry must implement a page cache memory allocation strategy that is bounded by a global user or container imposed limit. When this limit is approached, the sentry must decide from which page cache memory should be freed so that it can allocate more memory. If it makes a poor decision, the sentry may end up freeing and re-allocating memory to back regions of files that are frequently used, nullifying the optimization (and in some cases causing worse performance due to the overhead of memory allocation and general management). This is a form of "cache thrashing".

In Linux, much research has been done to select and implement a lightweight but optimal page cache eviction algorithm. Linux makes use of hardware page bits to keep track of whether memory has been accessed. The sentry does not have direct access to hardware. Implementing a similarly lightweight and optimal page cache eviction algorithm will need to either introduce a kernel interface to obtain these page bits or find a suitable alternative proxy for access events.

In Linux, readahead happens by default but is not always ideal. For instance, for files that are not read sequentially, it would be more ideal to simply read from only those regions of the file rather than to optimistically cache some number of bytes ahead of the read (up to 2MB in Linux) if the bytes cached won't be accessed. Linux implements the fadvise64(2) system call for applications to specify that a range of a file will not be accessed sequentially. The advice bit FADV_RANDOM turns off the readahead optimization for the given range in the given file. However fadvise64 is rarely used by applications so Linux implements a readahead backoff strategy if reads are not sequential. To ensure that application performance is not degraded, the sentry must implement a similar backoff strategy.

Documentation

Overview

Package fsutil provides utilities for implementing fs.InodeOperations and fs.FileOperations:

- For embeddable utilities, see inode.go and file.go.

  • For fs.Inodes that require a page cache to be memory mapped, see inode_cache.go.

- For fs.Files that implement fs.HandleOps, see handle.go.

- For anon fs.Inodes, see anon.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericConfigureMMap

func GenericConfigureMMap(file *fs.File, m memmap.Mappable, opts *memmap.MMapOpts) error

GenericConfigureMMap implements fs.FileOperations.ConfigureMMap for most filesystems that support memory mapping.

func NewHandle

func NewHandle(ctx context.Context, dirent *fs.Dirent, flags fs.FileFlags, hops fs.HandleOperations) *fs.File

NewHandle returns a File backed by the Dirent and FileFlags.

func NewSimpleInodeOperations

func NewSimpleInodeOperations(i InodeSimpleAttributes) fs.InodeOperations

NewSimpleInodeOperations constructs fs.InodeOperations from InodeSimpleAttributes.

func SeekWithDirCursor

func SeekWithDirCursor(ctx context.Context, file *fs.File, whence fs.SeekWhence, offset int64, dirCursor *string) (int64, error)

SeekWithDirCursor is used to implement fs.FileOperations.Seek. If dirCursor is not nil and the seek was on a directory, the cursor will be updated.

Currenly only seeking to 0 on a directory is supported.

FIXME: Lift directory seeking limitations.

func SyncDirty

func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, dirty *DirtySet, max uint64, mem platform.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 platform.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 CachedFileObject

type CachedFileObject interface {
	// ReadToBlocksAt reads up to dsts.NumBytes() bytes from the file to dsts,
	// starting at offset, and returns the number of bytes read. ReadToBlocksAt
	// may return a partial read without an error.
	ReadToBlocksAt(ctx context.Context, dsts safemem.BlockSeq, offset uint64) (uint64, error)

	// WriteFromBlocksAt writes up to srcs.NumBytes() bytes from srcs to the
	// file, starting at offset, and returns the number of bytes written.
	// WriteFromBlocksAt may return a partial write without an error.
	WriteFromBlocksAt(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)

	// SetMaskedAttributes sets the attributes in attr that are true in mask
	// on the backing file.
	//
	// SetMaskedAttributes may be called at any point, regardless of whether
	// the file was opened.
	SetMaskedAttributes(ctx context.Context, mask fs.AttrMask, attr fs.UnstableAttr) error

	// Sync instructs the remote filesystem to sync the file to stable storage.
	Sync(ctx context.Context) error

	// FD returns a host file descriptor. Return value must be -1 or not -1
	// for the lifetime of the CachedFileObject.
	//
	// FD is called iff the file has been memory mapped. This implies that
	// the file was opened (see fs.InodeOperations.GetFile).
	//
	// FIXME: This interface seems to be
	// fundamentally broken.  We should clarify CachingInodeOperation's
	// behavior with metadata.
	FD() int
}

CachedFileObject is a file that may require caching.

type CachingInodeOperations

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

CachingInodeOperations caches the metadata and content of a CachedFileObject. It implements a subset of InodeOperations. As a utility it can be used to implement the full set of InodeOperations. Generally it should not be embedded to avoid unexpected inherited behavior.

CachingInodeOperations implements Mappable for the CachedFileObject:

  • If CachedFileObject.FD returns a value >= 0 and the current platform shares a host fd table with the sentry, then the value of CachedFileObject.FD will be memory mapped on the host.
  • Otherwise, the contents of CachedFileObject are buffered into memory managed by the CachingInodeOperations.

Implementations of FileOperations for a CachedFileObject must read and write through CachingInodeOperations using Read and Write respectively.

Implementations of InodeOperations.WriteOut must call Sync to write out in-memory modifications of data and metadata to the CachedFileObject.

func NewCachingInodeOperations

func NewCachingInodeOperations(ctx context.Context, backingFile CachedFileObject, uattr fs.UnstableAttr, forcePageCache bool) *CachingInodeOperations

NewCachingInodeOperations returns a new CachingInodeOperations backed by a CachedFileObject and its initial unstable attributes.

func (*CachingInodeOperations) AddMapping

AddMapping implements memmap.Mappable.AddMapping.

func (*CachingInodeOperations) CopyMapping

func (c *CachingInodeOperations) CopyMapping(ctx context.Context, ms memmap.MappingSpace, srcAR, dstAR usermem.AddrRange, offset uint64) error

CopyMapping implements memmap.Mappable.CopyMapping.

func (c *CachingInodeOperations) DecLinks(ctx context.Context)

DecLinks decreases the link count and updates cached access time.

func (*CachingInodeOperations) DecRef

DecRef implements platform.File.DecRef. This is used when we directly map an underlying host fd and CachingInodeOperations is used as the platform.File during translation.

func (c *CachingInodeOperations) IncLinks(ctx context.Context)

IncLinks increases the link count and updates cached access time.

func (*CachingInodeOperations) IncRef

IncRef implements platform.File.IncRef. This is used when we directly map an underlying host fd and CachingInodeOperations is used as the platform.File during translation.

func (*CachingInodeOperations) InvalidateUnsavable

func (c *CachingInodeOperations) InvalidateUnsavable(ctx context.Context) error

InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.

func (*CachingInodeOperations) MapInternal

MapInternal implements platform.File.MapInternal. This is used when we directly map an underlying host fd and CachingInodeOperations is used as the platform.File during translation.

func (*CachingInodeOperations) MapInto

MapInto implements platform.File.MapInto. This is used when we directly map an underlying host fd and CachingInodeOperations is used as the platform.File during translation.

func (*CachingInodeOperations) Read

func (c *CachingInodeOperations) Read(ctx context.Context, file *fs.File, dst usermem.IOSequence, offset int64) (int64, error)

Read reads from frames and otherwise directly from the backing file into dst starting at offset until dst is full, EOF is reached, or an error is encountered.

Read may partially fill dst and return a nil error.

func (*CachingInodeOperations) Release

func (c *CachingInodeOperations) Release()

Release implements fs.InodeOperations.Release.

func (*CachingInodeOperations) RemoveMapping

func (c *CachingInodeOperations) RemoveMapping(ctx context.Context, ms memmap.MappingSpace, ar usermem.AddrRange, offset uint64)

RemoveMapping implements memmap.Mappable.RemoveMapping.

func (*CachingInodeOperations) SetOwner

func (c *CachingInodeOperations) SetOwner(ctx context.Context, inode *fs.Inode, owner fs.FileOwner) error

SetOwner implements fs.InodeOperations.SetOwner.

func (*CachingInodeOperations) SetPermissions

func (c *CachingInodeOperations) SetPermissions(ctx context.Context, inode *fs.Inode, perms fs.FilePermissions) bool

SetPermissions implements fs.InodeOperations.SetPermissions.

func (*CachingInodeOperations) SetTimestamps

func (c *CachingInodeOperations) SetTimestamps(ctx context.Context, inode *fs.Inode, ts fs.TimeSpec) error

SetTimestamps implements fs.InodeOperations.SetTimestamps.

func (*CachingInodeOperations) TouchAccessTime

func (c *CachingInodeOperations) TouchAccessTime(ctx context.Context, inode *fs.Inode)

TouchAccessTime updates the cached access time in-place to the current time. It does not update status change time in-place. See mm/filemap.c:do_generic_file_read -> include/linux/h:file_accessed.

func (*CachingInodeOperations) TouchModificationTime

func (c *CachingInodeOperations) TouchModificationTime(ctx context.Context)

TouchModificationTime updates the cached modification and status change time in-place to the current time.

func (*CachingInodeOperations) Translate

func (c *CachingInodeOperations) Translate(ctx context.Context, required, optional memmap.MappableRange, at usermem.AccessType) ([]memmap.Translation, error)

Translate implements memmap.Mappable.Translate.

func (*CachingInodeOperations) Truncate

func (c *CachingInodeOperations) Truncate(ctx context.Context, inode *fs.Inode, size int64) error

Truncate implements fs.InodeOperations.Truncate.

func (*CachingInodeOperations) UnstableAttr

func (c *CachingInodeOperations) UnstableAttr(ctx context.Context, inode *fs.Inode) (fs.UnstableAttr, error)

UnstableAttr implements fs.InodeOperations.UnstableAttr.

func (*CachingInodeOperations) Write

func (c *CachingInodeOperations) Write(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error)

Write writes to frames and otherwise directly to the backing file from src starting at offset and until src is empty or an error is encountered.

If Write partially fills src, a non-nil error is returned.

func (*CachingInodeOperations) WriteOut

func (c *CachingInodeOperations) WriteOut(ctx context.Context, inode *fs.Inode) error

WriteOut implements fs.InodeOperations.WriteOut.

type DeprecatedFileOperations

type DeprecatedFileOperations struct{}

DeprecatedFileOperations panics if any deprecated Inode method is called.

func (DeprecatedFileOperations) DeprecatedFlush

func (DeprecatedFileOperations) DeprecatedFlush() error

DeprecatedFlush implements fs.InodeOperations.DeprecatedFlush.

func (DeprecatedFileOperations) DeprecatedFsync

func (DeprecatedFileOperations) DeprecatedFsync() error

DeprecatedFsync implements fs.InodeOperations.DeprecatedFsync.

func (DeprecatedFileOperations) DeprecatedMappable

DeprecatedMappable implements fs.InodeOperations.DeprecatedMappable.

func (DeprecatedFileOperations) DeprecatedPreadv

DeprecatedPreadv implements fs.InodeOperations.DeprecatedPreadv.

func (DeprecatedFileOperations) DeprecatedPwritev

DeprecatedPwritev implements fs.InodeOperations.DeprecatedPwritev.

func (DeprecatedFileOperations) DeprecatedReaddir

func (DeprecatedFileOperations) DeprecatedReaddir(context.Context, *fs.DirCtx, int) (int, error)

DeprecatedReaddir implements fs.InodeOperations.DeprecatedReaddir.

func (DeprecatedFileOperations) EventRegister

EventRegister implements fs.InodeOperations.Waitable.EventRegister.

func (DeprecatedFileOperations) EventUnregister

func (DeprecatedFileOperations) EventUnregister(*waiter.Entry)

EventUnregister implements fs.InodeOperations.Waitable.EventUnregister.

func (DeprecatedFileOperations) Readiness

Readiness implements fs.InodeOperations.Waitable.Readiness.

type DirFileOperations

type DirFileOperations struct {
	waiter.AlwaysReady `state:"nosave"`
	NoopRelease        `state:"nosave"`
	GenericSeek        `state:"nosave"`
	NoFsync            `state:"nosave"`
	NoopFlush          `state:"nosave"`
	NoMMap             `state:"nosave"`
	NoIoctl            `state:"nosave"`
	// contains filtered or unexported fields
}

DirFileOperations implements FileOperations for directories.

func NewDirFileOperations

func NewDirFileOperations(dentries *fs.SortedDentryMap) *DirFileOperations

NewDirFileOperations returns a new DirFileOperations that will iterate the given denty map.

func (*DirFileOperations) IterateDir

func (dfo *DirFileOperations) IterateDir(ctx context.Context, dirCtx *fs.DirCtx, offset int) (int, error)

IterateDir implements DirIterator.IterateDir.

func (*DirFileOperations) Read

Read implements FileOperations.Read

func (*DirFileOperations) Readdir

func (dfo *DirFileOperations) Readdir(ctx context.Context, file *fs.File, serializer fs.DentrySerializer) (int64, error)

Readdir implements FileOperations.Readdir.

func (*DirFileOperations) Write

Write implements FileOperations.Write.

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).

type GenericSeek

type GenericSeek struct{}

GenericSeek implements FileOperations.Seek for files that use a generic seek implementation.

func (GenericSeek) Seek

func (GenericSeek) Seek(ctx context.Context, file *fs.File, whence fs.SeekWhence, offset int64) (int64, error)

Seek implements fs.FileOperations.Seek.

type Handle

type Handle struct {
	NoopRelease      `state:"nosave"`
	NoIoctl          `state:"nosave"`
	HandleOperations fs.HandleOperations
	// contains filtered or unexported fields
}

Handle implements FileOperations.

FIXME: Remove Handle entirely in favor of individual fs.File implementations using simple generic utilities.

func (*Handle) ConfigureMMap

func (h *Handle) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MMapOpts) error

ConfigureMMap implements FileOperations.ConfigureMMap.

func (*Handle) EventRegister

func (h *Handle) EventRegister(e *waiter.Entry, mask waiter.EventMask)

EventRegister implements waiter.Waitable.EventRegister.

func (*Handle) EventUnregister

func (h *Handle) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*Handle) Flush

func (h *Handle) Flush(context.Context, *fs.File) error

Flush implements FileOperations.Flush.

func (*Handle) Fsync

func (h *Handle) Fsync(ctx context.Context, file *fs.File, start int64, end int64, syncType fs.SyncType) error

Fsync implements FileOperations.Fsync.

func (*Handle) IterateDir

func (h *Handle) IterateDir(ctx context.Context, dirCtx *fs.DirCtx, offset int) (int, error)

IterateDir implements DirIterator.IterateDir.

func (*Handle) Read

func (h *Handle) Read(ctx context.Context, file *fs.File, dst usermem.IOSequence, offset int64) (int64, error)

Read implements FileOperations.Read.

func (*Handle) Readdir

func (h *Handle) Readdir(ctx context.Context, file *fs.File, serializer fs.DentrySerializer) (int64, error)

Readdir implements FileOperations.Readdir.

func (*Handle) Readiness

func (h *Handle) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

func (*Handle) Seek

func (h *Handle) Seek(ctx context.Context, file *fs.File, whence fs.SeekWhence, offset int64) (int64, error)

Seek implements FileOperations.Seek.

func (*Handle) Write

func (h *Handle) Write(ctx context.Context, file *fs.File, src usermem.IOSequence, offset int64) (int64, error)

Write implements FileOperations.Write.

type HostFileMapper

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

HostFileMapper caches mappings of an arbitrary host file descriptor. It is used by implementations of memmap.Mappable that represent a host file descriptor.

func NewHostFileMapper

func NewHostFileMapper() *HostFileMapper

NewHostFileMapper returns a HostFileMapper with no references or cached mappings.

func (*HostFileMapper) DecRefOn

func (f *HostFileMapper) DecRefOn(mr memmap.MappableRange)

DecRefOn decrements the reference count on all offsets in mr.

Preconditions: mr.Length() != 0. mr.Start and mr.End must be page-aligned.

func (*HostFileMapper) IncRefOn

func (f *HostFileMapper) IncRefOn(mr memmap.MappableRange)

IncRefOn increments the reference count on all offsets in mr.

Preconditions: mr.Length() != 0. mr.Start and mr.End must be page-aligned.

func (*HostFileMapper) MapInternal

func (f *HostFileMapper) MapInternal(fr platform.FileRange, fd int, write bool) (safemem.BlockSeq, error)

MapInternal returns a mapping of offsets in fr from fd. The returned safemem.BlockSeq is valid as long as at least one reference is held on all offsets in fr or until the next call to UnmapAll.

Preconditions: The caller must hold a reference on all offsets in fr.

func (*HostFileMapper) UnmapAll

func (f *HostFileMapper) UnmapAll()

UnmapAll unmaps all cached mappings. Callers are responsible for synchronization with mappings returned by previous calls to MapInternal.

type InMemoryAttributes

type InMemoryAttributes struct {
	Unstable fs.UnstableAttr
	Xattrs   map[string][]byte
}

InMemoryAttributes implements utilities for updating in-memory unstable attributes and extended attributes. It is not thread-safe.

Users need not initialize Xattrs to non-nil (it will be initialized when the first extended attribute is set.

func (*InMemoryAttributes) Getxattr

func (i *InMemoryAttributes) Getxattr(name string) ([]byte, error)

Getxattr returns the extended attribute at name or ENOATTR if it isn't set.

func (*InMemoryAttributes) Listxattr

func (i *InMemoryAttributes) Listxattr() (map[string]struct{}, error)

Listxattr returns the set of all currently set extended attributes.

func (*InMemoryAttributes) SetOwner

func (i *InMemoryAttributes) SetOwner(ctx context.Context, owner fs.FileOwner) error

SetOwner updates the file owner to owner.

func (*InMemoryAttributes) SetPermissions

func (i *InMemoryAttributes) SetPermissions(ctx context.Context, p fs.FilePermissions) bool

SetPermissions updates the permissions to p.

func (*InMemoryAttributes) SetTimestamps

func (i *InMemoryAttributes) SetTimestamps(ctx context.Context, ts fs.TimeSpec) error

SetTimestamps sets the timestamps to ts.

func (*InMemoryAttributes) Setxattr

func (i *InMemoryAttributes) Setxattr(name string, value []byte) error

Setxattr sets the extended attribute at name to value.

func (*InMemoryAttributes) TouchAccessTime

func (i *InMemoryAttributes) TouchAccessTime(ctx context.Context)

TouchAccessTime updates access time to the current time.

func (*InMemoryAttributes) TouchModificationTime

func (i *InMemoryAttributes) TouchModificationTime(ctx context.Context)

TouchModificationTime updates modification and status change time to the current time.

func (*InMemoryAttributes) TouchStatusChangeTime

func (i *InMemoryAttributes) TouchStatusChangeTime(ctx context.Context)

TouchStatusChangeTime updates status change time to the current time.

type InodeNoExtendedAttributes

type InodeNoExtendedAttributes struct{}

InodeNoExtendedAttributes can be used by Inodes that do not support extended attributes.

func (InodeNoExtendedAttributes) Getxattr

Getxattr implements fs.InodeOperations.Getxattr.

func (InodeNoExtendedAttributes) Listxattr

func (InodeNoExtendedAttributes) Listxattr(*fs.Inode) (map[string]struct{}, error)

Listxattr implements fs.InodeOperations.Listxattr.

func (InodeNoExtendedAttributes) Setxattr

Setxattr implements fs.InodeOperations.Setxattr.

type InodeNotDirectory

type InodeNotDirectory struct{}

InodeNotDirectory can be used by Inodes that are not directories.

func (InodeNotDirectory) Bind

Bind implements fs.InodeOperations.Bind.

func (InodeNotDirectory) Create

Create implements fs.InodeOperations.Create.

func (InodeNotDirectory) CreateDirectory

CreateDirectory implements fs.InodeOperations.CreateDirectory.

func (InodeNotDirectory) CreateFifo

CreateFifo implements fs.InodeOperations.CreateFifo.

func (InodeNotDirectory) CreateHardLink(context.Context, *fs.Inode, *fs.Inode, string) error

CreateHardLink implements fs.InodeOperations.CreateHardLink.

CreateLink implements fs.InodeOperations.CreateLink.

func (InodeNotDirectory) Lookup

Lookup implements fs.InodeOperations.Lookup.

func (InodeNotDirectory) Remove

Remove implements fs.InodeOperations.Remove.

func (InodeNotDirectory) RemoveDirectory

func (InodeNotDirectory) RemoveDirectory(context.Context, *fs.Inode, string) error

RemoveDirectory implements fs.InodeOperations.RemoveDirectory.

type InodeNotOpenable

type InodeNotOpenable struct{}

InodeNotOpenable can be used by Inodes that cannot be opened.

func (InodeNotOpenable) GetFile

GetFile implements fs.InodeOperations.GetFile.

type InodeNotRenameable

type InodeNotRenameable struct{}

InodeNotRenameable can be used by Inodes that cannot be renamed.

func (InodeNotRenameable) Rename

Rename implements fs.InodeOperations.Rename.

type InodeNotSocket

type InodeNotSocket struct{}

InodeNotSocket can be used by Inodes that are not sockets.

func (InodeNotSocket) BoundEndpoint

func (InodeNotSocket) BoundEndpoint(*fs.Inode, string) unix.BoundEndpoint

BoundEndpoint implements fs.InodeOperations.BoundEndpoint.

type InodeNotSymlink struct{}

InodeNotSymlink can be used by Inodes that are not symlinks.

Getlink implements fs.InodeOperations.Getlink.

Readlink implements fs.InodeOperations.Readlink.

type InodeNotVirtual

type InodeNotVirtual struct{}

InodeNotVirtual can be used by Inodes that are not virtual.

func (InodeNotVirtual) IsVirtual

func (InodeNotVirtual) IsVirtual() bool

IsVirtual implements fs.InodeOperations.IsVirtual.

type InodeSimpleAttributes

type InodeSimpleAttributes struct {
	// FSType is the filesystem type reported by StatFS.
	FSType uint64

	// UAttr are the unstable attributes of the Inode.
	UAttr fs.UnstableAttr
}

InodeSimpleAttributes implements a subset of the Inode interface. It provides read-only access to attributes.

func (*InodeSimpleAttributes) AddLink()

AddLink implements fs.InodeOperations.AddLink.

func (*InodeSimpleAttributes) Check

func (i *InodeSimpleAttributes) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool

Check implements fs.InodeOperations.Check.

func (*InodeSimpleAttributes) DropLink()

DropLink implements fs.InodeOperations.DropLink.

func (*InodeSimpleAttributes) NotifyStatusChange

func (i *InodeSimpleAttributes) NotifyStatusChange(ctx context.Context)

NotifyStatusChange implements fs.fs.InodeOperations.

func (*InodeSimpleAttributes) Release

Release implements fs.InodeOperations.Release.

func (*InodeSimpleAttributes) SetOwner

SetOwner implements fs.InodeOperations.SetOwner.

func (*InodeSimpleAttributes) SetPermissions

SetPermissions implements fs.InodeOperations.SetPermissions.

func (*InodeSimpleAttributes) SetTimestamps

SetTimestamps implements fs.InodeOperations.SetTimestamps.

func (*InodeSimpleAttributes) StatFS

StatFS implements fs.InodeOperations.StatFS.

func (*InodeSimpleAttributes) Truncate

Truncate implements fs.InodeOperations.Truncate.

func (*InodeSimpleAttributes) UnstableAttr

UnstableAttr implements fs.InodeOperations.UnstableAttr.

type NoFsync

type NoFsync struct{}

NoFsync implements FileOperations.Fsync for files that don't support syncing.

func (NoFsync) Fsync

Fsync implements FileOperations.Fsync.

type NoIoctl

type NoIoctl struct{}

NoIoctl implements fs.FileOperations.Ioctl for files that don't implement the ioctl syscall.

func (NoIoctl) Ioctl

Ioctl implements fs.FileOperations.Ioctl.

type NoMMap

type NoMMap struct{}

NoMMap implements fs.FileOperations.Mappable for files that cannot be memory mapped.

func (NoMMap) ConfigureMMap

func (NoMMap) ConfigureMMap(context.Context, *fs.File, *memmap.MMapOpts) error

ConfigureMMap implements fs.FileOperations.ConfigureMMap.

type NoMappable

type NoMappable struct{}

NoMappable returns a nil memmap.Mappable.

func (NoMappable) Mappable

func (NoMappable) Mappable(*fs.Inode) memmap.Mappable

Mappable implements fs.InodeOperations.Mappable.

type NoopFlush

type NoopFlush struct{}

NoopFlush implements FileOperations.Flush as a no-op.

func (NoopFlush) Flush

func (NoopFlush) Flush(context.Context, *fs.File) error

Flush implements FileOperations.Flush.

type NoopFsync

type NoopFsync struct{}

NoopFsync implements FileOperations.Fsync for files that don't need to synced.

func (NoopFsync) Fsync

Fsync implements FileOperations.Fsync.

type NoopRelease

type NoopRelease struct{}

NoopRelease implements FileOperations.Release for files that have no resources to release.

func (NoopRelease) Release

func (NoopRelease) Release()

Release is a no-op.

type NoopWriteOut

type NoopWriteOut struct{}

NoopWriteOut is a no-op implementation of Inode.WriteOut.

func (NoopWriteOut) WriteOut

func (NoopWriteOut) WriteOut(context.Context, *fs.Inode) error

WriteOut is a no-op.

type NotDirReaddir

type NotDirReaddir struct{}

NotDirReaddir implements FileOperations.Readdir for non-directories.

func (NotDirReaddir) Readdir

Readdir implements FileOperations.NotDirReaddir.

type PipeSeek

type PipeSeek struct{}

PipeSeek implements FileOperations.Seek and can be used for files that behave like pipes (seeking is not supported).

func (PipeSeek) Seek

Seek implements FileOperations.Seek.

type ZeroSeek

type ZeroSeek struct{}

ZeroSeek implements FileOperations.Seek for files that maintain a constant zero-value offset and require a no-op Seek.

func (ZeroSeek) Seek

Seek implements FileOperations.Seek.

Jump to

Keyboard shortcuts

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