vhost: remove session type checks
When rte_vhost tells us to start a session with given vid, we lookup the corresponsing session object from an spdk-internal session list and tell it to start polling without even specifying any backend. The vsession->vdev->type checks could only fail as a result of some spdk data corruption, so replace those with just asserts now. This code path could have never been hit in our tests anyway. Change-Id: I97c6cbe7088f338b684d291c93cbc59c44cfdc4e Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466042 Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
bfaa737dff
commit
d1d69a169c
@ -528,15 +528,7 @@ no_bdev_vdev_worker(void *arg)
|
|||||||
static struct spdk_vhost_blk_session *
|
static struct spdk_vhost_blk_session *
|
||||||
to_blk_session(struct spdk_vhost_session *vsession)
|
to_blk_session(struct spdk_vhost_session *vsession)
|
||||||
{
|
{
|
||||||
if (vsession == NULL) {
|
assert(vsession->vdev->backend == &vhost_blk_device_backend);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vsession->vdev->backend != &vhost_blk_device_backend) {
|
|
||||||
SPDK_ERRLOG("%s: not a vhost-blk device\n", vsession->vdev->name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (struct spdk_vhost_blk_session *)vsession;
|
return (struct spdk_vhost_blk_session *)vsession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +572,6 @@ _spdk_vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev, struct spdk_vhos
|
|||||||
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
|
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
|
||||||
|
|
||||||
assert(bvdev != NULL);
|
assert(bvdev != NULL);
|
||||||
|
|
||||||
spdk_bdev_close(bvdev->bdev_desc);
|
spdk_bdev_close(bvdev->bdev_desc);
|
||||||
bvdev->bdev_desc = NULL;
|
bvdev->bdev_desc = NULL;
|
||||||
bvdev->bdev = NULL;
|
bvdev->bdev = NULL;
|
||||||
@ -676,18 +667,10 @@ static int
|
|||||||
spdk_vhost_blk_start_cb(struct spdk_vhost_dev *vdev,
|
spdk_vhost_blk_start_cb(struct spdk_vhost_dev *vdev,
|
||||||
struct spdk_vhost_session *vsession, void *unused)
|
struct spdk_vhost_session *vsession, void *unused)
|
||||||
{
|
{
|
||||||
|
struct spdk_vhost_blk_session *bvsession = to_blk_session(vsession);
|
||||||
struct spdk_vhost_blk_dev *bvdev;
|
struct spdk_vhost_blk_dev *bvdev;
|
||||||
struct spdk_vhost_blk_session *bvsession;
|
|
||||||
int i, rc = 0;
|
int i, rc = 0;
|
||||||
|
|
||||||
bvsession = to_blk_session(vsession);
|
|
||||||
if (bvsession == NULL) {
|
|
||||||
SPDK_ERRLOG("%s: trying to start non-blk session as a blk one.\n",
|
|
||||||
vdev->name);
|
|
||||||
rc = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
bvdev = to_blk_dev(vdev);
|
bvdev = to_blk_dev(vdev);
|
||||||
assert(bvdev != NULL);
|
assert(bvdev != NULL);
|
||||||
bvsession->bvdev = bvdev;
|
bvsession->bvdev = bvdev;
|
||||||
@ -783,22 +766,12 @@ static int
|
|||||||
spdk_vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
spdk_vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
||||||
struct spdk_vhost_session *vsession, void *unused)
|
struct spdk_vhost_session *vsession, void *unused)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_blk_session *bvsession;
|
struct spdk_vhost_blk_session *bvsession = to_blk_session(vsession);
|
||||||
|
|
||||||
bvsession = to_blk_session(vsession);
|
|
||||||
if (bvsession == NULL) {
|
|
||||||
SPDK_ERRLOG("Trying to stop non-blk controller as a blk one.\n");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_poller_unregister(&bvsession->requestq_poller);
|
spdk_poller_unregister(&bvsession->requestq_poller);
|
||||||
bvsession->stop_poller = spdk_poller_register(destroy_session_poller_cb,
|
bvsession->stop_poller = spdk_poller_register(destroy_session_poller_cb,
|
||||||
bvsession, 1000);
|
bvsession, 1000);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
|
||||||
spdk_vhost_session_stop_done(vsession, -1);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -815,10 +788,6 @@ spdk_vhost_blk_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_writ
|
|||||||
struct spdk_vhost_blk_dev *bvdev;
|
struct spdk_vhost_blk_dev *bvdev;
|
||||||
|
|
||||||
bvdev = to_blk_dev(vdev);
|
bvdev = to_blk_dev(vdev);
|
||||||
if (bvdev == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(bvdev != NULL);
|
assert(bvdev != NULL);
|
||||||
spdk_json_write_named_object_begin(w, "block");
|
spdk_json_write_named_object_begin(w, "block");
|
||||||
|
|
||||||
@ -840,10 +809,7 @@ spdk_vhost_blk_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_w
|
|||||||
struct spdk_vhost_blk_dev *bvdev;
|
struct spdk_vhost_blk_dev *bvdev;
|
||||||
|
|
||||||
bvdev = to_blk_dev(vdev);
|
bvdev = to_blk_dev(vdev);
|
||||||
if (bvdev == NULL) {
|
assert(bvdev != NULL);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bvdev->bdev) {
|
if (!bvdev->bdev) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -874,11 +840,7 @@ spdk_vhost_blk_get_config(struct spdk_vhost_dev *vdev, uint8_t *config,
|
|||||||
uint64_t blkcnt;
|
uint64_t blkcnt;
|
||||||
|
|
||||||
bvdev = to_blk_dev(vdev);
|
bvdev = to_blk_dev(vdev);
|
||||||
if (bvdev == NULL) {
|
assert(bvdev != NULL);
|
||||||
SPDK_ERRLOG("Trying to get virito_blk configuration failed\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdev = bvdev->bdev;
|
bdev = bvdev->bdev;
|
||||||
if (bdev == NULL) {
|
if (bdev == NULL) {
|
||||||
/* We can't just return -1 here as this GET_CONFIG message might
|
/* We can't just return -1 here as this GET_CONFIG message might
|
||||||
@ -1075,10 +1037,7 @@ spdk_vhost_blk_destroy(struct spdk_vhost_dev *vdev)
|
|||||||
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
|
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!bvdev) {
|
assert(bvdev != NULL);
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = spdk_vhost_dev_unregister(&bvdev->vdev);
|
rc = spdk_vhost_dev_unregister(&bvdev->vdev);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -815,15 +815,7 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr)
|
|||||||
static struct spdk_vhost_scsi_session *
|
static struct spdk_vhost_scsi_session *
|
||||||
to_scsi_session(struct spdk_vhost_session *vsession)
|
to_scsi_session(struct spdk_vhost_session *vsession)
|
||||||
{
|
{
|
||||||
if (vsession == NULL) {
|
assert(vsession->vdev->backend == &spdk_vhost_scsi_device_backend);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vsession->vdev->backend != &spdk_vhost_scsi_device_backend) {
|
|
||||||
SPDK_ERRLOG("%s: not a vhost-scsi device.\n", vsession->vdev->name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (struct spdk_vhost_scsi_session *)vsession;
|
return (struct spdk_vhost_scsi_session *)vsession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,10 +847,7 @@ spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev)
|
|||||||
struct spdk_vhost_scsi_dev *svdev = to_scsi_dev(vdev);
|
struct spdk_vhost_scsi_dev *svdev = to_scsi_dev(vdev);
|
||||||
int rc, i;
|
int rc, i;
|
||||||
|
|
||||||
if (svdev == NULL) {
|
assert(svdev != NULL);
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; ++i) {
|
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; ++i) {
|
||||||
if (svdev->scsi_dev_state[i].dev) {
|
if (svdev->scsi_dev_state[i].dev) {
|
||||||
if (vdev->registered) {
|
if (vdev->registered) {
|
||||||
@ -890,7 +879,8 @@ spdk_vhost_scsi_dev_get_tgt(struct spdk_vhost_dev *vdev, uint8_t num)
|
|||||||
|
|
||||||
assert(num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS);
|
assert(num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS);
|
||||||
svdev = to_scsi_dev(vdev);
|
svdev = to_scsi_dev(vdev);
|
||||||
if (svdev == NULL || svdev->scsi_dev_state[num].status != VHOST_SCSI_DEV_PRESENT) {
|
assert(svdev != NULL);
|
||||||
|
if (svdev->scsi_dev_state[num].status != VHOST_SCSI_DEV_PRESENT) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -998,10 +988,7 @@ spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, int scsi_tgt_num,
|
|||||||
const char *bdev_names_list[1];
|
const char *bdev_names_list[1];
|
||||||
|
|
||||||
svdev = to_scsi_dev(vdev);
|
svdev = to_scsi_dev(vdev);
|
||||||
if (svdev == NULL) {
|
assert(svdev != NULL);
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scsi_tgt_num < 0) {
|
if (scsi_tgt_num < 0) {
|
||||||
for (scsi_tgt_num = 0; scsi_tgt_num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; scsi_tgt_num++) {
|
for (scsi_tgt_num = 0; scsi_tgt_num < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; scsi_tgt_num++) {
|
||||||
if (svdev->scsi_dev_state[scsi_tgt_num].dev == NULL) {
|
if (svdev->scsi_dev_state[scsi_tgt_num].dev == NULL) {
|
||||||
@ -1127,10 +1114,7 @@ spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
svdev = to_scsi_dev(vdev);
|
svdev = to_scsi_dev(vdev);
|
||||||
if (svdev == NULL) {
|
assert(svdev != NULL);
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
scsi_dev_state = &svdev->scsi_dev_state[scsi_tgt_num];
|
scsi_dev_state = &svdev->scsi_dev_state[scsi_tgt_num];
|
||||||
if (scsi_dev_state->dev == NULL || scsi_dev_state->status == VHOST_SCSI_DEV_ADDING) {
|
if (scsi_dev_state->dev == NULL || scsi_dev_state->status == VHOST_SCSI_DEV_ADDING) {
|
||||||
SPDK_ERRLOG("%s: SCSI target %u is not occupied\n", vdev->name, scsi_tgt_num);
|
SPDK_ERRLOG("%s: SCSI target %u is not occupied\n", vdev->name, scsi_tgt_num);
|
||||||
@ -1296,16 +1280,12 @@ static int
|
|||||||
spdk_vhost_scsi_start_cb(struct spdk_vhost_dev *vdev,
|
spdk_vhost_scsi_start_cb(struct spdk_vhost_dev *vdev,
|
||||||
struct spdk_vhost_session *vsession, void *unused)
|
struct spdk_vhost_session *vsession, void *unused)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_scsi_dev *svdev;
|
struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession);
|
||||||
struct spdk_vhost_scsi_session *svsession;
|
struct spdk_vhost_scsi_dev *svdev = svsession->svdev;
|
||||||
struct spdk_scsi_dev_vhost_state *state;
|
struct spdk_scsi_dev_vhost_state *state;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
svsession = to_scsi_session(vsession);
|
|
||||||
assert(svsession != NULL);
|
|
||||||
svdev = svsession->svdev;
|
|
||||||
|
|
||||||
/* validate all I/O queues are in a contiguous index range */
|
/* validate all I/O queues are in a contiguous index range */
|
||||||
for (i = VIRTIO_SCSI_REQUESTQ; i < vsession->max_queues; i++) {
|
for (i = VIRTIO_SCSI_REQUESTQ; i < vsession->max_queues; i++) {
|
||||||
if (vsession->virtqueue[i].vring.desc == NULL) {
|
if (vsession->virtqueue[i].vring.desc == NULL) {
|
||||||
@ -1360,17 +1340,10 @@ out:
|
|||||||
static int
|
static int
|
||||||
spdk_vhost_scsi_start(struct spdk_vhost_session *vsession)
|
spdk_vhost_scsi_start(struct spdk_vhost_session *vsession)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_scsi_session *svsession;
|
struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession);
|
||||||
struct spdk_vhost_scsi_dev *svdev;
|
struct spdk_vhost_scsi_dev *svdev;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
svsession = to_scsi_session(vsession);
|
|
||||||
if (svsession == NULL) {
|
|
||||||
SPDK_ERRLOG("%s: trying to start non-scsi session as a scsi one.\n",
|
|
||||||
vsession->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
svdev = to_scsi_dev(vsession->vdev);
|
svdev = to_scsi_dev(vsession->vdev);
|
||||||
assert(svdev != NULL);
|
assert(svdev != NULL);
|
||||||
svsession->svdev = svdev;
|
svsession->svdev = svdev;
|
||||||
@ -1450,10 +1423,7 @@ static int
|
|||||||
spdk_vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
spdk_vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
||||||
struct spdk_vhost_session *vsession, void *unused)
|
struct spdk_vhost_session *vsession, void *unused)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_scsi_session *svsession;
|
struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession);
|
||||||
|
|
||||||
svsession = to_scsi_session(vsession);
|
|
||||||
assert(svsession != NULL);
|
|
||||||
|
|
||||||
/* Stop receiving new I/O requests */
|
/* Stop receiving new I/O requests */
|
||||||
spdk_poller_unregister(&svsession->requestq_poller);
|
spdk_poller_unregister(&svsession->requestq_poller);
|
||||||
@ -1476,14 +1446,9 @@ spdk_vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
|||||||
static int
|
static int
|
||||||
spdk_vhost_scsi_stop(struct spdk_vhost_session *vsession)
|
spdk_vhost_scsi_stop(struct spdk_vhost_session *vsession)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_scsi_session *svsession;
|
struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession);
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
svsession = to_scsi_session(vsession);
|
|
||||||
if (svsession == NULL) {
|
|
||||||
SPDK_ERRLOG("Trying to stop non-scsi session as a scsi one.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
rc = spdk_vhost_session_send_event(vsession->poll_group, vsession,
|
rc = spdk_vhost_session_send_event(vsession->poll_group, vsession,
|
||||||
spdk_vhost_scsi_stop_cb, 3, "stop session");
|
spdk_vhost_scsi_stop_cb, 3, "stop session");
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
@ -1552,10 +1517,6 @@ spdk_vhost_scsi_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_
|
|||||||
struct spdk_scsi_lun *lun;
|
struct spdk_scsi_lun *lun;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (to_scsi_dev(vdev) == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_json_write_object_begin(w);
|
spdk_json_write_object_begin(w);
|
||||||
spdk_json_write_named_string(w, "method", "construct_vhost_scsi_controller");
|
spdk_json_write_named_string(w, "method", "construct_vhost_scsi_controller");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user