return driver->hasFeature(data, feature);
}
+
+bool
+cpuModelIsAllowed(const char *model,
+ const char **models,
+ unsigned int nmodels)
+{
+ unsigned int i;
+
+ if (!models || !nmodels)
+ return true;
+
+ for (i = 0; i < nmodels; i++) {
+ if (models[i] && STREQ(models[i], model))
+ return true;
+ }
+ return false;
+}
const char *feature);
+bool
+cpuModelIsAllowed(const char *model,
+ const char **models,
+ unsigned int nmodels);
+
#endif /* __VIR_CPU_H__ */
unsigned int count;
unsigned int i, j;
- if (models) {
- bool found = false;
- for (i = 0; i < nmodels; i++) {
- if (STREQ(cpus[0]->model, models[i])) {
- found = true;
- break;
- }
- }
- if (!found) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("CPU model '%s' is not support by hypervisor"),
- cpus[0]->model);
- goto error;
- }
+ if (!cpuModelIsAllowed(cpus[0]->model, models, nmodels)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("CPU model %s is not supported by hypervisor"),
+ cpus[0]->model);
+ goto error;
}
if (VIR_ALLOC(cpu) < 0 ||
candidate = map->models;
while (candidate != NULL) {
- bool allowed = (models == NULL);
-
- for (i = 0; i < nmodels; i++) {
- if (models && models[i] && STREQ(models[i], candidate->name)) {
- allowed = true;
- break;
- }
- }
-
- if (!allowed) {
+ if (!cpuModelIsAllowed(candidate->name, models, nmodels)) {
if (preferred && STREQ(candidate->name, preferred)) {
if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,