Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 935726
Collapse All | Expand All

(-)a/cargo_home/gentoo/vhost-0.10.0/src/vhost_user/backend.rs (+15 lines)
Lines 5-10 Link Here
5
5
6
use std::sync::Arc;
6
use std::sync::Arc;
7
7
8
use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
9
use std::os::unix::net::UnixStream;
8
use super::connection::{Endpoint, Listener};
10
use super::connection::{Endpoint, Listener};
9
use super::message::*;
11
use super::message::*;
10
use super::{BackendReqHandler, Result, VhostUserBackendReqHandler};
12
use super::{BackendReqHandler, Result, VhostUserBackendReqHandler};
Lines 26-31 Link Here
26
        })
28
        })
27
    }
29
    }
28
30
31
    pub fn from_raw_fd(&mut self, fd: RawFd) -> Result<Option<BackendReqHandler<S>>> {
32
        let mut unixstream : UnixStream;
33
        unsafe {
34
            unixstream = UnixStream::from_raw_fd(fd);
35
        }
36
        println!("creating from raw_fd {}", fd);
37
        return Ok(Some(BackendReqHandler::new(
38
            Endpoint::<FrontendReq>::from_stream(unixstream),
39
            self.backend.take().unwrap(),
40
        )));
41
    }
42
43
29
    /// Accept an incoming connection from the frontend, returning Some(Backend) on
44
    /// Accept an incoming connection from the frontend, returning Some(Backend) on
30
    /// success, or None if the socket is nonblocking and no incoming connection
45
    /// success, or None if the socket is nonblocking and no incoming connection
31
    /// was detected
46
    /// was detected
(-)a/cargo_home/gentoo/vhost-user-backend-0.13.1/src/lib.rs (+18 lines)
Lines 8-13 Link Here
8
#[macro_use]
8
#[macro_use]
9
extern crate log;
9
extern crate log;
10
10
11
use std::os::fd::RawFd;
11
use std::fmt::{Display, Formatter};
12
use std::fmt::{Display, Formatter};
12
use std::path::Path;
13
use std::path::Path;
13
use std::sync::{Arc, Mutex};
14
use std::sync::{Arc, Mutex};
Lines 123-128 Link Here
123
        &mut self,
124
        &mut self,
124
        mut handler: BackendReqHandler<Mutex<VhostUserHandler<T>>>,
125
        mut handler: BackendReqHandler<Mutex<VhostUserHandler<T>>>,
125
    ) -> Result<()> {
126
    ) -> Result<()> {
127
        println!("start_daemon daemon");
126
        let handle = thread::Builder::new()
128
        let handle = thread::Builder::new()
127
            .name(self.name.clone())
129
            .name(self.name.clone())
128
            .spawn(move || loop {
130
            .spawn(move || loop {
Lines 162-167 Link Here
162
        self.start_daemon(backend_handler)
164
        self.start_daemon(backend_handler)
163
    }
165
    }
164
166
167
    pub fn start_from_rawfd(&mut self, listener: Listener, fd: RawFd) -> Result<()> {
168
        println!("staring accept daemon with fd");
169
        let mut backend_listener = BackendListener::new(listener, self.handler.clone())
170
            .map_err(Error::CreateBackendListener)?;
171
        let backend_handler = self.from_raw_fd(&mut backend_listener, fd)?;
172
        self.start_daemon(backend_handler)
173
    }
174
175
    fn from_raw_fd(&self, backend_listener: &mut BackendListener<Mutex<VhostUserHandler<T>>>, fd: RawFd) -> Result<BackendReqHandler<Mutex<VhostUserHandler<T>>>> {
176
        match backend_listener.from_raw_fd(fd) {
177
            Err(e) => return Err(Error::CreateBackendListener(VhostUserError::Disconnected)),
178
            Ok(Some(v)) => return Ok(v),
179
            Ok(None) => Err(Error::CreateBackendListener(VhostUserError::Disconnected)),   
180
        }
181
    }
182
165
    fn accept(
183
    fn accept(
166
        &self,
184
        &self,
167
        backend_listener: &mut BackendListener<Mutex<VhostUserHandler<T>>>,
185
        backend_listener: &mut BackendListener<Mutex<VhostUserHandler<T>>>,
(-)a/src/main.rs (-4 / +18 lines)
Lines 87-92 Link Here
87
    InvalidTag,
87
    InvalidTag,
88
}
88
}
89
89
90
extern "C" {
91
    fn dup(input: i32) -> i32;
92
}
93
90
impl fmt::Display for Error {
94
impl fmt::Display for Error {
91
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92
        use self::Error::UnshareCloneFs;
96
        use self::Error::UnshareCloneFs;
Lines 1042-1048 Link Here
1042
    // We need to keep _pid_file around because it maintains a lock on the pid file
1046
    // We need to keep _pid_file around because it maintains a lock on the pid file
1043
    // that prevents another daemon from using the same pid file.
1047
    // that prevents another daemon from using the same pid file.
1044
    let (listener, socket_path, _pid_file) = match opt.fd.as_ref() {
1048
    let (listener, socket_path, _pid_file) = match opt.fd.as_ref() {
1045
        Some(fd) => unsafe { (Listener::from_raw_fd(*fd), None, None) },
1049
        Some(fd) => unsafe {  (Listener::from_raw_fd(dup(*fd)), None, None) },
1046
        None => {
1050
        None => {
1047
            // Set umask to ensure the socket is created with the right permissions
1051
            // Set umask to ensure the socket is created with the right permissions
1048
            let _umask_guard = oslib::ScopedUmask::new(umask);
1052
            let _umask_guard = oslib::ScopedUmask::new(umask);
Lines 1173-1181 Link Here
1173
1177
1174
    info!("Waiting for vhost-user socket connection...");
1178
    info!("Waiting for vhost-user socket connection...");
1175
1179
1176
    if let Err(e) = daemon.start(listener) {
1180
    match opt.fd.as_ref() {
1177
        error!("Failed to start daemon: {:?}", e);
1181
        Some(fd) => {
1178
        process::exit(1);
1182
            if let Err(e) = daemon.start_from_rawfd(listener, *fd) {
1183
                error!("Failed to start daemon: {:?}", e);
1184
                process::exit(1);
1185
            }
1186
        }
1187
        None => {
1188
            if let Err(e) = daemon.start(listener) {
1189
                error!("Failed to start daemon: {:?}", e);
1190
                process::exit(1);
1191
            }
1192
        }
1179
    }
1193
    }
1180
1194
1181
    info!("Client connected, servicing requests");
1195
    info!("Client connected, servicing requests");

Return to bug 935726