Compare commits
10 Commits
qdev-array
...
qmp-bql-8.
Author | SHA1 | Date | |
---|---|---|---|
|
5dfab28df7 | ||
|
c9097828ce | ||
|
38a19fb0cb | ||
871de8b605 | |||
|
2baf836f1a | ||
|
382b965ec5 | ||
|
d384bb304f | ||
|
b111101fc0 | ||
|
b1e0e18d9f | ||
|
89f0789b96 |
@@ -227,6 +227,9 @@ typedef struct RawPosixAIOData {
|
||||
struct {
|
||||
unsigned long op;
|
||||
} zone_mgmt;
|
||||
struct {
|
||||
struct stat *st;
|
||||
} fstat;
|
||||
};
|
||||
} RawPosixAIOData;
|
||||
|
||||
@@ -2612,6 +2615,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.
|
||||
@@ -2856,11 +2887,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;
|
||||
}
|
||||
|
||||
|
@@ -150,6 +150,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'
|
||||
|
@@ -394,7 +394,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;
|
||||
|
||||
@@ -419,18 +419,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,
|
||||
};
|
||||
@@ -443,8 +449,6 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
}
|
||||
|
||||
qapi_free_BlockInfoList(block_list);
|
||||
|
||||
exit:
|
||||
hmp_handle_error(mon, local_err);
|
||||
}
|
||||
@@ -738,7 +742,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;
|
||||
|
62
block/qapi.c
62
block/qapi.c
@@ -41,14 +41,14 @@
|
||||
#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;
|
||||
BlockDriverState *bs0, *backing;
|
||||
BlockDriverState *backing;
|
||||
BlockDeviceInfo *info;
|
||||
ERRP_GUARD();
|
||||
|
||||
@@ -145,7 +145,6 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
|
||||
info->write_threshold = bdrv_write_threshold_get(bs);
|
||||
|
||||
bs0 = bs;
|
||||
p_image_info = &info->image;
|
||||
info->backing_file_depth = 0;
|
||||
|
||||
@@ -153,7 +152,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
* Skip automatically inserted nodes that the user isn't aware of for
|
||||
* query-block (blk != NULL), but not for query-named-block-nodes
|
||||
*/
|
||||
bdrv_query_image_info(bs0, p_image_info, flat, blk != NULL, errp);
|
||||
bdrv_query_image_info(bs, p_image_info, flat, blk != NULL, errp);
|
||||
if (*errp) {
|
||||
qapi_free_BlockDeviceInfo(info);
|
||||
return NULL;
|
||||
@@ -236,8 +235,6 @@ static void bdrv_do_query_node_info(BlockDriverState *bs,
|
||||
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'",
|
||||
@@ -250,7 +247,9 @@ static void bdrv_do_query_node_info(BlockDriverState *bs,
|
||||
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;
|
||||
@@ -306,34 +305,7 @@ static void bdrv_do_query_node_info(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
out:
|
||||
aio_context_release(bdrv_get_aio_context(bs));
|
||||
}
|
||||
|
||||
/**
|
||||
* bdrv_query_block_node_info:
|
||||
* @bs: block node to examine
|
||||
* @p_info: location to store node information
|
||||
* @errp: location to store error information
|
||||
*
|
||||
* Store image information about @bs in @p_info.
|
||||
*
|
||||
* @p_info will be set only on success. On error, store error in @errp.
|
||||
*/
|
||||
void bdrv_query_block_node_info(BlockDriverState *bs,
|
||||
BlockNodeInfo **p_info,
|
||||
Error **errp)
|
||||
{
|
||||
BlockNodeInfo *info;
|
||||
ERRP_GUARD();
|
||||
|
||||
info = g_new0(BlockNodeInfo, 1);
|
||||
bdrv_do_query_node_info(bs, info, errp);
|
||||
if (*errp) {
|
||||
qapi_free_BlockNodeInfo(info);
|
||||
return;
|
||||
}
|
||||
|
||||
*p_info = info;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,7 +375,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
|
||||
@@ -412,15 +384,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) {
|
||||
@@ -436,7 +410,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;
|
||||
}
|
||||
@@ -694,7 +668,7 @@ 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;
|
||||
|
@@ -2818,9 +2818,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,26 +25,27 @@
|
||||
#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 *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);
|
||||
int bdrv_query_snapshot_info_list(BlockDriverState *bs,
|
||||
SnapshotInfoList **p_list,
|
||||
Error **errp);
|
||||
void bdrv_query_block_node_info(BlockDriverState *bs,
|
||||
BlockNodeInfo **p_info,
|
||||
Error **errp);
|
||||
void 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
|
||||
|
@@ -837,7 +837,7 @@
|
||||
# }
|
||||
##
|
||||
{ 'command': 'query-block', 'returns': ['BlockInfo'],
|
||||
'allow-preconfig': true }
|
||||
'allow-preconfig': true, 'coroutine': true }
|
||||
|
||||
##
|
||||
# @BlockDeviceTimedStats:
|
||||
@@ -1967,7 +1967,8 @@
|
||||
{ 'command': 'query-named-block-nodes',
|
||||
'returns': [ 'BlockDeviceInfo' ],
|
||||
'data': { '*flat': 'bool' },
|
||||
'allow-preconfig': true }
|
||||
'allow-preconfig': true,
|
||||
'coroutine': true}
|
||||
|
||||
##
|
||||
# @XDbgBlockGraphNodeType:
|
||||
|
@@ -2945,9 +2945,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