feat(ublk): functional options for block size, queue depth, max IO#35
Conversation
PR SummaryMedium Risk Overview Device parameter programming is updated to derive the kernel block-size shift values from the configured block size, and new unit + integration tests are added to validate option constraints and exercise a full filesystem round-trip with a non-default block size. Reviewed by Cursor Bugbot for commit 42ef28f. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 791775f. Configure here.
New(backend, size, opts ...Option) exposes the previously hard-coded knobs without changing existing 2-arg callers. - WithBlockSize: logical/physical block size, power of two >= 512 - WithQueueDepth: io_uring queue depth, [1, maxQueueDepth] - WithMaxIOSize: largest single IO, multiple of block size setParams derives LogicalBSShift / PhysicalBSShift / IOOptShift / IOMinShift from cfg.blockSize so the kernel exposes the requested geometry to the block layer.

Today
ublk.New(backend, size)hard-codes 512-byte blocks, queue depth 128, and 128 KiB max IO. Downstream consumers (e.g. a rootfs provider using 4 KiB blocks for parity with an older NBD backend) need these configurable. Backward-compatible: existing 2-argNew(backend, size)callers are unchanged.New(backend, size, opts ...Option)exposes the previously hard-coded knobs:setParamsderivesLogicalBSShift/PhysicalBSShift/IOOptShift/IOMinShiftfrombits.TrailingZeros32(cfg.blockSize)rather than the hard-coded 9.DevSectorsstays in 512-byte units since the kernel sector size is fixed.Test plan
TestNewValidationtable covers zero size, non-multiple size, bad block size, oversized queue depth, max-IO/block-size mismatch.TestNewWithOptionsround-trips 4 KiB blocks throughBLKBSZGET,BLKSECTGET, and a pwrite/ReadAt comparison.make lintclean.