mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
lxc: Make lxcProcessStop callable even without PID being available
This way the function can work as a central point of clean-up code and we don't have to duplicate code. And it works similarly to the qemu driver. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
2e6ecba1bc
commit
aa0dfb91d5
@ -845,12 +845,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
|
|
||||||
if (vm->pid <= 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Invalid PID %d for container"), vm->pid);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virSecurityManagerRestoreAllLabel(driver->securityManager,
|
virSecurityManagerRestoreAllLabel(driver->securityManager,
|
||||||
vm->def, false, false);
|
vm->def, false, false);
|
||||||
virSecurityManagerReleaseLabel(driver->securityManager, vm->def);
|
virSecurityManagerReleaseLabel(driver->securityManager, vm->def);
|
||||||
@ -895,7 +889,7 @@ int virLXCProcessStop(virLXCDriverPtr driver,
|
|||||||
_("Some processes refused to die"));
|
_("Some processes refused to die"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (vm->pid > 0) {
|
||||||
/* If cgroup doesn't exist, just try cleaning up the
|
/* If cgroup doesn't exist, just try cleaning up the
|
||||||
* libvirt_lxc process */
|
* libvirt_lxc process */
|
||||||
if (virProcessKillPainfully(vm->pid, true) < 0) {
|
if (virProcessKillPainfully(vm->pid, true) < 0) {
|
||||||
@ -1210,8 +1204,6 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
virCgroupPtr selfcgroup;
|
virCgroupPtr selfcgroup;
|
||||||
int status;
|
int status;
|
||||||
char *pidfile = NULL;
|
char *pidfile = NULL;
|
||||||
bool clearSeclabel = false;
|
|
||||||
bool need_stop = false;
|
|
||||||
|
|
||||||
if (virCgroupNewSelf(&selfcgroup) < 0)
|
if (virCgroupNewSelf(&selfcgroup) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1331,9 +1323,6 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
then generate a security label for isolation */
|
then generate a security label for isolation */
|
||||||
VIR_DEBUG("Generating domain security label (if required)");
|
VIR_DEBUG("Generating domain security label (if required)");
|
||||||
|
|
||||||
clearSeclabel = vm->def->nseclabels == 0 ||
|
|
||||||
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DEFAULT;
|
|
||||||
|
|
||||||
if (vm->def->nseclabels &&
|
if (vm->def->nseclabels &&
|
||||||
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DEFAULT)
|
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DEFAULT)
|
||||||
vm->def->seclabels[0]->type = VIR_DOMAIN_SECLABEL_NONE;
|
vm->def->seclabels[0]->type = VIR_DOMAIN_SECLABEL_NONE;
|
||||||
@ -1468,7 +1457,6 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_stop = true;
|
|
||||||
priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_FAILED;
|
priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_FAILED;
|
||||||
priv->wantReboot = false;
|
priv->wantReboot = false;
|
||||||
vm->def->id = vm->pid;
|
vm->def->id = vm->pid;
|
||||||
@ -1574,23 +1562,7 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
err = virSaveLastError();
|
err = virSaveLastError();
|
||||||
if (need_stop) {
|
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
|
||||||
virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
|
|
||||||
} else {
|
|
||||||
virSecurityManagerRestoreAllLabel(driver->securityManager,
|
|
||||||
vm->def, false, false);
|
|
||||||
virSecurityManagerReleaseLabel(driver->securityManager, vm->def);
|
|
||||||
/* Clear out dynamically assigned labels */
|
|
||||||
if (vm->def->nseclabels &&
|
|
||||||
(vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC ||
|
|
||||||
clearSeclabel)) {
|
|
||||||
VIR_FREE(vm->def->seclabels[0]->model);
|
|
||||||
VIR_FREE(vm->def->seclabels[0]->label);
|
|
||||||
VIR_FREE(vm->def->seclabels[0]->imagelabel);
|
|
||||||
VIR_DELETE_ELEMENT(vm->def->seclabels, 0, vm->def->nseclabels);
|
|
||||||
}
|
|
||||||
virLXCProcessCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
for (i = 0; i < nveths; i++)
|
for (i = 0; i < nveths; i++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user