Skip to content

Commit 655e4df

Browse files
committed
iommufd-ioctls: Add IommuFd::new_from_fd
Accept an externally-opened /dev/iommu file to create an IommuFD instance. Signed-off-by: Bo Chen <bchen@crusoe.ai>
1 parent 8125f84 commit 655e4df

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

iommufd-ioctls/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
## Added
66
- [[9]](https://github.com/cloud-hypervisor/iommufd/pull/9) Add `Iommufd::destroy_iommu_object` to release iommufd
77
objects explicitly.
8+
- [[9]](https://github.com/cloud-hypervisor/iommufd/pull/9) Add `Iommufd::new_from_fd` to construct a `Iommufd` from
9+
a pre-opened iommufd file.
810

911
## Fixed
1012

iommufd-ioctls/src/iommufd_ioctls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ impl IommuFd {
2626
Ok(IommuFd { iommufd })
2727
}
2828

29+
/// New from an already-opened `/dev/iommu` file. Caller transfers
30+
/// ownership; closing the fd is now `IommuFd`'s responsibility.
31+
pub fn new_from_fd(file: File) -> Self {
32+
IommuFd { iommufd: file }
33+
}
34+
2935
pub fn destroy_iommu_object(&self, id: u32) -> Result<()> {
3036
let destroy_data = iommu_destroy {
3137
size: std::mem::size_of::<iommu_destroy>() as u32,

0 commit comments

Comments
 (0)