Skip to content

Commit

Permalink
monitor/hmp: Move hmp_drive_add_node to block-hmp-cmds.c
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20200308092440.23564-12-mlevitsk@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  • Loading branch information
Maxim Levitsky authored and dagrh committed Mar 9, 2020
1 parent 2bcad73 commit 89802d5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
30 changes: 30 additions & 0 deletions block/monitor/block-hmp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@
#include "block/block-hmp-cmds.h"
#include "qemu-io.h"

static void hmp_drive_add_node(Monitor *mon, const char *optstr)
{
QemuOpts *opts;
QDict *qdict;
Error *local_err = NULL;

opts = qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false);
if (!opts) {
return;
}

qdict = qemu_opts_to_qdict(opts, NULL);

if (!qdict_get_try_str(qdict, "node-name")) {
qobject_unref(qdict);
error_report("'node-name' needs to be specified");
goto out;
}

BlockDriverState *bs = bds_tree_init(qdict, &local_err);
if (!bs) {
error_report_err(local_err);
goto out;
}

bdrv_set_monitor_owned(bs);
out:
qemu_opts_del(opts);
}

void hmp_drive_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
Expand Down
43 changes: 8 additions & 35 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@
#include "qemu/main-loop.h"
#include "qemu/throttle-options.h"

static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);

void bdrv_set_monitor_owned(BlockDriverState *bs)
{
QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list);
}

static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
[IF_IDE] = "ide",
Expand Down Expand Up @@ -640,7 +645,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
}

/* Takes the ownership of bs_opts */
static BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp)
BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp)
{
int bdrv_flags = 0;

Expand Down Expand Up @@ -3719,38 +3724,6 @@ void qmp_change_backing_file(const char *device,
aio_context_release(aio_context);
}


void hmp_drive_add_node(Monitor *mon, const char *optstr)
{
QemuOpts *opts;
QDict *qdict;
Error *local_err = NULL;

opts = qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false);
if (!opts) {
return;
}

qdict = qemu_opts_to_qdict(opts, NULL);

if (!qdict_get_try_str(qdict, "node-name")) {
qobject_unref(qdict);
error_report("'node-name' needs to be specified");
goto out;
}

BlockDriverState *bs = bds_tree_init(qdict, &local_err);
if (!bs) {
error_report_err(local_err);
goto out;
}

QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list);

out:
qemu_opts_del(opts);
}

void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
{
BlockDriverState *bs;
Expand Down Expand Up @@ -3780,7 +3753,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
goto fail;
}

QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list);
bdrv_set_monitor_owned(bs);

fail:
visit_free(v);
Expand Down
5 changes: 3 additions & 2 deletions include/block/block_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,6 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
BlockCompletionFunc *cb, void *opaque,
JobTxn *txn, Error **errp);

void hmp_drive_add_node(Monitor *mon, const char *optstr);

BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
const BdrvChildRole *child_role,
Expand Down Expand Up @@ -1322,4 +1320,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset,

int refresh_total_sectors(BlockDriverState *bs, int64_t hint);

void bdrv_set_monitor_owned(BlockDriverState *bs);
BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp);

#endif /* BLOCK_INT_H */

0 comments on commit 89802d5

Please sign in to comment.