mirror of
https://github.com/libvirt/libvirt.git
synced 2026-08-12 06:04:46 -05:00
virsh: Add --model option for hypervisor-cpu-baseline
This option can be used as a shortcut for creating a single XML with
just a CPU model name and no features:
$ virsh hypervisor-cpu-baseline --model Skylake-Server
<cpu mode='custom' match='exact'>
<model fallback='forbid'>Skylake-Server</model>
<feature policy='disable' name='avx512f'/>
<feature policy='disable' name='avx512dq'/>
<feature policy='disable' name='clwb'/>
<feature policy='disable' name='avx512cd'/>
<feature policy='disable' name='avx512bw'/>
<feature policy='disable' name='avx512vl'/>
<feature policy='disable' name='pku'/>
</cpu>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
+19
-4
@@ -1689,7 +1689,8 @@ static const vshCmdInfo info_hypervisor_cpu_baseline[] = {
|
||||
};
|
||||
|
||||
static const vshCmdOptDef opts_hypervisor_cpu_baseline[] = {
|
||||
VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")),
|
||||
VIRSH_COMMON_OPT_FILE_FULL(N_("file containing XML CPU descriptions"),
|
||||
false),
|
||||
{.name = "virttype",
|
||||
.type = VSH_OT_STRING,
|
||||
.completer = virshDomainVirtTypeCompleter,
|
||||
@@ -1716,6 +1717,11 @@ static const vshCmdOptDef opts_hypervisor_cpu_baseline[] = {
|
||||
.type = VSH_OT_BOOL,
|
||||
.help = N_("Do not include features that block migration")
|
||||
},
|
||||
{.name = "model",
|
||||
.type = VSH_OT_STRING,
|
||||
.help = N_("Shortcut for calling the command with a single CPU model "
|
||||
"and no additional features")
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
|
||||
@@ -1728,6 +1734,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
|
||||
const char *emulator = NULL;
|
||||
const char *arch = NULL;
|
||||
const char *machine = NULL;
|
||||
const char *model = NULL;
|
||||
bool ret = false;
|
||||
g_autofree char *result = NULL;
|
||||
g_auto(GStrv) list = NULL;
|
||||
@@ -1743,11 +1750,19 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
|
||||
vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 ||
|
||||
vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 ||
|
||||
vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 ||
|
||||
vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0)
|
||||
vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0 ||
|
||||
vshCommandOptStringReq(ctl, cmd, "model", &model) < 0)
|
||||
return false;
|
||||
|
||||
if (!(list = vshExtractCPUDefXMLs(ctl, from)))
|
||||
return false;
|
||||
VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model);
|
||||
|
||||
if (from) {
|
||||
if (!(list = vshExtractCPUDefXMLs(ctl, from)))
|
||||
return false;
|
||||
} else {
|
||||
list = g_new0(char *, 2);
|
||||
list[0] = g_strdup_printf("<cpu><model>%s</model></cpu>", model);
|
||||
}
|
||||
|
||||
result = virConnectBaselineHypervisorCPU(priv->conn, emulator, arch,
|
||||
machine, virttype,
|
||||
|
||||
+5
-2
@@ -96,9 +96,12 @@
|
||||
|
||||
/* Use this only for files which are existing and used locally by virsh */
|
||||
#define VIRSH_COMMON_OPT_FILE(_helpstr) \
|
||||
VIRSH_COMMON_OPT_FILE_FULL(_helpstr, true)
|
||||
|
||||
#define VIRSH_COMMON_OPT_FILE_FULL(_helpstr, required) \
|
||||
{.name = "file", \
|
||||
.type = VSH_OT_DATA, \
|
||||
.flags = VSH_OFLAG_REQ, \
|
||||
.type = required ? VSH_OT_DATA : VSH_OT_STRING, \
|
||||
.flags = required ? VSH_OFLAG_REQ : VSH_OFLAG_NONE, \
|
||||
.completer = virshCompletePathLocalExisting, \
|
||||
.help = _helpstr \
|
||||
}
|
||||
|
||||
+27
@@ -520,6 +520,33 @@ void vshReadlineHistoryAdd(const char *cmd);
|
||||
#define VSH_EXCLUSIVE_OPTIONS_VAR(VARNAME1, VARNAME2) \
|
||||
VSH_EXCLUSIVE_OPTIONS_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2)
|
||||
|
||||
/* Macros to help dealing with alternative mutually exclusive options. */
|
||||
|
||||
/* VSH_ALTERNATIVE_OPTIONS_EXPR:
|
||||
*
|
||||
* @NAME1: String containing the name of the option.
|
||||
* @EXPR1: Expression to validate the variable (must evaluate to bool).
|
||||
* @NAME2: String containing the name of the option.
|
||||
* @EXPR2: Expression to validate the variable (must evaluate to bool).
|
||||
*
|
||||
* Require exactly one of the command options in virsh. Use the provided
|
||||
* expression to check the variables.
|
||||
*
|
||||
* This helper does an early return and therefore it has to be called
|
||||
* before anything that would require cleanup.
|
||||
*/
|
||||
#define VSH_ALTERNATIVE_OPTIONS_EXPR(NAME1, EXPR1, NAME2, EXPR2) \
|
||||
do { \
|
||||
bool _expr1 = EXPR1; \
|
||||
bool _expr2 = EXPR2; \
|
||||
VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, _expr1, NAME2, _expr2); \
|
||||
if (!_expr1 && !_expr2) { \
|
||||
vshError(ctl, _("Either --%s or --%s must be provided"), \
|
||||
NAME1, NAME2); \
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Macros to help dealing with required options. */
|
||||
|
||||
/* VSH_REQUIRE_OPTION_EXPR:
|
||||
|
||||
Reference in New Issue
Block a user