• 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/hv/kvm/device.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::mem::{MaybeUninit, size_of_val};
16
use std::os::fd::{AsFd, BorrowedFd, FromRawFd, OwnedFd};
17

18
use snafu::ResultExt;
19

20
use crate::hv::kvm::kvm_error;
21
use crate::hv::{KvmError, Result};
22
use crate::sys::kvm::{
23
    KvmCreateDevice, KvmDevType, KvmDeviceAttr, kvm_create_device, kvm_get_device_attr,
24
    kvm_set_device_attr,
25
};
26

27
#[derive(Debug)]
28
pub(super) struct KvmDevice(pub OwnedFd);
29

30
impl KvmDevice {
UNCOV
31
    pub fn new(vm_fd: &impl AsFd, type_: KvmDevType) -> Result<KvmDevice, KvmError> {
32
        let mut create_device = KvmCreateDevice {
33
            type_,
34
            fd: 0,
35
            flags: 0,
36
        };
UNCOV
37
        unsafe { kvm_create_device(vm_fd, &mut create_device) }
UNCOV
38
            .context(kvm_error::CreateDevice { type_ })?;
UNCOV
39
        Ok(KvmDevice(unsafe { OwnedFd::from_raw_fd(create_device.fd) }))
40
    }
41
}
42

43
impl AsFd for KvmDevice {
UNCOV
44
    fn as_fd(&self) -> BorrowedFd<'_> {
UNCOV
45
        self.0.as_fd()
46
    }
47
}
48

49
impl KvmDevice {
50
    pub fn set_attr<T>(&self, group: u32, attr: u64, val: &T) -> Result<(), KvmError> {
×
51
        let attr = KvmDeviceAttr {
52
            group,
53
            attr,
54
            addr: if size_of_val(val) == 0 {
×
55
                0
56
            } else {
57
                val as *const _ as _
58
            },
59
            _flags: 0,
60
        };
61
        unsafe { kvm_set_device_attr(self, &attr) }.context(kvm_error::DeviceAttr)?;
×
62
        Ok(())
×
63
    }
64

65
    pub fn get_attr<T>(&self, group: u32, attr: u64) -> Result<T, KvmError> {
×
66
        let mut val = MaybeUninit::uninit();
×
67
        let attr = KvmDeviceAttr {
68
            group,
69
            attr,
70
            addr: val.as_mut_ptr() as _,
×
71
            _flags: 0,
72
        };
73
        unsafe { kvm_get_device_attr(self, &attr) }.context(kvm_error::DeviceAttr)?;
×
74
        Ok(unsafe { val.assume_init() })
×
75
    }
76
}
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