Files
CephfsMig/internal/storage/fs.go
T
Sebastian UnterschützandClaude Opus 5.5 02ebc08c88 feat(native): preserve access and birth time of every entry
Read atime and btime with statx and set them together with owner,
mode and mtime. Verification compares both, so a published snapshot
must match the source in all three times. The integration fixture
compares the times through libcephfs, since ceph-fuse does not expose
the birth time.

The ctime cannot be preserved: Ceph 21.2.0 accepts CEPH_SETATTR_CTIME
but stores the time of the call. The rsync backend still preserves
only the mtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:48:25 +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 and birth time. The change time is not part of
// Node because no filesystem interface allows setting it.
Atime, Mtime, 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, atime, mtime and btime; 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 }