• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / alioth / 17385686062

01 Sep 2025 07:20PM UTC coverage: 18.016% (-0.1%) from 18.149%
17385686062

Pull #281

github

web-flow
Merge f6f978f6a into 6ec9a6d6b
Pull Request #281: Port to Apple Hypervisor framework

0 of 152 new or added lines in 11 files covered. (0.0%)

1323 existing lines in 30 files now uncovered.

1362 of 7560 relevant lines covered (18.02%)

18.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/alioth/src/vfio/cdev.rs
1
// Copyright 2024 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
use std::fmt::Debug;
16
use std::fs::{File, OpenOptions};
17
use std::mem::size_of;
18
use std::os::fd::AsRawFd;
19
use std::path::Path;
20
use std::sync::Arc;
21

22
use snafu::ResultExt;
23

24
use crate::vfio::bindings::{
25
    VfioDeviceAttachIommufdPt, VfioDeviceBindIommufd, VfioDeviceDetachIommufdPt,
26
};
27
use crate::vfio::device::Device;
28
use crate::vfio::ioctls::{
29
    vfio_device_attach_iommufd_pt, vfio_device_bind_iommufd, vfio_device_detach_iommufd_pt,
30
};
31
use crate::vfio::iommu::Ioas;
32
use crate::vfio::{Result, error};
33

34
#[derive(Debug)]
35
pub struct Cdev {
36
    fd: File,
37
    ioas: Option<Arc<Ioas>>,
38
}
39

40
impl Cdev {
41
    pub fn new(path: impl AsRef<Path>) -> Result<Self> {
×
42
        let fd = OpenOptions::new()
×
43
            .read(true)
44
            .write(true)
45
            .open(&path)
×
46
            .context(error::AccessDevice {
×
47
                path: path.as_ref(),
×
48
            })?;
49
        Ok(Cdev { fd, ioas: None })
×
50
    }
51
}
52

53
impl Cdev {
UNCOV
54
    pub fn attach_iommu_ioas(&mut self, ioas: Arc<Ioas>) -> Result<()> {
55
        let bind = VfioDeviceBindIommufd {
UNCOV
56
            argsz: size_of::<VfioDeviceBindIommufd>() as u32,
UNCOV
57
            iommufd: ioas.iommu.fd.as_raw_fd(),
58
            ..Default::default()
59
        };
UNCOV
60
        unsafe { vfio_device_bind_iommufd(&self.fd, &bind) }?;
61
        let attach = VfioDeviceAttachIommufdPt {
UNCOV
62
            argsz: size_of::<VfioDeviceAttachIommufdPt>() as u32,
UNCOV
63
            pt_id: ioas.id,
64
            ..Default::default()
65
        };
UNCOV
66
        unsafe { vfio_device_attach_iommufd_pt(&self.fd, &attach) }?;
UNCOV
67
        self.ioas.replace(ioas);
UNCOV
68
        Ok(())
69
    }
70

UNCOV
71
    pub fn detach_iommu_ioas(&mut self) -> Result<()> {
UNCOV
72
        if self.ioas.is_none() {
UNCOV
73
            return Ok(());
74
        };
75
        let detach = VfioDeviceDetachIommufdPt {
UNCOV
76
            argsz: size_of::<VfioDeviceDetachIommufdPt>() as u32,
77
            flags: 0,
78
        };
UNCOV
79
        unsafe { vfio_device_detach_iommufd_pt(&self.fd, &detach) }?;
UNCOV
80
        self.ioas = None;
UNCOV
81
        Ok(())
82
    }
83
}
84

85
impl Device for Cdev {
UNCOV
86
    fn fd(&self) -> &File {
UNCOV
87
        &self.fd
88
    }
89
}
90

91
impl Drop for Cdev {
UNCOV
92
    fn drop(&mut self) {
UNCOV
93
        if let Err(e) = self.detach_iommu_ioas() {
UNCOV
94
            log::error!("Cdev-{}: detaching ioas: {e:?}", self.fd.as_raw_fd())
95
        }
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc