2
* virt-host-validate-common.c: Sanity check helper APIs
4
* Copyright (C) 2012 Red Hat, Inc.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
#include <sys/utsname.h>
33
#include "virt-host-validate-common.h"
37
void virHostMsgSetQuiet(bool quietFlag)
42
void virHostMsgCheck(const char *prefix,
52
va_start(args, format);
53
if (virVasprintf(&msg, format, args) < 0) {
59
fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg);
63
static bool virHostMsgWantEscape(void)
65
static bool detectTty = true;
66
static bool wantEscape = false;
68
if (isatty(STDOUT_FILENO))
75
void virHostMsgPass(void)
80
if (virHostMsgWantEscape())
81
fprintf(stdout, "\033[32m%s\033[0m\n", _("PASS"));
83
fprintf(stdout, "%s\n", _("PASS"));
87
static const char * failMessages[] = {
93
verify(ARRAY_CARDINALITY(failMessages) == VIR_HOST_VALIDATE_LAST);
95
static const char *failEscapeCodes[] = {
101
verify(ARRAY_CARDINALITY(failEscapeCodes) == VIR_HOST_VALIDATE_LAST);
103
void virHostMsgFail(virHostValidateLevel level,
106
if (virHostMsgWantEscape())
107
fprintf(stdout, "%s%s\033[0m (%s)\n",
108
failEscapeCodes[level], _(failMessages[level]), hint);
110
fprintf(stdout, "%s (%s)\n",
111
_(failMessages[level]), hint);
115
int virHostValidateDevice(const char *hvname,
116
const char *dev_name,
117
virHostValidateLevel level,
120
virHostMsgCheck(hvname, "for device %s", dev_name);
122
if (access(dev_name, R_OK|W_OK) < 0) {
123
virHostMsgFail(level, hint);
132
bool virHostValidateHasCPUFlag(const char *name)
134
FILE *fp = fopen("/proc/cpuinfo", "r");
143
if (!fgets(line, sizeof(line), fp))
146
if (strstr(line, name)) {
152
VIR_FORCE_FCLOSE(fp);
158
int virHostValidateLinuxKernel(const char *hvname,
160
virHostValidateLevel level,
164
unsigned long thisversion;
168
virHostMsgCheck(hvname, _("for Linux >= %d.%d.%d"),
169
((version >> 16) & 0xff),
170
((version >> 8) & 0xff),
173
if (STRNEQ(uts.sysname, "Linux")) {
174
virHostMsgFail(level, hint);
178
if (virParseVersionString(uts.release, &thisversion, true) < 0) {
179
virHostMsgFail(level, hint);
183
if (thisversion < version) {
184
virHostMsgFail(level, hint);