<commit_before>/*
 * virt-host-validate-ch.c: Sanity check a CH hypervisor host
 *
 * Copyright Microsoft Corp. 2020-2021
 *
 * 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>

#include "virarch.h"
#include "virbitmap.h"
#include "virt-host-validate-ch.h"
#include "virt-host-validate-common.h"

int virHostValidateCh(void)
{
    int ret = 0;
    virBitmap *flags;
    bool hasHwVirt = false;
    bool hasVirtFlag = false;
    virArch arch = virArchFromHost();
    const char *kvmhint =
        _("Check that CPU and firmware supports virtualization "
          "and kvm module is loaded");

    if (!(flags = virHostValidateGetCPUFlags()))
        return -1;

    /* Cloud-Hypervisor only supports x86_64 and aarch64 */
    switch ((int)arch) {
    case VIR_ARCH_X86_64:
        hasVirtFlag = true;
        kvmhint = _("Check that the 'kvm-intel' or 'kvm-amd' modules are "
                    "loaded & the BIOS has enabled virtualization");
        if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) ||
            virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))
            hasHwVirt = true;
        break;
    case VIR_ARCH_AARCH64:
        hasVirtFlag = true;
        hasHwVirt = true;
        break;
    default:
        hasHwVirt = false;
        break;<commit_msg>tools: virt-host-validate: fix memory leak<commit_after>/*
 * virt-host-validate-ch.c: Sanity check a CH hypervisor host
 *
 * Copyright Microsoft Corp. 2020-2021
 *
 * 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>

#include "virarch.h"
#include "virbitmap.h"
#include "virt-host-validate-ch.h"
#include "virt-host-validate-common.h"

int virHostValidateCh(void)
{
    int ret = 0;
    g_autoptr(virBitmap) flags = NULL;
    bool hasHwVirt = false;
    bool hasVirtFlag = false;
    virArch arch = virArchFromHost();
    const char *kvmhint =
        _("Check that CPU and firmware supports virtualization "
          "and kvm module is loaded");

    if (!(flags = virHostValidateGetCPUFlags()))
        return -1;

    /* Cloud-Hypervisor only supports x86_64 and aarch64 */
    switch ((int)arch) {
    case VIR_ARCH_X86_64:
        hasVirtFlag = true;
        kvmhint = _("Check that the 'kvm-intel' or 'kvm-amd' modules are "
                    "loaded & the BIOS has enabled virtualization");
        if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) ||
            virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))
            hasHwVirt = true;
        break;
    case VIR_ARCH_AARCH64:
        hasVirtFlag = true;
        hasHwVirt = true;
        break;
    default:
        hasHwVirt = false;
        break;
{'fraction_non_alphanumeric': 0.08613659531090724, 'fraction_numerical': 0.012232415902140673, 'mean_word_length': 2.921078921078921, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7124341', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1173, 'n_words': 416}