qapi: Convert block_passwd
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
4b37156c40
commit
a4dea8a9f4
22
blockdev.c
22
blockdev.c
|
@ -15,6 +15,7 @@
|
||||||
#include "qemu-config.h"
|
#include "qemu-config.h"
|
||||||
#include "sysemu.h"
|
#include "sysemu.h"
|
||||||
#include "block_int.h"
|
#include "block_int.h"
|
||||||
|
#include "qmp-commands.h"
|
||||||
|
|
||||||
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
|
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
|
||||||
|
|
||||||
|
@ -710,28 +711,25 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
|
||||||
return eject_device(mon, bs, force);
|
return eject_device(mon, bs, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_block_set_passwd(Monitor *mon, const QDict *qdict,
|
void qmp_block_passwd(const char *device, const char *password, Error **errp)
|
||||||
QObject **ret_data)
|
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
bs = bdrv_find(qdict_get_str(qdict, "device"));
|
bs = bdrv_find(device);
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
qerror_report(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device"));
|
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bdrv_set_key(bs, qdict_get_str(qdict, "password"));
|
err = bdrv_set_key(bs, password);
|
||||||
if (err == -EINVAL) {
|
if (err == -EINVAL) {
|
||||||
qerror_report(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
|
error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
|
||||||
return -1;
|
return;
|
||||||
} else if (err < 0) {
|
} else if (err < 0) {
|
||||||
qerror_report(QERR_INVALID_PASSWORD);
|
error_set(errp, QERR_INVALID_PASSWORD);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_change_block(Monitor *mon, const char *device,
|
int do_change_block(Monitor *mon, const char *device,
|
||||||
|
|
|
@ -59,7 +59,6 @@ DriveInfo *add_init_drive(const char *opts);
|
||||||
|
|
||||||
void do_commit(Monitor *mon, const QDict *qdict);
|
void do_commit(Monitor *mon, const QDict *qdict);
|
||||||
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
||||||
int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
|
||||||
int do_change_block(Monitor *mon, const char *device,
|
int do_change_block(Monitor *mon, const char *device,
|
||||||
const char *filename, const char *fmt);
|
const char *filename, const char *fmt);
|
||||||
int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
||||||
|
|
|
@ -1198,8 +1198,7 @@ ETEXI
|
||||||
.args_type = "device:B,password:s",
|
.args_type = "device:B,password:s",
|
||||||
.params = "block_passwd device password",
|
.params = "block_passwd device password",
|
||||||
.help = "set the password of encrypted block devices",
|
.help = "set the password of encrypted block devices",
|
||||||
.user_print = monitor_user_noop,
|
.mhandler.cmd = hmp_block_passwd,
|
||||||
.mhandler.cmd_new = do_block_set_passwd,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
STEXI
|
STEXI
|
||||||
|
|
10
hmp.c
10
hmp.c
|
@ -611,3 +611,13 @@ void hmp_set_link(Monitor *mon, const QDict *qdict)
|
||||||
qmp_set_link(name, up, &errp);
|
qmp_set_link(name, up, &errp);
|
||||||
hmp_handle_error(mon, &errp);
|
hmp_handle_error(mon, &errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hmp_block_passwd(Monitor *mon, const QDict *qdict)
|
||||||
|
{
|
||||||
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
|
const char *password = qdict_get_str(qdict, "password");
|
||||||
|
Error *errp = NULL;
|
||||||
|
|
||||||
|
qmp_block_passwd(device, password, &errp);
|
||||||
|
hmp_handle_error(mon, &errp);
|
||||||
|
}
|
||||||
|
|
1
hmp.h
1
hmp.h
|
@ -42,5 +42,6 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_cont(Monitor *mon, const QDict *qdict);
|
void hmp_cont(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
|
void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_set_link(Monitor *mon, const QDict *qdict);
|
void hmp_set_link(Monitor *mon, const QDict *qdict);
|
||||||
|
void hmp_block_passwd(Monitor *mon, const QDict *qdict);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -999,3 +999,36 @@
|
||||||
# notification.
|
# notification.
|
||||||
##
|
##
|
||||||
{ 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
|
{ 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @block_passwd:
|
||||||
|
#
|
||||||
|
# This command sets the password of a block device that has not been open
|
||||||
|
# with a password and requires one.
|
||||||
|
#
|
||||||
|
# The two cases where this can happen are a block device is created through
|
||||||
|
# QEMU's initial command line or a block device is changed through the legacy
|
||||||
|
# @change interface.
|
||||||
|
#
|
||||||
|
# In the event that the block device is created through the initial command
|
||||||
|
# line, the VM will start in the stopped state regardless of whether '-S' is
|
||||||
|
# used. The intention is for a management tool to query the block devices to
|
||||||
|
# determine which ones are encrypted, set the passwords with this command, and
|
||||||
|
# then start the guest with the @cont command.
|
||||||
|
#
|
||||||
|
# @device: the name of the device to set the password on
|
||||||
|
#
|
||||||
|
# @password: the password to use for the device
|
||||||
|
#
|
||||||
|
# Returns: nothing on success
|
||||||
|
# If @device is not a valid block device, DeviceNotFound
|
||||||
|
# If @device is not encrypted, DeviceNotEncrypted
|
||||||
|
# If @password is not valid for this device, InvalidPassword
|
||||||
|
#
|
||||||
|
# Notes: Not all block formats support encryption and some that do are not
|
||||||
|
# able to validate that a password is correct. Disk corruption may
|
||||||
|
# occur if an invalid password is specified.
|
||||||
|
#
|
||||||
|
# Since: 0.14.0
|
||||||
|
##
|
||||||
|
{ 'command': 'block_passwd', 'data': {'device': 'str', 'password': 'str'} }
|
||||||
|
|
|
@ -806,10 +806,7 @@ EQMP
|
||||||
{
|
{
|
||||||
.name = "block_passwd",
|
.name = "block_passwd",
|
||||||
.args_type = "device:B,password:s",
|
.args_type = "device:B,password:s",
|
||||||
.params = "block_passwd device password",
|
.mhandler.cmd_new = qmp_marshal_input_block_passwd,
|
||||||
.help = "set the password of encrypted block devices",
|
|
||||||
.user_print = monitor_user_noop,
|
|
||||||
.mhandler.cmd_new = do_block_set_passwd,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SQMP
|
SQMP
|
||||||
|
|
Loading…
Reference in a new issue