History | View | Annotate | Download (50.1 kB)
bdrv: Use "Error" for creating images
Add an Error ** parameter to BlockDriver.bdrv_create to allow morespecific error messages.
Signed-off-by: Max Reitz <mreitz@redhat.com>
bdrv: Use "Error" for opening images
Add an Error ** parameter to BlockDriver.bdrv_open andBlockDriver.bdrv_file_open to allow more specific error messages.
block: introduce bdrv_get_block_status API
For now, bdrv_get_block_status is just another name for bdrv_is_allocated.The next patches will add more flags.
This also touches all block drivers with a mostly mechanical rename. Thesole exception is cow; because it calls cow_co_is_allocated from the read...
raw-posix: return get_block_status data and flags
Reviewed-by: Eric Blake <eblake@redhat.com>Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
raw-posix: report unwritten extents as zero
These are created for example with XFS_IOC_ZERO_RANGE.
block: change default of .has_zero_init to 0
.has_zero_init defaults to 1 for all formats and protocols.
this is a dangerous default since this means that allnew added drivers need to manually overwrite it to 0 ifthey do not ensure that a device is zero initialized...
raw-posix: Fix /dev/cdrom magic on OS X
The raw-posix driver has code to provide a /dev/cdrom on OS X eventhough it doesn't really exist. However, since commit c66a6157 the realfilename is dismissed after finding it, so opening /dev/cdrom fails.Put the filename back into the options QDict to make this work again....
block: Remove filename parameter from .bdrv_file_open()
It is unused now in all block drivers.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Reviewed-by: Eric Blake <eblake@redhat.com>
raw-posix: Use bdrv_open options instead of filename
block: Add options QDict to bdrv_file_open() prototypes
The new parameter is unused yet.
threadpool: drop global thread pool
Now that each AioContext has a ThreadPool and the main loop AioContextcan be fetched with bdrv_get_aio_context(), we can eliminate the conceptof a global thread pool from thread-pool.c.
The submit functions must take a ThreadPool* argument....
block/raw-posix: detect readonly Linux block devices using BLKROGET
Linux block devices can be set read-only with "blockdev --setro<device>". The same thing can be done for LVM volumes using "lvchange--permission r <volume>". This read-only setting is independent of...
block/raw-posix: Build fix for O_ASYNC
Commit eeb6b45d48800e96f67ef2a5c80332557fd45ddb (block: raw-posix imagefile reopen) broke the build on OpenIndiana.
illumos has no O_ASYNC. Exclude it from flags to be comparedand instead assert that it is not set where defined....
block/raw-posix: Make hdev_aio_discard() available outside Linux
Fixes the build on OpenBSD among others.
Suggested-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Andreas Färber <andreas.faerber@web.de>Cc: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
raw-posix: support discard on more filesystems
Linux 2.6.38 introduced the filesystem independent interface todeallocate part of a file. As of Linux 3.7, btrfs, ext4, ocfs2,tmpfs and xfs support it.
Even though the system calls here are in practice issued on Linux,...
raw-posix: remember whether discard failed
Avoid sending system calls repeatedly if they shall fail. Thisdoes not apply to XFS: if the filesystem-specific ioctl fails,something weird is happening.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
raw: support discard on block devices
Block devices use a ioctl instead of fallocate, so add a separateimplementation.
block: make discard asynchronous
This is easy with the thread pool, because we can use s->is_xfs ands->has_discard from the worker function.
QEMU has a widespread assumption that each I/O operation writes lessthan 2^32 bytes. This patch doesn't fix it throughout of course,...
raw-posix: fix bdrv_aio_ioctl
When the raw-posix aio=thread code was moved from posix-aio-compat.cto block/raw-posix.c, there was an unintended change to the ioctl code.The code used to return the ioctl command, which posix_aio_read()would later morph into a zero. This hack is not necessary anymore,...
block: make qiov_is_aligned() public
The qiov_is_aligned() function checks whether a QEMUIOVector meets aBlockDriverState's alignment requirements. This is needed byvirtio-blk-data-plane so:
1. Move the function from block/raw-posix.c to block/block.c....
raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane
The raw_get_aio_fd() function allows virtio-blk-data-plane to get thefile descriptor of a raw image file with Linux AIO enabled. Thisinterface is really a layering violation that can be resolved once the...
misc: move include files to include/qemu/
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: move include files to include/block/
janitor: do not include qemu-char everywhere
Touching char/char.h basically causes the whole of QEMU tobe rebuilt. Avoid this, it is usually unnecessary.
raw-posix: inline paio_ioctl into hdev_aio_ioctl
clang now warns about an unused function: CC block/raw-posix.oblock/raw-posix.c:707:26: warning: unused function paio_ioctl[-Wunused-function]static BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,...
block: add bdrv_reopen() support for raw hdev, floppy, and cdrom
For hdev, floppy, and cdrom, the reopen() handlers are the same asfor the file reopen handler. For floppy and cdrom types, however,we keep O_NONBLOCK, as in the _open function.
Signed-off-by: Jeff Cody <jcody@redhat.com>...
block: switch posix-aio-compat to threadpool
This is not meant for portability, but to remove code duplication.
raw: merge posix-aio-compat.c into block/raw-posix.c
Making the qemu_paiocb specific to raw devices will let us access membersof the BDRVRawState arbitrarily.
raw-posix: rename raw-posix-aio.h, hide unavailable prototypes
block: purge s->aligned_buf and s->aligned_buf_size from raw-posix.c
The aligned_buf pointer and aligned_buf size are no longer used inraw_posix.c, so remove all references to them.
Signed-off-by: Jeff Cody <jcody@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: raw-posix image file reopen
This is derived from the Supriya Kannery's reopen patches.
This contains the raw-posix driver changes for the bdrv_reopen_*functions. All changes are staged into a temporary scratch bufferduring the prepare() stage, and copied over to the live structure...
block: move aio initialization into a helper function
Move AIO initialization for raw-posix block driver into a helper function.
In addition to just code motion, the aio_ctx pointer is checked for NULL,prior to calling laio_init(), to make sure laio_init() is only run once....
block: move open flag parsing in raw block drivers to helper functions
Code motion, to move parsing of open flags into a helper function.
block: do not parse BDRV_O_CACHE_WB in block drivers
Block drivers should ignore BDRV_O_CACHE_WB in .bdrv_open flags,and in the bs->open_flags.
This patch removes the code, leaving the behaviour behind as ifBDRV_O_CACHE_WB was set.
block: use BDRV_O_NOCACHE instead of s->aligned_buf in raw-posix.c
Rather than check for a non-NULL aligned_buf to determine ifraw_aio_submit needs to check for alignment, check for the presenceof BDRV_O_NOCACHE in the bs->open_flags.
block: Prevent detection of /dev/fdset/ as floppy
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Convert open calls to qemu_open
This patch converts all block layer open calls to qemu_open.
Note that this adds the O_CLOEXEC flag to the changed open pathswhen the O_CLOEXEC macro is defined.
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>...
block: Convert close calls to qemu_close
This patch converts all block layer close calls, that correspondto qemu_open calls, to qemu_close.
raw-posix: Fix build without is_allocated support
Move the declaration of s into the #ifdef sections that actually makeuse of it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Alexander Graf <agraf@suse.de>
block: implement is_allocated for raw
Either FIEMAP, or SEEK_DATA+SEEK_HOLE can be used to implement theis_allocated callback for raw files. On Linux ext4, btrfs and XFSall support it.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
raw-posix: Do not use CONFIG_COCOA macro
Use APPLE and MACH macros instead of CONFIG_COCOA to detect MacOS X host. The patch is based on Ben Leslie's patch:http://patchwork.ozlabs.org/patch/97859/
Signed-off-by: Ben Leslie <benno@benno.id.au>Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>...
block: bdrv_eject(): Make eject_flag a real bool
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>Reviewed-by: Markus Armbruster <armbru@redhat.com>Acked-by: Kevin Wolf <kwolf@redhat.com>
fix spelling in block sub directory
Cc: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
block: change discard to co_discard
Since coroutine operation is now mandatory, convert both bdrv_discardimplementations to coroutines. For qcow2, this means taking the lockaround the operation. raw-posix remains synchronous.
The bdrv_discard callback is then unused and can be eliminated....
block: drop redundant bdrv_flush implementation
Block drivers now only need to provide either of .bdrv_co_flush,.bdrv_aio_flush() or for legacy drivers .bdrv_flush(). Removethe redundant .bdrv_flush() implementations.
[Paolo Bonzini: change raw driver to bdrv_co_flush]...
raw-posix: remove bdrv_read()/bdrv_write()
Block drivers only need to provide one of sync, aio, or coroutineinterfaces. Since raw-posix.c provides aio interfaces, simply drop thesynchronous interfaces since they can be emulated using aio andcoroutines....
block: allow resizing of images residing on host devices
Allow to resize images that reside on host devices up to the availablespace. This allows to grow images after resizing the device manually orvice versa.
Signed-off-by: Christoph Hellwig <hch@lst.de>...
raw-posix: Fix bdrv_flush error return values
bdrv_flush is supposed to use 0/-errno return values
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Rename bdrv_set_locked() to bdrv_lock_medium()
While there, make the locked parameter bool.
Signed-off-by: Markus Armbruster <armbru@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
linux aio: some comments
Add some notes about Linux AIO explaining why we don't use AIO insome situations.
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
raw-posix: Typo fix
raw-posix: Always check paio_init result
block: Make BlockDriver method bdrv_set_locked() return void
The only caller is bdrv_set_locked(), and it ignores the value.
Callees always return 0, except for FreeBSD's cdrom_set_locked(),which returns -ENOTSUP when the device is in a terminally wedged...
block: Make BlockDriver method bdrv_eject() return void
Callees always return 0, except for FreeBSD's cdrom_eject(), whichreturns -ENOTSUP when the device is in a terminally wedged state.
The only caller is bdrv_eject(), and it maps -ENOTSUP to 0 since...
block: add bdrv_get_allocated_file_size() operation
qemu-img.c wants to count allocated file size of image. Previously itcounts a single bs->file by 'stat' or Window API. As VMDK introducesmultiple file support, the operation becomes format specific with...
block/raw-posix: Linux compat-ioctl warning workaround
On Linux x86_64 host with 32bit userspace, runningqemu or even just "qemu-img create -f qcow2 some.img 1G" causes a kernel warning:
ioctl32(qemu-img:5296): Unknown cmd fd(3) cmd(00005326){t:'S';sz:0} arg(7fffffff) on some.img...
Merge remote-tracking branch 'stefanha/trivial-patches' into staging
block/raw-posix: get right partition size
use the correct way to get the size of a disk device or partition
From: Adam Hamsik <haad@netbsd.org>Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: clarify the meaning of BDRV_O_NOCACHE
Change BDRV_O_NOCACHE to only imply bypassing the host OS file cache,but no writeback semantics. All existing callers are changed to alsospecify BDRV_O_CACHE_WB to give them writeback semantics.
block/raw-posix: use a character device if a block device is given
On NetBSD a userland process is better with the character deviceinterface. In addition, a block device can't be opened twice; if a Xenbackend opens it, qemu can't and vice-versa.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>...
Fix compilation warning due to missing header for sigaction (followup)
This patch removes all references to signal.h when qemu-common.h is includedas they become redundant.
Signed-off-by: Alexandre Raymond <cerbere@gmail.com>Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
raw-posix: add discard support
Add support to discard blocks in a raw image residing on an XFS filesystemby calling the XFS_IOC_UNRESVSP64 ioctl to punch holes. Support for otherhole punching mechanisms can be added when they become available.
raw-posix: raw_pwrite comment fixup
Signed-off-by: Christoph Hellwig <hch@lst.de>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block: Allow bdrv_flush to return errors
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>
qemu-timer: move commonly used timer code to qemu-timer-common
Move timer init functions to a new file, qemu-timer-common.c. Make othercritical timer functions inlined to preserve performance inqemu-timer.c, also move muldiv64() (used by the inline functions)...
raw-posix: handle > 512 byte alignment correctly
Replace the hardcoded handling of 512 byte alignment with bs->buffer_alignmentto handle larger sector size devices correctly.
Note that we can not rely on it to be initialize in bdrv_open, so dealwith the worst case there....
raw-posix: improve detection of scsi-generic devices
Allow symbolic links which point to /dev/sgX devices.
Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
raw-posix: Don't use file name for host_cdrom detection on Linux
On Linux, we have code to detect CD-ROMs using an ioctl. We shouldn't loseanything but false positives by removing the check for a /dev/cd* path.
block: Fix bdrv_has_zero_init
Assuming that any image on a block device is not properly zero-initialized isactually wrong: Only raw images have this problem. Any other image formatshouldn't care about it, they initialize everything properly themselves....
block: Replace u_int8_t, u_int16_t, u_int32_t, u_int64_t by standard int types
There is no need to have a second set of integral types.Replace them by the standard types from stdint.h.
Signed-off-by: Stefan Weil <weil@mail.berlios.de>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
raw-posix: Fix test for host CD-ROM
raw_pread_aligned() retries up to two times if the block device backsa virtual CD-ROM (a drive with media=cdrom and if=ide, scsi, xen ornone). This makes no sense. Whether retrying reads can correct readerrors can only depend on what we're reading, not on how the result...
Cleanup: raw-posix.c: Be more consistent using BDRV_SECTOR_SIZE instead of 512
Clean up raw-posix.c to be more consistent using BDRV_SECTOR_SIZEinstead of hard coded 512 values.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>Signed-off-by: Kevin Wolf <kwolf@redhat.com>
raw-posix: Use pread/pwrite instead of lseek+read/write
This patch combines the lseek+read/write calls to use pread/pwriteinstead. This will result in fewer system calls and is already used byAIO.
Thanks to Jan Kiszka <jan.kiszka@siemens.com> for identifying excessive...
block: separate raw images from the file protocol
We're running into various problems because the "raw" file access, whichis used internally by the various image formats is entangled with the"raw" image format, which maps the VM view 1:1 to a file system....
block: Open the underlying image file in generic code
Format drivers shouldn't need to bother with things like file names, but ratherjust get an open BlockDriverState for the underlying protocol. This patchintroduces this behaviour for bdrv_open implementation. For protocols which...
block: split raw_getlength
Split up the raw_getlength into separate generic, solaris and BSDversions to reduce the ifdef maze a bit. The BSD variant stillis a complete maze, but to clean it up properly we'd need somepeople using the BSD variants to figure out what code is used...
raw-posix: don't assign bs->read_only
bdrv_open already takes care of this for us.
Signed-off-by: Christoph Hellwig <hch@lst.de>Acked-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
raw-posix: Better error return values for hdev_create
Now that we output an error message according to the returned error code inqemu-img, let's return the real error codes. "Input/output error" foreverything isn't helpful.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>...
block/raw-posix: Abort on pread beyond end of non-growable file
This shouldn't happen under any normal circumstances. However, it looks likeit's possible to achieve this with corrupted images. Without this patchraw_pread is hanging in an endless loop in such cases....
win32: pair qemu_memalign() with qemu_vfree()
Win32 suffers from a very big memory leak when dealing with SCSI devices.Each read/write request allocates memory with qemu_memalign (ieVirtualAlloc) but frees it with qemu_free (ie free).Pair all qemu_memalign() calls with qemu_vfree() to prevent such leaks....
block: kill BDRV_O_CREAT
The BDRV_O_CREAT option is unused inside qemu and partially duplicatesthe bdrv_create method. Remove it, and the -C option to qemu-io whichisn't used in qemu-iotests anyway.
Signed-off-by: Christoph Hellwig <hch@lst.de>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Clean-up a little bit the RW related bits of BDRV_O_FLAGS. BDRV_O_RDONLY gone (and so is BDRV_O_ACCESS). Default value for bdrv_flags (0/zero) is READ-ONLY. Need to explicitly request READ-WRITE.
Instead of using the field 'readonly' of the BlockDriverState struct for passing the request,...
raw-posix: Detect CDROM via ioctl on linux
Current CDROM detection is hardcoded based on source file name.Make this smarter on linux by attempting a CDROM specific ioctl.
This makes '-cdrom /dev/sr0' succeed with no media present.
v2: Give ioctl check higher priority than filename check....
raw-posix: Detect legacy floppy via ioctl on linux
Current legacy floppy detection is hardcoded based on source filename. Make this smarter on linux by attempting a floppy specificioctl.
v2: Give ioctl check higher priority than filename check s/IDE/legacy/...
qemu-img: There is more than one host device driver
I haven't heard yet of anyone using qemu-img to copy an image to a real floppy,but it's a valid use case.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Don't leak file descriptors
We're leaking file descriptors to child processes. Set FD_CLOEXEC on filedescriptors that don't need to be passed to children to stop this misbehaviour.
Add support for GNU/kFreeBSD
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Remove aio_ctx from paio_* interface
The context parameter in paio_submit isn't used anyway, so there is no reasonwhy block drivers should need to remember it. This also avoids passing a LinuxAIO context to paio_submit (which doesn't do any harm as long as the parameter...
raw/linux-aio: Also initialize POSIX AIO
When using Linux AIO raw still falls back to POSIX AIO sometimes, so we shouldinitialize it.
Not initializing it happens to work if POSIX AIO is used by another drive, orif the format is not specified (probing the format uses POSIX AIO) or by pure...
block/raw: Add create_options for host_device
Today host_devices have a create function, so they also need a create_optionsfield to prevent qemu-img from complaining.
block: use fdatasync instead of fsync if possible
If we are flushing the caches for our image files we only care about thedata (including the metadata required for accessing it) but not thingslike timestamp updates. So try to use fdatasync instead of fsync to...
block: add aio_flush operation
Instead stalling the VCPU while serving a cache flush try to do itasynchronously. Use our good old helper thread pool to issue anasynchronous fdatasync for raw-posix. Note that while Linux AIOimplements a fdatasync operation it is not useful for us because...
Don't compile aio code if CONFIG_LINUX_AIO is undefined
This patch fixes linker errors when building QEMU without Linux AIO support.
It is based on suggestions from malc and Kevin Wolf.
Signed-off-by: Stefan Weil <weil@mail.berlios.de>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
raw-posix: refactor AIO support
Currently the raw-posix.c code contains a lot of knowledge about theasynchronous I/O scheme that is mostly implemented in posix-aio-compat.c.All this code does not really belong here and is getting a bit in theway of implementing native AIO on Linux....
raw-posix: add Linux native AIO support
Now that do have a nicer interface to work against we can add Linux nativeAIO support. It's an extremly thing layer just setting up an iocb forthe io_submit system call in the submission path, and registering an...
make pthreads mandatory
As requested by Anthony make pthreads mandatory. This means we will alwayshave AIO available on posix hosts, and it will also allow enabling the I/Othread unconditionally once it's ready.
rename HOST_BSD to CONFIG_BSD
Signed-off-by: Juan Quintela <quintela@redhat.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Fix most warnings (errors with -Werror) when debugging is enabled
I used the following command to enable debugging:perl -p -i -e 's/^\/\/#define DEBUG/#define DEBUG/g' * /* *//*
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
raw-posix: Handle errors in raw_create
In qemu-iotests, some large images are created using qemu-img.
Without checks for errors, qemu-img will just create anempty image, and later read / write tests will fail.
With the patch, failures during image creation are detected...
Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>