Block patches
The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81:
Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 9f460c64e13897117f35ffb61f6f5e0102cabc70:
block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100)
----------------------------------------------------------------
Pull request
----------------------------------------------------------------
Akihiko Odaki (3):
block/file-posix: Optimize for macOS
block: Add backend_defaults property
block/io: Merge discard request alignments
Stefan Hajnoczi (2):
util/async: add a human-readable name to BHs for debugging util/async: print leaked BH name when AioContext finalizes
include/block/aio.h | 31 ++++++++++++++++++++++--- include/hw/block/block.h | 3 +++ include/qemu/main-loop.h | 4 +++- block/file-posix.c | 27 ++++++++++++++++++++-- block/io.c | 2 ++ hw/block/block.c | 42 ++++++++++++++++++++++++++++++---- tests/unit/ptimer-test-stubs.c | 2 +- util/async.c | 25 ++++++++++++++++---- util/main-loop.c | 4 ++-- tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++ 10 files changed, 161 insertions(+), 17 deletions(-)
Signature · 1 line
2.31.1
[PULL 4/5] block: Add backend_defaults property
From: Akihiko Odaki <[email protected]>
backend_defaults property allow users to control if default block properties should be decided with backend information.
If it is off, any backend information will be discarded, which is suitable if you plan to perform live migration to a different disk backend.
If it is on, a block device may utilize backend information more aggressively.
By default, it is auto, which uses backend information for block sizes and ignores the others, which is consistent with the older versions.
Message-id: [email protected]
--- include/hw/block/block.h | 3 +++ hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++---- tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-)
include/hw/block/block.h +3 -0
@@ -19,6 +19,7 @@ typedef struct BlockConf { BlockBackend *blk; + OnOffAuto backend_defaults; uint32_t physical_block_size; uint32_t logical_block_size; uint32_t min_io_size;
@@ -48,6 +49,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) }#define DEFINE_BLOCK_PROPERTIES_BASE (_state, _conf) \ + DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \ + _conf.backend_defaults, ON_OFF_AUTO_AUTO), \ DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ _conf.logical_block_size), \ DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
hw/block/block.c +38 -4
62 lines not on this page · raw message
tests/qemu-iotests/172.out +38 -0
@@ -21,6 +21,7 @@ Testing: dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -48,6 +49,7 @@ Testing: -fda TEST_DIR/t.qcow2 dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -85,6 +87,7 @@ Testing: -fdb TEST_DIR/t.qcow2 dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -96,6 +99,7 @@ Testing: -fdb TEST_DIR/t.qcow2 dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -137,6 +141,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -148,6 +153,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -190,6 +196,7 @@ Testing: -fdb dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -201,6 +208,7 @@ Testing: -fdb dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -228,6 +236,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -265,6 +274,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -276,6 +286,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -317,6 +328,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -328,6 +340,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -373,6 +386,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -410,6 +424,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1 dev: floppy, id "" unit = 1 (0x1) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -447,6 +462,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco dev: floppy, id "" unit = 1 (0x1) drive = "none1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -458,6 +474,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -509,6 +526,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 1 (0x1) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -520,6 +538,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -562,6 +581,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 1 (0x1) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -573,6 +593,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -615,6 +636,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -626,6 +648,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -668,6 +691,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -679,6 +703,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit = 1 (0x1) drive = "floppy1" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -730,6 +755,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q dev: floppy, id "" unit = 1 (0x1) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -741,6 +767,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -783,6 +810,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q dev: floppy, id "" unit = 1 (0x1) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -794,6 +822,7 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q dev: floppy, id "" unit = 0 (0x0) drive = "floppy0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -842,6 +871,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -909,6 +939,7 @@ Testing: -device floppy dev: floppy, id "" unit = 0 (0x0) drive = "" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -933,6 +964,7 @@ Testing: -device floppy,drive-type=120 dev: floppy, id "" unit = 0 (0x0) drive = "" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -957,6 +989,7 @@ Testing: -device floppy,drive-type=144 dev: floppy, id "" unit = 0 (0x0) drive = "" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -981,6 +1014,7 @@ Testing: -device floppy,drive-type=288 dev: floppy, id "" unit = 0 (0x0) drive = "" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -1008,6 +1042,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -1045,6 +1080,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -1085,6 +1121,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
@@ -1122,6 +1159,7 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica dev: floppy, id "" unit = 0 (0x0) drive = "none0" + backend_defaults = "auto" logical_block_size = 512 (512 B) physical_block_size = 512 (512 B) min_io_size = 0 (0 B)
Signature · 1 line
2.31.1
[PULL 1/5] util/async: add a human-readable name to BHs for debugging
In reply to Stefan HajnocziIt can be difficult to debug issues with BHs in production environments. Although BHs can usually be identified by looking up their ->cb() function pointer, this requires debug information for the program. It is also not possible to print human-readable diagnostics about BHs because they have no identifier.
This patch adds a name to each BH. The name is not unique per instance but differentiates between cb() functions, which is usually enough. It's done by changing aio_bh_new() and friends to macros that stringify cb.
The next patch will use the name field when reporting leaked BHs.
Message-Id: <[email protected]>
--- include/block/aio.h | 31 ++++++++++++++++++++++++++++--- include/qemu/main-loop.h | 4 +++- tests/unit/ptimer-test-stubs.c | 2 +- util/async.c | 9 +++++++-- util/main-loop.c | 4 ++-- 5 files changed, 41 insertions(+), 9 deletions(-)
include/block/aio.h +28 -3
@@ -291,20 +291,45 @@ void aio_context_acquire(AioContext *ctx);/* Relinquish ownership of the AioContext. */ void aio_context_release (AioContext *ctx); +/** +* aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will +* run only once and as soon as possible. +* +* @name: A human-readable identifier for debugging purposes. +*/ +void aio_bh_schedule_oneshot_full (AioContext *ctx,QEMUBHFunc *cb,void *opaque, +const char *name); +/** * aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run * only once and as soon as possible. +* +* A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the +* name string. */ -void aio_bh_schedule_oneshot (AioContext *ctx,QEMUBHFunc *cb,void *opaque); +#define aio_bh_schedule_oneshot (ctx, cb, opaque) \ + aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb)))/** -* aio_bh_new: Allocate a new bottom half structure. +* aio_bh_new_full: Allocate a new bottom half structure. * * Bottom halves are lightweight callbacks whose invocation is guaranteed * to be wait-free, thread-safe and signal-safe. The #QEMUBH structure * is opaque and must be allocated prior to its use. +* +* @name: A human-readable identifier for debugging purposes. */ -QEMUBH *aio_bh_new (AioContext *ctx,QEMUBHFunc *cb,void *opaque); +QEMUBH *aio_bh_new_full (AioContext *ctx,QEMUBHFunc *cb,void *opaque, +const char *name); + +/** +* aio_bh_new: Allocate a new bottom half structure +* +* A convenience wrapper for aio_bh_new_full() that uses the cb as the name +* string. +*/ +#define aio_bh_new (ctx, cb, opaque) \ + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)))/** * aio_notify: Force processing of pending events.
include/qemu/main-loop.h +3 -1
@@ -294,7 +294,9 @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);void qemu_fd_register (int fd); -QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque); +#define qemu_bh_new (cb, opaque) \ + qemu_bh_new_full((cb), (opaque), (stringify(cb))) +QEMUBH *qemu_bh_new_full (QEMUBHFunc *cb,void *opaque,const char *name);void qemu_bh_schedule_idle (QEMUBH *bh);enum {
tests/unit/ptimer-test-stubs.c +1 -1
@@ -108,7 +108,7 @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)return deadline; } -QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque) +QEMUBH *qemu_bh_new_full (QEMUBHFunc *cb,void *opaque,const char *name) {QEMUBH *bh =g_new (QEMUBH ,1 );
util/async.c +7 -2
@@ -57,6 +57,7 @@ enum {struct QEMUBH {AioContext *ctx; +const char *name;QEMUBHFunc *cb;void *opaque;QSLIST_ENTRY (QEMUBH) next;
@@ -107,7 +108,8 @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags)return bh; } -void aio_bh_schedule_oneshot (AioContext *ctx,QEMUBHFunc *cb,void *opaque) +void aio_bh_schedule_oneshot_full (AioContext *ctx,QEMUBHFunc *cb, +void *opaque,const char *name) {QEMUBH *bh; bh =g_new (QEMUBH ,1 );
@@ -115,11 +117,13 @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) .ctx = ctx, .cb = cb, .opaque = opaque, + .name = name, };aio_bh_enqueue (bh,BH_SCHEDULED |BH_ONESHOT ); } -QEMUBH *aio_bh_new (AioContext *ctx,QEMUBHFunc *cb,void *opaque) +QEMUBH *aio_bh_new_full (AioContext *ctx,QEMUBHFunc *cb,void *opaque, +const char *name) {QEMUBH *bh; bh =g_new (QEMUBH ,1 );
@@ -127,6 +131,7 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) .ctx = ctx, .cb = cb, .opaque = opaque, + .name = name, };return bh; }
util/main-loop.c +2 -2
@@ -544,9 +544,9 @@ void main_loop_wait(int nonblocking)/* Functions to operate on the main QEMU AioContext. */ -QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque) +QEMUBH *qemu_bh_new_full (QEMUBHFunc *cb,void *opaque,const char *name) { -return aio_bh_new (qemu_aio_context, cb, opaque); +return aio_bh_new_full (qemu_aio_context, cb, opaque, name); }/*
Signature · 1 line
2.31.1
[PULL 5/5] block/io: Merge discard request alignments
In reply to Stefan HajnocziFrom: Akihiko Odaki <[email protected]>
Message-id: [email protected]
--- block/io.c | 2 ++ 1 file changed, 2 insertions(+)
block/io.c +2 -0
@@ -125,6 +125,8 @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)static void bdrv_merge_limits (BlockLimits *dst,const BlockLimits *src) { + dst->pdiscard_alignment =MAX (dst->pdiscard_alignment, + src->pdiscard_alignment); dst->opt_transfer =MAX (dst->opt_transfer, src->opt_transfer); dst->max_transfer =MIN_NON_ZERO (dst->max_transfer, src->max_transfer); dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer,
Signature · 1 line
2.31.1
[PULL 3/5] block/file-posix: Optimize for macOS
In reply to Stefan HajnocziFrom: Akihiko Odaki <[email protected]>
This commit introduces "punch hole" operation and optimizes transfer block size for macOS.
Thanks to Konstantin Nazarov for detailed analysis of a flaw in an old version of this change:
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667
Message-id: [email protected]
--- block/file-posix.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
block/file-posix.c +25 -2
@@ -46,6 +46,7 @@#if defined(HAVE_HOST_BLOCK_DEVICE )#include <paths.h> #include <sys/param.h> +#include <sys/mount.h> #include <IOKit/IOKitLib.h> #include <IOKit/IOBSD.h> #include <IOKit/storage/IOMediaBSDClient.h>
@@ -1254,6 +1255,15 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)return ; } +#if defined(__APPLE__) && (__MACH__) +struct statfs buf; + +if (!fstatfs (s->fd, &buf)) { + bs->bl.opt_transfer = buf.f_iosize; + bs->bl.pdiscard_alignment = buf.f_bsize; + } +#endif +if (bs->sg ||S_ISBLK (st.st_mode)) {int ret =hdev_get_max_hw_transfer (s->fd, &st);
@@ -1591,6 +1601,7 @@ out: } } +#if defined(CONFIG_FALLOCATE ) || defined(BLKZEROOUT ) || defined(BLKDISCARD )static int translate_err (int err) { if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP ||
@@ -1599,6 +1610,7 @@ static int translate_err(int err) }return err; } +#endif #ifdef CONFIG_FALLOCATE static int do_fallocate (int fd,int mode,off_t offset,off_t len)
@@ -1811,16 +1823,27 @@ static int handle_aiocb_discard(void *opaque) } }while (errno ==EINTR ); - ret = -errno; + ret =translate_err (-errno);#endif }else {#ifdef CONFIG_FALLOCATE_PUNCH_HOLE ret =do_fallocate (s->fd,FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE , aiocb->aio_offset, aiocb->aio_nbytes); + ret =translate_err (-errno); +#elif defined(__APPLE__) && (__MACH__) +fpunchhole_t fpunchhole; + fpunchhole.fp_flags =0 ; + fpunchhole.reserved =0 ; + fpunchhole.fp_offset = aiocb->aio_offset; + fpunchhole.fp_length = aiocb->aio_nbytes; +if (fcntl (s->fd,F_PUNCHHOLE , &fpunchhole) ==-1 ) { + ret = errno ==ENODEV ? -ENOTSUP : -errno; + }else { + ret =0 ; + }#endif } - ret =translate_err (ret);if (ret == -ENOTSUP ) { s->has_discard = false; }
Signature · 1 line
2.31.1
[PULL 2/5] util/async: print leaked BH name when AioContext finalizes
In reply to Stefan HajnocziBHs must be deleted before the AioContext is finalized. If not, it's a bug and probably indicates that some part of the program still expects the BH to run in the future. That can lead to memory leaks, inconsistent state, or just hangs.
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize() is difficult to debug because the assertion failure contains no information about the BH!
Use the QEMUBH name field added in the previous patch to show a useful error when a leaked BH is detected.
Message-Id: <[email protected]>
--- util/async.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
util/async.c +14 -2
@@ -344,8 +344,20 @@ aio_ctx_finalize(GSource *source)assert (QSIMPLEQ_EMPTY (&ctx->bh_slice_list));while ((bh =aio_bh_dequeue (&ctx->bh_list, &flags))) { -/* qemu_bh_delete() must have been called on BHs in this AioContext */ -assert (flags &BH_DELETED ); +/* +* qemu_bh_delete() must have been called on BHs in this AioContext. In +* many cases memory leaks, hangs, or inconsistent state occur when a +* BH is leaked because something still expects it to run. +* +* If you hit this, fix the lifecycle of the BH so that +* qemu_bh_delete() and any associated cleanup is called before the +* AioContext is finalized. +*/ +if (unlikely (!(flags &BH_DELETED ))) { +fprintf (stderr,"%s: BH '%s' leaked, aborting...\n" , + __func__, bh->name); +abort (); + }g_free (bh); }
Signature · 1 line
2.31.1
Peter Maydell
AppliedQuoted 7 lines · Stefan Hajnoczi
The following changes since commit
711c0418c8c1ce3a24346f058b001c4c5a2f0f81:Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100)
are available in the Git repository at:
Quoted 9 lines
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
9f460c64e13897117f35ffb61f6f5e0102cabc70:block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100)
----------------------------------------------------------------
Pull request
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.
-- PMM