gizhw:block
NVMe controllers through the kernel's passthrough ioctls (NVME_IOCTL_ADMIN_CMD and NVME_IOCTL_IO_CMD on the controller's node, /dev/nvmeN): Identify (the controller), the SMART health log, and a read of blocks by passthrough. The command is struct nvme_admin_cmd or nvme_passthru_cmd (72 bytes, the same layout), and the ioctls are the kernel's (linux/nvme_ioctl.h, checked against it). Every call is on a Handle of gizhw:device.
import * as Block from "gizhw:block";Types
Controller
type Controller = { vendor: i64; serial: string; model: string; firmware: string; capacity: i64; namespaces: i64; }The controller's identity: vendor id, serial, model, firmware, total capacity in bytes, namespace count.
vendor:i64serial:stringmodel:stringfirmware:stringcapacity:i64namespaces:i64
Smart
type Smart = { warning: i64; temperature: i64; spare: i64; percentUsed: i64; dataUnitsRead: i64; dataUnitsWritten: i64; powerOnHours: i64; unsafeShutdowns: i64; mediaErrors: i64; }The SMART / health log: warning bits, temperature in degrees C, spare percent, percent used, data units (512,000 bytes each) read and written, power-on hours, unsafe shutdowns, and media errors.
warning:i64temperature:i64spare:i64percentUsed:i64dataUnitsRead:i64dataUnitsWritten:i64powerOnHours:i64unsafeShutdowns:i64mediaErrors:i64
Functions
command
function command(opcode: i64, nsid: u64, addr: u64, length: i64, dwords: Vec<i64>): bytesA passthrough command: the opcode, the namespace, the data buffer (addr, length bytes), and up to six command
dwords (cdw10 to cdw15).
Effects: fail.
parseController
function parseController(data: bytes): ControllerThe controller from the Identify reply (4096 bytes): vendor id, serial (bytes 4 to 24), model (24 to 64), firmware (64 to 72), total capacity (the low 8 bytes at 280) and the namespace count (516).
Effects: fail.
parseSmart
function parseSmart(data: bytes): SmartThe SMART log from its reply (512 bytes). The temperature is the composite one, in Kelvin in the log.
Effects: fail.
controller
function controller(h: Device.Handle): Controller throws stringThe controller behind h: Identify with CNS 1.
Effects: fail, io.
smart
function smart(h: Device.Handle): Smart throws stringThe SMART / health log of the controller behind h (all namespaces).
Effects: fail, io.
read
function read(h: Device.Handle, nsid: u64, lba: i64, blocks: i64, blockBytes: i64): bytes throws stringblocks blocks of blockBytes each, from block lba of namespace nsid, by IO passthrough (a read).
Effects: fail, io.
open
function open(sys: System, node: string): Device.Handle throws stringThe handle on the controller's node (read-write, which the passthrough ioctls need).
Effects: fail, io.
controllers
function controllers(sys: System): Vec<Device.Device> throws IoErrorThe NVMe controllers of the nvme class, with their nodes.
Effects: fail, io.