Commit Graph

84 Commits

Author SHA1 Message Date
aliguori 51d7c00c14 block: Polish error handling of brdv_open2 (Jan Kiszka)
Make sure that we always delete temporary disk images on error, remove
obsolete malloc error checks and return proper error codes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6702 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-05 23:00:29 +00:00
aliguori 71d0770c4c Fix CVE-2008-0928 - insufficient block device address range checking (Anthony Liguori)
Introduce a growable flag that's set by bdrv_file_open().  Block devices should
never be growable, only files that are being used by block devices.

I went through Fabrice's early comments about the patch that was first applied.
While I disagree with that patch, I also disagree with Fabrice's suggestion.

There's no good reason to do the checks in the block drivers themselves.  It
just increases the possibility that this bug could show up again.  Since we're
calling bdrv_getlength() to determine the length, we're giving the block drivers
a chance to chime in and let us know what range is valid.

Basically, this patch makes the BlockDriver API guarantee that all requests are
within 0..bdrv_getlength() which to me seems like a Good Thing.

What do others think?

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6677 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-03 17:37:16 +00:00
aurel32 d905dba48f fix SIGSEGV when USE_KQEMU is defined
Signed-off-by: Alex Ivanov <void@aleksoft.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6674 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-03 06:28:26 +00:00
aliguori 3ec88e8036 block: remove error handling from qemu_malloc() callers (Avi Kivity)
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6527 c046a42c-6fe2-441c-8c8c-71466251a162
2009-02-05 22:05:53 +00:00
aliguori 249aa745fb qemu iovec: keep track of total size, allow partial copies (Gerd Hoffman)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6448 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-26 17:17:52 +00:00
aliguori 1987530fe0 qcow2 format: keep 'num_free_bytes', and show it upon 'info blockstats' (Uri Lublin)
'num_free_bytes' is the number of non-allocated bytes below highest-allocation.
It's useful, together with the highest-allocation, to figure out how
fragmented the image is, and how likely it will run out-of-space soon.

For example when the highest allocation is high (almost end-of-disk), but 
many bytes (clusters) are free, and can be re-allocated when neeeded, than
we know it's probably not going to reach end-of-disk-space soon.

Added bookkeeping to block-qcow2.c
Export it using BlockDeviceInfo
Show it upon 'info blockstats' if BlockDeviceInfo exists

Signed-off-by: Uri Lublin <uril@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6407 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22 18:57:34 +00:00
aliguori a7cbfae0cf info blockstats: show highest_allocated if exists (Uri Lublin)
Signed-off-by: Uri Lublin <uril@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6406 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22 18:57:30 +00:00
aliguori 3b69e4b9ad Vectored block device API (Avi Kivity)
Most devices that are capable of DMA are also capable of scatter-gather.
With the memory mapping API, this means that the device code needs to be
able to access discontiguous host memory regions.

For block devices, this translates to vectored I/O.  This patch implements
an aynchronous vectored interface for the qemu block devices.  At the moment
all I/O is bounced and submitted through the non-vectored API; in the future
we will convert block devices to natively support vectored I/O wherever
possible.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6397 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-22 16:59:24 +00:00
aliguori 42fb2807d9 bdrv_write should not stop on partial write (Gleb Natapov)
Should return real error instead.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6323 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-15 20:43:39 +00:00
blueswir1 a38131b669 Attached patch contains warning fixes.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5888 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-05 17:56:40 +00:00
blueswir1 3990d09adf sys-queue.h defines _SYS_QUEUE_H_ which is also defined by
the <sys/queue.h> system header. <sys/disk.h> uses SLIST_ENTRY
on NetBSD, which doesn't exist in sys-queue.h. Therefore,
include <sys/queue.h> before including sys-queue.h.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5885 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-05 17:53:21 +00:00
aliguori f3d54fc494 Abstract out geometry detection code from IDE for reuse
Virtio will want to use the geometry detection code.  It doesn't belong 
in ide.c anyway.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5797 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-25 21:50:24 +00:00
aliguori 4fc9af53d8 Use an option rom instead of boot sector for -kernel
Generate an option rom instead of using a hijacked boot sector for kernel
booting.  This just requires adding a small option ROM header and a few more
instructions to the boot sector to take over the int19 vector and run our
boot code.

A disk is no longer needed when using -kernel on x86.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5650 c046a42c-6fe2-441c-8c8c-71466251a162
2008-11-08 16:27:07 +00:00
aliguori 9f7965c7e9 Expand cache= option and use write-through caching by default
This patch changes the cache= option to accept none, writeback, or writethough
to control the host page cache behavior.  By default, writethrough caching is
now used which internally is implemented by using O_DSYNC to open the disk
images.  When using -snapshot, writeback is used by default since data integrity
it not at all an issue.

cache=none has the same behavior as cache=off previously.  The later syntax is
still supported by now deprecated.  I also cleaned up the O_DIRECT
implementation to avoid many of the #ifdefs.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5485 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-14 14:42:54 +00:00
aurel32 a0a83536e0 open() can also return EPERM for O_RDWR on a readonly device
Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5482 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-13 21:08:34 +00:00
aliguori c6ca28d636 Add bdrv_flush_all()
This patch adds a bdrv_flush_all() function.  It's necessary to ensure that all
IO operations have been flushed to disk before completely a live migration.

N.B. we don't actually use this now.  We really should flush the block drivers
using an live savevm callback to avoid unnecessary guest down time.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5432 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-06 13:55:43 +00:00
aliguori a76bab4952 Refactor AIO to allow multiple AIO implementations
This patch refactors the AIO layer to allow multiple AIO implementations.  It's
only possible because of the recent signalfd() patch.  

Right now, the AIO infrastructure is pretty specific to the block raw backend.
For other block devices to implement AIO, the qemu_aio_wait function must
support registration.  This patch introduces a new function,
qemu_aio_set_fd_handler, which can be used to register a file descriptor to be
called back.  qemu_aio_wait() now polls a set of file descriptors registered
with this function until one becomes readable or writable.

This patch should allow the implementation of alternative AIO backends (via a
thread pool or linux-aio) and AIO backends in non-traditional block devices
(like NBD).

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5297 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-22 19:17:18 +00:00
blueswir1 7ee930d031 Fix warnings that would be caused by ld flag --warn-common
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5240 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-17 19:04:14 +00:00
aliguori 03ff3ca30f Use common objects for qemu-img and qemu-nbd
Right now, we sprinkle #if defined(QEMU_IMG) && defined(QEMU_NBD) all over the
code.  It's ugly and causes us to have to build multiple object files for
linking against qemu and the tools.

This patch introduces a new file, qemu-tool.c which contains enough for
qemu-img, qemu-nbd, and QEMU to all share the same objects.

This also required getting qemu-nbd to be a bit more Windows friendly.  I also
changed the Windows block-raw to use normal IO instead of overlapping IO since
we don't actually do AIO yet on Windows.  I changed the various #if 0's to
 #if WIN32_AIO to make it easier for someone to eventually fix AIO on Windows.

After this patch, there are no longer any #ifdef's related to qemu-img and
qemu-nbd.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5226 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-15 15:51:35 +00:00
blueswir1 7ccfb2eb5f Fix warnings that would be caused by gcc flag -Wwrite-strings
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5206 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-14 06:45:34 +00:00
aliguori 7c96d46ec2 Let snapshot work with protocols
realpath will horribly mangle a protocol so avoid calling it if the backing
file is a protocol.



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5200 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-12 17:54:13 +00:00
aliguori a3392f9b10 Only build compatfd when using AIO and make sure to always init AIO
OpenBSD doesn't use AIO so don't try to build compatfd when not using AIO.

Also make sure to call qemu_aio_init() from bdrv_init.  Everything that uses
bdrv calls bdrv_init so it makes sense to init aio from there instead of
in every single tool.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5197 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-11 18:00:19 +00:00
aliguori baf35cb902 Use signalfd() to work around signal/select race
This patch introduces signalfd() to work around the signal/select race in
checking for AIO completions.  For platforms that don't support signalfd(), we
emulate it with threads.

There was a long discussion about this approach.  I don't believe there are any
fundamental problems with this approach and I believe eliminating the use of
signals is a good thing.

I've tested Windows and Linux using Windows and Linux guests.  I've also checked
for disk IO performance regressions.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5187 c046a42c-6fe2-441c-8c8c-71466251a162
2008-09-10 15:45:19 +00:00
blueswir1 79383c9c08 Fix some warnings that would be generated by gcc -Wredundant-decls
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5115 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-30 09:51:20 +00:00
aliguori cd01b4a312 Fix windows build
Right now, the Windows build is broken because of NBD.  Using a mingw32 cross
compiler is also badly broken.

This patch fixes the Windows build by stubbing out NBD support until someone
fixes it for Windows.  It also santizing the mingw32 cross compiler support
by replacing the --enable-mingw32 option with a compiler check to determine
if we're on windows or not.

Also remove the weird SDL pseudo-detection for mingw32 using a cross compiler.
The hardcoded sdl-config name is seemly arbitrary.  If you cross compiler SDL
correctly and modify your PATH variable appropriately, it will Just Work when
cross compiling.

The audio driver detection is also broken for cross compiling so you have to
specify the audio drivers explicitly for now.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>




git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5046 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-21 19:25:45 +00:00
ths 75818250ba Allow QEMU to connect directly to an NBD server, by Laurent Vivier.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4838 c046a42c-6fe2-441c-8c8c-71466251a162
2008-07-03 13:41:03 +00:00
ths f58c7b3545 New qemu-img convert -B option, by Marc Bevand.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4672 c046a42c-6fe2-441c-8c8c-71466251a162
2008-06-05 21:53:49 +00:00
aurel32 34c6f05032 unlink the bs from bdrv-list upon bdrv_delete(bs)
(Uri Lublin)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4179 c046a42c-6fe2-441c-8c8c-71466251a162
2008-04-08 19:51:21 +00:00
aurel32 b5eff35546 Revert fix for CVE-2008-0928. Will be fixed in a different way later.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4041 c046a42c-6fe2-441c-8c8c-71466251a162
2008-03-11 23:30:22 +00:00
aurel32 902b27d0b8 Fix CVE-2008-0928 - insufficient block device address range checking
Qemu 0.9.1 and earlier does not perform range checks for block device
read or write requests, which allows guest host users with root
privileges to access arbitrary memory and escape the virtual machine.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4037 c046a42c-6fe2-441c-8c8c-71466251a162
2008-03-11 17:17:59 +00:00
aurel32 0badc1ee0e Honor TMPDIR environment variable
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4033 c046a42c-6fe2-441c-8c8c-71466251a162
2008-03-10 00:05:34 +00:00
ths 985a03b0ce Real SCSI device passthrough (v4), by Laurent Vivier.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3851 c046a42c-6fe2-441c-8c8c-71466251a162
2007-12-24 16:10:43 +00:00
balrog 33f002714b Add "cache" parameter to "-drive" (Laurent Vivier).
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3848 c046a42c-6fe2-441c-8c8c-71466251a162
2007-12-24 14:33:24 +00:00
ths 96b8f136f5 Fix bdrv_get_geometry to return uint64_t, by Andre Przywara.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3825 c046a42c-6fe2-441c-8c8c-71466251a162
2007-12-17 01:35:20 +00:00
ths a36e69ddfe Collecting block device statistics, by Richard W.M. Jones.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3760 c046a42c-6fe2-441c-8c8c-71466251a162
2007-12-02 05:18:19 +00:00
pbrook 9596ebb701 Add statics and missing #includes for prototypes.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3683 c046a42c-6fe2-441c-8c8c-71466251a162
2007-11-18 01:44:38 +00:00
pbrook 87ecb68bdf Break up vl.h.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3674 c046a42c-6fe2-441c-8c8c-71466251a162
2007-11-17 17:14:51 +00:00
pbrook faf07963cb Split block API from vl.h.
Remove QEMU_TOOL. Replace with QEMU_IMG and NEED_CPU_H.
Avoid linking qemu-img against whole system emulatior.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3578 c046a42c-6fe2-441c-8c8c-71466251a162
2007-11-11 02:51:17 +00:00
ths 3b46e62427 find -type f | xargs sed -i 's/[\t ]*$//g' # Yes, again. Note the star in the regex.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3177 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-17 08:09:54 +00:00
ths 5fafdf24ef find -type f | xargs sed -i 's/[\t ]$//g' # on most files
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-16 21:08:06 +00:00
ths 6ada7453aa Parallels disk image support, by Alex Beregszaszi.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3102 c046a42c-6fe2-441c-8c8c-71466251a162
2007-07-31 23:28:53 +00:00
ths eb5c851f2d Use PATH_MAX for name lengths, by Sergey Vlasov.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2419 c046a42c-6fe2-441c-8c8c-71466251a162
2007-02-11 15:06:09 +00:00
ths 71c2fd5cdf Define ENOMEDIUM to match ENODEV if it isn't available.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2357 c046a42c-6fe2-441c-8c8c-71466251a162
2007-01-26 15:37:46 +00:00
ths 7f1c9da998 Darwin build fix, by Pierre d'Herbemont.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2334 c046a42c-6fe2-441c-8c8c-71466251a162
2007-01-18 22:43:16 +00:00
bellard 21664424ed path_is_absolute() fix for win32
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2307 c046a42c-6fe2-441c-8c8c-71466251a162
2007-01-07 18:22:37 +00:00
bellard 3b9f94e1a8 win32 block device fixes (initial patch by kazu)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2305 c046a42c-6fe2-441c-8c8c-71466251a162
2007-01-07 17:27:07 +00:00
ths fef3074347 Escape filname printout properly, by Anthony Liguori and Julian Seward.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2263 c046a42c-6fe2-441c-8c8c-71466251a162
2006-12-22 14:11:32 +00:00
bellard a817d93656 fixed handling of relative filenames with -snapshot
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2136 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-24 19:53:37 +00:00
bellard f45512feac win32 compilation fixes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2134 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-23 21:40:13 +00:00
bellard 6b21b973ab fixed error handling
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2133 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-23 21:14:37 +00:00