vhost-blk: add resize bdev support
This will allow us to resize the backend bdev of vhost-blk and notify the guest OS that the capactiy of virtio-blk disk has been resized. The spdk api entry is `spdk_bdev_notify_blockcnt_change`. Any bdev if used as vhost-blk backend may need to implement a rpc that calls this function. Related DPDK patch has been merged and release in 20.02. https://www.mail-archive.com/dev@dpdk.org/msg153365.html Change-Id: I961c61de0fc03e210d776035a40f3a4adfa9b4f3 Signed-off-by: Li Feng <fengli@smartx.com> Signed-off-by: Jin Yu <jin.yu@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1468 Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
0b1799cd98
commit
b45f293d57
@ -44,6 +44,7 @@
|
|||||||
#include "spdk/vhost.h"
|
#include "spdk/vhost.h"
|
||||||
|
|
||||||
#include "vhost_internal.h"
|
#include "vhost_internal.h"
|
||||||
|
#include <rte_version.h>
|
||||||
|
|
||||||
/* Minimal set of features supported by every SPDK VHOST-BLK device */
|
/* Minimal set of features supported by every SPDK VHOST-BLK device */
|
||||||
#define SPDK_VHOST_BLK_FEATURES_BASE (SPDK_VHOST_FEATURES | \
|
#define SPDK_VHOST_BLK_FEATURES_BASE (SPDK_VHOST_FEATURES | \
|
||||||
@ -801,6 +802,32 @@ to_blk_dev(struct spdk_vhost_dev *vdev)
|
|||||||
return SPDK_CONTAINEROF(vdev, struct spdk_vhost_blk_dev, vdev);
|
return SPDK_CONTAINEROF(vdev, struct spdk_vhost_blk_dev, vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vhost_session_bdev_resize_cb(struct spdk_vhost_dev *vdev,
|
||||||
|
struct spdk_vhost_session *vsession,
|
||||||
|
void *ctx)
|
||||||
|
{
|
||||||
|
#if RTE_VERSION >= RTE_VERSION_NUM(20, 02, 0, 0)
|
||||||
|
SPDK_NOTICELOG("bdev send slave msg to vid(%d)\n", vsession->vid);
|
||||||
|
rte_vhost_slave_config_change(vsession->vid, false);
|
||||||
|
#else
|
||||||
|
SPDK_NOTICELOG("bdev does not support resize until DPDK submodule version >= 20.02\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
blk_resize_cb(void *resize_ctx)
|
||||||
|
{
|
||||||
|
struct spdk_vhost_blk_dev *bvdev = resize_ctx;
|
||||||
|
|
||||||
|
spdk_vhost_lock();
|
||||||
|
vhost_dev_foreach_session(&bvdev->vdev, vhost_session_bdev_resize_cb,
|
||||||
|
NULL, NULL);
|
||||||
|
spdk_vhost_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vhost_dev_bdev_remove_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
|
vhost_dev_bdev_remove_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
|
||||||
{
|
{
|
||||||
@ -845,6 +872,29 @@ bdev_remove_cb(void *remove_ctx)
|
|||||||
spdk_vhost_unlock();
|
spdk_vhost_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
|
||||||
|
void *event_ctx)
|
||||||
|
{
|
||||||
|
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "Bdev event: type %d, name %s\n",
|
||||||
|
type,
|
||||||
|
bdev->name);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SPDK_BDEV_EVENT_REMOVE:
|
||||||
|
SPDK_NOTICELOG("bdev name (%s) received event(SPDK_BDEV_EVENT_REMOVE)\n", bdev->name);
|
||||||
|
bdev_remove_cb(event_ctx);
|
||||||
|
break;
|
||||||
|
case SPDK_BDEV_EVENT_RESIZE:
|
||||||
|
SPDK_NOTICELOG("bdev name (%s) received event(SPDK_BDEV_EVENT_RESIZE)\n", bdev->name);
|
||||||
|
blk_resize_cb(event_ctx);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SPDK_NOTICELOG("Unsupported bdev event: type %d\n", type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_task_pool(struct spdk_vhost_blk_session *bvsession)
|
free_task_pool(struct spdk_vhost_blk_session *bvsession)
|
||||||
{
|
{
|
||||||
@ -1234,7 +1284,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
|
|||||||
vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_FLUSH);
|
vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc);
|
ret = spdk_bdev_open_ext(dev_name, true, bdev_event_cb, bvdev, &bvdev->bdev_desc);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
SPDK_ERRLOG("%s: could not open bdev '%s', error=%d\n",
|
SPDK_ERRLOG("%s: could not open bdev '%s', error=%d\n",
|
||||||
name, dev_name, ret);
|
name, dev_name, ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user