Skip to content

Commit

Permalink
examples: null & loop: add --forground argument
Browse files Browse the repository at this point in the history
Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Oct 21, 2023
1 parent cfd06d1 commit 147daac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
15 changes: 14 additions & 1 deletion examples/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -354,6 +361,11 @@ fn main() {
.unwrap_or(52288);
let backing_file = add_matches.get_one::<String>("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 {
Expand All @@ -372,6 +384,7 @@ fn main() {
backing_file,
ctrl_flags,
aio,
fg,
);
}
Some(("del", add_matches)) => {
Expand Down
25 changes: 22 additions & 3 deletions examples/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 147daac

Please sign in to comment.