diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2013-06-07 20:47:46 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2013-09-09 17:29:18 -0400 |
commit | 4824d3bfb9097ac59cf7633c0bc4fb7c5b549a80 (patch) | |
tree | 452934fb853e1d9c98cfeb6981903006e58beca5 /drivers/vhost/scsi.c | |
parent | c0add7fd05ff99c3a516c78eb6b1e6460a3efdae (diff) |
vhost/scsi: Convert to per-cpu ida_alloc + ida_free command map
This patch changes vhost/scsi to use transport_init_session_tags()
pre-allocation logic for per-cpu session tag pooling with internal
ida_alloc() + ida_free() calls based upon the saved se_cmd->map_tag id.
FIXME: Make transport_init_session_tags() number of tags setup
configurable per vring client setting via configfs
v5 changes:
- Convert to percpu_ida.h include
v3 changes:
- Update to percpu-ida usage
- Rebase to v3.11-rc5 code
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Asias He <asias@redhat.com>
Cc: Kent Overstreet <kmo@daterainc.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/vhost/scsi.c')
-rw-r--r-- | drivers/vhost/scsi.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 0c27c7df1b09..8cd545ad3f51 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c | |||
@@ -48,12 +48,14 @@ | |||
48 | #include <linux/virtio_scsi.h> | 48 | #include <linux/virtio_scsi.h> |
49 | #include <linux/llist.h> | 49 | #include <linux/llist.h> |
50 | #include <linux/bitmap.h> | 50 | #include <linux/bitmap.h> |
51 | #include <linux/percpu_ida.h> | ||
51 | 52 | ||
52 | #include "vhost.h" | 53 | #include "vhost.h" |
53 | 54 | ||
54 | #define TCM_VHOST_VERSION "v0.1" | 55 | #define TCM_VHOST_VERSION "v0.1" |
55 | #define TCM_VHOST_NAMELEN 256 | 56 | #define TCM_VHOST_NAMELEN 256 |
56 | #define TCM_VHOST_MAX_CDB_SIZE 32 | 57 | #define TCM_VHOST_MAX_CDB_SIZE 32 |
58 | #define TCM_VHOST_DEFAULT_TAGS 256 | ||
57 | 59 | ||
58 | struct vhost_scsi_inflight { | 60 | struct vhost_scsi_inflight { |
59 | /* Wait for the flush operation to finish */ | 61 | /* Wait for the flush operation to finish */ |
@@ -450,6 +452,7 @@ static void tcm_vhost_release_cmd(struct se_cmd *se_cmd) | |||
450 | { | 452 | { |
451 | struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd, | 453 | struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd, |
452 | struct tcm_vhost_cmd, tvc_se_cmd); | 454 | struct tcm_vhost_cmd, tvc_se_cmd); |
455 | struct se_session *se_sess = se_cmd->se_sess; | ||
453 | 456 | ||
454 | if (tv_cmd->tvc_sgl_count) { | 457 | if (tv_cmd->tvc_sgl_count) { |
455 | u32 i; | 458 | u32 i; |
@@ -460,7 +463,7 @@ static void tcm_vhost_release_cmd(struct se_cmd *se_cmd) | |||
460 | } | 463 | } |
461 | 464 | ||
462 | tcm_vhost_put_inflight(tv_cmd->inflight); | 465 | tcm_vhost_put_inflight(tv_cmd->inflight); |
463 | kfree(tv_cmd); | 466 | percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); |
464 | } | 467 | } |
465 | 468 | ||
466 | static int tcm_vhost_shutdown_session(struct se_session *se_sess) | 469 | static int tcm_vhost_shutdown_session(struct se_session *se_sess) |
@@ -704,7 +707,7 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work) | |||
704 | } | 707 | } |
705 | 708 | ||
706 | static struct tcm_vhost_cmd * | 709 | static struct tcm_vhost_cmd * |
707 | vhost_scsi_allocate_cmd(struct vhost_virtqueue *vq, | 710 | vhost_scsi_get_tag(struct vhost_virtqueue *vq, |
708 | struct tcm_vhost_tpg *tpg, | 711 | struct tcm_vhost_tpg *tpg, |
709 | struct virtio_scsi_cmd_req *v_req, | 712 | struct virtio_scsi_cmd_req *v_req, |
710 | u32 exp_data_len, | 713 | u32 exp_data_len, |
@@ -712,18 +715,21 @@ vhost_scsi_allocate_cmd(struct vhost_virtqueue *vq, | |||
712 | { | 715 | { |
713 | struct tcm_vhost_cmd *cmd; | 716 | struct tcm_vhost_cmd *cmd; |
714 | struct tcm_vhost_nexus *tv_nexus; | 717 | struct tcm_vhost_nexus *tv_nexus; |
718 | struct se_session *se_sess; | ||
719 | int tag; | ||
715 | 720 | ||
716 | tv_nexus = tpg->tpg_nexus; | 721 | tv_nexus = tpg->tpg_nexus; |
717 | if (!tv_nexus) { | 722 | if (!tv_nexus) { |
718 | pr_err("Unable to locate active struct tcm_vhost_nexus\n"); | 723 | pr_err("Unable to locate active struct tcm_vhost_nexus\n"); |
719 | return ERR_PTR(-EIO); | 724 | return ERR_PTR(-EIO); |
720 | } | 725 | } |
726 | se_sess = tv_nexus->tvn_se_sess; | ||
721 | 727 | ||
722 | cmd = kzalloc(sizeof(struct tcm_vhost_cmd), GFP_ATOMIC); | 728 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, GFP_KERNEL); |
723 | if (!cmd) { | 729 | cmd = &((struct tcm_vhost_cmd *)se_sess->sess_cmd_map)[tag]; |
724 | pr_err("Unable to allocate struct tcm_vhost_cmd\n"); | 730 | memset(cmd, 0, sizeof(struct tcm_vhost_cmd)); |
725 | return ERR_PTR(-ENOMEM); | 731 | |
726 | } | 732 | cmd->tvc_se_cmd.map_tag = tag; |
727 | cmd->tvc_tag = v_req->tag; | 733 | cmd->tvc_tag = v_req->tag; |
728 | cmd->tvc_task_attr = v_req->task_attr; | 734 | cmd->tvc_task_attr = v_req->task_attr; |
729 | cmd->tvc_exp_data_len = exp_data_len; | 735 | cmd->tvc_exp_data_len = exp_data_len; |
@@ -989,10 +995,10 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) | |||
989 | for (i = 0; i < data_num; i++) | 995 | for (i = 0; i < data_num; i++) |
990 | exp_data_len += vq->iov[data_first + i].iov_len; | 996 | exp_data_len += vq->iov[data_first + i].iov_len; |
991 | 997 | ||
992 | cmd = vhost_scsi_allocate_cmd(vq, tpg, &v_req, | 998 | cmd = vhost_scsi_get_tag(vq, tpg, &v_req, |
993 | exp_data_len, data_direction); | 999 | exp_data_len, data_direction); |
994 | if (IS_ERR(cmd)) { | 1000 | if (IS_ERR(cmd)) { |
995 | vq_err(vq, "vhost_scsi_allocate_cmd failed %ld\n", | 1001 | vq_err(vq, "vhost_scsi_get_tag failed %ld\n", |
996 | PTR_ERR(cmd)); | 1002 | PTR_ERR(cmd)); |
997 | goto err_cmd; | 1003 | goto err_cmd; |
998 | } | 1004 | } |
@@ -1675,9 +1681,12 @@ static int tcm_vhost_make_nexus(struct tcm_vhost_tpg *tpg, | |||
1675 | return -ENOMEM; | 1681 | return -ENOMEM; |
1676 | } | 1682 | } |
1677 | /* | 1683 | /* |
1678 | * Initialize the struct se_session pointer | 1684 | * Initialize the struct se_session pointer and setup tagpool |
1685 | * for struct tcm_vhost_cmd descriptors | ||
1679 | */ | 1686 | */ |
1680 | tv_nexus->tvn_se_sess = transport_init_session(); | 1687 | tv_nexus->tvn_se_sess = transport_init_session_tags( |
1688 | TCM_VHOST_DEFAULT_TAGS, | ||
1689 | sizeof(struct tcm_vhost_cmd)); | ||
1681 | if (IS_ERR(tv_nexus->tvn_se_sess)) { | 1690 | if (IS_ERR(tv_nexus->tvn_se_sess)) { |
1682 | mutex_unlock(&tpg->tv_tpg_mutex); | 1691 | mutex_unlock(&tpg->tv_tpg_mutex); |
1683 | kfree(tv_nexus); | 1692 | kfree(tv_nexus); |