Skip to content

Commit 0462a32

Browse files
committed
Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging
Block layer patches - virtio-scsi: add iothread-vq-mapping parameter - Improve writethrough performance - Fix missing zero init in bdrv_snapshot_goto() - Added scripts/qcow2-to-stdout.py - Code cleanup and iotests fixes # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmfTDysRHGt3b2xmQHJl # ZGhhdC5jb20ACgkQfwmycsiPL9Yz6A//asOl37zjbtf9pYjY/gliH859TQOppPGD # LB9IIr+nTDME0wfUkCOlag+CeEYZwkeo2PF+XeopsyzlJeBOk4tL7AkY57XYe3lZ # M5hlnNrn6l3gb6iioMg60pEKSMrpKprB16vT3nAtyN6aEXsm9TvtPkWPFTCFGVeK # W74VCr7wuXbfdEJcOGd8WhB9ZHIgwoWYnoL41tvCoefW2yNaMA6X0TLn98toXzOi # il50ZnnchTQngns5R+n+1R1Ma995t393D+CArQcYVRzxKGOs5p0y4otz4gCkMhdp # GVL09R7Ge4TteSJ2myxlN/EjYOxmdoMrVDajr4xPdHBw12MKzgk8i82h4/Es/Q5o # 3Npgx74+jDyqlICb/czTVM5KJINpyO80vO3N3WpYUOQGyTCcYgv7pIpy8pB2o6Te # RPlv0W9bHVSSgThFFLQ0Ud8WRGJe1K/ar8bdmiWN08Wez1avENWaYmsv5zGnFL24 # vD6cNXMR4mF7mzyeWda/5hGKv75djVgX+ZfzvWNT3qgizD56JBOA3RdCRwBZJOJb # TvJkfi5RGyaji9BfKVCYBL3/iDELJEVDW8jxvIIUrS0aPcTHpAQ5gTO7VAokreqZ # 5Smll11eeoEgPPvNLw8ikmOGTWOMkJGrmExP2K1ApANq3kSbBSU4jroEr0BG9PZT # 6Y0hUdtFSdU= # =w2Ri # -----END PGP SIGNATURE----- # gpg: Signature made Fri 14 Mar 2025 01:00:27 HKT # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "[email protected]" # gpg: Good signature from "Kevin Wolf <[email protected]>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * tag 'for-upstream' of https://repo.or.cz/qemu/kevin: (23 commits) scripts/qcow2-to-stdout.py: Add script to write qcow2 images to stdout virtio-scsi: only expose cmd vqs via iothread-vq-mapping virtio-scsi: handle ctrl virtqueue in main loop virtio-scsi: add iothread-vq-mapping parameter virtio: extract iothread-vq-mapping.h API virtio-blk: tidy up iothread_vq_mapping functions virtio-blk: extract cleanup_iothread_vq_mapping() function virtio-scsi: perform TMFs in appropriate AioContexts virtio-scsi: protect events_dropped field virtio-scsi: introduce event and ctrl virtqueue locks scsi: introduce requests_lock scsi: track per-SCSIRequest AioContext dma: use current AioContext for dma_blk_io() scsi-disk: drop unused SCSIDiskState->bh field iotests: Limit qsd-migrate to working formats aio-posix: Adjust polling time also for new handlers aio-posix: Separate AioPolledEvent per AioHandler aio-posix: Factor out adjust_polling_time() aio: Create AioPolledEvent block/io: Ignore FUA with cache.no-flush=on ... Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents 28ea66f + df95711 commit 0462a32

30 files changed

+1286
-511
lines changed

block/block-backend.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,18 +2357,6 @@ void *blk_blockalign(BlockBackend *blk, size_t size)
23572357
return qemu_blockalign(blk ? blk_bs(blk) : NULL, size);
23582358
}
23592359

2360-
bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp)
2361-
{
2362-
BlockDriverState *bs = blk_bs(blk);
2363-
GLOBAL_STATE_CODE();
2364-
GRAPH_RDLOCK_GUARD_MAINLOOP();
2365-
2366-
if (!bs) {
2367-
return false;
2368-
}
2369-
2370-
return bdrv_op_is_blocked(bs, op, errp);
2371-
}
23722360

23732361
/**
23742362
* Return BB's current AioContext. Note that this context may change

block/file-posix.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static int fd_open(BlockDriverState *bs)
194194
}
195195

196196
static int64_t raw_getlength(BlockDriverState *bs);
197+
static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs);
197198

198199
typedef struct RawPosixAIOData {
199200
BlockDriverState *bs;
@@ -804,6 +805,13 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
804805
#endif
805806
s->needs_alignment = raw_needs_alignment(bs);
806807

808+
bs->supported_write_flags = BDRV_REQ_FUA;
809+
if (s->use_linux_aio && !laio_has_fua()) {
810+
bs->supported_write_flags &= ~BDRV_REQ_FUA;
811+
} else if (s->use_linux_io_uring && !luring_has_fua()) {
812+
bs->supported_write_flags &= ~BDRV_REQ_FUA;
813+
}
814+
807815
bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK;
808816
if (S_ISREG(st.st_mode)) {
809817
/* When extending regular files, we get zeros from the OS */
@@ -2477,7 +2485,8 @@ static inline bool raw_check_linux_aio(BDRVRawState *s)
24772485
#endif
24782486

24792487
static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr,
2480-
uint64_t bytes, QEMUIOVector *qiov, int type)
2488+
uint64_t bytes, QEMUIOVector *qiov, int type,
2489+
int flags)
24812490
{
24822491
BDRVRawState *s = bs->opaque;
24832492
RawPosixAIOData acb;
@@ -2508,13 +2517,13 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr,
25082517
#ifdef CONFIG_LINUX_IO_URING
25092518
} else if (raw_check_linux_io_uring(s)) {
25102519
assert(qiov->size == bytes);
2511-
ret = luring_co_submit(bs, s->fd, offset, qiov, type);
2520+
ret = luring_co_submit(bs, s->fd, offset, qiov, type, flags);
25122521
goto out;
25132522
#endif
25142523
#ifdef CONFIG_LINUX_AIO
25152524
} else if (raw_check_linux_aio(s)) {
25162525
assert(qiov->size == bytes);
2517-
ret = laio_co_submit(s->fd, offset, qiov, type,
2526+
ret = laio_co_submit(s->fd, offset, qiov, type, flags,
25182527
s->aio_max_batch);
25192528
goto out;
25202529
#endif
@@ -2534,6 +2543,10 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr,
25342543

25352544
assert(qiov->size == bytes);
25362545
ret = raw_thread_pool_submit(handle_aiocb_rw, &acb);
2546+
if (ret == 0 && (flags & BDRV_REQ_FUA)) {
2547+
/* TODO Use pwritev2() instead if it's available */
2548+
ret = raw_co_flush_to_disk(bs);
2549+
}
25372550
goto out; /* Avoid the compiler err of unused label */
25382551

25392552
out:
@@ -2571,14 +2584,14 @@ static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset,
25712584
int64_t bytes, QEMUIOVector *qiov,
25722585
BdrvRequestFlags flags)
25732586
{
2574-
return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ);
2587+
return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ, flags);
25752588
}
25762589

25772590
static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offset,
25782591
int64_t bytes, QEMUIOVector *qiov,
25792592
BdrvRequestFlags flags)
25802593
{
2581-
return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE);
2594+
return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE, flags);
25822595
}
25832596

25842597
static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs)
@@ -2600,12 +2613,12 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs)
26002613

26012614
#ifdef CONFIG_LINUX_IO_URING
26022615
if (raw_check_linux_io_uring(s)) {
2603-
return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH);
2616+
return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH, 0);
26042617
}
26052618
#endif
26062619
#ifdef CONFIG_LINUX_AIO
26072620
if (s->has_laio_fdsync && raw_check_linux_aio(s)) {
2608-
return laio_co_submit(s->fd, 0, NULL, QEMU_AIO_FLUSH, 0);
2621+
return laio_co_submit(s->fd, 0, NULL, QEMU_AIO_FLUSH, 0, 0);
26092622
}
26102623
#endif
26112624
return raw_thread_pool_submit(handle_aiocb_flush, &acb);
@@ -3540,7 +3553,7 @@ static int coroutine_fn raw_co_zone_append(BlockDriverState *bs,
35403553
}
35413554

35423555
trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS);
3543-
return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND);
3556+
return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND, 0);
35443557
}
35453558
#endif
35463559

block/io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,10 @@ bdrv_driver_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
10581058
return -ENOMEDIUM;
10591059
}
10601060

1061+
if (bs->open_flags & BDRV_O_NO_FLUSH) {
1062+
flags &= ~BDRV_REQ_FUA;
1063+
}
1064+
10611065
if ((flags & BDRV_REQ_FUA) &&
10621066
(~bs->supported_write_flags & BDRV_REQ_FUA)) {
10631067
flags &= ~BDRV_REQ_FUA;

block/io_uring.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,24 @@ static void luring_deferred_fn(void *opaque)
335335
*
336336
*/
337337
static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s,
338-
uint64_t offset, int type)
338+
uint64_t offset, int type, BdrvRequestFlags flags)
339339
{
340340
int ret;
341341
struct io_uring_sqe *sqes = &luringcb->sqeq;
342342

343343
switch (type) {
344344
case QEMU_AIO_WRITE:
345+
#ifdef HAVE_IO_URING_PREP_WRITEV2
346+
{
347+
int luring_flags = (flags & BDRV_REQ_FUA) ? RWF_DSYNC : 0;
348+
io_uring_prep_writev2(sqes, fd, luringcb->qiov->iov,
349+
luringcb->qiov->niov, offset, luring_flags);
350+
}
351+
#else
352+
assert(flags == 0);
345353
io_uring_prep_writev(sqes, fd, luringcb->qiov->iov,
346354
luringcb->qiov->niov, offset);
355+
#endif
347356
break;
348357
case QEMU_AIO_ZONE_APPEND:
349358
io_uring_prep_writev(sqes, fd, luringcb->qiov->iov,
@@ -380,7 +389,8 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s,
380389
}
381390

382391
int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset,
383-
QEMUIOVector *qiov, int type)
392+
QEMUIOVector *qiov, int type,
393+
BdrvRequestFlags flags)
384394
{
385395
int ret;
386396
AioContext *ctx = qemu_get_current_aio_context();
@@ -393,7 +403,7 @@ int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset,
393403
};
394404
trace_luring_co_submit(bs, s, &luringcb, fd, offset, qiov ? qiov->size : 0,
395405
type);
396-
ret = luring_do_submit(fd, &luringcb, s, offset, type);
406+
ret = luring_do_submit(fd, &luringcb, s, offset, type, flags);
397407

398408
if (ret < 0) {
399409
return ret;
@@ -448,3 +458,12 @@ void luring_cleanup(LuringState *s)
448458
trace_luring_cleanup_state(s);
449459
g_free(s);
450460
}
461+
462+
bool luring_has_fua(void)
463+
{
464+
#ifdef HAVE_IO_URING_PREP_WRITEV2
465+
return true;
466+
#else
467+
return false;
468+
#endif
469+
}

block/linux-aio.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,24 @@ static void laio_deferred_fn(void *opaque)
368368
}
369369

370370
static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
371-
int type, uint64_t dev_max_batch)
371+
int type, BdrvRequestFlags flags,
372+
uint64_t dev_max_batch)
372373
{
373374
LinuxAioState *s = laiocb->ctx;
374375
struct iocb *iocbs = &laiocb->iocb;
375376
QEMUIOVector *qiov = laiocb->qiov;
376377

377378
switch (type) {
378379
case QEMU_AIO_WRITE:
380+
#ifdef HAVE_IO_PREP_PWRITEV2
381+
{
382+
int laio_flags = (flags & BDRV_REQ_FUA) ? RWF_DSYNC : 0;
383+
io_prep_pwritev2(iocbs, fd, qiov->iov, qiov->niov, offset, laio_flags);
384+
}
385+
#else
386+
assert(flags == 0);
379387
io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset);
388+
#endif
380389
break;
381390
case QEMU_AIO_ZONE_APPEND:
382391
io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset);
@@ -409,7 +418,8 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
409418
}
410419

411420
int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov,
412-
int type, uint64_t dev_max_batch)
421+
int type, BdrvRequestFlags flags,
422+
uint64_t dev_max_batch)
413423
{
414424
int ret;
415425
AioContext *ctx = qemu_get_current_aio_context();
@@ -422,7 +432,7 @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov,
422432
.qiov = qiov,
423433
};
424434

425-
ret = laio_do_submit(fd, &laiocb, offset, type, dev_max_batch);
435+
ret = laio_do_submit(fd, &laiocb, offset, type, flags, dev_max_batch);
426436
if (ret < 0) {
427437
return ret;
428438
}
@@ -505,3 +515,12 @@ bool laio_has_fdsync(int fd)
505515
io_destroy(ctx);
506516
return (ret == -EINVAL) ? false : true;
507517
}
518+
519+
bool laio_has_fua(void)
520+
{
521+
#ifdef HAVE_IO_PREP_PWRITEV2
522+
return true;
523+
#else
524+
return false;
525+
#endif
526+
}

block/snapshot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
296296
bdrv_graph_wrunlock();
297297

298298
ret = bdrv_snapshot_goto(fallback_bs, snapshot_id, errp);
299+
memset(bs->opaque, 0, drv->instance_size);
299300
open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err);
300301
qobject_unref(options);
301302
if (open_ret < 0) {

0 commit comments

Comments
 (0)