ublk-org / ublksrv

ublk: userspace block device driver
MIT License
147 stars 50 forks source link

[v3]ublksrv: add NEED_GET_DATA support #3

Closed old-memories closed 2 years ago

old-memories commented 2 years ago

UBLKSRV_NEED_GET_DATA is one new flag used by ublksrv to support NEED_GET_DATA in ublk.

For now, ublk only support pre-allocated buffer which stores data to be written/read by backend(target). In this way, a backend has no chance to pass its own data buffer(e,g. RPC buffer) to ublksrv AFTER it gets a write request and one additional copy (from ublksrv pre-allocated buffer to backend's buffer) is necessary.

NEED_GET_DATA is one new feature for users who want to set IO buffer ONLY AFTER it gets one new WRITE request.

In detail, NEED_GET_DATA works as follow:

(1) After ublksrv get UBLK_IO_RES_NEED_GET_DATA from a cqe. It should set UBLKSRV_NEED_GET_DATA. Now ublksrv does not let backend(target) handle this IO(write) request. At the same time, the user application has a chance to pass IO buffer address allocated by itself. This IO buffer is used to copy data from bio vectors for a WRITE request.

(2) While queuing new ublk IO command, ublksrv should check this flag and set opcode to UBLK_IO_NEED_GET_DATA. The new ublk IO command will be issued to kernel ublk_drv with new IO buffer address from backend.

UBLK_F_NEED_GET_DATA is one optional feature for applications. You may choose open it or not in demo_null, demo_event and ublksrv_tgt.

Finally, test cases are added for NEED_GET_DATA and all tests passes.

changes from V2 to V3:

(1) update ublk_cmd.h and ublksrv.c in one single patch to avoid compiler error. (2) add new option for demo_null.c and demo_event.c

changes from V1 to V2:

(1) UBLK_F_NEED_GET_DATA as one optional feature. Users can switch it on. (2) Add more test cases under tests/

Signed-off-by: ZiyangZhang ZiyangZhang@linux.alibaba.com

ming1 commented 2 years ago

Applied, thanks!