domain_capabilities.c 18.5 KB
Newer Older
M
Michal Privoznik 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * domain_capabilities.c: domain capabilities XML processing
 *
 * Copyright (C) 2014 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <config.h>

23
#include "device_conf.h"
M
Michal Privoznik 已提交
24 25 26 27 28 29 30
#include "domain_capabilities.h"
#include "domain_conf.h"
#include "viralloc.h"
#include "virstring.h"

#define VIR_FROM_THIS VIR_FROM_CAPABILITIES

31 32
VIR_ENUM_IMPL(virDomainCapsCPUUsable,
              VIR_DOMCAPS_CPU_USABLE_LAST,
33 34
              "unknown", "yes", "no",
);
J
Jiri Denemark 已提交
35

36 37 38 39 40 41 42

VIR_ENUM_DECL(virDomainCapsFeature);
VIR_ENUM_IMPL(virDomainCapsFeature,
              VIR_DOMAIN_CAPS_FEATURE_LAST,
              "iothreads",
              "vmcoreinfo",
              "genid",
43
              "backingStoreInput",
44 45
);

M
Michal Privoznik 已提交
46
static virClassPtr virDomainCapsClass;
47
static virClassPtr virDomainCapsCPUModelsClass;
M
Michal Privoznik 已提交
48 49

static void virDomainCapsDispose(void *obj);
50
static void virDomainCapsCPUModelsDispose(void *obj);
M
Michal Privoznik 已提交
51 52 53

static int virDomainCapsOnceInit(void)
{
54
    if (!VIR_CLASS_NEW(virDomainCaps, virClassForObjectLockable()))
M
Michal Privoznik 已提交
55
        return -1;
56

57
    if (!VIR_CLASS_NEW(virDomainCapsCPUModels, virClassForObject()))
58 59
        return -1;

M
Michal Privoznik 已提交
60 61 62 63
    return 0;
}


64
VIR_ONCE_GLOBAL_INIT(virDomainCaps);
M
Michal Privoznik 已提交
65 66


67 68 69 70 71 72 73 74 75 76 77 78 79 80
static void
virDomainCapsStringValuesFree(virDomainCapsStringValuesPtr values)
{
    size_t i;

    if (!values || !values->values)
        return;

    for (i = 0; i < values->nvalues; i++)
        VIR_FREE(values->values[i]);
    VIR_FREE(values->values);
}


81 82 83 84 85 86 87 88 89 90 91 92
void
virSEVCapabilitiesFree(virSEVCapability *cap)
{
    if (!cap)
        return;

    VIR_FREE(cap->pdh);
    VIR_FREE(cap->cert_chain);
    VIR_FREE(cap);
}


M
Michal Privoznik 已提交
93 94 95 96 97 98 99
static void
virDomainCapsDispose(void *obj)
{
    virDomainCapsPtr caps = obj;

    VIR_FREE(caps->path);
    VIR_FREE(caps->machine);
100
    virObjectUnref(caps->cpu.custom);
101
    virCPUDefFree(caps->cpu.hostModel);
102
    virSEVCapabilitiesFree(caps->sev);
103 104

    virDomainCapsStringValuesFree(&caps->os.loader.values);
M
Michal Privoznik 已提交
105 106 107
}


108 109 110 111 112 113
static void
virDomainCapsCPUModelsDispose(void *obj)
{
    virDomainCapsCPUModelsPtr cpuModels = obj;
    size_t i;

114
    for (i = 0; i < cpuModels->nmodels; i++) {
115
        VIR_FREE(cpuModels->models[i].name);
116 117
        virStringListFree(cpuModels->models[i].blockers);
    }
118 119 120 121 122

    VIR_FREE(cpuModels->models);
}


M
Michal Privoznik 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136
virDomainCapsPtr
virDomainCapsNew(const char *path,
                 const char *machine,
                 virArch arch,
                 virDomainVirtType virttype)
{
    virDomainCapsPtr caps = NULL;

    if (virDomainCapsInitialize() < 0)
        return NULL;

    if (!(caps = virObjectLockableNew(virDomainCapsClass)))
        return NULL;

137 138
    caps->path = g_strdup(path);
    caps->machine = g_strdup(machine);
M
Michal Privoznik 已提交
139 140 141 142 143 144 145
    caps->arch = arch;
    caps->virttype = virttype;

    return caps;
}


146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
virDomainCapsCPUModelsPtr
virDomainCapsCPUModelsNew(size_t nmodels)
{
    virDomainCapsCPUModelsPtr cpuModels = NULL;

    if (virDomainCapsInitialize() < 0)
        return NULL;

    if (!(cpuModels = virObjectNew(virDomainCapsCPUModelsClass)))
        return NULL;

    if (VIR_ALLOC_N(cpuModels->models, nmodels) < 0)
        goto error;
    cpuModels->nmodels_max = nmodels;

    return cpuModels;

 error:
    virObjectUnref(cpuModels);
    return NULL;
}


virDomainCapsCPUModelsPtr
virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
{
    virDomainCapsCPUModelsPtr cpuModels;
    size_t i;

    if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels)))
        return NULL;

    for (i = 0; i < old->nmodels; i++) {
J
Jiri Denemark 已提交
179
        if (virDomainCapsCPUModelsAdd(cpuModels,
180
                                      old->models[i].name,
181 182
                                      old->models[i].usable,
                                      old->models[i].blockers) < 0)
183 184 185 186 187 188 189 190 191 192 193
            goto error;
    }

    return cpuModels;

 error:
    virObjectUnref(cpuModels);
    return NULL;
}


194 195 196
int
virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
                          const char *name,
197 198
                          virDomainCapsCPUUsable usable,
                          char **blockers)
199
{
200 201
    g_autofree char * nameCopy = NULL;
    VIR_AUTOSTRINGLIST blockersCopy = NULL;
202
    virDomainCapsCPUModelPtr cpu;
203

204
    nameCopy = g_strdup(name);
205

206
    if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
207
        return -1;
208

209 210
    if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
                     cpuModels->nmodels, 1) < 0)
211
        return -1;
212

213 214 215 216 217 218 219
    cpu = cpuModels->models + cpuModels->nmodels;
    cpuModels->nmodels++;

    cpu->usable = usable;
    cpu->name = g_steal_pointer(&nameCopy);
    cpu->blockers = g_steal_pointer(&blockersCopy);

220 221 222 223
    return 0;
}


224 225 226 227 228 229 230 231 232 233
virDomainCapsCPUModelPtr
virDomainCapsCPUModelsGet(virDomainCapsCPUModelsPtr cpuModels,
                          const char *name)
{
    size_t i;

    if (!cpuModels)
        return NULL;

    for (i = 0; i < cpuModels->nmodels; i++) {
234
        if (STREQ(cpuModels->models[i].name, name))
235 236 237 238 239 240 241
            return cpuModels->models + i;
    }

    return NULL;
}


M
Michal Privoznik 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
int
virDomainCapsEnumSet(virDomainCapsEnumPtr capsEnum,
                     const char *capsEnumName,
                     size_t nvalues,
                     unsigned int *values)
{
    size_t i;

    for (i = 0; i < nvalues; i++) {
        unsigned int val = 1 << values[i];

        if (!val) {
            /* Integer overflow */
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("integer overflow on %s. Please contact the "
                             "libvirt development team at libvir-list@redhat.com"),
                           capsEnumName);
259
            return -1;
M
Michal Privoznik 已提交
260 261 262 263 264
        }

        capsEnum->values |= val;
    }

265
    return 0;
M
Michal Privoznik 已提交
266 267 268 269 270 271 272 273 274 275 276 277
}


void
virDomainCapsEnumClear(virDomainCapsEnumPtr capsEnum)
{
    capsEnum->values = 0;
}


static int
virDomainCapsEnumFormat(virBufferPtr buf,
278
                        const virDomainCapsEnum *capsEnum,
M
Michal Privoznik 已提交
279 280 281 282 283
                        const char *capsEnumName,
                        virDomainCapsValToStr valToStr)
{
    size_t i;

284 285
    if (!capsEnum->report)
        return 0;
286

M
Michal Privoznik 已提交
287 288 289
    virBufferAsprintf(buf, "<enum name='%s'", capsEnumName);
    if (!capsEnum->values) {
        virBufferAddLit(buf, "/>\n");
290
        return 0;
M
Michal Privoznik 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    }
    virBufferAddLit(buf, ">\n");
    virBufferAdjustIndent(buf, 2);

    for (i = 0; i < sizeof(capsEnum->values) * CHAR_BIT; i++) {
        const char *val;

        if (!(capsEnum->values & (1 << i)))
            continue;

        if ((val = (valToStr)(i)))
            virBufferAsprintf(buf, "<value>%s</value>\n", val);
    }
    virBufferAdjustIndent(buf, -2);
    virBufferAddLit(buf, "</enum>\n");

307
    return 0;
M
Michal Privoznik 已提交
308 309
}

310 311 312

static void
virDomainCapsStringValuesFormat(virBufferPtr buf,
313
                                const virDomainCapsStringValues *values)
314 315 316 317 318 319 320 321
{
    size_t i;

    for (i = 0; i < values->nvalues; i++)
        virBufferEscapeString(buf, "<value>%s</value>\n", values->values[i]);
}


322 323
#define FORMAT_PROLOGUE(item) \
    do { \
324 325
        if (item->supported == VIR_TRISTATE_BOOL_ABSENT) \
            return; \
326
        virBufferAsprintf(buf, "<" #item " supported='%s'%s\n", \
327 328
                (item->supported == VIR_TRISTATE_BOOL_YES) ? "yes" : "no", \
                (item->supported == VIR_TRISTATE_BOOL_YES) ? ">" : "/>"); \
329
        if (item->supported == VIR_TRISTATE_BOOL_NO) \
330 331
            return; \
        virBufferAdjustIndent(buf, 2); \
M
Michal Privoznik 已提交
332 333
    } while (0)

334 335 336 337
#define FORMAT_EPILOGUE(item) \
    do { \
        virBufferAdjustIndent(buf, -2); \
        virBufferAddLit(buf, "</" #item ">\n"); \
M
Michal Privoznik 已提交
338 339
    } while (0)

340 341 342 343
#define ENUM_PROCESS(master, capsEnum, valToStr) \
    do { \
        virDomainCapsEnumFormat(buf, &master->capsEnum, \
                                #capsEnum, valToStr); \
M
Michal Privoznik 已提交
344 345
    } while (0)

346

347 348 349 350 351 352 353 354 355 356 357 358 359
static void
qemuDomainCapsFeatureFormatSimple(virBufferPtr buf,
                                  const char *featurename,
                                  virTristateBool supported)
{
    if (supported == VIR_TRISTATE_BOOL_ABSENT)
        return;

    virBufferAsprintf(buf, "<%s supported='%s'/>\n", featurename,
                      virTristateBoolTypeToString(supported));
}


360 361
static void
virDomainCapsLoaderFormat(virBufferPtr buf,
362
                          const virDomainCapsLoader *loader)
363 364 365
{
    FORMAT_PROLOGUE(loader);

366
    virDomainCapsStringValuesFormat(buf, &loader->values);
367 368
    ENUM_PROCESS(loader, type, virDomainLoaderTypeToString);
    ENUM_PROCESS(loader, readonly, virTristateBoolTypeToString);
369
    ENUM_PROCESS(loader, secure, virTristateBoolTypeToString);
370 371 372 373 374 375

    FORMAT_EPILOGUE(loader);
}

static void
virDomainCapsOSFormat(virBufferPtr buf,
376
                      const virDomainCapsOS *os)
377
{
378
    const virDomainCapsLoader *loader = &os->loader;
379 380 381

    FORMAT_PROLOGUE(os);

382 383
    ENUM_PROCESS(os, firmware, virDomainOsDefFirmwareTypeToString);

384 385 386 387 388
    virDomainCapsLoaderFormat(buf, loader);

    FORMAT_EPILOGUE(os);
}

389 390 391 392 393 394 395 396 397
static void
virDomainCapsCPUCustomFormat(virBufferPtr buf,
                             virDomainCapsCPUModelsPtr custom)
{
    size_t i;

    virBufferAdjustIndent(buf, 2);

    for (i = 0; i < custom->nmodels; i++) {
J
Jiri Denemark 已提交
398 399 400 401
        virDomainCapsCPUModelPtr model = custom->models + i;
        virBufferAsprintf(buf, "<model usable='%s'>%s</model>\n",
                          virDomainCapsCPUUsableTypeToString(model->usable),
                          model->name);
402 403 404 405 406 407 408
    }

    virBufferAdjustIndent(buf, -2);
}

static void
virDomainCapsCPUFormat(virBufferPtr buf,
409
                       const virDomainCapsCPU *cpu)
410 411 412 413 414 415 416 417
{
    virBufferAddLit(buf, "<cpu>\n");
    virBufferAdjustIndent(buf, 2);

    virBufferAsprintf(buf, "<mode name='%s' supported='%s'/>\n",
                      virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
                      cpu->hostPassthrough ? "yes" : "no");

418 419 420 421 422 423
    virBufferAsprintf(buf, "<mode name='%s' ",
                      virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL));
    if (cpu->hostModel) {
        virBufferAddLit(buf, "supported='yes'>\n");
        virBufferAdjustIndent(buf, 2);

424
        virCPUDefFormatBuf(buf, cpu->hostModel);
425 426 427 428 429 430

        virBufferAdjustIndent(buf, -2);
        virBufferAddLit(buf, "</mode>\n");
    } else {
        virBufferAddLit(buf, "supported='no'/>\n");
    }
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445

    virBufferAsprintf(buf, "<mode name='%s' ",
                      virCPUModeTypeToString(VIR_CPU_MODE_CUSTOM));
    if (cpu->custom && cpu->custom->nmodels) {
        virBufferAddLit(buf, "supported='yes'>\n");
        virDomainCapsCPUCustomFormat(buf, cpu->custom);
        virBufferAddLit(buf, "</mode>\n");
    } else {
        virBufferAddLit(buf, "supported='no'/>\n");
    }

    virBufferAdjustIndent(buf, -2);
    virBufferAddLit(buf, "</cpu>\n");
}

M
Michal Privoznik 已提交
446 447
static void
virDomainCapsDeviceDiskFormat(virBufferPtr buf,
448
                              const virDomainCapsDeviceDisk *disk)
M
Michal Privoznik 已提交
449 450 451 452 453
{
    FORMAT_PROLOGUE(disk);

    ENUM_PROCESS(disk, diskDevice, virDomainDiskDeviceTypeToString);
    ENUM_PROCESS(disk, bus, virDomainDiskBusTypeToString);
454
    ENUM_PROCESS(disk, model, virDomainDiskModelTypeToString);
M
Michal Privoznik 已提交
455 456 457 458 459

    FORMAT_EPILOGUE(disk);
}


460 461
static void
virDomainCapsDeviceGraphicsFormat(virBufferPtr buf,
462
                                  const virDomainCapsDeviceGraphics *graphics)
463 464 465 466 467 468 469 470 471
{
    FORMAT_PROLOGUE(graphics);

    ENUM_PROCESS(graphics, type, virDomainGraphicsTypeToString);

    FORMAT_EPILOGUE(graphics);
}


472 473
static void
virDomainCapsDeviceVideoFormat(virBufferPtr buf,
474
                               const virDomainCapsDeviceVideo *video)
475 476 477 478 479 480 481 482 483
{
    FORMAT_PROLOGUE(video);

    ENUM_PROCESS(video, modelType, virDomainVideoTypeToString);

    FORMAT_EPILOGUE(video);
}


M
Michal Privoznik 已提交
484 485
static void
virDomainCapsDeviceHostdevFormat(virBufferPtr buf,
486
                                 const virDomainCapsDeviceHostdev *hostdev)
M
Michal Privoznik 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499
{
    FORMAT_PROLOGUE(hostdev);

    ENUM_PROCESS(hostdev, mode, virDomainHostdevModeTypeToString);
    ENUM_PROCESS(hostdev, startupPolicy, virDomainStartupPolicyTypeToString);
    ENUM_PROCESS(hostdev, subsysType, virDomainHostdevSubsysTypeToString);
    ENUM_PROCESS(hostdev, capsType, virDomainHostdevCapsTypeToString);
    ENUM_PROCESS(hostdev, pciBackend, virDomainHostdevSubsysPCIBackendTypeToString);

    FORMAT_EPILOGUE(hostdev);
}


500 501
static void
virDomainCapsDeviceRNGFormat(virBufferPtr buf,
502
                             const virDomainCapsDeviceRNG *rng)
503 504 505 506 507 508 509 510 511 512
{
    FORMAT_PROLOGUE(rng);

    ENUM_PROCESS(rng, model, virDomainRNGModelTypeToString);
    ENUM_PROCESS(rng, backendModel, virDomainRNGBackendTypeToString);

    FORMAT_EPILOGUE(rng);
}


A
Andrea Bolognani 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
/**
 * virDomainCapsFeatureGICFormat:
 * @buf: target buffer
 * @gic: GIC features
 *
 * Format GIC features for inclusion in the domcapabilities XML.
 *
 * The resulting XML will look like
 *
 *   <gic supported='yes'>
 *     <enum name='version>
 *       <value>2</value>
 *       <value>3</value>
 *     </enum>
 *   </gic>
 */
static void
virDomainCapsFeatureGICFormat(virBufferPtr buf,
531
                              const virDomainCapsFeatureGIC *gic)
A
Andrea Bolognani 已提交
532 533 534 535 536 537 538 539
{
    FORMAT_PROLOGUE(gic);

    ENUM_PROCESS(gic, version, virGICVersionTypeToString);

    FORMAT_EPILOGUE(gic);
}

540 541
static void
virDomainCapsFeatureSEVFormat(virBufferPtr buf,
542
                              const virSEVCapability *sev)
543
{
544 545 546 547 548 549 550
    if (!sev) {
        virBufferAddLit(buf, "<sev supported='no'/>\n");
    } else {
        virBufferAddLit(buf, "<sev supported='yes'>\n");
        virBufferAdjustIndent(buf, 2);
        virBufferAsprintf(buf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
        virBufferAsprintf(buf, "<reducedPhysBits>%d</reducedPhysBits>\n",
551
                          sev->reduced_phys_bits);
552 553 554 555 556
        virBufferAdjustIndent(buf, -2);
        virBufferAddLit(buf, "</sev>\n");
    }

    return;
557 558
}

A
Andrea Bolognani 已提交
559

560 561 562 563
static void
virDomainCapsFormatFeatures(const virDomainCaps *caps,
                            virBufferPtr buf)
{
564
    g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
565
    size_t i;
566

567
    virDomainCapsFeatureGICFormat(&childBuf, &caps->gic);
568 569 570 571 572 573 574 575 576 577

    for (i = 0; i < VIR_DOMAIN_CAPS_FEATURE_LAST; i++) {
        if (i == VIR_DOMAIN_CAPS_FEATURE_IOTHREADS)
            continue;

        qemuDomainCapsFeatureFormatSimple(&childBuf,
                                          virDomainCapsFeatureTypeToString(i),
                                          caps->features[i]);
    }

578
    virDomainCapsFeatureSEVFormat(&childBuf, caps->sev);
579

580
    virXMLFormatElement(buf, "features", NULL, &childBuf);
581 582 583
}


584
char *
585
virDomainCapsFormat(const virDomainCaps *caps)
M
Michal Privoznik 已提交
586
{
587
    virBuffer buf = VIR_BUFFER_INITIALIZER;
M
Michal Privoznik 已提交
588 589 590
    const char *virttype_str = virDomainVirtTypeToString(caps->virttype);
    const char *arch_str = virArchToString(caps->arch);

591 592
    virBufferAddLit(&buf, "<domainCapabilities>\n");
    virBufferAdjustIndent(&buf, 2);
M
Michal Privoznik 已提交
593

594 595
    virBufferEscapeString(&buf, "<path>%s</path>\n", caps->path);
    virBufferAsprintf(&buf, "<domain>%s</domain>\n", virttype_str);
596
    if (caps->machine)
597 598
        virBufferAsprintf(&buf, "<machine>%s</machine>\n", caps->machine);
    virBufferAsprintf(&buf, "<arch>%s</arch>\n", arch_str);
M
Michal Privoznik 已提交
599 600

    if (caps->maxvcpus)
601
        virBufferAsprintf(&buf, "<vcpu max='%d'/>\n", caps->maxvcpus);
M
Michal Privoznik 已提交
602

603 604
    qemuDomainCapsFeatureFormatSimple(&buf, "iothreads",
                                      caps->features[VIR_DOMAIN_CAPS_FEATURE_IOTHREADS]);
605

606 607
    virDomainCapsOSFormat(&buf, &caps->os);
    virDomainCapsCPUFormat(&buf, &caps->cpu);
608

609 610
    virBufferAddLit(&buf, "<devices>\n");
    virBufferAdjustIndent(&buf, 2);
M
Michal Privoznik 已提交
611

612 613 614 615
    virDomainCapsDeviceDiskFormat(&buf, &caps->disk);
    virDomainCapsDeviceGraphicsFormat(&buf, &caps->graphics);
    virDomainCapsDeviceVideoFormat(&buf, &caps->video);
    virDomainCapsDeviceHostdevFormat(&buf, &caps->hostdev);
616
    virDomainCapsDeviceRNGFormat(&buf, &caps->rng);
M
Michal Privoznik 已提交
617

618 619
    virBufferAdjustIndent(&buf, -2);
    virBufferAddLit(&buf, "</devices>\n");
M
Michal Privoznik 已提交
620

621
    virDomainCapsFormatFeatures(caps, &buf);
A
Andrea Bolognani 已提交
622

623 624
    virBufferAdjustIndent(&buf, -2);
    virBufferAddLit(&buf, "</domainCapabilities>\n");
M
Michal Privoznik 已提交
625 626 627

    return virBufferContentAndReset(&buf);
}
628 629


630 631 632 633 634 635 636 637 638 639 640
#define ENUM_VALUE_MISSING(capsEnum, value) !(capsEnum.values & (1 << value))

#define ENUM_VALUE_ERROR(valueLabel, valueString) \
    do { \
        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
                       _("domain configuration does not support '%s' value '%s'"), \
                       valueLabel, valueString); \
    } while (0)


static int
641
virDomainCapsDeviceRNGDefValidate(const virDomainCaps *caps,
642 643 644 645 646 647 648 649 650 651 652 653
                                  const virDomainRNGDef *dev)
{
    if (ENUM_VALUE_MISSING(caps->rng.model, dev->model)) {
        ENUM_VALUE_ERROR("rng model",
                         virDomainRNGModelTypeToString(dev->model));
        return -1;
    }

    return 0;
}


654 655 656 657 658 659 660 661 662 663 664 665 666 667
static int
virDomainCapsDeviceVideoDefValidate(const virDomainCaps *caps,
                                    const virDomainVideoDef *dev)
{
    if (ENUM_VALUE_MISSING(caps->video.modelType, dev->type)) {
        ENUM_VALUE_ERROR("video model",
                         virDomainVideoTypeToString(dev->type));
        return -1;
    }

    return 0;
}


668
int
669
virDomainCapsDeviceDefValidate(const virDomainCaps *caps,
670
                               const virDomainDeviceDef *dev,
J
Ján Tomko 已提交
671
                               const virDomainDef *def G_GNUC_UNUSED)
672
{
673 674
    int ret = 0;

675
    switch ((virDomainDeviceType) dev->type) {
676 677 678
    case VIR_DOMAIN_DEVICE_RNG:
        ret = virDomainCapsDeviceRNGDefValidate(caps, dev->data.rng);
        break;
679 680 681
    case VIR_DOMAIN_DEVICE_VIDEO:
        ret = virDomainCapsDeviceVideoDefValidate(caps, dev->data.video);
        break;
682

683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
    case VIR_DOMAIN_DEVICE_DISK:
    case VIR_DOMAIN_DEVICE_REDIRDEV:
    case VIR_DOMAIN_DEVICE_NET:
    case VIR_DOMAIN_DEVICE_CONTROLLER:
    case VIR_DOMAIN_DEVICE_CHR:
    case VIR_DOMAIN_DEVICE_SMARTCARD:
    case VIR_DOMAIN_DEVICE_HOSTDEV:
    case VIR_DOMAIN_DEVICE_MEMORY:
    case VIR_DOMAIN_DEVICE_VSOCK:
    case VIR_DOMAIN_DEVICE_INPUT:
    case VIR_DOMAIN_DEVICE_SHMEM:
    case VIR_DOMAIN_DEVICE_LEASE:
    case VIR_DOMAIN_DEVICE_FS:
    case VIR_DOMAIN_DEVICE_SOUND:
    case VIR_DOMAIN_DEVICE_WATCHDOG:
    case VIR_DOMAIN_DEVICE_GRAPHICS:
    case VIR_DOMAIN_DEVICE_HUB:
    case VIR_DOMAIN_DEVICE_MEMBALLOON:
    case VIR_DOMAIN_DEVICE_NVRAM:
    case VIR_DOMAIN_DEVICE_TPM:
    case VIR_DOMAIN_DEVICE_PANIC:
    case VIR_DOMAIN_DEVICE_IOMMU:
    case VIR_DOMAIN_DEVICE_NONE:
    case VIR_DOMAIN_DEVICE_LAST:
        break;
    }

710
    return ret;
711
}