提交 0c53382d 编写于 作者: P Pavel Hrdina

conf: don't iterate over backcompat console in virDomainChrDefForeach

If the first console is just a copy of the first serial device we
don't need to iterate over the same device twice in order to perform
actions like security labeling, cgroup configuring, etc.

Currently only security SELinux manager was aware of this fact.
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 f8912d05
...@@ -3523,6 +3523,24 @@ void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) ...@@ -3523,6 +3523,24 @@ void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
} }
static bool
virDomainSkipBackcompatConsole(virDomainDefPtr def,
size_t index,
bool all)
{
virDomainChrDefPtr console = def->consoles[index];
if (!all && index == 0 &&
(console->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
console->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
return true;
}
return false;
}
static int static int
virDomainDeviceInfoIterateInternal(virDomainDefPtr def, virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
virDomainDeviceInfoCallback cb, virDomainDeviceInfoCallback cb,
...@@ -3591,11 +3609,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, ...@@ -3591,11 +3609,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
return -1; return -1;
} }
for (i = 0; i < def->nconsoles; i++) { for (i = 0; i < def->nconsoles; i++) {
if (!all && if (virDomainSkipBackcompatConsole(def, i, all))
i == 0 &&
(def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
def->os.type == VIR_DOMAIN_OSTYPE_HVM)
continue; continue;
device.data.chr = def->consoles[i]; device.data.chr = def->consoles[i];
if (cb(def, &device, &def->consoles[i]->info, opaque) < 0) if (cb(def, &device, &def->consoles[i]->info, opaque) < 0)
...@@ -25431,6 +25445,8 @@ virDomainChrDefForeach(virDomainDefPtr def, ...@@ -25431,6 +25445,8 @@ virDomainChrDefForeach(virDomainDefPtr def,
goto done; goto done;
} }
for (i = 0; i < def->nconsoles; i++) { for (i = 0; i < def->nconsoles; i++) {
if (virDomainSkipBackcompatConsole(def, i, false))
continue;
if ((iter)(def, if ((iter)(def,
def->consoles[i], def->consoles[i],
opaque) < 0) opaque) < 0)
......
...@@ -2323,11 +2323,6 @@ virSecuritySELinuxRestoreSecurityChardevCallback(virDomainDefPtr def, ...@@ -2323,11 +2323,6 @@ virSecuritySELinuxRestoreSecurityChardevCallback(virDomainDefPtr def,
{ {
virSecurityManagerPtr mgr = opaque; virSecurityManagerPtr mgr = opaque;
/* This is taken care of by processing of def->serials */
if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
dev->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL)
return 0;
return virSecuritySELinuxRestoreChardevLabel(mgr, def, dev, dev->source); return virSecuritySELinuxRestoreChardevLabel(mgr, def, dev, dev->source);
} }
...@@ -2717,11 +2712,6 @@ virSecuritySELinuxSetSecurityChardevCallback(virDomainDefPtr def, ...@@ -2717,11 +2712,6 @@ virSecuritySELinuxSetSecurityChardevCallback(virDomainDefPtr def,
{ {
virSecurityManagerPtr mgr = opaque; virSecurityManagerPtr mgr = opaque;
/* This is taken care of by processing of def->serials */
if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
dev->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL)
return 0;
return virSecuritySELinuxSetChardevLabel(mgr, def, dev, dev->source); return virSecuritySELinuxSetChardevLabel(mgr, def, dev, dev->source);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册