return errors from system module
This commit is contained in:
parent
df4ab4c0c9
commit
2b69ce2c08
@ -6,6 +6,7 @@ use std::fmt;
|
|||||||
use crate::system::ioctl::{ioctl_with_val,ioctl_with_ref,ioctl_with_mut_ref};
|
use crate::system::ioctl::{ioctl_with_val,ioctl_with_ref,ioctl_with_mut_ref};
|
||||||
|
|
||||||
use crate::vm::{Result,Error,ErrorKind};
|
use crate::vm::{Result,Error,ErrorKind};
|
||||||
|
use crate::system;
|
||||||
|
|
||||||
|
|
||||||
const KVMIO: u64 = 0xAE;
|
const KVMIO: u64 = 0xAE;
|
||||||
@ -602,9 +603,9 @@ pub fn kvm_run(cpufd: &VcpuFd) -> Result<u32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ioctl_err(ioctl_name: &'static str, e: Error) -> Error {
|
pub fn ioctl_err(ioctl_name: &'static str, e: system::Error) -> Error {
|
||||||
if e.is_interrupted() {
|
if e.is_interrupted() {
|
||||||
e
|
Error::new(ErrorKind::Interrupted, e)
|
||||||
} else {
|
} else {
|
||||||
Error::new(ErrorKind::IoctlFailed(ioctl_name), e)
|
Error::new(ErrorKind::IoctlFailed(ioctl_name), e)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ pub enum Error {
|
|||||||
GbmCreateDevice(system::Error),
|
GbmCreateDevice(system::Error),
|
||||||
GbmCreateBuffer(system::Error),
|
GbmCreateBuffer(system::Error),
|
||||||
OpenRenderNode(io::Error),
|
OpenRenderNode(io::Error),
|
||||||
PrimeHandleToFD(VmError),
|
PrimeHandleToFD(system::Error),
|
||||||
CreateBuffer(io::Error),
|
CreateBuffer(io::Error),
|
||||||
NoDrmAllocator,
|
NoDrmAllocator,
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,10 @@ impl Error {
|
|||||||
pub fn last_os_error() -> Error {
|
pub fn last_os_error() -> Error {
|
||||||
Error(unsafe { *__errno_location() })
|
Error(unsafe { *__errno_location() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_interrupted(&self) -> bool {
|
||||||
|
self.0 == libc::EINTR
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for Error {
|
impl From<io::Error> for Error {
|
||||||
@ -32,13 +36,19 @@ impl Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Error> for io::Error {
|
||||||
|
fn from(err: Error) -> io::Error {
|
||||||
|
io::Error::from_raw_os_error(err.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn errno_result<T>() -> Result<T> {
|
pub fn errno_result<T>() -> Result<T> {
|
||||||
Err(Error::last_os_error())
|
Err(Error::last_os_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cvt<T: IsMinusOne>(t: T) -> io::Result<T> {
|
pub fn cvt<T: IsMinusOne>(t: T) -> Result<T> {
|
||||||
if t.is_minus_one() {
|
if t.is_minus_one() {
|
||||||
Err(io::Error::last_os_error())
|
Err(Error::last_os_error())
|
||||||
} else {
|
} else {
|
||||||
Ok(t)
|
Ok(t)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::os::unix::io::{IntoRawFd,AsRawFd,RawFd};
|
use std::os::unix::io::{IntoRawFd,AsRawFd,RawFd};
|
||||||
use std::{mem, io};
|
use std::{mem, io};
|
||||||
use crate::system::cvt;
|
use crate::system::errno::cvt;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use libc::{self, c_ulong, c_void};
|
use libc::{self, c_ulong, c_void};
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use crate::vm::{Error,Result};
|
use crate::system::{Error,Result};
|
||||||
|
|
||||||
pub const IOC_SIZEBITS: u64 = 14;
|
pub const IOC_SIZEBITS: u64 = 14;
|
||||||
pub const IOC_DIRBITS: u64 = 2;
|
pub const IOC_DIRBITS: u64 = 2;
|
||||||
@ -26,7 +26,7 @@ macro_rules! ioc {
|
|||||||
((($dir as u64 & $crate::system::ioctl::IOC_DIRMASK) << $crate::system::ioctl::IOC_DIRSHIFT) |
|
((($dir as u64 & $crate::system::ioctl::IOC_DIRMASK) << $crate::system::ioctl::IOC_DIRSHIFT) |
|
||||||
(($ty as u64 & $crate::system::ioctl::IOC_TYPEMASK) << $crate::system::ioctl::IOC_TYPESHIFT) |
|
(($ty as u64 & $crate::system::ioctl::IOC_TYPEMASK) << $crate::system::ioctl::IOC_TYPESHIFT) |
|
||||||
(($nr as u64 & $crate::system::ioctl::IOC_NRMASK) << $crate::system::ioctl::IOC_NRSHIFT) |
|
(($nr as u64 & $crate::system::ioctl::IOC_NRMASK) << $crate::system::ioctl::IOC_NRSHIFT) |
|
||||||
(($sz as u64 & $crate::system::ioctl::IOC_SIZEMASK) << $crate::system::ioctl::IOC_SIZESHIFT)) as c_ulong)
|
(($sz as u64 & $crate::system::ioctl::IOC_SIZEMASK) << $crate::system::ioctl::IOC_SIZESHIFT)) as ::libc::c_ulong)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! io {
|
macro_rules! io {
|
||||||
@ -48,7 +48,7 @@ macro_rules! iorw {
|
|||||||
pub unsafe fn ioctl_with_val(fd: RawFd, request: c_ulong, val: c_ulong) -> Result<u32> {
|
pub unsafe fn ioctl_with_val(fd: RawFd, request: c_ulong, val: c_ulong) -> Result<u32> {
|
||||||
let ret = libc::ioctl(fd, request, val);
|
let ret = libc::ioctl(fd, request, val);
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return Err(Error::from_last_errno());
|
return Err(Error::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(ret as u32)
|
Ok(ret as u32)
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ pub unsafe fn ioctl_with_val(fd: RawFd, request: c_ulong, val: c_ulong) -> Resul
|
|||||||
pub unsafe fn ioctl_with_ref<T>(fd: RawFd, request: c_ulong, arg: &T) -> Result<u32> {
|
pub unsafe fn ioctl_with_ref<T>(fd: RawFd, request: c_ulong, arg: &T) -> Result<u32> {
|
||||||
let ret = libc::ioctl(fd, request, arg as *const T as *const c_void);
|
let ret = libc::ioctl(fd, request, arg as *const T as *const c_void);
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return Err(Error::from_last_errno());
|
return Err(Error::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(ret as u32)
|
Ok(ret as u32)
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ pub unsafe fn ioctl_with_ref<T>(fd: RawFd, request: c_ulong, arg: &T) -> Result<
|
|||||||
pub unsafe fn ioctl_with_mut_ref<T>(fd: RawFd, request: c_ulong, arg: &mut T) -> Result<u32> {
|
pub unsafe fn ioctl_with_mut_ref<T>(fd: RawFd, request: c_ulong, arg: &mut T) -> Result<u32> {
|
||||||
let ret = libc::ioctl(fd, request, arg as *mut T as *mut c_void);
|
let ret = libc::ioctl(fd, request, arg as *mut T as *mut c_void);
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return Err(Error::from_last_errno());
|
return Err(Error::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(ret as u32)
|
Ok(ret as u32)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user