[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/42] block/raw-posix: refactor handle_aiocb_write_z
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 05/42] block/raw-posix: refactor handle_aiocb_write_zeroes a bit |
Date: |
Fri, 6 Feb 2015 17:40:12 +0100 |
From: "Denis V. Lunev" <address@hidden>
move code dealing with a block device to a separate function. This will
allow to implement additional processing for ordinary files.
Please note, that xfs_code has been moved before checking for
s->has_write_zeroes as xfs_write_zeroes does not touch this flag inside.
This makes code a bit more consistent.
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
CC: Peter Lieven <address@hidden>
CC: Fam Zheng <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/raw-posix.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 2aa268a..d3910fd 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -914,41 +914,49 @@ static int do_fallocate(int fd, int mode, off_t offset,
off_t len)
}
#endif
-static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb)
+static ssize_t handle_aiocb_write_zeroes_block(RawPosixAIOData *aiocb)
{
- int ret = -EOPNOTSUPP;
+ int ret = -ENOTSUP;
BDRVRawState *s = aiocb->bs->opaque;
- if (s->has_write_zeroes == 0) {
+ if (!s->has_write_zeroes) {
return -ENOTSUP;
}
- if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
#ifdef BLKZEROOUT
- do {
- uint64_t range[2] = { aiocb->aio_offset, aiocb->aio_nbytes };
- if (ioctl(aiocb->aio_fildes, BLKZEROOUT, range) == 0) {
- return 0;
- }
- } while (errno == EINTR);
-
- ret = -errno;
-#endif
- } else {
-#ifdef CONFIG_XFS
- if (s->is_xfs) {
- return xfs_write_zeroes(s, aiocb->aio_offset, aiocb->aio_nbytes);
+ do {
+ uint64_t range[2] = { aiocb->aio_offset, aiocb->aio_nbytes };
+ if (ioctl(aiocb->aio_fildes, BLKZEROOUT, range) == 0) {
+ return 0;
}
+ } while (errno == EINTR);
+
+ ret = translate_err(-errno);
#endif
- }
- ret = translate_err(ret);
if (ret == -ENOTSUP) {
s->has_write_zeroes = false;
}
return ret;
}
+static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb)
+{
+ BDRVRawState *s = aiocb->bs->opaque;
+
+ if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
+ return handle_aiocb_write_zeroes_block(aiocb);
+ }
+
+#ifdef CONFIG_XFS
+ if (s->is_xfs) {
+ return xfs_write_zeroes(s, aiocb->aio_offset, aiocb->aio_nbytes);
+ }
+#endif
+
+ return -ENOTSUP;
+}
+
static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb)
{
int ret = -EOPNOTSUPP;
--
1.8.3.1
- [Qemu-devel] [PULL 00/42] Block patches, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 01/42] Restore atapi_dma flag across migration, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 05/42] block/raw-posix: refactor handle_aiocb_write_zeroes a bit,
Kevin Wolf <=
- [Qemu-devel] [PULL 07/42] block/raw-posix: call plain fallocate in handle_aiocb_write_zeroes, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 03/42] block/raw-posix: create translate_err helper to merge errno values, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 04/42] block/raw-posix: create do_fallocate helper, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 02/42] atapi migration: Throw recoverable error to avoid recovery, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 10/42] qemu-img: Add QEMU_PKGVERSION to QEMU_IMG_VERSION, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 06/42] block: use fallocate(FALLOC_FL_ZERO_RANGE) in handle_aiocb_write_zeroes, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 09/42] block: change default for discard and write zeroes to INT_MAX, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 08/42] block: use fallocate(FALLOC_FL_PUNCH_HOLE) & fallocate(0) to write zeroes, Kevin Wolf, 2015/02/06