Files
zosstorage/docs/API.md
Jan De Landtsheer 507bc172c2 feat: first-draft preview-capable zosstorage
- CLI: add topology selection (-t/--topology), preview flags (--show/--report), and removable policy override (--allow-removable) (src/cli/args.rs)
- Config: built-in sensible defaults; deterministic overlays for logging, fstab, removable, topology (src/config/loader.rs)
- Device: discovery via /proc + /sys with include/exclude regex and removable policy (src/device/discovery.rs)
- Idempotency: detection via blkid; safe emptiness checks (src/idempotency/mod.rs)
- Partition: topology-driven planning (Single, DualIndependent, BtrfsRaid1, SsdHddBcachefs) (src/partition/plan.rs)
- FS: planning + creation (mkfs.vfat, mkfs.btrfs, bcachefs format) and UUID capture via blkid (src/fs/plan.rs)
- Orchestrator: pre-flight with preview JSON (disks, partition_plan, filesystems_planned, mount scheme). Skips emptiness in preview; supports stdout+file (src/orchestrator/run.rs)
- Util/Logging/Types/Errors: process execution, tracing, shared types (src/util/mod.rs, src/logging/mod.rs, src/types.rs, src/errors.rs)
- Docs: add README with exhaustive usage and preview JSON shape (README.md)

Builds and unit tests pass: discovery, util, idempotency helpers, and fs parser tests.
2025-09-29 11:37:07 +02:00

12 KiB

zosstorage Public API Skeletons

This document defines the initial public API surface for all modules. It lists traits, structs, enums, constants, and functions with responsibilities and behavioral contracts. Implementations are intentionally deferred until approval. Function bodies will be added later and guarded by todo placeholders.

Conventions

  • All modules return a shared Result alias and Error enum.
  • No interactive prompts; APIs are deterministic and suitable for initramfs use.
  • External tooling calls are mediated via utility wrappers.

Module index

Common errors and result

  • enum Error
    • Top-level error type covering parse/validation errors, device discovery errors, partitioning failures, filesystem mkfs errors, mount errors, report write errors, and external tool invocation failures with stderr capture.
  • type Result = std::result::Result<T, Error>
    • Shared result alias across modules.

Crate root

  • src/lib.rs
    • Exposes crate version constants, the prelude, and re-exports common types for consumers of the library (tests/integration). No heavy logic.

Entrypoint

  • fn main()
    • Initializes logging based on CLI defaults, parses CLI flags and kernel cmdline, loads and validates configuration, and invokes the orchestrator run sequence. Avoids stdout; logs via tracing only.

Orchestrator

  • struct Context
    • Aggregates resolved configuration, logging options, and environment flags suited for initramfs execution.
  • fn run(ctx: &Context) -> Result<()>
    • High-level one-shot flow:
      • Idempotency detection
      • Device discovery
      • Partition planning and application
      • Filesystem planning and creation
      • Mount planning and application
      • Report generation and write
    • Aborts the entire run on any validation or execution failure. Returns Ok on successful no-op if already provisioned.

CLI

  • struct Cli
    • Mirrors kernel cmdline semantics with flags:
      • --config PATH
      • --log-level LEVEL
      • --log-to-file
      • --fstab
      • --force (present, returns unimplemented error)
  • fn from_args() -> Cli
    • Parses argv without side effects; suitable for initramfs.

Logging

Configuration types

  • struct Config
    • The validated configuration used by the orchestrator, containing logging, device selection rules, topology, partitioning, filesystem options, mount scheme, and report path.
  • enum Topology
    • Values: single, dual_independent, ssd_hdd_bcachefs, btrfs_raid1 (opt-in).
  • struct DeviceSelection
    • Include and exclude regex patterns, minimum size, removable policy.
  • struct Partitioning
    • Alignment, emptiness requirement, bios_boot, esp, data, cache GPT names and sizes where applicable.
  • struct BtrfsOptions
    • Compression string and raid profile (none or raid1).
  • struct BcachefsOptions
    • Cache mode (promote or writeback), compression, checksum.
  • struct VfatOptions
    • Reserved for ESP mkfs options; includes label ZOSBOOT.
  • struct FsOptions
    • Aggregates BtrfsOptions, BcachefsOptions, VfatOptions and shared defaults such as ZOSDATA label.
  • enum MountSchemeKind
    • Values: per_uuid, custom (future).
  • struct MountScheme
    • Base directory (/var/cache), scheme kind, fstab enabled flag.
  • struct ReportOptions
    • Output path (/run/zosstorage/state.json).

Configuration IO

  • fn load_and_merge(cli: &Cli) -> Result
    • Loads built-in defaults, optionally merges on-disk config, overlays CLI flags, and finally overlays kernel cmdline via zosstorage.config=. Validates the YAML against types and constraints.
  • fn validate(cfg: &Config) -> Result<()>
    • Ensures structural and semantic validity (e.g., disk selection rules not empty, sizes non-zero, supported topology combinations).

Device discovery

Partitioning

Filesystems

Mounting

Reporting

Idempotency

Utilities

Behavioral notes and contracts

  • Safety and idempotency:
    • Partitioning strictly aborts on any pre-existing partition or filesystem signature when require_empty_disks is true.
    • Filesystem creation never proceeds if partitioning validation fails.
    • The orchestrator treats any partial progress as failure; state report is only written on success.
  • Labels and GPT names:
    • ESP partitions are labeled ZOSBOOT (filesystem) and named zosboot (GPT).
    • Data filesystems use label ZOSDATA regardless of backend kind.
    • Cache partitions in bcachefs topology use GPT name zoscache.
  • Topology-specific behavior:
    • single: one data filesystem (btrfs) on the sole disk.
    • dual_independent: two separate btrfs filesystems, one per disk.
    • ssd_hdd_bcachefs: bcachefs spanning SSD (cache/promote) and HDD (backing), labeled ZOSDATA.
    • btrfs_raid1: only when explicitly requested; otherwise default to independent btrfs.

Module dependency overview

flowchart LR
  cli --> config
  config --> orchestrator
  logging --> orchestrator
  orchestrator --> idempotency
  orchestrator --> device
  device --> partition
  partition --> fs
  fs --> mount
  mount --> report
  orchestrator --> report
  util --> partition
  util --> fs
  util --> mount
  util --> idempotency

Status

  • This API surface is ready for code-mode skeleton implementation with todo placeholders in function bodies and comprehensive doc comments.