ublk

杏子的成长日记 / 2023-07-16 / 原文

资源整理

ebpf+ublk内核代码:https://lore.kernel.org/all/20230222132534.114574-1-xiaoguang.wang@linux.alibaba.com/
需要学习:

  • Linux内核源码:drivers/block/ublk_drv.c 链接:https://github.com/ming1/ubdsrv(内核驱动,只关注2023.2.22之前的版本)
  • 用户态代码:https://github.com/ming1/ubdsrv (2023.2.22之前的版本)

ebpf程序:https://lore.kernel.org/all/20230222132534.114574-1-xiaoguang.wang@linux.alibaba.com/

验收目标:安装好ublk内核模块,启动ublksrv daemon,会出现ublk设备。然后用fio读写这个ublk设备就行

ebpf+ublk内核代码

u64 bpf_ublk_queue_sqe(struct ublk_io_bpf_ctx *bpf_ctx, struct io_uring_sqe *sqe, u32 sqe_len, u32, fd)会使用io_uring 提交io请求
ideas来源:Pavel's patchset [2]

git clone https://github.com/ming1/ubdsrv
  cd ubdsrv
  git am -3 0001-Add-ebpf-support.patch
  # replace "/root/ublk/" with your own linux build directory
  cd bpf; make; cd ..;
  ./build_with_liburing_src
  ./ublk add -t loop -q 1 -d 128 -f loop.file

Linux内核安装

Linux内核版本:5.10
打补丁:https://lore.kernel.org/all/20230222132534.114574-1-xiaoguang.wang@linux.alibaba.com/#r

编译Linux内核,需要打三个补丁:
https://lore.kernel.org/all/20230222132534.114574-2-xiaoguang.wang@linux.alibaba.com/
https://lore.kernel.org/all/20230222132534.114574-3-xiaoguang.wang@linux.alibaba.com/
https://lore.kernel.org/all/20230222132534.114574-4-xiaoguang.wang@linux.alibaba.com/

编译ublk:
https://lore.kernel.org/all/20230222132534.114574-1-xiaoguang.wang@linux.alibaba.com/
需要打补丁:https://lore.kernel.org/all/20230222132744.117182-1-xiaoguang.wang@linux.alibaba.com/