rust/pv: Replace libc wherever possible

Replace all libc references to rust-std references if available.
This eliminates the need to include libc in the pv crate.
However, pv_base still refers to libc::ioctl and libc::ENOTTY.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Steffen Eiden
2023-12-07 10:52:32 +01:00
committed by Jan Höppner
parent b71279cda5
commit 02dded11a5
9 changed files with 14 additions and 21 deletions
+1 -1
View File
@@ -5,10 +5,10 @@
#![allow(non_camel_case_types)]
use crate::FileAccessErrorType;
use crate::{Error, Result};
use libc::c_ulong;
use log::debug;
use std::{
convert::TryInto,
ffi::c_ulong,
fs::File,
os::unix::prelude::{AsRawFd, RawFd},
};
+5 -8
View File
@@ -5,6 +5,7 @@
#![cfg(test)]
use std::{
ffi::{c_int, c_ulong},
os::unix::prelude::FromRawFd,
sync::{Mutex, MutexGuard},
};
@@ -28,18 +29,18 @@ fn get_lock<T>(m: &'static Mutex<T>) -> MutexGuard<'static, T> {
struct IoctlCtx {
modify: Box<dyn FnMut(&mut ffi::uvio_ioctl_cb) -> i32 + Send + Sync>,
exp_cmd: ::libc::c_ulong,
exp_cmd: c_ulong,
called: bool,
}
impl IoctlCtx {
pub fn exp_cmd(&mut self, cmd: ::libc::c_ulong) -> &mut Self {
pub fn exp_cmd(&mut self, cmd: c_ulong) -> &mut Self {
self.exp_cmd = cmd;
self
}
pub fn set_mdfy<F>(&mut self, mdfy: F) -> &mut Self
where
F: FnMut(&mut ffi::uvio_ioctl_cb) -> ::libc::c_int + 'static + Send + Sync,
F: FnMut(&mut ffi::uvio_ioctl_cb) -> c_int + 'static + Send + Sync,
{
self.modify = Box::new(mdfy);
self
@@ -62,11 +63,7 @@ impl IoctlCtx {
pub mod mock_libc {
use super::*;
pub unsafe fn ioctl(
fd: ::libc::c_int,
cmd: ::libc::c_ulong,
data: *mut ffi::uvio_ioctl_cb,
) -> ::libc::c_int {
pub unsafe fn ioctl(fd: c_int, cmd: c_ulong, data: *mut ffi::uvio_ioctl_cb) -> c_int {
let mut ctx = get_lock(&IOCTL_MTX);
assert!(!ctx.called, "IOCTL called more than once");
ctx.called = true;