kvm tools: Add initial virtio-scsi support

This patch brings virito-scsi support to kvm tool.

With the introduce of tcm_vhost (vhost-scsi)

   tcm_vhost: Initial merge for vhost level target fabric driver

we can implement virito-scsi by simply having vhost-scsi to handle the
SCSI command.

Howto use:
1) Setup the tcm_vhost target through /sys/kernel/config

   [Stefan Hajnoczi, Thanks for the script to setup tcm_vhost]

   ** Setup wwpn and tpgt
   $ wwpn="naa.0"
   $ tpgt=/sys/kernel/config/target/vhost/$wwpn/tpgt_0
   $ nexus=$tpgt/nexus
   $ mkdir -p $tpgt
   $ echo -n $wwpn > $nexus

   ** Setup lun using /dev/ram
   $ n=0
   $ lun=$tpgt/lun/lun_${n}
   $ data=/sys/kernel/config/target/core/iblock_0/data_${n}
   $ ram=/dev/ram${n}
   $ mkdir -p $lun
   $ mkdir -p $data
   $ echo -n udev_path=${ram} > $data/control
   $ echo -n 1 > $data/enable
   $ ln -s $data $lun

2) Run kvm tool with the new disk option '-d scsi:$wwpn:$tpgt', e.g
   $ lkvm run -k /boot/bzImage -d ~/img/sid.img -d scsi:naa.0:0

Signed-off-by: Asias He <asias.hejun@gmail.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Asias He
2015-06-01 16:39:52 +01:00
committed by Will Deacon
parent 24335ca268
commit a67da3beff
9 changed files with 393 additions and 0 deletions
+8
View File
@@ -41,6 +41,12 @@ struct disk_image_operations {
struct disk_image_params {
const char *filename;
/*
* wwpn == World Wide Port Number
* tpgt == Target Portal Group Tag
*/
const char *wwpn;
const char *tpgt;
bool readonly;
bool direct;
};
@@ -57,6 +63,8 @@ struct disk_image {
#ifdef CONFIG_HAS_AIO
io_context_t ctx;
#endif
const char *wwpn;
const char *tpgt;
};
struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct);
+1
View File
@@ -13,6 +13,7 @@
#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003
#define PCI_DEVICE_ID_VIRTIO_RNG 0x1004
#define PCI_DEVICE_ID_VIRTIO_BLN 0x1005
#define PCI_DEVICE_ID_VIRTIO_SCSI 0x1008
#define PCI_DEVICE_ID_VIRTIO_9P 0x1009
#define PCI_DEVICE_ID_VESA 0x2000
#define PCI_DEVICE_ID_PCI_SHMEM 0x0001
+26
View File
@@ -0,0 +1,26 @@
#ifndef KVM__SCSI_VIRTIO_H
#define KVM__SCSI_VIRTIO_H
#include "kvm/disk-image.h"
struct kvm;
int virtio_scsi_init(struct kvm *kvm);
int virtio_scsi_exit(struct kvm *kvm);
/*----------------------------------------------------*/
/* TODO: Remove this when tcm_vhost goes upstream */
#define TRANSPORT_IQN_LEN 224
#define VHOST_SCSI_ABI_VERSION 0
struct vhost_scsi_target {
int abi_version;
unsigned char vhost_wwpn[TRANSPORT_IQN_LEN];
unsigned short vhost_tpgt;
};
/* VHOST_SCSI specific defines */
#define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
#define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
#define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, struct vhost_scsi_target)
/*----------------------------------------------------*/
#endif /* KVM__SCSI_VIRTIO_H */
+1
View File
@@ -11,6 +11,7 @@
#endif
#define __used __attribute__((__unused__))
#define __packed __attribute__((packed))
#define __iomem
#define __force
#define __must_check