summaryrefslogtreecommitdiff
path: root/block/raw-posix.c
AgeCommit message (Collapse)AuthorFilesLines
2010-01-19raw-posix: Detect legacy floppy via ioctl on linuxCole Robinson1-2/+19
Current legacy floppy detection is hardcoded based on source file name. Make this smarter on linux by attempting a floppy specific ioctl. v2: Give ioctl check higher priority than filename check s/IDE/legacy/ v3: Actually initialize 'prio' variable Check for ioctl success rather than absence of specific failure v4: Explicitly mention that change is linux specific. Signed-off-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19raw-posix: Detect CDROM via ioctl on linuxCole Robinson1-2/+18
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. v3: Actually initialize 'prio' variable. Check for ioctl success rather than absence of specific failure. v4: Explicitly mention that change is linux specific. Signed-off-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03Don't leak file descriptorsKevin Wolf1-1/+1
We're leaking file descriptors to child processes. Set FD_CLOEXEC on file descriptors that don't need to be passed to children to stop this misbehaviour. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03qemu-img: There is more than one host device driverKevin Wolf1-0/+4
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>
2009-11-29Add support for GNU/kFreeBSDAurelien Jarno1-8/+8
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-10-30Remove aio_ctx from paio_* interfaceKevin Wolf1-6/+4
The context parameter in paio_submit isn't used anyway, so there is no reason why block drivers should need to remember it. This also avoids passing a Linux AIO context to paio_submit (which doesn't do any harm as long as the parameter is unused, but it is highly confusing). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-27raw/linux-aio: Also initialize POSIX AIOKevin Wolf1-0/+4
When using Linux AIO raw still falls back to POSIX AIO sometimes, so we should initialize it. Not initializing it happens to work if POSIX AIO is used by another drive, or if the format is not specified (probing the format uses POSIX AIO) or by pure luck (e.g. it doesn't seem to happen any more with qcow2 since we have re-added synchronous qcow2 functions). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05block/raw: Add create_options for host_deviceKevin Wolf1-6/+10
Today host_devices have a create function, so they also need a create_options field to prevent qemu-img from complaining. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-11block: add aio_flush operationChristoph Hellwig1-0/+17
Instead stalling the VCPU while serving a cache flush try to do it asynchronously. Use our good old helper thread pool to issue an asynchronous fdatasync for raw-posix. Note that while Linux AIO implements a fdatasync operation it is not useful for us because it isn't actually implement in asynchronous fashion. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-11block: use fdatasync instead of fsync if possibleChristoph Hellwig1-1/+1
If we are flushing the caches for our image files we only care about the data (including the metadata required for accessing it) but not things like timestamp updates. So try to use fdatasync instead of fsync to implement the flush operations. Unfortunately many operating systems still do not support fdatasync, so we add a qemu_fdatasync wrapper that uses fdatasync if available as per the _POSIX_SYNCHRONIZED_IO feature macro or fsync otherwise. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-28Don't compile aio code if CONFIG_LINUX_AIO is undefinedStefan Weil1-1/+7
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>
2009-08-27raw-posix: add Linux native AIO supportChristoph Hellwig1-5/+25
Now that do have a nicer interface to work against we can add Linux native AIO support. It's an extremly thing layer just setting up an iocb for the io_submit system call in the submission path, and registering an eventfd with the qemu poll handler to do complete the iocbs directly from there. This started out based on Anthony's earlier AIO patch, but after estimated 42,000 rewrites and just as many build system changes there's not much left of it. To enable native kernel aio use the aio=native sub-command on the drive command line. I have also added an option to qemu-io to test the aio support without needing a guest. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-27raw-posix: refactor AIO supportChristoph Hellwig1-236/+39
Currently the raw-posix.c code contains a lot of knowledge about the asynchronous 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 the way of implementing native AIO on Linux. So instead move all the guts of the AIO implementation into posix-aio-compat.c (which might need a better name, btw). There's now a very small interface between the AIO providers and raw-posix.c: - an init routine is called from raw_open_common to return an AIO context for this drive. An AIO implementation may either re-use one context for all drives, or use a different one for each as the Linux native AIO support will do. - an submit routine is called from the aio_reav/writev methods to submit an AIO request There are no indirect calls involved in this interface as we need to decide which one to call manually. We will only call the Linux AIO native init function if we were requested to by vl.c, and we will only call the native submit function if we are asked to and the request is properly aligned. That's also the reason why the alignment check actually does the inverse move and now goes into raw-posix.c. The old posix-aio-compat.h headers is removed now that most of it's content is private to posix-aio-compat.c, and instead we add a new block/raw-posix-aio.h headers is created containing only the tiny interface between raw-posix.c and the AIO implementation. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-24make pthreads mandatoryChristoph Hellwig1-27/+1
As requested by Anthony make pthreads mandatory. This means we will always have AIO available on posix hosts, and it will also allow enabling the I/O thread unconditionally once it's ready. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27rename HOST_BSD to CONFIG_BSDJuan Quintela1-2/+2
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-20Fix most warnings (errors with -Werror) when debugging is enabledBlue Swirl1-0/+1
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>
2009-07-16raw-posix: Handle errors in raw_createStefan Weil1-5/+12
In qemu-iotests, some large images are created using qemu-img. Without checks for errors, qemu-img will just create an empty image, and later read / write tests will fail. With the patch, failures during image creation are detected and reported. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-09Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.G 31-0/+4
Signed-off-by: John Arbuckle <programmingkidx@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-09Revert "support colon in filenames"Anthony Liguori1-1/+0
This reverts commit 707c0dbc97cddfe8d2441b8259c6c526d99f2dd8. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-29block-raw: Allow pread beyond the end of growable imagesKevin Wolf1-0/+11
When using O_DIRECT, qcow2 snapshots didn't work any more for me. In the process of creating the snapshot, qcow2 tries to pwrite some new information (e.g. new L1 table) which will often end up being after the old end of the image file. Now pwrite tries to align things and reads the old contents of the file, read returns 0 because there is nothing to read after the end of file and pwrite is stuck in an endless loop. This patch allows to pread beyond the end of an image file. Whenever the given offset is after the end of the image file, the read succeeds and fills the buffer with zeros. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-29support colon in filenamesRam Pai1-0/+1
Problem: It is impossible to feed filenames with the character colon because qemu interprets such names as a protocol. For example filename scsi:0, is interpreted as a protocol by name "scsi". This patch allows user to espace colon characters. For example the above filename can now be expressed either as 'scsi\:0' or as file:scsi:0 anything following the "file:" tag is interpreted verbatin. However if "file:" tag is omitted then any colon characters in the string must be escaped using backslash. Here are couple of examples: scsi\:0\:abc is a local file scsi:0:abc http\://myweb is a local file by name http://myweb file:scsi:0:abc is a local file scsi:0:abc file:http://myweb is a local file by name http://myweb Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-17Fix opening of read only raw imagesBlue Swirl1-16/+15
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-06-16raw-posix: Remove O_RDWR when attempting to open a file read-onlyAvi Kivity1-0/+1
When we open a file, we first attempt to open it read-write, then fall back to read-only. Unfortunately we reuse the flags from the previous attempt, so both attempts try to open the file with write permissions, and fail. Fix by clearing the O_RDWR flag from the previous attempt. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-16raw-posix: open flags use BDRV_ namespace, not posix namespaceAvi Kivity1-1/+1
The flags argument to raw_common_open() contain bits defined by the BDRV_O_* namespace, not the posix O_* namespace. Adjust to use the correct constants. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-06-15raw-posix: cleanup ioctl methodsChristoph Hellwig1-34/+8
Rename raw_ioctl and raw_aio_ioctl to hdev_ioctl and hdev_aio_ioctl as they are only used for the host device. Also only add them to the method table for the cases where we need them (generic hdev if linux and linux CDROM) instead of declaring stubs and always add them. Signed-off-by: Christoph Hellwig <hch@lst.de>
2009-06-15block: add bdrv_probe_device methodChristoph Hellwig1-0/+47
Add a bdrv_probe_device method to all BlockDriver instances implementing host devices to move matching of host device types into the actual drivers. For now we keep exacly the old matching behaviour based on the devices names, although we really should have better detetion methods based on device information in the future. Signed-off-by: Christoph Hellwig <hch@lst.de>
2009-06-15raw-posix: split hdev driversChristoph Hellwig1-260/+304
Instead of declaring one BlockDriver for all host devices declared one for each type: a generic one for normal disk devices, a Linux floppy driver and a CDROM driver for Linux and FreeBSD. This gets rid of a lot of messy ifdefs and switching based on the type in the various removal device methods. block.c grows a new method to find the correct host device driver based on OS-sepcific criteria, which will later into the actual drivers in a later patch in this series. Signed-off-by: Christoph Hellwig <hch@lst.de>
2009-06-15raw-posix: add a raw_open_common helperChristoph Hellwig1-29/+19
raw_open and hdev_open contain the same basic logic. Add a new raw_open_common helper containing the guts of the open routine and call it from raw_open and hdev_open. We use the new open_flags field in BDRVRawState to allow passing additional open flags to raw_open_common from both. Signed-off-by: Christoph Hellwig <hch@lst.de>
2009-06-15raw-posix: always store open flagsChristoph Hellwig1-26/+21
Both the Linux floppy and the FreeBSD CDROM host device need to store the open flags so that they can re-open the device later. Store the open flags unconditionally to remove the ifdef mess and simply the calling conventions for the later patches in the series. Signed-off-by: Christoph Hellwig <hch@lst.de>
2009-06-06qemu-img: Print available options with -o ?Kevin Wolf1-1/+5
This patch adds a small help text to each of the options in the block drivers which can be displayed by using qemu-img create -f fmt -o ? Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2009-05-27fully split aio_pool from BlockDriverChristoph Hellwig1-40/+41
Now that we have a separate aio pool structure we can remove those aio pool details from BlockDriver. Every driver supporting AIO now needs to declare a static AIOPool with the aiocb size and the cancellation method. This cleans up the current code considerably and will make it cleaner and more obvious to support two different aio implementations behind a single BlockDriver. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-27raw-posix: fix hdev_createChristoph Hellwig1-10/+1
We do need hdev_create unconditionally on all platforms so that qemu-img create support for host device works on all platforms. Also relax the check to allow character devices in addition to block devices. On many Unix platforms block devices have buffered block nodes and unbuffered character device nodes, and on FreeBSD the block nodes don't even exist anymore. Also on Linux we do support the /dev/sgN scsi passthrough devices through the host device driver, and probably the old-style /dev/raw/rawN raw devices although I haven't tested that. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-27fix raw_pread_aligned return valueChristoph Hellwig1-1/+1
raw_pread_aligned currently returns the raw return value from lseek/read, which is always -1 in case of an error. But the callers higher up the stack expect it to return the negated errno just like raw_pwrite_aligned. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22Convert all block drivers to new bdrv_createKevin Wolf1-10/+27
Now we can make use of the newly introduced option structures. Instead of having bdrv_create carry more and more parameters (which are format specific in most cases), just pass a option structure as defined by the driver itself. bdrv_create2() contains an emulation of the old interface to simplify the transition. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-14Move block drivers into their own directoryAnthony Liguori1-0/+1438
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>