Block patches for 1.1
The following changes since commit 1b3e76ebd1e270eae27e502ea8b836c31d95f801:
tcg/ppc: Fix CONFIG_TCG_PASS_AREG0 mode (2012-05-09 13:59:19 -0500)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony
Kevin Wolf (3):
qtest: Add function to send QMP commands
qtest: Add floppy test
tests/Makefile: Add missing $(EXESUF)
Paolo Bonzini (26):
block: add mode argument to blockdev-snapshot-sync
block: fail live snapshot if disk has no medium
block: push bdrv_change_backing_file error checking up from drivers
block: update in-memory backing file and format
block: open backing file as read-only when probing for size
block: fix allocation size for dirty bitmap
qemu-iotests: strip spaces from qemu-img/qemu-io/qemu command lines
block: fix snapshot on QED
block: another bdrv_append fix
block: do not reuse the backing file across bdrv_close/bdrv_open
block: fully delete bs->file when closing
block: add block_job_sleep_ns
block: wait for job callback in block_job_cancel_sync
block: simplify path_is_absolute
block: protect path_has_protocol from filenames with colons
block: move field reset from bdrv_open_common to bdrv_close
qemu-img: make "info" backing file output correct and easier to use
qemu-io: correctly print non-integer values as decimals
qemu-io: fix the alloc command
stream: fix sectors not allocated test
stream: add testcase for partial streaming
stream: pass new base image format to bdrv_change_backing_file
stream: fix HMP block_job_set_speed
stream: fix ratelimiting corner case
stream: do not copy unallocated sectors from the base declare ECANCELED on all machines
Zhi Yong Wu (1):
block: add the support to drain throttled requests
block.c | 176 ++- block.h | 2 + block/qcow2.c | 5 - block/qed.c | 7 + block/stream.c | 76 +- block/vvfat.c | 7 + block_int.h | 34 +- blockdev.c | 9 +- cmd.c | 40 +- hmp.c | 2 +- qemu-common.h | 3 + qemu-img.c | 12 +- qemu-io.c | 10 +- qmp-commands.hx | 2 +- tests/Makefile | 4 +- tests/fdc-test.c | 195 +++ tests/libqtest.c | 123 ++- tests/libqtest.h | 17 + tests/qemu-iotests/002.out | 4 +- tests/qemu-iotests/012.out | 2 +- tests/qemu-iotests/016.out | 12 +- tests/qemu-iotests/017.out | 1024 ++++++++-------- tests/qemu-iotests/018.out | 1024 ++++++++-------- tests/qemu-iotests/019.out | 1536 +++++++++++----------- tests/qemu-iotests/020.out | 1024 ++++++++-------- tests/qemu-iotests/023.out | 2880 ++++++++++++++++++++-------------------- tests/qemu-iotests/027.out | 2 +- tests/qemu-iotests/028.out | 448 ++++---- tests/qemu-iotests/030 | 34 +- tests/qemu-iotests/030.out | 4 +- tests/qemu-iotests/033.out | 6 +- tests/qemu-iotests/035.out | 384 +++--- tests/qemu-iotests/iotests.py | 16 +- 33 files changed, 4777 insertions(+), 4347 deletions(-) create mode 100644 tests/fdc-test.c
PATCH 1/30 block: add the support to drain throttled requests
From: Zhi Yong Wu <[email protected]>
[ Iterate until all block devices have processed all requests,
add comments. - Paolo ]
--- block.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
block.c +20 -1
@@ -906,12 +906,31 @@ void bdrv_close_all(void)* * This function does not flush data to disk, use bdrv_flush_all() for that * after calling this function. +* +* Note that completion of an asynchronous I/O operation can trigger any +* number of other I/O operations on other devices---for example a coroutine +* can be arbitrarily complex and a constant flow of I/O can come until the +* coroutine is complete. Because of this, it is not possible to have a +* function to drain a single device's I/O queue. */ void bdrv_drain_all (void ) {BlockDriverState *bs; +bool busy; -qemu_aio_flush (); +do { + busy =qemu_aio_wait (); + +/* FIXME: We do not have timer support here, so this is effectively +* a busy wait. +*/ + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (!qemu_co_queue_empty (&bs->throttled_reqs)) { +qemu_co_queue_restart_all (&bs->throttled_reqs); + busy = true; + } + } + }while (busy);/* If requests are still pending there is a bug somewhere */ QTAILQ_FOREACH(bs, &bdrv_states, list) {
Signature · 1 line
1.7.6.5
PATCH 3/30 block: fail live snapshot if disk has no medium
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
--- blockdev.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
blockdev.c +6 -3
@@ -756,14 +756,17 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) goto delete_and_fail; } +if (!bdrv_is_inserted (states->old_bs)) { +error_set (errp,QERR_DEVICE_HAS_NO_MEDIUM , device); + goto delete_and_fail; + } +if (bdrv_in_use (states->old_bs)) {error_set (errp,QERR_DEVICE_IN_USE , device); goto delete_and_fail; } -if (!bdrv_is_read_only (states->old_bs) && -bdrv_is_inserted (states->old_bs)) { - +if (!bdrv_is_read_only (states->old_bs)) {if (bdrv_flush (states->old_bs)) {error_set (errp,QERR_IO_ERROR ); goto delete_and_fail;
Signature · 1 line
1.7.6.5
PATCH 4/30 block: push bdrv_change_backing_file error checking up from drivers
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This check applies to all drivers, but QED lacks it.
--- block.c | 5 +++++ block/qcow2.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-)
block.c +5 -0
@@ -1460,6 +1460,11 @@ int bdrv_change_backing_file(BlockDriverState *bs, {BlockDriver *drv = bs->drv; +/* Backing file format doesn't make sense without a backing file */ +if (backing_fmt && !backing_file) { +return -EINVAL ; + } +if (drv->bdrv_change_backing_file !=NULL ) {return drv->bdrv_change_backing_file (bs, backing_file, backing_fmt); }else {
block/qcow2.c +0 -5
@@ -1011,11 +1011,6 @@ fail:static int qcow2_change_backing_file (BlockDriverState *bs,const char *backing_file,const char *backing_fmt) { -/* Backing file format doesn't make sense without a backing file */ -if (backing_fmt && !backing_file) { -return -EINVAL ; - } -pstrcpy (bs->backing_file,sizeof (bs->backing_file), backing_file ?:"" );pstrcpy (bs->backing_format,sizeof (bs->backing_format), backing_fmt ?:"" );
Signature · 1 line
1.7.6.5
PATCH 7/30 block: fix allocation size for dirty bitmap
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Also reuse elsewhere the new constant for sizeof(unsigned long) * 8.
The dirty bitmap is allocated in bits but declared as unsigned long. Thus, its memory block is accessed beyond its end unless the image is a multiple of 64 chunks (i.e. a multiple of 64 MB).
--- block.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
block.c +7 -5
@@ -1584,6 +1584,8 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,return bdrv_rw_co (bs, sector_num, buf, nb_sectors, false); } +#define BITS_PER_LONG (sizeof(unsigned long) * 8) +static void set_dirty_bitmap (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int dirty) {
@@ -1594,8 +1596,8 @@ static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num, end = (sector_num + nb_sectors -1 ) /BDRV_SECTORS_PER_DIRTY_CHUNK ;for (; start <= end; start++) { - idx = start / (sizeof (unsigned long ) *8 ); - bit = start % (sizeof (unsigned long ) *8 ); + idx = start /BITS_PER_LONG ; + bit = start %BITS_PER_LONG ; val = bs->dirty_bitmap[idx];if (dirty) {if (!(val & (1UL << bit))) {
@@ -3900,10 +3902,10 @@ void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable)if (enable) {if (!bs->dirty_bitmap) { bitmap_size = (bdrv_getlength (bs) >>BDRV_SECTOR_BITS ) + -BDRV_SECTORS_PER_DIRTY_CHUNK *8 -1 ; - bitmap_size /=BDRV_SECTORS_PER_DIRTY_CHUNK *8 ; +BDRV_SECTORS_PER_DIRTY_CHUNK *BITS_PER_LONG -1 ; + bitmap_size /=BDRV_SECTORS_PER_DIRTY_CHUNK *BITS_PER_LONG ; - bs->dirty_bitmap =g_malloc0 (bitmap_size); + bs->dirty_bitmap = g_new0(unsigned long, bitmap_size); } }else {if (bs->dirty_bitmap) {
Signature · 1 line
1.7.6.5
PATCH 2/30 block: add mode argument to blockdev-snapshot-sync
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
--- qmp-commands.hx | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
qmp-commands.hx +1 -1
@@ -759,7 +759,7 @@ EQMP { .name = "blockdev-snapshot-sync", - .args_type = "device:B,snapshot-file:s,format:s?", + .args_type = "device:B,snapshot-file:s,format:s?,mode:s?", .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync, },
Signature · 1 line
1.7.6.5
PATCH 5/30 block: update in-memory backing file and format
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
These are needed to print "info block" output correctly. QCOW2 does this because it needs it to write the header, but QED does not, and common code is the right place to do it.
--- block.c | 11 +++++++++-- block/stream.c | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-)
block.c +9 -2
@@ -1459,6 +1459,7 @@ int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt) { BlockDriver *drv = bs->drv; +int ret;/* Backing file format doesn't make sense without a backing file */ if (backing_fmt && !backing_file) {
@@ -1466,10 +1467,16 @@ int bdrv_change_backing_file(BlockDriverState *bs, }if (drv->bdrv_change_backing_file !=NULL ) { -return drv->bdrv_change_backing_file (bs, backing_file, backing_fmt); + ret = drv->bdrv_change_backing_file (bs, backing_file, backing_fmt); }else { -return -ENOTSUP ; + ret = -ENOTSUP ; + } + +if (ret ==0 ) { +pstrcpy (bs->backing_file,sizeof (bs->backing_file), backing_file ?:"" ); +pstrcpy (bs->backing_format,sizeof (bs->backing_format), backing_fmt ?:"" ); } +return ret; } static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset,
block/stream.c +0 -11
@@ -96,17 +96,6 @@ static void close_unused_images(BlockDriverState *top, BlockDriverState *base,bdrv_delete (unused); } top->backing_hd = base; - -pstrcpy (top->backing_file,sizeof (top->backing_file),"" ); -pstrcpy (top->backing_format,sizeof (top->backing_format),"" ); -if (base_id) { -pstrcpy (top->backing_file,sizeof (top->backing_file), base_id); -if (base->drv) { -pstrcpy (top->backing_format,sizeof (top->backing_format), - base->drv->format_name); - } - } - }/*
Signature · 1 line
1.7.6.5
PATCH 6/30 block: open backing file as read-only when probing for size
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
bdrv_img_create will temporarily open the backing file to probe its size. However, this could be done with a read-write open if the wrong flags are passed to bdrv_img_create. Since there is really no documentation on what flags can be passed, assume that bdrv_img_create receives the flags with which the new image will be opened; sanitize them when opening the backing file.
--- block.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
block.c +6 -1
@@ -4103,10 +4103,15 @@ int bdrv_img_create(const char *filename, const char *fmt,if (backing_file && backing_file->value.s) {uint64_t size;char buf[32 ]; +int back_flags; + +/* backing files always opened read-only */ + back_flags = + flags & ~(BDRV_O_RDWR |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING ); bs =bdrv_new ("" ); - ret =bdrv_open (bs, backing_file->value.s, flags, backing_drv); + ret =bdrv_open (bs, backing_file->value.s, back_flags, backing_drv);if (ret <0 ) {error_report ("Could not open '%s'" , backing_file->value.s); goto out;
Signature · 1 line
1.7.6.5
PATCH 9/30 qtest: Add function to send QMP commands
In reply to Kevin Wolf--- tests/libqtest.c | 123 ++++++++++++++++++++++++++++++++++++++++++------------ tests/libqtest.h | 17 +++++++ 2 files changed, 113 insertions(+), 27 deletions(-)
tests/libqtest.c +96 -27
@@ -36,6 +36,7 @@ QTestState *global_qtest;struct QTestState {int fd; +int qmp_fd;bool irq_level[MAX_IRQ ];GString *rx;gchar *pid_file;
@@ -45,48 +46,76 @@ struct QTestState g_assert_cmpint(ret, !=, -1); \ }while (0 ) +static int init_socket(const char *socket_path) +{ +struct sockaddr_un addr; +int sock; +int ret; + + sock =socket (PF_UNIX ,SOCK_STREAM ,0 ); +g_assert_no_errno (sock); + + addr.sun_family =AF_UNIX ; +snprintf (addr.sun_path,sizeof (addr.sun_path),"%s" , socket_path); +qemu_set_cloexec (sock); + +do { + ret =bind (sock, (struct sockaddr *)&addr,sizeof (addr)); + }while (ret ==-1 && errno ==EINTR ); +g_assert_no_errno (ret); +listen (sock,1 ); + +return sock; +} + +static int socket_accept (int sock) +{ +struct sockaddr_un addr; +socklen_t addrlen; +int ret; + +do { + ret =accept (sock, (struct sockaddr *)&addr, &addrlen); + }while (ret ==-1 && errno ==EINTR ); +g_assert_no_errno (ret); +close (sock); + +return ret; +} +QTestState *qtest_init (const char *extra_args) {QTestState *s; -struct sockaddr_un addr; -int sock, ret, i; +int sock, qmpsock, ret, i;gchar *socket_path; +gchar *qmp_socket_path;gchar *pid_file;gchar *command;const char *qemu_binary;pid_t pid; -socklen_t addrlen; qemu_binary =getenv ("QTEST_QEMU_BINARY" );g_assert (qemu_binary !=NULL ); socket_path =g_strdup_printf ("/tmp/qtest-%d.sock" ,getpid ()); + qmp_socket_path =g_strdup_printf ("/tmp/qtest-%d.qmp" ,getpid ()); pid_file =g_strdup_printf ("/tmp/qtest-%d.pid" ,getpid ()); s =g_malloc (sizeof (*s)); - sock =socket (PF_UNIX ,SOCK_STREAM ,0 ); -g_assert_no_errno (sock); - - addr.sun_family =AF_UNIX ; -snprintf (addr.sun_path,sizeof (addr.sun_path),"%s" , socket_path); -qemu_set_cloexec (sock); - -do { - ret =bind (sock, (struct sockaddr *)&addr,sizeof (addr)); - }while (ret ==-1 && errno ==EINTR ); -g_assert_no_errno (ret); -listen (sock,1 ); + sock =init_socket (socket_path); + qmpsock =init_socket (qmp_socket_path); pid =fork ();if (pid ==0 ) { command =g_strdup_printf ("%s " "-qtest unix:%s,nowait " "-qtest-log /dev/null " +"-qmp unix:%s,nowait " "-pidfile %s " "-machine accel=qtest " "%s" , qemu_binary, socket_path, - pid_file, + qmp_socket_path, pid_file, extra_args ?:"" ); ret =system (command);
@@ -94,13 +123,9 @@ QTestState *qtest_init(const char *extra_args)g_free (command); } -do { - ret =accept (sock, (struct sockaddr *)&addr, &addrlen); - }while (ret ==-1 && errno ==EINTR ); -g_assert_no_errno (ret); -close (sock); + s->fd =socket_accept (sock); + s->qmp_fd =socket_accept (qmpsock); - s->fd = ret; s->rx =g_string_new ("" ); s->pid_file = pid_file;for (i =0 ; i <MAX_IRQ ; i++) {
@@ -108,6 +133,11 @@ QTestState *qtest_init(const char *extra_args) }g_free (socket_path); +g_free (qmp_socket_path); + +/* Read the QMP greeting and then do the handshake */ +qtest_qmp (s,"" ); +qtest_qmp (s,"{ 'execute': 'qmp_capabilities' }" );return s; }
@@ -131,22 +161,19 @@ void qtest_quit(QTestState *s) } } -static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) +static void socket_sendf (int fd,const char *fmt,va_list ap) { -va_list ap;gchar *str;size_t size, offset; -va_start (ap, fmt); str =g_strdup_vprintf (fmt, ap); -va_end (ap); size =strlen (str); offset =0 ;while (offset < size) {ssize_t len; - len =write (s->fd, str + offset, size - offset); + len =write (fd, str + offset, size - offset);if (len ==-1 && errno ==EINTR ) {continue ; }
@@ -158,6 +185,15 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) } } +static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +socket_sendf (s->fd, fmt, ap); +va_end (ap); +} +static GString *qtest_recv_line (QTestState *s) {GString *line;
@@ -233,6 +269,39 @@ redo:return words; } +void qtest_qmp (QTestState *s,const char *fmt, ...) +{ +va_list ap; +bool has_reply = false; +int nesting =0 ; + +/* Send QMP request */ +va_start (ap, fmt); +socket_sendf (s->qmp_fd, fmt, ap); +va_end (ap); + +/* Receive reply */ +while (!has_reply || nesting >0 ) { +ssize_t len; +char c; + + len =read (s->qmp_fd, &c,1 ); +if (len ==-1 && errno ==EINTR ) { +continue ; + } + +switch (c) { +case '{' : + nesting++; + has_reply = true; +break ; +case '}' : + nesting--; +break ; + } + } +} +const char *qtest_get_arch (void ) {const char *qemu =getenv ("QTEST_QEMU_BINARY" );
tests/libqtest.h +17 -0
@@ -38,6 +38,15 @@ QTestState *qtest_init(const char *extra_args);void qtest_quit (QTestState *s);/** +* qtest_qmp: +* @s: QTestState instance to operate on. +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU +*/ +void qtest_qmp (QTestState *s,const char *fmt, ...); + +/** * qtest_get_irq: * @s: QTestState instance to operate on. * @num: Interrupt to observe.
@@ -207,6 +216,14 @@ void qtest_add_func(const char *str, void (*fn)); )/** +* qmp: +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU +*/ +#define qmp (fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__) + +/** * get_irq: * @num: Interrupt to observe. *
Signature · 1 line
1.7.6.5
PATCH 10/30 qtest: Add floppy test
In reply to Kevin WolfLet's start with testing media change.
--- tests/Makefile | 2 + tests/fdc-test.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 tests/fdc-test.c
tests/Makefile +2 -0
@@ -19,6 +19,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/fdc-test check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
@@ -67,6 +68,7 @@ tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marsh tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y) +tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o # QTest rules
tests/fdc-test.c new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 12/30 block: another bdrv_append fix
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
bdrv_append must also copy open_flags to the top, because the snapshot has BDRV_O_NO_BACKING set. This causes interesting results if you later use drive-reopen (not upstream) to reopen the image, and lose the backing file in the process.
--- block.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
block.c +1 -0
@@ -977,6 +977,7 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) tmp = *bs_new;/* there are some fields that need to stay on the top layer: */ + tmp.open_flags = bs_top->open_flags;/* dev info */ tmp.dev_ops = bs_top->dev_ops;
Signature · 1 line
1.7.6.5
PATCH 8/30 qemu-iotests: strip spaces from qemu-img/qemu-io/qemu command lines
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
A trailing space is left when qemu-img has no arguments, for example if -nocache is not used. This becomes an empty argument after split() and causes qemu-io to fail.
--- tests/qemu-iotests/iotests.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/iotests.py +3 -3
@@ -28,9 +28,9 @@ __all__ = ['imgfmt', 'imgproto', 'test_dir' 'qemu_img', 'qemu_io', # This will not work if arguments or path contain spaces but is necessary if we # want to support the override options that ./check supports. -qemu_img_args = os.environ.get('QEMU_IMG', 'qemu-img').split(' ') -qemu_io_args = os.environ.get('QEMU_IO', 'qemu-io').split(' ') -qemu_args = os.environ.get('QEMU', 'qemu').split(' ') +qemu_img_args = os.environ.get('QEMU_IMG', 'qemu-img').strip().split(' ') +qemu_io_args = os.environ.get('QEMU_IO', 'qemu-io').strip().split(' ') +qemu_args = os.environ.get('QEMU', 'qemu').strip().split(' ') imgfmt = os.environ.get('IMGFMT', 'raw') imgproto = os.environ.get('IMGPROTO', 'file')
Signature · 1 line
1.7.6.5
PATCH 11/30 block: fix snapshot on QED
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
QED's opaque data includes a pointer back to the BlockDriverState. This breaks when bdrv_append shuffles data between bs_new and bs_top. To avoid this, add a "rebind" function that tells the driver about the new relationship between the BlockDriverState and its opaque.
The patch also adds rebind to VVFAT for completeness, even though it is not used with live snapshots.
--- block.c | 10 ++++++++++ block/qed.c | 7 +++++++ block/vvfat.c | 7 +++++++ block_int.h | 1 + 4 files changed, 25 insertions(+), 0 deletions(-)
block.c +10 -0
@@ -949,6 +949,13 @@ void bdrv_make_anon(BlockDriverState *bs) bs->device_name[0 ] ='\0' ; } +static void bdrv_rebind (BlockDriverState *bs) +{ +if (bs->drv && bs->drv->bdrv_rebind) { + bs->drv->bdrv_rebind (bs); + } +} +/* * Add new bs contents at the top of an image chain while the chain is * live, while keeping required fields on the top layer.
@@ -1037,6 +1044,9 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) bs_new->slice_time =0 ; bs_new->slice_start =0 ; bs_new->slice_end =0 ; + +bdrv_rebind (bs_new); +bdrv_rebind (bs_top); }void bdrv_delete (BlockDriverState *bs)
block/qed.c +7 -0
@@ -367,6 +367,12 @@ static void qed_cancel_need_check_timer(BDRVQEDState *s)qemu_del_timer (s->need_check_timer); } +static void bdrv_qed_rebind (BlockDriverState *bs) +{ +BDRVQEDState *s = bs->opaque; + s->bs = bs; +} +static int bdrv_qed_open (BlockDriverState *bs,int flags) {BDRVQEDState *s = bs->opaque;
@@ -1550,6 +1556,7 @@ static BlockDriver bdrv_qed = { .create_options = qed_create_options, .bdrv_probe = bdrv_qed_probe, + .bdrv_rebind = bdrv_qed_rebind, .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_create = bdrv_qed_create,
block/vvfat.c +7 -0
@@ -982,6 +982,12 @@ static BDRVVVFATState *vvv = NULL;static int enable_write_target (BDRVVVFATState *s);static int is_consistent (BDRVVVFATState *s); +static void vvfat_rebind (BlockDriverState *bs) +{ +BDRVVVFATState *s = bs->opaque; + s->bs = bs; +} +static int vvfat_open (BlockDriverState *bs,const char * dirname,int flags) {BDRVVVFATState *s = bs->opaque;
@@ -2855,6 +2861,7 @@ static BlockDriver bdrv_vvfat = { .format_name = "vvfat", .instance_size = sizeof(BDRVVVFATState), .bdrv_file_open = vvfat_open, + .bdrv_rebind = vvfat_rebind, .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_close = vvfat_close,
block_int.h +1 -0
@@ -140,6 +140,7 @@ struct BlockDriver {int (*bdrv_write)(BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors);void (*bdrv_close)(BlockDriverState *bs); +void (*bdrv_rebind)(BlockDriverState *bs);int (*bdrv_create)(const char *filename,QEMUOptionParameter *options);int (*bdrv_set_key)(BlockDriverState *bs,const char *key);int (*bdrv_make_empty)(BlockDriverState *bs);
Signature · 1 line
1.7.6.5
PATCH 13/30 block: do not reuse the backing file across bdrv_close/bdrv_open
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This is another bug caused by not doing a full cleanup of the BDS across close/open. This was found with mirroring by Shaolong Hu, but it can probably be reproduced also with eject or change.
--- block.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
block.c +2 -0
@@ -878,6 +878,8 @@ void bdrv_close(BlockDriverState *bs) bs->opaque =NULL ; bs->drv =NULL ; bs->copy_on_read =0 ; + bs->backing_file[0 ] ='\0' ; + bs->backing_format[0 ] ='\0' ;if (bs->file !=NULL ) {bdrv_close (bs->file);
Signature · 1 line
1.7.6.5
PATCH 14/30 block: fully delete bs->file when closing
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
We are reusing bs->file across close/open, which may not cause any known bugs but is a recipe for trouble. Prefer bdrv_delete, and enjoy the new invariant in the implementation of bdrv_delete.
--- block.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
block.c +2 -4
@@ -882,7 +882,8 @@ void bdrv_close(BlockDriverState *bs) bs->backing_format[0 ] ='\0' ;if (bs->file !=NULL ) { -bdrv_close (bs->file); +bdrv_delete (bs->file); + bs->file =NULL ; }bdrv_dev_change_media_cb (bs, false);
@@ -1062,9 +1063,6 @@ void bdrv_delete(BlockDriverState *bs)bdrv_make_anon (bs);bdrv_close (bs); -if (bs->file !=NULL ) { -bdrv_delete (bs->file); - }assert (bs != bs_snapshots);g_free (bs);
Signature · 1 line
1.7.6.5
PATCH 17/30 block: simplify path_is_absolute
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
On Windows, all the logic is already in is_windows_drive and is_windows_drive_prefix. On POSIX, there is no need to look out for colons.
The win32 code changes the behaviour in some cases, we could have something like "d:foo.img". The old code would treat it as relative path, the new one as absolute. Now the path is absolute, because to go from c:/program files/blah to d:foo.img you cannot say c:/program files/blah/d:foo.img. You have to say d:foo.img. But you could also say it's relative because (I think, at least it was like that in DOS 15 years ago) d:foo.img is relative to the current path of drive D. Considering how path_is_absolute is used by path_combine, I think it's better to treat it as absolute.
--- block.c | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-)
block.c +4 -11
@@ -210,21 +210,14 @@ static int path_has_protocol(const char *path)int path_is_absolute (const char *path) { -const char *p;#ifdef _WIN32/* specific case for names like: "\\.\d:" */ -if (*path =='/' || *path =='\\' ) +if (is_windows_drive (path) ||is_windows_drive_prefix (path)) {return 1 ; -#endif - p =strchr (path,':' ); -if (p) - p++; -else - p = path; -#ifdef _WIN32 -return (*p =='/' || *p =='\\' ); + } +return (*path =='/' || *path =='\\' );#else -return (*p =='/' ); +return (*path =='/' );#endif }
Signature · 1 line
1.7.6.5
PATCH 20/30 qemu-img: make "info" backing file output correct and easier to use
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
qemu-img info should use the same logic as qemu when printing the backing file path, or debugging becomes quite tricky. We can also simplify the output in case the backing file has an absolute path or a protocol.
--- block.c | 19 +++++++++++-------- block.h | 2 ++ qemu-img.c | 12 +++++++----- 3 files changed, 20 insertions(+), 13 deletions(-)
block.c +11 -8
@@ -270,6 +270,15 @@ void path_combine(char *dest, int dest_size, } } +void bdrv_get_full_backing_filename (BlockDriverState *bs,char *dest,size_t sz) +{ +if (bs->backing_file[0 ] =='\0' ||path_has_protocol (bs->backing_file)) { +pstrcpy (dest, sz, bs->backing_file); + }else { +path_combine (dest, sz, bs->filename, bs->backing_file); + } +} +void bdrv_register (BlockDriver *bdrv) {/* Block drivers without coroutine functions need emulation */
@@ -796,14 +805,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,BlockDriver *back_drv =NULL ; bs->backing_hd =bdrv_new ("" ); - -if (path_has_protocol (bs->backing_file)) { -pstrcpy (backing_filename,sizeof (backing_filename), - bs->backing_file); - }else { -path_combine (backing_filename,sizeof (backing_filename), - filename, bs->backing_file); - } +bdrv_get_full_backing_filename (bs, backing_filename, +sizeof (backing_filename));if (bs->backing_format[0 ] !='\0' ) { back_drv =bdrv_find_format (bs->backing_format);
block.h +2 -0
@@ -303,6 +303,8 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);const char *bdrv_get_encrypted_filename (BlockDriverState *bs);void bdrv_get_backing_filename (BlockDriverState *bs,char *filename,int filename_size); +void bdrv_get_full_backing_filename (BlockDriverState *bs, +char *dest,size_t sz);int bdrv_can_snapshot (BlockDriverState *bs);int bdrv_is_snapshot (BlockDriverState *bs);BlockDriverState *bdrv_snapshots (void );
qemu-img.c +7 -5
@@ -1138,11 +1138,13 @@ static int img_info(int argc, char **argv) }bdrv_get_backing_filename (bs, backing_filename,sizeof (backing_filename));if (backing_filename[0 ] !='\0' ) { -path_combine (backing_filename2,sizeof (backing_filename2), - filename, backing_filename); -printf ("backing file: %s (actual path: %s)\n" , - backing_filename, - backing_filename2); +bdrv_get_full_backing_filename (bs, backing_filename2, +sizeof (backing_filename2)); +printf ("backing file: %s" , backing_filename); +if (strcmp (backing_filename, backing_filename2) !=0 ) { +printf (" (actual path: %s)" , backing_filename2); + } +putchar ('\n' ); }dump_snapshots (bs);bdrv_delete (bs);
Signature · 1 line
1.7.6.5
PATCH 18/30 block: protect path_has_protocol from filenames with colons
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
path_has_protocol will erroneously return "true" if the colon is part of a filename. These names are common with stable device names produced by udev. We cannot fully protect against this in case the filename does not have a path component (e.g. if the current directory is /dev/disk/by-path), but in the common case there will be a slash before and path_has_protocol can easily detect that and return false.
--- block.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
block.c +6 -1
@@ -198,14 +198,19 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,/* check if the path starts with "<protocol>:" */ static int path_has_protocol (const char *path) { +const char *p; +#ifdef _WIN32if (is_windows_drive (path) ||is_windows_drive_prefix (path)) {return 0 ; } + p = path +strcspn (path,":/\\" ); +#else + p = path +strcspn (path,":/" );#endif -return strchr (path,':' ) !=NULL ; +return *p ==':' ; }int path_is_absolute (const char *path)
Signature · 1 line
1.7.6.5
PATCH 15/30 block: add block_job_sleep_ns
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This function abstracts the pretty complex semantics of the "busy" member of BlockJob.
--- block.c | 11 +++++++++++ block/stream.c | 23 +++++++++-------------- block_int.h | 22 +++++++++++++++------- 3 files changed, 35 insertions(+), 21 deletions(-)
block.c +11 -0
@@ -4188,6 +4188,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs, job->bs = bs; job->cb = cb; job->opaque = opaque; + job->busy = true; bs->job = job;/* Only set speed when necessary to avoid NotSupported error */
@@ -4254,3 +4255,13 @@ void block_job_cancel_sync(BlockJob *job)qemu_aio_wait (); } } + +void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns) +{ +/* Check cancellation *before* setting busy = false, too! */ +if (!block_job_is_cancelled (job)) { + job->busy = false; +co_sleep_ns (clock, ns); + job->busy = true; + } +}
block/stream.c +9 -14
@@ -192,12 +192,17 @@ static void coroutine_fn stream_run(void *opaque) }for (sector_num =0 ; sector_num < end; sector_num += n) { -retry: +uint64_t delay_ns =0 ; + +wait: +/* Note that even when no rate limit is applied we need to yield +* with no pending I/O here so that qemu_aio_flush() returns. +*/ +block_job_sleep_ns (&s->common, rt_clock, delay_ns);if (block_job_is_cancelled (&s->common)) {break ; } - s->common.busy = true;if (base) { ret =is_allocated_base (bs, base, sector_num,STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , &n);
@@ -209,13 +214,9 @@ retry:trace_stream_one_iteration (s, sector_num, n, ret);if (ret ==0 ) {if (s->common.speed) { -uint64_t delay_ns =ratelimit_calculate_delay (&s->limit, n); + delay_ns =ratelimit_calculate_delay (&s->limit, n);if (delay_ns >0 ) { - s->common.busy = false; -co_sleep_ns (rt_clock, delay_ns); - -/* Recheck cancellation and that sectors are unallocated */ - goto retry; + goto wait; } } ret =stream_populate (bs, sector_num, n, buf);
@@ -227,12 +228,6 @@ retry:/* Publish progress */ s->common.offset += n *BDRV_SECTOR_SIZE ; - -/* Note that even when no rate limit is applied we need to yield -* with no pending I/O here so that qemu_aio_flush() returns. -*/ - s->common.busy = false; -co_sleep_ns (rt_clock,0 ); }if (!base) {
block_int.h +15 -7
@@ -97,18 +97,15 @@ struct BlockJob {/** * Set to true if the job should cancel itself. The flag must * always be tested just before toggling the busy flag from false -* to true. After a job has detected that the cancelled flag is -* true, it should not anymore issue any I/O operation to the -* block device. +* to true. After a job has been cancelled, it should only yield +* if #qemu_aio_wait will ("sooner or later") reenter the coroutine. */ bool cancelled;/** * Set to false by the job while it is in a quiescent state, where -* no I/O is pending and cancellation can be processed without -* issuing new I/O. The busy flag must be set to false when the -* job goes to sleep on any condition that is not detected by -* #qemu_aio_wait, such as a timer. +* no I/O is pending and the job has yielded on any condition +* that is not detected by #qemu_aio_wait, such as a timer. */ bool busy;
@@ -364,6 +361,17 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs, void *opaque, Error **errp);/** +* block_job_sleep_ns: +* @job: The job that calls the function. +* @clock: The clock to sleep on. +* @ns: How many nanoseconds to stop for. +* +* Put the job to sleep (assuming that it wasn't canceled) for @ns +* nanoseconds. Canceling the job will interrupt the wait immediately. +*/ +void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns); + +/** * block_job_complete: * @job: The job being completed. * @ret: The status code.
Signature · 1 line
1.7.6.5
PATCH 16/30 block: wait for job callback in block_job_cancel_sync
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
The limitation on not having I/O after cancellation cannot really be kept. Even streaming has a very small race window where you could cancel a job and have it report completion. If this window is hit, bdrv_change_backing_file() will yield and possibly cause accesses to dangling pointers etc.
So, let's just assume that we cannot know exactly what will happen after the coroutine has set busy to false. We can set a very lax condition:
- if we cancel the job, the coroutine won't set it to false again (and hence will not call co_sleep_ns again).
- block_job_cancel_sync will wait for the coroutine to exit, which pretty much ensures no race.
Instead, we track the coroutine that executes the job and put very strict conditions on what to do while it is quiescent (busy = false). First of all, the coroutine must never set busy = false while the job has been cancelled. Second, the coroutine can be reentered arbitrarily while it is quiescent, so you cannot really do anything but co_sleep_ns at that time. This condition is obeyed by the block_job_sleep_ns function.
--- block.c | 36 ++++++++++++++++++++++++++++++++++-- block/stream.c | 7 +++---- block_int.h | 11 ++++++++++- 3 files changed, 47 insertions(+), 7 deletions(-)
block.c +34 -2
@@ -4238,6 +4238,9 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)void block_job_cancel (BlockJob *job) { job->cancelled = true; +if (job->co && !job->busy) { +qemu_coroutine_enter (job->co,NULL ); + } }bool block_job_is_cancelled (BlockJob *job)
@@ -4245,15 +4248,44 @@ bool block_job_is_cancelled(BlockJob *job)return job->cancelled; } -void block_job_cancel_sync (BlockJob *job) +struct BlockCancelData { +BlockJob *job; +BlockDriverCompletionFunc *cb; +void *opaque; +bool cancelled; +int ret; +}; + +static void block_job_cancel_cb (void *opaque,int ret) { +struct BlockCancelData *data = opaque; + + data->cancelled =block_job_is_cancelled (data->job); + data->ret = ret; + data->cb (data->opaque, ret); +} + +int block_job_cancel_sync (BlockJob *job) +{ +struct BlockCancelData data;BlockDriverState *bs = job->bs;assert (bs->job == job); + +/* Set up our own callback to store the result and chain to +* the original callback. +*/ + data.job = job; + data.cb = job->cb; + data.opaque = job->opaque; + data.ret = -EINPROGRESS ; + job->cb = block_job_cancel_cb; + job->opaque = &data;block_job_cancel (job); -while (bs->job !=NULL && bs->job->busy) { +while (data.ret == -EINPROGRESS ) {qemu_aio_wait (); } +return (data.cancelled && data.ret ==0 ) ? -ECANCELED : data.ret; }void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns)
block/stream.c +3 -4
@@ -270,7 +270,6 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, void *opaque, Error **errp) { StreamBlockJob *s; -Coroutine *co; s =block_job_create (&stream_job_type, bs, speed, cb, opaque, errp);if (!s) {
@@ -282,7 +281,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,pstrcpy (s->backing_file_id,sizeof (s->backing_file_id), base_id); } - co =qemu_coroutine_create (stream_run); -trace_stream_start (bs, base, s, co, opaque); -qemu_coroutine_enter (co, s); + s->common.co =qemu_coroutine_create (stream_run); +trace_stream_start (bs, base, s, s->common.co, opaque); +qemu_coroutine_enter (s->common.co, s); }
block_int.h +10 -1
@@ -95,6 +95,12 @@ struct BlockJob {BlockDriverState *bs;/** +* The coroutine that executes the job. If not NULL, it is +* reentered when busy is false and the job is cancelled. +*/ +Coroutine *co; + +/** * Set to true if the job should cancel itself. The flag must * always be tested just before toggling the busy flag from false * to true. After a job has been cancelled, it should only yield
@@ -418,8 +424,11 @@ bool block_job_is_cancelled(BlockJob *job);* immediately after #block_job_cancel_sync. Users of block jobs * will usually protect the BlockDriverState objects with a reference * count, should this be a concern. +* +* Returns the return value from the job if the job actually completed +* during the call, or -ECANCELED if it was canceled. */ -void block_job_cancel_sync (BlockJob *job); +int block_job_cancel_sync (BlockJob *job);/** * stream_start:
Signature · 1 line
1.7.6.5
PATCH 19/30 block: move field reset from bdrv_open_common to bdrv_close
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
bdrv_close should leave fields in the same state as bdrv_new. It is not up to bdrv_open_common to fix the mess.
Also, backing_format was not being re-initialized.
--- block.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
block.c +6 -7
@@ -610,16 +610,11 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,int ret, open_flags;assert (drv !=NULL ); +assert (bs->file ==NULL );trace_bdrv_open_common (bs, filename, flags, drv->format_name); - bs->file =NULL ; - bs->total_sectors =0 ; - bs->encrypted =0 ; - bs->valid_key =0 ; - bs->sg =0 ; bs->open_flags = flags; - bs->growable =0 ; bs->buffer_alignment =512 ;assert (bs->copy_on_read ==0 );/* bdrv_new() and bdrv_close() make it so */
@@ -628,7 +623,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, }pstrcpy (bs->filename,sizeof (bs->filename), filename); - bs->backing_file[0 ] ='\0' ;if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv)) {return -ENOTSUP ;
@@ -878,6 +872,11 @@ void bdrv_close(BlockDriverState *bs) bs->copy_on_read =0 ; bs->backing_file[0 ] ='\0' ; bs->backing_format[0 ] ='\0' ; + bs->total_sectors =0 ; + bs->encrypted =0 ; + bs->valid_key =0 ; + bs->sg =0 ; + bs->growable =0 ;if (bs->file !=NULL ) {bdrv_delete (bs->file);
Signature · 1 line
1.7.6.5
PATCH 22/30 qemu-io: fix the alloc command
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Because sector_num is not updated, the loop would either go on forever or return garbage.
--- qemu-io.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
qemu-io.c +8 -2
@@ -1560,7 +1560,7 @@ out:static int alloc_f (int argc,char **argv) { -int64_t offset; +int64_t offset, sector_num;int nb_sectors, remaining;char s1[64 ];int num, sum_alloc;
@@ -1581,12 +1581,18 @@ static int alloc_f(int argc, char **argv) remaining = nb_sectors; sum_alloc =0 ; + sector_num = offset >>9 ;while (remaining) { - ret =bdrv_is_allocated (bs, offset >>9 , nb_sectors, &num); + ret =bdrv_is_allocated (bs, sector_num, remaining, &num); + sector_num += num; remaining -= num;if (ret) { sum_alloc += num; } +if (num ==0 ) { + nb_sectors -= remaining; + remaining =0 ; + } }cvtstr (offset, s1,sizeof (s1));
Signature · 1 line
1.7.6.5
PATCH 23/30 stream: fix sectors not allocated test
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
The test on sectors not allocated can fail if the L1/L2 tables are not on disk yet. Allow tests to shutdown the VM early.
--- tests/qemu-iotests/030 | 1 + tests/qemu-iotests/iotests.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
tests/qemu-iotests/030 +1 -0
@@ -78,6 +78,7 @@ class TestSingleDrive(ImageStreamingTestCase): completed = True self.assert_no_active_streams() + self.vm.shutdown() self.assertFalse('sectors not allocated' in qemu_io('-c', 'map', test_img), 'image file not fully populated after streaming')
tests/qemu-iotests/iotests.py +6 -4
@@ -87,10 +87,12 @@ class VM(object): def shutdown(self): '''Terminate the VM and clean up''' - self._qmp.cmd('quit') - self._popen.wait() - os.remove(self._monitor_path) - os.remove(self._qemu_log_path) + if not self._popen is None: + self._qmp.cmd('quit') + self._popen.wait() + os.remove(self._monitor_path) + os.remove(self._qemu_log_path) + self._popen = None def qmp(self, cmd, **args): '''Invoke a QMP command and return the result dict'''
Signature · 1 line
1.7.6.5
PATCH 26/30 stream: fix HMP block_job_set_speed
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
The change of the argument name from value to speed was not propagated there.
--- hmp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hmp.c +1 -1
@@ -849,7 +849,7 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) {Error *error =NULL ;const char *device =qdict_get_str (qdict,"device" ); -int64_t value =qdict_get_int (qdict,"value" ); +int64_t value =qdict_get_int (qdict,"speed" );qmp_block_job_set_speed (device, value, &error);
Signature · 1 line
1.7.6.5
PATCH 24/30 stream: add testcase for partial streaming
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
--- tests/qemu-iotests/030 | 28 +++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 ++-- 2 files changed, 29 insertions(+), 3 deletions(-)
tests/qemu-iotests/030 +27 -1
@@ -23,6 +23,7 @@ import iotests from iotests import qemu_img, qemu_io backing_img = os.path.join(iotests.test_dir, 'backing.img') +mid_img = os.path.join(iotests.test_dir, 'mid.img') test_img = os.path.join(iotests.test_dir, 'test.img') class ImageStreamingTestCase(iotests.QMPTestCase):
@@ -52,13 +53,15 @@ class TestSingleDrive(ImageStreamingTestCase): def setUp(self): qemu_img('create', backing_img, str(TestSingleDrive.image_len)) - qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) self.vm = iotests.VM().add_drive(test_img) self.vm.launch() def tearDown(self): self.vm.shutdown() os.remove(test_img) + os.remove(mid_img) os.remove(backing_img) def test_stream(self):
@@ -83,6 +86,29 @@ class TestSingleDrive(ImageStreamingTestCase): self.assertFalse('sectors not allocated' in qemu_io('-c', 'map', test_img), 'image file not fully populated after streaming') + def test_stream_partial(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0', base=mid_img) + self.assert_qmp(result, 'return', {}) + + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_COMPLETED': + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + self.assertEqual(qemu_io('-c', 'map', mid_img), + qemu_io('-c', 'map', test_img), + 'image file map does not match backing file after streaming') + def test_device_not_found(self): result = self.vm.qmp('block-stream', device='nonexistent') self.assert_qmp(result, 'error/class', 'DeviceNotFound')
tests/qemu-iotests/030.out +2 -2
@@ -1,5 +1,5 @@ -..... +...... ---------------------------------------------------------------------- -Ran 5 tests +Ran 6 tests OK
Signature · 1 line
1.7.6.5
PATCH 27/30 stream: fix ratelimiting corner case
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This fixes inability to make progress in streaming if the quota is set to less than the amount of data that an I/O operation has to write.
In this case, limit->dispatched + n will always be above the quota and, due to the "goto retry" to recheck cancellation and allocation, streaming will livelock.
This can be reproduced with "block_job_set_speed ide0-hd0 1b". Of course, with this patch the requested limit will not be obeyed. That could be done with another patch that caps is_allocated's n argument by the slice quota.
--- block/stream.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
block/stream.c +5 -5
@@ -33,19 +33,19 @@ typedef struct {static int64_t ratelimit_calculate_delay (RateLimit *limit,uint64_t n) { -int64_t delay_ns =0 ;int64_t now =qemu_get_clock_ns (rt_clock);if (limit->next_slice_time < now) { limit->next_slice_time = now +SLICE_TIME ; limit->dispatched =0 ; } -if (limit->dispatched + n > limit->slice_quota) { - delay_ns = limit->next_slice_time - now; - }else { +if (limit->dispatched ==0 || limit->dispatched + n <= limit->slice_quota) { limit->dispatched += n; +return 0 ; + }else { + limit->dispatched = n; +return limit->next_slice_time - now; } -return delay_ns; }static void ratelimit_set_speed (RateLimit *limit,uint64_t speed)
Signature · 1 line
1.7.6.5
PATCH 29/30 tests/Makefile: Add missing $(EXESUF)
In reply to Kevin Wolf--- tests/Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tests/Makefile +2 -2
@@ -18,8 +18,8 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. -check-qtest-i386-y = tests/rtc-test -check-qtest-i386-y = tests/fdc-test +check-qtest-i386-y = tests/rtc-test$(EXESUF) +check-qtest-i386-y = tests/fdc-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
Signature · 1 line
1.7.6.5
PATCH 25/30 stream: pass new base image format to bdrv_change_backing_file
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
When an image is modified to point to the new backing file, the backing file format is set to NULL, which means auto-probe. This is wrong, in fact it is a small security problem.
--- block/stream.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
block/stream.c +5 -2
@@ -235,11 +235,14 @@ wait: }if (!block_job_is_cancelled (&s->common) && sector_num == end && ret ==0 ) { -const char *base_id =NULL ; +const char *base_id =NULL , *base_fmt =NULL ;if (base) { base_id = s->backing_file_id; +if (base->drv) { + base_fmt = base->drv->format_name; + } } - ret =bdrv_change_backing_file (bs, base_id,NULL ); + ret =bdrv_change_backing_file (bs, base_id, base_fmt);close_unused_images (bs, base, base_id); }
Signature · 1 line
1.7.6.5
PATCH 28/30 stream: do not copy unallocated sectors from the base
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Unallocated sectors should really never be accessed by the guest, so there's no need to copy them during the streaming process. If they are read by the guest during streaming, guest-initiated copy-on-read will copy them (we're in the base == NULL case, which enables copy on read). If they are read after we disconnect the image from the base, they will read as zeroes anyway.
--- block/stream.c | 18 ++++-------------- tests/qemu-iotests/030 | 5 +++-- 2 files changed, 7 insertions(+), 16 deletions(-)
block/stream.c +4 -14
@@ -130,14 +130,9 @@ static int coroutine_fn is_allocated_base(BlockDriverState *top,*/ intermediate = top->backing_hd; -while (intermediate) { +while (intermediate != base) {int pnum_inter; -/* reached base */ -if (intermediate == base) { - *pnum = n; -return 1 ; - } ret =bdrv_co_is_allocated (intermediate, sector_num, nb_sectors, &pnum_inter);if (ret <0 ) {
@@ -160,6 +155,7 @@ static int coroutine_fn is_allocated_base(BlockDriverState *top, intermediate = intermediate->backing_hd; } + *pnum = n;return 1 ; }
@@ -203,14 +199,8 @@ wait:break ; } -if (base) { - ret =is_allocated_base (bs, base, sector_num, -STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , &n); - }else { - ret =bdrv_co_is_allocated (bs, sector_num, -STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , - &n); - } + ret =is_allocated_base (bs, base, sector_num, +STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , &n);trace_stream_one_iteration (s, sector_num, n, ret);if (ret ==0 ) {if (s->common.speed) {
tests/qemu-iotests/030 +3 -2
@@ -83,8 +83,9 @@ class TestSingleDrive(ImageStreamingTestCase): self.assert_no_active_streams() self.vm.shutdown() - self.assertFalse('sectors not allocated' in qemu_io('-c', 'map', test_img), - 'image file not fully populated after streaming') + self.assertEqual(qemu_io('-c', 'map', backing_img), + qemu_io('-c', 'map', test_img), + 'image file map does not match backing file after streaming') def test_stream_partial(self): self.assert_no_active_streams()
Signature · 1 line
1.7.6.5
PATCH 30/30 declare ECANCELED on all machines
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This is needed in particular on Win32.
--- qemu-common.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
qemu-common.h +3 -0
@@ -61,6 +61,9 @@ typedef struct Monitor Monitor;#if !defined(ENOTSUP )#define ENOTSUP 4096#endif +#if !defined(ECANCELED ) +#define ECANCELED 4097 +#endif #ifndef TIME_MAX #define TIME_MAX LONG_MAX#endif
Signature · 1 line
1.7.6.5
PATCH 21/30 qemu-io: correctly print non-integer values as decimals
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
qemu-io's cvtstr function sometimes will incorrectly omit the decimal part of the number, and sometimes will incorrectly include it. This patch fixes both. The former is more serious, and can be seen in the patches to 027.out and 033.out.
The changes to all other files were scripted with sed, so there were no "surprises" beyond 027.out and 033.out.
--- cmd.c | 40 +- tests/qemu-iotests/002.out | 4 +- tests/qemu-iotests/012.out | 2 +- tests/qemu-iotests/016.out | 12 +- tests/qemu-iotests/017.out | 1024 ++++++++-------- tests/qemu-iotests/018.out | 1024 ++++++++-------- tests/qemu-iotests/019.out | 1536 ++++++++++++------------ tests/qemu-iotests/020.out | 1024 ++++++++-------- tests/qemu-iotests/023.out | 2880 ++++++++++++++++++++++---------------------- tests/qemu-iotests/027.out | 2 +- tests/qemu-iotests/028.out | 448 ++++---- tests/qemu-iotests/033.out | 6 +- tests/qemu-iotests/035.out | 384 +++--- 13 files changed, 4196 insertions(+), 4190 deletions(-)
cmd.c +23 -17
@@ -418,31 +418,37 @@ cvtstr(char *str, size_t size) { -const char *fmt; -int precise; - - precise = ((double )value *1000 == (double )(int )value *1000 ); + char *trim; +const char *suffix;if (value >=EXABYTES (1 )) { - fmt = precise ?"%.f EiB" :"%.3f EiB" ; -snprintf (str, size, fmt,TO_EXABYTES (value)); + suffix =" EiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_EXABYTES (value)); }else if (value >=PETABYTES (1 )) { - fmt = precise ?"%.f PiB" :"%.3f PiB" ; -snprintf (str, size, fmt,TO_PETABYTES (value)); + suffix =" PiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_PETABYTES (value)); }else if (value >=TERABYTES (1 )) { - fmt = precise ?"%.f TiB" :"%.3f TiB" ; -snprintf (str, size, fmt,TO_TERABYTES (value)); + suffix =" TiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_TERABYTES (value)); }else if (value >=GIGABYTES (1 )) { - fmt = precise ?"%.f GiB" :"%.3f GiB" ; -snprintf (str, size, fmt,TO_GIGABYTES (value)); + suffix =" GiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_GIGABYTES (value)); }else if (value >=MEGABYTES (1 )) { - fmt = precise ?"%.f MiB" :"%.3f MiB" ; -snprintf (str, size, fmt,TO_MEGABYTES (value)); + suffix =" MiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_MEGABYTES (value)); }else if (value >=KILOBYTES (1 )) { - fmt = precise ?"%.f KiB" :"%.3f KiB" ; -snprintf (str, size, fmt,TO_KILOBYTES (value)); + suffix =" KiB" ; +snprintf (str, size -4 ,"%.3f" ,TO_KILOBYTES (value)); + }else { + suffix =" bytes" ; +snprintf (str, size -6 ,"%f" , value); + } + + trim =strstr (str,".000" ); +if (trim) { +strcpy (trim, suffix); }else { -snprintf (str, size,"%f bytes" , value); +strcat (str, suffix); } }
tests/qemu-iotests/002.out +2 -2
@@ -15,9 +15,9 @@ read 134217728/134217728 bytes at offset 0 unaligned pwrite wrote 42/42 bytes at offset 66 -42.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) verify pattern read 42/42 bytes at offset 66 -42.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
tests/qemu-iotests/012.out +1 -1
@@ -5,5 +5,5 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 == read from read-only image read 512/512 bytes at offset 0 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
tests/qemu-iotests/016.out +6 -6
@@ -3,21 +3,21 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 == reading at EOF == read 512/512 bytes at offset 134217728 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == reading far past EOF == read 512/512 bytes at offset 268435456 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == writing at EOF == wrote 512/512 bytes at offset 134217728 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 512/512 bytes at offset 134217728 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == writing far past EOF == wrote 512/512 bytes at offset 268435456 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 512/512 bytes at offset 268435456 -512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
tests/qemu-iotests/017.out +512 -512
1,566 lines not on this page · raw message
tests/qemu-iotests/018.out +512 -512
1,336 lines not on this page · raw message
tests/qemu-iotests/019.out +768 -768
1,536 lines not on this page · raw message
tests/qemu-iotests/020.out +512 -512
1,024 lines not on this page · raw message
tests/qemu-iotests/023.out +1440 -1440
2,880 lines not on this page · raw message
tests/qemu-iotests/028.out +224 -224
448 lines not on this page · raw message
tests/qemu-iotests/035.out +192 -192
384 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
No errors were found on the image.
Signature · 1 line
1.7.6.5
Part of the diff is not shown here. View the raw message.
Quoted 7 lines · Kevin Wolf
The following changes since commit
1b3e76ebd1e270eae27e502ea8b836c31d95f801:tcg/ppc: Fix CONFIG_TCG_PASS_AREG0 mode (2012-05-09 13:59:19 -0500)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthony
Pulled. With the addition of a small fixup that we discussed on IRC.
Regards,
Anthony Liguori
Quoted 73 lines
Kevin Wolf (3):
qtest: Add function to send QMP commands
qtest: Add floppy test
tests/Makefile: Add missing $(EXESUF)Paolo Bonzini (26):
block: add mode argument to blockdev-snapshot-sync
block: fail live snapshot if disk has no medium
block: pushbdrv_change_backing_fileerror checking up from drivers
block: update in-memory backing file and format
block: open backing file as read-only when probing for size
block: fix allocation size for dirty bitmap
qemu-iotests: strip spaces from qemu-img/qemu-io/qemu command lines
block: fix snapshot on QED
block: anotherbdrv_appendfix
block: do not reuse the backing file across bdrv_close/bdrv_open
block: fully deletebs->filewhen closing
block: addblock_job_sleep_ns
block: wait for job callback inblock_job_cancel_sync
block: simplifypath_is_absolute
block: protectpath_has_protocolfrom filenames with colons
block: move field reset frombdrv_open_commontobdrv_close
qemu-img: make "info" backing file output correct and easier to use
qemu-io: correctly print non-integer values as decimals
qemu-io: fix the alloc command
stream: fix sectors not allocated test
stream: add testcase for partial streaming
stream: pass new base image format tobdrv_change_backing_file
stream: fix HMPblock_job_set_speed
stream: fix ratelimiting corner case
stream: do not copy unallocated sectors from the base declare ECANCELED on all machinesZhi Yong Wu (1):
block: add the support to drain throttled requestsblock.c | 176 ++- block.h | 2 + block/qcow2.c | 5 - block/qed.c | 7 + block/stream.c | 76 +- block/vvfat.c | 7 + block_int.h | 34 +- blockdev.c | 9 +- cmd.c | 40 +- hmp.c | 2 +- qemu-common.h | 3 + qemu-img.c | 12 +- qemu-io.c | 10 +- qmp-commands.hx | 2 +- tests/Makefile | 4 +- tests/fdc-test.c | 195 +++ tests/libqtest.c | 123 ++- tests/libqtest.h | 17 + tests/qemu-iotests/002.out | 4 +- tests/qemu-iotests/012.out | 2 +- tests/qemu-iotests/016.out | 12 +- tests/qemu-iotests/017.out | 1024 ++++++++-------- tests/qemu-iotests/018.out | 1024 ++++++++-------- tests/qemu-iotests/019.out | 1536 +++++++++++----------- tests/qemu-iotests/020.out | 1024 ++++++++-------- tests/qemu-iotests/023.out | 2880 ++++++++++++++++++++-------------------- tests/qemu-iotests/027.out | 2 +- tests/qemu-iotests/028.out | 448 ++++---- tests/qemu-iotests/030 | 34 +- tests/qemu-iotests/030.out | 4 +- tests/qemu-iotests/033.out | 6 +- tests/qemu-iotests/035.out | 384 +++--- tests/qemu-iotests/iotests.py | 16 +- 33 files changed, 4777 insertions(+), 4347 deletions(-)create mode 100644
tests/fdc-test.c