Commit 23ef6388 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

module/vfu_device: add virtio-blk emulation



Here we use vfu-tgt library and emulate a virtio-blk device
as the first use case of vfu-tgt library.

Usage example with QEMU:

1. build/bin/spdk_tgt
2. scripts/rpc.py bdev_malloc_create -b malloc0 $((512)) 512
3. scripts/rpc.py vfu_virtio_create_blk_endpoint vfu.0 --bdev-name malloc0 \
                                                 --cpumask=0x1 --num-queues=2 \
                                                 --qsize=256 --packed-ring
4. Start QEMU with '-device vfio-user-pci,socket=/spdk/vfu.0'

Change-Id: I45e45360c669584583b0b8a3f83250ab6c48efec
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12315


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
parent da231290
Loading
Loading
Loading
Loading
+79 −0
Original line number Diff line number Diff line
@@ -8010,6 +8010,85 @@ Example response:
}
~~~

### vfu_virtio_delete_endpoint {#rpc_vfu_virtio_delete_endpoint}

Delete PCI device via endpoint name.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Endpoint name

#### Example

Example request:

~~~json
{
  "params": {
    "name": "vfu.0"
  },
  "jsonrpc": "2.0",
  "method": "vfu_virtio_delete_endpoint",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

### vfu_virtio_create_blk_endpoint {#rpc_vfu_virtio_create_blk_endpoint}

Create vfio-user virtio-blk PCI endpoint.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Endpoint name
bdev_name               | Required | string      | Block device name
cpumask                 | Optional | string      | CPU masks
num_queues              | Optional | number      | Number of queues
qsize                   | Optional | number      | Queue size
packed_ring             | Optional | boolean     | Enable packed ring

#### Example

Example request:

~~~json
{
  "params": {
    "name": "vfu.0",
    "bdev_name": "Malloc0",
    "cpumask": "0x2",
    "num_queues": 4,
    "qsize": 256
  },
  "jsonrpc": "2.0",
  "method": "vfu_virtio_create_blk_endpoint",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

## Vhost Target {#jsonrpc_components_vhost_tgt}

The following common preconditions need to be met in all target types.
+6 −0
Original line number Diff line number Diff line
@@ -160,3 +160,9 @@ DEPDIRS-event_vhost_blk := init vhost
DEPDIRS-event_vhost_scsi := init vhost event_scheduler event_scsi
DEPDIRS-event_sock := init sock
DEPDIRS-event_vfu_tgt := init vfu_tgt

# module/vfu_device

ifeq ($(CONFIG_VFIO_USER),y)
DEPDIRS-vfu_device := $(BDEV_DEPS_THREAD) vfu_tgt
endif
+5 −0
Original line number Diff line number Diff line
@@ -107,7 +107,12 @@ ifeq (y,$(DPDK_POWER))
SCHEDULER_MODULES_LIST += env_dpdk scheduler_dpdk_governor scheduler_gscheduler
endif

ifeq ($(CONFIG_VFIO_USER),y)
VFU_DEVICE_MODULES_LIST = vfu_device
endif

EVENT_BDEV_SUBSYSTEM = event_bdev event_accel event_vmd event_sock

ALL_MODULES_LIST = $(BLOCKDEV_MODULES_LIST) $(ACCEL_MODULES_LIST) $(SCHEDULER_MODULES_LIST) $(SOCK_MODULES_LIST)
ALL_MODULES_LIST += $(VFU_DEVICE_MODULES_LIST)
SYS_LIBS += $(BLOCKDEV_MODULES_PRIVATE_LIBS)
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,10 @@ ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV))
DIRS-y += env_dpdk
endif

ifeq ($(CONFIG_VFIO_USER), y)
DIRS-y += vfu_device
endif

DEPDIRS-blob :=
DEPDIRS-accel :=
DEPDIRS-env_dpdk :=
@@ -20,6 +24,7 @@ DEPDIRS-scheduler :=
DEPDIRS-bdev := blob
DEPDIRS-blobfs := blob
DEPDIRS-event := bdev blob
DEPDIRS-vfu_device :=

.PHONY: all clean $(DIRS-y)

+17 −0
Original line number Diff line number Diff line
#  SPDX-License-Identifier: BSD-3-Clause
#  Copyright (c) Intel Corporation.
#  All rights reserved.
#

SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 1
SO_MINOR := 0

C_SRCS = vfu_virtio.c vfu_virtio_blk.c vfu_virtio_rpc.c
LIBNAME = vfu_device

SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map

include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
Loading