xref: /dpdk/doc/guides/sample_app_ug/vhost_blk.rst (revision e2a94f9ad3ef949c0df3e63699bd4e381b5003d9)
1c19beb3fSJin Yu..  SPDX-License-Identifier: BSD-3-Clause
2c19beb3fSJin Yu    Copyright(c) 2010-2017 Intel Corporation.
3c19beb3fSJin Yu
4c19beb3fSJin YuVhost_blk Sample Application
5c19beb3fSJin Yu=============================
6c19beb3fSJin Yu
7c19beb3fSJin YuThe vhost_blk sample application implemented a simple block device,
8c19beb3fSJin Yuwhich used as the  backend of Qemu vhost-user-blk device. Users can extend
9c19beb3fSJin Yuthe exist example to use other type of block device(e.g. AIO) besides
10c19beb3fSJin Yumemory based block device. Similar with vhost-user-net device, the sample
11c19beb3fSJin Yuapplication used domain socket to communicate with Qemu, and the virtio
12c19beb3fSJin Yuring (split or packed format) was processed by vhost_blk sample application.
13c19beb3fSJin Yu
14c19beb3fSJin YuThe sample application reuse lots codes from SPDK(Storage Performance
15c19beb3fSJin YuDevelopment Kit, https://github.com/spdk/spdk) vhost-user-blk target,
16c19beb3fSJin Yufor DPDK vhost library used in storage area, user can take SPDK as
17c19beb3fSJin Yureference as well.
18c19beb3fSJin Yu
19c19beb3fSJin YuTesting steps
20c19beb3fSJin Yu-------------
21c19beb3fSJin Yu
22c19beb3fSJin YuThis section shows the steps how to start a VM with the block device as
23c19beb3fSJin Yufast data path for critical application.
24c19beb3fSJin Yu
25c19beb3fSJin YuCompiling the Application
26c19beb3fSJin Yu-------------------------
27c19beb3fSJin Yu
28c19beb3fSJin YuTo compile the sample application see :doc:`compiling`.
29c19beb3fSJin Yu
30c19beb3fSJin YuThe application is located in the ``examples`` sub-directory.
31c19beb3fSJin Yu
32c19beb3fSJin YuYou will also need to build DPDK both on the host and inside the guest
33c19beb3fSJin Yu
34c19beb3fSJin YuStart the vhost_blk example
35c19beb3fSJin Yu~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36c19beb3fSJin Yu
37c19beb3fSJin Yu.. code-block:: console
38c19beb3fSJin Yu
39*e2a94f9aSCiara Power        ./dpdk-vhost_blk -m 1024
40c19beb3fSJin Yu
41c19beb3fSJin Yu.. _vhost_blk_app_run_vm:
42c19beb3fSJin Yu
43c19beb3fSJin YuStart the VM
44c19beb3fSJin Yu~~~~~~~~~~~~
45c19beb3fSJin Yu
46c19beb3fSJin Yu.. code-block:: console
47c19beb3fSJin Yu
48c19beb3fSJin Yu    qemu-system-x86_64 -machine accel=kvm \
49c19beb3fSJin Yu        -m $mem -object memory-backend-file,id=mem,size=$mem,\
50c19beb3fSJin Yu        mem-path=/dev/hugepages,share=on -numa node,memdev=mem \
51c19beb3fSJin Yu        -drive file=os.img,if=none,id=disk \
52c19beb3fSJin Yu        -device ide-hd,drive=disk,bootindex=0 \
53c19beb3fSJin Yu        -chardev socket,id=char0,reconnect=1,path=/tmp/vhost.socket \
5491d3e2d4SJin Yu        -device vhost-user-blk-pci,packed=on,chardev=char0,num-queues=1 \
55c19beb3fSJin Yu        ...
56c19beb3fSJin Yu
57c19beb3fSJin Yu.. note::
58c19beb3fSJin Yu    You must check whether your Qemu can support "vhost-user-blk" or not,
59c19beb3fSJin Yu    Qemu v4.0 or newer version is required.
60c19beb3fSJin Yu    reconnect=1 means live recovery support that qemu can reconnect vhost_blk
61c19beb3fSJin Yu    after we restart vhost_blk example.
6291d3e2d4SJin Yu    packed=on means the device support packed ring but need the guest kernel
6391d3e2d4SJin Yu    version >= 5.0.
6491d3e2d4SJin Yu    Now Qemu commit 9bb73502321d46f4d320fa17aa38201445783fc4 both support the
6591d3e2d4SJin Yu    vhost-blk reconnect and packed ring.
66