Compare commits
9 Commits
migration-
...
qmp-bql--2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e452599063 | ||
|
|
cd4043e8ba | ||
|
|
eb4f25a12a | ||
|
|
4e27ebb579 | ||
| b7dcc04ac1 | |||
|
|
66fcfd864d | ||
|
|
fa1bec927d | ||
|
|
685c04eeb3 | ||
|
|
ad1c10b265 |
2
block.c
2
block.c
@@ -6344,7 +6344,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool flat,
|
||||
BlockDriverState *bs;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
GRAPH_RDLOCK_GUARD();
|
||||
|
||||
list = NULL;
|
||||
QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) {
|
||||
|
||||
@@ -226,6 +226,9 @@ typedef struct RawPosixAIOData {
|
||||
struct {
|
||||
unsigned long op;
|
||||
} zone_mgmt;
|
||||
struct {
|
||||
struct stat *st;
|
||||
} fstat;
|
||||
};
|
||||
} RawPosixAIOData;
|
||||
|
||||
@@ -2613,6 +2616,34 @@ static void raw_close(BlockDriverState *bs)
|
||||
}
|
||||
}
|
||||
|
||||
static int handle_aiocb_fstat(void *opaque)
|
||||
{
|
||||
RawPosixAIOData *aiocb = opaque;
|
||||
|
||||
if (fstat(aiocb->aio_fildes, aiocb->fstat.st) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_fstat(BlockDriverState *bs, struct stat *st)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
RawPosixAIOData acb;
|
||||
|
||||
acb = (RawPosixAIOData) {
|
||||
.bs = bs,
|
||||
.aio_fildes = s->fd,
|
||||
.aio_type = QEMU_AIO_FSTAT,
|
||||
.fstat = {
|
||||
.st = st,
|
||||
},
|
||||
};
|
||||
|
||||
return raw_thread_pool_submit(handle_aiocb_fstat, &acb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates the given regular file @fd to @offset and, when growing, fills the
|
||||
* new space according to @prealloc.
|
||||
@@ -2857,11 +2888,14 @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
|
||||
static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverState *bs)
|
||||
{
|
||||
struct stat st;
|
||||
BDRVRawState *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
if (fstat(s->fd, &st) < 0) {
|
||||
return -errno;
|
||||
ret = raw_co_fstat(bs, &st);
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return (int64_t)st.st_blocks * 512;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ block_gen_c = custom_target('block-gen.c',
|
||||
'../include/block/dirty-bitmap.h',
|
||||
'../include/block/block_int-io.h',
|
||||
'../include/block/block-global-state.h',
|
||||
'../include/block/qapi.h',
|
||||
'../include/sysemu/block-backend-global-state.h',
|
||||
'../include/sysemu/block-backend-io.h',
|
||||
'coroutines.h'
|
||||
|
||||
@@ -400,7 +400,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||
bool writable = qdict_get_try_bool(qdict, "writable", false);
|
||||
bool all = qdict_get_try_bool(qdict, "all", false);
|
||||
Error *local_err = NULL;
|
||||
BlockInfoList *block_list, *info;
|
||||
BlockBackend *blk;
|
||||
SocketAddress *addr;
|
||||
NbdServerAddOptions export;
|
||||
|
||||
@@ -425,18 +425,24 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Then try adding all block devices. If one fails, close all and
|
||||
/*
|
||||
* Then try adding all block devices. If one fails, close all and
|
||||
* exit.
|
||||
*/
|
||||
block_list = qmp_query_block(NULL);
|
||||
for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
|
||||
for (info = block_list; info; info = info->next) {
|
||||
if (!info->value->inserted) {
|
||||
if (!*blk_name(blk) && !blk_get_attached_dev(blk)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bs = bdrv_skip_implicit_filters(bs);
|
||||
if (!bs || !bs->drv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
export = (NbdServerAddOptions) {
|
||||
.device = info->value->device,
|
||||
.device = g_strdup(blk_name(blk)),
|
||||
.has_writable = true,
|
||||
.writable = writable,
|
||||
};
|
||||
@@ -449,8 +455,6 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
}
|
||||
|
||||
qapi_free_BlockInfoList(block_list);
|
||||
|
||||
exit:
|
||||
hmp_handle_error(mon, local_err);
|
||||
}
|
||||
@@ -744,7 +748,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
||||
}
|
||||
}
|
||||
|
||||
void hmp_info_block(Monitor *mon, const QDict *qdict)
|
||||
void coroutine_fn hmp_info_block(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
BlockInfoList *block_list, *info;
|
||||
BlockDeviceInfoList *blockdev_list, *blockdev;
|
||||
|
||||
32
block/qapi.c
32
block/qapi.c
@@ -41,10 +41,10 @@
|
||||
#include "qemu/qemu-print.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
|
||||
BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
BlockDriverState *bs,
|
||||
bool flat,
|
||||
Error **errp)
|
||||
BlockDeviceInfo *coroutine_fn bdrv_block_device_info(BlockBackend *blk,
|
||||
BlockDriverState *bs,
|
||||
bool flat,
|
||||
Error **errp)
|
||||
{
|
||||
ImageInfo **p_image_info;
|
||||
ImageInfo *backing_info;
|
||||
@@ -234,8 +234,6 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp)
|
||||
int ret;
|
||||
Error *err = NULL;
|
||||
|
||||
aio_context_acquire(bdrv_get_aio_context(bs));
|
||||
|
||||
size = bdrv_getlength(bs);
|
||||
if (size < 0) {
|
||||
error_setg_errno(errp, -size, "Can't get image size '%s'",
|
||||
@@ -248,7 +246,9 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp)
|
||||
info->filename = g_strdup(bs->filename);
|
||||
info->format = g_strdup(bdrv_get_format_name(bs));
|
||||
info->virtual_size = size;
|
||||
info->actual_size = bdrv_get_allocated_file_size(bs);
|
||||
bdrv_graph_co_rdlock();
|
||||
info->actual_size = bdrv_co_get_allocated_file_size(bs);
|
||||
bdrv_graph_co_rdunlock();
|
||||
info->has_actual_size = info->actual_size >= 0;
|
||||
if (bs->encrypted) {
|
||||
info->encrypted = true;
|
||||
@@ -304,7 +304,7 @@ bdrv_do_query_node_info(BlockDriverState *bs, BlockNodeInfo *info, Error **errp)
|
||||
}
|
||||
|
||||
out:
|
||||
aio_context_release(bdrv_get_aio_context(bs));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +374,7 @@ fail:
|
||||
}
|
||||
|
||||
/**
|
||||
* bdrv_query_block_graph_info:
|
||||
* bdrv_co_query_block_graph_info:
|
||||
* @bs: root node to start from
|
||||
* @p_info: location to store image information
|
||||
* @errp: location to store error information
|
||||
@@ -383,15 +383,17 @@ fail:
|
||||
*
|
||||
* @p_info will be set only on success. On error, store error in @errp.
|
||||
*/
|
||||
void bdrv_query_block_graph_info(BlockDriverState *bs,
|
||||
BlockGraphInfo **p_info,
|
||||
Error **errp)
|
||||
void coroutine_fn bdrv_co_query_block_graph_info(BlockDriverState *bs,
|
||||
BlockGraphInfo **p_info,
|
||||
Error **errp)
|
||||
{
|
||||
BlockGraphInfo *info;
|
||||
BlockChildInfoList **children_list_tail;
|
||||
BdrvChild *c;
|
||||
ERRP_GUARD();
|
||||
|
||||
assert_bdrv_graph_readable();
|
||||
|
||||
info = g_new0(BlockGraphInfo, 1);
|
||||
bdrv_do_query_node_info(bs, qapi_BlockGraphInfo_base(info), errp);
|
||||
if (*errp) {
|
||||
@@ -407,7 +409,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs,
|
||||
QAPI_LIST_APPEND(children_list_tail, c_info);
|
||||
|
||||
c_info->name = g_strdup(c->name);
|
||||
bdrv_query_block_graph_info(c->bs, &c_info->info, errp);
|
||||
bdrv_co_query_block_graph_info(c->bs, &c_info->info, errp);
|
||||
if (*errp) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -665,13 +667,13 @@ bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level)
|
||||
return s;
|
||||
}
|
||||
|
||||
BlockInfoList *qmp_query_block(Error **errp)
|
||||
BlockInfoList *coroutine_fn qmp_query_block(Error **errp)
|
||||
{
|
||||
BlockInfoList *head = NULL, **p_next = &head;
|
||||
BlockBackend *blk;
|
||||
Error *local_err = NULL;
|
||||
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
GRAPH_RDLOCK_GUARD();
|
||||
|
||||
for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
|
||||
BlockInfoList *info;
|
||||
|
||||
@@ -387,7 +387,7 @@ int bdrv_snapshot_list(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_info)
|
||||
{
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
GRAPH_RDLOCK_GUARD();
|
||||
|
||||
BlockDriver *drv = bs->drv;
|
||||
BlockDriverState *fallback_bs = bdrv_snapshot_fallback(bs);
|
||||
|
||||
@@ -2871,9 +2871,9 @@ void qmp_drive_backup(DriveBackup *backup, Error **errp)
|
||||
blockdev_do_action(&action, errp);
|
||||
}
|
||||
|
||||
BlockDeviceInfoList *qmp_query_named_block_nodes(bool has_flat,
|
||||
bool flat,
|
||||
Error **errp)
|
||||
BlockDeviceInfoList *coroutine_fn qmp_query_named_block_nodes(bool has_flat,
|
||||
bool flat,
|
||||
Error **errp)
|
||||
{
|
||||
bool return_flat = has_flat && flat;
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ ERST
|
||||
.help = "show info of one block device or all block devices "
|
||||
"(-n: show named nodes; -v: show details)",
|
||||
.cmd = hmp_info_block,
|
||||
.coroutine = true,
|
||||
},
|
||||
|
||||
SRST
|
||||
|
||||
@@ -48,7 +48,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict);
|
||||
|
||||
void hmp_qemu_io(Monitor *mon, const QDict *qdict);
|
||||
|
||||
void hmp_info_block(Monitor *mon, const QDict *qdict);
|
||||
void coroutine_fn hmp_info_block(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_blockstats(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
#ifndef BLOCK_QAPI_H
|
||||
#define BLOCK_QAPI_H
|
||||
|
||||
#include "block/block-common.h"
|
||||
#include "block/graph-lock.h"
|
||||
#include "block/snapshot.h"
|
||||
#include "qapi/qapi-types-block-core.h"
|
||||
|
||||
BlockDeviceInfo * GRAPH_RDLOCK
|
||||
bdrv_block_device_info(BlockBackend *blk, BlockDriverState *bs,
|
||||
bool flat, Error **errp);
|
||||
|
||||
BlockDeviceInfo *coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_block_device_info(BlockBackend *blk, BlockDriverState *bs, bool flat,
|
||||
Error **errp);
|
||||
int GRAPH_RDLOCK
|
||||
bdrv_query_snapshot_info_list(BlockDriverState *bs,
|
||||
SnapshotInfoList **p_list,
|
||||
@@ -40,7 +40,10 @@ bdrv_query_snapshot_info_list(BlockDriverState *bs,
|
||||
void GRAPH_RDLOCK
|
||||
bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, bool flat,
|
||||
bool skip_implicit_filters, Error **errp);
|
||||
void GRAPH_RDLOCK
|
||||
void coroutine_fn GRAPH_RDLOCK
|
||||
bdrv_co_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info,
|
||||
Error **errp);
|
||||
void co_wrapper_bdrv_rdlock
|
||||
bdrv_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info,
|
||||
Error **errp);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define QEMU_AIO_ZONE_REPORT 0x0100
|
||||
#define QEMU_AIO_ZONE_MGMT 0x0200
|
||||
#define QEMU_AIO_ZONE_APPEND 0x0400
|
||||
#define QEMU_AIO_FSTAT 0x0800
|
||||
#define QEMU_AIO_TYPE_MASK \
|
||||
(QEMU_AIO_READ | \
|
||||
QEMU_AIO_WRITE | \
|
||||
@@ -42,7 +43,8 @@
|
||||
QEMU_AIO_TRUNCATE | \
|
||||
QEMU_AIO_ZONE_REPORT | \
|
||||
QEMU_AIO_ZONE_MGMT | \
|
||||
QEMU_AIO_ZONE_APPEND)
|
||||
QEMU_AIO_ZONE_APPEND | \
|
||||
QEMU_AIO_FSTAT)
|
||||
|
||||
/* AIO flags */
|
||||
#define QEMU_AIO_MISALIGNED 0x1000
|
||||
|
||||
@@ -839,7 +839,7 @@
|
||||
# }
|
||||
##
|
||||
{ 'command': 'query-block', 'returns': ['BlockInfo'],
|
||||
'allow-preconfig': true }
|
||||
'allow-preconfig': true, 'coroutine': true }
|
||||
|
||||
##
|
||||
# @BlockDeviceTimedStats:
|
||||
@@ -1985,7 +1985,8 @@
|
||||
{ 'command': 'query-named-block-nodes',
|
||||
'returns': [ 'BlockDeviceInfo' ],
|
||||
'data': { '*flat': 'bool' },
|
||||
'allow-preconfig': true }
|
||||
'allow-preconfig': true,
|
||||
'coroutine': true}
|
||||
|
||||
##
|
||||
# @XDbgBlockGraphNodeType:
|
||||
|
||||
@@ -2962,9 +2962,7 @@ static BlockGraphInfoList *collect_image_info_list(bool image_opts,
|
||||
* duplicate the backing chain information that we obtain by walking
|
||||
* the chain manually here.
|
||||
*/
|
||||
bdrv_graph_rdlock_main_loop();
|
||||
bdrv_query_block_graph_info(bs, &info, &err);
|
||||
bdrv_graph_rdunlock_main_loop();
|
||||
|
||||
if (err) {
|
||||
error_report_err(err);
|
||||
|
||||
@@ -44,6 +44,7 @@ def gen_header():
|
||||
#include "block/block-gen.h"
|
||||
#include "block/block_int.h"
|
||||
#include "block/dirty-bitmap.h"
|
||||
#include "block/qapi.h"
|
||||
"""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user