From nobody Sat May 4 07:27:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1677497721; cv=none; d=zohomail.com; s=zohoarc; b=F7+nP/BbRoGz6D1QC9O6F70Sdu2m4/mj4QnIR1Vkg+gKu/tQUHhSABviahFi5sHEjux6mFApGZFEGu+x9eo/LE9+qO85uqYSgbeCkOpe+DBmDW0XdX+dd2VdaF6i/ltXk9oGJY7mCdh6hp7qhbp5CpL5QwEdU/54tHutpF4jl8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677497721; 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=hgf1MQODWvmco6I2HscijOXY1zyPZjmad+3M3W1CA3w=; b=OeMhXZMhWV/X7iJ3FcPuNY0InyZqh7JLTIsydjV4APYTiViAjPAPahujiLewbBP0DMT6/CV4Rbj5oaPYBonpEx10B38M9bhHbzFpIyd9dHHDYZlqPGV0zZMUCO8BdZOqkGkSS7FidR+858cIZy8Z9u3hSNYEjuJ7Zce1RSjV2QM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1677497721656504.9366545530571; Mon, 27 Feb 2023 03:35:21 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-231-X-G0DkEIMoKcozQsVWISrA-1; Mon, 27 Feb 2023 06:35:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0EAD995D60E; Mon, 27 Feb 2023 11:35:13 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7532A40C6EC4; Mon, 27 Feb 2023 11:35:12 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5016C1946589; Mon, 27 Feb 2023 11:35:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2FCFC1946586 for ; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1546C492B14; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id B02EC492B12 for ; Mon, 27 Feb 2023 11:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677497720; 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=hgf1MQODWvmco6I2HscijOXY1zyPZjmad+3M3W1CA3w=; b=Ax9ncobuCRseqkUpPtf7XKQQ12wGwkwvJlfRAbOCSGtpT/GwOwmLXZ9Xh9lwzqH6loa4VJ AP5stoADSrli60GM7rmN+NeI6hLaHDJfdTzZfgnMpQT5VjlMAshTQJ/RQvXFgWCHaXh3M2 d46YNt5uo0ESDHszX/Vhkk+K1KCQrl0= X-MC-Unique: X-G0DkEIMoKcozQsVWISrA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] qemu: Don't error out on 'unknown' memory model in qemuMonitorJSONGetMemoryDeviceInfo() Date: Mon, 27 Feb 2023 12:35:00 +0100 Message-Id: <6e051c3c6459d3399f3746bcb2bf095646a8fb6f.1677497565.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677497723497100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When starting QEMU (or when reconnecting to a running one), qemuMonitorJSONGetMemoryDeviceInfo() is called to refresh info on memory devices. In here, query-memory-devices is called which returns info on all memory devices. The result is then iterated over and for some memory models runtime information is updated. The rest is to be ignored. Except, when introducing SGX support, this was turned into an error leaving us unable to start any domain with virtio-pmem memory device (as virtio-pmem is to be ignored). Fixes: ddb1bc051959eef4ad7ed6ac47b57056632bdb5e Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/qemu/qemu_monitor_json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e81b464eea..d76fea8b00 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7243,9 +7243,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, return -1; } } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s memory device info is not handled yet"), typ= e); - return -1; + /* type not handled yet */ + continue; } =20 meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); --=20 2.39.2 From nobody Sat May 4 07:27:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1677497724; cv=none; d=zohomail.com; s=zohoarc; b=FblFa/KtGfjXKXtTtLHSFRLtbLRqPhbnZvnL6Qe7mdyp7OXOpczFHClMUbsq4qYIqm3qwZasLI2CAnjLfK6iCyeITdIVgRt0aXFgLfl1JW572QziRNGSbRbANBbKWNv1FRyQAYaIvPzLRu6xULykabiKj10Fh6dvCkQ+laEBoXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677497724; 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=cYLBKjG9jgCih/Zap6anN3aEZT0IYKR4bw7SjAd5MnI=; b=VQpxO5rQ1YJZroGqst/hmH+OfsMZGG+1WOAoSWd7PDXojFI/F+q4UEMPPVJXd9VU+NcXBD5bSnvcl2O89Dvyp5y2HTqm1WXDasamvbA6VDYao90bvYm1HrSgHO+7yfaJLuYVqUgAikwzOos9a6DDsZypZg8qJNtHld6MlCVbSFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1677497724425147.79181195956085; Mon, 27 Feb 2023 03:35:24 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-qjhGbGO0MG-BPS4CffsdZA-1; Mon, 27 Feb 2023 06:35:20 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A457F1C08788; Mon, 27 Feb 2023 11:35:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90426C15BAD; Mon, 27 Feb 2023 11:35:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9C4761946A42; Mon, 27 Feb 2023 11:35:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AF66C1946586 for ; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A5588492B14; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C7DB492B12 for ; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677497723; 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=cYLBKjG9jgCih/Zap6anN3aEZT0IYKR4bw7SjAd5MnI=; b=a1GjF3s5XBsVDG/XYHuFhgNBTIwgi+AZ/u7uZZHnZZCjalRavl9m7dB+mQv7IjCb9blnZK Tn1CXA9J4C64n2IeHy6m+FVZNTZOPc4mj/W66qExQtE5cVzZYKQuX/+36UqtcMT5zhHerr FM47Qmoah4+InYEBrlqxHb7M+wviGp0= X-MC-Unique: qjhGbGO0MG-BPS4CffsdZA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] libvirt_private.syms: Export virDomainMemoryModelTypeFromString() Date: Mon, 27 Feb 2023 12:35:01 +0100 Message-Id: <56517f6ff2606d3761e1978d8a8da976d3c8014f.1677497565.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677497725440100003 Content-Type: text/plain; charset="utf-8"; x-default="true" The virDomainMemoryModelTypeFromString() is not exported, though the enum translation functions are declared in src/conf/domain_conf.h. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/libvirt_private.syms | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c6c47dbfac..f1bed27ba7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -519,6 +519,7 @@ virDomainMemoryFindByDeviceAlias; virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; +virDomainMemoryModelTypeFromString; virDomainMemoryModelTypeToString; virDomainMemoryRemove; virDomainMemorySourceTypeFromString; --=20 2.39.2 From nobody Sat May 4 07:27:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1677497738; cv=none; d=zohomail.com; s=zohoarc; b=fzZzqtoXUeJ9TX1m173h/Af/QMxClKy5SNvgsBovgwhwYOuly6MG8SnVT83sGRr0475DrA2kLstkEFj6iPS3aIzmyO+gjyyFzhBHCtjbSLGHyZYVeKeeAgw3S9t6ufB8xP7pgg7shk71S96jZ7nGIU7jJj7wGScfI9gaPKfcJkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677497738; 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=YXjlxNL4tW6DyWm8Iw6R/U8JJQSiWOEU76HyE7JmtRQ=; b=iKa4kS8n37RqJyQelv+ncq9PPpQTI39YOY5ZixoT8zAj5ejiIyzxXIUQVKjhLts7BHuySS/aNlJ3bar0r1APPzinG2l21oBUnwbRF5u9vKxuI3xDili6DLr62qma3FQ/DklPfMzdTBZwNc1qxNmvgN4KX8yQx2H3UDZlPXhIbIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1677497738661633.6531259790137; Mon, 27 Feb 2023 03:35:38 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-216-b8QMymCtNuOQ8p2IsOpfVQ-1; Mon, 27 Feb 2023 06:35:31 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 057F980D0F9; Mon, 27 Feb 2023 11:35:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1316140EBF4; Mon, 27 Feb 2023 11:35:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C2F3F1946A78; Mon, 27 Feb 2023 11:35:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 81F481946A41 for ; Mon, 27 Feb 2023 11:35:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 41ECF492B14; Mon, 27 Feb 2023 11:35:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD29B492B12 for ; Mon, 27 Feb 2023 11:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677497737; 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=YXjlxNL4tW6DyWm8Iw6R/U8JJQSiWOEU76HyE7JmtRQ=; b=LYHaJouMc2gBT2osHhOkKakl2qZLaUnpcoo/vksvjtqtik/uM85S0NHZmiID2NGZirQhW5 mb12867AUmaMR886DPLE8LG3MyN4SukXHKHSLV/WKMAK78qY1lA9w/4Lxlm9QIDRxT5p1d 0DkOep9fQvxNmi3jMMspJMbHZQ2VCqU= X-MC-Unique: b8QMymCtNuOQ8p2IsOpfVQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] qemu_monitor: Switch to virDomainMemoryModel enum in qemuMonitorJSONGetMemoryDeviceInfo() Date: Mon, 27 Feb 2023 12:35:02 +0100 Message-Id: <55662d5fe7071a136365d32ac51351da38988364.1677497565.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677497739551100003 Content-Type: text/plain; charset="utf-8"; x-default="true" When processing memory devices (as a reply from QEMU), a bunch of STREQ()-s is used. Fortunately, the set of strings we process is the same as virDomainMemoryModel enum. Therefore, we can use virDomainMemoryModelTypeFromString() and when use integer comparison (well, switch()). This has an up side, that introducing a new memory model let's us see immediately at compile time, what places need adjusting. NB, this is in contrast with cmd line generator (qemuBuildMemoryDeviceProps()), where more specific models are generated (e.g. "pc-dimm", "virtio-mem-pci", etc.). But QEMU reports back the parent model, instead of specific child instance. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/qemu/qemu_monitor_json.c | 52 +++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d76fea8b00..a5e525b7ce 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7211,15 +7211,21 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, g_autofree qemuMonitorMemoryDeviceInfo *meminfo =3D NULL; virJSONValue *dimminfo; const char *devalias; - const char *type; + const char *modelStr; + int model; =20 - if (!(type =3D virJSONValueObjectGetString(elem, "type"))) { + if (!(modelStr =3D virJSONValueObjectGetString(elem, "type"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-memory-devices reply data doesn't cont= ain " "enum type discriminator")); return -1; } =20 + if ((model =3D virDomainMemoryModelTypeFromString(modelStr)) < 0) { + VIR_WARN("Unknown memory model: %s", modelStr); + continue; + } + if (!(dimminfo =3D virJSONValueObjectGetObject(elem, "data"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-memory-devices reply data doesn't " @@ -7227,30 +7233,40 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, return -1; } =20 - if (STREQ(type, "dimm") || STREQ(type, "nvdimm") || STREQ(type, "v= irtio-mem")) { + switch ((virDomainMemoryModel) model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: /* While 'id' attribute is marked as optional in QEMU's QAPI - * specification, Libvirt always sets it. Thus we can fail if n= ot - * present. */ + * specification, Libvirt always sets it. Thus we can fail if = not + * present. */ if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "id")= )) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("dimm memory info data is missing 'id'")); + _("dimm memory info data is missing 'id'")); return -1; } - } else if (STREQ(type, "sgx-epc")) { + break; + + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "memd= ev"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("sgx-epc memory info data is missing 'memdev= '")); + _("sgx-epc memory info data is missing 'mem= dev'")); return -1; } - } else { + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: /* type not handled yet */ continue; } =20 meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); =20 - /* dimm memory devices */ - if (STREQ(type, "dimm") || STREQ(type, "nvdimm")) { + switch ((virDomainMemoryModel) model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -7280,16 +7296,18 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, return -1; =20 } + break; =20 - } else if (STREQ(type, "virtio-mem")) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (virJSONValueObjectGetNumberUlong(dimminfo, "size", &meminfo->size) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing size in virtio memory = info")); return -1; } - } else if (STREQ(type, "sgx-epc")) { - /* sgx-epc memory devices */ + break; + + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: if (virJSONValueObjectGetNumberUlong(dimminfo, "memaddr", &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -7303,7 +7321,11 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, _("malformed/missing size in sgx-epc memory= info")); return -1; } - } else { + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: /* type not handled yet */ continue; } --=20 2.39.2 From nobody Sat May 4 07:27:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1677497736; cv=none; d=zohomail.com; s=zohoarc; b=HekfeEXDQY2eBVZuDpL3jMkSiNJnb+FMmjBmuIDXjLoEB7xBZxRvBatWmXGWP5wggAL+1RCVe9IevoRXmwel9ReIh8irdraPu/SSK1XojRoWELGRWxGnZiVGFNkZTfpRjFJOwKuOPvOhuyMPYzKGB/TLOoj1TyBoYyGHqBIKda4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677497736; 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=KLIH1I13W3tiG+VbDoy+/hT/fPX38aYxHLeMfAPXsug=; b=e3k1XWmItRj7UCyj3qTLC0xpv9JA3Qh8hVlP5jxz2ZTXo8Kiu9iHxGayfHRgt9ckUjdC9kTmJCYQB0WIeOAg3tIbXvF/XTeLSuaG0+70Fk9rnK7DPxAnp5IQr8Fvto9KzdpTiaxhTa7tIjBareXer2vc6donV46RDrEv0HRmkS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1677497736537131.34752716644357; Mon, 27 Feb 2023 03:35:36 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-343-BFy7ej6JO6a3ihaQLQAS4A-1; Mon, 27 Feb 2023 06:35:31 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C93693C0DDB3; Mon, 27 Feb 2023 11:35:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B157A492B11; Mon, 27 Feb 2023 11:35:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 846801946A6B; Mon, 27 Feb 2023 11:35:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 073C719465B9 for ; Mon, 27 Feb 2023 11:35:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D298D492B13; Mon, 27 Feb 2023 11:35:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79749492B12 for ; Mon, 27 Feb 2023 11:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677497735; 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=KLIH1I13W3tiG+VbDoy+/hT/fPX38aYxHLeMfAPXsug=; b=ZVWisFvl4jjMl7arPyjaNfO6hkpRsZs5BFGb7WFVT5JHZsrLYiMgR/Ou6JoiAQZfZ3saSC zP4IMv0mMtmhrhREVkbe5NUA8rAADf2eM7h7nXbs/iIcXLWdN1q80L3s8kapI5k32QhdTV 5pOdyK9DZEHgYd17d7LNwLjzmrw/dR0= X-MC-Unique: BFy7ej6JO6a3ihaQLQAS4A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] qemu_monitor: Decouple switch()-es in qemuMonitorJSONGetMemoryDeviceInfo() Date: Mon, 27 Feb 2023 12:35:03 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677497737532100001 Content-Type: text/plain; charset="utf-8"; x-default="true" There are two switch() statements over the same variable inside of qemuMonitorJSONGetMemoryDeviceInfo(). Join them together into one switch. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/qemu/qemu_monitor_json.c | 97 ++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a5e525b7ce..464e1e1822 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7233,6 +7233,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, return -1; } =20 + meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); + switch ((virDomainMemoryModel) model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: @@ -7245,6 +7247,46 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, _("dimm memory info data is missing 'id'")); return -1; } + + if (model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM || + model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", + &meminfo->address) < = 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing addr in dimm memor= y info")); + return -1; + } + + if (virJSONValueObjectGetNumberUint(dimminfo, "slot", + &meminfo->slot) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing slot in dimm memor= y info")); + return -1; + } + + if (virJSONValueObjectGetBoolean(dimminfo, "hotplugged", + &meminfo->hotplugged) < 0= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing hotplugged in dimm= memory info")); + return -1; + + } + + if (virJSONValueObjectGetBoolean(dimminfo, "hotpluggable", + &meminfo->hotpluggable) <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing hotpluggable in di= mm memory info")); + return -1; + + } + } else if (model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) { + if (virJSONValueObjectGetNumberUlong(dimminfo, "size", + &meminfo->size) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing size in virtio mem= ory info")); + return -1; + } + } break; =20 case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: @@ -7253,61 +7295,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, _("sgx-epc memory info data is missing 'mem= dev'")); return -1; } - break; - - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: - case VIR_DOMAIN_MEMORY_MODEL_NONE: - case VIR_DOMAIN_MEMORY_MODEL_LAST: - /* type not handled yet */ - continue; - } - - meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); - - switch ((virDomainMemoryModel) model) { - case VIR_DOMAIN_MEMORY_MODEL_DIMM: - case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", - &meminfo->address) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed/missing addr in dimm memory in= fo")); - return -1; - } - - if (virJSONValueObjectGetNumberUint(dimminfo, "slot", - &meminfo->slot) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed/missing slot in dimm memory in= fo")); - return -1; - } - - if (virJSONValueObjectGetBoolean(dimminfo, "hotplugged", - &meminfo->hotplugged) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed/missing hotplugged in dimm mem= ory info")); - return -1; - - } - - if (virJSONValueObjectGetBoolean(dimminfo, "hotpluggable", - &meminfo->hotpluggable) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed/missing hotpluggable in dimm m= emory info")); - return -1; - - } - break; - - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: - if (virJSONValueObjectGetNumberUlong(dimminfo, "size", - &meminfo->size) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed/missing size in virtio memory = info")); - return -1; - } - break; - - case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: if (virJSONValueObjectGetNumberUlong(dimminfo, "memaddr", &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", --=20 2.39.2