qemu: remove support for generating yes|no boolean options

All callers are now using the on|off syntax, so yes|no is a unreachable
code path.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-02-16 12:36:15 +00:00
parent 0d981fcd97
commit 2931839966
3 changed files with 25 additions and 45 deletions

View File

@ -37,7 +37,6 @@ struct virQEMUCommandLineJSONIteratorData {
const char *prefix; const char *prefix;
virBufferPtr buf; virBufferPtr buf;
const char *skipKey; const char *skipKey;
bool onOff;
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc; virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc;
}; };
@ -47,7 +46,6 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
virJSONValuePtr value, virJSONValuePtr value,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey,
bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc, virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested); bool nested);
@ -57,8 +55,7 @@ int
virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey G_GNUC_UNUSED, const char *skipKey G_GNUC_UNUSED)
bool onOff G_GNUC_UNUSED)
{ {
ssize_t pos = -1; ssize_t pos = -1;
ssize_t end; ssize_t end;
@ -87,8 +84,7 @@ int
virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey)
bool onOff)
{ {
virJSONValuePtr member; virJSONValuePtr member;
size_t i; size_t i;
@ -99,7 +95,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
member = virJSONValueArrayGet((virJSONValuePtr) array, i); member = virJSONValueArrayGet((virJSONValuePtr) array, i);
prefix = g_strdup_printf("%s.%zu", key, i); prefix = g_strdup_printf("%s.%zu", key, i);
if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey, onOff, if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey,
virQEMUBuildCommandLineJSONArrayNumbered, virQEMUBuildCommandLineJSONArrayNumbered,
true) < 0) true) < 0)
return 0; return 0;
@ -125,8 +121,7 @@ static int
virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key, virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey G_GNUC_UNUSED, const char *skipKey G_GNUC_UNUSED)
bool onOff G_GNUC_UNUSED)
{ {
g_auto(virBuffer) tmp = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) tmp = VIR_BUFFER_INITIALIZER;
size_t i; size_t i;
@ -163,11 +158,11 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
tmpkey = g_strdup_printf("%s.%s", data->prefix, key); tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
data->skipKey, data->onOff, data->skipKey,
data->arrayFunc, false); data->arrayFunc, false);
} else { } else {
return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
data->skipKey, data->onOff, data->skipKey,
data->arrayFunc, false); data->arrayFunc, false);
} }
} }
@ -178,11 +173,10 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
virJSONValuePtr value, virJSONValuePtr value,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey,
bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc, virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested) bool nested)
{ {
struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, onOff, arrayFunc }; struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, arrayFunc };
virJSONType type = virJSONValueGetType(value); virJSONType type = virJSONValueGetType(value);
virJSONValuePtr elem; virJSONValuePtr elem;
bool tmp; bool tmp;
@ -207,18 +201,10 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
case VIR_JSON_TYPE_BOOLEAN: case VIR_JSON_TYPE_BOOLEAN:
virJSONValueGetBoolean(value, &tmp); virJSONValueGetBoolean(value, &tmp);
if (onOff) { if (tmp)
if (tmp) virBufferAsprintf(buf, "%s=on,", key);
virBufferAsprintf(buf, "%s=on,", key); else
else virBufferAsprintf(buf, "%s=off,", key);
virBufferAsprintf(buf, "%s=off,", key);
} else {
if (tmp)
virBufferAsprintf(buf, "%s=yes,", key);
else
virBufferAsprintf(buf, "%s=no,", key);
}
break; break;
case VIR_JSON_TYPE_ARRAY: case VIR_JSON_TYPE_ARRAY:
@ -229,7 +215,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
return -1; return -1;
} }
if (!arrayFunc || arrayFunc(key, value, buf, skipKey, onOff) < 0) { if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 0) {
/* fallback, treat the array as a non-bitmap, adding the key /* fallback, treat the array as a non-bitmap, adding the key
* for each member */ * for each member */
for (i = 0; i < virJSONValueArraySize(value); i++) { for (i = 0; i < virJSONValueArraySize(value); i++) {
@ -237,7 +223,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
/* recurse to avoid duplicating code */ /* recurse to avoid duplicating code */
if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, skipKey, if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, skipKey,
onOff, arrayFunc, true) < 0) arrayFunc, true) < 0)
return -1; return -1;
} }
} }
@ -265,7 +251,6 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
* @value: json object containing the value * @value: json object containing the value
* @buf: otuput buffer * @buf: otuput buffer
* @skipKey: name of key that will be handled separately by caller * @skipKey: name of key that will be handled separately by caller
* @onOff: Use 'on' and 'off' for boolean values rather than 'yes' and 'no'
* @arrayFunc: array formatter function to allow for different syntax * @arrayFunc: array formatter function to allow for different syntax
* *
* Formats JSON value object into command line parameters suitable for use with * Formats JSON value object into command line parameters suitable for use with
@ -277,10 +262,9 @@ int
virQEMUBuildCommandLineJSON(virJSONValuePtr value, virQEMUBuildCommandLineJSON(virJSONValuePtr value,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey,
bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc array) virQEMUBuildCommandLineJSONArrayFormatFunc array)
{ {
if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, onOff, array, false) < 0) if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, array, false) < 0)
return -1; return -1;
virBufferTrim(buf, ","); virBufferTrim(buf, ",");
@ -311,7 +295,7 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
virBufferAsprintf(&buf, "%s,", type); virBufferAsprintf(&buf, "%s,", type);
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, if (virQEMUBuildCommandLineJSON(props, &buf, "type",
virQEMUBuildCommandLineJSONArrayObjectsStr) < 0) virQEMUBuildCommandLineJSONArrayObjectsStr) < 0)
return NULL; return NULL;
@ -336,7 +320,7 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf,
if (props) { if (props) {
virBufferAddLit(buf, ","); virBufferAddLit(buf, ",");
if (virQEMUBuildCommandLineJSON(props, buf, NULL, true, if (virQEMUBuildCommandLineJSON(props, buf, NULL,
virQEMUBuildCommandLineJSONArrayBitmap) < 0) virQEMUBuildCommandLineJSONArrayBitmap) < 0)
return -1; return -1;
} }
@ -362,7 +346,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
{ {
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, true, if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL,
virQEMUBuildCommandLineJSONArrayNumbered) < 0) virQEMUBuildCommandLineJSONArrayNumbered) < 0)
return NULL; return NULL;

View File

@ -29,23 +29,19 @@
typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey);
bool onOff);
int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, int virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey);
bool onOff);
int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, int virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virJSONValuePtr array, virJSONValuePtr array,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey);
bool onOff);
int virQEMUBuildCommandLineJSON(virJSONValuePtr value, int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
virBufferPtr buf, virBufferPtr buf,
const char *skipKey, const char *skipKey,
bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc array); virQEMUBuildCommandLineJSONArrayFormatFunc array);
char * char *

View File

@ -47,7 +47,7 @@ testQemuCommandBuildFromJSON(const void *opaque)
return -1; return -1;
} }
if (virQEMUBuildCommandLineJSON(val, &buf, NULL, false, data->arrayfunc) < 0) { if (virQEMUBuildCommandLineJSON(val, &buf, NULL, data->arrayfunc) < 0) {
fprintf(stderr, fprintf(stderr,
"\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n", "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n",
data->props); data->props);
@ -99,8 +99,8 @@ mymain(void)
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qwer\"}", "string=qwer"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qwer\"}", "string=qwer");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qw,e,r\"}", "string=qw,,e,,r"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qw,e,r\"}", "string=qw,,e,,r");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"number\":1234}", "number=1234"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"number\":1234}", "number=1234");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=yes"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=on");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=no"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=off");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[]}", NULL); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[]}", NULL);
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[0]}", "bitmap=0"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[0]}", "bitmap=0");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[1,3,5]}", DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[1,3,5]}",
@ -113,14 +113,14 @@ mymain(void)
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"array\":[\"bleah\",\"qwerty\",1]}", DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"array\":[\"bleah\",\"qwerty\",1]}",
"array=bleah,array=qwerty,array=1"); "array=bleah,array=qwerty,array=1");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true,\"hyphen-name\":1234,\"some_string\":\"bleah\"}", DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true,\"hyphen-name\":1234,\"some_string\":\"bleah\"}",
"boolean=yes,hyphen-name=1234,some_string=bleah"); "boolean=on,hyphen-name=1234,some_string=bleah");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"nest\": {\"boolean\":true," DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"nest\": {\"boolean\":true,"
"\"hyphen-name\":1234," "\"hyphen-name\":1234,"
"\"some_string\":\"bleah\"," "\"some_string\":\"bleah\","
"\"bleah\":\"bl,eah\"" "\"bleah\":\"bl,eah\""
"}" "}"
"}", "}",
"nest.boolean=yes,nest.hyphen-name=1234," "nest.boolean=on,nest.hyphen-name=1234,"
"nest.some_string=bleah,nest.bleah=bl,,eah"); "nest.some_string=bleah,nest.bleah=bl,,eah");
DO_TEST_COMMAND_DRIVE_FROM_JSON("{\"driver\":\"gluster\"," DO_TEST_COMMAND_DRIVE_FROM_JSON("{\"driver\":\"gluster\","
"\"volume\":\"test\"," "\"volume\":\"test\","