From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 09/31] block: Switch bdrv_write_zeroes() to byte interface
Date: Wed, 8 Jun 2016 11:16:35 +0200 [thread overview]
Message-ID: <1465377417-5012-10-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1465377417-5012-1-git-send-email-kwolf@redhat.com>
From: Eric Blake <eblake@redhat.com>
Rename to bdrv_pwrite_zeroes() to let the compiler ensure we
cater to the updated semantics. Do the same for bdrv_co_write_zeroes().
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/blkreplay.c | 4 +++-
block/io.c | 34 +++++++++++++++++++++-------------
block/parallels.c | 4 +++-
block/qcow2-cluster.c | 3 +--
block/qcow2.c | 9 ++++-----
block/raw_bsd.c | 3 ++-
include/block/block.h | 10 +++++-----
migration/block.c | 5 +++--
tests/qemu-iotests/034 | 2 +-
tests/qemu-iotests/154 | 2 +-
trace-events | 2 +-
11 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/block/blkreplay.c b/block/blkreplay.c
index 42f1813..1a721ad 100755
--- a/block/blkreplay.c
+++ b/block/blkreplay.c
@@ -107,7 +107,9 @@ static int coroutine_fn blkreplay_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
{
uint64_t reqid = request_id++;
- int ret = bdrv_co_write_zeroes(bs->file->bs, sector_num, nb_sectors, flags);
+ int ret = bdrv_co_pwrite_zeroes(bs->file->bs,
+ sector_num << BDRV_SECTOR_BITS,
+ nb_sectors << BDRV_SECTOR_BITS, flags);
block_request_create(reqid, bs, qemu_coroutine_self());
qemu_coroutine_yield();
diff --git a/block/io.c b/block/io.c
index 91a2e23..a426094 100644
--- a/block/io.c
+++ b/block/io.c
@@ -620,18 +620,25 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
}
-int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, BdrvRequestFlags flags)
+int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
+ int count, BdrvRequestFlags flags)
{
- return bdrv_rw_co(bs, sector_num, NULL, nb_sectors, true,
- BDRV_REQ_ZERO_WRITE | flags);
+ QEMUIOVector qiov;
+ struct iovec iov = {
+ .iov_base = NULL,
+ .iov_len = count,
+ };
+
+ qemu_iovec_init_external(&qiov, &iov, 1);
+ return bdrv_prwv_co(bs, offset, &qiov, true,
+ BDRV_REQ_ZERO_WRITE | flags);
}
/*
- * Completely zero out a block device with the help of bdrv_write_zeroes.
+ * Completely zero out a block device with the help of bdrv_pwrite_zeroes.
* The operation is sped up by checking the block status and only writing
* zeroes to the device if they currently do not return zeroes. Optional
- * flags are passed through to bdrv_write_zeroes (e.g. BDRV_REQ_MAY_UNMAP,
+ * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP,
* BDRV_REQ_FUA).
*
* Returns < 0 on error, 0 on success. For error codes see bdrv_write().
@@ -662,7 +669,8 @@ int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
sector_num += n;
continue;
}
- ret = bdrv_write_zeroes(bs, sector_num, n, flags);
+ ret = bdrv_pwrite_zeroes(bs, sector_num << BDRV_SECTOR_BITS,
+ n << BDRV_SECTOR_BITS, flags);
if (ret < 0) {
error_report("error writing zeroes at sector %" PRId64 ": %s",
sector_num, strerror(-ret));
@@ -1526,18 +1534,18 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
return bdrv_co_do_writev(bs, sector_num, nb_sectors, qiov, 0);
}
-int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors,
- BdrvRequestFlags flags)
+int coroutine_fn bdrv_co_pwrite_zeroes(BlockDriverState *bs,
+ int64_t offset, int count,
+ BdrvRequestFlags flags)
{
- trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
+ trace_bdrv_co_pwrite_zeroes(bs, offset, count, flags);
if (!(bs->open_flags & BDRV_O_UNMAP)) {
flags &= ~BDRV_REQ_MAY_UNMAP;
}
- return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
- BDRV_REQ_ZERO_WRITE | flags);
+ return bdrv_co_pwritev(bs, offset, count, NULL,
+ BDRV_REQ_ZERO_WRITE | flags);
}
typedef struct BdrvCoGetBlockStatusData {
diff --git a/block/parallels.c b/block/parallels.c
index b9b5c6d..d6a1a61 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -210,7 +210,9 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
int ret;
space += s->prealloc_size;
if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
- ret = bdrv_write_zeroes(bs->file->bs, s->data_end, space, 0);
+ ret = bdrv_pwrite_zeroes(bs->file->bs,
+ s->data_end << BDRV_SECTOR_BITS,
+ space << BDRV_SECTOR_BITS, 0);
} else {
ret = bdrv_truncate(bs->file->bs,
(s->data_end + space) << BDRV_SECTOR_BITS);
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index c737973..b04bfaf 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1765,8 +1765,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
goto fail;
}
- ret = bdrv_write_zeroes(bs->file->bs, offset / BDRV_SECTOR_SIZE,
- s->cluster_sectors, 0);
+ ret = bdrv_pwrite_zeroes(bs->file->bs, offset, s->cluster_size, 0);
if (ret < 0) {
if (!preallocated) {
qcow2_free_clusters(bs, offset, s->cluster_size,
diff --git a/block/qcow2.c b/block/qcow2.c
index a6ea6cb..cc59efc 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2655,8 +2655,8 @@ static int make_completely_empty(BlockDriverState *bs)
/* After this call, neither the in-memory nor the on-disk refcount
* information accurately describe the actual references */
- ret = bdrv_write_zeroes(bs->file->bs, s->l1_table_offset / BDRV_SECTOR_SIZE,
- l1_clusters * s->cluster_sectors, 0);
+ ret = bdrv_pwrite_zeroes(bs->file->bs, s->l1_table_offset,
+ l1_clusters * s->cluster_size, 0);
if (ret < 0) {
goto fail_broken_refcounts;
}
@@ -2669,9 +2669,8 @@ static int make_completely_empty(BlockDriverState *bs)
* overwrite parts of the existing refcount and L1 table, which is not
* an issue because the dirty flag is set, complete data loss is in fact
* desired and partial data loss is consequently fine as well */
- ret = bdrv_write_zeroes(bs->file->bs, s->cluster_size / BDRV_SECTOR_SIZE,
- (2 + l1_clusters) * s->cluster_size /
- BDRV_SECTOR_SIZE, 0);
+ ret = bdrv_pwrite_zeroes(bs->file->bs, s->cluster_size,
+ (2 + l1_clusters) * s->cluster_size, 0);
/* This call (even if it failed overall) may have overwritten on-disk
* refcount structures; in that case, the in-memory refcount information
* will probably differ from the on-disk information which makes the BDS
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 3385ed4..d9adf90 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -131,7 +131,8 @@ static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
BdrvRequestFlags flags)
{
- return bdrv_co_write_zeroes(bs->file->bs, sector_num, nb_sectors, flags);
+ return bdrv_co_pwrite_zeroes(bs->file->bs, sector_num << BDRV_SECTOR_BITS,
+ nb_sectors << BDRV_SECTOR_BITS, flags);
}
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
diff --git a/include/block/block.h b/include/block/block.h
index 3fd5043..54cca28 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -33,7 +33,7 @@ typedef struct BlockDriverInfo {
* True if the driver can optimize writing zeroes by unmapping
* sectors. This is equivalent to the BLKDISCARDZEROES ioctl in Linux
* with the difference that in qemu a discard is allowed to silently
- * fail. Therefore we have to use bdrv_write_zeroes with the
+ * fail. Therefore we have to use bdrv_pwrite_zeroes with the
* BDRV_REQ_MAY_UNMAP flag for an optimized zero write with unmapping.
* After this call the driver has to guarantee that the contents read
* back as zero. It is additionally required that the block device is
@@ -227,8 +227,8 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors);
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
-int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, BdrvRequestFlags flags);
+int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
+ int count, BdrvRequestFlags flags);
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
int bdrv_pread(BlockDriverState *bs, int64_t offset,
void *buf, int count);
@@ -247,8 +247,8 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
* function is not suitable for zeroing the entire image in a single request
* because it may allocate memory for the entire region.
*/
-int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, BdrvRequestFlags flags);
+int coroutine_fn bdrv_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
+ int count, BdrvRequestFlags flags);
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
const char *backing_file);
int bdrv_get_backing_file_depth(BlockDriverState *bs);
diff --git a/migration/block.c b/migration/block.c
index e0628d1..16cc1f8 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -883,8 +883,9 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
}
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
- ret = bdrv_write_zeroes(bs, addr, nr_sectors,
- BDRV_REQ_MAY_UNMAP);
+ ret = bdrv_pwrite_zeroes(bs, addr << BDRV_SECTOR_BITS,
+ nr_sectors << BDRV_SECTOR_BITS,
+ BDRV_REQ_MAY_UNMAP);
} else {
buf = g_malloc(BLOCK_SIZE);
qemu_get_buffer(f, buf, BLOCK_SIZE);
diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034
index c711cfc..1b28bda 100755
--- a/tests/qemu-iotests/034
+++ b/tests/qemu-iotests/034
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Test bdrv_write_zeroes with backing files
+# Test bdrv_pwrite_zeroes with backing files (see also 154)
#
# Copyright (C) 2012 Red Hat, Inc.
#
diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154
index 5905c55..7ca7219 100755
--- a/tests/qemu-iotests/154
+++ b/tests/qemu-iotests/154
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# qcow2 specific bdrv_write_zeroes tests with backing files (complements 034)
+# qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
#
# Copyright (C) 2016 Red Hat, Inc.
#
diff --git a/trace-events b/trace-events
index 5f720d0..cfb1886 100644
--- a/trace-events
+++ b/trace-events
@@ -72,7 +72,7 @@ bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %
bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
-bdrv_co_write_zeroes(void *bs, int64_t sector_num, int nb_sector, int flags) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x"
+bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs %p offset %"PRId64" count %d flags %#x"
bdrv_co_do_copy_on_readv(void *bs, int64_t sector_num, int nb_sectors, int64_t cluster_sector_num, int cluster_nb_sectors) "bs %p sector_num %"PRId64" nb_sectors %d cluster_sector_num %"PRId64" cluster_nb_sectors %d"
# block/stream.c
--
1.8.3.1
next prev parent reply other threads:[~2016-06-08 9:17 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-08 9:16 [Qemu-devel] [PULL 00/31] Block layer patches Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 01/31] block: split write_zeroes always Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 02/31] qcow2: simplify logic in qcow2_co_write_zeroes Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 03/31] qcow2: add tracepoints for qcow2_co_write_zeroes Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 04/31] qemu-iotests: Test one more spot for optimizing write_zeroes Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 05/31] qcow2: Catch more unaligned write_zero into zero cluster Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 06/31] iscsi: Use block size as minimum zero/discard alignment Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 07/31] block: Track write zero limits in bytes Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 08/31] block: Add .bdrv_co_pwrite_zeroes() Kevin Wolf
2016-06-08 9:16 ` Kevin Wolf [this message]
2016-06-08 9:16 ` [Qemu-devel] [PULL 10/31] iscsi: Convert to bdrv_co_pwrite_zeroes() Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 11/31] qcow2: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 12/31] blkreplay: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 13/31] gluster: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 14/31] qed: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 15/31] raw-posix: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 16/31] raw_bsd: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 17/31] vmdk: " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 18/31] block: Kill bdrv_co_write_zeroes() Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 19/31] migration/block: Convert load to BlockBackend Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 20/31] migration/block: Convert saving " Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 21/31] block: assert that bs->request_alignment is a power of 2 Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 22/31] raw-posix: Fetch max sectors for host block device Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 23/31] qcow2: avoid extra flushes in qcow2 Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 24/31] block: Fix bdrv_all_delete_snapshot() error handling Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 25/31] blockdev: clean up error handling in do_open_tray Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 26/31] block: Don't emulate natively supported pwritev flags Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 27/31] qemu-img bench Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 28/31] qemu-img bench: Sequential writes Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 29/31] qemu-img bench: Make start offset configurable Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 30/31] qemu-img bench: Implement -S (step size) Kevin Wolf
2016-06-08 9:16 ` [Qemu-devel] [PULL 31/31] qemu-img bench: Add --flush-interval Kevin Wolf
2016-06-08 17:27 ` [Qemu-devel] [PULL 00/31] Block layer patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465377417-5012-10-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).