* [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier
@ 2015-09-08 3:28 Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 1/2] block: Introduce a new API bdrv_co_no_copy_on_readv() Wen Congyang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Wen Congyang @ 2015-09-08 3:28 UTC (permalink / raw)
To: qemu devel, Paolo Bonzini, Kevin Wolf, Stefan Hajnoczi,
qemu block, Jeff Cody
If we do copy-on-read in before_write_notifier, qemu will be crashed. The
backtrace is:
Program terminated with signal 6, Aborted.
#0 0x00007f5d69207b55 in raise () from /lib64/libc.so.6
(gdb) bt
#0 0x00007f5d69207b55 in raise () from /lib64/libc.so.6
#1 0x00007f5d69209131 in abort () from /lib64/libc.so.6
#2 0x00007f5d69200a10 in __assert_fail () from /lib64/libc.so.6
#3 0x00007f5d6cb3a0d5 in wait_serialising_requests (self=0x7f5d36feeae0) at block/io.c:452
#4 0x00007f5d6cb3ae79 in bdrv_aligned_preadv (bs=0x7f5d6d570170, req=0x7f5d36feeae0, offset=93585408, bytes=65536, align=512, qiov=0x7f5d36feec90, flags=1)
at block/io.c:847
#5 0x00007f5d6cb3b3cc in bdrv_co_do_preadv (bs=0x7f5d6d570170, offset=93585408, bytes=65536, qiov=0x7f5d36feec90, flags=BDRV_REQ_COPY_ON_READ)
at block/io.c:971
#6 0x00007f5d6cb3b497 in bdrv_co_do_readv (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=128, qiov=0x7f5d36feec90, flags=0) at block/io.c:993
#7 0x00007f5d6cb3b504 in bdrv_co_readv (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=128, qiov=0x7f5d36feec90) at block/io.c:1002
#8 0x00007f5d6c8eaf42 in backup_do_cow (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=8, error_is_read=0x0) at block/backup.c:132
#9 0x00007f5d6c8eb6cf in backup_before_write_notify (notifier=0x7f5d435fcf30, opaque=0x7f5d36feee40) at block/backup.c:193
#10 0x00007f5d6cb9ec33 in notifier_with_return_list_notify (list=0x7f5d6d5731f8, data=0x7f5d36feee40) at util/notify.c:65
#11 0x00007f5d6cb3bcc8 in bdrv_aligned_pwritev (bs=0x7f5d6d570170, req=0x7f5d36feee40, offset=93585408, bytes=4096, qiov=0x7f5d6eef4cf8, flags=0)
at block/io.c:1126
#12 0x00007f5d6cb3c79e in bdrv_co_do_pwritev (bs=0x7f5d6d570170, offset=93585408, bytes=4096, qiov=0x7f5d6eef4cf8, flags=0) at block/io.c:1364
#13 0x00007f5d6cb3c867 in bdrv_co_do_writev (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=8, qiov=0x7f5d6eef4cf8, flags=0) at block/io.c:1388
#14 0x00007f5d6cb3ea09 in bdrv_co_do_rw (opaque=0x7f5d38465ee0) at block/io.c:2123
#15 0x00007f5d6caeb03d in coroutine_trampoline (i0=944146112, i1=32605) at coroutine-ucontext.c:80
#16 0x00007f5d69218be0 in __correctly_grouped_prefixwc () from /lib64/libc.so.6
#17 0x0000000000000000 in ?? ()
Wen Congyang (2):
block: Introduce a new API bdrv_co_no_copy_on_readv()
Backup: don't do copy-on-read in before_write_notifier
block/backup.c | 20 ++++++++++++++------
block/io.c | 12 +++++++++++-
include/block/block.h | 9 ++++++---
trace-events | 1 +
4 files changed, 32 insertions(+), 10 deletions(-)
--
2.4.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 1/2] block: Introduce a new API bdrv_co_no_copy_on_readv()
2015-09-08 3:28 [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier Wen Congyang
@ 2015-09-08 3:28 ` Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 2/2] Backup: don't do copy-on-read in before_write_notifier Wen Congyang
2015-09-16 18:27 ` [Qemu-devel] [PATCH v2 0/2] Block: " Jeff Cody
2 siblings, 0 replies; 4+ messages in thread
From: Wen Congyang @ 2015-09-08 3:28 UTC (permalink / raw)
To: qemu devel, Paolo Bonzini, Kevin Wolf, Stefan Hajnoczi,
qemu block, Jeff Cody
In some cases, we need to disable copy-on-read, and just
read the data.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
block/io.c | 12 +++++++++++-
include/block/block.h | 9 ++++++---
trace-events | 1 +
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/block/io.c b/block/io.c
index d4bc83b..94e18e6 100644
--- a/block/io.c
+++ b/block/io.c
@@ -932,7 +932,8 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,
return ret;
}
- if (bs->copy_on_read) {
+ /* Don't do copy-on-read if we read data before write operation */
+ if (bs->copy_on_read && !(flags & BDRV_REQ_NO_COPY_ON_READ)) {
flags |= BDRV_REQ_COPY_ON_READ;
}
@@ -1001,6 +1002,15 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov, 0);
}
+int coroutine_fn bdrv_co_no_copy_on_readv(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
+{
+ trace_bdrv_co_no_copy_on_readv(bs, sector_num, nb_sectors);
+
+ return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov,
+ BDRV_REQ_NO_COPY_ON_READ);
+}
+
int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
{
diff --git a/include/block/block.h b/include/block/block.h
index 608cd4e..c80d95d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -51,15 +51,16 @@ typedef struct BlockFragInfo {
} BlockFragInfo;
typedef enum {
- BDRV_REQ_COPY_ON_READ = 0x1,
- BDRV_REQ_ZERO_WRITE = 0x2,
+ BDRV_REQ_COPY_ON_READ = 0x1,
+ BDRV_REQ_ZERO_WRITE = 0x2,
/* The BDRV_REQ_MAY_UNMAP flag is used to indicate that the block driver
* is allowed to optimize a write zeroes request by unmapping (discarding)
* blocks if it is guaranteed that the result will read back as
* zeroes. The flag is only passed to the driver if the block device is
* opened with BDRV_O_UNMAP.
*/
- BDRV_REQ_MAY_UNMAP = 0x4,
+ BDRV_REQ_MAY_UNMAP = 0x4,
+ BDRV_REQ_NO_COPY_ON_READ = 0x8,
} BdrvRequestFlags;
typedef struct BlockSizes {
@@ -253,6 +254,8 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov);
int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
+int coroutine_fn bdrv_co_no_copy_on_readv(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov);
/*
diff --git a/trace-events b/trace-events
index 0a82f0c..3a7d163 100644
--- a/trace-events
+++ b/trace-events
@@ -69,6 +69,7 @@ bdrv_aio_write_zeroes(void *bs, int64_t sector_num, int nb_sectors, int flags, v
bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d"
bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
bdrv_co_copy_on_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
+bdrv_co_no_copy_on_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_io_em(void *bs, int64_t sector_num, int nb_sectors, int is_write, void *acb) "bs %p sector_num %"PRId64" nb_sectors %d is_write %d acb %p"
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 2/2] Backup: don't do copy-on-read in before_write_notifier
2015-09-08 3:28 [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 1/2] block: Introduce a new API bdrv_co_no_copy_on_readv() Wen Congyang
@ 2015-09-08 3:28 ` Wen Congyang
2015-09-16 18:27 ` [Qemu-devel] [PATCH v2 0/2] Block: " Jeff Cody
2 siblings, 0 replies; 4+ messages in thread
From: Wen Congyang @ 2015-09-08 3:28 UTC (permalink / raw)
To: qemu devel, Paolo Bonzini, Kevin Wolf, Stefan Hajnoczi,
qemu block, Jeff Cody
We will copy data in before_write_notifier to do backup.
It is a nested I/O request, so we cannot do copy-on-read.
The steps to reproduce it:
1. -drive copy-on-read=on,... // qemu option
2. drive_backup -f disk0 /path_to_backup.img // monitor command
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Tested-by: Jeff Cody <jcody@redhat.com>
---
block/backup.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 965654d..5696431 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -89,7 +89,8 @@ static void cow_request_end(CowRequest *req)
static int coroutine_fn backup_do_cow(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
- bool *error_is_read)
+ bool *error_is_read,
+ bool is_write_notifier)
{
BackupBlockJob *job = (BackupBlockJob *)bs->job;
CowRequest cow_request;
@@ -129,8 +130,14 @@ static int coroutine_fn backup_do_cow(BlockDriverState *bs,
iov.iov_len = n * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&bounce_qiov, &iov, 1);
- ret = bdrv_co_readv(bs, start * BACKUP_SECTORS_PER_CLUSTER, n,
- &bounce_qiov);
+ if (is_write_notifier) {
+ ret = bdrv_co_no_copy_on_readv(bs,
+ start * BACKUP_SECTORS_PER_CLUSTER,
+ n, &bounce_qiov);
+ } else {
+ ret = bdrv_co_readv(bs, start * BACKUP_SECTORS_PER_CLUSTER, n,
+ &bounce_qiov);
+ }
if (ret < 0) {
trace_backup_do_cow_read_fail(job, start, ret);
if (error_is_read) {
@@ -190,7 +197,7 @@ static int coroutine_fn backup_before_write_notify(
assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0);
assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
- return backup_do_cow(req->bs, sector_num, nb_sectors, NULL);
+ return backup_do_cow(req->bs, sector_num, nb_sectors, NULL, true);
}
static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
@@ -303,7 +310,8 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
return ret;
}
ret = backup_do_cow(bs, cluster * BACKUP_SECTORS_PER_CLUSTER,
- BACKUP_SECTORS_PER_CLUSTER, &error_is_read);
+ BACKUP_SECTORS_PER_CLUSTER, &error_is_read,
+ false);
if ((ret < 0) &&
backup_error_action(job, error_is_read, -ret) ==
BLOCK_ERROR_ACTION_REPORT) {
@@ -408,7 +416,7 @@ static void coroutine_fn backup_run(void *opaque)
}
/* FULL sync mode we copy the whole drive. */
ret = backup_do_cow(bs, start * BACKUP_SECTORS_PER_CLUSTER,
- BACKUP_SECTORS_PER_CLUSTER, &error_is_read);
+ BACKUP_SECTORS_PER_CLUSTER, &error_is_read, false);
if (ret < 0) {
/* Depending on error action, fail now or retry cluster */
BlockErrorAction action =
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier
2015-09-08 3:28 [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 1/2] block: Introduce a new API bdrv_co_no_copy_on_readv() Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 2/2] Backup: don't do copy-on-read in before_write_notifier Wen Congyang
@ 2015-09-16 18:27 ` Jeff Cody
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-09-16 18:27 UTC (permalink / raw)
To: Wen Congyang
Cc: Kevin Wolf, Paolo Bonzini, qemu block, qemu devel, Stefan Hajnoczi
On Tue, Sep 08, 2015 at 11:28:31AM +0800, Wen Congyang wrote:
> If we do copy-on-read in before_write_notifier, qemu will be crashed. The
> backtrace is:
> Program terminated with signal 6, Aborted.
> #0 0x00007f5d69207b55 in raise () from /lib64/libc.so.6
> (gdb) bt
> #0 0x00007f5d69207b55 in raise () from /lib64/libc.so.6
> #1 0x00007f5d69209131 in abort () from /lib64/libc.so.6
> #2 0x00007f5d69200a10 in __assert_fail () from /lib64/libc.so.6
> #3 0x00007f5d6cb3a0d5 in wait_serialising_requests (self=0x7f5d36feeae0) at block/io.c:452
> #4 0x00007f5d6cb3ae79 in bdrv_aligned_preadv (bs=0x7f5d6d570170, req=0x7f5d36feeae0, offset=93585408, bytes=65536, align=512, qiov=0x7f5d36feec90, flags=1)
> at block/io.c:847
> #5 0x00007f5d6cb3b3cc in bdrv_co_do_preadv (bs=0x7f5d6d570170, offset=93585408, bytes=65536, qiov=0x7f5d36feec90, flags=BDRV_REQ_COPY_ON_READ)
> at block/io.c:971
> #6 0x00007f5d6cb3b497 in bdrv_co_do_readv (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=128, qiov=0x7f5d36feec90, flags=0) at block/io.c:993
> #7 0x00007f5d6cb3b504 in bdrv_co_readv (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=128, qiov=0x7f5d36feec90) at block/io.c:1002
> #8 0x00007f5d6c8eaf42 in backup_do_cow (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=8, error_is_read=0x0) at block/backup.c:132
> #9 0x00007f5d6c8eb6cf in backup_before_write_notify (notifier=0x7f5d435fcf30, opaque=0x7f5d36feee40) at block/backup.c:193
> #10 0x00007f5d6cb9ec33 in notifier_with_return_list_notify (list=0x7f5d6d5731f8, data=0x7f5d36feee40) at util/notify.c:65
> #11 0x00007f5d6cb3bcc8 in bdrv_aligned_pwritev (bs=0x7f5d6d570170, req=0x7f5d36feee40, offset=93585408, bytes=4096, qiov=0x7f5d6eef4cf8, flags=0)
> at block/io.c:1126
> #12 0x00007f5d6cb3c79e in bdrv_co_do_pwritev (bs=0x7f5d6d570170, offset=93585408, bytes=4096, qiov=0x7f5d6eef4cf8, flags=0) at block/io.c:1364
> #13 0x00007f5d6cb3c867 in bdrv_co_do_writev (bs=0x7f5d6d570170, sector_num=182784, nb_sectors=8, qiov=0x7f5d6eef4cf8, flags=0) at block/io.c:1388
> #14 0x00007f5d6cb3ea09 in bdrv_co_do_rw (opaque=0x7f5d38465ee0) at block/io.c:2123
> #15 0x00007f5d6caeb03d in coroutine_trampoline (i0=944146112, i1=32605) at coroutine-ucontext.c:80
> #16 0x00007f5d69218be0 in __correctly_grouped_prefixwc () from /lib64/libc.so.6
> #17 0x0000000000000000 in ?? ()
>
>
> Wen Congyang (2):
> block: Introduce a new API bdrv_co_no_copy_on_readv()
> Backup: don't do copy-on-read in before_write_notifier
>
> block/backup.c | 20 ++++++++++++++------
> block/io.c | 12 +++++++++++-
> include/block/block.h | 9 ++++++---
> trace-events | 1 +
> 4 files changed, 32 insertions(+), 10 deletions(-)
>
> --
> 2.4.3
>
Thanks, applied to my block branch:
git://github.com/codyprime/qemu-kvm-jtc.git block
-Jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-16 18:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-08 3:28 [Qemu-devel] [PATCH v2 0/2] Block: don't do copy-on-read in before_write_notifier Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 1/2] block: Introduce a new API bdrv_co_no_copy_on_readv() Wen Congyang
2015-09-08 3:28 ` [Qemu-devel] [PATCH v2 2/2] Backup: don't do copy-on-read in before_write_notifier Wen Congyang
2015-09-16 18:27 ` [Qemu-devel] [PATCH v2 0/2] Block: " Jeff Cody
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.