iSCSI block driver support
Subsystems (2)
The following patch adds a new block driver to QEMU/KVM for iSCSI.
This utilizes the userspace client library for iscsi at https://github.com/sahlberg/libiscsi and will link with this library if available.
This allows using iSCSI resources with QEMU/KVM without making them visible to the underlying host. Which is very useful when having very large number of iscsi devices, or when you for other reasons do not want to expose these devicdes to others.
I have used this patch and installed a RHEL6 system from an iscsi dvd onto a iscsi disk. I have done extensive testing. Both normally and also running under valgrind (which is very slow)
./x86_64-softmmu/qemu-system-x86_64 -m 1024 --enable-kvm -cdrom iscsi://127.0.0.1:3262/iqn.ronnie.test/2 -drive if=virtio,file=iscsi://127.0.0.1:3262/iqn.ronnie.test/1 -boot c
Please review and/or apply.
This is version 4 of the patch :
Version 4 adds :
- Remove iscsi_is_inserted() since we dont need that function.
- Change status to -ECANCELED instead of -EIO when aios are cancelled
- Check that the i/o is not cancelled before calling the callback function.
- Replace the flush fuinction with an async version.
- Verify that qemu block size is at least 512 bytes
- Handle the case where qemu blocksize is smaller than lun blocksize and qemu issues an unaligned read.
-----
Version 3 :
- Fix a bug when writing freed data to the disk
- Convert TAB to spaces
- Add tracing functions (From Stefan Hajnoczi)
- Add a io_flush() handler
-----
Version 2:
Changes from Blue Swirl's suggestions
- Change naming of structures and typedefs to match coding style
- Use CONFIG_ISCSI in the makefile to conditionally compile iscsi.c
- Missing spaces added around operators
- Use uint8_t instead of unsigned char for buffer pointer
- Use a temporary variable for the result of long functions, to move them out from the if(...) expressions. Making the code easier to read.
- Create a function sector_qemu2lun() and use it instead of performing the same conversion explicitely at several palces in the code.
- Use the name opaque instead of private_data
- Use memset() instead of bzero()
- Use the common library function to parse the iSCSI URL
- Add support for CHAP authentication
PATCH 1/1 iSCSI block driver support
This patch adds a new block driver : block.iscsi.c This driver interfaces with the multiplatform posix library for iscsi initiator/client access to iscsi devices hosted atgit://github.com/sahlberg/libiscsi.git
The patch adds the driver to interface with the iscsi library. It also updated the configure script to
* by default, probe is libiscsi is available and if so, build qemu against libiscsi.
* --enable-libiscsi
Force a build against libiscsi. If libiscsi is not available the build will fail.
* --disable-libiscsi
Do not link against libiscsi, even if it is available.
When linked with libiscsi, qemu gains support to access iscsi resources such as disks and cdrom directly, without having to make the devices visible to the host.
You can specify devices using a iscsi url of the form :
iscsi://[<username>[:<password>@]]<host>[:<port]/<target-iqn-name>/<lun> When using authentication, the password can optionally be set with LIBISCSI_CHAP_PASSWORD="password" to avoid it showing up in the process list
Example:
-drive file=iscsi://10.1.1.1:3260/iqn.ronnie.test/1
-cdrom iscsi://10.1.1.1:3260/iqn.ronnie.test/2
--- Makefile.objs | 1 + block/iscsi.c | 564 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 31 +++ trace-events | 7 + 4 files changed, 603 insertions(+), 0 deletions(-) create mode 100644 block/iscsi.c
Makefile.objs +1 -0
@@ -25,6 +25,7 @@ block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o +block-nested-$(CONFIG_LIBISCSI) += iscsi.o block-nested-$(CONFIG_CURL) += curl.o block-nested-$(CONFIG_RBD) += rbd.o
block/iscsi.c new file +564 -0
564 lines not on this page · raw message
configure +31 -0
@@ -174,6 +174,7 @@ trace_backend="nop" trace_file="trace" spice="" rbd="" +libiscsi="" # parse CC options first for opt do
@@ -622,6 +623,10 @@ for opt do ;; --enable-spice) spice="yes" ;; + --disable-libiscsi) libiscsi="no" + ;; + --enable-libiscsi) libiscsi="yes" + ;; --enable-profiler) profiler="yes" ;; --enable-cocoa)
@@ -914,6 +919,8 @@ echo " Default:trace-<pid>" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device (rbd)" +echo " --disable-libiscsi disable iscsi support" +echo " --enable-libiscsi enable iscsi support" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2224,6 +2231,25 @@ if compile_prog "" "" ; then fi ########################################## +# Do we have libiscsi +if test "$libiscsi" != "no" ; then + cat > $TMPC << EOF +#include <iscsi/iscsi.h> +int main(void) { iscsi_create_context(""); return 0; } +EOF + if compile_prog "-Werror" "-liscsi" ; then + libiscsi="yes" + LIBS="$LIBS -liscsi" + else + if test "$libiscsi" = "yes" ; then + feature_not_found "libiscsi" + fi + libiscsi="no" + fi +fi + + +########################################## # Do we need librt cat > $TMPC <<EOF #include <signal.h>
@@ -2525,6 +2551,7 @@ echo "Trace output file $trace_file-<pid>" echo "spice support $spice" echo "rbd support $rbd" echo "xfsctl support $xfs" +echo "libiscsi support $libiscsi" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2806,6 +2833,10 @@ if test "$spice" = "yes" ; then echo "CONFIG_SPICE=y" >> $config_host_mak fi +if test "$libiscsi" = "yes" ; then + echo "CONFIG_LIBISCSI=y" >> $config_host_mak +fi + # XXX: suppress that if [ "$bsd" = "yes" ] ; then echo "CONFIG_BSD=y" >> $config_host_mak
trace-events +7 -0
@@ -254,3 +254,10 @@ disable spice_vmc_write(ssize_t out, int len) "spice wrottn %lu of requested %zd disable spice_vmc_read(int bytes, int len) "spice read %lu of requested %zd" disable spice_vmc_register_interface(void *scd) "spice vmc registered interface %p" disable spice_vmc_unregister_interface(void *scd) "spice vmc unregistered interface %p" + + +# block/iscsi.c +disable iscsi_aio_write10_cb(void *iscsi, int status, void *acb, int canceled) "iscsi %p status %d acb %p canceled %d" +disable iscsi_aio_writev(void *iscsi, int64_t sector_num, int nb_sectors, void *opaque, void *acb) "iscsi %p sector_num %"PRId64" nb_sectors %d opaque %p acb %p" +disable iscsi_aio_read10_cb(void *iscsi, int status, void *acb, int canceled) "iscsi %p status %d acb %p canceled %d" +disable iscsi_aio_readv(void *iscsi, int64_t sector_num, int nb_sectors, void *opaque, void *acb) "iscsi %p sector_num %"PRId64" nb_sectors %d opaque %p acb %p"
Signature · 1 line
1.7.3.1