41 Commits
Author SHA1 Message Date
Sasha Levin 3b55dcde7f kvm tools: disk image related cleanup
Move io debug delay into kvm_config, the parser out of builtin-run into the disk code
and make the init/exit functions match the rest of the code in style.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He a67da3beff 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>
2015-06-01 16:39:52 +01:00
Asias He 5236b50516 kvm tools: Enable O_DIRECT support
With Direct I/O, file reads and writes go directly from the applications
to the storage device, bypassing the operating system read and write
caches. This is useful for applications that manage their own caches.

Open a disk image with O_DIRECT:
   $ lkvm run -d ~/img/test.img,direct

The original readonly flag is still supported.
Open a disk image with O_DIRECT and readonly:
   $ lkvm run -d ~/img/test.img,direct,ro

Signed-off-by: Asias He <asias.hejun@gmail.com>
Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 97f16d6688 kvm tools: Introduce struct disk_image_params
Introduce struct disk_image_params to contain all the disk image parameters.
This is useful for adding more disk image parameters, e.g. disk image
cache mode.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He dcd3cd8e4e kvm tools: Simplify disk read write function name
We read and write in sectors by default. It makes little sense to add
the extra _sector string for read and write ops/function name.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin 9f9207c5ad kvm tools: Fixes for disk image module
Fixes include:
 - Error handling
 - Cleanup
 - Standard init/uninit

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
2015-06-01 16:39:51 +01:00
Sasha Levin f41a132b0a kvm tools: Use native vectored AIO in virtio-blk
This patch hooks AIO support into virtio-blk, allowing for faster IO.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: wrap libaio include with CONFIG_HAS_AIO ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 8b52f877bf kvm tools: Split io request from completion
This patch splits IO request processing from completion notification.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 5af21162e5 kvm tools: Add optional callback on disk op completion
This patch adds an optional callback to be called when a disk op completes.

Currently theres not much use for it, but it is the infrastructure for adding
aio support.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 2534c9b641 kvm tools: Remove the non-iov interface from disk image ops
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 38c396e485 kvm tools: Switch to using an enum for disk image types
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin ff6462e808 kvm tools: Implement VIRTIO_BLK_T_GET_ID
Return device id when requested by virtio-blk.
Device id is currently based on the device information and the inode
number of the underlying disk image.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Prasad Joshi 9df47d0069 kvm tools: Close the disk images after the guest shuts down
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Prasad Joshi c1ed214e17 kvm tools: Add a wrapper function to open disk images
The patch was suggested by Ingo to move the disk image subsystem code
from the kvm-run.c file. The code to open all of the specified disk
images is now moved to a wrapper function in disk/core.c.

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Asias He fda63751b2 kvm tools: Do not use 'inline' for disk_image__flush
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Asias He 87ee33c8e9 kvm tools: Rename struct disk_image_operations ops name for raw image
This patch renames:

raw_image__read_sector_ro_mmap to raw_image__read_sector
raw_image__write_sector_ro_mmap to raw_image__write_sector
raw_image__close_ro_mmap to raw_image__close

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Asias He 72133dd2d8 kvm tools: Tune up ops in 'struct disk_image_operations'
Make read/write ops in 'struct disk_image_operations'
always return the number of bytes read/written and close/flush
ops return int.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Asias He 708dc6cb4d kvm tools: Split blk device code from raw.c to blk.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Asias He 7d22135f61 kvm tools: Consolidate disk_image__{new, new_readonly}
This patch simplifies the disk image API.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Asias He ebe6667cf5 kvm tools: Remove dead coe disk_image__{read, write}_sector
These code are not used anymore. Let's remove it.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Asias He b8861977e4 kvm tools: Rename disk_image__{read, write}_sector_iov
This patch renames disk_image__{read, write}_sector_io to
disk_image__{read, write}.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Asias He c9310ac48d kvm tools: Split raw image and blk device code from disk/core.c
This patch moves raw image and blk device code into disk/raw.c

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin 70b0d7b0d1 kvm tools: Return correct values from disk IOV functions
Currently read/write IOV functions return an incorrect
value instead of the amount of bytes read/written.

This incorrect value may cause errors within the virtio layer.

Return correct amount of bytes read/written from _iov functions.

[ penberg@kernel.org: don't use 'inline' for out-of-line functions ]
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Prasad Joshi 29084a74e9 kvm tools: Add VIRTIO_BLK_T_FLUSH feature to handle flush operation from VM
The virtual machine calls 'sync' when the machine
is halted. Adding the virtio flush feature will
ensure that the data is synced on to disk before
the virtual machine is halted. This is needed to
ensure the intigrity of the data.

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Pekka Enberg f10860ca9c kvm tools: Fix read-only support in QCOW
If the user specifies a read-only image, make sure we never write to it.
Booting to a read-only image looks like this now:

  $ ./kvm run -i ~/images/linux-0.2.qcow2,ro

  [ snip ]
  [    1.250236] end_request: I/O error, dev vda, sector 32856
  [    1.252867] Buffer I/O error on device vda, logical block 16428
  [    1.255706] lost page write due to I/O error on vda
  [    1.258120] EXT4-fs (vda): previous I/O error to superblock detected
  [    1.261157] end_request: I/O error, dev vda, sector 2
  [    1.263333] Buffer I/O error on device vda, logical block 1
  [    1.264944] lost page write due to I/O error on vda
  [    1.266139] EXT4-fs (vda): re-mounted. Opts:
  [    1.284390] end_request: I/O error, dev vda, sector 35842
  [    1.285679] Buffer I/O error on device vda, logical block 17921
  [    1.287175] EXT4-fs warning (device vda): ext4_end_bio:259: I/O error writing to inode 3756 (offset 0 size 1024 starting block 17922)

Reported-by: Sasha Levin <levinsasha928@gmail.com>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin 43835ac90f kvm tools: Rename 'self' variables
Give proper names to vars named 'self'.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin 3fdf659d95 kvm tools: Abolishment of uint*_t types
Clean uint*_t type from the code.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:43 +01:00
Sasha Levin 2d10309857 kvm tools: Rename _sg to _iov and remove dead code
Use _iov to indicate scatter-gather.
Remove simple IO ops from raw image - Dead code.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Sasha Levin 70b53f2559 kvm tools: Add scatter-gather support for disk images
Add optional support for scatter-gather to disk_image.
Formats that can't take advantage of scatter-gather fallback to simple IO.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Prasad Joshi f4ff38df31 kvm tools: Avoid using disk_image->priv member in disk_image__new()
The disk_image->priv is supposed to be a private member for users of
disk_image__new(). The other block device drivers, for example qcow, might need
this pointer to hold their header.

Added a new function disk_image__new_readonly() which calls disk_image__new()
to allocate a new disk and then sets the priv member to mmamped address.

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Sasha Levin 9ac38fe149 kvm tools: Add option to load disk image read only
As suggested by Christoph Hellwig and Pekka Enberg, Add a '--readonly' flag to
prevent runtime changes to the disk to be saved in the image file.  Please note
that since the changes are saved in the VM instead of being written out, a
large amount of modified blocks may kill the tool.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Pekka Enberg fffb37a932 Revert "kvm tools: Use mmap by default for disk images"
This reverts commit ca8dc9130dd89ca790a7c0830d1129dfa6c5c69e.

As pointed out by Christoph Helwig, shared writeable mappings are error prone
and don't handle I/O errors nor ENOSPC properly.
2015-06-01 16:39:42 +01:00
Sasha Levin 5d4d9902fa kvm tools: Use mmap by default for disk images
Use mmap() for disk images and fallback to read()/write() if it fails (for
example, with large images on 32 bit systems).

Performance (kB/s) test using bonnie++ shows 19% improvement in block writes,
7% improvement in block rewrites, and 6% improvement in block reads.

Guest was started with the following command:

  ./kvm run --mem=256 --image=./work/vms/gentoo.img --kernel=/boot/bzImage-git

and bonnie++ with:

  bonnie++ -u 0

Before:
------

  Version  1.96       ------Sequential Output----- --Sequential Input- -Random-
  Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
  Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
  tux            480M   673 100 308017  61 288156  49  3286  99 892186  76 +++++ +++
  Latency             12998us   50992us   35993us    3000us    1999us     201ms
  Version  1.96       ------Sequential Create------ --------Random Create--------
  tux                 -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
                files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                   16 +++++ +++ +++++ +++ +++++ +++ +++++ +++ +++++ +++ +++++ +++
  Latency              3000us    1000us    1000us    1000us    1998us    1000us

After:
------

  Version  1.96       ------Sequential Output------ --Sequential Input- --Random-
  Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
  Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
  tux            480M   674  99 366588  42 309514  44  3539  99 954554  76 +++++ +++
  Latency             17997us   15997us   37993us    4999us    1998us     145ms
  Version  1.96       ------Sequential Create------ --------Random Create--------
  tux                 -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
                files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                   16 +++++ +++ +++++ +++ +++++ +++ +++++ +++ +++++ +++ +++++ +++
  Latency              1000us    1000us    2000us    1999us    1000us    1000us

[ penberg@kernel.org: drop MAP_NORESERVE, it's no-op for MAP_SHARED ]
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Pekka Enberg 499f3bedf8 kvm tools: Cleanup disk image code
This patch cleans up disk image in preparation for supporting other disk
format.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg c4d7847b22 kvm tools: Fix large disk images on 32-bit
Use read()/write() instead of mmap() for virtio block device emulation to
support large disk images on 32-bit.

Reported-and-tested-by: Asias He <asias.hejun@gmail.com>
Tested-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He 2924f993ed kvm,virtio: move SECTOR_SHIFT and SECTOR_SIZE to disk-image.h
Suggested-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 258dd093dc kvm: Implement virtio block device write support
This patch implement virtio block device write support. The writes are not
persistent because we map the disk image with MAP_PRIVATE.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 1ef2738d03 virtio-blk: Leave disk geometry to compute in kernel
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov ca7c891bfe kvm: Setup disk geometry if needed
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Pekka Enberg 5a24a9f279 kvm: Use disk image API from virtio block device
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 9f532d0016 kvm: Add support for disk images
This patch implements "--image" command line option that can be used to specify
a disk image. It supports raw images and it needs to be integrated to the
hypervisor block layer.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00