From nobody Mon Feb 9 20:36:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589556548; cv=none; d=zohomail.com; s=zohoarc; b=fhKRYP0UCh6z5l5dpis/h4l3XlGp7/d475wcAUP9BuoaF55ohyprSs3T332StcWqPNRnKkDG/U2jupOT3JEpP/1RZpeSG6ygTDVzCM/Wcn4sZvcrCc3SeOw7CayZzjNJsJ+0lk2P3MDk5xGeLAiOIL/EZdC607pAmcvHnYIx2eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556548; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9y4khby1NoycR9cEQgejBakU4ve500OeBOlJotlPHmY=; b=J+IHltDgF+/mMSo+twU/6jtgZh1iS6SYxxjcJ4Xr5FmXkYI5k1XtN4FkGK3CNUUCqh2kw1jcslsZsljfrZSjXGegwfoOfgVMGG5ct8KOCcaUnnSbPRK852ZSfZMKjMIjgM8JJl/wa/poWAmlk1FnwfwfD3KU0w2mPuNDzHbn4UA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589556548663977.7010852712284; Fri, 15 May 2020 08:29:08 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-132-F2B_XA0ANEaQ904gMYD_EA-1; Fri, 15 May 2020 11:29:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F9B618FE863; Fri, 15 May 2020 15:28:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5186A63F8F; Fri, 15 May 2020 15:28:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2021E1809547; Fri, 15 May 2020 15:28:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04FFSvV8011278 for ; Fri, 15 May 2020 11:28:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9DA15D9F5; Fri, 15 May 2020 15:28:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 527425D9D7 for ; Fri, 15 May 2020 15:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556547; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9y4khby1NoycR9cEQgejBakU4ve500OeBOlJotlPHmY=; b=UZ8zGe3IMhViYE1/foJyH09LkZxyHW+PzYDbce8wjYAnrzb//mf+S5xIkPdMJteEIdIHzo +LpnhqcEJlkx4GV6y5VBigzPkdgq7r6MOkRI+sF7t75GxE4+IDBWP4MjOKoe3HaUDMADc1 5Zv+4FIp/S5+HzoSngGukU5uKs/auHs= X-MC-Unique: F2B_XA0ANEaQ904gMYD_EA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/21] virQEMUBuildCommandLineJSON: Add possibility for using 'on/off' instead of 'yes/no' Date: Fri, 15 May 2020 17:27:54 +0200 Message-Id: <722fd285ab17e8574213b1d57e97863871455233.1589556042.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In some cases we use 'on/off' for command line arguments. Add a switch which will select the prefred spelling for a specific usage. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virqemu.c | 44 ++++++++++++++++++++++++------------- src/util/virqemu.h | 10 ++++++--- tests/qemucommandutiltest.c | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 0e6fa412bc..549f88fcd5 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -37,6 +37,7 @@ struct virQEMUCommandLineJSONIteratorData { const char *prefix; virBufferPtr buf; const char *skipKey; + bool onOff; virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc; }; @@ -46,6 +47,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested); @@ -55,7 +57,8 @@ int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey G_GNUC_UNUSED) + const char *skipKey G_GNUC_UNUSED, + bool onOff G_GNUC_UNUSED) { ssize_t pos =3D -1; ssize_t end; @@ -84,7 +87,8 @@ int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey) + const char *skipKey, + bool onOff) { virJSONValuePtr member; size_t i; @@ -95,7 +99,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key, prefix =3D g_strdup_printf("%s.%zu", key, i); - if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, + if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, onOff, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) return 0; @@ -122,11 +126,11 @@ virQEMUBuildCommandLineJSONIterate(const char *key, tmpkey =3D g_strdup_printf("%s.%s", data->prefix, key); return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, - data->skipKey, + data->skipKey, data->onO= ff, data->arrayFunc, false); } else { return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, - data->skipKey, + data->skipKey, data->onO= ff, data->arrayFunc, false); } } @@ -137,10 +141,11 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested) { - struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, skipKey= , arrayFunc }; + struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, skipKey= , onOff, arrayFunc }; virJSONType type =3D virJSONValueGetType(value); virJSONValuePtr elem; bool tmp; @@ -165,10 +170,17 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, case VIR_JSON_TYPE_BOOLEAN: virJSONValueGetBoolean(value, &tmp); - if (tmp) - virBufferAsprintf(buf, "%s=3Dyes,", key); - else - virBufferAsprintf(buf, "%s=3Dno,", key); + if (onOff) { + if (tmp) + virBufferAsprintf(buf, "%s=3Don,", key); + else + virBufferAsprintf(buf, "%s=3Doff,", key); + } else { + if (tmp) + virBufferAsprintf(buf, "%s=3Dyes,", key); + else + virBufferAsprintf(buf, "%s=3Dno,", key); + } break; @@ -180,7 +192,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, return -1; } - if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 0) { + if (!arrayFunc || arrayFunc(key, value, buf, skipKey, onOff) < 0) { /* fallback, treat the array as a non-bitmap, adding the key * for each member */ for (i =3D 0; i < virJSONValueArraySize(value); i++) { @@ -188,7 +200,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, /* recurse to avoid duplicating code */ if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, ski= pKey, - arrayFunc, true) < = 0) + onOff, arrayFunc, t= rue) < 0) return -1; } } @@ -216,6 +228,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, * @value: json object containing the value * @buf: otuput buffer * @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 * * Formats JSON value object into command line parameters suitable for use= with @@ -227,9 +240,10 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatFunc arr= ay) { - if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, arra= y, false) < 0) + if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, onOf= f, array, false) < 0) return -1; virBufferTrim(buf, ","); @@ -255,7 +269,7 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBuffer= Ptr buf, if (props) { virBufferAddLit(buf, ","); - if (virQEMUBuildCommandLineJSON(props, buf, NULL, + if (virQEMUBuildCommandLineJSON(props, buf, NULL, false, virQEMUBuildCommandLineJSONArrayBitmap) < = 0) return -1; } @@ -282,7 +296,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr sr= cdef) virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *ret =3D NULL; - if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, + if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false, virQEMUBuildCommandLineJSONArrayNumber= ed) < 0) goto cleanup; diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 9d3db7c2a2..67a5711613 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -30,19 +30,23 @@ typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, virJSONValuePtr = array, virBufferPtr buf, - const char *skip= Key); + const char *skip= Key, + bool onOff); int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey); + const char *skipKey, + bool onOff); int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey); + const char *skipKey, + bool onOff); int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatFunc= array); int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index 923776e642..049fd2f0b0 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -47,7 +47,7 @@ testQemuCommandBuildFromJSON(const void *opaque) return -1; } - if (virQEMUBuildCommandLineJSON(val, &buf, NULL, data->arrayfunc) < 0)= { + if (virQEMUBuildCommandLineJSON(val, &buf, NULL, false, data->arrayfun= c) < 0) { fprintf(stderr, "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n", data->props); --=20 2.26.2