summaryrefslogtreecommitdiff
path: root/block/vdi.c
AgeCommit message (Collapse)AuthorFilesLines
2012-04-05vdi: change goto to loopPaolo Bonzini1-73/+68
Finally reindent all code and change goto statements to a loop. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: do not create useless iovecsPaolo Bonzini1-46/+33
Reads and writes to the underlying file can also occur with the simple non-vectored I/O interfaces. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: leave bounce buffering to block layerPaolo Bonzini1-55/+12
vdi.c really works as if it implemented bdrv_read and bdrv_write. However, because only vector I/O is supported by the asynchronous callbacks, it went through extra pain to bounce-buffer the I/O. This can be handled by the block layer now that the format is coroutine-based. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: move aiocb fields to localsPaolo Bonzini1-98/+65
Most of the AIOCB really holds local variables that need to persist across callback invocation. It can go away now. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: merge aio_read_cb and aio_write_cb into callersPaolo Bonzini1-28/+12
Now inline the former AIO callbacks into vdi_co_readv and vdi_co_writev. While many cleanups are possible, the code now really looks synchronous. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: move end-of-I/O handling at the endPaolo Bonzini1-67/+56
The next step is to take code that only triggers after the first operation, and move it at the end of vdi_aio_read_cb and vdi_aio_write_cb. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05vdi: basic conversion to coroutinesPaolo Bonzini1-121/+37
Even a basic conversion changing the bdrv_aio_readv/bdrv_aio_writev calls to bdrv_co_readv/bdrv_co_writev, and callbacks to goto statements can eliminate a lot of code. This is because error handling is simplified and indirections through bottom halves can go away. After this patch, I/O to the underlying file already happens via coroutines, but the code still looks a lot like if asynchronous I/O was being used. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05block: push recursive flushing up from driversPaolo Bonzini1-8/+0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-01-26block/vdi: Zero unused parts when allocating a new block (fix #919242)Stefan Weil1-2/+6
The new block was filled with zero when it was allocated by g_malloc0, but when it was reused later and only partially used, data from the previously allocated block were still present and written to the new block. This caused the problems reported by bug #919242 (https://bugs.launchpad.net/qemu/+bug/919242). Now the unused parts of the new block which are before and after the data are always filled with zero, so it is no longer necessary to zero the whole block with g_malloc0. I also updated the copyright comment. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-12-15block: qemu_aio_get does not return NULLPaolo Bonzini1-29/+19
Initially done with the following semantic patch: @ rule1 @ expression E; statement S; @@ E = qemu_aio_get (...); ( - if (E == NULL) { ... } | - if (E) { <... S ...> } ) which however missed occurrences in linux-aio.c and posix-aio-compat.c. Those were done by hand. The change in vdi_aio_setup's caller was also done by hand. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-12-15block: bdrv_aio_* do not return NULLPaolo Bonzini1-20/+0
Initially done with the following semantic patch: @ rule1 @ expression E; statement S; @@ E = ( bdrv_aio_readv | bdrv_aio_writev | bdrv_aio_flush | bdrv_aio_discard | bdrv_aio_ioctl ) (...); ( - if (E == NULL) { ... } | - if (E) { <... S ...> } ) which however missed the occurrence in block/blkverify.c (as it should have done), and left behind some unused variables. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-12-05vdi: convert to .bdrv_co_is_allocated()Stefan Hajnoczi1-3/+3
It is trivial to switch from the synchronous .bdrv_is_allocated() interface to .bdrv_co_is_allocated() since vdi_is_allocated() does not block. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-11-23vdi: Fix memory leakKevin Wolf1-0/+3
The block map is allocated in vdi_open, but was never freed. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-11-23vdi: Add migration blockerKevin Wolf1-0/+12
vdi caches the block map. For migration to work, it would have to be invalidated. Block migration for now. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-11-11block: Rename bdrv_co_flush to bdrv_co_flush_to_diskKevin Wolf1-1/+1
There are two different types of flush that you can do: Flushing one level up to the OS (i.e. writing data to the host page cache) or flushing it all the way down to the disk. The existing functions flush to the disk, reflect this in the function name. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-10-28Teach block/vdi about "discarded" (no longer allocated) blocksEric Sunshine1-9/+14
An entry in the VDI block map will hold an offset to the actual block if the block is allocated, or one of two specially-interpreted values if not allocated. Using VirtualBox terminology, value VDI_IMAGE_BLOCK_FREE (0xffffffff) represents a never-allocated block (semantically arbitrary content). VDI_IMAGE_BLOCK_ZERO (0xfffffffe) represents a "discarded" block (semantically zero-filled). block/vdi knows only about VDI_IMAGE_BLOCK_FREE. Teach it about VDI_IMAGE_BLOCK_ZERO. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-10-21block: change flush to co_flushPaolo Bonzini1-3/+3
Since coroutine operation is now mandatory, convert all bdrv_flush implementations to coroutines. For qcow2, this means taking the lock. Other implementations are simpler and just forward bdrv_flush to the underlying protocol, so they can avoid the lock. The bdrv_flush callback is then unused and can be eliminated. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-8/+8
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-06-15vdi: Avoid direct AIO callbackKevin Wolf1-5/+36
bdrv_aio_* must not call the callback before returning to its caller. In vdi, this could happen in some error cases. This starts the real requests processing in a BH to avoid this situation. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-06-08qemu-img create: Fix displayed default cluster sizeKevin Wolf1-2/+4
When not specifying a cluster size on the command line, qemu-img printed a cluster size of 0: Formatting '/tmp/test.qcow2', fmt=qcow2 size=67108864 encryption=off cluster_size=0 This patch adds the default cluster size to the QEMUOptionParameter list, so that it displays the default value that is used. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-04-03Fix trivial "endianness bugs"Stefan Weil1-2/+2
Replace endianess -> endianness. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-03-15block/vdi: Don't ignore immediate read/write failuresStefan Weil1-0/+5
This patch is similar to 171e3d6b9997c98a97d0c525867f7cd9b640cadd which fixed qcow2: Returning -EIO is far from optimal, but at least it's an error code. Cc: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-02-07block/vdi: Fix wrong size in conditionally used memset, memcmpStefan Weil1-2/+2
Error report from cppcheck: block/vdi.c:122: error: Using sizeof for array given as function argument returns the size of pointer. block/vdi.c:128: error: Using sizeof for array given as function argument returns the size of pointer. Fix both by setting the correct size. The buggy code is only used when QEMU is build without uuid support. The bug is not critical, so there is no urgent need to apply it to old versions of QEMU. Cc: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-11-24block: Remove unused s->hd in various driversKevin Wolf1-1/+0
All drivers use bs->file instead of s->hd for quite a while now, so it's time to remove s->hd. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-11-04block: Allow bdrv_flush to return errorsKevin Wolf1-2/+2
This changes bdrv_flush to return 0 on success and -errno in case of failure. It's a requirement for implementing proper error handle in users of bdrv_flush. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-07-06qcow2/vdi: Change check to distinguish error casesKevin Wolf1-5/+5
This distinguishes between harmless leaks and real corruption. Hopefully users better understand what qemu-img check wants to tell them. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-17block/vdi: Fix image opening and creation for odd disk sizesStefan Weil1-7/+16
The fix is based on a patch from Kevin Wolf. Here his comment: "The number of blocks needs to be rounded up to cover all of the virtual hard disk. Without this fix, we can't even open our own images if their size is not a multiple of the block size." While Kevin's patch addressed vdi_create, my modification also fixes vdi_open which now accepts images with odd disk sizes. v3: Don't allow reading of disk images with too large disk sizes. Neither VBoxManage nor old versions of qemu-img read such images. This change requires rounding of odd disk sizes before we do the checks. Cc: Kevin Wolf <kwolf@redhat.com> Cc: François Revol <revol@free.fr> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-17block/vdi: Allow disk images of size 0Stefan Weil1-2/+7
Even it is not very useful, users may create images of size 0. Without the special option CONFIG_ZERO_MALLOC, qemu_mallocz aborts execution when it is told to allocate 0 bytes, so avoid this kind of call. Cc: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-17block: Avoid unchecked casts for AIOCBsKevin Wolf1-1/+1
Use container_of for one direction and &acb->common for the other one. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-03block: Open the underlying image file in generic codeKevin Wolf1-20/+9
Format drivers shouldn't need to bother with things like file names, but rather just get an open BlockDriverState for the underlying protocol. This patch introduces this behaviour for bdrv_open implementation. For protocols which need to access the filename to open their file/device/connection/... a new callback bdrv_file_open is introduced which doesn't get an underlying file opened. For now, also some of the more obscure formats use bdrv_file_open because they open() the file themselves instead of using the block.c functions. They need to be fixed in later patches. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-01-08block/vdi: allow disk sizes not multiple of block sizeFrançois Revol1-2/+5
The disk image I created from my old laptop disk with VBoxManage internalcommand converthd obviously was not a multiple of 1MB as when created from scratch. This fixes QEMU refusing it. We still require the size to be a multiple of sector size though. It then boots correctly. Allow opening VDI images with size not multiple of 1MB (as when converted from a raw disk). Signed-off-by: François Revol <revol@free.fr> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-04Check availability of uuid header / libraryStefan Weil1-2/+2
If available, the Universally Unique Identifier library is used by the vdi block driver. Other parts of QEMU (vl.c) could also use it. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-09-12Fix signedness warnings on OpenSolarisBlue Swirl1-4/+4
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-08-27block/vdi.c: Fix several bugsStefan Weil1-4/+9
* The code for option '-static' was wrong, so image creation always created static images. * Static images created with qemu-img did not set header entry blocks_allocated. * The size of the block map must be rounded to the next multiple of SECTOR_SIZE, otherwise the block map is only read partially for block map sizes which are not a multiple of SECTOR_SIZE. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-15Use pstrcpy to avoid OpenBSD linker warningsBlue Swirl1-1/+1
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-08-10Add new block driver for the VDI format (only aio supported)Stefan Weil1-0/+951
This is a new block driver written from scratch to support the VDI format in QEMU. VDI is the native format used by Innotek / SUN VirtualBox. Latest changes: * stripped down version (code for synchronous operations and experimental code removed) * don't open VDI snapshot images (with uuid_link or uuid_parent) * modified vdi_aio_cancel Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-Id: