2022-03-03 18:15:52 +03:00
|
|
|
/*
|
|
|
|
* QEMU Block backends
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2016 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Markus Armbruster <armbru@redhat.com>,
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1
|
|
|
|
* or later. See the COPYING.LIB file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLOCK_BACKEND_IO_H
|
|
|
|
#define BLOCK_BACKEND_IO_H
|
|
|
|
|
|
|
|
#include "block-backend-common.h"
|
2022-12-21 16:35:49 +03:00
|
|
|
#include "block/accounting.h"
|
2022-03-03 18:15:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O API functions. These functions are thread-safe.
|
|
|
|
*
|
|
|
|
* See include/block/block-io.h for more information about
|
|
|
|
* the I/O API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *blk_name(const BlockBackend *blk);
|
|
|
|
|
|
|
|
BlockDriverState *blk_bs(BlockBackend *blk);
|
|
|
|
|
|
|
|
void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
|
|
|
|
void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow);
|
|
|
|
void blk_set_disable_request_queuing(BlockBackend *blk, bool disable);
|
|
|
|
bool blk_iostatus_is_enabled(const BlockBackend *blk);
|
|
|
|
|
|
|
|
char *blk_get_attached_dev_id(BlockBackend *blk);
|
|
|
|
|
|
|
|
BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, BdrvRequestFlags flags,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
|
|
|
|
BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
|
|
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
|
|
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
BlockAIOCB *blk_aio_flush(BlockBackend *blk,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Add zoned device option to host_device BlockDriver. It will be presented only
for zoned host block devices. By adding zone management operations to the
host_block_device BlockDriver, users can use the new block layer APIs
including Report Zone and four zone management operations
(open, close, finish, reset, reset_all).
Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp), zone_open(zo), zone_close(zc), zone_reset(zrs),
zone_finish(zf).
For example, to test zone_report, use following command:
$ ./build/qemu-io --image-opts -n driver=host_device, filename=/dev/nullb0
-c "zrp offset nr_zones"
Signed-off-by: Sam Li <faithilikerun@gmail.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20230508045533.175575-4-faithilikerun@gmail.com
Message-id: 20230324090605.28361-4-faithilikerun@gmail.com
[Adjust commit message prefix as suggested by Philippe Mathieu-Daudé
<philmd@linaro.org> and remove spurious ret = -errno in
raw_co_zone_mgmt().
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2023-05-08 07:55:28 +03:00
|
|
|
BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset,
|
|
|
|
unsigned int *nr_zones,
|
|
|
|
BlockZoneDescriptor *zones,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
|
|
|
|
int64_t offset, int64_t len,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
2023-05-08 08:15:08 +03:00
|
|
|
BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset,
|
|
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
2022-03-03 18:15:52 +03:00
|
|
|
BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
void blk_aio_cancel_async(BlockAIOCB *acb);
|
|
|
|
BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
|
|
|
|
void blk_inc_in_flight(BlockBackend *blk);
|
|
|
|
void blk_dec_in_flight(BlockBackend *blk);
|
2023-01-13 23:42:02 +03:00
|
|
|
|
2023-02-03 18:21:57 +03:00
|
|
|
bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk);
|
|
|
|
bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk);
|
2023-01-13 23:42:02 +03:00
|
|
|
|
2023-02-03 18:21:57 +03:00
|
|
|
bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk);
|
|
|
|
bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk);
|
2023-01-13 23:42:10 +03:00
|
|
|
|
|
|
|
void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked);
|
|
|
|
void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked);
|
2023-01-13 23:42:09 +03:00
|
|
|
|
|
|
|
void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
|
|
|
|
void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag);
|
2023-01-13 23:42:04 +03:00
|
|
|
|
|
|
|
int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
|
|
|
|
int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
|
|
|
|
|
block/export: Fix graph locking in blk_get_geometry() call
blk_get_geometry() eventually calls bdrv_nb_sectors(), which is a
co_wrapper_mixed_bdrv_rdlock. This means that when it is called from
coroutine context, it already assume to have the graph locked.
However, virtio_blk_sect_range_ok() in block/export/virtio-blk-handler.c
(used by vhost-user-blk and VDUSE exports) runs in a coroutine, but
doesn't take the graph lock - blk_*() functions are generally expected
to do that internally. This causes an assertion failure when accessing
an export for the first time if it runs in an iothread.
This is an example of the crash:
$ ./storage-daemon/qemu-storage-daemon --object iothread,id=th0 --blockdev file,filename=/home/kwolf/images/hd.img,node-name=disk --export vhost-user-blk,addr.type=unix,addr.path=/tmp/vhost.sock,node-name=disk,id=exp0,iothread=th0
qemu-storage-daemon: ../block/graph-lock.c:268: void assert_bdrv_graph_readable(void): Assertion `qemu_in_main_thread() || reader_count()' failed.
(gdb) bt
#0 0x00007ffff6eafe5c in __pthread_kill_implementation () from /lib64/libc.so.6
#1 0x00007ffff6e5fa76 in raise () from /lib64/libc.so.6
#2 0x00007ffff6e497fc in abort () from /lib64/libc.so.6
#3 0x00007ffff6e4971b in __assert_fail_base.cold () from /lib64/libc.so.6
#4 0x00007ffff6e58656 in __assert_fail () from /lib64/libc.so.6
#5 0x00005555556337a3 in assert_bdrv_graph_readable () at ../block/graph-lock.c:268
#6 0x00005555555fd5a2 in bdrv_co_nb_sectors (bs=0x5555564c5ef0) at ../block.c:5847
#7 0x00005555555ee949 in bdrv_nb_sectors (bs=0x5555564c5ef0) at block/block-gen.c:256
#8 0x00005555555fd6b9 in bdrv_get_geometry (bs=0x5555564c5ef0, nb_sectors_ptr=0x7fffef7fedd0) at ../block.c:5884
#9 0x000055555562ad6d in blk_get_geometry (blk=0x5555564cb200, nb_sectors_ptr=0x7fffef7fedd0) at ../block/block-backend.c:1624
#10 0x00005555555ddb74 in virtio_blk_sect_range_ok (blk=0x5555564cb200, block_size=512, sector=0, size=512) at ../block/export/virtio-blk-handler.c:44
#11 0x00005555555dd80d in virtio_blk_process_req (handler=0x5555564cbb98, in_iov=0x7fffe8003830, out_iov=0x7fffe8003860, in_num=1, out_num=0) at ../block/export/virtio-blk-handler.c:189
#12 0x00005555555dd546 in vu_blk_virtio_process_req (opaque=0x7fffe8003800) at ../block/export/vhost-user-blk-server.c:66
#13 0x00005555557bf4a1 in coroutine_trampoline (i0=-402635264, i1=32767) at ../util/coroutine-ucontext.c:177
#14 0x00007ffff6e75c20 in ?? () from /lib64/libc.so.6
#15 0x00007fffefffa870 in ?? ()
#16 0x0000000000000000 in ?? ()
Fix this by creating a new blk_co_get_geometry() that takes the lock,
and changing blk_get_geometry() to be a co_wrapper_mixed around it.
To make the resulting code cleaner, virtio-blk-handler.c can directly
call the coroutine version now (though that wouldn't be necessary for
fixing the bug, taking the lock in blk_co_get_geometry() is what fixes
it).
Fixes: 8ab8140a04cf771d63e9754d6ba6c1e676bfe507
Reported-by: Lukáš Doktor <ldoktor@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230327113959.60071-1-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2023-03-27 14:39:59 +03:00
|
|
|
void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
|
|
|
|
uint64_t *nb_sectors_ptr);
|
2023-04-07 18:33:03 +03:00
|
|
|
void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
|
2023-01-13 23:42:04 +03:00
|
|
|
|
|
|
|
int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk);
|
2023-04-07 18:33:03 +03:00
|
|
|
int64_t blk_nb_sectors(BlockBackend *blk);
|
2023-01-13 23:42:04 +03:00
|
|
|
|
2022-03-03 18:15:52 +03:00
|
|
|
void *blk_try_blockalign(BlockBackend *blk, size_t size);
|
|
|
|
void *blk_blockalign(BlockBackend *blk, size_t size);
|
|
|
|
bool blk_is_writable(BlockBackend *blk);
|
|
|
|
bool blk_enable_write_cache(BlockBackend *blk);
|
|
|
|
BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
|
|
|
|
BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
|
|
|
|
int error);
|
|
|
|
void blk_error_action(BlockBackend *blk, BlockErrorAction action,
|
|
|
|
bool is_read, int error);
|
|
|
|
void blk_iostatus_set_err(BlockBackend *blk, int error);
|
|
|
|
int blk_get_max_iov(BlockBackend *blk);
|
|
|
|
int blk_get_max_hw_iov(BlockBackend *blk);
|
|
|
|
|
|
|
|
AioContext *blk_get_aio_context(BlockBackend *blk);
|
|
|
|
BlockAcctStats *blk_get_stats(BlockBackend *blk);
|
|
|
|
void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
|
|
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
|
|
BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
|
|
|
|
BlockCompletionFunc *cb,
|
|
|
|
void *opaque, int ret);
|
|
|
|
|
|
|
|
uint32_t blk_get_request_alignment(BlockBackend *blk);
|
|
|
|
uint32_t blk_get_max_transfer(BlockBackend *blk);
|
|
|
|
uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
|
|
|
|
|
|
|
|
int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
|
|
|
|
BlockBackend *blk_out, int64_t off_out,
|
|
|
|
int64_t bytes, BdrvRequestFlags read_flags,
|
|
|
|
BdrvRequestFlags write_flags);
|
|
|
|
|
2022-11-28 17:23:27 +03:00
|
|
|
int coroutine_fn blk_co_block_status_above(BlockBackend *blk,
|
|
|
|
BlockDriverState *base,
|
|
|
|
int64_t offset, int64_t bytes,
|
|
|
|
int64_t *pnum, int64_t *map,
|
|
|
|
BlockDriverState **file);
|
|
|
|
int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk,
|
|
|
|
BlockDriverState *base,
|
|
|
|
bool include_base, int64_t offset,
|
|
|
|
int64_t bytes, int64_t *pnum);
|
2022-03-03 18:15:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "I/O or GS" API functions. These functions can run without
|
|
|
|
* the BQL, but only in one specific iothread/main loop.
|
|
|
|
*
|
|
|
|
* See include/block/block-io.h for more information about
|
|
|
|
* the "I/O or GS" API.
|
|
|
|
*/
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pread(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, void *buf,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
|
|
|
|
void *buf, BdrvRequestFlags flags);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_preadv(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_preadv_part(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
size_t qiov_offset,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:16 +03:00
|
|
|
int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
size_t qiov_offset, BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pwrite(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, const void *buf,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
|
|
|
|
const void *buf, BdrvRequestFlags flags);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pwritev(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pwritev_part(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, QEMUIOVector *qiov,
|
|
|
|
size_t qiov_offset,
|
|
|
|
BdrvRequestFlags flags);
|
2022-03-03 18:15:52 +03:00
|
|
|
int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes,
|
|
|
|
QEMUIOVector *qiov, size_t qiov_offset,
|
|
|
|
BdrvRequestFlags flags);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pwrite_compressed(BlockBackend *blk,
|
|
|
|
int64_t offset, int64_t bytes,
|
|
|
|
const void *buf);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, const void *buf);
|
2022-03-03 18:15:52 +03:00
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes,
|
|
|
|
BdrvRequestFlags flags);
|
2022-07-05 19:15:25 +03:00
|
|
|
int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes, BdrvRequestFlags flags);
|
block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Add zoned device option to host_device BlockDriver. It will be presented only
for zoned host block devices. By adding zone management operations to the
host_block_device BlockDriver, users can use the new block layer APIs
including Report Zone and four zone management operations
(open, close, finish, reset, reset_all).
Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp), zone_open(zo), zone_close(zc), zone_reset(zrs),
zone_finish(zf).
For example, to test zone_report, use following command:
$ ./build/qemu-io --image-opts -n driver=host_device, filename=/dev/nullb0
-c "zrp offset nr_zones"
Signed-off-by: Sam Li <faithilikerun@gmail.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20230508045533.175575-4-faithilikerun@gmail.com
Message-id: 20230324090605.28361-4-faithilikerun@gmail.com
[Adjust commit message prefix as suggested by Philippe Mathieu-Daudé
<philmd@linaro.org> and remove spurious ret = -errno in
raw_co_zone_mgmt().
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2023-05-08 07:55:28 +03:00
|
|
|
|
|
|
|
int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset,
|
|
|
|
unsigned int *nr_zones,
|
|
|
|
BlockZoneDescriptor *zones);
|
|
|
|
int co_wrapper_mixed blk_zone_report(BlockBackend *blk, int64_t offset,
|
|
|
|
unsigned int *nr_zones,
|
|
|
|
BlockZoneDescriptor *zones);
|
|
|
|
int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
|
|
|
|
int64_t offset, int64_t len);
|
|
|
|
int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
|
|
|
|
int64_t offset, int64_t len);
|
2023-05-08 08:15:08 +03:00
|
|
|
int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset,
|
|
|
|
QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
|
|
|
int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset,
|
|
|
|
QEMUIOVector *qiov,
|
|
|
|
BdrvRequestFlags flags);
|
2022-03-03 18:15:52 +03:00
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes);
|
2022-03-03 18:15:52 +03:00
|
|
|
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
|
|
|
|
int64_t bytes);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_flush(BlockBackend *blk);
|
2022-03-03 18:15:52 +03:00
|
|
|
int coroutine_fn blk_co_flush(BlockBackend *blk);
|
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_ioctl(BlockBackend *blk, unsigned long int req,
|
|
|
|
void *buf);
|
2022-07-05 19:15:23 +03:00
|
|
|
int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
|
|
|
|
void *buf);
|
2022-03-03 18:15:52 +03:00
|
|
|
|
2022-11-28 17:23:32 +03:00
|
|
|
int co_wrapper_mixed blk_truncate(BlockBackend *blk, int64_t offset,
|
|
|
|
bool exact, PreallocMode prealloc,
|
|
|
|
BdrvRequestFlags flags, Error **errp);
|
2022-07-05 19:15:24 +03:00
|
|
|
int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
|
|
|
|
PreallocMode prealloc, BdrvRequestFlags flags,
|
|
|
|
Error **errp);
|
2022-03-03 18:15:52 +03:00
|
|
|
|
|
|
|
#endif /* BLOCK_BACKEND_IO_H */
|