scsi.c (2b703bbda2713fd2a7d98029ea6c44f9c3159f34) scsi.c (247643f85782fc1119ccbd712a5075535ebf9d43)
1/*******************************************************************************
2 * Vhost kernel TCM fabric driver for virtio SCSI initiators
3 *
4 * (C) Copyright 2010-2013 Datera, Inc.
5 * (C) Copyright 2010-2012 IBM Corp.
6 *
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 *

--- 438 unchanged lines hidden (view full) ---

447vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)
448{
449 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
450 struct virtio_scsi_event *event = &evt->event;
451 struct virtio_scsi_event __user *eventp;
452 unsigned out, in;
453 int head, ret;
454
1/*******************************************************************************
2 * Vhost kernel TCM fabric driver for virtio SCSI initiators
3 *
4 * (C) Copyright 2010-2013 Datera, Inc.
5 * (C) Copyright 2010-2012 IBM Corp.
6 *
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 *

--- 438 unchanged lines hidden (view full) ---

447vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)
448{
449 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
450 struct virtio_scsi_event *event = &evt->event;
451 struct virtio_scsi_event __user *eventp;
452 unsigned out, in;
453 int head, ret;
454
455 if (!vq->private_data) {
455 if (!vhost_vq_get_backend(vq)) {
456 vs->vs_events_missed = true;
457 return;
458 }
459
460again:
461 vhost_disable_notify(&vs->dev, vq);
462 head = vhost_get_vq_desc(vq, vq->iov,
463 ARRAY_SIZE(vq->iov), &out, &in,

--- 423 unchanged lines hidden (view full) ---

887 &vc->out_iter))) {
888 vq_err(vq, "Faulted on copy_from_iter_full\n");
889 } else if (unlikely(*vc->lunp != 1)) {
890 /* virtio-scsi spec requires byte 0 of the lun to be 1 */
891 vq_err(vq, "Illegal virtio-scsi lun: %u\n", *vc->lunp);
892 } else {
893 struct vhost_scsi_tpg **vs_tpg, *tpg;
894
456 vs->vs_events_missed = true;
457 return;
458 }
459
460again:
461 vhost_disable_notify(&vs->dev, vq);
462 head = vhost_get_vq_desc(vq, vq->iov,
463 ARRAY_SIZE(vq->iov), &out, &in,

--- 423 unchanged lines hidden (view full) ---

887 &vc->out_iter))) {
888 vq_err(vq, "Faulted on copy_from_iter_full\n");
889 } else if (unlikely(*vc->lunp != 1)) {
890 /* virtio-scsi spec requires byte 0 of the lun to be 1 */
891 vq_err(vq, "Illegal virtio-scsi lun: %u\n", *vc->lunp);
892 } else {
893 struct vhost_scsi_tpg **vs_tpg, *tpg;
894
895 vs_tpg = vq->private_data; /* validated at handler entry */
895 vs_tpg = vhost_vq_get_backend(vq); /* validated at handler entry */
896
897 tpg = READ_ONCE(vs_tpg[*vc->target]);
898 if (unlikely(!tpg)) {
899 vq_err(vq, "Target 0x%x does not exist\n", *vc->target);
900 } else {
901 if (tpgp)
902 *tpgp = tpg;
903 ret = 0;

--- 20 unchanged lines hidden (view full) ---

924 bool t10_pi = vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI);
925 void *cdb;
926
927 mutex_lock(&vq->mutex);
928 /*
929 * We can handle the vq only after the endpoint is setup by calling the
930 * VHOST_SCSI_SET_ENDPOINT ioctl.
931 */
896
897 tpg = READ_ONCE(vs_tpg[*vc->target]);
898 if (unlikely(!tpg)) {
899 vq_err(vq, "Target 0x%x does not exist\n", *vc->target);
900 } else {
901 if (tpgp)
902 *tpgp = tpg;
903 ret = 0;

--- 20 unchanged lines hidden (view full) ---

924 bool t10_pi = vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI);
925 void *cdb;
926
927 mutex_lock(&vq->mutex);
928 /*
929 * We can handle the vq only after the endpoint is setup by calling the
930 * VHOST_SCSI_SET_ENDPOINT ioctl.
931 */
932 vs_tpg = vq->private_data;
932 vs_tpg = vhost_vq_get_backend(vq);
933 if (!vs_tpg)
934 goto out;
935
936 memset(&vc, 0, sizeof(vc));
937 vc.rsp_size = sizeof(struct virtio_scsi_cmd_resp);
938
939 vhost_disable_notify(&vs->dev, vq);
940

--- 238 unchanged lines hidden (view full) ---

1179 size_t typ_size;
1180 int ret, c = 0;
1181
1182 mutex_lock(&vq->mutex);
1183 /*
1184 * We can handle the vq only after the endpoint is setup by calling the
1185 * VHOST_SCSI_SET_ENDPOINT ioctl.
1186 */
933 if (!vs_tpg)
934 goto out;
935
936 memset(&vc, 0, sizeof(vc));
937 vc.rsp_size = sizeof(struct virtio_scsi_cmd_resp);
938
939 vhost_disable_notify(&vs->dev, vq);
940

--- 238 unchanged lines hidden (view full) ---

1179 size_t typ_size;
1180 int ret, c = 0;
1181
1182 mutex_lock(&vq->mutex);
1183 /*
1184 * We can handle the vq only after the endpoint is setup by calling the
1185 * VHOST_SCSI_SET_ENDPOINT ioctl.
1186 */
1187 if (!vq->private_data)
1187 if (!vhost_vq_get_backend(vq))
1188 goto out;
1189
1190 memset(&vc, 0, sizeof(vc));
1191
1192 vhost_disable_notify(&vs->dev, vq);
1193
1194 do {
1195 ret = vhost_scsi_get_desc(vs, vq, &vc);

--- 121 unchanged lines hidden (view full) ---

1317
1318static void vhost_scsi_evt_handle_kick(struct vhost_work *work)
1319{
1320 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
1321 poll.work);
1322 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev);
1323
1324 mutex_lock(&vq->mutex);
1188 goto out;
1189
1190 memset(&vc, 0, sizeof(vc));
1191
1192 vhost_disable_notify(&vs->dev, vq);
1193
1194 do {
1195 ret = vhost_scsi_get_desc(vs, vq, &vc);

--- 121 unchanged lines hidden (view full) ---

1317
1318static void vhost_scsi_evt_handle_kick(struct vhost_work *work)
1319{
1320 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
1321 poll.work);
1322 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev);
1323
1324 mutex_lock(&vq->mutex);
1325 if (!vq->private_data)
1325 if (!vhost_vq_get_backend(vq))
1326 goto out;
1327
1328 if (vs->vs_events_missed)
1329 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
1330out:
1331 mutex_unlock(&vq->mutex);
1332}
1333

--- 121 unchanged lines hidden (view full) ---

1455 }
1456
1457 if (match) {
1458 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn,
1459 sizeof(vs->vs_vhost_wwpn));
1460 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1461 vq = &vs->vqs[i].vq;
1462 mutex_lock(&vq->mutex);
1326 goto out;
1327
1328 if (vs->vs_events_missed)
1329 vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
1330out:
1331 mutex_unlock(&vq->mutex);
1332}
1333

--- 121 unchanged lines hidden (view full) ---

1455 }
1456
1457 if (match) {
1458 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn,
1459 sizeof(vs->vs_vhost_wwpn));
1460 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1461 vq = &vs->vqs[i].vq;
1462 mutex_lock(&vq->mutex);
1463 vq->private_data = vs_tpg;
1463 vhost_vq_set_backend(vq, vs_tpg);
1464 vhost_vq_init_access(vq);
1465 mutex_unlock(&vq->mutex);
1466 }
1467 ret = 0;
1468 } else {
1469 ret = -EEXIST;
1470 }
1471

--- 70 unchanged lines hidden (view full) ---

1542 */
1543 se_tpg = &tpg->se_tpg;
1544 target_undepend_item(&se_tpg->tpg_group.cg_item);
1545 }
1546 if (match) {
1547 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1548 vq = &vs->vqs[i].vq;
1549 mutex_lock(&vq->mutex);
1464 vhost_vq_init_access(vq);
1465 mutex_unlock(&vq->mutex);
1466 }
1467 ret = 0;
1468 } else {
1469 ret = -EEXIST;
1470 }
1471

--- 70 unchanged lines hidden (view full) ---

1542 */
1543 se_tpg = &tpg->se_tpg;
1544 target_undepend_item(&se_tpg->tpg_group.cg_item);
1545 }
1546 if (match) {
1547 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1548 vq = &vs->vqs[i].vq;
1549 mutex_lock(&vq->mutex);
1550 vq->private_data = NULL;
1550 vhost_vq_set_backend(vq, NULL);
1551 mutex_unlock(&vq->mutex);
1552 }
1553 }
1554 /*
1555 * Act as synchronize_rcu to make sure access to
1556 * old vs->vs_tpg is finished.
1557 */
1558 vhost_scsi_flush(vs);

--- 804 unchanged lines hidden ---
1551 mutex_unlock(&vq->mutex);
1552 }
1553 }
1554 /*
1555 * Act as synchronize_rcu to make sure access to
1556 * old vs->vs_tpg is finished.
1557 */
1558 vhost_scsi_flush(vs);

--- 804 unchanged lines hidden ---