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

google / alioth / 18638570188

20 Oct 2025 12:38AM UTC coverage: 20.202% (-0.01%) from 20.213%
18638570188

Pull #308

github

web-flow
Merge 73a1640e9 into 416357998
Pull Request #308: Add tests for PciSegment

0 of 59 new or added lines in 5 files covered. (0.0%)

1163 existing lines in 25 files now uncovered.

1578 of 7811 relevant lines covered (20.2%)

19.85 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::sys::vfio::{
25
    VfioDeviceAttachIommufdPt, VfioDeviceBindIommufd, VfioDeviceDetachIommufdPt,
26
    vfio_device_attach_iommufd_pt, vfio_device_bind_iommufd, vfio_device_detach_iommufd_pt,
27
};
28
use crate::vfio::device::Device;
29
use crate::vfio::iommu::Ioas;
30
use crate::vfio::{Result, error};
31

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

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

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

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

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

89
impl Drop for Cdev {
UNCOV
90
    fn drop(&mut self) {
UNCOV
91
        if let Err(e) = self.detach_iommu_ioas() {
UNCOV
92
            log::error!("Cdev-{}: detaching ioas: {e:?}", self.fd.as_raw_fd())
93
        }
94
    }
95
}
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