From nobody Sat May 4 00:21:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1598282069; cv=none; d=zohomail.com; s=zohoarc; b=RM6KJadSfS/RhbdosyetmDqzjj5E/q/4aWM0Tp844jCleaFh7BpqTR6QrCKruBqKi1Jy1UZtRaEhAOSXjGUIs190jJtZKgxCo37y8hkesRrskxVXwu8LvTS1WFEpln0LubxwhZBkFmR+et1jbNq5hnHYRzeYrCtq0pZAztTflyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598282069; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=wggwNTNMV62c61ZNw/AYmtpwcDPKXHyUl1SxfVLCpUw=; b=Yyr2FS93blt1IUlaayEptaqUayJ9CUh1Xv3tnuR316SFLbNmK4lBE47OtE11mcew/EZ72VEpIrVXIXk/+2tQIDoSqT025BhcSRddUCIedzPWGLESa+GRp+kcAwubhvhIXLbUiKjosjzP956ZDNNwOxo9ABIfXMzjRQHRUe8sLvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1598282069841327.6181996277104; Mon, 24 Aug 2020 08:14:29 -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-317-W6aHk1njMi-wVp1RaPZh3Q-1; Mon, 24 Aug 2020 11:14:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 62A7418A224E; Mon, 24 Aug 2020 15:14:20 +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 07E3460C13; Mon, 24 Aug 2020 15:14:19 +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 A3E9218A0B65; Mon, 24 Aug 2020 15:14:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07OF5xmE023289 for ; Mon, 24 Aug 2020 11:05:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 577D05C1DA; Mon, 24 Aug 2020 15:05:59 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id B027E5C1C4 for ; Mon, 24 Aug 2020 15:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598282068; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wggwNTNMV62c61ZNw/AYmtpwcDPKXHyUl1SxfVLCpUw=; b=BzlM+/vqaST6cEfyQi3Jdgg3pENGLTQqt5mpvnqs+mSKFIvBi4gd3dlGifLnjcpCExofaN i+8D9jivYroa8V83hCV/vrHCjR5VS4dQrdSSppAxVt32Os8PC6Ryfv6rz/gHF7uXt2qiIU l0YTt+bGZIkd05xRXKsOfKDu6iE2S/U= X-MC-Unique: W6aHk1njMi-wVp1RaPZh3Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] qemuMigrationCapsToJSON: Refactor capability object formatting Date: Mon, 24 Aug 2020 17:05:54 +0200 Message-Id: <819b4edd956ac6a7aef501917557df579286f89b.1598281554.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use virJSONValueObjectCreate rather than creating the object piece-by-piece and use new accessors for bitmap to simplify the code. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/qemu/qemu_migration_params.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index 513140a6ca..231a8a2ee8 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -763,21 +763,15 @@ qemuMigrationCapsToJSON(virBitmapPtr caps, qemuMigrationCapability bit; for (bit =3D 0; bit < QEMU_MIGRATION_CAP_LAST; bit++) { - g_autoptr(virJSONValue) cap =3D virJSONValueNewObject(); - const char *name =3D qemuMigrationCapabilityTypeToString(bit); - bool supported =3D false; - bool state =3D false; + g_autoptr(virJSONValue) cap =3D NULL; - ignore_value(virBitmapGetBit(caps, bit, &supported)); - if (!supported) + if (!virBitmapIsBitSet(caps, bit)) continue; - ignore_value(virBitmapGetBit(states, bit, &state)); - - if (virJSONValueObjectAppendString(cap, "capability", name) < 0) - return NULL; - - if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0) + if (virJSONValueObjectCreate(&cap, + "s:capability", qemuMigrationCapabili= tyTypeToString(bit), + "b:state", virBitmapIsBitSet(states, = bit), + NULL) < 0) return NULL; if (virJSONValueArrayAppend(json, cap) < 0) --=20 2.26.2