|
| 1 | +/* |
| 2 | +Copyright 2026 Cozystack contributors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package drbd |
| 18 | + |
| 19 | +// Option describes one DRBD-9 configurable knob — a port of one entry |
| 20 | +// from upstream's `drbdoptions.json` catalogue. We use it both for |
| 21 | +// property validation (Phase 6) and so the satellite reconciler can |
| 22 | +// route a flat string→string property bag into the right `.res` file |
| 23 | +// section. |
| 24 | +type Option struct { |
| 25 | + // Name is the bare option key (e.g. "max-buffers", "auto-promote"). |
| 26 | + Name string |
| 27 | + |
| 28 | + // Section selects which `.res` block this option belongs in: |
| 29 | + // `SectionNet`, `SectionDisk`, `SectionPeerDevice`, `SectionOptions` |
| 30 | + // (top-level resource options), or `SectionHandlers`. |
| 31 | + Section string |
| 32 | + |
| 33 | + // LinstorKey is the upstream-compatible LINSTOR property name |
| 34 | + // (e.g. "DrbdOptions/Net/max-buffers") that callers set on |
| 35 | + // resource definitions. Stored verbatim so existing golinstor |
| 36 | + // clients keep working unmodified. |
| 37 | + LinstorKey string |
| 38 | + |
| 39 | + // Default is the value DRBD-9 uses when the option is unset. |
| 40 | + // Empty string means "no default; let DRBD decide" (rarely useful |
| 41 | + // — most are typed). |
| 42 | + Default string |
| 43 | + |
| 44 | + // Description is a one-line summary, lifted from the DRBD man pages. |
| 45 | + Description string |
| 46 | +} |
| 47 | + |
| 48 | +// Section names for `.res` block placement. Exposed so callers can |
| 49 | +// route a flat property bag into the correct block without re-parsing |
| 50 | +// the LINSTOR key namespace. |
| 51 | +const ( |
| 52 | + SectionNet = "net" |
| 53 | + SectionDisk = "disk" |
| 54 | + SectionPeerDevice = "peer-device" |
| 55 | + SectionOptions = "options" |
| 56 | + SectionHandlers = "handlers" |
| 57 | +) |
| 58 | + |
| 59 | +// Options is the catalogue of DRBD knobs blockstor knows about. Far |
| 60 | +// from exhaustive — DRBD has 100+ options and we add them on demand — |
| 61 | +// but covers the keys cozystack-style clusters actually need. Built |
| 62 | +// up by section to keep each subset reviewable. |
| 63 | +func Options() []Option { |
| 64 | + net := netOptions() |
| 65 | + disk := diskOptions() |
| 66 | + peerDev := peerDeviceOptions() |
| 67 | + res := resourceOptions() |
| 68 | + |
| 69 | + out := make([]Option, 0, len(net)+len(disk)+len(peerDev)+len(res)) |
| 70 | + out = append(out, net...) |
| 71 | + out = append(out, disk...) |
| 72 | + out = append(out, peerDev...) |
| 73 | + out = append(out, res...) |
| 74 | + |
| 75 | + return out |
| 76 | +} |
| 77 | + |
| 78 | +// netOptions returns the `net { … }` section catalogue. |
| 79 | +func netOptions() []Option { |
| 80 | + return []Option{ |
| 81 | + { |
| 82 | + Name: "protocol", |
| 83 | + Section: SectionNet, |
| 84 | + LinstorKey: "DrbdOptions/Net/protocol", |
| 85 | + Default: "C", |
| 86 | + Description: "Replication protocol — A (async) / B (semi-sync) / C (sync). Cozystack runs C.", |
| 87 | + }, |
| 88 | + { |
| 89 | + Name: "shared-secret", |
| 90 | + Section: SectionNet, |
| 91 | + LinstorKey: "DrbdOptions/Net/shared-secret", |
| 92 | + Description: "HMAC secret authenticating peer-to-peer connections.", |
| 93 | + }, |
| 94 | + { |
| 95 | + Name: "max-buffers", |
| 96 | + Section: SectionNet, |
| 97 | + LinstorKey: "DrbdOptions/Net/max-buffers", |
| 98 | + Default: "8000", |
| 99 | + Description: "Receive ring depth in 4 KiB pages.", |
| 100 | + }, |
| 101 | + { |
| 102 | + Name: "after-sb-0pri", |
| 103 | + Section: SectionNet, |
| 104 | + LinstorKey: "DrbdOptions/Net/after-sb-0pri", |
| 105 | + Default: "discard-zero-changes", |
| 106 | + Description: "Split-brain recovery policy when neither side was Primary.", |
| 107 | + }, |
| 108 | + { |
| 109 | + Name: "after-sb-1pri", |
| 110 | + Section: SectionNet, |
| 111 | + LinstorKey: "DrbdOptions/Net/after-sb-1pri", |
| 112 | + Default: "discard-secondary", |
| 113 | + Description: "Split-brain recovery policy when one side was Primary.", |
| 114 | + }, |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +// diskOptions returns the `disk { … }` section catalogue. |
| 119 | +func diskOptions() []Option { |
| 120 | + return []Option{ |
| 121 | + { |
| 122 | + Name: "on-io-error", |
| 123 | + Section: SectionDisk, |
| 124 | + LinstorKey: "DrbdOptions/Disk/on-io-error", |
| 125 | + Default: "detach", |
| 126 | + Description: "Behaviour on lower-level IO failure (pass-on / detach / call-local-io-error).", |
| 127 | + }, |
| 128 | + { |
| 129 | + Name: "al-extents", |
| 130 | + Section: SectionDisk, |
| 131 | + LinstorKey: "DrbdOptions/Disk/al-extents", |
| 132 | + Default: "1237", |
| 133 | + Description: "Activity-log size; trades resync time against random-write throughput.", |
| 134 | + }, |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +// peerDeviceOptions returns the `peer-device { … }` section catalogue. |
| 139 | +func peerDeviceOptions() []Option { |
| 140 | + return []Option{ |
| 141 | + { |
| 142 | + Name: "c-max-rate", |
| 143 | + Section: SectionPeerDevice, |
| 144 | + LinstorKey: "DrbdOptions/PeerDevice/c-max-rate", |
| 145 | + Default: "100M", |
| 146 | + Description: "Upper bound on resync rate in bytes/second.", |
| 147 | + }, |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +// resourceOptions returns the top-level `options { … }` catalogue. |
| 152 | +func resourceOptions() []Option { |
| 153 | + return []Option{ |
| 154 | + { |
| 155 | + Name: "auto-promote", |
| 156 | + Section: SectionOptions, |
| 157 | + LinstorKey: "DrbdOptions/Resource/auto-promote", |
| 158 | + Default: "yes", |
| 159 | + Description: "Auto-promote to Primary on first open(2).", |
| 160 | + }, |
| 161 | + { |
| 162 | + Name: "quorum", |
| 163 | + Section: SectionOptions, |
| 164 | + LinstorKey: "DrbdOptions/Resource/quorum", |
| 165 | + Default: "majority", |
| 166 | + Description: "Quorum policy — off / majority / all / <count>.", |
| 167 | + }, |
| 168 | + { |
| 169 | + Name: "on-no-quorum", |
| 170 | + Section: SectionOptions, |
| 171 | + LinstorKey: "DrbdOptions/Resource/on-no-quorum", |
| 172 | + Default: "io-error", |
| 173 | + Description: "Behaviour when quorum is lost: io-error or suspend-io.", |
| 174 | + }, |
| 175 | + } |
| 176 | +} |
0 commit comments