vhost: refactor process_vq

Add process_blk_task to replace the common codes
of the process_vq and submit_inflight_desc for making
code simple.

Change-Id: I5ff146e904874714dd59249f5191a3606e523c3e
Signed-off-by: Jin Yu <jin.yu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1348
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Jin Yu 2020-03-18 18:22:26 +08:00 committed by Tomasz Zawadzki
parent 91003e5287
commit ab23eb6565

View File

@ -448,15 +448,39 @@ process_blk_request(struct spdk_vhost_blk_task *task,
return 0;
}
static void
process_blk_task(struct spdk_vhost_virtqueue *vq, uint16_t req_idx)
{
struct spdk_vhost_blk_task *task;
task = &((struct spdk_vhost_blk_task *)vq->tasks)[req_idx];
if (spdk_unlikely(task->used)) {
SPDK_ERRLOG("%s: request with idx '%"PRIu16"' is already pending.\n",
task->bvsession->vsession.name, req_idx);
task->used_len = 0;
vhost_vq_used_ring_enqueue(&task->bvsession->vsession, vq, req_idx, 0);
return;
}
task->bvsession->vsession.task_cnt++;
blk_task_init(task);
if (process_blk_request(task, task->bvsession, vq) == 0) {
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "====== Task %p req_idx %d submitted ======\n", task,
req_idx);
} else {
SPDK_ERRLOG("====== Task %p req_idx %d failed ======\n", task, req_idx);
}
}
static void
submit_inflight_desc(struct spdk_vhost_blk_session *bvsession,
struct spdk_vhost_virtqueue *vq)
{
struct spdk_vhost_blk_task *task;
struct spdk_vhost_session *vsession = &bvsession->vsession;
spdk_vhost_resubmit_info *resubmit = vq->vring_inflight.resubmit_inflight;
spdk_vhost_resubmit_desc *resubmit_list;
int rc;
uint16_t req_idx;
if (spdk_likely(resubmit == NULL || resubmit->resubmit_list == NULL)) {
@ -476,26 +500,7 @@ submit_inflight_desc(struct spdk_vhost_blk_session *bvsession,
continue;
}
task = &((struct spdk_vhost_blk_task *)vq->tasks)[req_idx];
if (spdk_unlikely(task->used)) {
SPDK_ERRLOG("%s: request with idx '%"PRIu16"' is already pending.\n",
vsession->name, req_idx);
vhost_vq_used_ring_enqueue(vsession, vq, req_idx, 0);
continue;
}
vsession->task_cnt++;
blk_task_init(task);
rc = process_blk_request(task, bvsession, vq);
if (rc == 0) {
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "====== Task %p req_idx %d submitted ======\n", task,
req_idx);
} else {
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "====== Task %p req_idx %d failed ======\n", task,
req_idx);
}
process_blk_task(vq, req_idx);
}
free(resubmit_list);
@ -505,9 +510,7 @@ submit_inflight_desc(struct spdk_vhost_blk_session *bvsession,
static void
process_vq(struct spdk_vhost_blk_session *bvsession, struct spdk_vhost_virtqueue *vq)
{
struct spdk_vhost_blk_task *task;
struct spdk_vhost_session *vsession = &bvsession->vsession;
int rc;
uint16_t reqs[32];
uint16_t reqs_cnt, i;
uint16_t vq_idx = vq->vring_idx;
@ -531,25 +534,8 @@ process_vq(struct spdk_vhost_blk_session *bvsession, struct spdk_vhost_virtqueue
}
rte_vhost_set_inflight_desc_split(vsession->vid, vq_idx, reqs[i]);
task = &((struct spdk_vhost_blk_task *)vq->tasks)[reqs[i]];
if (spdk_unlikely(task->used)) {
SPDK_ERRLOG("%s: request with idx '%"PRIu16"' is already pending.\n",
vsession->name, reqs[i]);
vhost_vq_used_ring_enqueue(vsession, vq, reqs[i], 0);
continue;
}
vsession->task_cnt++;
blk_task_init(task);
rc = process_blk_request(task, bvsession, vq);
if (rc == 0) {
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "====== Task %p req_idx %d submitted ======\n", task,
reqs[i]);
} else {
SPDK_DEBUGLOG(SPDK_LOG_VHOST_BLK, "====== Task %p req_idx %d failed ======\n", task, reqs[i]);
}
process_blk_task(vq, reqs[i]);
}
}