code wiki / _hdl_build / nx_raidwatch.nx
nx_raidwatch.nx
buildroot/runtime/_hdl_build/nx_raidwatch.nx
about
nx_raidwatch.nx -- ARRAY + KERNEL-IO HEALTH BEAT. The estate had NONE.
WHY THIS EXISTS (2026-08-07). A grep across every organ for mdstat, smartctl or raid returned only
substring false positives (a bip39 wordlist, a chemistry table). Nothing in a 140 TB estate was
watching whether its arrays were intact. Two live faults were sitting there unwatched:
md3 (raid1, the NVMe mirror) DEGRADED [2/1] [_U] -- one member gone, /dev/nvme0n1p1 has no
device node at all, so it cannot even be re-added without physical intervention. It was
recorded in a memory file and NOTHING CHECKED IT, which is the difference between a note and
a monitor.
sata8 throwing repeated UNC (uncorrectable) read errors on ONE sector, 840 kernel records over
four hours, while the array it backs still reports [8/8] because raid5 keeps reconstructing
the block from parity. A disk can be failing loudly while every array metric reads healthy.
ROOT-FREE BY CONSTRUCTION, because the beat runs as the estate user:
/sys/block/<md>/md/degraded, raid_disks, level, mismatch_cnt -- structured integers, no text
parsing of /proc/mdstat, so this cannot be broken by a format change.
/dev/kmsg -- readable here, opened O_NONBLOCK so the final read returns EAGAIN instead of
BLOCKING FOREVER at the end of the buffer. A monitor that can hang is not a monitor.
smartctl is present but needs root (open of /dev/sata8 = Permission denied, measured), so
per-disk SMART is deliberately OUT OF SCOPE here rather than silently half-working.
REFUSES if it can read neither surface: ignorance is not health, and a GREEN produced by an
unreadable sysfs would be worse than no beat at all.
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_raidwatch_gate.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 26 | const RW_MAXMD: i64 = 16 |
| 27 | const RW_MAXSECT: i64 = 256 |
| 28 | const RW_KMSG_RECS: i64 = 8192 |
| 29 | const RW_RECBUF: i64 = 8192 |
| 30 | const RW_SMALL: i64 = 64 |
| 31 | const RW_PATH: i64 = 256 |
| 32 | const RW_O_NONBLOCK: i64 = 2048 |
| 33 | const RW_AT_FDCWD: i64 = 0 - 100 |
| 34 | const RW_SYS_OPENAT: i64 = 257 |
| 35 | const RW_EXIT_RED: i64 = 6 |
| 36 | const RW_EXIT_AMBER: i64 = 4 |
| 37 | const RW_EXIT_NODATA: i64 = 5 |
| 38 | const RW_DIRBUF: i64 = 65536 // getdents64 batch for the per-member walk |
| 39 | const RW_RECLEN_OFF: i64 = 16 // linux_dirent64.d_reclen |
| 40 | const RW_NAME_OFF: i64 = 19 // linux_dirent64.d_name |
| 50 | const RW_STATUS: *u8 = "knowledge/status/raidwatch.status" |
| 51 | const RW_STATBUF: i64 = 1024 |
functions
| 55 | func rw_verdict_code(degraded: i64, ioerr: i64, memberbad: i64, mismatched: i64) -> i64 |
| 62 | func rw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 63 | func rwe(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 } |
| 64 | func rwn(v: i64) -> i64 |
| 81 | func rw_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o + i] = s[i]; i = i + 1 } return o + i } |
| 83 | func rw_catn(d: *u8, o: i64, v: i64) -> i64 |
| 102 | func rw_sysint(path: *u8) -> i64 |
| 123 | func rw_sysstr(path: *u8, dst: *u8, cap: i64) -> i64 |
| 135 | func rw_after(buf: *u8, n: i64, key: *u8) -> i64 called by 1: main |
| 164 | func rw_has(buf: *u8, n: i64, lit: *u8) -> i64 |
| 196 | func rw_member_scan(mdnum: i64, out: *i64) -> i64 |
| 245 | func main(argc: i64, argv: *i64) -> i64 |