Metadata-Version: 2.1
Name: ohr
Version: 0.0.1
Summary: Open Hardware Raid - a free software RAID management CLI
Home-page: UNKNOWN
Author: Open Hardware Raid contributors
License: GPL-2.0-or-later
Platform: UNKNOWN
Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Hardware
Requires-Python: >=3.5
License-File: LICENSE

# Open Hardware Raid (ohr)

A free software (GPL-2.0-or-later) RAID management command line
interface for SAS RAID controllers that speak the MFI management
interface of the Linux `megaraid_sas` driver, directly through
`/dev/megaraid_sas_ioctl_node`.

`ohr` is command-line compatible with the controllers' proprietary
management utility (JSON machine output byte-exact; human output
rendered OpenStack-style), so existing scripts and runbooks keep
working. On top of the compatible surface sits a friendlier
OpenStack-style CLI (`ohr controller list`, `ohr disk show`, ...) - see
the Friendly CLI section below and `docs/ohr.1.rst`.

Why a new tool? The controllers' current proprietary management
utility is widely regarded as cumbersome and unpleasant to work with,
yet it is the only maintained option: its predecessor is no longer
maintained, and the current utility does not support very old
controller generations that are still running reliably in production.
`ohr` fills that gap with a free software, scriptable and friendly
management CLI, for that older hardware as much as for recent
controllers.

## Table of Contents

- [Compatibility](#compatibility)
- [Friendly CLI](#friendly-cli)
- [Status](#status)
- [Implementation notes](#implementation-notes)
- [Legal basis](#legal-basis)
- [Hardware-blocked coverage gaps](#hardware-blocked-coverage-gaps)

## Compatibility

- Python 3.5+ (Debian Stretch, pbr 1.8.0): no f-strings, no variable
  annotations, no 3.6+ dict ordering assumptions - the JSON renderer
  uses OrderedDict / explicit templates to stay byte-exact.
- pbr is a build-time-only dependency; at runtime the package is stdlib +
  cliff + oslo.* only.

## Friendly CLI

Everything that does not start with a `/cX` selector is a friendly,
discoverable surface: multi-word commands, argparse help, cliff
formatters (`--format table|json|csv|value|shell`) and one shared ID
resolution rule - omit the selector and the lone object is picked,
ambiguity fails fast with the candidate ids, `all` fans out:

```bash
ohr controller list
ohr controller show --format json
ohr disk list --controller all
ohr disk list --long
ohr disk set 14 --offline
ohr vd set 0 --wrcache write-back --rdcache read-ahead
ohr vd create --raid-level 1 --disks 14,15
ohr vd delete 0 --yes-i-really-mean-it
ohr vd init 0 --full --yes-i-really-mean-it
ohr battery show
ohr events list --latest 20 --severity warning
ohr controller foreign-config import --yes-i-really-mean-it
ohr tui
```

A taste of the output (with a fictional drive brand and serials):

```text
$ ohr disk list
+------------+---------+-----+------------------+----------------+-------+------------+--------+-----------+
| Controller | EID:Slt | DID | Model            | Serial         | Media | Size       | State  | Interface |
+------------+---------+-----+------------------+----------------+-------+------------+--------+-----------+
| 0          | 134:2   | 45  | TWOSTARS SATA960 | TWOSTARS000042 | SSD   | 893.750 GB | Online | SATA      |
| 0          | 134:6   | 46  | TWOSTARS SATA960 | TWOSTARS000043 | SSD   | 893.750 GB | Online | SATA      |
+------------+---------+-----+------------------+----------------+-------+------------+--------+-----------+

$ ohr disk show 45
+---------------------+------------------+
| Field               | Value            |
+---------------------+------------------+
| EID:Slot            | 134:2            |
| Device_ID           | 45               |
| Model               | TWOSTARS SATA960 |
| Serial_Number       | TWOSTARS000042   |
| Media_Type          | SSD              |
| Interface           | SATA             |
| Coerced_Size        | 893.750 GB       |
| Raw_Size            | 894.253 GB       |
| Sector_Size         | 512B             |
| SAS_Address         | 42c0ffee00000045 |
| Firmware_State      | Online           |
| Media_Errors        | 0                |
| Other_Errors        | 0                |
| Predictive_Failures | 0                |
| Drive_Temperature   | 33 C             |
+---------------------+------------------+

$ ohr vd list
+----+------+----------+-------+-------+--------+
| VD | Name | Size     | Type  | State | Access |
+----+------+----------+-------+-------+--------+
| 0  |      | 1.745 TB | RAID0 | Optl  | RW     |
+----+------+----------+-------+-------+--------+

$ ohr vd show 0
+------------------------------+----------------------------------+
| Field                        | Value                            |
+------------------------------+----------------------------------+
| Virtual_Drive                | 0                                |
| Name                         |                                  |
| Size                         | 1.745 TB                         |
| Type                         | RAID0                            |
| State                        | Optl                             |
| Strip_Size                   | 256 KB                           |
| Number_of_Blocks             | 3748659200                       |
| VD_has_Emulated_PD           | No                               |
| Span_Depth                   | 1                                |
| Number_of_Drives_Per_Span    | 2                                |
| Write_Cache(initial_setting) | WriteBack                        |
| Disk_Cache_Policy            | Disk's Default                   |
| Encryption                   | None                             |
| Data_Protection              | None                             |
| Active_Operations            | None                             |
| Exposed_to_OS                | Yes                              |
| OS_Drive_Name                | /dev/sda                         |
| Creation_Date                | 05-11-2026                       |
| Creation_Time                | 02:08:58 PM                      |
| Emulation_type               | default                          |
| Cachebypass_size             | Cachebypass-64k                  |
| Cachebypass_Mode             | Cachebypass Intelligent          |
| Is_LD_Ready_for_OS_Requests  | Yes                              |
| SCSI_NAA_Id                  | 42c0ffee0000000042c0ffee00000042 |
| Unmap_Enabled                | No                               |
| Consistency_Check            | Not in progress                  |
| Background_Initialization    | Not in progress                  |
| Foreground_Initialization    | Not in progress                  |
| Reconstruction               | Not in progress                  |
+------------------------------+----------------------------------+
```

For scripting, every command accepts `-f json` — the OpenStack CLI way
(piped through jq below, which also colors it in a terminal):

```text
$ ohr disk list -f json | jq .
[
  {
    "Controller": 0,
    "EID:Slt": "134:2",
    "DID": 45,
    "Model": "TWOSTARS SATA960",
    "Serial": "TWOSTARS000042",
    "Media": "SSD",
    "Size": "893.750 GB",
    "State": "Online",
    "Interface": "SATA"
  },
  {
    "Controller": 0,
    "EID:Slt": "134:6",
    "DID": 46,
    "Model": "TWOSTARS SATA960",
    "Serial": "TWOSTARS000043",
    "Media": "SSD",
    "Size": "893.750 GB",
    "State": "Online",
    "Interface": "SATA"
  }
]
```

### Terminal UI

`ohr tui` opens a full screen (curses) browser: on the left panel,
it is possible to nagivate through controllers, enclosure, and
disks (physical and virtual). The highlighted object on the left
panel has its properties displayed on the right. `e` edits the
highlighted object. Any change in the TUI is applied real-time.

![ohr TUI](ohr-tui.png)

### Bash completion

Ohr comes with bash-completion that does dynamic id candidates.
Every value-taking option completes, and so do positional ids:
id-bearing options (`--controller`, `--disks`) and the
commands that take a positional id (`vd show`, `disk show`,
`enclosure show`, ...).

## Status

Developed and verified against a controllers' proprietary management
utility, on a 16-port SAS3 controller, and on an embedded Mini-form-factor
controller with a live battery-backed cache module, using the original
vendor utility's own JSON output as the golden reference for every
rendered row.

## Implementation notes

Every firmware interaction is pinned against a captured MFI frame
trace (the `[capture]` markers in the source) or against the
free-software struct definitions of FreeBSD's `mfireg.h` and the
Linux `megaraid_sas` driver (the `[kernel]` markers); flows that
could not be exercised on the available hardware carry explicit
`[RE]` / `[parity-TBD]` markers in the source comments.

## Legal basis

This software was written exclusively by lawful black-box observation,
in exercise of the rights described below.

Article 5(3) of Directive 2009/24/EC says that a person entitled to use
a copy of a program may observe, study or test the functioning of the
program.

The activities that have been used to write this software were
exclusively:

- running the controllers' proprietary management utility against our
  own RAID controllers through black-box experiments;
- capturing the utility's SAS/SATA management commands;
- recording commands and responses;
- changing input parameters and observing resulting traffic;
- documenting the protocol and packet formats;
- writing an independent implementation from observations.

The rules that were respected throughout:

- no technical protection measure (encryption, DRM, server-side
  licensing, ...) was bypassed;
- no code from the proprietary software was used and the binary was not
  decompiled: this tool is an original clean-room reimplementation based
  on observing the protocol;
- the general prohibition on reverse engineering in the end-user licence
  agreement of the vendor of the card does not automatically override
  the right to observe and study software operation under EU law;
- software functionality, programming languages and data-file formats
  are not protected by copyright as expression of a computer program,
  as confirmed by the CJEU judgment C-406/10, paragraphs 47–62
  (judgment and operative ruling).

Swiss law provides a direct statutory basis for black-box observation:
Article 17(1)(b) of the Swiss Copyright Ordinance expressly permits
observing, studying and testing a program's functioning to determine
the ideas and principles underlying its elements, when doing so in the
course of authorized use.

Official texts:

- Swiss Copyright Act (Fedlex), Article 21 — Decoding of computer programs
- Swiss Copyright Ordinance, Article 17

## Hardware-blocked coverage gaps

The development rig is a single 16-port controller whose only volume
is a two-drive RAID0 on an otherwise empty backplane, with no BBU
attached. A handful of the utility's renderings describe situations that
rig cannot produce, so ohr pins everything around them at the frame
level and leaves the exact success/progress wording to the markers
below. None of these are open decode problems: each lists the
hardware that would finish it.

- **Consistency-check progress and success rows**
  (`/cX/vX show cc` while a check runs). The check itself,
  including start/stop and the reject path, is pinned; but the
  running-progress rows require a redundant virtual drive, and the
  rig's RAID0 is rejected for consistency checks client-side by
  the utility itself. Needs any redundant VD.
- **Degraded and offline state enum texts.** Rendering the
  degraded-state wording faithfully means degrading a redundant
  array on purpose; without redundancy the states are unreachable.
  Needs a redundant VD and a tolerable maintenance window.
- **Drive-initialisation success texts** (`/cX/vX start init`).
  The initialisation DCMD (0x03060100) and its reject path are
  pinned; the success rendering needs a sacrificial virtual drive,
  because the verb destroys its target.
- **Hotspare drive states.** Both rig drives are Online members of
  the RAID0, so no drive is spare-eligible and the hotspare state
  transitions stay unimplemented. Needs one unconfigured drive.
- **BBU relearn success texts** (`/cX/bbu start learn` and
  `show learn`). The rig controller carries no battery, so the
  learn flow cannot run. The golden reference is a read-only
  capture on a production embedded controller with a live battery-backed
  cache module, pending access to that host.
- **Non-empty foreign-configuration rendering** (`/cX/fall show`
  and `import preview`). The empty-scan case is pinned
  byte-exactly; a populated foreign configuration on some
  controller is needed for the populated tables.

Two further limits are effort-bound rather than hardware-bound: the
`/cX show support` archive is not implemented, and the enclosure
locator LED (`/cX/eX start locate`) is decoded-adjacent but
outside the frozen command spec. Where a success-path text is
rendered without a captured original, the source marks it
`[parity-TBD]` and the wording approximates the utility's.

See LICENSE for licensing terms (GPL-2.0-or-later).



