Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and run multiple devices #1

Open
wwylele opened this issue Nov 5, 2023 · 1 comment
Open

Create and run multiple devices #1

wwylele opened this issue Nov 5, 2023 · 1 comment

Comments

@wwylele
Copy link

wwylele commented Nov 5, 2023

Is there an example of how to properly create and run multiple block devices in a single process? The recommended run_target only accepts one device and dedicates the current thread for that device. I tried running run_target in multiple threads simultaneously, but that seems to invoke some sort of race condition, which causes all threads to block on starting the handler and never create the device. Adding delay between these threads seem to resolve the problem, but obviously that shouldn't be the proper way to do it.

@ming1
Copy link
Collaborator

ming1 commented Nov 6, 2023

Hello,

There isn't such example yet, and this feature is planned to
be supported in 0.3 by converting control commands into
async/await.

However you still can do that with current interfaces, and please refer to examples/ramdisk.rs, in which one ublk device
is created, such as:

  1. start one device:

let (mut ctrl, dev) = sess.create_devices();
ctrl.configure_queue(&dev, 0, unsafe { libc::gettid() })
let (token, buf) = ctrl.submit_start_dev(&dev).unwrap();
let res = loop {
let _ = q_rc.flush_and_wake_io_tasks(&exe, 0);
let _res = ctrl.poll_start_dev(token);
...
};

  1. repeat the above logic for N devices in current process

  2. run epoll() on all queue's ring FD, and once there is an
    event coming, call q_rc.flush_and_wake_io_tasks(exe, 0) for this queue.

The drawback is that you have to start device one by one.

Once control command is converted to async/await, multiple
devices can be supported concurrently in single task. And in
future, shared (both control and data) uring will be supported too for creating N devices in single task.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants