diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8c5bfb23c6..51a64d33d3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7528,249 +7528,6 @@ void qemuProcessStop(virQEMUDriverPtr driver, } -int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, - virQEMUDriverPtr driver, - virDomainObjPtr vm, - pid_t pid, - const char *pidfile, - virDomainChrSourceDefPtr monConfig, - bool monJSON) -{ - size_t i; - qemuDomainLogContextPtr logCtxt = NULL; - char *timestamp; - qemuDomainObjPrivatePtr priv = vm->privateData; - bool running = true; - virDomainPausedReason reason; - virSecurityLabelPtr seclabel = NULL; - virSecurityLabelDefPtr seclabeldef = NULL; - bool seclabelgen = false; - virSecurityManagerPtr* sec_managers = NULL; - const char *model; - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - bool active = false; - virDomainVirtType virtType; - - VIR_DEBUG("Beginning VM attach process"); - - if (virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("VM is already active")); - virObjectUnref(cfg); - return -1; - } - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto error; - - /* Do this upfront, so any part of the startup process can add - * runtime state to vm->def that won't be persisted. This let's us - * report implicit runtime defaults in the XML, like vnc listen/socket - */ - VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(caps, driver->xmlopt, vm) < 0) - goto error; - - vm->def->id = qemuDriverAllocateID(driver); - - if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback) - driver->inhibitCallback(true, driver->inhibitOpaque); - active = true; - - if (virFileMakePath(cfg->logDir) < 0) { - virReportSystemError(errno, - _("cannot create log directory %s"), - cfg->logDir); - goto error; - } - - VIR_FREE(priv->pidfile); - if (VIR_STRDUP(priv->pidfile, pidfile) < 0) - goto error; - - vm->pid = pid; - - VIR_DEBUG("Detect security driver config"); - sec_managers = qemuSecurityGetNested(driver->securityManager); - if (sec_managers == NULL) - goto error; - - for (i = 0; sec_managers[i]; i++) { - seclabelgen = false; - model = qemuSecurityGetModel(sec_managers[i]); - seclabeldef = virDomainDefGetSecurityLabelDef(vm->def, model); - if (seclabeldef == NULL) { - if (!(seclabeldef = virSecurityLabelDefNew(model))) - goto error; - seclabelgen = true; - } - seclabeldef->type = VIR_DOMAIN_SECLABEL_STATIC; - if (VIR_ALLOC(seclabel) < 0) - goto error; - if (qemuSecurityGetProcessLabel(sec_managers[i], vm->def, - vm->pid, seclabel) < 0) - goto error; - - if (VIR_STRDUP(seclabeldef->model, model) < 0) - goto error; - - if (VIR_STRDUP(seclabeldef->label, seclabel->label) < 0) - goto error; - VIR_FREE(seclabel); - - if (seclabelgen) { - if (VIR_APPEND_ELEMENT(vm->def->seclabels, vm->def->nseclabels, seclabeldef) < 0) - goto error; - seclabelgen = false; - } - } - - if (qemuSecurityCheckAllLabel(driver->securityManager, vm->def) < 0) - goto error; - if (qemuSecurityGenLabel(driver->securityManager, vm->def) < 0) - goto error; - - if (qemuDomainPerfRestart(vm) < 0) - goto error; - - VIR_DEBUG("Creating domain log file"); - if (!(logCtxt = qemuDomainLogContextNew(driver, vm, - QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH))) - goto error; - - VIR_DEBUG("Determining emulator version"); - if (qemuDomainUpdateQEMUCaps(vm, driver->qemuCapsCache) < 0) - goto error; - - VIR_DEBUG("Preparing monitor state"); - priv->monConfig = virObjectRef(monConfig); - priv->monJSON = monJSON; - - /* Attaching to running QEMU so we need to detect whether it was started - * with -no-reboot. */ - qemuProcessPrepareAllowReboot(vm); - - /* - * Normally PCI addresses are assigned in the virDomainCreate - * or virDomainDefine methods. We might still need to assign - * some here to cope with the question of upgrades. Regardless - * we also need to populate the PCI address set cache for later - * use in hotplug - */ - VIR_DEBUG("Assigning domain PCI addresses"); - if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, - driver, vm, false)) < 0) { - goto error; - } - - if ((timestamp = virTimeStringNow()) == NULL) - goto error; - - qemuDomainLogContextWrite(logCtxt, "%s: attaching\n", timestamp); - VIR_FREE(timestamp); - - qemuDomainObjTaint(driver, vm, VIR_DOMAIN_TAINT_EXTERNAL_LAUNCH, logCtxt); - - VIR_DEBUG("Waiting for monitor to show up"); - if (qemuProcessWaitForMonitor(driver, vm, QEMU_ASYNC_JOB_NONE, NULL) < 0) - goto error; - - if (qemuConnectAgent(driver, vm) < 0) - goto error; - - VIR_DEBUG("Detecting VCPU PIDs"); - if (qemuDomainRefreshVcpuInfo(driver, vm, QEMU_ASYNC_JOB_NONE, false) < 0) - goto error; - - if (qemuDomainValidateVcpuInfo(vm) < 0) - goto error; - - VIR_DEBUG("Detecting IOThread PIDs"); - if (qemuProcessDetectIOThreadPIDs(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) - goto error; - - VIR_DEBUG("Getting initial memory amount"); - qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorGetBalloonInfo(priv->mon, &vm->def->mem.cur_balloon) < 0) - goto exit_monitor; - if (qemuMonitorGetStatus(priv->mon, &running, &reason) < 0) - goto exit_monitor; - if (qemuMonitorGetVirtType(priv->mon, &virtType) < 0) - goto exit_monitor; - vm->def->virtType = virtType; - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto error; - - if (running) { - virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, - VIR_DOMAIN_RUNNING_UNPAUSED); - if (virDomainDefHasMemballoon(vm->def) && - vm->def->memballoon->period) { - qemuDomainObjEnterMonitor(driver, vm); - qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon, - vm->def->memballoon->period); - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto error; - } - } else { - virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason); - } - - VIR_DEBUG("Writing domain status to disk"); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) - goto error; - - /* Run an hook to allow admins to do some magic */ - if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { - char *xml = qemuDomainDefFormatXML(driver, vm->def, 0); - int hookret; - - hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, - VIR_HOOK_QEMU_OP_ATTACH, VIR_HOOK_SUBOP_BEGIN, - NULL, xml, NULL); - VIR_FREE(xml); - - /* - * If the script raised an error abort the launch - */ - if (hookret < 0) - goto error; - } - - virObjectUnref(logCtxt); - VIR_FREE(seclabel); - VIR_FREE(sec_managers); - virObjectUnref(cfg); - virObjectUnref(caps); - - return 0; - - exit_monitor: - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - error: - /* We jump here if we failed to attach to the VM for any reason. - * Leave the domain running, but pretend we never attempted to - * attach to it. */ - if (active && virAtomicIntDecAndTest(&driver->nactive) && - driver->inhibitCallback) - driver->inhibitCallback(false, driver->inhibitOpaque); - - qemuMonitorClose(priv->mon); - priv->mon = NULL; - virObjectUnref(logCtxt); - VIR_FREE(seclabel); - VIR_FREE(sec_managers); - if (seclabelgen) - virSecurityLabelDefFree(seclabeldef); - virObjectUnref(priv->monConfig); - priv->monConfig = NULL; - virObjectUnref(cfg); - virObjectUnref(caps); - return -1; -} - - static void qemuProcessAutoDestroy(virDomainObjPtr dom, virConnectPtr conn, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 4840d897f8..1d62319092 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -153,14 +153,6 @@ void qemuProcessStop(virQEMUDriverPtr driver, qemuDomainAsyncJob asyncJob, unsigned int flags); -int qemuProcessAttach(virConnectPtr conn, - virQEMUDriverPtr driver, - virDomainObjPtr vm, - pid_t pid, - const char *pidfile, - virDomainChrSourceDefPtr monConfig, - bool monJSON); - typedef enum { VIR_QEMU_PROCESS_KILL_FORCE = 1 << 0, VIR_QEMU_PROCESS_KILL_NOWAIT = 1 << 1,