inode

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ConflictingFileNameSuffix = "\n"

A suffix that can be used to unambiguously tag a file system name. (Unambiguous because U+000A is not allowed in GCS object names.) This is used to refer to the file/symlink in a (file/symlink, directory) pair with conflicting object names.

See also the notes on DirInode.LookUpChild.

View Source
const FileMtimeMetadataKey = gcsx.MtimeMetadataKey

A GCS object metadata key for file mtimes. mtimes are UTC, and are stored in the format defined by time.RFC3339Nano.

View Source
const SymlinkMetadataKey = "gcsfuse_symlink_target"

When this custom metadata key is present in an object record, it is to be treated as a symlink. For use in testing only; other users should detect this with IsSymlink.

Variables

This section is empty.

Functions

func IsDirName

func IsDirName(name string) bool

Does the supplied object name represent a directory (as opposed to a file or symlink)?

func IsSymlink(o *gcs.Object) bool

Does the supplied object represent a symlink inode?

Types

type DirInode

type DirInode interface {
	Inode

	// Look up the direct child with the given relative name, returning
	// information about the object backing the child or whether it exists as an
	// implicit directory. If a file/symlink and a directory with the given name
	// both exist, the directory is preferred. Return a result with
	// !result.Exists() and a nil error if neither is found.
	//
	// Special case: if the name ends in ConflictingFileNameSuffix, we strip the
	// suffix, confirm that a conflicting directory exists, then return a result
	// for the file/symlink.
	//
	// If this inode was created with implicitDirs is set, this method will use
	// ListObjects to find child directories that are "implicitly" defined by the
	// existence of their own descendents. For example, if there is an object
	// named "foo/bar/baz" and this is the directory "foo", a child directory
	// named "bar" will be implied. In this case, result.ImplicitDir will be
	// true.
	LookUpChild(
		ctx context.Context,
		name string) (result LookUpResult, err error)

	// Read some number of entries from the directory, returning a continuation
	// token that can be used to pick up the read operation where it left off.
	// Supply the empty token on the first call.
	//
	// At the end of the directory, the returned continuation token will be
	// empty. Otherwise it will be non-empty. There is no guarantee about the
	// number of entries returned; it may be zero even with a non-empty
	// continuation token.
	//
	// The contents of the Offset and Inode fields for returned entries is
	// undefined.
	ReadEntries(
		ctx context.Context,
		tok string) (entries []fuseutil.Dirent, newTok string, err error)

	// Create an empty child file with the supplied (relative) name, failing with
	// *gcs.PreconditionError if a backing object already exists in GCS.
	CreateChildFile(
		ctx context.Context,
		name string) (o *gcs.Object, err error)

	// Like CreateChildFile, except clone the supplied source object instead of
	// creating an empty object.
	CloneToChildFile(
		ctx context.Context,
		name string,
		src *gcs.Object) (o *gcs.Object, err error)

	// Create a symlink object with the supplied (relative) name and the supplied
	// target, failing with *gcs.PreconditionError if a backing object already
	// exists in GCS.
	CreateChildSymlink(
		ctx context.Context,
		name string,
		target string) (o *gcs.Object, err error)

	// Create a backing object for a child directory with the supplied (relative)
	// name, failing with *gcs.PreconditionError if a backing object already
	// exists in GCS.
	CreateChildDir(
		ctx context.Context,
		name string) (o *gcs.Object, err error)

	// Delete the backing object for the child file or symlink with the given
	// (relative) name and generation number, where zero means the latest
	// generation. If the object/generation doesn't exist, no error is returned.
	//
	// metaGeneration may be set to a non-nil pointer giving a meta-generation
	// precondition, but need not be.
	DeleteChildFile(
		ctx context.Context,
		name string,
		generation int64,
		metaGeneration *int64) (err error)

	// Delete the backing object for the child directory with the given
	// (relative) name.
	DeleteChildDir(
		ctx context.Context,
		name string) (err error)
}

An inode representing a directory, with facilities for listing entries, looking up children, and creating and deleting children. Must be locked for any method additional to the Inode interface.

func NewDirInode

func NewDirInode(
	id fuseops.InodeID,
	name string,
	attrs fuseops.InodeAttributes,
	implicitDirs bool,
	typeCacheTTL time.Duration,
	bucket gcs.Bucket,
	mtimeClock timeutil.Clock,
	cacheClock timeutil.Clock) (d DirInode)

Create a directory inode for the name, representing the directory containing the objects for which it is an immediate prefix. For the root directory, this is the empty string.

If implicitDirs is set, LookUpChild will use ListObjects to find child directories that are "implicitly" defined by the existence of their own descendents. For example, if there is an object named "foo/bar/baz" and this is the directory "foo", a child directory named "bar" will be implied.

If typeCacheTTL is non-zero, a cache from child name to information about whether that name exists as a file/symlink and/or directory will be maintained. This may speed up calls to LookUpChild, especially when combined with a stat-caching GCS bucket, but comes at the cost of consistency: if the child is removed and recreated with a different type before the expiration, we may fail to find it.

The initial lookup count is zero.

REQUIRES: IsDirName(name)

type ExplicitDirInode

type ExplicitDirInode interface {
	DirInode
	SourceGeneration() Generation
}

An inode representing a directory backed by an object in GCS with a specific generation.

func NewExplicitDirInode

func NewExplicitDirInode(
	id fuseops.InodeID,
	o *gcs.Object,
	attrs fuseops.InodeAttributes,
	implicitDirs bool,
	typeCacheTTL time.Duration,
	bucket gcs.Bucket,
	mtimeClock timeutil.Clock,
	cacheClock timeutil.Clock) (d ExplicitDirInode)

Create an explicit dir inode backed by the supplied object. See notes on NewDirInode for more.

type FileInode

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

func NewFileInode

func NewFileInode(
	id fuseops.InodeID,
	o *gcs.Object,
	attrs fuseops.InodeAttributes,
	bucket gcs.Bucket,
	syncer gcsx.Syncer,
	tempDir string,
	mtimeClock timeutil.Clock) (f *FileInode)

Create a file inode for the given object in GCS. The initial lookup count is zero.

REQUIRES: o != nil REQUIRES: o.Generation > 0 REQUIRES: o.MetaGeneration > 0 REQUIRES: len(o.Name) > 0 REQUIRES: o.Name[len(o.Name)-1] != '/'

func (*FileInode) Attributes

func (f *FileInode) Attributes(
	ctx context.Context) (attrs fuseops.InodeAttributes, err error)

LOCKS_REQUIRED(f.mu)

func (*FileInode) DecrementLookupCount

func (f *FileInode) DecrementLookupCount(n uint64) (destroy bool)

LOCKS_REQUIRED(f.mu)

func (*FileInode) Destroy

func (f *FileInode) Destroy() (err error)

LOCKS_REQUIRED(f.mu)

func (*FileInode) ID

func (f *FileInode) ID() fuseops.InodeID

func (*FileInode) IncrementLookupCount

func (f *FileInode) IncrementLookupCount()

LOCKS_REQUIRED(f.mu)

func (*FileInode) Lock

func (f *FileInode) Lock()

func (*FileInode) Name

func (f *FileInode) Name() string

func (*FileInode) Read

func (f *FileInode) Read(
	ctx context.Context,
	dst []byte,
	offset int64) (n int, err error)

Serve a read for this file with semantics matching io.ReaderAt.

The caller may be better off reading directly from GCS when f.SourceGenerationIsAuthoritative() is true.

LOCKS_REQUIRED(f.mu)

func (*FileInode) SetMtime added in v0.10.0

func (f *FileInode) SetMtime(
	ctx context.Context,
	mtime time.Time) (err error)

Set the mtime for this file. May involve a round trip to GCS.

LOCKS_REQUIRED(f.mu)

func (*FileInode) Source

func (f *FileInode) Source() *gcs.Object

Return a record for the GCS object from which this inode is branched. The record is guaranteed not to be modified, and users must not modify it.

LOCKS_REQUIRED(f.mu)

func (*FileInode) SourceGeneration

func (f *FileInode) SourceGeneration() (g Generation)

Equivalent to the generation returned by f.Source().

LOCKS_REQUIRED(f)

func (*FileInode) SourceGenerationIsAuthoritative

func (f *FileInode) SourceGenerationIsAuthoritative() bool

If true, it is safe to serve reads directly from the object given by f.Source(), rather than calling f.ReadAt. Doing so may be more efficient, because f.ReadAt may cause the entire object to be faulted in and requires the inode to be locked during the read.

LOCKS_REQUIRED(f.mu)

func (*FileInode) Sync

func (f *FileInode) Sync(ctx context.Context) (err error)

Write out contents to GCS. If this fails due to the generation having been clobbered, treat it as a non-error (simulating the inode having been unlinked).

After this method succeeds, SourceGeneration will return the new generation by which this inode should be known (which may be the same as before). If it fails, the generation will not change.

LOCKS_REQUIRED(f.mu)

func (*FileInode) Truncate

func (f *FileInode) Truncate(
	ctx context.Context,
	size int64) (err error)

Truncate the file to the specified size.

LOCKS_REQUIRED(f.mu)

func (*FileInode) Unlock

func (f *FileInode) Unlock()

func (*FileInode) Write

func (f *FileInode) Write(
	ctx context.Context,
	data []byte,
	offset int64) (err error)

Serve a write for this file with semantics matching fuseops.WriteFileOp.

LOCKS_REQUIRED(f.mu)

type Generation added in v0.11.0

type Generation struct {
	Object   int64
	Metadata int64
}

A particular generation of a GCS object, consisting of both a GCS object generation number and meta-generation number. Lexicographically ordered on the two.

Cf. https://cloud.google.com/storage/docs/generations-preconditions

func (Generation) Compare added in v0.11.0

func (g Generation) Compare(other Generation) int

Return -1, 0, or 1 according to whether g is less than, equal to, or greater than other.

type GenerationBackedInode added in v0.11.0

type GenerationBackedInode interface {
	Inode

	// Requires the inode lock.
	SourceGeneration() Generation
}

An inode that is backed by a particular generation of a GCS object.

type Inode

type Inode interface {
	// All methods below require the lock to be held unless otherwise documented.
	sync.Locker

	// Return the ID assigned to the inode.
	//
	// Does not require the lock to be held.
	ID() fuseops.InodeID

	// Return the name of the GCS object backing the inode. This may be "foo/bar"
	// for a file, or "foo/bar/" for a directory.
	//
	// Does not require the lock to be held.
	Name() string

	// Increment the lookup count for the inode. For use in fuse operations where
	// the kernel expects us to remember the inode.
	IncrementLookupCount()

	// Return up to date attributes for this inode.
	Attributes(ctx context.Context) (fuseops.InodeAttributes, error)

	// Decrement the lookup count for the inode by the given amount.
	//
	// If this method returns true, the lookup count has hit zero and the
	// Destroy() method should be called to release any local resources, perhaps
	// after releasing locks that should not be held while blocking.
	DecrementLookupCount(n uint64) (destroy bool)

	// Clean up any local resources used by the inode, putting it into an
	// indeterminate state where no method should be called except Unlock.
	//
	// This method may block. Errors are for logging purposes only.
	Destroy() (err error)
}

type LookUpResult

type LookUpResult struct {
	// For both object-backed children and implicit directories, the full
	// canonical name of the child. For example, if the parent inode is "foo/"
	// and the child is a directory, then this is "foo/bar/".
	//
	// Guaranteed to be present only if Exists().
	FullName string

	// The backing object for the child, if any. If the child is not found or
	// exists only as an implicit directory, this is nil.
	Object *gcs.Object

	// Does the child exist as a directory implicitly defined by its own
	// descendents? Meaningful only if Object is nil and implicit directories are
	// enabled for the parent inode.
	ImplicitDir bool
}

The result of looking up a child within a directory inode. See notes on DirInode.LookUpChild for more info.

func (*LookUpResult) Exists

func (lr *LookUpResult) Exists() bool

Return true iff the result indicates that the child exists, explicitly or implicitly.

type SymlinkInode

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

func NewSymlinkInode

func NewSymlinkInode(
	id fuseops.InodeID,
	o *gcs.Object,
	attrs fuseops.InodeAttributes) (s *SymlinkInode)

Create a symlink inode for the supplied object record.

REQUIRES: IsSymlink(o)

func (*SymlinkInode) Attributes

func (s *SymlinkInode) Attributes(
	ctx context.Context) (attrs fuseops.InodeAttributes, err error)

func (*SymlinkInode) DecrementLookupCount

func (s *SymlinkInode) DecrementLookupCount(n uint64) (destroy bool)

LOCKS_REQUIRED(s.mu)

func (*SymlinkInode) Destroy

func (s *SymlinkInode) Destroy() (err error)

LOCKS_REQUIRED(s.mu)

func (*SymlinkInode) ID

func (s *SymlinkInode) ID() fuseops.InodeID

func (*SymlinkInode) IncrementLookupCount

func (s *SymlinkInode) IncrementLookupCount()

LOCKS_REQUIRED(s.mu)

func (*SymlinkInode) Lock

func (s *SymlinkInode) Lock()

func (*SymlinkInode) Name

func (s *SymlinkInode) Name() string

func (*SymlinkInode) SourceGeneration

func (s *SymlinkInode) SourceGeneration() Generation

Return the object generation from which this inode was branched.

LOCKS_REQUIRED(s)

func (*SymlinkInode) Target

func (s *SymlinkInode) Target() (target string)

Return the target of the symlink.

func (*SymlinkInode) Unlock

func (s *SymlinkInode) Unlock()

Jump to

Keyboard shortcuts

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