-
-
Notifications
You must be signed in to change notification settings - Fork 169
feat(loop-device):实现Dragonos对loop的支持 #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
da1ac6a to
f7e4c02
Compare
f7e4c02 to
5cbe962
Compare
e9ebe47 to
be65aaa
Compare
= 添加loopdevice的四种状态
- 添加loop_add和loop_remove函数 - 添加loop_control_ioctl的loop文件私有信息,发现data可以代替 - 待完成loop_ctl的read 和write
- 修改gendisk中的默认行为,使得read和write能传递到loop_device中 - 完成loop_device的正确挂载和写入数据的行为
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR upgrades the Rust toolchain from nightly-2024-11-05 to nightly-2025-08-10 and introduces a loop device driver implementation for DragonOS.
Key changes include:
- Toolchain version update across all Makefiles and configuration files
- New loop device driver with complete device management infrastructure
- Integration of loop devices into the DevFS and block device management systems
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| user/apps/*/Makefile | Updated Rust toolchain version from nightly-2024-11-05 to nightly-2025-08-10 |
| tools/nix-dev-shell/flake.nix | Updated Rust toolchain version in Nix dev shell configuration |
| tools/Makefile | Updated cargo toolchain version for check command |
| build-scripts/Makefile | Updated cargo toolchain version for build and check commands |
| kernel/src/driver/base/block/loop_device.rs | New file implementing loop device driver with control device, manager, and device structures |
| kernel/src/driver/base/block/mod.rs | Added loop_device module and removed blank line |
| kernel/src/driver/base/block/manager.rs | Implemented unregister functionality for block devices |
| kernel/src/driver/base/block/gendisk/mod.rs | Added read/write support, dynamic metadata, and ioctl forwarding to underlying loop devices |
| kernel/src/driver/base/device/device_number.rs | Added LOOP_MAJOR constant (7) for loop devices |
| kernel/src/filesystem/vfs/file.rs | Added Loop variant to FilePrivateData enum with typo in comment |
| kernel/src/filesystem/devfs/mod.rs | Added special handling for loop-control and loop* devices in registration and removal |
| user/apps/c_unitest/test_loop.c | New test file for loop device functionality |
| config/app-blocklist.toml | Blocked NovaShell app with typo in toolchain version |
Comments suppressed due to low confidence (1)
kernel/src/driver/base/block/loop_device.rs:1
- Inconsistent indentation: line 47 has incorrect spacing (3 spaces instead of 4) compared to line 46.
use crate::{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- feat: supplement test_loop
- add docs - delete some useless code - cargo fmt
- 在IdAllocator中新增alloc_specific方法,允许按用户指定的ID进行分配 - 重构LoopManager,移除next_free_minor字段,简化minor号管理逻辑 - 修改设备查找和创建逻辑,直接使用ID作为minor号,提高代码简洁性 Signed-off-by: longjin <longjin@DragonOS.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
e72bab9 to
6151dbf
Compare
- Make LOOP_SET_STATUS64 update offset/limit and file_size atomically to avoid new offset with stale size during concurrent I/O. - Allow Draining -> Rundown rollback on drain timeout to prevent devices getting stuck in Draining and leaking resources. - Implement LoopDevice/LoopControlDevice IndexNode::fs() to avoid todo!() panics by returning DevFS (with /dev fallback). - Make BlockDevManager::unregister transactional: unregister from devfs first, rollback on partial failures, then clear manager/meta state. Signed-off-by: longjin <longjin@DragonOS.org>
- Introduced a new method `calc_effective_size` to centralize the logic for calculating the effective size based on total size, offset, and size limit. - Updated `set_file_locked` and `recalc_effective_size` methods to utilize the new calculation method, improving code clarity and reducing duplication. - Enhanced error handling during effective size recalculation to ensure stability under high concurrency scenarios. - Added comments to clarify the locking strategy and the importance of atomic updates to prevent inconsistent states. This refactor aims to improve maintainability and reliability of loop device operations. Signed-off-by: longjin <longjin@DragonOS.org>
…e and LoopDevice - Replaced `todo!()` with actual implementation for the `fs` method in both `LoopControlDevice` and `LoopDevice`. - The new implementation retrieves the filesystem from the device inode, ensuring it is properly set and upgraded. This change enhances the functionality of loop devices by providing a valid filesystem reference, improving overall stability and reliability. Signed-off-by: longjin <longjin@DragonOS.org>
…wo-phase rollback mechanism - Improved the `unregister` method in `BlockDevManager` to implement a two-phase approach for safely unregistering devices from the manager and devfs. - Added detailed comments to clarify the importance of maintaining atomicity and recoverability during the unregistration process. - Ensured that device metadata is only cleared after successful unregistration of all devfs nodes, preventing inconsistent states. This change enhances the reliability of device management by ensuring that failures during unregistration do not leave the system in an unrecoverable state. Signed-off-by: longjin <longjin@DragonOS.org>
- Introduced a new inline method `device_reusable` to determine if a loop device is in a reusable state, specifically checking for the `Unbound` state. - Updated device allocation logic to utilize the new method, ensuring that devices in `Rundown`, `Draining`, or `Deleting` states are not mistakenly considered available for reuse. - Enhanced comments for clarity on device state management during allocation and reuse processes. This refactor aims to improve the reliability of loop device management by preventing the allocation of devices that are in the process of being deleted.
… into zhanghuizhou-feat/loop-device
- Updated the LoopDevice implementation to ensure that the Deleting state returns Ok idempotently, preventing devices from getting stuck in a zombie state after a failed deletion attempt. - Enhanced comments to clarify the importance of maintaining device state consistency during the unregistration process from BlockDevManager, allowing for retries without resource leaks. This fix improves the reliability of loop device management by addressing potential deadlock scenarios during device removal.
- Updated the LoopDevice implementation to handle the transition to the Deleting state idempotently, preventing errors when multiple threads attempt to set the state concurrently. - Enhanced comments to clarify the rationale behind the idempotent handling, ensuring consistent device state management during deletion.
- Added a new `LoopStatus` structure to represent legacy loop device status information, including fields for name and encryption key sizes. - Implemented validation logic for `LoopStatus` parameters to ensure correct offset and flag values during state updates. - Updated `set_status` and `get_status` methods to handle `LoopStatus`, maintaining compatibility with legacy loop device operations. This enhancement improves the handling of legacy loop device states and ensures proper validation of input parameters, contributing to overall system stability.
- Introduced a new type `KernelOldDevT` for compatibility with legacy loop device structures. - Updated `LoopStatus` and `LoopStatus64` to use `KernelOldDevT` for device identifiers, ensuring consistency with Linux UAPI. - Enhanced the test suite for loop devices, improving readability and structure of test output. - Added comprehensive tests for loop device operations, including read/write, capacity changes, and deletion scenarios. These changes improve the robustness and maintainability of loop device management, ensuring better alignment with Linux standards and enhancing testing capabilities.
| }; | ||
| drop(inner); | ||
| self.recalc_effective_size()?; | ||
| Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: State inconsistency if recalc_effective_size fails after binding
In bind_file, the lock is dropped and then recalc_effective_size() is called. If recalc_effective_size() fails (e.g., due to a transient metadata read failure), the function returns an error but the device state has already been set to Bound with file_inode set. The caller receives an error suggesting binding failed, but subsequent bind attempts would get EBUSY since the device is now Bound. This leaves the device in a usable but caller-confusing state where the error return doesn't match the actual device state.
Note
Implements a full loop device stack (
/dev/loop-control,/dev/loopX) with IOCTLs, lifecycle management, safe unregister, devfs integration, and unit tests.driver/block/loop_device/*implementingLoopDevice,LoopControlDevice,LoopManager,LoopDeviceDriver, and IOCTLs (LOOP_SET/GET_STATUS(64),LOOP_SET_FD,LOOP_CLR_FD,LOOP_CHANGE_FD,LOOP_SET_CAPACITY).Unbound/Bound/Rundown/Draining/Deleting), active I/O tracking with drain-on-delete, read-only enforcement, offset/size-limit handling with atomic updates.kernel/src/driver/block/mod.rs; new majorsLOOP_MAJORandLOOP_CONTROL_MAJOR./dev/loop-control(char) at/dev; register/dev/loopN(block) at/devwith special-case unregister logic.gendisk: enable byteread_at/write_at, dynamicmetadatasizing, and forwardioctltoLoopDevice.unregister()with devfs rollback for consistency; uses vectors to stage/removegendisks.ida: addalloc_specific(id)for fixed minor allocation used by loop manager.vfs/file.rs: addFilePrivateData::Loopvariant.docs/kernel/device/loop_device.mdand index entry describing architecture and design.user/apps/c_unitest/test_loop.ccovering creation, binding, status change, capacity, concurrent I/O deletion, leak detection, and deletion behavior.Written by Cursor Bugbot for commit 9752ea7. This will update automatically on new commits. Configure here.