Skip to content

Add storage API #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Add storage API #210

wants to merge 15 commits into from

Conversation

gibmat
Copy link
Collaborator

@gibmat gibmat commented Jul 29, 2025

Adds a preliminary storage API:

  • /1.0/system/storage:
    • GET returns details about each drive and the status of each zpool
    • PUT creates/updates a new zpool
    • DELETE destroys a zpool and runs blkdiscard on its former members
  • /1.0/system/security:
    • GET also returns base64 encoded zpool encryption keys

Closes #145

@gibmat gibmat force-pushed the add-storage-api branch from dc2a4d4 to 1537e07 Compare July 30, 2025 14:20
@gibmat gibmat marked this pull request as ready for review July 30, 2025 14:20
// SystemStorage defines a struct to hold information about the system's local storage.
type SystemStorage struct {
State struct {
SMARTStatus map[string]json.RawMessage `json:"smart_status" yaml:"smart_status"`
Copy link
Member

@stgraber stgraber Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be more work, but I think we should try to abstract things a bit more.

Basically having a Drives []SystemStorageDrive with each drive then including at least:

  • ID
  • Manufacturer
  • Model
  • Serial number
  • Bus
  • Removable
  • WWN
  • SMART status
  • Pool

We'll also want to do a bit of filtering.
For example, if we find a multipath device, we should only show the ID for the multipath device itself and exclude all of the individual drives that are part of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got a pretty good solution for this, although it will be interesting to see if any fields are missing/incorrect across wider hardware.

lsblk has a merge option (-M), which supposedly should handle cases like multipath devices and only show the actual device, but we'll need to test that.

)

// SystemStorage defines a struct to hold information about the system's local storage.
type SystemStorage struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think defining and updating pools should be done through the Config struct same we do elsewhere.

So having something like:

Config {
    Pools [
        Pool {
            Name: "local-nvme",
            Type: "zfs-raidz1",
            Devices: ["dev1", "dev2"],
        }
        Pool {
            Name: "local-nvme",
            Type: "zfs-raidz2",
            Devices: ["dev1", "dev2", "dev3", "dev4", "dev5"],
            Cache: ["dev6", "dev7"],
            Log: ["dev8", "dev9"],
        }
    ]
}

We'd define those types for now:

  • zfs-raid0 (stripe across all devices)
  • zfs-raid1 (mirror across all devices)
  • zfs-raid10 (stripe across pairs of devices)
  • zfs-raidz1
  • zfs-raidz2
  • zfs-raidz3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacement operations would then literally be a PUT to the config, replacing one drive ID with another. Same would go for device addition or removal (when supported).

@stgraber
Copy link
Member

stgraber commented Aug 1, 2025

Looks like there's a small test migration related to the state

gibmat added 15 commits August 1, 2025 08:18
Too much muscle memory typing apt :)

Signed-off-by: Mathias Gibbens <[email protected]>
@stgraber
Copy link
Member

stgraber commented Aug 1, 2025

Static analysis isn't happy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Define a storage API
2 participants