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

google / alioth / 17385983897

01 Sep 2025 07:41PM UTC coverage: 18.009% (-0.1%) from 18.149%
17385983897

Pull #281

github

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

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

1166 existing lines in 29 files now uncovered.

1362 of 7563 relevant lines covered (18.01%)

18.77 hits per line

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

100.0
/alioth/src/virtio/worker/worker.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
#[cfg(target_os = "linux")]
16
pub mod io_uring;
17
pub mod mio;
18

19
#[cfg(target_os = "linux")]
20
use std::fs::File;
21
#[cfg(target_os = "linux")]
22
use std::io::{ErrorKind, Read, Write};
23
#[cfg(target_os = "linux")]
24
use std::os::fd::FromRawFd;
25

26
#[cfg(target_os = "linux")]
27
use libc::{EFD_CLOEXEC, EFD_NONBLOCK, eventfd};
28
use serde::Deserialize;
29
use serde_aco::Help;
30
#[cfg(target_os = "linux")]
31
use snafu::ResultExt;
32

33
#[cfg(target_os = "linux")]
34
use crate::ffi;
35
use crate::virtio::Result;
36
#[cfg(target_os = "linux")]
37
use crate::virtio::error;
38

39
#[derive(Debug, Clone, Copy, Default, Deserialize, Help)]
40
pub enum WorkerApi {
41
    /// I/O event queue backed by epoll/kqeueu.
42
    #[default]
43
    #[serde(alias = "mio")]
44
    Mio,
45
    /// Linux io_uring.
46
    #[cfg(target_os = "linux")]
47
    #[serde(alias = "iouring", alias = "io_uring")]
48
    IoUring,
49
}
50

51
#[derive(Debug)]
52
pub struct Waker(
53
    #[cfg(target_os = "linux")] File,
54
    #[cfg(not(target_os = "linux"))] ::mio::Waker,
55
);
56

57
impl Waker {
58
    #[cfg(target_os = "linux")]
59
    pub fn new_eventfd() -> Result<Self> {
3✔
60
        let efd =
5✔
61
            ffi!(unsafe { eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK) }).context(error::CreateWaker)?;
10✔
62
        Ok(Waker(unsafe { File::from_raw_fd(efd) }))
1✔
63
    }
64

65
    #[cfg(target_os = "linux")]
66
    pub fn wake(&self) -> Result<()> {
14✔
67
        let mut fd = &self.0;
27✔
68
        let Err(e) = fd.write(&1u64.to_ne_bytes()) else {
27✔
69
            return Ok(());
14✔
70
        };
71
        if e.kind() != ErrorKind::WouldBlock {
UNCOV
72
            return Err(e.into());
73
        };
74
        let mut buf = [0u8; 8];
UNCOV
75
        let _ = fd.read(&mut buf)?;
UNCOV
76
        let _ = fd.write(&1u64.to_ne_bytes())?;
UNCOV
77
        Ok(())
78
    }
79

80
    #[cfg(not(target_os = "linux"))]
81
    pub fn wake(&self) -> Result<()> {
13✔
82
        self.0.wake()?;
26✔
83
        Ok(())
13✔
84
    }
85
}
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