Skip to content

Comments

Misc clean fix#6

Merged
ming1 merged 5 commits intomainfrom
misc-clean-fix
Aug 17, 2025
Merged

Misc clean fix#6
ming1 merged 5 commits intomainfrom
misc-clean-fix

Conversation

@ming1
Copy link
Collaborator

@ming1 ming1 commented Aug 17, 2025

630fd3e fix: Fully detach daemon process
3ce39c7 refactor(args): Clean up command-line argument parsing
6d3cb3d refactor(tests): Abstract has_blkdiscard() helper
0b9424b feat(null): Add unconditional discard support
5acacca refactor(loop): Clean up and simplify loop target implementation

ming1 added 5 commits August 17, 2025 01:16
This commit applies several cleanups to the `src/loop.rs` file to improve
code clarity, robustness, and adherence to Rust idioms.

- Removed unnecessary `#[inline]` attributes from internal helper functions.
The compiler's own heuristics are sufficient for making inlining decisions
for these private, non-generic functions, making the explicit attribute redundant.

- Replaced `.unwrap()` with `anyhow::Context` when opening the backing file.
This provides more informative error messages if the file cannot be opened,
improving diagnostics.

- Simplified the logic in `ublk_add_loop` for handling device recovery and
command-line options, making the code easier to follow and maintain.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Enable discard support for the null target unconditionally. The null
device now advertises discard capabilities and handles discard/write-zeroes
commands by returning a success status (0), as no actual data operation
is needed.

Also, add a basic integration test to verify that the `blkdiscard` command
runs successfully against a `rublk` null device.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Create a single `has_blkdiscard()` helper function to check for the
availability of the `blkdiscard` command.

This refactoring removes code duplication from the `test_ublk_loop_discard`
and `test_ublk_null_discard` tests, making the test suite cleaner and
easier to maintain.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
This commit refactors `src/args.rs` to improve code clarity, robustness,
and adherence to Rust idioms.

- Replaced `.unwrap()` calls with `?` to ensure proper error propagation
when building the `UblkCtrl` object.

- Simplified boolean flag handling for setting control flags.

- Added comments to clarify the purpose of the `start_dir` field and the
`round_up` and `is_power2_of` helper functions.

- Improved the implementation of `is_power2_of` to use the standard library's
`is_power_of_two()` for better readability.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
When `rublk add` is run in a subshell, as in `$(rublk add null)`, the parent
shell waits for the daemon's stdout and stderr file descriptors to close.
Previously, these were kept open, causing the parent to hang indefinitely.

This commit fixes the issue by redirecting the daemon's stdout and stderr to
`/dev/null`. This allows the daemon to fully detach, preventing the parent
shell from hanging and enabling correct behavior in subshells.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
@ming1 ming1 merged commit d778fb2 into main Aug 17, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant