Files
CephfsMig/internal/storage/fs.go
T
Sebastian UnterschützandClaude Opus 5.5 cc2dff46a0 feat(native): preserve ctime of files, directories and symlinks
The MDS takes an inode's ctime from the time stamp the client sends with
each request. The native backend overrides clock_gettime per thread and
per libcephfs call: modifying calls run at 1970-01-01T00:00:01Z, and the
last change to each entry creates and removes the xattr
user.cephmig.ctime stamped with the source ctime. Link, unlink, rename
and xattr requests set ctime = max(stamp, mtime), also backwards.

- write xattrs and quotas before SetAttr, which must come last
- always restamp directories after their children and hardlinks after
  linking or pruning, since the writer's cache may be stale
- verify through a separate, freshly mounted target client
- name the differing attributes in metadata mismatch errors
- compare ctime of every entry, the root included, in the lab fixture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 19:33:19 +01:00

99 lines
2.6 KiB
Go

// Package storage defines the native filesystem operations used by the copier.
package storage
import (
"io"
"time"
)
// Node holds the inode attributes the copier needs.
type Node struct {
Mode uint32
Inode, Version, Nlink, Size, Rdev uint64
UID, GID uint32
// Access, modification, change and birth time. SetAttr sets the change
// time to Ctime, but not below Mtime.
Atime, Mtime, Ctime, Btime time.Time
}
// File type bits of Node.Mode, as in stat(2).
const (
TypeMask uint32 = 0170000
Regular uint32 = 0100000
Directory uint32 = 0040000
Symlink uint32 = 0120000
FIFO uint32 = 0010000
Socket uint32 = 0140000
BlockDevice uint32 = 0060000
CharDevice uint32 = 0020000
)
// Kind returns the file type bits of n.Mode.
func (n Node) Kind() uint32 { return n.Mode & TypeMask }
// Entry is a single directory entry.
type Entry struct {
Name string
Node Node
}
// DirectoryStream iterates over a directory. Next returns io.EOF at the end.
type DirectoryStream interface {
Next() (*Entry, error)
Close() error
}
// File is an open regular file.
type File interface {
io.ReaderAt
io.WriterAt
io.Closer
Truncate(int64) error
Sync() error
Lock(uint64) error
PunchHole(int64, int64) error
}
// DiffStream yields the paths that differ between two snapshots.
type DiffStream interface {
Next() (string, error)
Close() error
}
// Extent is a changed byte range of a file.
type Extent struct{ Offset, Length uint64 }
// BlockStream yields batches of changed extents between two snapshots.
type BlockStream interface {
Next() ([]Extent, error)
Close() error
}
// FS is the filesystem interface implemented by the native libcephfs client.
type FS interface {
Stat(string) (Node, error) // Never follows the final symlink.
Open(string, int, uint32) (File, error)
OpenDir(string) (DirectoryStream, error)
Mkdir(string, uint32) error
Unlink(string) error
Rmdir(string) error
Rename(string, string) error
Link(string, string) error
Symlink(string, string) error
Readlink(string) (string, error)
Mknod(string, uint32, uint64) error
SetAttr(string, Node) error // Numeric owner, mode, all four times; no symlink following.
ListXattr(string) ([]string, error)
GetXattr(string, string) ([]byte, error)
SetXattr(string, string, []byte) error
RemoveXattr(string, string) error
SnapDiff(string, string, string, string) (DiffStream, error)
BlockDiff(string, string, string, string) (BlockStream, error)
Sync() error
Close() error
}
// Options identifies the cluster, credentials and filesystem to connect to.
type Options struct{ Config, Keyring, User, Filesystem string }