From nobody Tue Nov 18 22:50:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613545908; cv=none; d=zohomail.com; s=zohoarc; b=h82+SNDJqFMU+lGFidwXs97Ms23Qa5ciWJHXQ0pRYqvlBPBgqVVt+CdaUaP+OPzEXjcKfkVB4DuZV7HWUD/NZTyIZXhCeXQoQbgTZuh5MgcmxFXvhrIVCCjH9FmPMXgg2PPorE9xkLZkQmbjNN+qP0UdFNpCsGUQptuTl17xfSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613545908; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZSUdrBRPPPxVgZzDnP5hw4/zEg9sFLZ0KUMcgAkdJVo=; b=fZAs8FpIr/PUGDyMlFnqM1CIfmys6t0PvVIw7DplDAS+i4e3JLUrPLheJ6CMj+49+DsNXNngRksAQjavE//DHLhQxbvDpHZFcFEorAZcjey0RxDvQt9vS+rS87SdHi0QcGWTf2ksmV7qJIDwDfPFhwiLXVhiqHZiUjezHjUt5LM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613545908545687.9359791354948; Tue, 16 Feb 2021 23:11:48 -0800 (PST) Received: from localhost ([::1]:49854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lCGzy-00071L-Ls for importer@patchew.org; Wed, 17 Feb 2021 02:11:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCGyK-0006SU-MC for qemu-devel@nongnu.org; Wed, 17 Feb 2021 02:10:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lCGyE-0003h3-J2 for qemu-devel@nongnu.org; Wed, 17 Feb 2021 02:10:03 -0500 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-162-pNsuhB8ONXKCuKRz4RPQNA-1; Wed, 17 Feb 2021 02:09:53 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39B84100A623; Wed, 17 Feb 2021 07:09:52 +0000 (UTC) Received: from localhost (unknown [10.36.110.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id B110E10023B2; Wed, 17 Feb 2021 07:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613545796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZSUdrBRPPPxVgZzDnP5hw4/zEg9sFLZ0KUMcgAkdJVo=; b=Oz3y041jtCxtRcu3jnErf9/fFBAowtZw0+6qsl+ZWgo/b/8nYKH0HBuOYeBoarCL3V+6Jb VWsNzXGL8zhoEx5Lo2s0gaGgUQnxe3C46G1eSUnxxDnZ+KeoBn2fqqmSROG1O0gTdqjHfc DFkqZsPRgqwfKq+7BiiVNB32Li7FEvM= X-MC-Unique: pNsuhB8ONXKCuKRz4RPQNA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v2] qga: return a more explicit error on why a command is disabled Date: Wed, 17 Feb 2021 11:09:44 +0400 Message-Id: <20210217070944.2371327-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: michael.roth@amd.com, pkrempa@redhat.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau qmp_disable_command() now takes an enum for the reason, to be able to give more explicit error messages. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1928806 Signed-off-by: Marc-Andr=C3=A9 Lureau --- v2: - replace string with an enum for disabling reason - remove trailing dot include/qapi/qmp/dispatch.h | 12 ++++++++++-- monitor/qmp-cmds-control.c | 2 +- qapi/qmp-dispatch.c | 10 +++++++++- qapi/qmp-registry.c | 16 +++++++++------- qga/main.c | 4 ++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 1486cac3ef..fda9ffad73 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -28,6 +28,13 @@ typedef enum QmpCommandOptions QCO_COROUTINE =3D (1U << 3), } QmpCommandOptions; =20 +typedef enum QmpDisabled +{ + QMP_DISABLED_NONE, + QMP_DISABLED_GENERIC, + QMP_DISABLED_FROZEN, +} QmpDisabled; + typedef struct QmpCommand { const char *name; @@ -35,7 +42,7 @@ typedef struct QmpCommand QmpCommandFunc *fn; QmpCommandOptions options; QTAILQ_ENTRY(QmpCommand) node; - bool enabled; + QmpDisabled disabled; } QmpCommand; =20 typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList; @@ -44,7 +51,8 @@ void qmp_register_command(QmpCommandList *cmds, const cha= r *name, QmpCommandFunc *fn, QmpCommandOptions options); const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name); -void qmp_disable_command(QmpCommandList *cmds, const char *name); +void qmp_disable_command(QmpCommandList *cmds, const char *name, + QmpDisabled disabled); void qmp_enable_command(QmpCommandList *cmds, const char *name); =20 bool qmp_command_is_enabled(const QmpCommand *cmd); diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index 509ae870bd..94a8e133b6 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -107,7 +107,7 @@ static void query_commands_cb(const QmpCommand *cmd, vo= id *opaque) CommandInfo *info; CommandInfoList **list =3D opaque; =20 - if (!cmd->enabled) { + if (!qmp_command_is_enabled(cmd)) { return; } =20 diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 0a2b20a4e4..b65f670152 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -155,11 +155,19 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObje= ct *request, "The command %s has not been found", command); goto out; } - if (!cmd->enabled) { + switch (cmd->disabled) { + case QMP_DISABLED_FROZEN: + error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, + "The command %s has been disabled after fsfreeze", + command); + goto out; + case QMP_DISABLED_GENERIC: error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance", command); goto out; + case QMP_DISABLED_NONE: + break; } if (oob && !(cmd->options & QCO_ALLOW_OOB)) { error_setg(&err, "The command %s does not support OOB", diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 58c65b5052..e39e3b449c 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -25,7 +25,7 @@ void qmp_register_command(QmpCommandList *cmds, const cha= r *name, =20 cmd->name =3D name; cmd->fn =3D fn; - cmd->enabled =3D true; + cmd->disabled =3D QMP_DISABLED_NONE; cmd->options =3D options; QTAILQ_INSERT_TAIL(cmds, cmd, node); } @@ -43,31 +43,33 @@ const QmpCommand *qmp_find_command(const QmpCommandList= *cmds, const char *name) } =20 static void qmp_toggle_command(QmpCommandList *cmds, const char *name, - bool enabled) + QmpDisabled disabled) { QmpCommand *cmd; =20 QTAILQ_FOREACH(cmd, cmds, node) { if (strcmp(cmd->name, name) =3D=3D 0) { - cmd->enabled =3D enabled; + cmd->disabled =3D disabled; return; } } } =20 -void qmp_disable_command(QmpCommandList *cmds, const char *name) +void qmp_disable_command(QmpCommandList *cmds, const char *name, + QmpDisabled disabled) { - qmp_toggle_command(cmds, name, false); + assert(disabled !=3D QMP_DISABLED_NONE); + qmp_toggle_command(cmds, name, disabled); } =20 void qmp_enable_command(QmpCommandList *cmds, const char *name) { - qmp_toggle_command(cmds, name, true); + qmp_toggle_command(cmds, name, QMP_DISABLED_NONE); } =20 bool qmp_command_is_enabled(const QmpCommand *cmd) { - return cmd->enabled; + return cmd->disabled !=3D QMP_DISABLED_NONE; } =20 const char *qmp_command_name(const QmpCommand *cmd) diff --git a/qga/main.c b/qga/main.c index e7f8f3b161..0dbf0cacd2 100644 --- a/qga/main.c +++ b/qga/main.c @@ -375,7 +375,7 @@ static void ga_disable_non_whitelisted(const QmpCommand= *cmd, void *opaque) } if (!whitelisted) { g_debug("disabling command: %s", name); - qmp_disable_command(&ga_commands, name); + qmp_disable_command(&ga_commands, name, QMP_DISABLED_FROZEN); } } =20 @@ -1329,7 +1329,7 @@ static GAState *initialize_agent(GAConfig *config, in= t socket_activation) s->blacklist =3D config->blacklist; do { g_debug("disabling command: %s", (char *)l->data); - qmp_disable_command(&ga_commands, l->data); + qmp_disable_command(&ga_commands, l->data, QMP_DISABLED_GENERI= C); l =3D g_list_next(l); } while (l); } --=20 2.29.0