// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial /** * The volume spec every storage operation shares: which disk, mounted where * and which subtrees opt out of compression. * * btrfs compresses in 128 KiB extents while a SQLite page read is 4 KiB, * so a random page read decompresses the whole extent. * The retrieval databases are built once and then read randomly. * * That access pattern pays the amplification on every read, so they opt out through a btrfs property. * The property leaves copy-on-write and checksums in place, where `chattr +C` drops both. * * One entry rather than a list of every directory that happens to hold a database. * The property propagates to children created after it is set, at any depth, so a database * written into `db/` next year is uncompressed without anyone remembering to extend a list. * * The flat alternative was already wrong when it was written: it listed eight directories * and missed `address-points` and `interpolation`, which hold 54 and 52 databases. */ import type { ParseArgsOptionsConfig } from "@mailwoman/core/scripting/arguments" import { z } from "zod" import { DEFAULT_MOUNT_OPTIONS } from "#storage-kit/fstab" import { commaList } from "#storage-kit/inputs" /** * Which disk, mounted where, with which subtrees opting out of compression. * * Shared by every storage operation so one invocation's flags describe the same volume as the next. */ export const volumeSpec = z.object({ device: z.string().describe("The block device to prepare, e.g. /dev/sda."), serial: z.string().describe("The serial the device must report, from `lsblk -dno SERIAL`."), transport: z.string().default("usb").describe("The transport the device must report."), model: z.string().optional().describe("A substring the device model must contain."), label: z.string().default("mw").describe("The btrfs filesystem label."), "mount-point": z.string().default("/mnt/mw").describe("Where the volume mounts."), options: commaList(DEFAULT_MOUNT_OPTIONS).describe("Mount options written to /etc/fstab."), uncompressed: commaList(["db"]).describe( "Subtrees, relative to the mount point, that opt out of compression because they hold SQLite." ), owner: z.string().optional().describe("The user that should own the mount point. Defaults to the sudo invoker."), }) export type VolumeSpec = z.infer /** * The `mwops storage` flags for {@linkcode volumeSpec}, one per key. */ export const VOLUME_OPTIONS = { device: { type: "string" }, serial: { type: "string" }, transport: { type: "string" }, model: { type: "string" }, label: { type: "string" }, "mount-point": { type: "string" }, options: { type: "string" }, uncompressed: { type: "string" }, owner: { type: "string" }, } as const satisfies ParseArgsOptionsConfig