提交 2b15f2a1 编写于 作者: P Peter Krempa

qemu: cgroup: Split up qemuSetImageCgroupInternal

Separate the Teardown and Setup code paths into separate helpers.
上级 5dd610d0
...@@ -53,10 +53,9 @@ static const char *const defaultDeviceACL[] = { ...@@ -53,10 +53,9 @@ static const char *const defaultDeviceACL[] = {
#define DEVICE_SND_MAJOR 116 #define DEVICE_SND_MAJOR 116
static int static int
qemuSetImageCgroupInternal(virDomainObjPtr vm, qemuSetupImageCgroupInternal(virDomainObjPtr vm,
virStorageSourcePtr src, virStorageSourcePtr src,
bool deny, bool forceReadonly)
bool forceReadonly)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int perms = VIR_CGROUP_DEVICE_READ; int perms = VIR_CGROUP_DEVICE_READ;
...@@ -72,25 +71,15 @@ qemuSetImageCgroupInternal(virDomainObjPtr vm, ...@@ -72,25 +71,15 @@ qemuSetImageCgroupInternal(virDomainObjPtr vm,
return 0; return 0;
} }
if (deny) { if (!src->readonly && !forceReadonly)
perms |= VIR_CGROUP_DEVICE_WRITE | VIR_CGROUP_DEVICE_MKNOD; perms |= VIR_CGROUP_DEVICE_WRITE;
VIR_DEBUG("Deny path %s", src->path); VIR_DEBUG("Allow path %s, perms: %s",
src->path, virCgroupGetDevicePermsString(perms));
ret = virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true); ret = virCgroupAllowDevicePath(priv->cgroup, src->path, perms, true);
} else {
if (!src->readonly && !forceReadonly)
perms |= VIR_CGROUP_DEVICE_WRITE;
VIR_DEBUG("Allow path %s, perms: %s", virDomainAuditCgroupPath(vm, priv->cgroup, "allow", src->path,
src->path, virCgroupGetDevicePermsString(perms));
ret = virCgroupAllowDevicePath(priv->cgroup, src->path, perms, true);
}
virDomainAuditCgroupPath(vm, priv->cgroup,
deny ? "deny" : "allow",
src->path,
virCgroupGetDevicePermsString(perms), virCgroupGetDevicePermsString(perms),
ret == 0); ret == 0);
...@@ -102,7 +91,7 @@ int ...@@ -102,7 +91,7 @@ int
qemuSetupImageCgroup(virDomainObjPtr vm, qemuSetupImageCgroup(virDomainObjPtr vm,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
return qemuSetImageCgroupInternal(vm, src, false, false); return qemuSetupImageCgroupInternal(vm, src, false);
} }
...@@ -110,7 +99,30 @@ int ...@@ -110,7 +99,30 @@ int
qemuTeardownImageCgroup(virDomainObjPtr vm, qemuTeardownImageCgroup(virDomainObjPtr vm,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
return qemuSetImageCgroupInternal(vm, src, true, false); qemuDomainObjPrivatePtr priv = vm->privateData;
int perms = VIR_CGROUP_DEVICE_READ |
VIR_CGROUP_DEVICE_WRITE |
VIR_CGROUP_DEVICE_MKNOD;
int ret;
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_DEVICES))
return 0;
if (!src->path || !virStorageSourceIsLocalStorage(src)) {
VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s",
NULLSTR(src->path), virStorageTypeToString(src->type));
return 0;
}
VIR_DEBUG("Deny path %s", src->path);
ret = virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true);
virDomainAuditCgroupPath(vm, priv->cgroup, "deny", src->path,
virCgroupGetDevicePermsString(perms), ret == 0);
return ret;
} }
...@@ -122,7 +134,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm, ...@@ -122,7 +134,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
bool forceReadonly = false; bool forceReadonly = false;
for (next = disk->src; next; next = next->backingStore) { for (next = disk->src; next; next = next->backingStore) {
if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly) < 0) if (qemuSetupImageCgroupInternal(vm, next, forceReadonly) < 0)
return -1; return -1;
/* setup only the top level image for read-write */ /* setup only the top level image for read-write */
...@@ -140,7 +152,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm, ...@@ -140,7 +152,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
virStorageSourcePtr next; virStorageSourcePtr next;
for (next = disk->src; next; next = next->backingStore) { for (next = disk->src; next; next = next->backingStore) {
if (qemuSetImageCgroupInternal(vm, next, true, false) < 0) if (qemuTeardownImageCgroup(vm, next) < 0)
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册