Skip to content

feat(ublk): functional options for block size, queue depth, max IO#35

Merged
ValentaTomas merged 1 commit into
mainfrom
feat/config
May 16, 2026
Merged

feat(ublk): functional options for block size, queue depth, max IO#35
ValentaTomas merged 1 commit into
mainfrom
feat/config

Conversation

@arkamar
Copy link
Copy Markdown
Contributor

@arkamar arkamar commented May 15, 2026

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-arg New(backend, size) callers are unchanged.

New(backend, size, opts ...Option) exposes the previously hard-coded knobs:

ublk.New(b, sz)                                  // defaults
ublk.New(b, sz, ublk.WithBlockSize(4096))        // 4 KiB LBA
ublk.New(b, sz,
    ublk.WithBlockSize(4096),
    ublk.WithQueueDepth(64),
    ublk.WithMaxIOSize(64<<10),
)

setParams derives LogicalBSShift / PhysicalBSShift / IOOptShift / IOMinShift from bits.TrailingZeros32(cfg.blockSize) rather than the hard-coded 9. DevSectors stays in 512-byte units since the kernel sector size is fixed.

Test plan

  • Unit: TestNewValidation table covers zero size, non-multiple size, bad block size, oversized queue depth, max-IO/block-size mismatch.
  • Integration: TestNewWithOptions round-trips 4 KiB blocks through BLKBSZGET, BLKSECTGET, and a pwrite/ReadAt comparison.
  • Full integration suite green, make lint clean.

@arkamar arkamar requested a review from ValentaTomas as a code owner May 15, 2026 11:02
@cla-bot cla-bot Bot added the cla-signed label May 15, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented May 15, 2026

PR Summary

Medium Risk
Touches core device-creation parameters and kernel-facing SET_PARAMS values; misconfiguration could lead to IO failures or filesystem/mount issues, but validation and integration coverage reduce risk.

Overview
ublk.New now accepts functional options to configure block size, io_uring queue depth, and max IO size, replacing previously hard-coded defaults.

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.

@ValentaTomas ValentaTomas changed the title Add Config struct and NewWithConfig for parameterised device creation feat(ublk): functional options for block size, queue depth, max IO May 16, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread ublk/ublk.go
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.
@ValentaTomas ValentaTomas merged commit e4a86bc into main May 16, 2026
14 checks passed
@ValentaTomas ValentaTomas deleted the feat/config branch May 16, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants