cpu_s390.c 3.4 KB
Newer Older
T
Thang Pham 已提交
1 2 3
/*
 * cpu_s390.c: CPU driver for s390(x) CPUs
 *
4
 * Copyright (C) 2013 Red Hat, Inc.
T
Thang Pham 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright IBM Corp. 2012
 *
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
T
Thang Pham 已提交
20 21 22 23 24 25 26
 *
 * Authors:
 *      Thang Pham <thang.pham@us.ibm.com>
 */

#include <config.h>

27
#include "viralloc.h"
28
#include "virstring.h"
T
Thang Pham 已提交
29 30 31 32 33
#include "cpu.h"


#define VIR_FROM_THIS VIR_FROM_CPU

34
static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
T
Thang Pham 已提交
35 36

static void
37
s390DataFree(virCPUDataPtr data)
T
Thang Pham 已提交
38 39 40 41
{
    VIR_FREE(data);
}

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
static virCPUCompareResult
virCPUs390Compare(virCPUDefPtr host ATTRIBUTE_UNUSED,
                  virCPUDefPtr cpu ATTRIBUTE_UNUSED,
                  bool failMessages ATTRIBUTE_UNUSED)
{
    /* s390 relies on Qemu to perform all runability checking. Return
     * VIR_CPU_COMPARE_IDENTICAL to bypass Libvirt checking.
     */
    return VIR_CPU_COMPARE_IDENTICAL;
}

static int
virCPUs390Update(virCPUDefPtr guest,
                 const virCPUDef *host)
{
     virCPUDefPtr updated = NULL;
     int ret = -1;
     size_t i;

     if (guest->match == VIR_CPU_MATCH_MINIMUM) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("match mode %s not supported"),
                        virCPUMatchTypeToString(guest->match));
         goto cleanup;
     }

     if (guest->mode != VIR_CPU_MODE_HOST_MODEL) {
         ret = 0;
         goto cleanup;
     }

     if (!host) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("unknown host CPU model"));
         goto cleanup;
     }

     if (!(updated = virCPUDefCopyWithoutModel(guest)))
         goto cleanup;

     updated->mode = VIR_CPU_MODE_CUSTOM;
     if (virCPUDefCopyModel(updated, host, true) < 0)
         goto cleanup;

     for (i = 0; i < guest->nfeatures; i++) {
         if (guest->features[i].policy == VIR_CPU_FEATURE_OPTIONAL) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("only cpu feature policies 'require' and "
                              "'disable' are supported for %s"),
                            guest->features[i].name);
             goto cleanup;
        }

        if (virCPUDefUpdateFeature(updated,
                                   guest->features[i].name,
                                   guest->features[i].policy) < 0)
            goto cleanup;
     }

     virCPUDefStealModel(guest, updated, false);
     guest->mode = VIR_CPU_MODE_CUSTOM;
     guest->match = VIR_CPU_MATCH_EXACT;
     ret = 0;

 cleanup:
     virCPUDefFree(updated);
     return ret;
}

T
Thang Pham 已提交
111 112 113 114
struct cpuArchDriver cpuDriverS390 = {
    .name = "s390",
    .arch = archs,
    .narch = ARRAY_CARDINALITY(archs),
115
    .compare    = virCPUs390Compare,
116
    .decode     = NULL,
T
Thang Pham 已提交
117 118
    .encode     = NULL,
    .free       = s390DataFree,
119
    .nodeData   = NULL,
T
Thang Pham 已提交
120
    .baseline   = NULL,
121
    .update     = virCPUs390Update,
T
Thang Pham 已提交
122
};