From nobody Mon May 20 16:30:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1671696115; cv=none; d=zohomail.com; s=zohoarc; b=m77IAj2eig4lXN+hxeYGNeG2znhfFFf8SeD90afAl7wIV8V8JJ5bk1196wAmcn5QyWexBtQupnLDh/dpIsoM7bDlC39pH+bgNVwQm03perqHMCPNjlFY4ZcR7XDwB4Yc7wnUbsM4R3GEJaIfS7kQRkxOG6yty4PBnNWNM3/37OY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671696115; h=Content-Type:Content-Transfer-Encoding:Cc: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=iWzy4CIRhUOqHOcTLWw0eZAa1rtKKowFtFuMx9dLf04=; b=PG4nooI4V/ChVbNKCm2nMjt7IxoxzUEupnSRi86vuBwUfTU2n9w4y5Laik8ZAfD5JOl4Ay8BM22NUgDzOF6cDSf+tP8DjNeKVTmmJj7akHjC5Eqacp2Ln+N4+/DBVE0OEukMVuk7n6ICyYbK2GtN5jiZa2omfVEZ2go3cjV4SHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671696115466213.56970978474726; Thu, 22 Dec 2022 00:01:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8GV8-00009i-8g; Thu, 22 Dec 2022 03:00:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8GUx-00006r-QN for qemu-devel@nongnu.org; Thu, 22 Dec 2022 03:00:16 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8GUw-0003mQ-5G for qemu-devel@nongnu.org; Thu, 22 Dec 2022 03:00:15 -0500 Received: by mail-wr1-x430.google.com with SMTP id h10so823230wrx.3 for ; Thu, 22 Dec 2022 00:00:13 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id ba18-20020a0560001c1200b002421ce6a275sm17406983wrb.114.2022.12.22.00.00.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 00:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iWzy4CIRhUOqHOcTLWw0eZAa1rtKKowFtFuMx9dLf04=; b=KqkAIKW5mZXTphq7AiBEtjm3PgcIgpQMoFORR4D0SWrlK4O5HASr+vIY19XpF8/ezI cDfkJyBrmNI8y++f53uSdLbA/uUi9DLbAXw7iEU9Fx2QiO1HAXZpHyvFW0BBpWLxPmTv tRXrDy/mMOx/901IAodpR9YykSQPBgFeSKUZdP9wfR4pWIln+G4NLX2i9/77Mie4CDZT lgEYCHOS+TQVkqWuXKlOwR/dQWx7Whi+Badf6GsO2t4hryiCLeZv4acnM+nJbG7DPsQW c+b2IQGNl19eWRG5GIA5CHeT3bnYh0Zl1stjeaR7cPl0+HsbTqhZAVcyyESUNSefn8WM C10w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iWzy4CIRhUOqHOcTLWw0eZAa1rtKKowFtFuMx9dLf04=; b=LHZLEOca7ItgZhOzKPoIRicHhGGROvyzSVnAAqjB/FCrgQCGEQKMMc5Y0R1QG/0DIC cKPs2CqczO1fIaB1Tt9pyaFcQ0lt3QcQHsRcUfXfdX0mhs383cgsKZnxqEMB0BRSy4WV U9z4PG2D9HSrhK8l3DVbMU8Q6UL/OMg3ug7MFqnMzXgr8eSxZXMWGGTdlAuDVyJdEEWA csKVf1yZZpUb7520ZtVIvLKuUard6cUHZ9xjtnSBRlfzLvviFhmtKWv021bbalwvO2de H9bBfdvNCVuc1G2zJyyAAty1SACN2zM/Va1JS5XNUExwThQOOeCrvw/95WFKJM7ti76j wRkQ== X-Gm-Message-State: AFqh2kpub2iIogF2hrMkLBnYsx7agMkB6E26oKTDzebdPU1CjIPC+x4j yU7NiPQ9L3GIbZLZ/aBQ28rcE+zOGoyxrHKUyDk= X-Google-Smtp-Source: AMrXdXtBGwyMiVG76gdJWavckNepUk2vKChO/zLM7GayDK3+uTmbVHFI+3k3/Y7ESTZcYI9zYoQwfA== X-Received: by 2002:a5d:438e:0:b0:24f:11eb:2746 with SMTP id i14-20020a5d438e000000b0024f11eb2746mr3088847wrq.68.1671696012353; Thu, 22 Dec 2022 00:00:12 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 1/2] hw/virtio: Rename virtio_device_find() -> qmp_find_virtio_device() Date: Thu, 22 Dec 2022 09:00:04 +0100 Message-Id: <20221222080005.27616-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222080005.27616-1-philmd@linaro.org> References: <20221222080005.27616-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1671696117940100011 To emphasize this function is QMP related, rename it. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/virtio/virtio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 289eb71045..a87007d22f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3826,7 +3826,7 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp) return list; } =20 -static VirtIODevice *virtio_device_find(const char *path) +static VirtIODevice *qmp_find_virtio_device(const char *path) { VirtIODevice *vdev; =20 @@ -3867,7 +3867,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) VirtIODevice *vdev; VirtioStatus *status; =20 - vdev =3D virtio_device_find(path); + vdev =3D qmp_find_virtio_device(path); if (vdev =3D=3D NULL) { error_setg(errp, "Path %s is not a VirtIODevice", path); return NULL; @@ -3943,7 +3943,7 @@ VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_= status(const char *path, VirtIODevice *vdev; VirtVhostQueueStatus *status; =20 - vdev =3D virtio_device_find(path); + vdev =3D qmp_find_virtio_device(path); if (vdev =3D=3D NULL) { error_setg(errp, "Path %s is not a VirtIODevice", path); return NULL; @@ -3987,7 +3987,7 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(cons= t char *path, VirtIODevice *vdev; VirtQueueStatus *status; =20 - vdev =3D virtio_device_find(path); + vdev =3D qmp_find_virtio_device(path); if (vdev =3D=3D NULL) { error_setg(errp, "Path %s is not a VirtIODevice", path); return NULL; @@ -4080,7 +4080,7 @@ VirtioQueueElement *qmp_x_query_virtio_queue_element(= const char *path, VirtQueue *vq; VirtioQueueElement *element =3D NULL; =20 - vdev =3D virtio_device_find(path); + vdev =3D qmp_find_virtio_device(path); if (vdev =3D=3D NULL) { error_setg(errp, "Path %s is not a VirtIO device", path); return NULL; --=20 2.38.1 From nobody Mon May 20 16:30:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1671696096; cv=none; d=zohomail.com; s=zohoarc; b=gw0jI5bK3cRVoZAzsKP/pSWT/5nnXJ3uIB8p7eK3US+Brz+EdBIGXJmkgO90jrvrbucnoUS0ixyg5MK/NWW6emqpyliPCtv7GzjmEk9KlUNt58mgGla6buMdBNxgjPdIiVdjqGYI+rFlSeyQS2h2cAq5chjuLGMENL3yazvaZz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671696096; h=Content-Type:Content-Transfer-Encoding:Cc: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=yzkZR6NpC7O5EhSQR19B0/UuekedlTmG41/Uubgc1gQ=; b=blL0FqiFQQZmwb1wv5iUlrbfr2FC9ygSDvcXOBpGmRd3MLQ/U6i2P8WE6MR7Yktzv6p2cONNuizaIYBQXkN1+oM18MK78EOdgH1gfw8HCM/LxnPEv5TWcqz9IR6Qqw4imACK9a9ChB9Wvaoy1epheJZyg6o9vHIVBTXdsdBPBJ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167169609647862.2730653274599; Thu, 22 Dec 2022 00:01:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8GVA-0000BL-8T; Thu, 22 Dec 2022 03:00:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8GV4-00008k-I1 for qemu-devel@nongnu.org; Thu, 22 Dec 2022 03:00:23 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8GV0-0003nG-Vb for qemu-devel@nongnu.org; Thu, 22 Dec 2022 03:00:22 -0500 Received: by mail-wm1-x332.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so3279881wma.1 for ; Thu, 22 Dec 2022 00:00:18 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id w16-20020a5d5450000000b0026a4bb75477sm3620516wrv.28.2022.12.22.00.00.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 00:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yzkZR6NpC7O5EhSQR19B0/UuekedlTmG41/Uubgc1gQ=; b=xZFETl7rcI+VLp7lyMwpKhwKQT1wiZnkW9gOu0j3wVx6pCBj8sN8R4dGW5TdKNAM9d DFWwkdfPvuPkcr8PVc1lHUHSSvRUvuT2x3VUgbfNPn5FoiAkWcdzKL7mQqbKlaEo4ojQ tJv1qaNygMiVXNS2CJdbSIxIrhOeQdYMdtpCpPrqRNZFUT3VfrVMl1xUtkUizc9oAWeN cbjTl5sZxchWyo8Z67NA8OWfLylODXxZoFXTNzzjWnx1DLJAXbL5iMKGKFzVdZFYFiYV DSGQPzG4/bVKFLCn4GpIZn0wfLEnS8DZdqK2F6DMaK5s/mvIT9xq25t0DU0cMzFuzLpe 9V+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzkZR6NpC7O5EhSQR19B0/UuekedlTmG41/Uubgc1gQ=; b=g+2q+ZTwAIRHPFH9ekX7DFKvg9i9VLSFl6RUrEnkwfoXZE7/YMB7jf16Q/+P10AKFe kkDbUjugGTiBu5U3v3zaTrBZ4AGf7P8yl7rG+gWpZsTNloh9xDmEKw7+mgucWGvICH/a PFikDi0vcE6HJpRNyx44tOH4tDEesCTtMA4+TAIdBZjHkIXQy5v3tzLLf9vaXPM8lxsf 1p7hvqeKKHIJR6H6jdb2r+xr7znQBvZFhFE0XTyJBQW25k+mL5+ajIUGYAeqnNiCceke gHxXR6sCY3/fLBp46IjJo0eAMjQffbQrvmehteAfMTARuBmxyEfeARAUyV2poe7rGNb7 rtww== X-Gm-Message-State: AFqh2kqoJjLqLPwHLzeJ9jhJCSaV7L10oCU1iy3/52BHbF3EUOq2aikW YHrLeDJs2vhkJhNoKwamwnI94QFFMpIvapQ9f5c= X-Google-Smtp-Source: AMrXdXvjsbRxBcpGqNi0zOw+35Tnoygs1Tl4QozMdUA2yRPohgqHZQCGhKNnYRLtqI9zN/22JQHWTg== X-Received: by 2002:a05:600c:5128:b0:3c6:e62e:2e67 with SMTP id o40-20020a05600c512800b003c6e62e2e67mr3311185wms.2.1671696017321; Thu, 22 Dec 2022 00:00:17 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 2/2] hw/virtio: Extract QMP QOM-specific functions to virtio-qmp.c Date: Thu, 22 Dec 2022 09:00:05 +0100 Message-Id: <20221222080005.27616-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222080005.27616-1-philmd@linaro.org> References: <20221222080005.27616-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1671696097959100003 virtio.c is big enough, extract more QMP related code to virtio-qmp.c. To do so, expose qmp_find_virtio_device() and declar virtio_list in the internal virtio-qmp.h header. Note we have to leave qmp_x_query_virtio_queue_status() and qmp_x_query_virtio_queue_element(), because they access VirtQueue internal fields, and VirtQueue is only declared within virtio.c. Suggested-by: Jonah Palmer Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/virtio/virtio-qmp.c | 192 ++++++++++++++++++++++++++++++++++++++++- hw/virtio/virtio-qmp.h | 9 ++ hw/virtio/virtio.c | 191 +--------------------------------------- 3 files changed, 201 insertions(+), 191 deletions(-) diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 8e7282658f..e4d4bece2d 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -10,9 +10,14 @@ */ =20 #include "qemu/osdep.h" -#include "hw/virtio/virtio.h" #include "virtio-qmp.h" =20 +#include "qapi/error.h" +#include "qapi/qapi-commands-virtio.h" +#include "qapi/qapi-commands-qom.h" +#include "qapi/qmp/qobject.h" +#include "qapi/qmp/qjson.h" + #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/virtio_blk.h" @@ -657,3 +662,188 @@ VirtioDeviceFeatures *qmp_decode_features(uint16_t de= vice_id, uint64_t bitmap) =20 return features; } + +VirtioInfoList *qmp_x_query_virtio(Error **errp) +{ + VirtioInfoList *list =3D NULL; + VirtioInfoList *node; + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev =3D DEVICE(vdev); + Error *err =3D NULL; + QObject *obj =3D qmp_qom_get(dev->canonical_path, "realized", &err= ); + + if (err =3D=3D NULL) { + GString *is_realized =3D qobject_to_json_pretty(obj, true); + /* virtio device is NOT realized, remove it from list */ + if (!strncmp(is_realized->str, "false", 4)) { + QTAILQ_REMOVE(&virtio_list, vdev, next); + } else { + node =3D g_new0(VirtioInfoList, 1); + node->value =3D g_new(VirtioInfo, 1); + node->value->path =3D g_strdup(dev->canonical_path); + node->value->name =3D g_strdup(vdev->name); + QAPI_LIST_PREPEND(list, node->value); + } + g_string_free(is_realized, true); + } + qobject_unref(obj); + } + + return list; +} + +VirtIODevice *qmp_find_virtio_device(const char *path) +{ + VirtIODevice *vdev; + + QTAILQ_FOREACH(vdev, &virtio_list, next) { + DeviceState *dev =3D DEVICE(vdev); + + if (strcmp(dev->canonical_path, path) !=3D 0) { + continue; + } + + Error *err =3D NULL; + QObject *obj =3D qmp_qom_get(dev->canonical_path, "realized", &err= ); + if (err =3D=3D NULL) { + GString *is_realized =3D qobject_to_json_pretty(obj, true); + /* virtio device is NOT realized, remove it from list */ + if (!strncmp(is_realized->str, "false", 4)) { + g_string_free(is_realized, true); + qobject_unref(obj); + QTAILQ_REMOVE(&virtio_list, vdev, next); + return NULL; + } + g_string_free(is_realized, true); + } else { + /* virtio device doesn't exist in QOM tree */ + QTAILQ_REMOVE(&virtio_list, vdev, next); + qobject_unref(obj); + return NULL; + } + /* device exists in QOM tree & is realized */ + qobject_unref(obj); + return vdev; + } + return NULL; +} + +VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) +{ + VirtIODevice *vdev; + VirtioStatus *status; + + vdev =3D qmp_find_virtio_device(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + status =3D g_new0(VirtioStatus, 1); + status->name =3D g_strdup(vdev->name); + status->device_id =3D vdev->device_id; + status->vhost_started =3D vdev->vhost_started; + status->guest_features =3D qmp_decode_features(vdev->device_id, + vdev->guest_features); + status->host_features =3D qmp_decode_features(vdev->device_id, + vdev->host_features); + status->backend_features =3D qmp_decode_features(vdev->device_id, + vdev->backend_features); + + switch (vdev->device_endian) { + case VIRTIO_DEVICE_ENDIAN_LITTLE: + status->device_endian =3D g_strdup("little"); + break; + case VIRTIO_DEVICE_ENDIAN_BIG: + status->device_endian =3D g_strdup("big"); + break; + default: + status->device_endian =3D g_strdup("unknown"); + break; + } + + status->num_vqs =3D virtio_get_num_queues(vdev); + status->status =3D qmp_decode_status(vdev->status); + status->isr =3D vdev->isr; + status->queue_sel =3D vdev->queue_sel; + status->vm_running =3D vdev->vm_running; + status->broken =3D vdev->broken; + status->disabled =3D vdev->disabled; + status->use_started =3D vdev->use_started; + status->started =3D vdev->started; + status->start_on_kick =3D vdev->start_on_kick; + status->disable_legacy_check =3D vdev->disable_legacy_check; + status->bus_name =3D g_strdup(vdev->bus_name); + status->use_guest_notifier_mask =3D vdev->use_guest_notifier_mask; + + if (vdev->vhost_started) { + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev =3D vdc->get_vhost(vdev); + + status->vhost_dev =3D g_new0(VhostStatus, 1); + status->vhost_dev->n_mem_sections =3D hdev->n_mem_sections; + status->vhost_dev->n_tmp_sections =3D hdev->n_tmp_sections; + status->vhost_dev->nvqs =3D hdev->nvqs; + status->vhost_dev->vq_index =3D hdev->vq_index; + status->vhost_dev->features =3D + qmp_decode_features(vdev->device_id, hdev->features); + status->vhost_dev->acked_features =3D + qmp_decode_features(vdev->device_id, hdev->acked_features); + status->vhost_dev->backend_features =3D + qmp_decode_features(vdev->device_id, hdev->backend_features); + status->vhost_dev->protocol_features =3D + qmp_decode_protocols(hdev->protocol_features); + status->vhost_dev->max_queues =3D hdev->max_queues; + status->vhost_dev->backend_cap =3D hdev->backend_cap; + status->vhost_dev->log_enabled =3D hdev->log_enabled; + status->vhost_dev->log_size =3D hdev->log_size; + } + + return status; +} + +VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *pa= th, + uint16_t queue, + Error **errp) +{ + VirtIODevice *vdev; + VirtVhostQueueStatus *status; + + vdev =3D qmp_find_virtio_device(path); + if (vdev =3D=3D NULL) { + error_setg(errp, "Path %s is not a VirtIODevice", path); + return NULL; + } + + if (!vdev->vhost_started) { + error_setg(errp, "Error: vhost device has not started yet"); + return NULL; + } + + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev =3D vdc->get_vhost(vdev); + + if (queue < hdev->vq_index || queue >=3D hdev->vq_index + hdev->nvqs) { + error_setg(errp, "Invalid vhost virtqueue number %d", queue); + return NULL; + } + + status =3D g_new0(VirtVhostQueueStatus, 1); + status->name =3D g_strdup(vdev->name); + status->kick =3D hdev->vqs[queue].kick; + status->call =3D hdev->vqs[queue].call; + status->desc =3D (uintptr_t)hdev->vqs[queue].desc; + status->avail =3D (uintptr_t)hdev->vqs[queue].avail; + status->used =3D (uintptr_t)hdev->vqs[queue].used; + status->num =3D hdev->vqs[queue].num; + status->desc_phys =3D hdev->vqs[queue].desc_phys; + status->desc_size =3D hdev->vqs[queue].desc_size; + status->avail_phys =3D hdev->vqs[queue].avail_phys; + status->avail_size =3D hdev->vqs[queue].avail_size; + status->used_phys =3D hdev->vqs[queue].used_phys; + status->used_size =3D hdev->vqs[queue].used_size; + + return status; +} diff --git a/hw/virtio/virtio-qmp.h b/hw/virtio/virtio-qmp.h index 075fc27030..59681082e5 100644 --- a/hw/virtio/virtio-qmp.h +++ b/hw/virtio/virtio-qmp.h @@ -12,7 +12,16 @@ #define HW_VIRTIO_QMP_H =20 #include "qapi/qapi-types-virtio.h" +#include "hw/virtio/virtio.h" =20 +#include "qemu/queue.h" + +typedef QTAILQ_HEAD(QmpVirtIODeviceList, VirtIODevice) QmpVirtIODeviceList; + +/* QAPI list of realized VirtIODevices */ +extern QmpVirtIODeviceList virtio_list; + +VirtIODevice *qmp_find_virtio_device(const char *path); VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap); VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap); VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bit= map); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a87007d22f..40a1d3e8db 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -13,10 +13,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" -#include "qapi/qmp/qdict.h" #include "qapi/qapi-commands-virtio.h" -#include "qapi/qapi-commands-qom.h" -#include "qapi/qmp/qjson.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/log.h" @@ -47,8 +44,7 @@ #include "standard-headers/linux/virtio_mem.h" #include "standard-headers/linux/virtio_vsock.h" =20 -/* QAPI list of realized VirtIODevices */ -static QTAILQ_HEAD(, VirtIODevice) virtio_list; +QmpVirtIODeviceList virtio_list; =20 /* * Maximum size of virtio device config space @@ -3795,191 +3791,6 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *= vdev) return virtio_bus_ioeventfd_enabled(vbus); } =20 -VirtioInfoList *qmp_x_query_virtio(Error **errp) -{ - VirtioInfoList *list =3D NULL; - VirtioInfoList *node; - VirtIODevice *vdev; - - QTAILQ_FOREACH(vdev, &virtio_list, next) { - DeviceState *dev =3D DEVICE(vdev); - Error *err =3D NULL; - QObject *obj =3D qmp_qom_get(dev->canonical_path, "realized", &err= ); - - if (err =3D=3D NULL) { - GString *is_realized =3D qobject_to_json_pretty(obj, true); - /* virtio device is NOT realized, remove it from list */ - if (!strncmp(is_realized->str, "false", 4)) { - QTAILQ_REMOVE(&virtio_list, vdev, next); - } else { - node =3D g_new0(VirtioInfoList, 1); - node->value =3D g_new(VirtioInfo, 1); - node->value->path =3D g_strdup(dev->canonical_path); - node->value->name =3D g_strdup(vdev->name); - QAPI_LIST_PREPEND(list, node->value); - } - g_string_free(is_realized, true); - } - qobject_unref(obj); - } - - return list; -} - -static VirtIODevice *qmp_find_virtio_device(const char *path) -{ - VirtIODevice *vdev; - - QTAILQ_FOREACH(vdev, &virtio_list, next) { - DeviceState *dev =3D DEVICE(vdev); - - if (strcmp(dev->canonical_path, path) !=3D 0) { - continue; - } - - Error *err =3D NULL; - QObject *obj =3D qmp_qom_get(dev->canonical_path, "realized", &err= ); - if (err =3D=3D NULL) { - GString *is_realized =3D qobject_to_json_pretty(obj, true); - /* virtio device is NOT realized, remove it from list */ - if (!strncmp(is_realized->str, "false", 4)) { - g_string_free(is_realized, true); - qobject_unref(obj); - QTAILQ_REMOVE(&virtio_list, vdev, next); - return NULL; - } - g_string_free(is_realized, true); - } else { - /* virtio device doesn't exist in QOM tree */ - QTAILQ_REMOVE(&virtio_list, vdev, next); - qobject_unref(obj); - return NULL; - } - /* device exists in QOM tree & is realized */ - qobject_unref(obj); - return vdev; - } - return NULL; -} - -VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp) -{ - VirtIODevice *vdev; - VirtioStatus *status; - - vdev =3D qmp_find_virtio_device(path); - if (vdev =3D=3D NULL) { - error_setg(errp, "Path %s is not a VirtIODevice", path); - return NULL; - } - - status =3D g_new0(VirtioStatus, 1); - status->name =3D g_strdup(vdev->name); - status->device_id =3D vdev->device_id; - status->vhost_started =3D vdev->vhost_started; - status->guest_features =3D qmp_decode_features(vdev->device_id, - vdev->guest_features); - status->host_features =3D qmp_decode_features(vdev->device_id, - vdev->host_features); - status->backend_features =3D qmp_decode_features(vdev->device_id, - vdev->backend_features); - - switch (vdev->device_endian) { - case VIRTIO_DEVICE_ENDIAN_LITTLE: - status->device_endian =3D g_strdup("little"); - break; - case VIRTIO_DEVICE_ENDIAN_BIG: - status->device_endian =3D g_strdup("big"); - break; - default: - status->device_endian =3D g_strdup("unknown"); - break; - } - - status->num_vqs =3D virtio_get_num_queues(vdev); - status->status =3D qmp_decode_status(vdev->status); - status->isr =3D vdev->isr; - status->queue_sel =3D vdev->queue_sel; - status->vm_running =3D vdev->vm_running; - status->broken =3D vdev->broken; - status->disabled =3D vdev->disabled; - status->use_started =3D vdev->use_started; - status->started =3D vdev->started; - status->start_on_kick =3D vdev->start_on_kick; - status->disable_legacy_check =3D vdev->disable_legacy_check; - status->bus_name =3D g_strdup(vdev->bus_name); - status->use_guest_notifier_mask =3D vdev->use_guest_notifier_mask; - - if (vdev->vhost_started) { - VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - struct vhost_dev *hdev =3D vdc->get_vhost(vdev); - - status->vhost_dev =3D g_new0(VhostStatus, 1); - status->vhost_dev->n_mem_sections =3D hdev->n_mem_sections; - status->vhost_dev->n_tmp_sections =3D hdev->n_tmp_sections; - status->vhost_dev->nvqs =3D hdev->nvqs; - status->vhost_dev->vq_index =3D hdev->vq_index; - status->vhost_dev->features =3D - qmp_decode_features(vdev->device_id, hdev->features); - status->vhost_dev->acked_features =3D - qmp_decode_features(vdev->device_id, hdev->acked_features); - status->vhost_dev->backend_features =3D - qmp_decode_features(vdev->device_id, hdev->backend_features); - status->vhost_dev->protocol_features =3D - qmp_decode_protocols(hdev->protocol_features); - status->vhost_dev->max_queues =3D hdev->max_queues; - status->vhost_dev->backend_cap =3D hdev->backend_cap; - status->vhost_dev->log_enabled =3D hdev->log_enabled; - status->vhost_dev->log_size =3D hdev->log_size; - } - - return status; -} - -VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *pa= th, - uint16_t queue, - Error **errp) -{ - VirtIODevice *vdev; - VirtVhostQueueStatus *status; - - vdev =3D qmp_find_virtio_device(path); - if (vdev =3D=3D NULL) { - error_setg(errp, "Path %s is not a VirtIODevice", path); - return NULL; - } - - if (!vdev->vhost_started) { - error_setg(errp, "Error: vhost device has not started yet"); - return NULL; - } - - VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - struct vhost_dev *hdev =3D vdc->get_vhost(vdev); - - if (queue < hdev->vq_index || queue >=3D hdev->vq_index + hdev->nvqs) { - error_setg(errp, "Invalid vhost virtqueue number %d", queue); - return NULL; - } - - status =3D g_new0(VirtVhostQueueStatus, 1); - status->name =3D g_strdup(vdev->name); - status->kick =3D hdev->vqs[queue].kick; - status->call =3D hdev->vqs[queue].call; - status->desc =3D (uintptr_t)hdev->vqs[queue].desc; - status->avail =3D (uintptr_t)hdev->vqs[queue].avail; - status->used =3D (uintptr_t)hdev->vqs[queue].used; - status->num =3D hdev->vqs[queue].num; - status->desc_phys =3D hdev->vqs[queue].desc_phys; - status->desc_size =3D hdev->vqs[queue].desc_size; - status->avail_phys =3D hdev->vqs[queue].avail_phys; - status->avail_size =3D hdev->vqs[queue].avail_size; - status->used_phys =3D hdev->vqs[queue].used_phys; - status->used_size =3D hdev->vqs[queue].used_size; - - return status; -} - VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path, uint16_t queue, Error **errp) --=20 2.38.1