#include "qemu/osdep.h"
+#include "block/block_int.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-block.h"
#include "qapi/qmp/qdict.h"
return 0;
}
-void qmp_blockdev_open_tray(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_open_tray(const char *device,
+ const char *id,
bool has_force, bool force,
Error **errp)
{
if (!has_force) {
force = false;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- force, &local_err);
+ rc = do_open_tray(device, id, force, &local_err);
if (rc && rc != -ENOSYS && rc != -EINPROGRESS) {
error_propagate(errp, local_err);
return;
error_free(local_err);
}
-void qmp_blockdev_close_tray(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_close_tray(const char *device,
+ const char *id,
Error **errp)
{
BlockBackend *blk;
Error *local_err = NULL;
- device = has_device ? device : NULL;
- id = has_id ? id : NULL;
-
blk = qmp_get_blk(device, id, errp);
if (!blk) {
return;
}
}
-static void blockdev_remove_medium(bool has_device, const char *device,
- bool has_id, const char *id, Error **errp)
+static void GRAPH_UNLOCKED
+blockdev_remove_medium(const char *device, const char *id, Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
AioContext *aio_context;
bool has_attached_device;
- device = has_device ? device : NULL;
- id = has_id ? id : NULL;
+ GLOBAL_STATE_CODE();
blk = qmp_get_blk(device, id, errp);
if (!blk) {
aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
+ bdrv_graph_rdlock_main_loop();
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) {
+ bdrv_graph_rdunlock_main_loop();
goto out;
}
+ bdrv_graph_rdunlock_main_loop();
blk_remove_bs(blk);
void qmp_blockdev_remove_medium(const char *id, Error **errp)
{
- blockdev_remove_medium(false, NULL, true, id, errp);
+ blockdev_remove_medium(NULL, id, errp);
}
static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
BlockDriverState *bs, Error **errp)
{
Error *local_err = NULL;
+ AioContext *ctx;
bool has_device;
int ret;
return;
}
+ ctx = bdrv_get_aio_context(bs);
+ aio_context_acquire(ctx);
ret = blk_insert_bs(blk, bs, errp);
+ aio_context_release(ctx);
+
if (ret < 0) {
return;
}
}
}
-static void blockdev_insert_medium(bool has_device, const char *device,
- bool has_id, const char *id,
+static void blockdev_insert_medium(const char *device, const char *id,
const char *node_name, Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
- blk = qmp_get_blk(has_device ? device : NULL,
- has_id ? id : NULL,
- errp);
+ GRAPH_RDLOCK_GUARD_MAINLOOP();
+
+ blk = qmp_get_blk(device, id, errp);
if (!blk) {
return;
}
void qmp_blockdev_insert_medium(const char *id, const char *node_name,
Error **errp)
{
- blockdev_insert_medium(false, NULL, true, id, node_name, errp);
+ blockdev_insert_medium(NULL, id, node_name, errp);
}
-void qmp_blockdev_change_medium(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_change_medium(const char *device,
+ const char *id,
const char *filename,
- bool has_format, const char *format,
+ const char *format,
+ bool has_force, bool force,
bool has_read_only,
BlockdevChangeReadOnlyMode read_only,
Error **errp)
QDict *options = NULL;
Error *err = NULL;
- blk = qmp_get_blk(has_device ? device : NULL,
- has_id ? id : NULL,
- errp);
+ blk = qmp_get_blk(device, id, errp);
if (!blk) {
goto fail;
}
detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off");
- if (has_format) {
+ if (format) {
qdict_put_str(options, "driver", format);
}
+ aio_context_acquire(qemu_get_aio_context());
medium_bs = bdrv_open(filename, NULL, options, bdrv_flags, errp);
+ aio_context_release(qemu_get_aio_context());
+
if (!medium_bs) {
goto fail;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- false, &err);
+ rc = do_open_tray(device, id, force, &err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, err);
goto fail;
error_free(err);
err = NULL;
- blockdev_remove_medium(has_device, device, has_id, id, &err);
+ blockdev_remove_medium(device, id, &err);
if (err) {
error_propagate(errp, err);
goto fail;
goto fail;
}
- qmp_blockdev_close_tray(has_device, device, has_id, id, errp);
+ qmp_blockdev_close_tray(device, id, errp);
fail:
/* If the medium has been inserted, the device has its own reference, so
bdrv_unref(medium_bs);
}
-void qmp_eject(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_eject(const char *device, const char *id,
bool has_force, bool force, Error **errp)
{
Error *local_err = NULL;
force = false;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- force, &local_err);
+ rc = do_open_tray(device, id, force, &local_err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, local_err);
return;
}
error_free(local_err);
- blockdev_remove_medium(has_device, device, has_id, id, errp);
+ blockdev_remove_medium(device, id, errp);
}
/* throttling disk I/O limits */
BlockBackend *blk;
AioContext *aio_context;
- blk = qmp_get_blk(arg->has_device ? arg->device : NULL,
- arg->has_id ? arg->id : NULL,
- errp);
+ blk = qmp_get_blk(arg->device, arg->id, errp);
if (!blk) {
return;
}
/* Enable I/O limits if they're not enabled yet, otherwise
* just update the throttling group. */
if (!blk_get_public(blk)->throttle_group_member.throttle_state) {
- blk_io_limits_enable(blk,
- arg->has_group ? arg->group :
- arg->has_device ? arg->device :
- arg->id);
- } else if (arg->has_group) {
+ blk_io_limits_enable(blk, arg->group ?: arg->device ?: arg->id);
+ } else if (arg->group) {
blk_io_limits_update_group(blk, arg->group);
}
/* Set the new throttling configuration */
bool has_boundaries, uint64List *boundaries,
bool has_boundaries_read, uint64List *boundaries_read,
bool has_boundaries_write, uint64List *boundaries_write,
+ bool has_boundaries_append, uint64List *boundaries_append,
bool has_boundaries_flush, uint64List *boundaries_flush,
Error **errp)
{
}
}
+ if (has_boundaries || has_boundaries_append) {
+ ret = block_latency_histogram_set(
+ stats, BLOCK_ACCT_ZONE_APPEND,
+ has_boundaries_append ? boundaries_append : boundaries);
+ if (ret) {
+ error_setg(errp, "Device '%s' set append write boundaries fail", id);
+ return;
+ }
+ }
+
if (has_boundaries || has_boundaries_flush) {
ret = block_latency_histogram_set(
stats, BLOCK_ACCT_FLUSH,