-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
147e59b
commit 968e65d
Showing
8 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
#[cfg(target_os = "linux")] | ||
extern crate bindgen; | ||
extern crate rustc_version; | ||
|
||
use rustc_version::{version_meta, Channel}; | ||
|
||
#[cfg(target_os = "linux")] | ||
fn gen_linux_aio_bindings() { | ||
use std::env; | ||
use std::path::PathBuf; | ||
// The bindgen::Builder is the main entry point | ||
// to bindgen, and lets you build up options for | ||
// the resulting bindings. | ||
let bindings = bindgen::Builder::default() | ||
.trust_clang_mangling(false) | ||
// The input header we would like to generate | ||
// bindings for. | ||
.header("linux_aio_wrapper.h") | ||
// Finish the builder and generate the bindings. | ||
.generate() | ||
// Unwrap the Result and panic on failure. | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the $OUT_DIR/linux_bindings.rs file. | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("linux_bindings.rs")) | ||
.expect("Couldn't write linux_bindings.rs!"); | ||
} | ||
|
||
fn main() { | ||
// Set cfg flags depending on release channel | ||
if let Channel::Nightly = version_meta().unwrap().channel { | ||
println!("cargo:rustc-cfg=nightly"); | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
gen_linux_aio_bindings(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <time.h> | ||
#include <unistd.h> | ||
#include <linux/aio_abi.h> | ||
#include <sys/eventfd.h> | ||
#include <sys/syscall.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,6 @@ impl File { | |
}); | ||
} | ||
} | ||
dbg!(path.as_ref()); | ||
let file = fs_impl::create(path)?; | ||
File::from(file) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#![allow(dead_code)] | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_snake_case)] | ||
|
||
include!(concat!(env!("OUT_DIR"), "/linux_bindings.rs")); | ||
|
||
/* | ||
* extracted from https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/fs.h#L372 | ||
* Flags for preadv2/pwritev2: | ||
*/ | ||
|
||
/* per-IO O_DSYNC */ | ||
//#define RWF_DSYNC ((__force __kernel_rwf_t)0x00000002) | ||
pub const RWF_DSYNC: u32 = 2; | ||
|
||
/* per-IO O_SYNC */ | ||
//#define RWF_SYNC ((__force __kernel_rwf_t)0x00000004) | ||
pub const RWF_SYNC: u32 = 4; | ||
|
||
/* per-IO, return -EAGAIN if operation would block */ | ||
//#define RWF_NOWAIT ((__force __kernel_rwf_t)0x00000008) | ||
pub const RWF_NOWAIT: u32 = 8; | ||
|
||
|
||
pub use libc::c_long; | ||
|
||
// Relevant symbols from the native bindings exposed via aio-bindings | ||
// pub use self::{aio_context_t, io_event, iocb, syscall, timespec, | ||
// __NR_io_destroy, __NR_io_getevents, __NR_io_setup, __NR_io_submit, | ||
// IOCB_CMD_PREAD, IOCB_CMD_PWRITE, IOCB_CMD_FSYNC, IOCB_CMD_FDSYNC, IOCB_FLAG_RESFD, | ||
// RWF_DSYNC, RWF_SYNC}; | ||
|
||
// ----------------------------------------------------------------------------------------------- | ||
// Inline functions that wrap the kernel calls for the entry points corresponding to Linux | ||
// AIO functions | ||
// ----------------------------------------------------------------------------------------------- | ||
|
||
// Initialize an AIO context for a given submission queue size within the kernel. | ||
// | ||
// See [io_setup(7)](http://man7.org/linux/man-pages/man2/io_setup.2.html) for details. | ||
#[inline(always)] | ||
pub unsafe fn io_setup(nr: c_long, ctxp: *mut aio_context_t) -> c_long { | ||
syscall(__NR_io_setup as c_long, nr, ctxp) | ||
} | ||
|
||
// Destroy an AIO context. | ||
// | ||
// See [io_destroy(7)](http://man7.org/linux/man-pages/man2/io_destroy.2.html) for details. | ||
#[inline(always)] | ||
pub unsafe fn io_destroy(ctx: aio_context_t) -> c_long { | ||
syscall(__NR_io_destroy as c_long, ctx) | ||
} | ||
|
||
// Submit a batch of IO operations. | ||
// | ||
// See [io_sumit(7)](http://man7.org/linux/man-pages/man2/io_submit.2.html) for details. | ||
#[inline(always)] | ||
pub unsafe fn io_submit(ctx: aio_context_t, nr: c_long, iocbpp: *mut *mut iocb) -> c_long { | ||
syscall(__NR_io_submit as c_long, ctx, nr, iocbpp) | ||
} | ||
|
||
// Retrieve completion events for previously submitted IO requests. | ||
// | ||
// See [io_getevents(7)](http://man7.org/linux/man-pages/man2/io_getevents.2.html) for details. | ||
#[inline(always)] | ||
pub unsafe fn io_getevents( | ||
ctx: aio_context_t, | ||
min_nr: c_long, | ||
max_nr: c_long, | ||
events: *mut io_event, | ||
timeout: *mut timespec, | ||
) -> c_long { | ||
syscall( | ||
__NR_io_getevents as c_long, | ||
ctx, | ||
min_nr, | ||
max_nr, | ||
events, | ||
timeout, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters