Commit 4d453b24 authored by Anton Nayshtut's avatar Anton Nayshtut Committed by Jim Harris
Browse files

module/vfu_device: vfu_virtio_fs introduced

This patch set implements the virtiofs vfio-user device based on SPDK fsdev +
FUSE dispatcher.

Steps to run w/QEMU:

1. Run target:

  build/bin/spdk_tgt -S /tmp/vfio-sockets

2. Create an fsdev and a corresponding vfu endpoint:

  spdk_rpc.py fsdev_aio_create aio0 /tmp/vfio-test
  spdk_rpc.py vfu_virtio_create_fs_endpoint vfufs.0 --fsdev-name aio0 \
    --tag vfu_test --cpumask=0x1 --num-queues=8 --qsize=256 --packed-ring

3. Run the QEMU with:

  -device vfio-user-pci,socket=/tmp/vfio-sockets/vfufs.0

Then inside the VM:

  $ mkdir /tmp/zzz
  $ modprobe -v virtiofs
  $ mount -t virtiofs vfu_test /tmp/zzz

NOTE: as the implementation is based upon the nutanix/libvfio-user library
([1]) similar to vfu_virtio_blk and vfu_virtio_scsi. It requires an QEMU
version that supports the vfio-virtio-pci devices. More information can be
found in the libvfio-user README ([2]).

[1] https://github.com/nutanix/libvfio-user
[2] https://github.com/nutanix/libvfio-user/blob/master/README.md



Change-Id: I182119aced0640d6f9290802d91f93b27294f468
Signed-off-by: default avatarAnton Nayshtut <anayshtut@nvidia.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24086


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
parent a9eea50d
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -9512,6 +9512,52 @@ Example response:
}
~~~

### vfu_virtio_create_fs_endpoint {#vfu_virtio_create_fs_endpoint}

Create vfio-user virtio-fs PCI endpoint.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Endpoint name
fsdev_name              | Optional | string      | Name of an underlying fsdev
tag                     | Optional | string      | Virtio FS tag according to the virtio specification
cpumask                 | Optional | string      | CPU masks
num_queues              | Optional | number      | Number of IO queues
qsize                   | Optional | number      | Queue size
packed_ring             | Optional | boolean     | Enable packed ring

#### Example

Example request:

~~~json
{
  "params": {
    "name": "vfu.0",
    "fsdev_name": "aio0",
    "tag": "virtiofs0",
    "cpumask": "0x2",
    "num_queues": 4,
    "qsize": 256
  },
  "jsonrpc": "2.0",
  "method": "vfu_virtio_create_fs_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.
+22 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */

#ifndef _LINUX_VIRTIO_FS_H
#define _LINUX_VIRTIO_FS_H

#include <linux/types.h>
#include <linux/virtio_ids.h>
#include <linux/virtio_config.h>
#include <linux/virtio_types.h>

struct virtio_fs_config {
	/* Filesystem name (UTF-8, not NUL-terminated, padded with NULs) */
	__u8 tag[36];

	/* Number of request queues */
	__le32 num_request_queues;
} __attribute__((packed));

/* For the id field in virtio_pci_shm_cap */
#define VIRTIO_FS_SHMCAP_ID_CACHE 0

#endif /* _LINUX_VIRTIO_FS_H */
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ extern "C" {
#define PCI_DEVICE_ID_VIRTIO_SCSI_LEGACY 0x1004
#define PCI_DEVICE_ID_VIRTIO_BLK_MODERN	0x1042
#define PCI_DEVICE_ID_VIRTIO_SCSI_MODERN 0x1048
#define PCI_DEVICE_ID_VIRTIO_FS		0x105A

#define PCI_DEVICE_ID_VIRTIO_VHOST_USER 0x1017

+3 −0
Original line number Diff line number Diff line
@@ -200,6 +200,9 @@ DEPDIRS-event_fsdev := init fsdev

ifeq ($(CONFIG_VFIO_USER),y)
DEPDIRS-vfu_device := $(BDEV_DEPS_THREAD) scsi vfu_tgt
ifeq ($(CONFIG_FSDEV),y)
DEPDIRS-vfu_device += fuse_dispatcher
endif
endif

# module/keyring
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,10 @@ SO_MINOR := 0
C_SRCS = vfu_virtio.c vfu_virtio_blk.c vfu_virtio_scsi.c vfu_virtio_rpc.c
LIBNAME = vfu_device

ifeq ($(CONFIG_FSDEV),y)
C_SRCS += vfu_virtio_fs.c
endif

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

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