* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add a
new qemuMonitorSetVNCPassword() API
* src/qemu/qemu_driver.c: Refactor qemudInitPasswords to
call qemuMonitorSetVNCPassword()
---
src/qemu/qemu_driver.c | 24 ++++++++----------------
src/qemu/qemu_monitor_text.c | 15 +++++++++++++++
src/qemu/qemu_monitor_text.h | 3 +++
3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 30d1468..e0b7c84 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1275,29 +1275,21 @@ qemudInitCpus(virConnectPtr conn,
static int
-qemudInitPasswords(virConnectPtr conn,
- struct qemud_driver *driver,
+qemudInitPasswords(struct qemud_driver *driver,
virDomainObjPtr vm) {
- char *info = NULL;
+ int ret = 0;
if ((vm->def->ngraphics == 1) &&
vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
(vm->def->graphics[0]->data.vnc.passwd || driver->vncPassword)) {
- if (qemudMonitorCommandExtra(vm, "change vnc password",
- vm->def->graphics[0]->data.vnc.passwd ?
- vm->def->graphics[0]->data.vnc.passwd :
- driver->vncPassword,
- QEMU_PASSWD_PROMPT,
- -1, &info) < 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("setting VNC password
failed"));
- return -1;
- }
- VIR_FREE(info);
+ ret = qemuMonitorSetVNCPassword(vm,
+ vm->def->graphics[0]->data.vnc.passwd ?
+ vm->def->graphics[0]->data.vnc.passwd :
+ driver->vncPassword);
}
- return 0;
+ return ret;
}
@@ -2144,7 +2136,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
if ((qemudWaitForMonitor(conn, driver, vm, pos) < 0) ||
(qemuDetectVcpuPIDs(conn, vm) < 0) ||
(qemudInitCpus(conn, vm, migrateFrom) < 0) ||
- (qemudInitPasswords(conn, driver, vm) < 0) ||
+ (qemudInitPasswords(driver, vm) < 0) ||
(qemudDomainSetMemoryBalloon(conn, vm, vm->def->memory) < 0) ||
(virDomainSaveStatus(conn, driver->stateDir, vm) < 0)) {
qemudShutdownVMDaemon(conn, driver, vm);
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index d93e475..ba28f02 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -520,3 +520,18 @@ error:
}
+int qemuMonitorSetVNCPassword(const virDomainObjPtr vm,
+ const char *password)
+{
+ char *info = NULL;
+ if (qemudMonitorCommandExtra(vm, "change vnc password",
+ password,
+ QEMU_PASSWD_PROMPT,
+ -1, &info) < 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("setting VNC password failed"));
+ return -1;
+ }
+ VIR_FREE(info);
+ return 0;
+}
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index 973c3b6..fd0fa61 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -71,4 +71,7 @@ int qemudMonitorSendCont(virConnectPtr conn,
int qemuMonitorGetCPUInfo(const virDomainObjPtr vm,
int **pids);
+int qemuMonitorSetVNCPassword(const virDomainObjPtr vm,
+ const char *password);
+
#endif /* QEMU_MONITOR_TEXT_H */
--
1.6.2.5