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
|
|
@ -30,6 +30,11 @@
|
|||
#define IDE_CMD_WRITE_EXT 0x34
|
||||
#define IDE_CMD_RDMUL_EXT 0x29
|
||||
#define IDE_CMD_WRMUL_EXT 0x39
|
||||
// FLUSH CACHE, and the form a drive using 48-bit addressing wants. Neither
|
||||
// takes an address; the difference is only which one a given drive admits to
|
||||
// supporting, so ideflush tries the plain one and falls back.
|
||||
#define IDE_CMD_FLUSH 0xe7
|
||||
#define IDE_CMD_FLUSH_EXT 0xea
|
||||
|
||||
// idequeue points to the buf now being read/written to the disk.
|
||||
// idequeue->qnext points to the next buf to be processed.
|
||||
|
|
@ -248,10 +253,69 @@ ideintr(void)
|
|||
// Start disk on next buf in queue.
|
||||
if(idequeue != 0)
|
||||
idestart(idequeue);
|
||||
else
|
||||
wakeup(&idequeue); // ideflush waits for the channel to go quiet
|
||||
|
||||
release(&idelock);
|
||||
}
|
||||
|
||||
// FLUSH CACHE: do not return until the drive has committed what it has taken
|
||||
// to the medium.
|
||||
//
|
||||
// Every layer above this driver assumes a write that has returned is on the
|
||||
// disk. On a drive with a volatile write cache that is simply not true, and it
|
||||
// is the assumption SchFS's whole crash-safety argument rests on: copy-on-write
|
||||
// promises that a crash lands on either the old tree or the new one, but only
|
||||
// if the tree blocks reach the platter before the uberblock that names them.
|
||||
// The drive is otherwise free to write them in whatever order suits its head,
|
||||
// and a power cut then leaves a newest uberblock -- correctly checksummed --
|
||||
// pointing at a tree that was never written. Nothing can recover from that,
|
||||
// because nothing about it looks wrong.
|
||||
//
|
||||
// Polled rather than queued: it moves no data, so it does not fit idestart's
|
||||
// shape, and it is rare enough that the simplest correct thing wins.
|
||||
int
|
||||
ideflush(int dev)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
if(dev == 0 ? !havedisk0 : !havedisk1)
|
||||
return 0; // nothing there is nothing to flush
|
||||
|
||||
acquire(&idelock);
|
||||
|
||||
// The channel has to be idle. This talks straight to the registers, and
|
||||
// issuing it underneath a queued transfer would corrupt that transfer's
|
||||
// handshake rather than merely delay it.
|
||||
while(idequeue != 0)
|
||||
sleep(&idequeue, &idelock);
|
||||
|
||||
outb(0x3f6, 2); // nIEN: this command answers by status, not IRQ
|
||||
outb(0x1f6, 0xe0 | ((dev & 1) << 4));
|
||||
if(idewait(0) < 0){
|
||||
r = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
outb(0x1f7, IDE_CMD_FLUSH);
|
||||
// A drive with a full write cache can take seconds over this, which is the
|
||||
// other reason idewait's bound is as large as it is.
|
||||
if(idewait(1) < 0){
|
||||
// Drives that came up in 48-bit mode may abort the 28-bit spelling. Same
|
||||
// operation, and there is no third option, so a failure here is real.
|
||||
outb(0x1f7, IDE_CMD_FLUSH_EXT);
|
||||
if(idewait(1) < 0){
|
||||
cprintf("ide%d: FLUSH CACHE failed; writes are not durable\n", dev);
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
outb(0x3f6, 0); // interrupts back on for ordinary transfers
|
||||
release(&idelock);
|
||||
return r;
|
||||
}
|
||||
|
||||
//PAGEBREAK!
|
||||
// Sync buf with disk.
|
||||
// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
|
||||
|
|
|
|||
Loading…
Reference in a new issue