Commit 97aa71a
authored
fix(nbd): parse Request flags and type as separate u16 fields (#2548)
The NBD request wire layout (big-endian, 28 bytes) is `magic(4) |
flags(2) | type(2) | handle(8) | from(8) | length(4)`, but `dispatch.go`
was reading the four bytes after `magic` as a single `uint32` and
assigning it to `Request.Type`. That works only while the kernel chooses
`flags=0`; as soon as it sets any `NBD_CMD_FLAG_*` bit (e.g.
`NBD_CMD_FLAG_FUA` on a sync write) the high half leaks into `Type` and
the dispatch switch falls through to the default error path, killing the
NBD connection.
This PR splits `Flags` from `Type` into two `uint16` fields, decodes
each independently, and extracts the parsing into a small `parseRequest`
helper so the byte offsets are unit-testable. All command flags are
still intentionally ignored.
Production traffic on `main` is unaffected: the orchestrator does not
advertise `FlagSendTrim` or `FlagSendWriteZeroes`, so today's kernels
never set non-zero flags on the requests we receive. This is purely a
correctness fix to the wire parser so the dispatch keeps matching the
right command the moment any flag bit is set.1 parent 1af207c commit 97aa71a
1 file changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | | - | |
| 83 | + | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
| |||
189 | 197 | | |
190 | 198 | | |
191 | 199 | | |
192 | | - | |
| 200 | + | |
| 201 | + | |
193 | 202 | | |
194 | 203 | | |
195 | 204 | | |
| |||
0 commit comments