From patchwork Fri Jan 10 09:35:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13934107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1623E7719E for ; Fri, 10 Jan 2025 09:37:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWBQo-0007L4-6k; Fri, 10 Jan 2025 04:35:54 -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 1tWBQm-0007KW-Jq for qemu-devel@nongnu.org; Fri, 10 Jan 2025 04:35:52 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWBQk-000182-UM for qemu-devel@nongnu.org; Fri, 10 Jan 2025 04:35:52 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aa679ad4265so543658966b.0 for ; Fri, 10 Jan 2025 01:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1736501749; x=1737106549; darn=nongnu.org; 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=heAlNNCsF7d+p9roHrTGYRStQWTNbLe8js38yKlHKDA=; b=fYx3luO5HkedtxBS0UOk38igmMoAHUMxuixOmCLWubQf07d7ooWkVfmBGwjcjchnVz 2/OuzmmXFPoja5Q0turv2Ebm3zbwJ6i2c/By/pmQ+QfXl0utXcpcdS4l0NVwnwtpawKG 2N+E9eAsuXzRI6qiQbIsdgz1hJTsfValVLm4M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736501749; x=1737106549; 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=heAlNNCsF7d+p9roHrTGYRStQWTNbLe8js38yKlHKDA=; b=IbU+FASgBL5xhEkwAR62+1yad+n/Tv7hhOPC9rHpQc4j5A97sgRD9a9eSbZ/RooR8/ UIqDlcDKm642mP/P/cIWgCv6i/XH1vg5oJOIxrVdLkqXL9S9Cnzo+rNFOqxDCpYpo5ng zK/aXsFg9wYcECLLNzx36C+3ASpZ4MnIDjOfufEjrzFudhuESXG+SIFACbHz/wcbVN9t RgiWXVZQ/RdCAPZGFuUdliwv7+3CbH32QcjJEklQ4v1jGrnAh72EbComgChUmW7miJca IBGMJgoEVyO5kSq1PUKc8Ahl4wf4A74L4lkI3VaJOsD3U9I57wSm+pPZvOMBo7mKGI+l EzxA== X-Gm-Message-State: AOJu0YyC0P4iQHOx7s9Fxlepg+F4hn6OEY4ZZBHE6eD4dfoYigZkfw/w tu0Ysk/GbxnBlumY0hrTGZ1VCoaq6oFvQcy5BxRM3N9Y6EgkmDW98n/rLBbcCggHfZpDMbvAR0q 7 X-Gm-Gg: ASbGnct6BangnkQCVhScUCL2qpMXGPnOpLa7evZS1P+aKxgVrS5oo/gaVpgjyrpilkG 6DNhuqkWh1YSHn9IF/nly8/WA/DsLiVBoipH8x4ZzQC9a/wBxld968+JP3gY5PMsjRaA9Q50pQx h90uPeNc8NjX0VmGdCF9Neyf2H51U3eLwJkRi/jPPLACVqLQAWch0S2C/niZPS2ZgvdaiU0+Q11 LhLYMMkWxukOMyjshxlanbBRggBJdmBE8V7iaKiS83mzjpObzZKqqZbxgdW1P9LvwM= X-Google-Smtp-Source: AGHT+IF9I+Bn1k3Y/QmCjZal+54tLnhYTkVBay0iOh00OvkCwpx1fGD8280XTGNWMnzZIdz6+zIOPQ== X-Received: by 2002:a17:907:7282:b0:a9a:6c41:50a8 with SMTP id a640c23a62f3a-ab2c3c79cf5mr496036166b.17.1736501749069; Fri, 10 Jan 2025 01:35:49 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c9562519sm149700166b.132.2025.01.10.01.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 01:35:48 -0800 (PST) From: Roger Pau Monne To: qemu-devel@nongnu.org Cc: David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Anthony PERARD , Paul Durrant , "Edgar E. Iglesias" , xen-devel@lists.xenproject.org Subject: [PATCH v2 1/2] hw/xen: Add xs_node_read() helper function Date: Fri, 10 Jan 2025 10:35:30 +0100 Message-ID: <20250110093531.23221-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250110093531.23221-1-roger.pau@citrix.com> References: <20250110093531.23221-1-roger.pau@citrix.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=roger.pau@cloud.com; helo=mail-ej1-x62a.google.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.436, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: David Woodhouse This returns the full contents of the node, having created the node path from the printf-style format string provided in its arguments. This will save various callers from having to do so for themselves (and from using xs_node_scanf() with the non-portable %ms format string. Signed-off-by: David Woodhouse [remove double newline and constify trace parameters] Signed-off-by: Roger Pau Monné --- Cc: Stefano Stabellini Cc: Anthony PERARD Cc: Paul Durrant Cc: "Edgar E. Iglesias" Cc: xen-devel@lists.xenproject.org --- hw/xen/trace-events | 1 + hw/xen/xen-bus-helper.c | 22 ++++++++++++++++++++++ include/hw/xen/xen-bus-helper.h | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/hw/xen/trace-events b/hw/xen/trace-events index a07fe41c6d3b..461dee7b239f 100644 --- a/hw/xen/trace-events +++ b/hw/xen/trace-events @@ -39,6 +39,7 @@ xs_node_create(const char *node) "%s" xs_node_destroy(const char *node) "%s" xs_node_vprintf(char *path, char *value) "%s %s" xs_node_vscanf(char *path, char *value) "%s %s" +xs_node_read(const char *path, const char *value) "%s %s" xs_node_watch(char *path) "%s" xs_node_unwatch(char *path) "%s" diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c index b2b2cc9c5d5e..0fba7946c55e 100644 --- a/hw/xen/xen-bus-helper.c +++ b/hw/xen/xen-bus-helper.c @@ -142,6 +142,28 @@ int xs_node_scanf(struct qemu_xs_handle *h, xs_transaction_t tid, return rc; } +char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid, + unsigned int *len, Error **errp, + const char *node_fmt, ...) +{ + char *path, *value; + va_list ap; + + va_start(ap, node_fmt); + path = g_strdup_vprintf(node_fmt, ap); + va_end(ap); + + value = qemu_xen_xs_read(h, tid, path, len); + trace_xs_node_read(path, value); + if (!value) { + error_setg_errno(errp, errno, "failed to read from '%s'", path); + } + + g_free(path); + + return value; +} + struct qemu_xs_watch *xs_node_watch(struct qemu_xs_handle *h, const char *node, const char *key, xs_watch_fn fn, void *opaque, Error **errp) diff --git a/include/hw/xen/xen-bus-helper.h b/include/hw/xen/xen-bus-helper.h index d8dcc2f0107d..6478d25be5e6 100644 --- a/include/hw/xen/xen-bus-helper.h +++ b/include/hw/xen/xen-bus-helper.h @@ -37,6 +37,10 @@ int xs_node_scanf(struct qemu_xs_handle *h, xs_transaction_t tid, const char *node, const char *key, Error **errp, const char *fmt, ...) G_GNUC_SCANF(6, 7); +char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid, + unsigned int *len, Error **errp, + const char *node_fmt, ...) + G_GNUC_PRINTF(5, 6); /* Watch node/key unless node is empty, in which case watch key */ struct qemu_xs_watch *xs_node_watch(struct qemu_xs_handle *h, const char *node, From patchwork Fri Jan 10 09:35:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13934108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54814E7719D for ; Fri, 10 Jan 2025 09:37:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWBQq-0007Lm-7B; Fri, 10 Jan 2025 04:35:56 -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 1tWBQo-0007L9-FB for qemu-devel@nongnu.org; Fri, 10 Jan 2025 04:35:54 -0500 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWBQm-00018G-OB for qemu-devel@nongnu.org; Fri, 10 Jan 2025 04:35:54 -0500 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5d9882a936eso3308070a12.3 for ; Fri, 10 Jan 2025 01:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1736501751; x=1737106551; darn=nongnu.org; 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=Fl8lgxmL+/V36LVrcdeJiI3S1Q/yOAFdboy4Zc6RdL0=; b=VHdekNdcMd76t64MaVNV4qBk5uOaxoR6EkRJH+F3+DE0ezWKGz0L34ErhgcKT1b0y8 vzb3exFJ8ud8fA+fvNe0kO5J4SIYVudKmVODKHzzQZHhgz49CxURZq0Iavo6sPgh6AEu vZ9A3NWOFoncWC6ggt+O5OcuBcWXCY/WT8oYQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736501751; x=1737106551; 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=Fl8lgxmL+/V36LVrcdeJiI3S1Q/yOAFdboy4Zc6RdL0=; b=Rs6KFDX0HMTWcHMMzrv8O0qZE/1xVB6wO20cylNN7/ilXYpVcwpcGkSIgjzwNuSNs4 InxMizfXuxvg33TwnJkJna0ft2RgIXIt8P6bA8AyofgtB7wrfFMwmBL4Zp3dKlzbpEmP hqJ5AbQi8z+fCvIZIMjbbIUbpT9wovgk8e71QvVPcVWSqafdg509gbjDF/FKWqQBK1II ceKfmQ/BmgP8yk0QBRb7ix/t1ZyJMNHeXXef0qpQmTq0B4iuvKpFgB+hcviWKquKrCz3 hxKTD7zZbBhzZWjA2/C9hKrGVRUVRWkC9CC62V6kiR5NNlzuaY6UBmfyBJfismhhgq/t wqhQ== X-Gm-Message-State: AOJu0Yz9noWGcTcUR2jyeMdUAwyyWb7GoOjlsnLvhxgHqIW9Uvt1XJOE 4e8efetqNNO+eVqxJWdmnNZiG147zh/zpu+jYzQM9UN9F87meRHX9a6AMn0IZoK/nPSaNYggVoG J X-Gm-Gg: ASbGncur/ovG22zpicppiihfeavZWFTDXe/+nXzsT+XUaEVeSCP75lBrfXbdY+F/eY2 qENBvskA4bMmQt/Z5SwJuG3llLz30UyDY9yAm9Ds2sBWBFimULu+f1MVE2LV1yamBg2o/VmBcT2 XRkmPDQQHK9bXVJP/dXWKWW53fobWZvRHCVxzTQK4XqEGvviW1DwBDWtNli5gUsYSvNDuymKan7 5iqoDlXPIoNOwr/9TszrPlM+3a5P61AZ0yryNVqm2WhEoxUIxX3yUDbsnToQlvgPmk= X-Google-Smtp-Source: AGHT+IEo9mpyvl6MxMhMK3vDEIeyTCqPvEtk3ZTUCN5P4v3M5pMXiIevI2rskGgecot8tg5zTq3PXg== X-Received: by 2002:a05:6402:50c6:b0:5d3:cfd0:8d3f with SMTP id 4fb4d7f45d1cf-5d972e4cc1amr9661346a12.24.1736501750881; Fri, 10 Jan 2025 01:35:50 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1406017a12.35.2025.01.10.01.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 01:35:50 -0800 (PST) From: Roger Pau Monne To: qemu-devel@nongnu.org Cc: Roger Pau Monne , Stefano Stabellini , Anthony PERARD , Paul Durrant , "Edgar E. Iglesias" , Kevin Wolf , Hanna Reitz , =?utf-8?q?M?= =?utf-8?q?arc-Andr=C3=A9_Lureau?= , Paolo Bonzini , xen-devel@lists.xenproject.org, qemu-block@nongnu.org Subject: [PATCH v2 2/2] xen: do not use '%ms' scanf specifier Date: Fri, 10 Jan 2025 10:35:31 +0100 Message-ID: <20250110093531.23221-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250110093531.23221-1-roger.pau@citrix.com> References: <20250110093531.23221-1-roger.pau@citrix.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=roger.pau@cloud.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.436, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The 'm' parameter used to request auto-allocation of the destination variable is not supported on FreeBSD, and as such leads to failures to parse. What's more, the current usage of '%ms' with xs_node_scanf() is pointless, as it just leads to a double allocation of the same string. Instead use xs_node_read() to read the whole xenstore node. Fixes: a783f8ad4ec9 ('xen: add a mechanism to automatically create XenDevice-s...') Fixes: 9b7737469080 ('hw/xen: update Xen console to XenDevice model') Signed-off-by: Roger Pau Monné Reviewed-by: David Woodhouse --- Changes since v2: - New version of xs_node_read(). - Fix usage of %ms in xen-block.c Changes since v1: - Introduce xs_node_read() helper. - Merge with errp fixes. --- Cc: Stefano Stabellini Cc: Anthony PERARD Cc: Paul Durrant Cc: "Edgar E. Iglesias" Cc: Kevin Wolf Cc: Hanna Reitz Cc: "Marc-André Lureau" Cc: Paolo Bonzini Cc: xen-devel@lists.xenproject.org Cc: qemu-block@nongnu.org --- hw/block/xen-block.c | 3 ++- hw/char/xen_console.c | 6 ++++-- hw/xen/xen-bus.c | 14 ++++++++++++-- include/hw/xen/xen-bus.h | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 306d38927cf4..034a18b70e28 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -239,7 +239,8 @@ static void xen_block_connect(XenDevice *xendev, Error **errp) return; } - if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) != 1) { + str = xen_device_frontend_read(xendev, "protocol"); + if (!str) { /* x86 defaults to the 32-bit protocol even for 64-bit guests. */ if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) { protocol = BLKIF_PROTOCOL_X86_32; diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index ef0c2912efa1..989e75fef88f 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -550,7 +550,8 @@ static void xen_console_device_create(XenBackendInstance *backend, goto fail; } - if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) { + type = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "type"); + if (!type) { error_prepend(errp, "failed to read console device type: "); goto fail; } @@ -568,7 +569,8 @@ static void xen_console_device_create(XenBackendInstance *backend, snprintf(label, sizeof(label), "xencons%ld", number); - if (xs_node_scanf(xsh, XBT_NULL, fe, "output", NULL, "%ms", &output) == 1) { + output = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "output"); + if (output) { /* * FIXME: sure we want to support implicit * muxed monitors here? diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index adfc4efad035..85b92cded4e2 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -156,8 +156,8 @@ again: !strcmp(key[i], "hotplug-status")) continue; - if (xs_node_scanf(xenbus->xsh, tid, path, key[i], NULL, "%ms", - &val) == 1) { + val = xs_node_read(xenbus->xsh, tid, NULL, NULL, "%s/%s", path, key[i]); + if (val) { qdict_put_str(opts, key[i], val); free(val); } @@ -650,6 +650,16 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key, return rc; } +char *xen_device_frontend_read(XenDevice *xendev, const char *key) +{ + XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + + g_assert(xenbus->xsh); + + return xs_node_read(xenbus->xsh, XBT_NULL, NULL, NULL, "%s/%s", + xendev->frontend_path, key);; +} + static void xen_device_frontend_set_state(XenDevice *xendev, enum xenbus_state state, bool publish) diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index 38d40afa3798..2adb2af83919 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -91,6 +91,7 @@ void xen_device_frontend_printf(XenDevice *xendev, const char *key, int xen_device_frontend_scanf(XenDevice *xendev, const char *key, const char *fmt, ...) G_GNUC_SCANF(3, 4); +char *xen_device_frontend_read(XenDevice *xendev, const char *key); void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs, Error **errp);