From 147daac4e905597be8eb887e06f7e0d48fca50f7 Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Wed, 18 Oct 2023 15:27:17 +0000 Subject: [PATCH] examples: null & loop: add --forground argument Signed-off-by: Ming Lei --- examples/loop.rs | 15 ++++++++++++++- examples/null.rs | 25 ++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/examples/loop.rs b/examples/loop.rs index ccab1b2..cc65132 100644 --- a/examples/loop.rs +++ b/examples/loop.rs @@ -176,8 +176,9 @@ fn test_add( backing_file: &String, ctrl_flags: u64, aio: bool, + fg: bool, ) { - let _pid = unsafe { libc::fork() }; + let _pid = if !fg { unsafe { libc::fork() } } else { 0 }; if _pid == 0 { __test_add(id, nr_queues, depth, buf_sz, backing_file, ctrl_flags, aio); @@ -315,6 +316,12 @@ fn main() { .short('a') .action(ArgAction::SetTrue) .help("use async/await to handle IO command"), + ) + .arg( + Arg::new("forground") + .long("forground") + .action(ArgAction::SetTrue) + .help("run in forground mode"), ), ) .subcommand( @@ -354,6 +361,11 @@ fn main() { .unwrap_or(52288); let backing_file = add_matches.get_one::("backing_file").unwrap(); + let fg = if add_matches.get_flag("forground") { + true + } else { + false + }; let ctrl_flags: u64 = if add_matches.get_flag("unprivileged") { libublk::sys::UBLK_F_UNPRIVILEGED_DEV as u64 } else { @@ -372,6 +384,7 @@ fn main() { backing_file, ctrl_flags, aio, + fg, ); } Some(("del", add_matches)) => { diff --git a/examples/null.rs b/examples/null.rs index 816400c..088e2f8 100755 --- a/examples/null.rs +++ b/examples/null.rs @@ -12,8 +12,16 @@ fn handle_io_cmd(q: &UblkQueue, tag: u16) { q.complete_io_cmd(tag, Ok(UblkIORes::Result(bytes))); } -fn test_add(id: i32, nr_queues: u32, depth: u32, ctrl_flags: u64, buf_size: u32, aio: bool) { - let _pid = unsafe { libc::fork() }; +fn test_add( + id: i32, + nr_queues: u32, + depth: u32, + ctrl_flags: u64, + buf_size: u32, + aio: bool, + fg: bool, +) { + let _pid = if !fg { unsafe { libc::fork() } } else { 0 }; if _pid == 0 { __test_add(id, nr_queues, depth, ctrl_flags, buf_size, aio); } @@ -142,6 +150,12 @@ fn main() { .short('a') .action(ArgAction::SetTrue) .help("use async/await to handle IO command"), + ) + .arg( + Arg::new("forground") + .long("forground") + .action(ArgAction::SetTrue) + .help("run in forground mode"), ), ) .subcommand( @@ -195,7 +209,12 @@ fn main() { } else { false }; - test_add(id, nr_queues, depth, ctrl_flags, buf_size, aio); + let fg = if add_matches.get_flag("forground") { + true + } else { + false + }; + test_add(id, nr_queues, depth, ctrl_flags, buf_size, aio, fg); } Some(("del", add_matches)) => { let id = add_matches