Lines Matching full:vs

175 	struct vhost_scsi *vs;  member
253 static void vhost_scsi_init_inflight(struct vhost_scsi *vs, in vhost_scsi_init_inflight() argument
260 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_init_inflight()
261 vq = &vs->vqs[i].vq; in vhost_scsi_init_inflight()
266 idx = vs->vqs[i].inflight_idx; in vhost_scsi_init_inflight()
268 old_inflight[i] = &vs->vqs[i].inflights[idx]; in vhost_scsi_init_inflight()
271 vs->vqs[i].inflight_idx = idx ^ 1; in vhost_scsi_init_inflight()
272 new_inflight = &vs->vqs[i].inflights[idx ^ 1]; in vhost_scsi_init_inflight()
424 static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_free_evt() argument
426 vs->vs_events_nr--; in vhost_scsi_free_evt()
431 vhost_scsi_allocate_evt(struct vhost_scsi *vs, in vhost_scsi_allocate_evt() argument
434 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_allocate_evt()
437 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { in vhost_scsi_allocate_evt()
438 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
445 vs->vs_events_missed = true; in vhost_scsi_allocate_evt()
451 vs->vs_events_nr++; in vhost_scsi_allocate_evt()
462 vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) in vhost_scsi_do_evt_work() argument
464 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_evt_work()
471 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
476 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_do_evt_work()
481 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
485 if (vhost_enable_notify(&vs->dev, vq)) in vhost_scsi_do_evt_work()
487 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
494 vs->vs_events_missed = true; in vhost_scsi_do_evt_work()
498 if (vs->vs_events_missed) { in vhost_scsi_do_evt_work()
500 vs->vs_events_missed = false; in vhost_scsi_do_evt_work()
506 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_do_evt_work()
511 static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) in vhost_scsi_complete_events() argument
513 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_complete_events()
518 llnode = llist_del_all(&vs->vs_event_list); in vhost_scsi_complete_events()
521 vhost_scsi_do_evt_work(vs, evt); in vhost_scsi_complete_events()
522 vhost_scsi_free_evt(vs, evt); in vhost_scsi_complete_events()
529 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, in vhost_scsi_evt_work() local
531 vhost_scsi_complete_events(vs, false); in vhost_scsi_evt_work()
608 vhost_signal(&svq->vs->dev, &svq->vq); in vhost_scsi_complete_cmd_work()
933 vhost_scsi_send_bad_target(struct vhost_scsi *vs, in vhost_scsi_send_bad_target() argument
946 vhost_add_used_and_signal(&vs->dev, vq, head, 0); in vhost_scsi_send_bad_target()
952 vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_get_desc() argument
970 if (unlikely(vhost_enable_notify(&vs->dev, vq))) { in vhost_scsi_get_desc()
971 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_get_desc()
1058 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_handle_vq() argument
1086 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_handle_vq()
1089 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_handle_vq()
1126 * iovec sizes + incoming iovec sizes vs. virtio-scsi request + in vhost_scsi_handle_vq()
1223 cmd->tvc_vhost = vs; in vhost_scsi_handle_vq()
1261 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_handle_vq()
1268 vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_tmf_resp() argument
1284 vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0); in vhost_scsi_send_tmf_resp()
1320 vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg, in vhost_scsi_handle_tmf() argument
1344 tmf->vhost = vs; in vhost_scsi_handle_tmf()
1362 vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out], in vhost_scsi_handle_tmf()
1367 vhost_scsi_send_an_resp(struct vhost_scsi *vs, in vhost_scsi_send_an_resp() argument
1383 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); in vhost_scsi_send_an_resp()
1389 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) in vhost_scsi_ctl_handle_vq() argument
1411 vhost_disable_notify(&vs->dev, vq); in vhost_scsi_ctl_handle_vq()
1414 ret = vhost_scsi_get_desc(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1478 vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc); in vhost_scsi_ctl_handle_vq()
1480 vhost_scsi_send_an_resp(vs, vq, &vc); in vhost_scsi_ctl_handle_vq()
1491 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); in vhost_scsi_ctl_handle_vq()
1501 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_ctl_handle_kick() local
1504 vhost_scsi_ctl_handle_vq(vs, vq); in vhost_scsi_ctl_handle_kick()
1508 vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq, in vhost_scsi_send_evt() argument
1514 evt = vhost_scsi_allocate_evt(vs, event, reason); in vhost_scsi_send_evt()
1531 llist_add(&evt->list, &vs->vs_event_list); in vhost_scsi_send_evt()
1532 if (!vhost_vq_work_queue(vq, &vs->vs_event_work)) in vhost_scsi_send_evt()
1533 vhost_scsi_complete_events(vs, true); in vhost_scsi_send_evt()
1540 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_evt_handle_kick() local
1546 if (vs->vs_events_missed) in vhost_scsi_evt_handle_kick()
1547 vhost_scsi_send_evt(vs, vq, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, in vhost_scsi_evt_handle_kick()
1557 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev); in vhost_scsi_handle_kick() local
1559 vhost_scsi_handle_vq(vs, vq); in vhost_scsi_handle_kick()
1563 static void vhost_scsi_flush(struct vhost_scsi *vs) in vhost_scsi_flush() argument
1568 vhost_scsi_init_inflight(vs, vs->old_inflight); in vhost_scsi_flush()
1575 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1576 kref_put(&vs->old_inflight[i]->kref, vhost_scsi_done_inflight); in vhost_scsi_flush()
1579 vhost_dev_flush(&vs->dev); in vhost_scsi_flush()
1582 for (i = 0; i < vs->dev.nvqs; i++) in vhost_scsi_flush()
1583 wait_for_completion(&vs->old_inflight[i]->comp); in vhost_scsi_flush()
1677 * vs->dev.mutex -> vhost_scsi_mutex -> tpg->tv_tpg_mutex -> vq->mutex
1680 vhost_scsi_set_endpoint(struct vhost_scsi *vs, in vhost_scsi_set_endpoint() argument
1691 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1694 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_set_endpoint()
1696 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_set_endpoint()
1708 if (vs->vs_tpg) in vhost_scsi_set_endpoint()
1709 memcpy(vs_tpg, vs->vs_tpg, len); in vhost_scsi_set_endpoint()
1725 if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { in vhost_scsi_set_endpoint()
1746 tpg->vhost_scsi = vs; in vhost_scsi_set_endpoint()
1755 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn, in vhost_scsi_set_endpoint()
1756 sizeof(vs->vs_vhost_wwpn)); in vhost_scsi_set_endpoint()
1758 for (i = VHOST_SCSI_VQ_IO; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1759 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1768 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_endpoint()
1769 vq = &vs->vqs[i].vq; in vhost_scsi_set_endpoint()
1782 * old vs->vs_tpg is finished. in vhost_scsi_set_endpoint()
1784 vhost_scsi_flush(vs); in vhost_scsi_set_endpoint()
1785 kfree(vs->vs_tpg); in vhost_scsi_set_endpoint()
1786 vs->vs_tpg = vs_tpg; in vhost_scsi_set_endpoint()
1791 if (!vhost_vq_get_backend(&vs->vqs[i].vq)) in vhost_scsi_set_endpoint()
1792 vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq); in vhost_scsi_set_endpoint()
1807 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_endpoint()
1812 vhost_scsi_clear_endpoint(struct vhost_scsi *vs, in vhost_scsi_clear_endpoint() argument
1823 mutex_lock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1825 for (index = 0; index < vs->dev.nvqs; ++index) { in vhost_scsi_clear_endpoint()
1826 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) { in vhost_scsi_clear_endpoint()
1832 if (!vs->vs_tpg) { in vhost_scsi_clear_endpoint()
1839 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1863 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1864 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1870 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1872 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_clear_endpoint()
1873 vq = &vs->vqs[i].vq; in vhost_scsi_clear_endpoint()
1883 tpg = vs->vs_tpg[target]; in vhost_scsi_clear_endpoint()
1891 vs->vs_tpg[target] = NULL; in vhost_scsi_clear_endpoint()
1902 * old vs->vs_tpg is finished. in vhost_scsi_clear_endpoint()
1904 vhost_scsi_flush(vs); in vhost_scsi_clear_endpoint()
1905 kfree(vs->vs_tpg); in vhost_scsi_clear_endpoint()
1906 vs->vs_tpg = NULL; in vhost_scsi_clear_endpoint()
1907 WARN_ON(vs->vs_events_nr); in vhost_scsi_clear_endpoint()
1908 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1912 mutex_unlock(&vs->dev.mutex); in vhost_scsi_clear_endpoint()
1916 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) in vhost_scsi_set_features() argument
1924 mutex_lock(&vs->dev.mutex); in vhost_scsi_set_features()
1926 !vhost_log_access_ok(&vs->dev)) { in vhost_scsi_set_features()
1927 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1931 for (i = 0; i < vs->dev.nvqs; i++) { in vhost_scsi_set_features()
1932 vq = &vs->vqs[i].vq; in vhost_scsi_set_features()
1937 mutex_unlock(&vs->dev.mutex); in vhost_scsi_set_features()
1944 struct vhost_scsi *vs; in vhost_scsi_open() local
1948 vs = kvzalloc(sizeof(*vs), GFP_KERNEL); in vhost_scsi_open()
1949 if (!vs) in vhost_scsi_open()
1962 vs->old_inflight = kmalloc_array(nvqs, sizeof(*vs->old_inflight), in vhost_scsi_open()
1964 if (!vs->old_inflight) in vhost_scsi_open()
1967 vs->vqs = kmalloc_array(nvqs, sizeof(*vs->vqs), in vhost_scsi_open()
1969 if (!vs->vqs) in vhost_scsi_open()
1976 vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); in vhost_scsi_open()
1978 vs->vs_events_nr = 0; in vhost_scsi_open()
1979 vs->vs_events_missed = false; in vhost_scsi_open()
1981 vqs[VHOST_SCSI_VQ_CTL] = &vs->vqs[VHOST_SCSI_VQ_CTL].vq; in vhost_scsi_open()
1982 vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_open()
1983 vs->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick; in vhost_scsi_open()
1984 vs->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick; in vhost_scsi_open()
1986 svq = &vs->vqs[i]; in vhost_scsi_open()
1989 svq->vs = vs; in vhost_scsi_open()
1995 vhost_dev_init(&vs->dev, vqs, nvqs, UIO_MAXIOV, in vhost_scsi_open()
1998 vhost_scsi_init_inflight(vs, NULL); in vhost_scsi_open()
2000 f->private_data = vs; in vhost_scsi_open()
2004 kfree(vs->vqs); in vhost_scsi_open()
2006 kfree(vs->old_inflight); in vhost_scsi_open()
2008 kvfree(vs); in vhost_scsi_open()
2015 struct vhost_scsi *vs = f->private_data; in vhost_scsi_release() local
2018 mutex_lock(&vs->dev.mutex); in vhost_scsi_release()
2019 memcpy(t.vhost_wwpn, vs->vs_vhost_wwpn, sizeof(t.vhost_wwpn)); in vhost_scsi_release()
2020 mutex_unlock(&vs->dev.mutex); in vhost_scsi_release()
2021 vhost_scsi_clear_endpoint(vs, &t); in vhost_scsi_release()
2022 vhost_dev_stop(&vs->dev); in vhost_scsi_release()
2023 vhost_dev_cleanup(&vs->dev); in vhost_scsi_release()
2024 kfree(vs->dev.vqs); in vhost_scsi_release()
2025 kfree(vs->vqs); in vhost_scsi_release()
2026 kfree(vs->old_inflight); in vhost_scsi_release()
2027 kvfree(vs); in vhost_scsi_release()
2036 struct vhost_scsi *vs = f->private_data; in vhost_scsi_ioctl() local
2044 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_ioctl()
2053 return vhost_scsi_set_endpoint(vs, &backend); in vhost_scsi_ioctl()
2060 return vhost_scsi_clear_endpoint(vs, &backend); in vhost_scsi_ioctl()
2069 vs->vs_events_missed = events_missed; in vhost_scsi_ioctl()
2074 events_missed = vs->vs_events_missed; in vhost_scsi_ioctl()
2087 return vhost_scsi_set_features(vs, features); in vhost_scsi_ioctl()
2092 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
2093 r = vhost_worker_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2094 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
2097 mutex_lock(&vs->dev.mutex); in vhost_scsi_ioctl()
2098 r = vhost_dev_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2101 r = vhost_vring_ioctl(&vs->dev, ioctl, argp); in vhost_scsi_ioctl()
2102 mutex_unlock(&vs->dev.mutex); in vhost_scsi_ioctl()
2153 struct vhost_scsi *vs = tpg->vhost_scsi; in vhost_scsi_do_plug() local
2157 if (!vs) in vhost_scsi_do_plug()
2165 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; in vhost_scsi_do_plug()
2175 vhost_scsi_send_evt(vs, vq, tpg, lun, in vhost_scsi_do_plug()