Change the QEMU driver to not directly invoke the text mode monitor APIs. Instead add a generic wrapper layer, which will eventually invoke either the text or JSON protocol code as needed. Pass an qemuMonitorPtr object into the monitor APIs instead of virDomainObjPtr to complete the de-coupling of the monitor impl from virDomainObj data structures * src/qemu/qemu_conf.h: Remove qemuDomainObjPrivate definition * src/qemu/qemu_driver.c: Add qemuDomainObjPrivate definition. Pass qemuMonitorPtr into all monitor APIs instead of the virDomainObjPtr instance. * src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add thin wrappers for all qemuMonitorXXX command APIs, calling into qemu_monitor_text.c/h * src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Rename qemuMonitor -> qemuMonitorText & update to accept qemuMonitorPtr instead of virDomainObjPtr --- src/qemu/qemu_conf.h | 11 - src/qemu/qemu_driver.c | 133 +++++++++----- src/qemu/qemu_monitor.c | 319 ++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.h | 148 ++++++++++++++ src/qemu/qemu_monitor_text.c | 436 +++++++++++++++++------------------------- src/qemu/qemu_monitor_text.h | 269 ++++++++++++--------------- 6 files changed, 845 insertions(+), 471 deletions(-) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 171bf90..f9a970f 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -36,7 +36,6 @@ #include "security/security_driver.h" #include "cgroup.h" #include "pci.h" -#include "qemu_monitor.h" #define qemudDebug(fmt, ...) do {} while(0) @@ -129,16 +128,6 @@ struct qemud_driver { pciDeviceList *activePciHostdevs; }; -/* XXX temporarily exposed. - * This will be moved back into qemu_driver.c, once the - * qemu_monitor* code is refactored a little more - */ -typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate; -typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr; -struct _qemuDomainObjPrivate { - qemuMonitorPtr mon; -}; - /* Port numbers used for KVM migration. */ #define QEMUD_MIGRATION_FIRST_PORT 49152 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 30cc66e..0fbd20f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -56,7 +56,6 @@ #include "qemu_driver.h" #include "qemu_conf.h" #include "qemu_monitor.h" -#include "qemu_monitor_text.h" #include "c-ctype.h" #include "event.h" #include "buf.h" @@ -77,6 +76,12 @@ #define VIR_FROM_THIS VIR_FROM_QEMU +typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate; +typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr; +struct _qemuDomainObjPrivate { + qemuMonitorPtr mon; +}; + static int qemudShutdown(void); static void qemuDriverLock(struct qemud_driver *driver) @@ -1120,6 +1125,7 @@ qemuDetectVcpuPIDs(virConnectPtr conn, virDomainObjPtr vm) { pid_t *cpupids = NULL; int ncpupids; + qemuDomainObjPrivatePtr priv = vm->privateData; if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM) { vm->nvcpupids = 1; @@ -1133,7 +1139,7 @@ qemuDetectVcpuPIDs(virConnectPtr conn, /* What follows is now all KVM specific */ - if ((ncpupids = qemuMonitorGetCPUInfo(vm, &cpupids)) < 0) + if ((ncpupids = qemuMonitorGetCPUInfo(priv->mon, &cpupids)) < 0) return -1; /* Treat failure to get VCPU<->PID mapping as non-fatal */ @@ -1161,6 +1167,7 @@ qemudInitCpus(virConnectPtr conn, cpu_set_t mask; int i, maxcpu = QEMUD_CPUMASK_LEN; virNodeInfo nodeinfo; + qemuDomainObjPrivatePtr priv = vm->privateData; if (nodeGetInfo(conn, &nodeinfo) < 0) return -1; @@ -1192,7 +1199,7 @@ qemudInitCpus(virConnectPtr conn, if (migrateFrom == NULL) { /* Allow the CPUS to start executing */ - if (qemuMonitorStartCPUs(conn, vm) < 0) { + if (qemuMonitorStartCPUs(priv->mon, conn) < 0) { if (virGetLastError() == NULL) qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("resume operation failed")); @@ -1208,12 +1215,13 @@ static int qemuInitPasswords(struct qemud_driver *driver, virDomainObjPtr vm) { int ret = 0; + qemuDomainObjPrivatePtr priv = vm->privateData; if ((vm->def->ngraphics == 1) && vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC && (vm->def->graphics[0]->data.vnc.passwd || driver->vncPassword)) { - ret = qemuMonitorSetVNCPassword(vm, + ret = qemuMonitorSetVNCPassword(priv->mon, vm->def->graphics[0]->data.vnc.passwd ? vm->def->graphics[0]->data.vnc.passwd : driver->vncPassword); @@ -2081,7 +2089,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, (qemuDetectVcpuPIDs(conn, vm) < 0) || (qemudInitCpus(conn, vm, migrateFrom) < 0) || (qemuInitPasswords(driver, vm) < 0) || - (qemuMonitorSetBalloon(vm, vm->def->memory) < 0) || + (qemuMonitorSetBalloon(((qemuDomainObjPrivatePtr)vm->privateData)->mon, vm->def->memory) < 0) || (virDomainSaveStatus(conn, driver->stateDir, vm) < 0)) { qemudShutdownVMDaemon(conn, driver, vm); ret = -1; @@ -2640,7 +2648,8 @@ static int qemudDomainSuspend(virDomainPtr dom) { goto cleanup; } if (vm->state != VIR_DOMAIN_PAUSED) { - if (qemuMonitorStopCPUs(vm) < 0) + qemuDomainObjPrivatePtr priv = vm->privateData; + if (qemuMonitorStopCPUs(priv->mon) < 0) goto cleanup; vm->state = VIR_DOMAIN_PAUSED; event = virDomainEventNewFromObj(vm, @@ -2684,7 +2693,8 @@ static int qemudDomainResume(virDomainPtr dom) { goto cleanup; } if (vm->state == VIR_DOMAIN_PAUSED) { - if (qemuMonitorStartCPUs(dom->conn, vm) < 0) { + qemuDomainObjPrivatePtr priv = vm->privateData; + if (qemuMonitorStartCPUs(priv->mon, dom->conn) < 0) { if (virGetLastError() == NULL) qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("resume operation failed")); @@ -2732,7 +2742,8 @@ static int qemudDomainShutdown(virDomainPtr dom) { goto cleanup; } - if (qemuMonitorSystemPowerdown(vm) < 0) + qemuDomainObjPrivatePtr priv = vm->privateData; + if (qemuMonitorSystemPowerdown(priv->mon) < 0) goto cleanup; ret = 0; @@ -2893,7 +2904,8 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { } if (virDomainObjIsActive(vm)) { - int r = qemuMonitorSetBalloon(vm, newmem); + qemuDomainObjPrivatePtr priv = vm->privateData; + int r = qemuMonitorSetBalloon(priv->mon, newmem); if (r < 0) goto cleanup; @@ -2947,7 +2959,8 @@ static int qemudDomainGetInfo(virDomainPtr dom, info->maxMem = vm->def->maxmem; if (virDomainObjIsActive(vm)) { - err = qemuMonitorGetBalloonInfo(vm, &balloon); + qemuDomainObjPrivatePtr priv = vm->privateData; + err = qemuMonitorGetBalloonInfo(priv->mon, &balloon); if (err < 0) goto cleanup; @@ -3054,8 +3067,9 @@ static int qemudDomainSave(virDomainPtr dom, /* Pause */ if (vm->state == VIR_DOMAIN_RUNNING) { + qemuDomainObjPrivatePtr priv = vm->privateData; header.was_running = 1; - if (qemuMonitorStopCPUs(vm) < 0) + if (qemuMonitorStopCPUs(priv->mon) < 0) goto cleanup; vm->state = VIR_DOMAIN_PAUSED; } @@ -3098,15 +3112,17 @@ static int qemudDomainSave(virDomainPtr dom, if (header.compressed == QEMUD_SAVE_FORMAT_RAW) { const char *args[] = { "cat", NULL }; - ret = qemuMonitorMigrateToCommand(vm, 0, args, path); + qemuDomainObjPrivatePtr priv = vm->privateData; + ret = qemuMonitorMigrateToCommand(priv->mon, 0, args, path); } else { const char *prog = qemudSaveCompressionTypeToString(header.compressed); + qemuDomainObjPrivatePtr priv = vm->privateData; const char *args[] = { prog, "-c", NULL }; - ret = qemuMonitorMigrateToCommand(vm, 0, args, path); + ret = qemuMonitorMigrateToCommand(priv->mon, 0, args, path); } if (ret < 0) @@ -3173,14 +3189,16 @@ static int qemudDomainCoreDump(virDomainPtr dom, the stop command is issued. */ resume = (vm->state == VIR_DOMAIN_RUNNING); + qemuDomainObjPrivatePtr priv = vm->privateData; + /* Pause domain for non-live dump */ if (vm->state == VIR_DOMAIN_RUNNING) { - if (qemuMonitorStopCPUs(vm) < 0) + if (qemuMonitorStopCPUs(priv->mon) < 0) goto cleanup; paused = 1; } - ret = qemuMonitorMigrateToCommand(vm, 0, args, path); + ret = qemuMonitorMigrateToCommand(priv->mon, 0, args, path); paused = 1; cleanup: @@ -3188,7 +3206,7 @@ cleanup: will support synchronous operations so we always get here after the migration is complete. */ if (resume && paused) { - if (qemuMonitorStartCPUs(dom->conn, vm) < 0) { + if (qemuMonitorStartCPUs(priv->mon, dom->conn) < 0) { if (virGetLastError() == NULL) qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("resuming after dump failed")); @@ -3705,7 +3723,8 @@ static int qemudDomainRestore(virConnectPtr conn, /* If it was running before, resume it now. */ if (header.was_running) { - if (qemuMonitorStartCPUs(conn, vm) < 0) { + qemuDomainObjPrivatePtr priv = vm->privateData; + if (qemuMonitorStartCPUs(priv->mon, conn) < 0) { if (virGetLastError() == NULL) qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("failed to resume domain")); @@ -3752,7 +3771,8 @@ static char *qemudDomainDumpXML(virDomainPtr dom, /* Refresh current memory based on balloon info */ if (virDomainObjIsActive(vm)) { - err = qemuMonitorGetBalloonInfo(vm, &balloon); + qemuDomainObjPrivatePtr priv = vm->privateData; + err = qemuMonitorGetBalloonInfo(priv->mon, &balloon); if (err < 0) goto cleanup; if (err > 0) @@ -4322,10 +4342,11 @@ static int qemudDomainChangeEjectableMedia(virConnectPtr conn, } } + qemuDomainObjPrivatePtr priv = vm->privateData; if (newdisk->src) { - ret = qemuMonitorChangeMedia(vm, devname, newdisk->src); + ret = qemuMonitorChangeMedia(priv->mon, devname, newdisk->src); } else { - ret = qemuMonitorEjectMedia(vm, devname); + ret = qemuMonitorEjectMedia(priv->mon, devname); } if (ret == 0) { @@ -4345,6 +4366,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, { int i; const char* type = virDomainDiskBusTypeToString(dev->data.disk->bus); + qemuDomainObjPrivatePtr priv = vm->privateData; for (i = 0 ; i < vm->def->ndisks ; i++) { if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) { @@ -4359,7 +4381,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, return -1; } - if (qemuMonitorAddPCIDisk(vm, + if (qemuMonitorAddPCIDisk(priv->mon, dev->data.disk->src, type, &dev->data.disk->pci_addr.domain, @@ -4376,6 +4398,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virConnectPtr conn, virDomainObjPtr vm, virDomainDeviceDefPtr dev) { + qemuDomainObjPrivatePtr priv = vm->privateData; int i; for (i = 0 ; i < vm->def->ndisks ; i++) { @@ -4397,7 +4420,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virConnectPtr conn, return -1; } - if (qemuMonitorAddUSBDisk(vm, dev->data.disk->src) < 0) + if (qemuMonitorAddUSBDisk(priv->mon, dev->data.disk->src) < 0) return -1; virDomainDiskInsertPreAlloced(vm->def, dev->data.disk); @@ -4412,6 +4435,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, unsigned int qemuCmdFlags) { virDomainNetDefPtr net = dev->data.net; + qemuDomainObjPrivatePtr priv = vm->privateData; char *tapfd_name = NULL; int i, tapfd = -1; char *nicstr = NULL; @@ -4457,7 +4481,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, if (virAsprintf(&tapfd_name, "fd-%s", net->hostnet_name) < 0) goto no_memory; - if (qemuMonitorSendFileHandle(vm, tapfd_name, tapfd) < 0) + if (qemuMonitorSendFileHandle(priv->mon, tapfd_name, tapfd) < 0) goto cleanup; } @@ -4465,7 +4489,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, net->vlan, tapfd_name, &netstr) < 0) goto try_tapfd_close; - if (qemuMonitorAddHostNetwork(vm, netstr) < 0) + if (qemuMonitorAddHostNetwork(priv->mon, netstr) < 0) goto try_tapfd_close; if (tapfd != -1) @@ -4475,7 +4499,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, if (qemuBuildNicStr(conn, net, NULL, net->vlan, &nicstr) < 0) goto try_remove; - if (qemuMonitorAddPCINetwork(vm, nicstr, + if (qemuMonitorAddPCINetwork(priv->mon, nicstr, &net->pci_addr.domain, &net->pci_addr.bus, &net->pci_addr.slot) < 0) @@ -4497,14 +4521,14 @@ cleanup: try_remove: if (!net->hostnet_name || net->vlan == 0) VIR_WARN0(_("Unable to remove network backend\n")); - else if (qemuMonitorRemoveHostNetwork(vm, net->vlan, net->hostnet_name) < 0) + else if (qemuMonitorRemoveHostNetwork(priv->mon, net->vlan, net->hostnet_name) < 0) VIR_WARN(_("Failed to remove network backend for vlan %d, net %s"), net->vlan, net->hostnet_name); goto cleanup; try_tapfd_close: if (tapfd_name && - qemuMonitorCloseFileHandle(vm, tapfd_name) < 0) + qemuMonitorCloseFileHandle(priv->mon, tapfd_name) < 0) VIR_WARN(_("Failed to close tapfd with '%s'\n"), tapfd_name); goto cleanup; @@ -4519,6 +4543,7 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr conn, virDomainObjPtr vm, virDomainDeviceDefPtr dev) { + qemuDomainObjPrivatePtr priv = vm->privateData; virDomainHostdevDefPtr hostdev = dev->data.hostdev; pciDevice *pci; @@ -4546,7 +4571,7 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr conn, return -1; } - if (qemuMonitorAddPCIHostDevice(vm, + if (qemuMonitorAddPCIHostDevice(priv->mon, hostdev->source.subsys.u.pci.domain, hostdev->source.subsys.u.pci.bus, hostdev->source.subsys.u.pci.slot, @@ -4571,6 +4596,7 @@ static int qemudDomainAttachHostUsbDevice(virConnectPtr conn, virDomainDeviceDefPtr dev) { int ret; + qemuDomainObjPrivatePtr priv = vm->privateData; if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { virReportOOMError(conn); @@ -4578,11 +4604,11 @@ static int qemudDomainAttachHostUsbDevice(virConnectPtr conn, } if (dev->data.hostdev->source.subsys.u.usb.vendor) { - ret = qemuMonitorAddUSBDeviceMatch(vm, + ret = qemuMonitorAddUSBDeviceMatch(priv->mon, dev->data.hostdev->source.subsys.u.usb.vendor, dev->data.hostdev->source.subsys.u.usb.product); } else { - ret = qemuMonitorAddUSBDeviceExact(vm, + ret = qemuMonitorAddUSBDeviceExact(priv->mon, dev->data.hostdev->source.subsys.u.usb.bus, dev->data.hostdev->source.subsys.u.usb.device); } @@ -4756,6 +4782,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn, { int i, ret = -1; virDomainDiskDefPtr detach = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; for (i = 0 ; i < vm->def->ndisks ; i++) { if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) { @@ -4777,7 +4804,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn, goto cleanup; } - if (qemuMonitorRemovePCIDevice(vm, + if (qemuMonitorRemovePCIDevice(priv->mon, detach->pci_addr.domain, detach->pci_addr.bus, detach->pci_addr.slot) < 0) @@ -4811,6 +4838,7 @@ qemudDomainDetachNetDevice(virConnectPtr conn, { int i, ret = -1; virDomainNetDefPtr detach = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; for (i = 0 ; i < vm->def->nnets ; i++) { virDomainNetDefPtr net = vm->def->nets[i]; @@ -4836,13 +4864,13 @@ qemudDomainDetachNetDevice(virConnectPtr conn, goto cleanup; } - if (qemuMonitorRemovePCIDevice(vm, + if (qemuMonitorRemovePCIDevice(priv->mon, detach->pci_addr.domain, detach->pci_addr.bus, detach->pci_addr.slot) < 0) goto cleanup; - if (qemuMonitorRemoveHostNetwork(vm, detach->vlan, detach->hostnet_name) < 0) + if (qemuMonitorRemoveHostNetwork(priv->mon, detach->vlan, detach->hostnet_name) < 0) goto cleanup; if (vm->def->nnets > 1) { @@ -4872,6 +4900,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn, virDomainDeviceDefPtr dev) { virDomainHostdevDefPtr detach = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; int i, ret; pciDevice *pci; @@ -4906,7 +4935,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn, return -1; } - if (qemuMonitorRemovePCIDevice(vm, + if (qemuMonitorRemovePCIDevice(priv->mon, detach->source.subsys.u.pci.guest_addr.domain, detach->source.subsys.u.pci.guest_addr.bus, detach->source.subsys.u.pci.guest_addr.slot) < 0) @@ -5339,7 +5368,9 @@ qemudDomainBlockStats (virDomainPtr dom, if (!qemu_dev_name) goto cleanup; - if (qemuMonitorGetBlockStatsInfo(vm, qemu_dev_name, + qemuDomainObjPrivatePtr priv = vm->privateData; + if (qemuMonitorGetBlockStatsInfo(priv->mon, + qemu_dev_name, &stats->rd_req, &stats->rd_bytes, &stats->wr_req, @@ -5536,11 +5567,12 @@ qemudDomainMemoryPeek (virDomainPtr dom, goto cleanup; } + qemuDomainObjPrivatePtr priv = vm->privateData; if (flags == VIR_MEMORY_VIRTUAL) { - if (qemuMonitorSaveVirtualMemory(vm, offset, size, tmp) < 0) + if (qemuMonitorSaveVirtualMemory(priv->mon, offset, size, tmp) < 0) goto cleanup; } else { - if (qemuMonitorSavePhysicalMemory(vm, offset, size, tmp) < 0) + if (qemuMonitorSavePhysicalMemory(priv->mon, offset, size, tmp) < 0) goto cleanup; } @@ -6293,6 +6325,7 @@ static int doNativeMigrate(virDomainPtr dom, xmlURIPtr uribits = NULL; int status; unsigned long long transferred, remaining, total; + qemuDomainObjPrivatePtr priv = vm->privateData; /* Issue the migrate command. */ if (STRPREFIX(uri, "tcp:") && !STRPREFIX(uri, "tcp://")) { @@ -6314,16 +6347,17 @@ static int doNativeMigrate(virDomainPtr dom, } if (resource > 0 && - qemuMonitorSetMigrationSpeed(vm, resource) < 0) + qemuMonitorSetMigrationSpeed(priv->mon, resource) < 0) goto cleanup; - if (qemuMonitorMigrateToHost(vm, 0, uribits->server, uribits->port) < 0) + if (qemuMonitorMigrateToHost(priv->mon, 0, uribits->server, uribits->port) < 0) goto cleanup; /* it is also possible that the migrate didn't fail initially, but * rather failed later on. Check the output of "info migrate" */ - if (qemuMonitorGetMigrationStatus(vm, &status, + if (qemuMonitorGetMigrationStatus(priv->mon, + &status, &transferred, &remaining, &total) < 0) { @@ -6388,6 +6422,7 @@ static int doTunnelMigrate(virDomainPtr dom, unsigned long resource) { struct qemud_driver *driver = dom->conn->privateData; + qemuDomainObjPrivatePtr priv = vm->privateData; int client_sock = -1; int qemu_sock = -1; struct sockaddr_un sa_qemu, sa_client; @@ -6485,10 +6520,10 @@ static int doTunnelMigrate(virDomainPtr dom, /* 3. start migration on source */ if (qemuCmdFlags & QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX) - internalret = qemuMonitorMigrateToUnix(vm, 1, unixfile); + internalret = qemuMonitorMigrateToUnix(priv->mon, 1, unixfile); else if (qemuCmdFlags & QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC) { const char *args[] = { "nc", "-U", unixfile, NULL }; - internalret = qemuMonitorMigrateToCommand(vm, 1, args, "/dev/null"); + internalret = qemuMonitorMigrateToCommand(priv->mon, 1, args, "/dev/null"); } else { internalret = -1; } @@ -6504,7 +6539,8 @@ static int doTunnelMigrate(virDomainPtr dom, /* it is also possible that the migrate didn't fail initially, but * rather failed later on. Check the output of "info migrate" */ - if (qemuMonitorGetMigrationStatus(vm, &status, + if (qemuMonitorGetMigrationStatus(priv->mon, + &status, &transferred, &remaining, &total) < 0) { @@ -6530,7 +6566,7 @@ static int doTunnelMigrate(virDomainPtr dom, cancel: if (retval != 0) - qemuMonitorMigrateCancel(vm); + qemuMonitorMigrateCancel(priv->mon); finish: dname = dname ? dname : dom->name; @@ -6691,8 +6727,9 @@ qemudDomainMigratePerform (virDomainPtr dom, } if (!(flags & VIR_MIGRATE_LIVE)) { + qemuDomainObjPrivatePtr priv = vm->privateData; /* Pause domain for non-live migration */ - if (qemuMonitorStopCPUs(vm) < 0) + if (qemuMonitorStopCPUs(priv->mon) < 0) goto cleanup; paused = 1; @@ -6729,8 +6766,9 @@ qemudDomainMigratePerform (virDomainPtr dom, cleanup: if (paused) { + qemuDomainObjPrivatePtr priv = vm->privateData; /* we got here through some sort of failure; start the domain again */ - if (qemuMonitorStartCPUs(dom->conn, vm) < 0) { + if (qemuMonitorStartCPUs(priv->mon, dom->conn) < 0) { /* Hm, we already know we are in error here. We don't want to * overwrite the previous error, though, so we just throw something * to the logs and hope for the best @@ -6808,13 +6846,14 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn, qemuDomainEventQueue(driver, event); } + qemuDomainObjPrivatePtr priv = vm->privateData; dom = virGetDomain (dconn, vm->def->name, vm->def->uuid); /* run 'cont' on the destination, which allows migration on qemu * >= 0.10.6 to work properly. This isn't strictly necessary on * older qemu's, but it also doesn't hurt anything there */ - if (qemuMonitorStartCPUs(dconn, vm) < 0) { + if (qemuMonitorStartCPUs(priv->mon, dconn) < 0) { if (virGetLastError() == NULL) qemudReportError(dconn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("resume operation failed")); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 352328d..46d5d9f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -29,6 +29,7 @@ #include <fcntl.h> #include "qemu_monitor.h" +#include "qemu_monitor_text.h" #include "qemu_conf.h" #include "event.h" #include "virterror_internal.h" @@ -432,3 +433,321 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, return mon->secretCB(mon, conn, mon->vm, path, secret, secretLen); } + + +int +qemuMonitorStartCPUs(qemuMonitorPtr mon, + virConnectPtr conn) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextStartCPUs(mon, conn); +} + + +int +qemuMonitorStopCPUs(qemuMonitorPtr mon) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextStopCPUs(mon); +} + + +int qemuMonitorSystemPowerdown(qemuMonitorPtr mon) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextSystemPowerdown(mon); +} + + +int qemuMonitorGetCPUInfo(qemuMonitorPtr mon, + int **pids) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextGetCPUInfo(mon, pids); +} + +int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon, + unsigned long *currmem) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextGetBalloonInfo(mon, currmem); +} + + +int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon, + const char *devname, + long long *rd_req, + long long *rd_bytes, + long long *wr_req, + long long *wr_bytes, + long long *errs) +{ + DEBUG("mon=%p, fd=%d dev=%s", mon, mon->fd, devname); + + return qemuMonitorTextGetBlockStatsInfo(mon, devname, + rd_req, rd_bytes, + wr_req, wr_bytes, + errs); +} + + +int qemuMonitorSetVNCPassword(qemuMonitorPtr mon, + const char *password) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextSetVNCPassword(mon, password); +} + + +int qemuMonitorSetBalloon(qemuMonitorPtr mon, + unsigned long newmem) +{ + DEBUG("mon=%p, fd=%d newmem=%lu", mon, mon->fd, newmem); + + return qemuMonitorTextSetBalloon(mon, newmem); +} + +int qemuMonitorEjectMedia(qemuMonitorPtr mon, + const char *devname) +{ + DEBUG("mon=%p, fd=%d devname=%s", mon, mon->fd, devname); + + return qemuMonitorTextEjectMedia(mon, devname); +} + + +int qemuMonitorChangeMedia(qemuMonitorPtr mon, + const char *devname, + const char *newmedia) +{ + DEBUG("mon=%p, fd=%d devname=%s newmedia=%s", + mon, mon->fd, devname, newmedia); + + return qemuMonitorTextChangeMedia(mon, devname, newmedia); +} + + +int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path) +{ + DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s", + mon, mon->fd, offset, length, path); + + return qemuMonitorTextSaveVirtualMemory(mon, offset, length, path); +} + +int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path) +{ + DEBUG("mon=%p, fd=%d offset=%llu length=%zu path=%s", + mon, mon->fd, offset, length, path); + + return qemuMonitorTextSavePhysicalMemory(mon, offset, length, path); +} + + +int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon, + unsigned long bandwidth) +{ + DEBUG("mon=%p, fd=%d bandwidth=%lu", mon, mon->fd, bandwidth); + + return qemuMonitorTextSetMigrationSpeed(mon, bandwidth); +} + +int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon, + int *status, + unsigned long long *transferred, + unsigned long long *remaining, + unsigned long long *total) +{ + DEBUG("mon=%p, fd=%d", mon, mon->fd); + + return qemuMonitorTextGetMigrationStatus(mon, status, + transferred, + remaining, + total); +} + + +int qemuMonitorMigrateToHost(qemuMonitorPtr mon, + int background, + const char *hostname, + int port) +{ + DEBUG("mon=%p, fd=%d hostname=%s port=%d", + mon, mon->fd, hostname, port); + + return qemuMonitorTextMigrateToHost(mon, background, hostname, port); +} + + +int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, + int background, + const char * const *argv, + const char *target) +{ + DEBUG("mon=%p, fd=%d argv=%p target=%s", + mon, mon->fd, argv, target); + + return qemuMonitorTextMigrateToCommand(mon, background, argv, target); +} + +int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, + int background, + const char *unixfile) +{ + DEBUG("mon=%p fd=%d unixfile=%s", + mon, mon->fd, unixfile); + + return qemuMonitorTextMigrateToUnix(mon, background, unixfile); +} + +int qemuMonitorMigrateCancel(qemuMonitorPtr mon) +{ + DEBUG("mon=%p fd=%d", mon, mon->fd); + + return qemuMonitorTextMigrateCancel(mon); +} + +int qemuMonitorAddUSBDisk(qemuMonitorPtr mon, + const char *path) +{ + DEBUG("mon=%p, fd=%d path=%s", mon, mon->fd, path); + + return qemuMonitorTextAddUSBDisk(mon, path); +} + + +int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon, + int bus, + int dev) +{ + DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, bus, dev); + + return qemuMonitorTextAddUSBDeviceExact(mon, bus, dev); +} + +int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon, + int vendor, + int product) +{ + DEBUG("mon=%p, fd=%d vendor=%d product=%d", + mon, mon->fd, vendor, product); + + return qemuMonitorTextAddUSBDeviceMatch(mon, vendor, product); +} + + +int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon, + unsigned hostDomain, + unsigned hostBus, + unsigned hostSlot, + unsigned hostFunction, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) +{ + DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d", + mon, mon->fd, + hostDomain, hostBus, hostSlot, hostFunction); + + return qemuMonitorTextAddPCIHostDevice(mon, hostDomain, + hostBus, hostSlot, + hostFunction, + guestDomain, + guestBus, + guestSlot); +} + + +int qemuMonitorAddPCIDisk(qemuMonitorPtr mon, + const char *path, + const char *bus, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) +{ + DEBUG("mon=%p, fd=%d path=%s bus=%s", + mon, mon->fd, path, bus); + + return qemuMonitorTextAddPCIDisk(mon, path, bus, + guestDomain, guestBus, guestSlot); +} + + +int qemuMonitorAddPCINetwork(qemuMonitorPtr mon, + const char *nicstr, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) +{ + DEBUG("mon=%p, fd=%d nicstr=%s", mon, mon->fd, nicstr); + + return qemuMonitorTextAddPCINetwork(mon, nicstr, guestDomain, + guestBus, guestSlot); +} + + +int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon, + unsigned guestDomain, + unsigned guestBus, + unsigned guestSlot) +{ + DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d", + mon, mon->fd, guestDomain, guestBus, guestSlot); + + return qemuMonitorTextRemovePCIDevice(mon, guestDomain, + guestBus, guestSlot); +} + + +int qemuMonitorSendFileHandle(qemuMonitorPtr mon, + const char *fdname, + int fd) +{ + DEBUG("mon=%p, fd=%d fdname=%s fd=%d", + mon, mon->fd, fdname, fd); + + return qemuMonitorTextSendFileHandle(mon, fdname, fd); +} + + +int qemuMonitorCloseFileHandle(qemuMonitorPtr mon, + const char *fdname) +{ + DEBUG("mon=%p, fd=%d fdname=%s", + mon, mon->fd, fdname); + + return qemuMonitorTextCloseFileHandle(mon, fdname); +} + + +int qemuMonitorAddHostNetwork(qemuMonitorPtr mon, + const char *netstr) +{ + DEBUG("mon=%p, fd=%d netstr=%s", + mon, mon->fd, netstr); + + return qemuMonitorTextAddHostNetwork(mon, netstr); +} + + +int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon, + int vlan, + const char *netname) +{ + DEBUG("mon=%p, fd=%d netname=%s", + mon, mon->fd, netname); + + return qemuMonitorTextRemoveHostNetwork(mon, vlan, netname); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6fb99a9..5f06155 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -78,4 +78,152 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, char **secret, size_t *secretLen); + +int qemuMonitorStartCPUs(qemuMonitorPtr mon, + virConnectPtr conn); +int qemuMonitorStopCPUs(qemuMonitorPtr mon); + +int qemuMonitorSystemPowerdown(qemuMonitorPtr mon); + +int qemuMonitorGetCPUInfo(qemuMonitorPtr mon, + int **pids); +int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon, + unsigned long *currmem); +int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon, + const char *devname, + long long *rd_req, + long long *rd_bytes, + long long *wr_req, + long long *wr_bytes, + long long *errs); + + +int qemuMonitorSetVNCPassword(qemuMonitorPtr mon, + const char *password); +int qemuMonitorSetBalloon(qemuMonitorPtr mon, + unsigned long newmem); + +/* XXX should we pass the virDomainDiskDefPtr instead + * and hide devname details inside monitor. Reconsider + * this when doing the QMP implementation + */ +int qemuMonitorEjectMedia(qemuMonitorPtr mon, + const char *devname); +int qemuMonitorChangeMedia(qemuMonitorPtr mon, + const char *devname, + const char *newmedia); + + +int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path); +int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path); + +int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon, + unsigned long bandwidth); + +enum { + QEMU_MONITOR_MIGRATION_STATUS_INACTIVE, + QEMU_MONITOR_MIGRATION_STATUS_ACTIVE, + QEMU_MONITOR_MIGRATION_STATUS_COMPLETED, + QEMU_MONITOR_MIGRATION_STATUS_ERROR, + QEMU_MONITOR_MIGRATION_STATUS_CANCELLED, + + QEMU_MONITOR_MIGRATION_STATUS_LAST +}; + +int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon, + int *status, + unsigned long long *transferred, + unsigned long long *remaining, + unsigned long long *total); + +int qemuMonitorMigrateToHost(qemuMonitorPtr mon, + int background, + const char *hostname, + int port); + +int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, + int background, + const char * const *argv, + const char *target); + +int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, + int background, + const char *unixfile); + +int qemuMonitorMigrateCancel(qemuMonitorPtr mon); + + +/* XXX disk driver type eg, qcow/etc. + * XXX cache mode + */ +int qemuMonitorAddUSBDisk(qemuMonitorPtr mon, + const char *path); + +int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon, + int bus, + int dev); +int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon, + int vendor, + int product); + + +int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon, + unsigned hostDomain, + unsigned hostBus, + unsigned hostSlot, + unsigned hostFunction, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +/* XXX disk driver type eg, qcow/etc. + * XXX cache mode + */ +int qemuMonitorAddPCIDisk(qemuMonitorPtr mon, + const char *path, + const char *bus, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +/* XXX do we really want to hardcode 'nicstr' as the + * sendable item here + */ +int qemuMonitorAddPCINetwork(qemuMonitorPtr mon, + const char *nicstr, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon, + unsigned guestDomain, + unsigned guestBus, + unsigned guestSlot); + + +int qemuMonitorSendFileHandle(qemuMonitorPtr mon, + const char *fdname, + int fd); + +int qemuMonitorCloseFileHandle(qemuMonitorPtr mon, + const char *fdname); + + +/* XXX do we really want to hardcode 'netstr' as the + * sendable item here + */ +int qemuMonitorAddHostNetwork(qemuMonitorPtr mon, + const char *netstr); + +int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon, + int vlan, + const char *netname); + + #endif /* QEMU_MONITOR_H */ diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index a0146ae..7ad7f09 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -45,7 +45,7 @@ #define QEMU_PASSWD_PROMPT "Password: " /* Return -1 for error, 0 for success */ -typedef int qemuMonitorExtraPromptHandler(const virDomainObjPtr vm, +typedef int qemuMonitorExtraPromptHandler(qemuMonitorPtr mon, const char *buf, const char *prompt, void *data); @@ -141,8 +141,7 @@ static char *qemuMonitorEscapeShell(const char *in) * when we reconnect to the monitor after restarts. */ static void -qemuMonitorDiscardPendingData(virDomainObjPtr vm) { - qemuDomainObjPrivatePtr priv = vm->privateData; +qemuMonitorDiscardPendingData(qemuMonitorPtr mon) { char buf[1024]; int ret = 0; @@ -150,17 +149,16 @@ qemuMonitorDiscardPendingData(virDomainObjPtr vm) { * get -1 or 0. Don't bother with detecting * errors, since we'll deal with that better later */ do { - ret = qemuMonitorRead(priv->mon, buf, sizeof (buf)-1); + ret = qemuMonitorRead(mon, buf, sizeof (buf)-1); } while (ret > 0); } static int -qemuMonitorSend(const virDomainObjPtr vm, +qemuMonitorSend(qemuMonitorPtr mon, const char *cmd, int scm_fd) { - qemuDomainObjPrivatePtr priv = vm->privateData; char *full; size_t len; int ret = -1; @@ -171,35 +169,29 @@ qemuMonitorSend(const virDomainObjPtr vm, len = strlen(full); if (scm_fd == -1) - ret = qemuMonitorWrite(priv->mon, full, len); + ret = qemuMonitorWrite(mon, full, len); else - ret = qemuMonitorWriteWithFD(priv->mon, full, len, scm_fd); + ret = qemuMonitorWriteWithFD(mon, full, len, scm_fd); VIR_FREE(full); return ret; } static int -qemuMonitorCommandWithHandler(const virDomainObjPtr vm, +qemuMonitorCommandWithHandler(qemuMonitorPtr mon, const char *cmd, const char *extraPrompt, qemuMonitorExtraPromptHandler extraHandler, void *handlerData, int scm_fd, char **reply) { - qemuDomainObjPrivatePtr priv = vm->privateData; int size = 0; char *buf = NULL; - /* Should never happen, but just in case, protect - * against null monitor (ocurrs when VM is inactive) */ - if (!priv->mon) - return -1; - - qemuMonitorDiscardPendingData(vm); + qemuMonitorDiscardPendingData(mon); VIR_DEBUG("cmd='%s' extraPrompt='%s'", cmd, NULLSTR(extraPrompt)); - if (qemuMonitorSend(vm, cmd, scm_fd) < 0) + if (qemuMonitorSend(mon, cmd, scm_fd) < 0) return -1; *reply = NULL; @@ -208,7 +200,7 @@ qemuMonitorCommandWithHandler(const virDomainObjPtr vm, /* Read all the data QEMU has sent thus far */ for (;;) { char data[1024]; - int got = qemuMonitorRead(priv->mon, data, sizeof(data)); + int got = qemuMonitorRead(mon, data, sizeof(data)); if (got == 0) goto error; @@ -237,7 +229,7 @@ qemuMonitorCommandWithHandler(const virDomainObjPtr vm, char *promptEnd; DEBUG("prompt='%s' handler=%p", extraPrompt, extraHandler); - if (extraHandler(vm, buf, foundPrompt, handlerData) < 0) + if (extraHandler(mon, buf, foundPrompt, handlerData) < 0) return -1; /* Discard output so far, necessary to detect whether extraPrompt appears again. We don't need the output between @@ -268,7 +260,7 @@ qemuMonitorCommandWithHandler(const virDomainObjPtr vm, } /* Need to wait for more data */ - if (qemuMonitorWaitForInput(priv->mon) < 0) + if (qemuMonitorWaitForInput(mon) < 0) goto error; } *reply = buf; @@ -287,7 +279,7 @@ struct extraHandlerData }; static int -qemuMonitorCommandSimpleExtraHandler(const virDomainObjPtr vm, +qemuMonitorCommandSimpleExtraHandler(qemuMonitorPtr mon, const char *buf ATTRIBUTE_UNUSED, const char *prompt ATTRIBUTE_UNUSED, void *data_) @@ -296,14 +288,14 @@ qemuMonitorCommandSimpleExtraHandler(const virDomainObjPtr vm, if (!data->first) return 0; - if (qemuMonitorSend(vm, data->reply, -1) < 0) + if (qemuMonitorSend(mon, data->reply, -1) < 0) return -1; data->first = false; return 0; } static int -qemuMonitorCommandExtra(const virDomainObjPtr vm, +qemuMonitorCommandExtra(qemuMonitorPtr mon, const char *cmd, const char *extra, const char *extraPrompt, @@ -313,35 +305,34 @@ qemuMonitorCommandExtra(const virDomainObjPtr vm, data.reply = extra; data.first = true; - return qemuMonitorCommandWithHandler(vm, cmd, extraPrompt, + return qemuMonitorCommandWithHandler(mon, cmd, extraPrompt, qemuMonitorCommandSimpleExtraHandler, &data, scm_fd, reply); } static int -qemuMonitorCommandWithFd(const virDomainObjPtr vm, +qemuMonitorCommandWithFd(qemuMonitorPtr mon, const char *cmd, int scm_fd, char **reply) { - return qemuMonitorCommandExtra(vm, cmd, NULL, NULL, scm_fd, reply); + return qemuMonitorCommandExtra(mon, cmd, NULL, NULL, scm_fd, reply); } static int -qemuMonitorCommand(const virDomainObjPtr vm, +qemuMonitorCommand(qemuMonitorPtr mon, const char *cmd, char **reply) { - return qemuMonitorCommandWithFd(vm, cmd, -1, reply); + return qemuMonitorCommandWithFd(mon, cmd, -1, reply); } static int -qemuMonitorSendVolumePassphrase(const virDomainObjPtr vm, +qemuMonitorSendVolumePassphrase(qemuMonitorPtr mon, const char *buf, const char *prompt, void *data) { virConnectPtr conn = data; - qemuDomainObjPrivatePtr priv = vm->privateData; char *passphrase = NULL, *path; const char *prompt_path; size_t path_len, passphrase_len = 0; @@ -362,13 +353,13 @@ qemuMonitorSendVolumePassphrase(const virDomainObjPtr vm, memcpy(path, prompt_path, path_len); path[path_len] = '\0'; - res = qemuMonitorGetDiskSecret(priv->mon, conn, path, + res = qemuMonitorGetDiskSecret(mon, conn, path, &passphrase, &passphrase_len); VIR_FREE(path); if (res < 0) return -1; - res = qemuMonitorSend(vm, passphrase, -1); + res = qemuMonitorSend(mon, passphrase, -1); memset(passphrase, 0, passphrase_len); VIR_FREE(passphrase); @@ -377,13 +368,11 @@ qemuMonitorSendVolumePassphrase(const virDomainObjPtr vm, } int -qemuMonitorStartCPUs(virConnectPtr conn, - const virDomainObjPtr vm) { +qemuMonitorTextStartCPUs(qemuMonitorPtr mon, + virConnectPtr conn) { char *reply; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommandWithHandler(vm, "cont", ") is encrypted.", + if (qemuMonitorCommandWithHandler(mon, "cont", ") is encrypted.", qemuMonitorSendVolumePassphrase, conn, -1, &reply) < 0) return -1; @@ -394,12 +383,10 @@ qemuMonitorStartCPUs(virConnectPtr conn, int -qemuMonitorStopCPUs(const virDomainObjPtr vm) { +qemuMonitorTextStopCPUs(qemuMonitorPtr mon) { char *info; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommand(vm, "stop", &info) < 0) { + if (qemuMonitorCommand(mon, "stop", &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("cannot stop CPU execution")); return -1; @@ -409,12 +396,10 @@ qemuMonitorStopCPUs(const virDomainObjPtr vm) { } -int qemuMonitorSystemPowerdown(const virDomainObjPtr vm) { +int qemuMonitorTextSystemPowerdown(qemuMonitorPtr mon) { char *info; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommand(vm, "system_powerdown", &info) < 0) { + if (qemuMonitorCommand(mon, "system_powerdown", &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("system shutdown operation failed")); return -1; @@ -424,8 +409,8 @@ int qemuMonitorSystemPowerdown(const virDomainObjPtr vm) { } -int qemuMonitorGetCPUInfo(const virDomainObjPtr vm, - int **pids) +int qemuMonitorTextGetCPUInfo(qemuMonitorPtr mon, + int **pids) { char *qemucpus = NULL; char *line; @@ -433,9 +418,7 @@ int qemuMonitorGetCPUInfo(const virDomainObjPtr vm, pid_t *cpupids = NULL; size_t ncpupids = 0; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommand(vm, "info cpus", &qemucpus) < 0) { + if (qemuMonitorCommand(mon, "info cpus", &qemucpus) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot run monitor command to fetch CPU thread info")); return -1; @@ -517,16 +500,14 @@ error: * Returns: 0 if balloon not supported, +1 if balloon query worked * or -1 on failure */ -int qemuMonitorGetBalloonInfo(const virDomainObjPtr vm, - unsigned long *currmem) +int qemuMonitorTextGetBalloonInfo(qemuMonitorPtr mon, + unsigned long *currmem) { char *reply = NULL; int ret = -1; char *offset; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommand(vm, "info balloon", &reply) < 0) { + if (qemuMonitorCommand(mon, "info balloon", &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("could not query memory balloon allocation")); return -1; @@ -556,13 +537,13 @@ cleanup: } -int qemuMonitorGetBlockStatsInfo(const virDomainObjPtr vm, - const char *devname, - long long *rd_req, - long long *rd_bytes, - long long *wr_req, - long long *wr_bytes, - long long *errs) +int qemuMonitorTextGetBlockStatsInfo(qemuMonitorPtr mon, + const char *devname, + long long *rd_req, + long long *rd_bytes, + long long *wr_req, + long long *wr_bytes, + long long *errs) { char *info = NULL; int ret = -1; @@ -570,10 +551,7 @@ int qemuMonitorGetBlockStatsInfo(const virDomainObjPtr vm, const char *p, *eol; int devnamelen = strlen(devname); - DEBUG("vm=%p, pid=%d, id=%d, name=%s dev=%s", - vm, vm->pid, vm->def->id, vm->def->name, devname); - - if (qemuMonitorCommand (vm, "info blockstats", &info) < 0) { + if (qemuMonitorCommand (mon, "info blockstats", &info) < 0) { qemudReportError (NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("'info blockstats' command failed")); goto cleanup; @@ -618,25 +596,21 @@ int qemuMonitorGetBlockStatsInfo(const virDomainObjPtr vm, if (STRPREFIX (p, "rd_bytes=")) { p += 9; if (virStrToLong_ll (p, &dummy, 10, rd_bytes) == -1) - DEBUG ("%s: error reading rd_bytes: %s", - vm->def->name, p); + DEBUG ("error reading rd_bytes: %s", p); } else if (STRPREFIX (p, "wr_bytes=")) { p += 9; if (virStrToLong_ll (p, &dummy, 10, wr_bytes) == -1) - DEBUG ("%s: error reading wr_bytes: %s", - vm->def->name, p); + DEBUG ("error reading wr_bytes: %s", p); } else if (STRPREFIX (p, "rd_operations=")) { p += 14; if (virStrToLong_ll (p, &dummy, 10, rd_req) == -1) - DEBUG ("%s: error reading rd_req: %s", - vm->def->name, p); + DEBUG ("error reading rd_req: %s", p); } else if (STRPREFIX (p, "wr_operations=")) { p += 14; if (virStrToLong_ll (p, &dummy, 10, wr_req) == -1) - DEBUG ("%s: error reading wr_req: %s", - vm->def->name, p); + DEBUG ("error reading wr_req: %s", p); } else - DEBUG ("%s: unknown block stat near %s", vm->def->name, p); + DEBUG ("unknown block stat near %s", p); /* Skip to next label. */ p = strchr (p, ' '); @@ -663,14 +637,12 @@ int qemuMonitorGetBlockStatsInfo(const virDomainObjPtr vm, } -int qemuMonitorSetVNCPassword(const virDomainObjPtr vm, - const char *password) +int qemuMonitorTextSetVNCPassword(qemuMonitorPtr mon, + const char *password) { char *info = NULL; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - - if (qemuMonitorCommandExtra(vm, "change vnc password", + if (qemuMonitorCommandExtra(mon, "change vnc password", password, QEMU_PASSWD_PROMPT, -1, &info) < 0) { @@ -686,16 +658,13 @@ int qemuMonitorSetVNCPassword(const virDomainObjPtr vm, * Returns: 0 if balloon not supported, +1 if balloon adjust worked * or -1 on failure */ -int qemuMonitorSetBalloon(const virDomainObjPtr vm, - unsigned long newmem) +int qemuMonitorTextSetBalloon(qemuMonitorPtr mon, + unsigned long newmem) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s newmem=%lu", - vm, vm->pid, vm->def->id, vm->def->name, newmem); - /* * 'newmem' is in KB, QEMU monitor works in MB, and we all wish * we just worked in bytes with unsigned long long everywhere. @@ -705,7 +674,7 @@ int qemuMonitorSetBalloon(const virDomainObjPtr vm, return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("could not balloon memory allocation")); VIR_FREE(cmd); @@ -726,22 +695,19 @@ int qemuMonitorSetBalloon(const virDomainObjPtr vm, return ret; } -int qemuMonitorEjectMedia(const virDomainObjPtr vm, - const char *devname) +int qemuMonitorTextEjectMedia(qemuMonitorPtr mon, + const char *devname) { char *cmd = NULL; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s devname=%s", - vm, vm->pid, vm->def->id, vm->def->name, devname); - if (virAsprintf(&cmd, "eject %s", devname) < 0) { virReportOOMError(NULL); goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("could not eject media on %s"), devname); goto cleanup; @@ -765,18 +731,15 @@ cleanup: } -int qemuMonitorChangeMedia(const virDomainObjPtr vm, - const char *devname, - const char *newmedia) +int qemuMonitorTextChangeMedia(qemuMonitorPtr mon, + const char *devname, + const char *newmedia) { char *cmd = NULL; char *reply = NULL; char *safepath = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s devname=%s newmedia=%s", - vm, vm->pid, vm->def->id, vm->def->name, devname, newmedia); - if (!(safepath = qemuMonitorEscapeArg(newmedia))) { virReportOOMError(NULL); goto cleanup; @@ -787,7 +750,7 @@ int qemuMonitorChangeMedia(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("could not eject media on %s"), devname); goto cleanup; @@ -811,11 +774,11 @@ cleanup: return ret; } -static int qemuMonitorSaveMemory(const virDomainObjPtr vm, - const char *cmdtype, - unsigned long long offset, - size_t length, - const char *path) +static int qemuMonitorTextSaveMemory(qemuMonitorPtr mon, + const char *cmdtype, + unsigned long long offset, + size_t length, + const char *path) { char *cmd = NULL; char *reply = NULL; @@ -832,7 +795,7 @@ static int qemuMonitorSaveMemory(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("could save memory region to '%s'"), path); goto cleanup; @@ -850,45 +813,36 @@ cleanup: } -int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm, - unsigned long long offset, - size_t length, - const char *path) +int qemuMonitorTextSaveVirtualMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path) { - DEBUG("vm=%p, pid=%d, id=%d, name=%s offset=%llu length=%zu path=%s", - vm, vm->pid, vm->def->id, vm->def->name, offset, length, path); - - return qemuMonitorSaveMemory(vm, "memsave", offset, length, path); + return qemuMonitorTextSaveMemory(mon, "memsave", offset, length, path); } -int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm, - unsigned long long offset, - size_t length, - const char *path) +int qemuMonitorTextSavePhysicalMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path) { - DEBUG("vm=%p, pid=%d, id=%d, name=%s offset=%llu length=%zu path=%s", - vm, vm->pid, vm->def->id, vm->def->name, offset, length, path); - - return qemuMonitorSaveMemory(vm, "pmemsave", offset, length, path); + return qemuMonitorTextSaveMemory(mon, "pmemsave", offset, length, path); } -int qemuMonitorSetMigrationSpeed(const virDomainObjPtr vm, - unsigned long bandwidth) +int qemuMonitorTextSetMigrationSpeed(qemuMonitorPtr mon, + unsigned long bandwidth) { char *cmd = NULL; char *info = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s bandwidth=%lu", - vm, vm->pid, vm->def->id, vm->def->name, bandwidth); - if (virAsprintf(&cmd, "migrate_set_speed %lum", bandwidth) < 0) { virReportOOMError(NULL); goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &info) < 0) { + if (qemuMonitorCommand(mon, cmd, &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("could restrict migration speed")); goto cleanup; @@ -913,24 +867,22 @@ VIR_ENUM_IMPL(qemuMonitorMigrationStatus, QEMU_MONITOR_MIGRATION_STATUS_LAST, "inactive", "active", "completed", "failed", "cancelled") -int qemuMonitorGetMigrationStatus(const virDomainObjPtr vm, - int *status, - unsigned long long *transferred, - unsigned long long *remaining, - unsigned long long *total) { +int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon, + int *status, + unsigned long long *transferred, + unsigned long long *remaining, + unsigned long long *total) { char *reply; char *tmp; char *end; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s", vm, vm->pid, vm->def->id, vm->def->name); - *status = QEMU_MONITOR_MIGRATION_STATUS_INACTIVE; *transferred = 0; *remaining = 0; *total = 0; - if (qemuMonitorCommand(vm, "info migrate", &reply) < 0) { + if (qemuMonitorCommand(mon, "info migrate", &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("cannot query migration status")); return -1; @@ -995,9 +947,9 @@ cleanup: } -static int qemuMonitorMigrate(const virDomainObjPtr vm, - int background, - const char *dest) +static int qemuMonitorTextMigrate(qemuMonitorPtr mon, + int background, + const char *dest) { char *cmd = NULL; char *info = NULL; @@ -1020,7 +972,7 @@ static int qemuMonitorMigrate(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &info) < 0) { + if (qemuMonitorCommand(mon, cmd, &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("unable to start migration to %s"), dest); goto cleanup; @@ -1050,23 +1002,20 @@ cleanup: return ret; } -int qemuMonitorMigrateToHost(const virDomainObjPtr vm, - int background, - const char *hostname, - int port) +int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon, + int background, + const char *hostname, + int port) { char *uri = NULL; int ret; - DEBUG("vm=%p, pid=%d, id=%d, name=%s hostname=%s port=%d", - vm, vm->pid, vm->def->id, vm->def->name, hostname, port); - if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) { virReportOOMError(NULL); return -1; } - ret = qemuMonitorMigrate(vm, background, uri); + ret = qemuMonitorTextMigrate(mon, background, uri); VIR_FREE(uri); @@ -1074,19 +1023,16 @@ int qemuMonitorMigrateToHost(const virDomainObjPtr vm, } -int qemuMonitorMigrateToCommand(const virDomainObjPtr vm, - int background, - const char * const *argv, - const char *target) +int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon, + int background, + const char * const *argv, + const char *target) { char *argstr; char *dest = NULL; int ret = -1; char *safe_target = NULL; - DEBUG("vm=%p, pid=%d, id=%d, name=%s argv=%p target=%s", - vm, vm->pid, vm->def->id, vm->def->name, argv, target); - argstr = virArgvToString(argv); if (!argstr) { virReportOOMError(NULL); @@ -1105,7 +1051,7 @@ int qemuMonitorMigrateToCommand(const virDomainObjPtr vm, goto cleanup; } - ret = qemuMonitorMigrate(vm, background, dest); + ret = qemuMonitorTextMigrate(mon, background, dest); cleanup: VIR_FREE(safe_target); @@ -1114,7 +1060,7 @@ cleanup: return ret; } -int qemuMonitorMigrateToUnix(const virDomainObjPtr vm, +int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon, int background, const char *unixfile) { @@ -1126,18 +1072,18 @@ int qemuMonitorMigrateToUnix(const virDomainObjPtr vm, return -1; } - ret = qemuMonitorMigrate(vm, background, dest); + ret = qemuMonitorTextMigrate(mon, background, dest); VIR_FREE(dest); return ret; } -int qemuMonitorMigrateCancel(const virDomainObjPtr vm) +int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon) { char *info = NULL; - if (qemuMonitorCommand(vm, "migrate cancel", &info) < 0) { + if (qemuMonitorCommand(mon, "migrate cancel", &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot run monitor command to cancel migration")); return -1; @@ -1147,17 +1093,14 @@ int qemuMonitorMigrateCancel(const virDomainObjPtr vm) return 0; } -int qemuMonitorAddUSBDisk(const virDomainObjPtr vm, - const char *path) +int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon, + const char *path) { char *cmd = NULL; char *safepath; int ret = -1; char *info = NULL; - DEBUG("vm=%p, pid=%d, id=%d, name=%s path=%s", - vm, vm->pid, vm->def->id, vm->def->name, path); - safepath = qemuMonitorEscapeArg(path); if (!safepath) { virReportOOMError(NULL); @@ -1169,7 +1112,7 @@ int qemuMonitorAddUSBDisk(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &info) < 0) { + if (qemuMonitorCommand(mon, cmd, &info) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot run monitor command to add usb disk")); goto cleanup; @@ -1192,8 +1135,8 @@ cleanup: } -static int qemuMonitorAddUSBDevice(const virDomainObjPtr vm, - const char *addr) +static int qemuMonitorTextAddUSBDevice(qemuMonitorPtr mon, + const char *addr) { char *cmd; char *reply = NULL; @@ -1204,7 +1147,7 @@ static int qemuMonitorAddUSBDevice(const virDomainObjPtr vm, return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("cannot attach usb device")); goto cleanup; @@ -1227,43 +1170,37 @@ cleanup: } -int qemuMonitorAddUSBDeviceExact(const virDomainObjPtr vm, - int bus, - int dev) +int qemuMonitorTextAddUSBDeviceExact(qemuMonitorPtr mon, + int bus, + int dev) { int ret; char *addr; - DEBUG("vm=%p, pid=%d, id=%d, name=%s bus=%d dev=%d", - vm, vm->pid, vm->def->id, vm->def->name, bus, dev); - if (virAsprintf(&addr, "host:%.3d.%.3d", bus, dev) < 0) { virReportOOMError(NULL); return -1; } - ret = qemuMonitorAddUSBDevice(vm, addr); + ret = qemuMonitorTextAddUSBDevice(mon, addr); VIR_FREE(addr); return ret; } -int qemuMonitorAddUSBDeviceMatch(const virDomainObjPtr vm, - int vendor, - int product) +int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon, + int vendor, + int product) { int ret; char *addr; - DEBUG("vm=%p, pid=%d, id=%d, name=%s vendor=%d product=%d", - vm, vm->pid, vm->def->id, vm->def->name, vendor, product); - if (virAsprintf(&addr, "host:%.4x:%.4x", vendor, product) < 0) { virReportOOMError(NULL); return -1; } - ret = qemuMonitorAddUSBDevice(vm, addr); + ret = qemuMonitorTextAddUSBDevice(mon, addr); VIR_FREE(addr); return ret; @@ -1271,16 +1208,14 @@ int qemuMonitorAddUSBDeviceMatch(const virDomainObjPtr vm, static int -qemuMonitorParsePciAddReply(virDomainObjPtr vm, - const char *reply, - unsigned *domain, - unsigned *bus, - unsigned *slot) +qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, + const char *reply, + unsigned *domain, + unsigned *bus, + unsigned *slot) { char *s, *e; - DEBUG("%s: pci_add reply: %s", vm->def->name, reply); - /* If the command succeeds qemu prints: * OK bus 0, slot XXX... * or @@ -1338,23 +1273,19 @@ qemuMonitorParsePciAddReply(virDomainObjPtr vm, } -int qemuMonitorAddPCIHostDevice(const virDomainObjPtr vm, - unsigned hostDomain ATTRIBUTE_UNUSED, - unsigned hostBus, - unsigned hostSlot, - unsigned hostFunction, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot) +int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon, + unsigned hostDomain ATTRIBUTE_UNUSED, + unsigned hostBus, + unsigned hostSlot, + unsigned hostFunction, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s domain=%d bus=%d slot=%d function=%d", - vm, vm->pid, vm->def->id, vm->def->name, - hostDomain, hostBus, hostSlot, hostFunction); - *guestDomain = *guestBus = *guestSlot = 0; /* XXX hostDomain */ @@ -1364,7 +1295,7 @@ int qemuMonitorAddPCIHostDevice(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("cannot attach host pci device")); goto cleanup; @@ -1376,10 +1307,10 @@ int qemuMonitorAddPCIHostDevice(const virDomainObjPtr vm, goto cleanup; } - if (qemuMonitorParsePciAddReply(vm, reply, - guestDomain, - guestBus, - guestSlot) < 0) { + if (qemuMonitorTextParsePciAddReply(mon, reply, + guestDomain, + guestBus, + guestSlot) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("parsing pci_add reply failed: %s"), reply); goto cleanup; @@ -1394,21 +1325,18 @@ cleanup: } -int qemuMonitorAddPCIDisk(const virDomainObjPtr vm, - const char *path, - const char *bus, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot) { +int qemuMonitorTextAddPCIDisk(qemuMonitorPtr mon, + const char *path, + const char *bus, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) { char *cmd = NULL; char *reply = NULL; char *safe_path = NULL; int tryOldSyntax = 0; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s path=%s bus=%s", - vm, vm->pid, vm->def->id, vm->def->name, path, bus); - safe_path = qemuMonitorEscapeArg(path); if (!safe_path) { virReportOOMError(NULL); @@ -1422,14 +1350,14 @@ try_command: goto cleanup; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("cannot attach %s disk %s"), bus, path); goto cleanup; } - if (qemuMonitorParsePciAddReply(vm, reply, - guestDomain, guestBus, guestSlot) < 0) { + if (qemuMonitorTextParsePciAddReply(mon, reply, + guestDomain, guestBus, guestSlot) < 0) { if (!tryOldSyntax && strstr(reply, "invalid char in expression")) { VIR_FREE(reply); VIR_FREE(cmd); @@ -1452,32 +1380,29 @@ cleanup: } -int qemuMonitorAddPCINetwork(const virDomainObjPtr vm, - const char *nicstr, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot) +int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon, + const char *nicstr, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s nicstr=%s", - vm, vm->pid, vm->def->id, vm->def->name, nicstr); - if (virAsprintf(&cmd, "pci_add pci_addr=auto nic %s", nicstr) < 0) { virReportOOMError(NULL); return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("failed to add NIC with '%s'"), cmd); goto cleanup; } - if (qemuMonitorParsePciAddReply(vm, reply, - guestDomain, guestBus, guestSlot) < 0) { + if (qemuMonitorTextParsePciAddReply(mon, reply, + guestDomain, guestBus, guestSlot) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("parsing pci_add reply failed: %s"), reply); goto cleanup; @@ -1492,19 +1417,16 @@ cleanup: } -int qemuMonitorRemovePCIDevice(const virDomainObjPtr vm, - unsigned guestDomain, - unsigned guestBus, - unsigned guestSlot) +int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon, + unsigned guestDomain, + unsigned guestBus, + unsigned guestSlot) { char *cmd = NULL; char *reply = NULL; int tryOldSyntax = 0; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s domain=%d bus=%d slot=%d", - vm, vm->pid, vm->def->id, vm->def->name, guestDomain, guestBus, guestSlot); - try_command: if (tryOldSyntax) { if (virAsprintf(&cmd, "pci_del 0 %.2x", guestSlot) < 0) { @@ -1519,7 +1441,7 @@ try_command: } } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("failed to remove PCI device")); goto cleanup; @@ -1554,23 +1476,20 @@ cleanup: } -int qemuMonitorSendFileHandle(const virDomainObjPtr vm, - const char *fdname, - int fd) +int qemuMonitorTextSendFileHandle(qemuMonitorPtr mon, + const char *fdname, + int fd) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s fdname=%s fd=%d", - vm, vm->pid, vm->def->id, vm->def->name, fdname, fd); - if (virAsprintf(&cmd, "getfd %s", fdname) < 0) { virReportOOMError(NULL); return -1; } - if (qemuMonitorCommandWithFd(vm, cmd, fd, &reply) < 0) { + if (qemuMonitorCommandWithFd(mon, cmd, fd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("failed to pass fd to qemu with '%s'"), cmd); goto cleanup; @@ -1594,22 +1513,19 @@ cleanup: } -int qemuMonitorCloseFileHandle(const virDomainObjPtr vm, - const char *fdname) +int qemuMonitorTextCloseFileHandle(qemuMonitorPtr mon, + const char *fdname) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s fdname=%s", - vm, vm->pid, vm->def->id, vm->def->name, fdname); - if (virAsprintf(&cmd, "closefd %s", fdname) < 0) { virReportOOMError(NULL); return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("failed to close fd in qemu with '%s'"), cmd); goto cleanup; @@ -1633,22 +1549,19 @@ cleanup: } -int qemuMonitorAddHostNetwork(const virDomainObjPtr vm, - const char *netstr) +int qemuMonitorTextAddHostNetwork(qemuMonitorPtr mon, + const char *netstr) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s netstr=%s", - vm, vm->pid, vm->def->id, vm->def->name, netstr); - if (virAsprintf(&cmd, "host_net_add %s", netstr) < 0) { virReportOOMError(NULL); return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("failed to close fd in qemu with '%s'"), cmd); goto cleanup; @@ -1665,23 +1578,20 @@ cleanup: } -int qemuMonitorRemoveHostNetwork(const virDomainObjPtr vm, - int vlan, - const char *netname) +int qemuMonitorTextRemoveHostNetwork(qemuMonitorPtr mon, + int vlan, + const char *netname) { char *cmd; char *reply = NULL; int ret = -1; - DEBUG("vm=%p, pid=%d, id=%d, name=%s netname=%s", - vm, vm->pid, vm->def->id, vm->def->name, netname); - if (virAsprintf(&cmd, "host_net_remove %d %s", vlan, netname) < 0) { virReportOOMError(NULL); return -1; } - if (qemuMonitorCommand(vm, cmd, &reply) < 0) { + if (qemuMonitorCommand(mon, cmd, &reply) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("failed to remove host metnwork in qemu with '%s'"), cmd); goto cleanup; diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h index 9175456..35eaf05 100644 --- a/src/qemu/qemu_monitor_text.h +++ b/src/qemu/qemu_monitor_text.h @@ -27,155 +27,124 @@ #include "internal.h" -#include "domain_conf.h" - - -/* Formal APIs for each required monitor command */ - -int qemuMonitorStartCPUs(virConnectPtr conn, - const virDomainObjPtr vm); -int qemuMonitorStopCPUs(const virDomainObjPtr vm); - -int qemuMonitorSystemPowerdown(const virDomainObjPtr vm); - -int qemuMonitorGetCPUInfo(const virDomainObjPtr vm, - int **pids); -int qemuMonitorGetBalloonInfo(const virDomainObjPtr vm, - unsigned long *currmem); -int qemuMonitorGetBlockStatsInfo(const virDomainObjPtr vm, - const char *devname, - long long *rd_req, - long long *rd_bytes, - long long *wr_req, - long long *wr_bytes, - long long *errs); - - -int qemuMonitorSetVNCPassword(const virDomainObjPtr vm, - const char *password); -int qemuMonitorSetBalloon(const virDomainObjPtr vm, - unsigned long newmem); - -/* XXX should we pass the virDomainDiskDefPtr instead - * and hide devname details inside monitor. Reconsider - * this when doing the QMP implementation - */ -int qemuMonitorEjectMedia(const virDomainObjPtr vm, - const char *devname); -int qemuMonitorChangeMedia(const virDomainObjPtr vm, - const char *devname, - const char *newmedia); - - -int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm, - unsigned long long offset, - size_t length, - const char *path); -int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm, - unsigned long long offset, - size_t length, - const char *path); - -int qemuMonitorSetMigrationSpeed(const virDomainObjPtr vm, - unsigned long bandwidth); - -enum { - QEMU_MONITOR_MIGRATION_STATUS_INACTIVE, - QEMU_MONITOR_MIGRATION_STATUS_ACTIVE, - QEMU_MONITOR_MIGRATION_STATUS_COMPLETED, - QEMU_MONITOR_MIGRATION_STATUS_ERROR, - QEMU_MONITOR_MIGRATION_STATUS_CANCELLED, - - QEMU_MONITOR_MIGRATION_STATUS_LAST -}; - -int qemuMonitorGetMigrationStatus(const virDomainObjPtr vm, - int *status, - unsigned long long *transferred, - unsigned long long *remaining, - unsigned long long *total); - -int qemuMonitorMigrateToHost(const virDomainObjPtr vm, - int background, - const char *hostname, - int port); - -int qemuMonitorMigrateToCommand(const virDomainObjPtr vm, - int background, - const char * const *argv, - const char *target); - -int qemuMonitorMigrateToUnix(const virDomainObjPtr vm, - int background, - const char *unixfile); - -int qemuMonitorMigrateCancel(const virDomainObjPtr vm); - - -/* XXX disk driver type eg, qcow/etc. - * XXX cache mode - */ -int qemuMonitorAddUSBDisk(const virDomainObjPtr vm, - const char *path); - -int qemuMonitorAddUSBDeviceExact(const virDomainObjPtr vm, - int bus, - int dev); -int qemuMonitorAddUSBDeviceMatch(const virDomainObjPtr vm, - int vendor, - int product); - - -int qemuMonitorAddPCIHostDevice(const virDomainObjPtr vm, - unsigned hostDomain, - unsigned hostBus, - unsigned hostSlot, - unsigned hostFunction, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot); - -/* XXX disk driver type eg, qcow/etc. - * XXX cache mode - */ -int qemuMonitorAddPCIDisk(const virDomainObjPtr vm, - const char *path, - const char *bus, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot); - -/* XXX do we really want to hardcode 'nicstr' as the - * sendable item here - */ -int qemuMonitorAddPCINetwork(const virDomainObjPtr vm, - const char *nicstr, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot); - -int qemuMonitorRemovePCIDevice(const virDomainObjPtr vm, - unsigned guestDomain, - unsigned guestBus, - unsigned guestSlot); - - -int qemuMonitorSendFileHandle(const virDomainObjPtr vm, - const char *fdname, - int fd); - -int qemuMonitorCloseFileHandle(const virDomainObjPtr vm, - const char *fdname); - - -/* XXX do we relaly want to hardcode 'netstr' as the - * sendable item here - */ -int qemuMonitorAddHostNetwork(const virDomainObjPtr vm, - const char *netstr); - -int qemuMonitorRemoveHostNetwork(const virDomainObjPtr vm, - int vlan, - const char *netname); +#include "qemu_monitor.h" + +int qemuMonitorTextStartCPUs(qemuMonitorPtr mon, + virConnectPtr conn); +int qemuMonitorTextStopCPUs(qemuMonitorPtr mon); + +int qemuMonitorTextSystemPowerdown(qemuMonitorPtr mon); + +int qemuMonitorTextGetCPUInfo(qemuMonitorPtr mon, + int **pids); +int qemuMonitorTextGetBalloonInfo(qemuMonitorPtr mon, + unsigned long *currmem); +int qemuMonitorTextGetBlockStatsInfo(qemuMonitorPtr mon, + const char *devname, + long long *rd_req, + long long *rd_bytes, + long long *wr_req, + long long *wr_bytes, + long long *errs); + + +int qemuMonitorTextSetVNCPassword(qemuMonitorPtr mon, + const char *password); +int qemuMonitorTextSetBalloon(qemuMonitorPtr mon, + unsigned long newmem); + +int qemuMonitorTextEjectMedia(qemuMonitorPtr mon, + const char *devname); +int qemuMonitorTextChangeMedia(qemuMonitorPtr mon, + const char *devname, + const char *newmedia); + + +int qemuMonitorTextSaveVirtualMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path); +int qemuMonitorTextSavePhysicalMemory(qemuMonitorPtr mon, + unsigned long long offset, + size_t length, + const char *path); + +int qemuMonitorTextSetMigrationSpeed(qemuMonitorPtr mon, + unsigned long bandwidth); + +int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon, + int *status, + unsigned long long *transferred, + unsigned long long *remaining, + unsigned long long *total); + +int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon, + int background, + const char *hostname, + int port); + +int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon, + int background, + const char * const *argv, + const char *target); + +int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon, + int background, + const char *unixfile); + +int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon); + +int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon, + const char *path); + +int qemuMonitorTextAddUSBDeviceExact(qemuMonitorPtr mon, + int bus, + int dev); +int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon, + int vendor, + int product); + + +int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon, + unsigned hostDomain, + unsigned hostBus, + unsigned hostSlot, + unsigned hostFunction, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +int qemuMonitorTextAddPCIDisk(qemuMonitorPtr mon, + const char *path, + const char *bus, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon, + const char *nicstr, + unsigned *guestDomain, + unsigned *guestBus, + unsigned *guestSlot); + +int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon, + unsigned guestDomain, + unsigned guestBus, + unsigned guestSlot); + + +int qemuMonitorTextSendFileHandle(qemuMonitorPtr mon, + const char *fdname, + int fd); + +int qemuMonitorTextCloseFileHandle(qemuMonitorPtr mon, + const char *fdname); + +int qemuMonitorTextAddHostNetwork(qemuMonitorPtr mon, + const char *netstr); + +int qemuMonitorTextRemoveHostNetwork(qemuMonitorPtr mon, + int vlan, + const char *netname); #endif /* QEMU_MONITOR_TEXT_H */ -- 1.6.2.5 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list