static int qemudDomainGetMaxVcpus(virDomainPtr dom);
-static int qemudDomainSetMemoryBalloon(virConnectPtr conn,
- virDomainObjPtr vm,
- unsigned long newmem);
static int qemuDetectVcpuPIDs(virConnectPtr conn,
virDomainObjPtr vm);
(qemuDetectVcpuPIDs(conn, vm) < 0) ||
(qemudInitCpus(conn, vm, migrateFrom) < 0) ||
(qemuInitPasswords(driver, vm) < 0) ||
- (qemudDomainSetMemoryBalloon(conn, vm, vm->def->memory) < 0) ||
+ (qemuMonitorSetBalloon(vm, vm->def->memory) < 0) ||
(virDomainSaveStatus(conn, driver->stateDir, vm) < 0)) {
qemudShutdownVMDaemon(conn, driver, vm);
ret = -1;
}
-/*
- * Returns: 0 if balloon not supported, +1 if balloon query worked
- * or -1 on failure
- */
-static int qemudDomainSetMemoryBalloon(virConnectPtr conn,
- virDomainObjPtr vm,
- unsigned long newmem) {
- char *cmd;
- char *reply = NULL;
- int ret = -1;
-
- /*
- * 'newmem' is in KB, QEMU monitor works in MB, and we all wish
- * we just worked in bytes with unsigned long long everywhere.
- */
- if (virAsprintf(&cmd, "balloon %lu", (newmem / 1024)) < 0) {
- virReportOOMError(conn);
- goto cleanup;
- }
-
- if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
- qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("could not balloon memory allocation"));
- VIR_FREE(cmd);
- goto cleanup;
- }
- VIR_FREE(cmd);
-
- /* If the command failed qemu prints: 'unknown command'
- * No message is printed on success it seems */
- DEBUG ("%s: balloon reply: %s",vm->def->name, reply);
- if (strstr(reply, "\nunknown command:")) {
- /* Don't set error - it is expected memory balloon fails on many qemu */
- ret = 0;
- } else {
- ret = 1;
- }
-
-cleanup:
- VIR_FREE(reply);
- return ret;
-}
-
-
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
}
if (virDomainIsActive(vm)) {
- ret = qemudDomainSetMemoryBalloon(dom->conn, vm, newmem);
- if (ret == 0)
+ ret = qemuMonitorSetBalloon(vm, newmem);
+ /* Turn lack of balloon support into a fatal error */
+ if (ret == 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", _("cannot set memory of an active domain"));
+ ret = -1;
+ }
} else {
vm->def->memory = newmem;
ret = 0;
/* The reply from QEMU contains 'ballon: actual=421' where value is in MB */
#define BALLOON_PREFIX "balloon: actual="
+/*
+ * Returns: 0 if balloon not supported, +1 if balloon query worked
+ * or -1 on failure
+ */
int qemuMonitorGetBalloonInfo(const virDomainObjPtr vm,
unsigned long *currmem)
{
VIR_FREE(info);
return 0;
}
+
+/*
+ * Returns: 0 if balloon not supported, +1 if balloon adjust worked
+ * or -1 on failure
+ */
+int qemuMonitorSetBalloon(const virDomainObjPtr vm,
+ unsigned long newmem)
+{
+ char *cmd;
+ char *reply = NULL;
+ int ret = -1;
+
+ /*
+ * 'newmem' is in KB, QEMU monitor works in MB, and we all wish
+ * we just worked in bytes with unsigned long long everywhere.
+ */
+ if (virAsprintf(&cmd, "balloon %lu", (newmem / 1024)) < 0) {
+ virReportOOMError(NULL);
+ return -1;
+ }
+
+ if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "%s", _("could not balloon memory allocation"));
+ VIR_FREE(cmd);
+ return -1;
+ }
+ VIR_FREE(cmd);
+
+ /* If the command failed qemu prints: 'unknown command'
+ * No message is printed on success it seems */
+ DEBUG ("%s: balloon reply: %s", vm->def->name, reply);
+ if (strstr(reply, "\nunknown command:")) {
+ /* Don't set error - it is expected memory balloon fails on many qemu */
+ ret = 0;
+ } else {
+ ret = 1;
+ }
+
+ VIR_FREE(reply);
+ return ret;
+}
+