1 /*******************************************************************************
2 * Vhost kernel TCM fabric driver for virtio SCSI initiators
4 * (C) Copyright 2010-2012 RisingTide Systems LLC.
5 * (C) Copyright 2010-2012 IBM Corp.
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 * Authors: Nicholas A. Bellinger <nab@risingtidesystems.com>
10 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/kthread.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
33 #include <linux/configfs.h>
34 #include <linux/ctype.h>
35 #include <linux/compat.h>
36 #include <linux/eventfd.h>
38 #include <linux/miscdevice.h>
39 #include <asm/unaligned.h>
40 #include <scsi/scsi.h>
41 #include <scsi/scsi_tcq.h>
42 #include <target/target_core_base.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_fabric_configfs.h>
45 #include <target/target_core_configfs.h>
46 #include <target/configfs_macros.h>
47 #include <linux/vhost.h>
48 #include <linux/virtio_scsi.h>
49 #include <linux/llist.h>
50 #include <linux/bitmap.h>
55 #define TCM_VHOST_VERSION "v0.1"
56 #define TCM_VHOST_NAMELEN 256
57 #define TCM_VHOST_MAX_CDB_SIZE 32
59 struct vhost_scsi_inflight {
60 /* Wait for the flush operation to finish */
61 struct completion comp;
62 /* Refcount for the inflight reqs */
66 struct tcm_vhost_cmd {
67 /* Descriptor from vhost_get_vq_desc() for virt_queue segment */
69 /* virtio-scsi initiator task attribute */
71 /* virtio-scsi initiator data direction */
72 enum dma_data_direction tvc_data_direction;
73 /* Expected data transfer length from virtio-scsi header */
75 /* The Tag from include/linux/virtio_scsi.h:struct virtio_scsi_cmd_req */
77 /* The number of scatterlists associated with this cmd */
79 /* Saved unpacked SCSI LUN for tcm_vhost_submission_work() */
81 /* Pointer to the SGL formatted memory from virtio-scsi */
82 struct scatterlist *tvc_sgl;
83 /* Pointer to response */
84 struct virtio_scsi_cmd_resp __user *tvc_resp;
85 /* Pointer to vhost_scsi for our device */
86 struct vhost_scsi *tvc_vhost;
87 /* Pointer to vhost_virtqueue for the cmd */
88 struct vhost_virtqueue *tvc_vq;
89 /* Pointer to vhost nexus memory */
90 struct tcm_vhost_nexus *tvc_nexus;
91 /* The TCM I/O descriptor that is accessed via container_of() */
92 struct se_cmd tvc_se_cmd;
93 /* work item used for cmwq dispatch to tcm_vhost_submission_work() */
94 struct work_struct work;
95 /* Copy of the incoming SCSI command descriptor block (CDB) */
96 unsigned char tvc_cdb[TCM_VHOST_MAX_CDB_SIZE];
97 /* Sense buffer that will be mapped into outgoing status */
98 unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER];
99 /* Completed commands list, serviced from vhost worker thread */
100 struct llist_node tvc_completion_list;
101 /* Used to track inflight cmd */
102 struct vhost_scsi_inflight *inflight;
105 struct tcm_vhost_nexus {
106 /* Pointer to TCM session for I_T Nexus */
107 struct se_session *tvn_se_sess;
110 struct tcm_vhost_nacl {
111 /* Binary World Wide unique Port Name for Vhost Initiator port */
113 /* ASCII formatted WWPN for Sas Initiator port */
114 char iport_name[TCM_VHOST_NAMELEN];
115 /* Returned by tcm_vhost_make_nodeacl() */
116 struct se_node_acl se_node_acl;
120 struct tcm_vhost_tpg {
121 /* Vhost port target portal group tag for TCM */
123 /* Used to track number of TPG Port/Lun Links wrt to explict I_T Nexus shutdown */
124 int tv_tpg_port_count;
125 /* Used for vhost_scsi device reference to tpg_nexus, protected by tv_tpg_mutex */
126 int tv_tpg_vhost_count;
127 /* list for tcm_vhost_list */
128 struct list_head tv_tpg_list;
129 /* Used to protect access for tpg_nexus */
130 struct mutex tv_tpg_mutex;
131 /* Pointer to the TCM VHost I_T Nexus for this TPG endpoint */
132 struct tcm_vhost_nexus *tpg_nexus;
133 /* Pointer back to tcm_vhost_tport */
134 struct tcm_vhost_tport *tport;
135 /* Returned by tcm_vhost_make_tpg() */
136 struct se_portal_group se_tpg;
137 /* Pointer back to vhost_scsi, protected by tv_tpg_mutex */
138 struct vhost_scsi *vhost_scsi;
141 struct tcm_vhost_tport {
142 /* SCSI protocol the tport is providing */
144 /* Binary World Wide unique Port Name for Vhost Target port */
146 /* ASCII formatted WWPN for Vhost Target port */
147 char tport_name[TCM_VHOST_NAMELEN];
148 /* Returned by tcm_vhost_make_tport() */
149 struct se_wwn tport_wwn;
152 struct tcm_vhost_evt {
153 /* event to be sent to guest */
154 struct virtio_scsi_event event;
155 /* event list, serviced from vhost worker thread */
156 struct llist_node list;
160 VHOST_SCSI_VQ_CTL = 0,
161 VHOST_SCSI_VQ_EVT = 1,
162 VHOST_SCSI_VQ_IO = 2,
166 VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG)
169 #define VHOST_SCSI_MAX_TARGET 256
170 #define VHOST_SCSI_MAX_VQ 128
171 #define VHOST_SCSI_MAX_EVENT 128
173 struct vhost_scsi_virtqueue {
174 struct vhost_virtqueue vq;
176 * Reference counting for inflight reqs, used for flush operation. At
177 * each time, one reference tracks new commands submitted, while we
178 * wait for another one to reach 0.
180 struct vhost_scsi_inflight inflights[2];
182 * Indicate current inflight in use, protected by vq->mutex.
183 * Writers must also take dev mutex and flush under it.
189 /* Protected by vhost_scsi->dev.mutex */
190 struct tcm_vhost_tpg **vs_tpg;
191 char vs_vhost_wwpn[TRANSPORT_IQN_LEN];
193 struct vhost_dev dev;
194 struct vhost_scsi_virtqueue vqs[VHOST_SCSI_MAX_VQ];
196 struct vhost_work vs_completion_work; /* cmd completion work item */
197 struct llist_head vs_completion_list; /* cmd completion queue */
199 struct vhost_work vs_event_work; /* evt injection work item */
200 struct llist_head vs_event_list; /* evt injection queue */
202 bool vs_events_missed; /* any missed events, protected by vq->mutex */
203 int vs_events_nr; /* num of pending events, protected by vq->mutex */
206 /* Local pointer to allocated TCM configfs fabric module */
207 static struct target_fabric_configfs *tcm_vhost_fabric_configfs;
209 static struct workqueue_struct *tcm_vhost_workqueue;
211 /* Global spinlock to protect tcm_vhost TPG list for vhost IOCTL access */
212 static DEFINE_MUTEX(tcm_vhost_mutex);
213 static LIST_HEAD(tcm_vhost_list);
215 static int iov_num_pages(struct iovec *iov)
217 return (PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) -
218 ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT;
221 void tcm_vhost_done_inflight(struct kref *kref)
223 struct vhost_scsi_inflight *inflight;
225 inflight = container_of(kref, struct vhost_scsi_inflight, kref);
226 complete(&inflight->comp);
229 static void tcm_vhost_init_inflight(struct vhost_scsi *vs,
230 struct vhost_scsi_inflight *old_inflight[])
232 struct vhost_scsi_inflight *new_inflight;
233 struct vhost_virtqueue *vq;
236 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
239 mutex_lock(&vq->mutex);
241 /* store old infight */
242 idx = vs->vqs[i].inflight_idx;
244 old_inflight[i] = &vs->vqs[i].inflights[idx];
246 /* setup new infight */
247 vs->vqs[i].inflight_idx = idx ^ 1;
248 new_inflight = &vs->vqs[i].inflights[idx ^ 1];
249 kref_init(&new_inflight->kref);
250 init_completion(&new_inflight->comp);
252 mutex_unlock(&vq->mutex);
256 static struct vhost_scsi_inflight *
257 tcm_vhost_get_inflight(struct vhost_virtqueue *vq)
259 struct vhost_scsi_inflight *inflight;
260 struct vhost_scsi_virtqueue *svq;
262 svq = container_of(vq, struct vhost_scsi_virtqueue, vq);
263 inflight = &svq->inflights[svq->inflight_idx];
264 kref_get(&inflight->kref);
269 static void tcm_vhost_put_inflight(struct vhost_scsi_inflight *inflight)
271 kref_put(&inflight->kref, tcm_vhost_done_inflight);
274 static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
279 static int tcm_vhost_check_false(struct se_portal_group *se_tpg)
284 static char *tcm_vhost_get_fabric_name(void)
289 static u8 tcm_vhost_get_fabric_proto_ident(struct se_portal_group *se_tpg)
291 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
292 struct tcm_vhost_tpg, se_tpg);
293 struct tcm_vhost_tport *tport = tpg->tport;
295 switch (tport->tport_proto_id) {
296 case SCSI_PROTOCOL_SAS:
297 return sas_get_fabric_proto_ident(se_tpg);
298 case SCSI_PROTOCOL_FCP:
299 return fc_get_fabric_proto_ident(se_tpg);
300 case SCSI_PROTOCOL_ISCSI:
301 return iscsi_get_fabric_proto_ident(se_tpg);
303 pr_err("Unknown tport_proto_id: 0x%02x, using"
304 " SAS emulation\n", tport->tport_proto_id);
308 return sas_get_fabric_proto_ident(se_tpg);
311 static char *tcm_vhost_get_fabric_wwn(struct se_portal_group *se_tpg)
313 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
314 struct tcm_vhost_tpg, se_tpg);
315 struct tcm_vhost_tport *tport = tpg->tport;
317 return &tport->tport_name[0];
320 static u16 tcm_vhost_get_tag(struct se_portal_group *se_tpg)
322 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
323 struct tcm_vhost_tpg, se_tpg);
324 return tpg->tport_tpgt;
327 static u32 tcm_vhost_get_default_depth(struct se_portal_group *se_tpg)
332 static u32 tcm_vhost_get_pr_transport_id(struct se_portal_group *se_tpg,
333 struct se_node_acl *se_nacl,
334 struct t10_pr_registration *pr_reg,
338 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
339 struct tcm_vhost_tpg, se_tpg);
340 struct tcm_vhost_tport *tport = tpg->tport;
342 switch (tport->tport_proto_id) {
343 case SCSI_PROTOCOL_SAS:
344 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
346 case SCSI_PROTOCOL_FCP:
347 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
349 case SCSI_PROTOCOL_ISCSI:
350 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
353 pr_err("Unknown tport_proto_id: 0x%02x, using"
354 " SAS emulation\n", tport->tport_proto_id);
358 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
362 static u32 tcm_vhost_get_pr_transport_id_len(struct se_portal_group *se_tpg,
363 struct se_node_acl *se_nacl,
364 struct t10_pr_registration *pr_reg,
367 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
368 struct tcm_vhost_tpg, se_tpg);
369 struct tcm_vhost_tport *tport = tpg->tport;
371 switch (tport->tport_proto_id) {
372 case SCSI_PROTOCOL_SAS:
373 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
375 case SCSI_PROTOCOL_FCP:
376 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
378 case SCSI_PROTOCOL_ISCSI:
379 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
382 pr_err("Unknown tport_proto_id: 0x%02x, using"
383 " SAS emulation\n", tport->tport_proto_id);
387 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
391 static char *tcm_vhost_parse_pr_out_transport_id(struct se_portal_group *se_tpg,
394 char **port_nexus_ptr)
396 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
397 struct tcm_vhost_tpg, se_tpg);
398 struct tcm_vhost_tport *tport = tpg->tport;
400 switch (tport->tport_proto_id) {
401 case SCSI_PROTOCOL_SAS:
402 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
404 case SCSI_PROTOCOL_FCP:
405 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
407 case SCSI_PROTOCOL_ISCSI:
408 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
411 pr_err("Unknown tport_proto_id: 0x%02x, using"
412 " SAS emulation\n", tport->tport_proto_id);
416 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
420 static struct se_node_acl *tcm_vhost_alloc_fabric_acl(
421 struct se_portal_group *se_tpg)
423 struct tcm_vhost_nacl *nacl;
425 nacl = kzalloc(sizeof(struct tcm_vhost_nacl), GFP_KERNEL);
427 pr_err("Unable to allocate struct tcm_vhost_nacl\n");
431 return &nacl->se_node_acl;
434 static void tcm_vhost_release_fabric_acl(struct se_portal_group *se_tpg,
435 struct se_node_acl *se_nacl)
437 struct tcm_vhost_nacl *nacl = container_of(se_nacl,
438 struct tcm_vhost_nacl, se_node_acl);
442 static u32 tcm_vhost_tpg_get_inst_index(struct se_portal_group *se_tpg)
447 static void tcm_vhost_release_cmd(struct se_cmd *se_cmd)
452 static int tcm_vhost_shutdown_session(struct se_session *se_sess)
457 static void tcm_vhost_close_session(struct se_session *se_sess)
462 static u32 tcm_vhost_sess_get_index(struct se_session *se_sess)
467 static int tcm_vhost_write_pending(struct se_cmd *se_cmd)
469 /* Go ahead and process the write immediately */
470 target_execute_cmd(se_cmd);
474 static int tcm_vhost_write_pending_status(struct se_cmd *se_cmd)
479 static void tcm_vhost_set_default_node_attrs(struct se_node_acl *nacl)
484 static u32 tcm_vhost_get_task_tag(struct se_cmd *se_cmd)
489 static int tcm_vhost_get_cmd_state(struct se_cmd *se_cmd)
494 static void vhost_scsi_complete_cmd(struct tcm_vhost_cmd *tv_cmd)
496 struct vhost_scsi *vs = tv_cmd->tvc_vhost;
498 llist_add(&tv_cmd->tvc_completion_list, &vs->vs_completion_list);
500 vhost_work_queue(&vs->dev, &vs->vs_completion_work);
503 static int tcm_vhost_queue_data_in(struct se_cmd *se_cmd)
505 struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd,
506 struct tcm_vhost_cmd, tvc_se_cmd);
507 vhost_scsi_complete_cmd(tv_cmd);
511 static int tcm_vhost_queue_status(struct se_cmd *se_cmd)
513 struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd,
514 struct tcm_vhost_cmd, tvc_se_cmd);
515 vhost_scsi_complete_cmd(tv_cmd);
519 static int tcm_vhost_queue_tm_rsp(struct se_cmd *se_cmd)
524 static void tcm_vhost_free_evt(struct vhost_scsi *vs, struct tcm_vhost_evt *evt)
530 static struct tcm_vhost_evt *tcm_vhost_allocate_evt(struct vhost_scsi *vs,
531 u32 event, u32 reason)
533 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
534 struct tcm_vhost_evt *evt;
536 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) {
537 vs->vs_events_missed = true;
541 evt = kzalloc(sizeof(*evt), GFP_KERNEL);
543 vq_err(vq, "Failed to allocate tcm_vhost_evt\n");
544 vs->vs_events_missed = true;
548 evt->event.event = event;
549 evt->event.reason = reason;
555 static void vhost_scsi_free_cmd(struct tcm_vhost_cmd *tv_cmd)
557 struct se_cmd *se_cmd = &tv_cmd->tvc_se_cmd;
559 /* TODO locking against target/backend threads? */
560 transport_generic_free_cmd(se_cmd, 1);
562 if (tv_cmd->tvc_sgl_count) {
564 for (i = 0; i < tv_cmd->tvc_sgl_count; i++)
565 put_page(sg_page(&tv_cmd->tvc_sgl[i]));
567 kfree(tv_cmd->tvc_sgl);
570 tcm_vhost_put_inflight(tv_cmd->inflight);
575 static void tcm_vhost_do_evt_work(struct vhost_scsi *vs,
576 struct tcm_vhost_evt *evt)
578 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
579 struct virtio_scsi_event *event = &evt->event;
580 struct virtio_scsi_event __user *eventp;
584 if (!vq->private_data) {
585 vs->vs_events_missed = true;
590 vhost_disable_notify(&vs->dev, vq);
591 head = vhost_get_vq_desc(&vs->dev, vq, vq->iov,
592 ARRAY_SIZE(vq->iov), &out, &in,
595 vs->vs_events_missed = true;
598 if (head == vq->num) {
599 if (vhost_enable_notify(&vs->dev, vq))
601 vs->vs_events_missed = true;
605 if ((vq->iov[out].iov_len != sizeof(struct virtio_scsi_event))) {
606 vq_err(vq, "Expecting virtio_scsi_event, got %zu bytes\n",
607 vq->iov[out].iov_len);
608 vs->vs_events_missed = true;
612 if (vs->vs_events_missed) {
613 event->event |= VIRTIO_SCSI_T_EVENTS_MISSED;
614 vs->vs_events_missed = false;
617 eventp = vq->iov[out].iov_base;
618 ret = __copy_to_user(eventp, event, sizeof(*event));
620 vhost_add_used_and_signal(&vs->dev, vq, head, 0);
622 vq_err(vq, "Faulted on tcm_vhost_send_event\n");
625 static void tcm_vhost_evt_work(struct vhost_work *work)
627 struct vhost_scsi *vs = container_of(work, struct vhost_scsi,
629 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
630 struct tcm_vhost_evt *evt;
631 struct llist_node *llnode;
633 mutex_lock(&vq->mutex);
634 llnode = llist_del_all(&vs->vs_event_list);
636 evt = llist_entry(llnode, struct tcm_vhost_evt, list);
637 llnode = llist_next(llnode);
638 tcm_vhost_do_evt_work(vs, evt);
639 tcm_vhost_free_evt(vs, evt);
641 mutex_unlock(&vq->mutex);
644 /* Fill in status and signal that we are done processing this command
646 * This is scheduled in the vhost work queue so we are called with the owner
647 * process mm and can access the vring.
649 static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
651 struct vhost_scsi *vs = container_of(work, struct vhost_scsi,
653 DECLARE_BITMAP(signal, VHOST_SCSI_MAX_VQ);
654 struct virtio_scsi_cmd_resp v_rsp;
655 struct tcm_vhost_cmd *tv_cmd;
656 struct llist_node *llnode;
657 struct se_cmd *se_cmd;
660 bitmap_zero(signal, VHOST_SCSI_MAX_VQ);
661 llnode = llist_del_all(&vs->vs_completion_list);
663 tv_cmd = llist_entry(llnode, struct tcm_vhost_cmd,
664 tvc_completion_list);
665 llnode = llist_next(llnode);
666 se_cmd = &tv_cmd->tvc_se_cmd;
668 pr_debug("%s tv_cmd %p resid %u status %#02x\n", __func__,
669 tv_cmd, se_cmd->residual_count, se_cmd->scsi_status);
671 memset(&v_rsp, 0, sizeof(v_rsp));
672 v_rsp.resid = se_cmd->residual_count;
673 /* TODO is status_qualifier field needed? */
674 v_rsp.status = se_cmd->scsi_status;
675 v_rsp.sense_len = se_cmd->scsi_sense_length;
676 memcpy(v_rsp.sense, tv_cmd->tvc_sense_buf,
678 ret = copy_to_user(tv_cmd->tvc_resp, &v_rsp, sizeof(v_rsp));
679 if (likely(ret == 0)) {
680 struct vhost_scsi_virtqueue *q;
681 vhost_add_used(tv_cmd->tvc_vq, tv_cmd->tvc_vq_desc, 0);
682 q = container_of(tv_cmd->tvc_vq, struct vhost_scsi_virtqueue, vq);
684 __set_bit(vq, signal);
686 pr_err("Faulted on virtio_scsi_cmd_resp\n");
688 vhost_scsi_free_cmd(tv_cmd);
692 while ((vq = find_next_bit(signal, VHOST_SCSI_MAX_VQ, vq + 1))
694 vhost_signal(&vs->dev, &vs->vqs[vq].vq);
697 static struct tcm_vhost_cmd *vhost_scsi_allocate_cmd(
698 struct vhost_virtqueue *vq,
699 struct tcm_vhost_tpg *tv_tpg,
700 struct virtio_scsi_cmd_req *v_req,
704 struct tcm_vhost_cmd *tv_cmd;
705 struct tcm_vhost_nexus *tv_nexus;
707 tv_nexus = tv_tpg->tpg_nexus;
709 pr_err("Unable to locate active struct tcm_vhost_nexus\n");
710 return ERR_PTR(-EIO);
713 tv_cmd = kzalloc(sizeof(struct tcm_vhost_cmd), GFP_ATOMIC);
715 pr_err("Unable to allocate struct tcm_vhost_cmd\n");
716 return ERR_PTR(-ENOMEM);
718 tv_cmd->tvc_tag = v_req->tag;
719 tv_cmd->tvc_task_attr = v_req->task_attr;
720 tv_cmd->tvc_exp_data_len = exp_data_len;
721 tv_cmd->tvc_data_direction = data_direction;
722 tv_cmd->tvc_nexus = tv_nexus;
723 tv_cmd->inflight = tcm_vhost_get_inflight(vq);
729 * Map a user memory range into a scatterlist
731 * Returns the number of scatterlist entries used or -errno on error.
733 static int vhost_scsi_map_to_sgl(struct scatterlist *sgl,
734 unsigned int sgl_count, struct iovec *iov, int write)
736 unsigned int npages = 0, pages_nr, offset, nbytes;
737 struct scatterlist *sg = sgl;
738 void __user *ptr = iov->iov_base;
739 size_t len = iov->iov_len;
743 pages_nr = iov_num_pages(iov);
744 if (pages_nr > sgl_count)
747 pages = kmalloc(pages_nr * sizeof(struct page *), GFP_KERNEL);
751 ret = get_user_pages_fast((unsigned long)ptr, pages_nr, write, pages);
752 /* No pages were pinned */
755 /* Less pages pinned than wanted */
756 if (ret != pages_nr) {
757 for (i = 0; i < ret; i++)
764 offset = (uintptr_t)ptr & ~PAGE_MASK;
765 nbytes = min_t(unsigned int, PAGE_SIZE - offset, len);
766 sg_set_page(sg, pages[npages], nbytes, offset);
778 static int vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *tv_cmd,
779 struct iovec *iov, unsigned int niov, int write)
784 struct scatterlist *sg;
787 * Find out how long sglist needs to be
790 for (i = 0; i < niov; i++)
791 sgl_count += iov_num_pages(&iov[i]);
793 /* TODO overflow checking */
795 sg = kmalloc(sizeof(tv_cmd->tvc_sgl[0]) * sgl_count, GFP_ATOMIC);
798 pr_debug("%s sg %p sgl_count %u is_err %d\n", __func__,
800 sg_init_table(sg, sgl_count);
802 tv_cmd->tvc_sgl = sg;
803 tv_cmd->tvc_sgl_count = sgl_count;
805 pr_debug("Mapping %u iovecs for %u pages\n", niov, sgl_count);
806 for (i = 0; i < niov; i++) {
807 ret = vhost_scsi_map_to_sgl(sg, sgl_count, &iov[i], write);
809 for (i = 0; i < tv_cmd->tvc_sgl_count; i++)
810 put_page(sg_page(&tv_cmd->tvc_sgl[i]));
811 kfree(tv_cmd->tvc_sgl);
812 tv_cmd->tvc_sgl = NULL;
813 tv_cmd->tvc_sgl_count = 0;
823 static void tcm_vhost_submission_work(struct work_struct *work)
825 struct tcm_vhost_cmd *tv_cmd =
826 container_of(work, struct tcm_vhost_cmd, work);
827 struct tcm_vhost_nexus *tv_nexus;
828 struct se_cmd *se_cmd = &tv_cmd->tvc_se_cmd;
829 struct scatterlist *sg_ptr, *sg_bidi_ptr = NULL;
830 int rc, sg_no_bidi = 0;
832 if (tv_cmd->tvc_sgl_count) {
833 sg_ptr = tv_cmd->tvc_sgl;
834 /* FIXME: Fix BIDI operation in tcm_vhost_submission_work() */
836 if (se_cmd->se_cmd_flags & SCF_BIDI) {
844 tv_nexus = tv_cmd->tvc_nexus;
846 rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess,
847 tv_cmd->tvc_cdb, &tv_cmd->tvc_sense_buf[0],
848 tv_cmd->tvc_lun, tv_cmd->tvc_exp_data_len,
849 tv_cmd->tvc_task_attr, tv_cmd->tvc_data_direction,
850 0, sg_ptr, tv_cmd->tvc_sgl_count,
851 sg_bidi_ptr, sg_no_bidi);
853 transport_send_check_condition_and_sense(se_cmd,
854 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
855 transport_generic_free_cmd(se_cmd, 0);
859 static void vhost_scsi_send_bad_target(struct vhost_scsi *vs,
860 struct vhost_virtqueue *vq, int head, unsigned out)
862 struct virtio_scsi_cmd_resp __user *resp;
863 struct virtio_scsi_cmd_resp rsp;
866 memset(&rsp, 0, sizeof(rsp));
867 rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
868 resp = vq->iov[out].iov_base;
869 ret = __copy_to_user(resp, &rsp, sizeof(rsp));
871 vhost_add_used_and_signal(&vs->dev, vq, head, 0);
873 pr_err("Faulted on virtio_scsi_cmd_resp\n");
876 static void vhost_scsi_handle_vq(struct vhost_scsi *vs,
877 struct vhost_virtqueue *vq)
879 struct tcm_vhost_tpg **vs_tpg;
880 struct virtio_scsi_cmd_req v_req;
881 struct tcm_vhost_tpg *tv_tpg;
882 struct tcm_vhost_cmd *tv_cmd;
883 u32 exp_data_len, data_first, data_num, data_direction;
889 * We can handle the vq only after the endpoint is setup by calling the
890 * VHOST_SCSI_SET_ENDPOINT ioctl.
892 * TODO: Check that we are running from vhost_worker which acts
893 * as read-side critical section for vhost kind of RCU.
894 * See the comments in struct vhost_virtqueue in drivers/vhost/vhost.h
896 vs_tpg = rcu_dereference_check(vq->private_data, 1);
900 mutex_lock(&vq->mutex);
901 vhost_disable_notify(&vs->dev, vq);
904 head = vhost_get_vq_desc(&vs->dev, vq, vq->iov,
905 ARRAY_SIZE(vq->iov), &out, &in,
907 pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n",
909 /* On error, stop handling until the next kick. */
910 if (unlikely(head < 0))
912 /* Nothing new? Wait for eventfd to tell us they refilled. */
913 if (head == vq->num) {
914 if (unlikely(vhost_enable_notify(&vs->dev, vq))) {
915 vhost_disable_notify(&vs->dev, vq);
921 /* FIXME: BIDI operation */
922 if (out == 1 && in == 1) {
923 data_direction = DMA_NONE;
926 } else if (out == 1 && in > 1) {
927 data_direction = DMA_FROM_DEVICE;
928 data_first = out + 1;
930 } else if (out > 1 && in == 1) {
931 data_direction = DMA_TO_DEVICE;
935 vq_err(vq, "Invalid buffer layout out: %u in: %u\n",
941 * Check for a sane resp buffer so we can report errors to
944 if (unlikely(vq->iov[out].iov_len !=
945 sizeof(struct virtio_scsi_cmd_resp))) {
946 vq_err(vq, "Expecting virtio_scsi_cmd_resp, got %zu"
947 " bytes\n", vq->iov[out].iov_len);
951 if (unlikely(vq->iov[0].iov_len != sizeof(v_req))) {
952 vq_err(vq, "Expecting virtio_scsi_cmd_req, got %zu"
953 " bytes\n", vq->iov[0].iov_len);
956 pr_debug("Calling __copy_from_user: vq->iov[0].iov_base: %p,"
957 " len: %zu\n", vq->iov[0].iov_base, sizeof(v_req));
958 ret = __copy_from_user(&v_req, vq->iov[0].iov_base,
961 vq_err(vq, "Faulted on virtio_scsi_cmd_req\n");
965 /* Extract the tpgt */
966 target = v_req.lun[1];
967 tv_tpg = ACCESS_ONCE(vs_tpg[target]);
969 /* Target does not exist, fail the request */
970 if (unlikely(!tv_tpg)) {
971 vhost_scsi_send_bad_target(vs, vq, head, out);
976 for (i = 0; i < data_num; i++)
977 exp_data_len += vq->iov[data_first + i].iov_len;
979 tv_cmd = vhost_scsi_allocate_cmd(vq, tv_tpg, &v_req,
980 exp_data_len, data_direction);
981 if (IS_ERR(tv_cmd)) {
982 vq_err(vq, "vhost_scsi_allocate_cmd failed %ld\n",
986 pr_debug("Allocated tv_cmd: %p exp_data_len: %d, data_direction"
987 ": %d\n", tv_cmd, exp_data_len, data_direction);
989 tv_cmd->tvc_vhost = vs;
991 tv_cmd->tvc_resp = vq->iov[out].iov_base;
994 * Copy in the recieved CDB descriptor into tv_cmd->tvc_cdb
995 * that will be used by tcm_vhost_new_cmd_map() and down into
996 * target_setup_cmd_from_cdb()
998 memcpy(tv_cmd->tvc_cdb, v_req.cdb, TCM_VHOST_MAX_CDB_SIZE);
1000 * Check that the recieved CDB size does not exceeded our
1001 * hardcoded max for tcm_vhost
1003 /* TODO what if cdb was too small for varlen cdb header? */
1004 if (unlikely(scsi_command_size(tv_cmd->tvc_cdb) >
1005 TCM_VHOST_MAX_CDB_SIZE)) {
1006 vq_err(vq, "Received SCSI CDB with command_size: %d that"
1007 " exceeds SCSI_MAX_VARLEN_CDB_SIZE: %d\n",
1008 scsi_command_size(tv_cmd->tvc_cdb),
1009 TCM_VHOST_MAX_CDB_SIZE);
1012 tv_cmd->tvc_lun = ((v_req.lun[2] << 8) | v_req.lun[3]) & 0x3FFF;
1014 pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n",
1015 tv_cmd->tvc_cdb[0], tv_cmd->tvc_lun);
1017 if (data_direction != DMA_NONE) {
1018 ret = vhost_scsi_map_iov_to_sgl(tv_cmd,
1019 &vq->iov[data_first], data_num,
1020 data_direction == DMA_FROM_DEVICE);
1021 if (unlikely(ret)) {
1022 vq_err(vq, "Failed to map iov to sgl\n");
1028 * Save the descriptor from vhost_get_vq_desc() to be used to
1029 * complete the virtio-scsi request in TCM callback context via
1030 * tcm_vhost_queue_data_in() and tcm_vhost_queue_status()
1032 tv_cmd->tvc_vq_desc = head;
1034 * Dispatch tv_cmd descriptor for cmwq execution in process
1035 * context provided by tcm_vhost_workqueue. This also ensures
1036 * tv_cmd is executed on the same kworker CPU as this vhost
1037 * thread to gain positive L2 cache locality effects..
1039 INIT_WORK(&tv_cmd->work, tcm_vhost_submission_work);
1040 queue_work(tcm_vhost_workqueue, &tv_cmd->work);
1043 mutex_unlock(&vq->mutex);
1047 vhost_scsi_free_cmd(tv_cmd);
1049 vhost_scsi_send_bad_target(vs, vq, head, out);
1050 mutex_unlock(&vq->mutex);
1053 static void vhost_scsi_ctl_handle_kick(struct vhost_work *work)
1055 pr_debug("%s: The handling func for control queue.\n", __func__);
1058 static void tcm_vhost_send_evt(struct vhost_scsi *vs, struct tcm_vhost_tpg *tpg,
1059 struct se_lun *lun, u32 event, u32 reason)
1061 struct tcm_vhost_evt *evt;
1063 evt = tcm_vhost_allocate_evt(vs, event, reason);
1068 /* TODO: share lun setup code with virtio-scsi.ko */
1070 * Note: evt->event is zeroed when we allocate it and
1071 * lun[4-7] need to be zero according to virtio-scsi spec.
1073 evt->event.lun[0] = 0x01;
1074 evt->event.lun[1] = tpg->tport_tpgt & 0xFF;
1075 if (lun->unpacked_lun >= 256)
1076 evt->event.lun[2] = lun->unpacked_lun >> 8 | 0x40 ;
1077 evt->event.lun[3] = lun->unpacked_lun & 0xFF;
1080 llist_add(&evt->list, &vs->vs_event_list);
1081 vhost_work_queue(&vs->dev, &vs->vs_event_work);
1084 static void vhost_scsi_evt_handle_kick(struct vhost_work *work)
1086 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
1088 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev);
1090 mutex_lock(&vq->mutex);
1091 if (!vq->private_data)
1094 if (vs->vs_events_missed)
1095 tcm_vhost_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
1097 mutex_unlock(&vq->mutex);
1100 static void vhost_scsi_handle_kick(struct vhost_work *work)
1102 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
1104 struct vhost_scsi *vs = container_of(vq->dev, struct vhost_scsi, dev);
1106 vhost_scsi_handle_vq(vs, vq);
1109 static void vhost_scsi_flush_vq(struct vhost_scsi *vs, int index)
1111 vhost_poll_flush(&vs->vqs[index].vq.poll);
1114 /* Callers must hold dev mutex */
1115 static void vhost_scsi_flush(struct vhost_scsi *vs)
1117 struct vhost_scsi_inflight *old_inflight[VHOST_SCSI_MAX_VQ];
1120 /* Init new inflight and remember the old inflight */
1121 tcm_vhost_init_inflight(vs, old_inflight);
1124 * The inflight->kref was initialized to 1. We decrement it here to
1125 * indicate the start of the flush operation so that it will reach 0
1126 * when all the reqs are finished.
1128 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
1129 kref_put(&old_inflight[i]->kref, tcm_vhost_done_inflight);
1131 /* Flush both the vhost poll and vhost work */
1132 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
1133 vhost_scsi_flush_vq(vs, i);
1134 vhost_work_flush(&vs->dev, &vs->vs_completion_work);
1135 vhost_work_flush(&vs->dev, &vs->vs_event_work);
1137 /* Wait for all reqs issued before the flush to be finished */
1138 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
1139 wait_for_completion(&old_inflight[i]->comp);
1143 * Called from vhost_scsi_ioctl() context to walk the list of available
1144 * tcm_vhost_tpg with an active struct tcm_vhost_nexus
1146 * The lock nesting rule is:
1147 * tcm_vhost_mutex -> vs->dev.mutex -> tpg->tv_tpg_mutex -> vq->mutex
1149 static int vhost_scsi_set_endpoint(
1150 struct vhost_scsi *vs,
1151 struct vhost_scsi_target *t)
1153 struct se_portal_group *se_tpg;
1154 struct tcm_vhost_tport *tv_tport;
1155 struct tcm_vhost_tpg *tv_tpg;
1156 struct tcm_vhost_tpg **vs_tpg;
1157 struct vhost_virtqueue *vq;
1158 int index, ret, i, len;
1161 mutex_lock(&tcm_vhost_mutex);
1162 mutex_lock(&vs->dev.mutex);
1164 /* Verify that ring has been setup correctly. */
1165 for (index = 0; index < vs->dev.nvqs; ++index) {
1166 /* Verify that ring has been setup correctly. */
1167 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) {
1173 len = sizeof(vs_tpg[0]) * VHOST_SCSI_MAX_TARGET;
1174 vs_tpg = kzalloc(len, GFP_KERNEL);
1180 memcpy(vs_tpg, vs->vs_tpg, len);
1182 list_for_each_entry(tv_tpg, &tcm_vhost_list, tv_tpg_list) {
1183 mutex_lock(&tv_tpg->tv_tpg_mutex);
1184 if (!tv_tpg->tpg_nexus) {
1185 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1188 if (tv_tpg->tv_tpg_vhost_count != 0) {
1189 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1192 tv_tport = tv_tpg->tport;
1194 if (!strcmp(tv_tport->tport_name, t->vhost_wwpn)) {
1195 if (vs->vs_tpg && vs->vs_tpg[tv_tpg->tport_tpgt]) {
1197 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1202 * In order to ensure individual vhost-scsi configfs
1203 * groups cannot be removed while in use by vhost ioctl,
1204 * go ahead and take an explicit se_tpg->tpg_group.cg_item
1207 se_tpg = &tv_tpg->se_tpg;
1208 ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
1209 &se_tpg->tpg_group.cg_item);
1211 pr_warn("configfs_depend_item() failed: %d\n", ret);
1213 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1216 tv_tpg->tv_tpg_vhost_count++;
1217 tv_tpg->vhost_scsi = vs;
1218 vs_tpg[tv_tpg->tport_tpgt] = tv_tpg;
1219 smp_mb__after_atomic_inc();
1222 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1226 memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn,
1227 sizeof(vs->vs_vhost_wwpn));
1228 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1229 vq = &vs->vqs[i].vq;
1230 /* Flushing the vhost_work acts as synchronize_rcu */
1231 mutex_lock(&vq->mutex);
1232 rcu_assign_pointer(vq->private_data, vs_tpg);
1233 vhost_init_used(vq);
1234 mutex_unlock(&vq->mutex);
1242 * Act as synchronize_rcu to make sure access to
1243 * old vs->vs_tpg is finished.
1245 vhost_scsi_flush(vs);
1247 vs->vs_tpg = vs_tpg;
1250 mutex_unlock(&vs->dev.mutex);
1251 mutex_unlock(&tcm_vhost_mutex);
1255 static int vhost_scsi_clear_endpoint(
1256 struct vhost_scsi *vs,
1257 struct vhost_scsi_target *t)
1259 struct se_portal_group *se_tpg;
1260 struct tcm_vhost_tport *tv_tport;
1261 struct tcm_vhost_tpg *tv_tpg;
1262 struct vhost_virtqueue *vq;
1267 mutex_lock(&tcm_vhost_mutex);
1268 mutex_lock(&vs->dev.mutex);
1269 /* Verify that ring has been setup correctly. */
1270 for (index = 0; index < vs->dev.nvqs; ++index) {
1271 if (!vhost_vq_access_ok(&vs->vqs[index].vq)) {
1282 for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) {
1284 tv_tpg = vs->vs_tpg[target];
1288 mutex_lock(&tv_tpg->tv_tpg_mutex);
1289 tv_tport = tv_tpg->tport;
1295 if (strcmp(tv_tport->tport_name, t->vhost_wwpn)) {
1296 pr_warn("tv_tport->tport_name: %s, tv_tpg->tport_tpgt: %hu"
1297 " does not match t->vhost_wwpn: %s, t->vhost_tpgt: %hu\n",
1298 tv_tport->tport_name, tv_tpg->tport_tpgt,
1299 t->vhost_wwpn, t->vhost_tpgt);
1303 tv_tpg->tv_tpg_vhost_count--;
1304 tv_tpg->vhost_scsi = NULL;
1305 vs->vs_tpg[target] = NULL;
1307 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1309 * Release se_tpg->tpg_group.cg_item configfs dependency now
1310 * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur.
1312 se_tpg = &tv_tpg->se_tpg;
1313 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
1314 &se_tpg->tpg_group.cg_item);
1317 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
1318 vq = &vs->vqs[i].vq;
1319 /* Flushing the vhost_work acts as synchronize_rcu */
1320 mutex_lock(&vq->mutex);
1321 rcu_assign_pointer(vq->private_data, NULL);
1322 mutex_unlock(&vq->mutex);
1326 * Act as synchronize_rcu to make sure access to
1327 * old vs->vs_tpg is finished.
1329 vhost_scsi_flush(vs);
1332 WARN_ON(vs->vs_events_nr);
1333 mutex_unlock(&vs->dev.mutex);
1334 mutex_unlock(&tcm_vhost_mutex);
1338 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1340 mutex_unlock(&vs->dev.mutex);
1341 mutex_unlock(&tcm_vhost_mutex);
1345 static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features)
1347 if (features & ~VHOST_SCSI_FEATURES)
1350 mutex_lock(&vs->dev.mutex);
1351 if ((features & (1 << VHOST_F_LOG_ALL)) &&
1352 !vhost_log_access_ok(&vs->dev)) {
1353 mutex_unlock(&vs->dev.mutex);
1356 vs->dev.acked_features = features;
1358 vhost_scsi_flush(vs);
1359 mutex_unlock(&vs->dev.mutex);
1363 static int vhost_scsi_open(struct inode *inode, struct file *f)
1365 struct vhost_scsi *s;
1366 struct vhost_virtqueue **vqs;
1369 s = kzalloc(sizeof(*s), GFP_KERNEL);
1373 vqs = kmalloc(VHOST_SCSI_MAX_VQ * sizeof(*vqs), GFP_KERNEL);
1379 vhost_work_init(&s->vs_completion_work, vhost_scsi_complete_cmd_work);
1380 vhost_work_init(&s->vs_event_work, tcm_vhost_evt_work);
1382 s->vs_events_nr = 0;
1383 s->vs_events_missed = false;
1385 vqs[VHOST_SCSI_VQ_CTL] = &s->vqs[VHOST_SCSI_VQ_CTL].vq;
1386 vqs[VHOST_SCSI_VQ_EVT] = &s->vqs[VHOST_SCSI_VQ_EVT].vq;
1387 s->vqs[VHOST_SCSI_VQ_CTL].vq.handle_kick = vhost_scsi_ctl_handle_kick;
1388 s->vqs[VHOST_SCSI_VQ_EVT].vq.handle_kick = vhost_scsi_evt_handle_kick;
1389 for (i = VHOST_SCSI_VQ_IO; i < VHOST_SCSI_MAX_VQ; i++) {
1390 vqs[i] = &s->vqs[i].vq;
1391 s->vqs[i].vq.handle_kick = vhost_scsi_handle_kick;
1393 r = vhost_dev_init(&s->dev, vqs, VHOST_SCSI_MAX_VQ);
1395 tcm_vhost_init_inflight(s, NULL);
1403 f->private_data = s;
1407 static int vhost_scsi_release(struct inode *inode, struct file *f)
1409 struct vhost_scsi *s = f->private_data;
1410 struct vhost_scsi_target t;
1412 mutex_lock(&s->dev.mutex);
1413 memcpy(t.vhost_wwpn, s->vs_vhost_wwpn, sizeof(t.vhost_wwpn));
1414 mutex_unlock(&s->dev.mutex);
1415 vhost_scsi_clear_endpoint(s, &t);
1416 vhost_dev_stop(&s->dev);
1417 vhost_dev_cleanup(&s->dev, false);
1418 /* Jobs can re-queue themselves in evt kick handler. Do extra flush. */
1419 vhost_scsi_flush(s);
1425 static long vhost_scsi_ioctl(struct file *f, unsigned int ioctl,
1428 struct vhost_scsi *vs = f->private_data;
1429 struct vhost_scsi_target backend;
1430 void __user *argp = (void __user *)arg;
1431 u64 __user *featurep = argp;
1432 u32 __user *eventsp = argp;
1435 int r, abi_version = VHOST_SCSI_ABI_VERSION;
1436 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
1439 case VHOST_SCSI_SET_ENDPOINT:
1440 if (copy_from_user(&backend, argp, sizeof backend))
1442 if (backend.reserved != 0)
1445 return vhost_scsi_set_endpoint(vs, &backend);
1446 case VHOST_SCSI_CLEAR_ENDPOINT:
1447 if (copy_from_user(&backend, argp, sizeof backend))
1449 if (backend.reserved != 0)
1452 return vhost_scsi_clear_endpoint(vs, &backend);
1453 case VHOST_SCSI_GET_ABI_VERSION:
1454 if (copy_to_user(argp, &abi_version, sizeof abi_version))
1457 case VHOST_SCSI_SET_EVENTS_MISSED:
1458 if (get_user(events_missed, eventsp))
1460 mutex_lock(&vq->mutex);
1461 vs->vs_events_missed = events_missed;
1462 mutex_unlock(&vq->mutex);
1464 case VHOST_SCSI_GET_EVENTS_MISSED:
1465 mutex_lock(&vq->mutex);
1466 events_missed = vs->vs_events_missed;
1467 mutex_unlock(&vq->mutex);
1468 if (put_user(events_missed, eventsp))
1471 case VHOST_GET_FEATURES:
1472 features = VHOST_SCSI_FEATURES;
1473 if (copy_to_user(featurep, &features, sizeof features))
1476 case VHOST_SET_FEATURES:
1477 if (copy_from_user(&features, featurep, sizeof features))
1479 return vhost_scsi_set_features(vs, features);
1481 mutex_lock(&vs->dev.mutex);
1482 r = vhost_dev_ioctl(&vs->dev, ioctl, argp);
1483 /* TODO: flush backend after dev ioctl. */
1484 if (r == -ENOIOCTLCMD)
1485 r = vhost_vring_ioctl(&vs->dev, ioctl, argp);
1486 mutex_unlock(&vs->dev.mutex);
1491 #ifdef CONFIG_COMPAT
1492 static long vhost_scsi_compat_ioctl(struct file *f, unsigned int ioctl,
1495 return vhost_scsi_ioctl(f, ioctl, (unsigned long)compat_ptr(arg));
1499 static const struct file_operations vhost_scsi_fops = {
1500 .owner = THIS_MODULE,
1501 .release = vhost_scsi_release,
1502 .unlocked_ioctl = vhost_scsi_ioctl,
1503 #ifdef CONFIG_COMPAT
1504 .compat_ioctl = vhost_scsi_compat_ioctl,
1506 .open = vhost_scsi_open,
1507 .llseek = noop_llseek,
1510 static struct miscdevice vhost_scsi_misc = {
1516 static int __init vhost_scsi_register(void)
1518 return misc_register(&vhost_scsi_misc);
1521 static int vhost_scsi_deregister(void)
1523 return misc_deregister(&vhost_scsi_misc);
1526 static char *tcm_vhost_dump_proto_id(struct tcm_vhost_tport *tport)
1528 switch (tport->tport_proto_id) {
1529 case SCSI_PROTOCOL_SAS:
1531 case SCSI_PROTOCOL_FCP:
1533 case SCSI_PROTOCOL_ISCSI:
1542 static void tcm_vhost_do_plug(struct tcm_vhost_tpg *tpg,
1543 struct se_lun *lun, bool plug)
1546 struct vhost_scsi *vs = tpg->vhost_scsi;
1547 struct vhost_virtqueue *vq;
1553 mutex_lock(&vs->dev.mutex);
1554 if (!vhost_has_feature(&vs->dev, VIRTIO_SCSI_F_HOTPLUG)) {
1555 mutex_unlock(&vs->dev.mutex);
1560 reason = VIRTIO_SCSI_EVT_RESET_RESCAN;
1562 reason = VIRTIO_SCSI_EVT_RESET_REMOVED;
1564 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
1565 mutex_lock(&vq->mutex);
1566 tcm_vhost_send_evt(vs, tpg, lun,
1567 VIRTIO_SCSI_T_TRANSPORT_RESET, reason);
1568 mutex_unlock(&vq->mutex);
1569 mutex_unlock(&vs->dev.mutex);
1572 static void tcm_vhost_hotplug(struct tcm_vhost_tpg *tpg, struct se_lun *lun)
1574 tcm_vhost_do_plug(tpg, lun, true);
1577 static void tcm_vhost_hotunplug(struct tcm_vhost_tpg *tpg, struct se_lun *lun)
1579 tcm_vhost_do_plug(tpg, lun, false);
1582 static int tcm_vhost_port_link(struct se_portal_group *se_tpg,
1585 struct tcm_vhost_tpg *tv_tpg = container_of(se_tpg,
1586 struct tcm_vhost_tpg, se_tpg);
1588 mutex_lock(&tcm_vhost_mutex);
1590 mutex_lock(&tv_tpg->tv_tpg_mutex);
1591 tv_tpg->tv_tpg_port_count++;
1592 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1594 tcm_vhost_hotplug(tv_tpg, lun);
1596 mutex_unlock(&tcm_vhost_mutex);
1601 static void tcm_vhost_port_unlink(struct se_portal_group *se_tpg,
1604 struct tcm_vhost_tpg *tv_tpg = container_of(se_tpg,
1605 struct tcm_vhost_tpg, se_tpg);
1607 mutex_lock(&tcm_vhost_mutex);
1609 mutex_lock(&tv_tpg->tv_tpg_mutex);
1610 tv_tpg->tv_tpg_port_count--;
1611 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1613 tcm_vhost_hotunplug(tv_tpg, lun);
1615 mutex_unlock(&tcm_vhost_mutex);
1618 static struct se_node_acl *tcm_vhost_make_nodeacl(
1619 struct se_portal_group *se_tpg,
1620 struct config_group *group,
1623 struct se_node_acl *se_nacl, *se_nacl_new;
1624 struct tcm_vhost_nacl *nacl;
1628 /* tcm_vhost_parse_wwn(name, &wwpn, 1) < 0)
1629 return ERR_PTR(-EINVAL); */
1630 se_nacl_new = tcm_vhost_alloc_fabric_acl(se_tpg);
1632 return ERR_PTR(-ENOMEM);
1636 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
1637 * when converting a NodeACL from demo mode -> explict
1639 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
1641 if (IS_ERR(se_nacl)) {
1642 tcm_vhost_release_fabric_acl(se_tpg, se_nacl_new);
1646 * Locate our struct tcm_vhost_nacl and set the FC Nport WWPN
1648 nacl = container_of(se_nacl, struct tcm_vhost_nacl, se_node_acl);
1649 nacl->iport_wwpn = wwpn;
1654 static void tcm_vhost_drop_nodeacl(struct se_node_acl *se_acl)
1656 struct tcm_vhost_nacl *nacl = container_of(se_acl,
1657 struct tcm_vhost_nacl, se_node_acl);
1658 core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);
1662 static int tcm_vhost_make_nexus(struct tcm_vhost_tpg *tv_tpg,
1665 struct se_portal_group *se_tpg;
1666 struct tcm_vhost_nexus *tv_nexus;
1668 mutex_lock(&tv_tpg->tv_tpg_mutex);
1669 if (tv_tpg->tpg_nexus) {
1670 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1671 pr_debug("tv_tpg->tpg_nexus already exists\n");
1674 se_tpg = &tv_tpg->se_tpg;
1676 tv_nexus = kzalloc(sizeof(struct tcm_vhost_nexus), GFP_KERNEL);
1678 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1679 pr_err("Unable to allocate struct tcm_vhost_nexus\n");
1683 * Initialize the struct se_session pointer
1685 tv_nexus->tvn_se_sess = transport_init_session();
1686 if (IS_ERR(tv_nexus->tvn_se_sess)) {
1687 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1692 * Since we are running in 'demo mode' this call with generate a
1693 * struct se_node_acl for the tcm_vhost struct se_portal_group with
1694 * the SCSI Initiator port name of the passed configfs group 'name'.
1696 tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
1697 se_tpg, (unsigned char *)name);
1698 if (!tv_nexus->tvn_se_sess->se_node_acl) {
1699 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1700 pr_debug("core_tpg_check_initiator_node_acl() failed"
1702 transport_free_session(tv_nexus->tvn_se_sess);
1707 * Now register the TCM vhost virtual I_T Nexus as active with the
1708 * call to __transport_register_session()
1710 __transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl,
1711 tv_nexus->tvn_se_sess, tv_nexus);
1712 tv_tpg->tpg_nexus = tv_nexus;
1714 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1718 static int tcm_vhost_drop_nexus(struct tcm_vhost_tpg *tpg)
1720 struct se_session *se_sess;
1721 struct tcm_vhost_nexus *tv_nexus;
1723 mutex_lock(&tpg->tv_tpg_mutex);
1724 tv_nexus = tpg->tpg_nexus;
1726 mutex_unlock(&tpg->tv_tpg_mutex);
1730 se_sess = tv_nexus->tvn_se_sess;
1732 mutex_unlock(&tpg->tv_tpg_mutex);
1736 if (tpg->tv_tpg_port_count != 0) {
1737 mutex_unlock(&tpg->tv_tpg_mutex);
1738 pr_err("Unable to remove TCM_vhost I_T Nexus with"
1739 " active TPG port count: %d\n",
1740 tpg->tv_tpg_port_count);
1744 if (tpg->tv_tpg_vhost_count != 0) {
1745 mutex_unlock(&tpg->tv_tpg_mutex);
1746 pr_err("Unable to remove TCM_vhost I_T Nexus with"
1747 " active TPG vhost count: %d\n",
1748 tpg->tv_tpg_vhost_count);
1752 pr_debug("TCM_vhost_ConfigFS: Removing I_T Nexus to emulated"
1753 " %s Initiator Port: %s\n", tcm_vhost_dump_proto_id(tpg->tport),
1754 tv_nexus->tvn_se_sess->se_node_acl->initiatorname);
1756 * Release the SCSI I_T Nexus to the emulated vhost Target Port
1758 transport_deregister_session(tv_nexus->tvn_se_sess);
1759 tpg->tpg_nexus = NULL;
1760 mutex_unlock(&tpg->tv_tpg_mutex);
1766 static ssize_t tcm_vhost_tpg_show_nexus(struct se_portal_group *se_tpg,
1769 struct tcm_vhost_tpg *tv_tpg = container_of(se_tpg,
1770 struct tcm_vhost_tpg, se_tpg);
1771 struct tcm_vhost_nexus *tv_nexus;
1774 mutex_lock(&tv_tpg->tv_tpg_mutex);
1775 tv_nexus = tv_tpg->tpg_nexus;
1777 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1780 ret = snprintf(page, PAGE_SIZE, "%s\n",
1781 tv_nexus->tvn_se_sess->se_node_acl->initiatorname);
1782 mutex_unlock(&tv_tpg->tv_tpg_mutex);
1787 static ssize_t tcm_vhost_tpg_store_nexus(struct se_portal_group *se_tpg,
1791 struct tcm_vhost_tpg *tv_tpg = container_of(se_tpg,
1792 struct tcm_vhost_tpg, se_tpg);
1793 struct tcm_vhost_tport *tport_wwn = tv_tpg->tport;
1794 unsigned char i_port[TCM_VHOST_NAMELEN], *ptr, *port_ptr;
1797 * Shutdown the active I_T nexus if 'NULL' is passed..
1799 if (!strncmp(page, "NULL", 4)) {
1800 ret = tcm_vhost_drop_nexus(tv_tpg);
1801 return (!ret) ? count : ret;
1804 * Otherwise make sure the passed virtual Initiator port WWN matches
1805 * the fabric protocol_id set in tcm_vhost_make_tport(), and call
1806 * tcm_vhost_make_nexus().
1808 if (strlen(page) >= TCM_VHOST_NAMELEN) {
1809 pr_err("Emulated NAA Sas Address: %s, exceeds"
1810 " max: %d\n", page, TCM_VHOST_NAMELEN);
1813 snprintf(&i_port[0], TCM_VHOST_NAMELEN, "%s", page);
1815 ptr = strstr(i_port, "naa.");
1817 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_SAS) {
1818 pr_err("Passed SAS Initiator Port %s does not"
1819 " match target port protoid: %s\n", i_port,
1820 tcm_vhost_dump_proto_id(tport_wwn));
1823 port_ptr = &i_port[0];
1826 ptr = strstr(i_port, "fc.");
1828 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_FCP) {
1829 pr_err("Passed FCP Initiator Port %s does not"
1830 " match target port protoid: %s\n", i_port,
1831 tcm_vhost_dump_proto_id(tport_wwn));
1834 port_ptr = &i_port[3]; /* Skip over "fc." */
1837 ptr = strstr(i_port, "iqn.");
1839 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_ISCSI) {
1840 pr_err("Passed iSCSI Initiator Port %s does not"
1841 " match target port protoid: %s\n", i_port,
1842 tcm_vhost_dump_proto_id(tport_wwn));
1845 port_ptr = &i_port[0];
1848 pr_err("Unable to locate prefix for emulated Initiator Port:"
1852 * Clear any trailing newline for the NAA WWN
1855 if (i_port[strlen(i_port)-1] == '\n')
1856 i_port[strlen(i_port)-1] = '\0';
1858 ret = tcm_vhost_make_nexus(tv_tpg, port_ptr);
1865 TF_TPG_BASE_ATTR(tcm_vhost, nexus, S_IRUGO | S_IWUSR);
1867 static struct configfs_attribute *tcm_vhost_tpg_attrs[] = {
1868 &tcm_vhost_tpg_nexus.attr,
1872 static struct se_portal_group *tcm_vhost_make_tpg(struct se_wwn *wwn,
1873 struct config_group *group,
1876 struct tcm_vhost_tport *tport = container_of(wwn,
1877 struct tcm_vhost_tport, tport_wwn);
1879 struct tcm_vhost_tpg *tpg;
1883 if (strstr(name, "tpgt_") != name)
1884 return ERR_PTR(-EINVAL);
1885 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
1886 return ERR_PTR(-EINVAL);
1888 tpg = kzalloc(sizeof(struct tcm_vhost_tpg), GFP_KERNEL);
1890 pr_err("Unable to allocate struct tcm_vhost_tpg");
1891 return ERR_PTR(-ENOMEM);
1893 mutex_init(&tpg->tv_tpg_mutex);
1894 INIT_LIST_HEAD(&tpg->tv_tpg_list);
1896 tpg->tport_tpgt = tpgt;
1898 ret = core_tpg_register(&tcm_vhost_fabric_configfs->tf_ops, wwn,
1899 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1904 mutex_lock(&tcm_vhost_mutex);
1905 list_add_tail(&tpg->tv_tpg_list, &tcm_vhost_list);
1906 mutex_unlock(&tcm_vhost_mutex);
1908 return &tpg->se_tpg;
1911 static void tcm_vhost_drop_tpg(struct se_portal_group *se_tpg)
1913 struct tcm_vhost_tpg *tpg = container_of(se_tpg,
1914 struct tcm_vhost_tpg, se_tpg);
1916 mutex_lock(&tcm_vhost_mutex);
1917 list_del(&tpg->tv_tpg_list);
1918 mutex_unlock(&tcm_vhost_mutex);
1920 * Release the virtual I_T Nexus for this vhost TPG
1922 tcm_vhost_drop_nexus(tpg);
1924 * Deregister the se_tpg from TCM..
1926 core_tpg_deregister(se_tpg);
1930 static struct se_wwn *tcm_vhost_make_tport(struct target_fabric_configfs *tf,
1931 struct config_group *group,
1934 struct tcm_vhost_tport *tport;
1939 /* if (tcm_vhost_parse_wwn(name, &wwpn, 1) < 0)
1940 return ERR_PTR(-EINVAL); */
1942 tport = kzalloc(sizeof(struct tcm_vhost_tport), GFP_KERNEL);
1944 pr_err("Unable to allocate struct tcm_vhost_tport");
1945 return ERR_PTR(-ENOMEM);
1947 tport->tport_wwpn = wwpn;
1949 * Determine the emulated Protocol Identifier and Target Port Name
1950 * based on the incoming configfs directory name.
1952 ptr = strstr(name, "naa.");
1954 tport->tport_proto_id = SCSI_PROTOCOL_SAS;
1957 ptr = strstr(name, "fc.");
1959 tport->tport_proto_id = SCSI_PROTOCOL_FCP;
1960 off = 3; /* Skip over "fc." */
1963 ptr = strstr(name, "iqn.");
1965 tport->tport_proto_id = SCSI_PROTOCOL_ISCSI;
1969 pr_err("Unable to locate prefix for emulated Target Port:"
1972 return ERR_PTR(-EINVAL);
1975 if (strlen(name) >= TCM_VHOST_NAMELEN) {
1976 pr_err("Emulated %s Address: %s, exceeds"
1977 " max: %d\n", name, tcm_vhost_dump_proto_id(tport),
1980 return ERR_PTR(-EINVAL);
1982 snprintf(&tport->tport_name[0], TCM_VHOST_NAMELEN, "%s", &name[off]);
1984 pr_debug("TCM_VHost_ConfigFS: Allocated emulated Target"
1985 " %s Address: %s\n", tcm_vhost_dump_proto_id(tport), name);
1987 return &tport->tport_wwn;
1990 static void tcm_vhost_drop_tport(struct se_wwn *wwn)
1992 struct tcm_vhost_tport *tport = container_of(wwn,
1993 struct tcm_vhost_tport, tport_wwn);
1995 pr_debug("TCM_VHost_ConfigFS: Deallocating emulated Target"
1996 " %s Address: %s\n", tcm_vhost_dump_proto_id(tport),
2002 static ssize_t tcm_vhost_wwn_show_attr_version(
2003 struct target_fabric_configfs *tf,
2006 return sprintf(page, "TCM_VHOST fabric module %s on %s/%s"
2007 "on "UTS_RELEASE"\n", TCM_VHOST_VERSION, utsname()->sysname,
2008 utsname()->machine);
2011 TF_WWN_ATTR_RO(tcm_vhost, version);
2013 static struct configfs_attribute *tcm_vhost_wwn_attrs[] = {
2014 &tcm_vhost_wwn_version.attr,
2018 static struct target_core_fabric_ops tcm_vhost_ops = {
2019 .get_fabric_name = tcm_vhost_get_fabric_name,
2020 .get_fabric_proto_ident = tcm_vhost_get_fabric_proto_ident,
2021 .tpg_get_wwn = tcm_vhost_get_fabric_wwn,
2022 .tpg_get_tag = tcm_vhost_get_tag,
2023 .tpg_get_default_depth = tcm_vhost_get_default_depth,
2024 .tpg_get_pr_transport_id = tcm_vhost_get_pr_transport_id,
2025 .tpg_get_pr_transport_id_len = tcm_vhost_get_pr_transport_id_len,
2026 .tpg_parse_pr_out_transport_id = tcm_vhost_parse_pr_out_transport_id,
2027 .tpg_check_demo_mode = tcm_vhost_check_true,
2028 .tpg_check_demo_mode_cache = tcm_vhost_check_true,
2029 .tpg_check_demo_mode_write_protect = tcm_vhost_check_false,
2030 .tpg_check_prod_mode_write_protect = tcm_vhost_check_false,
2031 .tpg_alloc_fabric_acl = tcm_vhost_alloc_fabric_acl,
2032 .tpg_release_fabric_acl = tcm_vhost_release_fabric_acl,
2033 .tpg_get_inst_index = tcm_vhost_tpg_get_inst_index,
2034 .release_cmd = tcm_vhost_release_cmd,
2035 .shutdown_session = tcm_vhost_shutdown_session,
2036 .close_session = tcm_vhost_close_session,
2037 .sess_get_index = tcm_vhost_sess_get_index,
2038 .sess_get_initiator_sid = NULL,
2039 .write_pending = tcm_vhost_write_pending,
2040 .write_pending_status = tcm_vhost_write_pending_status,
2041 .set_default_node_attributes = tcm_vhost_set_default_node_attrs,
2042 .get_task_tag = tcm_vhost_get_task_tag,
2043 .get_cmd_state = tcm_vhost_get_cmd_state,
2044 .queue_data_in = tcm_vhost_queue_data_in,
2045 .queue_status = tcm_vhost_queue_status,
2046 .queue_tm_rsp = tcm_vhost_queue_tm_rsp,
2048 * Setup callers for generic logic in target_core_fabric_configfs.c
2050 .fabric_make_wwn = tcm_vhost_make_tport,
2051 .fabric_drop_wwn = tcm_vhost_drop_tport,
2052 .fabric_make_tpg = tcm_vhost_make_tpg,
2053 .fabric_drop_tpg = tcm_vhost_drop_tpg,
2054 .fabric_post_link = tcm_vhost_port_link,
2055 .fabric_pre_unlink = tcm_vhost_port_unlink,
2056 .fabric_make_np = NULL,
2057 .fabric_drop_np = NULL,
2058 .fabric_make_nodeacl = tcm_vhost_make_nodeacl,
2059 .fabric_drop_nodeacl = tcm_vhost_drop_nodeacl,
2062 static int tcm_vhost_register_configfs(void)
2064 struct target_fabric_configfs *fabric;
2067 pr_debug("TCM_VHOST fabric module %s on %s/%s"
2068 " on "UTS_RELEASE"\n", TCM_VHOST_VERSION, utsname()->sysname,
2069 utsname()->machine);
2071 * Register the top level struct config_item_type with TCM core
2073 fabric = target_fabric_configfs_init(THIS_MODULE, "vhost");
2074 if (IS_ERR(fabric)) {
2075 pr_err("target_fabric_configfs_init() failed\n");
2076 return PTR_ERR(fabric);
2079 * Setup fabric->tf_ops from our local tcm_vhost_ops
2081 fabric->tf_ops = tcm_vhost_ops;
2083 * Setup default attribute lists for various fabric->tf_cit_tmpl
2085 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = tcm_vhost_wwn_attrs;
2086 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = tcm_vhost_tpg_attrs;
2087 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;
2088 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;
2089 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;
2090 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2091 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2092 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2093 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2095 * Register the fabric for use within TCM
2097 ret = target_fabric_configfs_register(fabric);
2099 pr_err("target_fabric_configfs_register() failed"
2100 " for TCM_VHOST\n");
2104 * Setup our local pointer to *fabric
2106 tcm_vhost_fabric_configfs = fabric;
2107 pr_debug("TCM_VHOST[0] - Set fabric -> tcm_vhost_fabric_configfs\n");
2111 static void tcm_vhost_deregister_configfs(void)
2113 if (!tcm_vhost_fabric_configfs)
2116 target_fabric_configfs_deregister(tcm_vhost_fabric_configfs);
2117 tcm_vhost_fabric_configfs = NULL;
2118 pr_debug("TCM_VHOST[0] - Cleared tcm_vhost_fabric_configfs\n");
2121 static int __init tcm_vhost_init(void)
2125 * Use our own dedicated workqueue for submitting I/O into
2126 * target core to avoid contention within system_wq.
2128 tcm_vhost_workqueue = alloc_workqueue("tcm_vhost", 0, 0);
2129 if (!tcm_vhost_workqueue)
2132 ret = vhost_scsi_register();
2134 goto out_destroy_workqueue;
2136 ret = tcm_vhost_register_configfs();
2138 goto out_vhost_scsi_deregister;
2142 out_vhost_scsi_deregister:
2143 vhost_scsi_deregister();
2144 out_destroy_workqueue:
2145 destroy_workqueue(tcm_vhost_workqueue);
2150 static void tcm_vhost_exit(void)
2152 tcm_vhost_deregister_configfs();
2153 vhost_scsi_deregister();
2154 destroy_workqueue(tcm_vhost_workqueue);
2157 MODULE_DESCRIPTION("VHOST_SCSI series fabric driver");
2158 MODULE_ALIAS("tcm_vhost");
2159 MODULE_LICENSE("GPL");
2160 module_init(tcm_vhost_init);
2161 module_exit(tcm_vhost_exit);