schfs: the commit barrier, reflink, and attributes with an index over them
The last three phases of the filesystem, which were written together and
touch the same files throughout -- kmount.c, objw.c and vfs.c are each
rewritten by all three -- so they land as one commit rather than three
that could not be built separately.
Durability. A transaction that reaches the platter out of order is worse
than one that never reached it: the uberblock can name a tree whose
blocks are still in the drive's write cache. bdirty/bflush give the
buffer layer an explicit barrier, ideflush issues ATA FLUSH CACHE and
usb_storage_flush the SCSI SYNCHRONIZE CACHE that means the same thing,
and a commit now waits for the data before it writes the root that
points at it. The uberblock groups are read newest-first with fallback,
so a volume whose newest roots are torn mounts at an older one and says
which generations were lost.
Reflink. Extents carry a refcount, so two objects can name the same
blocks and neither frees them while the other holds them. Exposed as
FICLONE -- Linux's ioctl value, so `cp --reflink` works unmodified --
and as cmd/reflink for the case where there is no cp to hand.
Attributes, and the one genuinely new idea here. attr.c stores named
values on an object, reachable through setxattr/getxattr/removexattr at
Linux's syscall numbers. On top of that, schfs_index declares an index
over an attribute name and schfs_query answers "which objects carry this
value" from the B-tree rather than by walking. A query against an
unindexed attribute is refused with an error, never silently answered by
a full scan: a query that quietly becomes a scan is worse than one that
admits it cannot help. cmd/schattr drives both.
Three bugs fixed on the way, each found by the numbers being wrong
rather than by inspection:
- statfs's f_fsid was declared int64[2]. Linux's fsid_t is two *ints*,
so every field after it landed one slot late: userland read f_frsize
out of f_namelen, got 255, and df reported a 32 MB root filesystem
as 1992 KB. It hid for as long as it did because the fields used to
be invented constants, so wrong numbers looked like the usual ones.
- struct inode's nlink was a short against SchFS's uint32, so a file
past 32767 names came back negative -- and iput frees an object
whose count reaches zero. It is an int now, signed on purpose, so an
underflow lands somewhere a check can see rather than wrapping.
- filewrite split every write to fit v1's log. That limit belongs to
the journal, not to writing, and SchFS makes one transaction of
whatever it is handed: a 1 MB write was becoming 170 commits and
170 flushes for nothing. fs_ops carries max_write now, and SchFS
sets no limit.
Also here: a real mount table, so `mount -t schfs /dev/hdb /mnt` shows
up in /proc/mounts -- df looks a path up there before it calls statfs at
all, so a mount missing from that list was invisible to it -- several
volumes mounted at once, snapshots mounted by name, and /proc/fsstat
with an rdtsc-based counter, which is the only instrument fine enough to
see inside a single syscall.
Verified: `make schfs-check` passes in full, including the sweep that
crashes the volume at each of 119 points mid-transaction and requires
every one to mount with exactly its committed data, and the case where
both newest uberblocks are rubbish and the volume still comes back. The
headless boot check passes with 27 [ok] and no failures, on a SchFS root.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
f4d5c671a7
commit
03cc316001
39 changed files with 3942 additions and 550 deletions
|
|
@ -40,6 +40,19 @@ struct schfs_bdev {
|
|||
// blocks from balloc. NULL means unsupported; callers then fall back to
|
||||
// allocating singly and accept the extra extent records.
|
||||
uint64_t (*balloc_run)(void *ctx, uint64_t n);
|
||||
// Optional: make every write issued so far durable, and do not return until
|
||||
// it is. NULL means the backing store has no volatile stage to worry about
|
||||
// -- a memory-backed device, or a host file the tools fsync themselves.
|
||||
//
|
||||
// This is the one hook the format's crash-safety argument actually rests
|
||||
// on. Copy-on-write guarantees that a tree is never half-modified, but only
|
||||
// if the blocks a root points at reach the medium *before* the block that
|
||||
// names that root. Nothing in the ordering of bwrite calls guarantees that:
|
||||
// a drive with a write cache is free to complete them in any order it
|
||||
// likes. Without a barrier between the two, a power cut lands on a newest
|
||||
// uberblock whose tree was never written -- exactly the failure copy-on-
|
||||
// write is supposed to make impossible.
|
||||
int (*bflush)(void *ctx);
|
||||
};
|
||||
|
||||
struct schfs_btree {
|
||||
|
|
@ -93,9 +106,24 @@ struct schfs_cursor {
|
|||
void *blk; // caller-owned, SCHFS_BLKSIZE bytes
|
||||
int depth; // path[depth] is the leaf
|
||||
int valid; // 0 once the walk has run off either end
|
||||
// Which block `blk` currently holds, as far as this cursor knows, or 0 for
|
||||
// "nothing yet". See cur_load: re-reading a block that is already in the
|
||||
// buffer costs a 4 KB copy and a CRC32c over the whole 4 KB, and the code
|
||||
// was paying both on every single access to the current record.
|
||||
//
|
||||
// Cleared by schfs_cursor_init rather than trusted across cursors, because
|
||||
// the buffer belongs to the caller and the *next* caller's contents are not
|
||||
// this cursor's business. Cross-checked against the block header on every
|
||||
// use, so a second cursor sharing the same page cannot fool it either.
|
||||
uint64_t resident;
|
||||
uint64_t epoch; // schfs_tree_epoch when it was loaded
|
||||
struct schfs_path_ent path[SCHFS_MAX_LEVEL + 1];
|
||||
};
|
||||
|
||||
// Every mutation bumps this, retiring every cursor's cached block. See
|
||||
// cur_load in btree.c.
|
||||
extern uint64_t schfs_tree_epoch;
|
||||
|
||||
// `blk` must point at SCHFS_BLKSIZE bytes that outlive the cursor.
|
||||
void schfs_cursor_init(struct schfs_cursor *c, struct schfs_btree *t, void *blk);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue