From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790789; cv=none; d=zohomail.com; s=zohoarc; b=Wk5zlAKeYLo4/V5PpYyccMBswsDGwPMVrwqpZInxvkZBA5pEKpI5JXSSkzH2np6x2xI+wfJ9mYmq6tDkh069d8fDtFt16K8baBpFBQdxf2rZ835+dCJ/FHoxp7tJuupb3d0GXeK47R29uLsR6ENAapGVq1TjaPYqRzYaVweDczU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790789; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v8nD6iuCbHPgF9mhe63uSEXaCcXMYEjvJ4HdJ2BdZQ0=; b=KJpn+oTXwA2ncWbqQub7dsS1VOHBC2NzKtyg6lxwhE4ms5FIxRkCCl+VH4DOp+2nVvz1kM18gwGliDPk16s3LcJjcKXDLcxDusSJXCHhxcpHwaNK7mKcTpJkBvlndriLwV6gmdsDLPFsFu+G/nsvSpk9UME6HdkwWK++W6B3ThI= 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+importer2=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 1720790789781313.4955090055895; Fri, 12 Jul 2024 06:26:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGH3-0001fk-2z; Fri, 12 Jul 2024 09:25:21 -0400 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 1sSGH0-0001aB-Vr for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGGu-0003j6-Ol for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:18 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-y_Kd6Ll1PH6g_IfVsnjw3w-1; Fri, 12 Jul 2024 09:25:10 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4E331955F45; Fri, 12 Jul 2024 13:25:08 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 638281955E70; Fri, 12 Jul 2024 13:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790711; 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: in-reply-to:in-reply-to:references:references; bh=v8nD6iuCbHPgF9mhe63uSEXaCcXMYEjvJ4HdJ2BdZQ0=; b=UdVWDgSa2Yincm77cIybAgtf7hgl3YWs6xPuL9G2wcM9g8ZLUEzFWsPNMOGo0D2FgabJTn Yd4GK11Fgvtc2KQe7CxzAOkxlRVvgq8ridElzOHWwU+8SB22rEyAKHKtHhOPW7dK4H/gS/ Nunon8+AXHcImOHDqjQeUCKNno0iurk= X-MC-Unique: y_Kd6Ll1PH6g_IfVsnjw3w-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk , Manos Pitsidianakis Subject: [PATCH v3 01/22] qga: drop blocking of guest-get-memory-block-size command Date: Fri, 12 Jul 2024 14:24:38 +0100 Message-ID: <20240712132459.3974109-2-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790791928116300 This command has never existed in tree, since it was renamed to guest-get-memory-block-info before being merged. Reviewed-by: Manos Pitsidianakis Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 2 +- qga/commands-win32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 7f05996495..76af98ba32 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -3099,7 +3099,7 @@ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) "guest-suspend-disk", "guest-suspend-ram", "guest-suspend-hybrid", "guest-get-vcpus", "guest-set-vcpus", "guest-get-memory-blocks", "guest-set-memory-blocks", - "guest-get-memory-block-size", "guest-get-memory-block-info", + "guest-get-memory-block-info", NULL}; char **p =3D (char **)list; =20 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0d1b836e87..9fe670d5b4 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1995,7 +1995,7 @@ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) "guest-suspend-hybrid", "guest-set-vcpus", "guest-get-memory-blocks", "guest-set-memory-blocks", - "guest-get-memory-block-size", "guest-get-memory-block-info", + "guest-get-memory-block-info", NULL}; char **p =3D (char **)list_unsupported; =20 --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790856; cv=none; d=zohomail.com; s=zohoarc; b=iPJ6GWH40o7OymcO2HWJ2En+TfaJw0RljMVQqJ8sPgIuaG4S4kc7kQAfie+nfBeNeU6W3yExC6ZTiOLIdqHuVYApYovjamTehT/eMam7+14Lhmrpk+endA/vlQLdfkCvQBa+DJGjmYC0NzeNgsR19v/BdSy/0YN3U/GBsaoLaiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790856; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bm+4Y0UqiYKTV3dL0JZau+MxMlAJOiinhP/mxPTRVDI=; b=MYgJi+aB8NyI0OiY9K3TFlXOM6gcFAhagGSH5TgNX4S/d/q6sprfKDjpTUf7PPiDBY+y5IJ7Boa3vmqEQkjzmCKiNAshxdRLk0+pxbhUFjoa4kiUr3r4hqiG0NIhUbkm0gkblfbe2UlW73HXkOkI933W46W2rnyWCN3Y1yR9L10= 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+importer2=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 1720790856192682.9056051002498; Fri, 12 Jul 2024 06:27:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGHE-0002QT-VM; Fri, 12 Jul 2024 09:25:34 -0400 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 1sSGH3-0001jz-IT for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGH0-0003jv-Ap for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:21 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-UFa_Ks7QPSO92Sz0HM25rQ-1; Fri, 12 Jul 2024 09:25:13 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6725B1958B15; Fri, 12 Jul 2024 13:25:12 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 28BA61955F40; Fri, 12 Jul 2024 13:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790716; 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: in-reply-to:in-reply-to:references:references; bh=Bm+4Y0UqiYKTV3dL0JZau+MxMlAJOiinhP/mxPTRVDI=; b=RRdPNJOslZWu/Ie7UeZURjO0yoD/x8xaFLVntvaposdfQABgLZZiq48YUzwM2UKADwHskt Fq43apzx50sK73shH0SoWcVU323j/oS2q9ptSVtZ9ZUB0POBZQ5hFT4nvl4AZ2tmr22wHK P2ro5Pu8uYDw9gitzu5NGhLip3VrZNI= X-MC-Unique: UFa_Ks7QPSO92Sz0HM25rQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk , Manos Pitsidianakis Subject: [PATCH v3 02/22] qga: move linux vcpu command impls to commands-linux.c Date: Fri, 12 Jul 2024 14:24:39 +0100 Message-ID: <20240712132459.3974109-3-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790858284116300 The qmp_guest_set_vcpus and qmp_guest_get_vcpus command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 141 +++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 139 ------------------------------------------ 2 files changed, 141 insertions(+), 139 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 214e408fcd..78580ac39d 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qga-qapi-commands.h" #include "commands-common.h" #include "cutils.h" #include @@ -284,3 +285,143 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) return i; } #endif /* CONFIG_FSFREEZE */ + +/* Transfer online/offline status between @vcpu and the guest system. + * + * On input either @errp or *@errp must be NULL. + * + * In system-to-@vcpu direction, the following @vcpu fields are accessed: + * - R: vcpu->logical_id + * - W: vcpu->online + * - W: vcpu->can_offline + * + * In @vcpu-to-system direction, the following @vcpu fields are accessed: + * - R: vcpu->logical_id + * - R: vcpu->online + * + * Written members remain unmodified on error. + */ +static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, + char *dirpath, Error **errp) +{ + int fd; + int res; + int dirfd; + static const char fn[] =3D "online"; + + dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); + if (dirfd =3D=3D -1) { + error_setg_errno(errp, errno, "open(\"%s\")", dirpath); + return; + } + + fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); + if (fd =3D=3D -1) { + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); + } else if (sys2vcpu) { + vcpu->online =3D true; + vcpu->can_offline =3D false; + } else if (!vcpu->online) { + error_setg(errp, "logical processor #%" PRId64 " can't be " + "offlined", vcpu->logical_id); + } /* otherwise pretend successful re-onlining */ + } else { + unsigned char status; + + res =3D pread(fd, &status, 1, 0); + if (res =3D=3D -1) { + error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); + } else if (res =3D=3D 0) { + error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, + fn); + } else if (sys2vcpu) { + vcpu->online =3D (status !=3D '0'); + vcpu->can_offline =3D true; + } else if (vcpu->online !=3D (status !=3D '0')) { + status =3D '0' + vcpu->online; + if (pwrite(fd, &status, 1, 0) =3D=3D -1) { + error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, + fn); + } + } /* otherwise pretend successful re-(on|off)-lining */ + + res =3D close(fd); + g_assert(res =3D=3D 0); + } + + res =3D close(dirfd); + g_assert(res =3D=3D 0); +} + +GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) +{ + GuestLogicalProcessorList *head, **tail; + const char *cpu_dir =3D "/sys/devices/system/cpu"; + const gchar *line; + g_autoptr(GDir) cpu_gdir =3D NULL; + Error *local_err =3D NULL; + + head =3D NULL; + tail =3D &head; + cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL); + + if (cpu_gdir =3D=3D NULL) { + error_setg_errno(errp, errno, "failed to list entries: %s", cpu_di= r); + return NULL; + } + + while (local_err =3D=3D NULL && (line =3D g_dir_read_name(cpu_gdir)) != =3D NULL) { + GuestLogicalProcessor *vcpu; + int64_t id; + if (sscanf(line, "cpu%" PRId64, &id)) { + g_autofree char *path =3D g_strdup_printf("/sys/devices/system= /cpu/" + "cpu%" PRId64 "/", id); + vcpu =3D g_malloc0(sizeof *vcpu); + vcpu->logical_id =3D id; + vcpu->has_can_offline =3D true; /* lolspeak ftw */ + transfer_vcpu(vcpu, true, path, &local_err); + QAPI_LIST_APPEND(tail, vcpu); + } + } + + if (local_err =3D=3D NULL) { + /* there's no guest with zero VCPUs */ + g_assert(head !=3D NULL); + return head; + } + + qapi_free_GuestLogicalProcessorList(head); + error_propagate(errp, local_err); + return NULL; +} + +int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) +{ + int64_t processed; + Error *local_err =3D NULL; + + processed =3D 0; + while (vcpus !=3D NULL) { + char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", + vcpus->value->logical_id); + + transfer_vcpu(vcpus->value, false, path, &local_err); + g_free(path); + if (local_err !=3D NULL) { + break; + } + ++processed; + vcpus =3D vcpus->next; + } + + if (local_err !=3D NULL) { + if (processed =3D=3D 0) { + error_propagate(errp, local_err); + } else { + error_free(local_err); + } + } + + return processed; +} diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 76af98ba32..a8ef41f175 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2003,145 +2003,6 @@ void qmp_guest_suspend_hybrid(Error **errp) guest_suspend(SUSPEND_MODE_HYBRID, errp); } =20 -/* Transfer online/offline status between @vcpu and the guest system. - * - * On input either @errp or *@errp must be NULL. - * - * In system-to-@vcpu direction, the following @vcpu fields are accessed: - * - R: vcpu->logical_id - * - W: vcpu->online - * - W: vcpu->can_offline - * - * In @vcpu-to-system direction, the following @vcpu fields are accessed: - * - R: vcpu->logical_id - * - R: vcpu->online - * - * Written members remain unmodified on error. - */ -static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, - char *dirpath, Error **errp) -{ - int fd; - int res; - int dirfd; - static const char fn[] =3D "online"; - - dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); - if (dirfd =3D=3D -1) { - error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - return; - } - - fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); - if (fd =3D=3D -1) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); - } else if (sys2vcpu) { - vcpu->online =3D true; - vcpu->can_offline =3D false; - } else if (!vcpu->online) { - error_setg(errp, "logical processor #%" PRId64 " can't be " - "offlined", vcpu->logical_id); - } /* otherwise pretend successful re-onlining */ - } else { - unsigned char status; - - res =3D pread(fd, &status, 1, 0); - if (res =3D=3D -1) { - error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); - } else if (res =3D=3D 0) { - error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, - fn); - } else if (sys2vcpu) { - vcpu->online =3D (status !=3D '0'); - vcpu->can_offline =3D true; - } else if (vcpu->online !=3D (status !=3D '0')) { - status =3D '0' + vcpu->online; - if (pwrite(fd, &status, 1, 0) =3D=3D -1) { - error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, - fn); - } - } /* otherwise pretend successful re-(on|off)-lining */ - - res =3D close(fd); - g_assert(res =3D=3D 0); - } - - res =3D close(dirfd); - g_assert(res =3D=3D 0); -} - -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) -{ - GuestLogicalProcessorList *head, **tail; - const char *cpu_dir =3D "/sys/devices/system/cpu"; - const gchar *line; - g_autoptr(GDir) cpu_gdir =3D NULL; - Error *local_err =3D NULL; - - head =3D NULL; - tail =3D &head; - cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL); - - if (cpu_gdir =3D=3D NULL) { - error_setg_errno(errp, errno, "failed to list entries: %s", cpu_di= r); - return NULL; - } - - while (local_err =3D=3D NULL && (line =3D g_dir_read_name(cpu_gdir)) != =3D NULL) { - GuestLogicalProcessor *vcpu; - int64_t id; - if (sscanf(line, "cpu%" PRId64, &id)) { - g_autofree char *path =3D g_strdup_printf("/sys/devices/system= /cpu/" - "cpu%" PRId64 "/", id); - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D id; - vcpu->has_can_offline =3D true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, path, &local_err); - QAPI_LIST_APPEND(tail, vcpu); - } - } - - if (local_err =3D=3D NULL) { - /* there's no guest with zero VCPUs */ - g_assert(head !=3D NULL); - return head; - } - - qapi_free_GuestLogicalProcessorList(head); - error_propagate(errp, local_err); - return NULL; -} - -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - int64_t processed; - Error *local_err =3D NULL; - - processed =3D 0; - while (vcpus !=3D NULL) { - char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", - vcpus->value->logical_id); - - transfer_vcpu(vcpus->value, false, path, &local_err); - g_free(path); - if (local_err !=3D NULL) { - break; - } - ++processed; - vcpus =3D vcpus->next; - } - - if (local_err !=3D NULL) { - if (processed =3D=3D 0) { - error_propagate(errp, local_err); - } else { - error_free(local_err); - } - } - - return processed; -} #endif /* __linux__ */ =20 #if defined(__linux__) || defined(__FreeBSD__) --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790763; cv=none; d=zohomail.com; s=zohoarc; b=jOY7CpezVi9CKpUHwar5f0j2wEJUi7FmyZW6Mc/p57ebGDLKvMBrKHeL+0je/6pLo7pqzAlwXsJpAZjamj4HEYCHXdX0QPGkTDqj7LTk0ywmotmISAY+plomov4TRGuW9ApJLjkwUtS3P96vxoLVoE2vNbfeKSjYGSn6gi+H0m8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790763; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oeI52+vdkaI59K6ejpX0UAFKYDK7QeGJvRxnrz/9WnI=; b=dECnP4GVRlHLcTCmY3BE4nTYCjJiGwk/5NE0B9TudrIXJXkWbMj7Fn7zy07xHtZ+Jo9xCXcXRX2oEAGuKFHXUXO2V8UxG0oNryP2vCOazhH3SidU/wIQMIwS3IgiOQL/RP/Rvs9Unhu+4T/VOokdl79RBpwpEmkU5QV5Etvl+eQ= 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+importer2=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 1720790763654788.2994622043938; Fri, 12 Jul 2024 06:26:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGHG-0002T7-EH; Fri, 12 Jul 2024 09:25:34 -0400 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 1sSGH6-0001vl-Qz for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGH4-0003kl-27 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:24 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-hgEFgaRTO3iV-wpK2LsI0A-1; Fri, 12 Jul 2024 09:25:17 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 054BF196CDEF; Fri, 12 Jul 2024 13:25:16 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8A751955E76; Fri, 12 Jul 2024 13:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790721; 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: in-reply-to:in-reply-to:references:references; bh=oeI52+vdkaI59K6ejpX0UAFKYDK7QeGJvRxnrz/9WnI=; b=iMNN2BGQ2Ru6nswn4EQMi9l6p1Y5DIrKZxyGB3fGjbckTttTCVYrc8rvu9NalDrvmezCV3 PZv+qDPWpdgkvYI5moVCgB7Ktftvm4PyncYWWzNFZZEJdrz+aFH145NAn5cuALdQqoJLBJ gryJsuJOQcApjqRxPjnZx73TGSrzt1U= X-MC-Unique: hgEFgaRTO3iV-wpK2LsI0A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk , Manos Pitsidianakis Subject: [PATCH v3 03/22] qga: move linux suspend command impls to commands-linux.c Date: Fri, 12 Jul 2024 14:24:40 +0100 Message-ID: <20240712132459.3974109-4-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790763871116300 The qmp_guest_suspend_{disk,ram,hybrid} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 265 +++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 265 ------------------------------------------- 2 files changed, 265 insertions(+), 265 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 78580ac39d..3fabf54882 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -286,6 +286,271 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) } #endif /* CONFIG_FSFREEZE */ =20 + +#define LINUX_SYS_STATE_FILE "/sys/power/state" +#define SUSPEND_SUPPORTED 0 +#define SUSPEND_NOT_SUPPORTED 1 + +typedef enum { + SUSPEND_MODE_DISK =3D 0, + SUSPEND_MODE_RAM =3D 1, + SUSPEND_MODE_HYBRID =3D 2, +} SuspendMode; + +/* + * Executes a command in a child process using g_spawn_sync, + * returning an int >=3D 0 representing the exit status of the + * process. + * + * If the program wasn't found in path, returns -1. + * + * If a problem happened when creating the child process, + * returns -1 and errp is set. + */ +static int run_process_child(const char *command[], Error **errp) +{ + int exit_status, spawn_flag; + GError *g_err =3D NULL; + bool success; + + spawn_flag =3D G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | + G_SPAWN_STDERR_TO_DEV_NULL; + + success =3D g_spawn_sync(NULL, (char **)command, NULL, spawn_flag, + NULL, NULL, NULL, NULL, + &exit_status, &g_err); + + if (success) { + return WEXITSTATUS(exit_status); + } + + if (g_err && (g_err->code !=3D G_SPAWN_ERROR_NOENT)) { + error_setg(errp, "failed to create child process, error '%s'", + g_err->message); + } + + g_error_free(g_err); + return -1; +} + +static bool systemd_supports_mode(SuspendMode mode, Error **errp) +{ + const char *systemctl_args[3] =3D {"systemd-hibernate", "systemd-suspe= nd", + "systemd-hybrid-sleep"}; + const char *cmd[4] =3D {"systemctl", "status", systemctl_args[mode], N= ULL}; + int status; + + status =3D run_process_child(cmd, errp); + + /* + * systemctl status uses LSB return codes so we can expect + * status > 0 and be ok. To assert if the guest has support + * for the selected suspend mode, status should be < 4. 4 is + * the code for unknown service status, the return value when + * the service does not exist. A common value is status =3D 3 + * (program is not running). + */ + if (status > 0 && status < 4) { + return true; + } + + return false; +} + +static void systemd_suspend(SuspendMode mode, Error **errp) +{ + Error *local_err =3D NULL; + const char *systemctl_args[3] =3D {"hibernate", "suspend", "hybrid-sle= ep"}; + const char *cmd[3] =3D {"systemctl", systemctl_args[mode], NULL}; + int status; + + status =3D run_process_child(cmd, &local_err); + + if (status =3D=3D 0) { + return; + } + + if ((status =3D=3D -1) && !local_err) { + error_setg(errp, "the helper program 'systemctl %s' was not found", + systemctl_args[mode]); + return; + } + + if (local_err) { + error_propagate(errp, local_err); + } else { + error_setg(errp, "the helper program 'systemctl %s' returned an " + "unexpected exit status code (%d)", + systemctl_args[mode], status); + } +} + +static bool pmutils_supports_mode(SuspendMode mode, Error **errp) +{ + Error *local_err =3D NULL; + const char *pmutils_args[3] =3D {"--hibernate", "--suspend", + "--suspend-hybrid"}; + const char *cmd[3] =3D {"pm-is-supported", pmutils_args[mode], NULL}; + int status; + + status =3D run_process_child(cmd, &local_err); + + if (status =3D=3D SUSPEND_SUPPORTED) { + return true; + } + + if ((status =3D=3D -1) && !local_err) { + return false; + } + + if (local_err) { + error_propagate(errp, local_err); + } else { + error_setg(errp, + "the helper program '%s' returned an unexpected exit" + " status code (%d)", "pm-is-supported", status); + } + + return false; +} + +static void pmutils_suspend(SuspendMode mode, Error **errp) +{ + Error *local_err =3D NULL; + const char *pmutils_binaries[3] =3D {"pm-hibernate", "pm-suspend", + "pm-suspend-hybrid"}; + const char *cmd[2] =3D {pmutils_binaries[mode], NULL}; + int status; + + status =3D run_process_child(cmd, &local_err); + + if (status =3D=3D 0) { + return; + } + + if ((status =3D=3D -1) && !local_err) { + error_setg(errp, "the helper program '%s' was not found", + pmutils_binaries[mode]); + return; + } + + if (local_err) { + error_propagate(errp, local_err); + } else { + error_setg(errp, + "the helper program '%s' returned an unexpected exit" + " status code (%d)", pmutils_binaries[mode], status); + } +} + +static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp) +{ + const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; + const char *sysfile_str =3D sysfile_strs[mode]; + char buf[32]; /* hopefully big enough */ + int fd; + ssize_t ret; + + if (!sysfile_str) { + error_setg(errp, "unknown guest suspend mode"); + return false; + } + + fd =3D open(LINUX_SYS_STATE_FILE, O_RDONLY); + if (fd < 0) { + return false; + } + + ret =3D read(fd, buf, sizeof(buf) - 1); + close(fd); + if (ret <=3D 0) { + return false; + } + buf[ret] =3D '\0'; + + if (strstr(buf, sysfile_str)) { + return true; + } + return false; +} + +static void linux_sys_state_suspend(SuspendMode mode, Error **errp) +{ + g_autoptr(GError) local_gerr =3D NULL; + const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; + const char *sysfile_str =3D sysfile_strs[mode]; + + if (!sysfile_str) { + error_setg(errp, "unknown guest suspend mode"); + return; + } + + if (!g_file_set_contents(LINUX_SYS_STATE_FILE, sysfile_str, + -1, &local_gerr)) { + error_setg(errp, "suspend: cannot write to '%s': %s", + LINUX_SYS_STATE_FILE, local_gerr->message); + return; + } +} + +static void guest_suspend(SuspendMode mode, Error **errp) +{ + Error *local_err =3D NULL; + bool mode_supported =3D false; + + if (systemd_supports_mode(mode, &local_err)) { + mode_supported =3D true; + systemd_suspend(mode, &local_err); + + if (!local_err) { + return; + } + } + + error_free(local_err); + local_err =3D NULL; + + if (pmutils_supports_mode(mode, &local_err)) { + mode_supported =3D true; + pmutils_suspend(mode, &local_err); + + if (!local_err) { + return; + } + } + + error_free(local_err); + local_err =3D NULL; + + if (linux_sys_state_supports_mode(mode, &local_err)) { + mode_supported =3D true; + linux_sys_state_suspend(mode, &local_err); + } + + if (!mode_supported) { + error_free(local_err); + error_setg(errp, + "the requested suspend mode is not supported by the gue= st"); + } else { + error_propagate(errp, local_err); + } +} + +void qmp_guest_suspend_disk(Error **errp) +{ + guest_suspend(SUSPEND_MODE_DISK, errp); +} + +void qmp_guest_suspend_ram(Error **errp) +{ + guest_suspend(SUSPEND_MODE_RAM, errp); +} + +void qmp_guest_suspend_hybrid(Error **errp) +{ + guest_suspend(SUSPEND_MODE_HYBRID, errp); +} + /* Transfer online/offline status between @vcpu and the guest system. * * On input either @errp or *@errp must be NULL. diff --git a/qga/commands-posix.c b/qga/commands-posix.c index a8ef41f175..ef21da63be 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1738,271 +1738,6 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,= Error **errp) } #endif /* CONFIG_FSTRIM */ =20 - -#define LINUX_SYS_STATE_FILE "/sys/power/state" -#define SUSPEND_SUPPORTED 0 -#define SUSPEND_NOT_SUPPORTED 1 - -typedef enum { - SUSPEND_MODE_DISK =3D 0, - SUSPEND_MODE_RAM =3D 1, - SUSPEND_MODE_HYBRID =3D 2, -} SuspendMode; - -/* - * Executes a command in a child process using g_spawn_sync, - * returning an int >=3D 0 representing the exit status of the - * process. - * - * If the program wasn't found in path, returns -1. - * - * If a problem happened when creating the child process, - * returns -1 and errp is set. - */ -static int run_process_child(const char *command[], Error **errp) -{ - int exit_status, spawn_flag; - GError *g_err =3D NULL; - bool success; - - spawn_flag =3D G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | - G_SPAWN_STDERR_TO_DEV_NULL; - - success =3D g_spawn_sync(NULL, (char **)command, NULL, spawn_flag, - NULL, NULL, NULL, NULL, - &exit_status, &g_err); - - if (success) { - return WEXITSTATUS(exit_status); - } - - if (g_err && (g_err->code !=3D G_SPAWN_ERROR_NOENT)) { - error_setg(errp, "failed to create child process, error '%s'", - g_err->message); - } - - g_error_free(g_err); - return -1; -} - -static bool systemd_supports_mode(SuspendMode mode, Error **errp) -{ - const char *systemctl_args[3] =3D {"systemd-hibernate", "systemd-suspe= nd", - "systemd-hybrid-sleep"}; - const char *cmd[4] =3D {"systemctl", "status", systemctl_args[mode], N= ULL}; - int status; - - status =3D run_process_child(cmd, errp); - - /* - * systemctl status uses LSB return codes so we can expect - * status > 0 and be ok. To assert if the guest has support - * for the selected suspend mode, status should be < 4. 4 is - * the code for unknown service status, the return value when - * the service does not exist. A common value is status =3D 3 - * (program is not running). - */ - if (status > 0 && status < 4) { - return true; - } - - return false; -} - -static void systemd_suspend(SuspendMode mode, Error **errp) -{ - Error *local_err =3D NULL; - const char *systemctl_args[3] =3D {"hibernate", "suspend", "hybrid-sle= ep"}; - const char *cmd[3] =3D {"systemctl", systemctl_args[mode], NULL}; - int status; - - status =3D run_process_child(cmd, &local_err); - - if (status =3D=3D 0) { - return; - } - - if ((status =3D=3D -1) && !local_err) { - error_setg(errp, "the helper program 'systemctl %s' was not found", - systemctl_args[mode]); - return; - } - - if (local_err) { - error_propagate(errp, local_err); - } else { - error_setg(errp, "the helper program 'systemctl %s' returned an " - "unexpected exit status code (%d)", - systemctl_args[mode], status); - } -} - -static bool pmutils_supports_mode(SuspendMode mode, Error **errp) -{ - Error *local_err =3D NULL; - const char *pmutils_args[3] =3D {"--hibernate", "--suspend", - "--suspend-hybrid"}; - const char *cmd[3] =3D {"pm-is-supported", pmutils_args[mode], NULL}; - int status; - - status =3D run_process_child(cmd, &local_err); - - if (status =3D=3D SUSPEND_SUPPORTED) { - return true; - } - - if ((status =3D=3D -1) && !local_err) { - return false; - } - - if (local_err) { - error_propagate(errp, local_err); - } else { - error_setg(errp, - "the helper program '%s' returned an unexpected exit" - " status code (%d)", "pm-is-supported", status); - } - - return false; -} - -static void pmutils_suspend(SuspendMode mode, Error **errp) -{ - Error *local_err =3D NULL; - const char *pmutils_binaries[3] =3D {"pm-hibernate", "pm-suspend", - "pm-suspend-hybrid"}; - const char *cmd[2] =3D {pmutils_binaries[mode], NULL}; - int status; - - status =3D run_process_child(cmd, &local_err); - - if (status =3D=3D 0) { - return; - } - - if ((status =3D=3D -1) && !local_err) { - error_setg(errp, "the helper program '%s' was not found", - pmutils_binaries[mode]); - return; - } - - if (local_err) { - error_propagate(errp, local_err); - } else { - error_setg(errp, - "the helper program '%s' returned an unexpected exit" - " status code (%d)", pmutils_binaries[mode], status); - } -} - -static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp) -{ - const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; - const char *sysfile_str =3D sysfile_strs[mode]; - char buf[32]; /* hopefully big enough */ - int fd; - ssize_t ret; - - if (!sysfile_str) { - error_setg(errp, "unknown guest suspend mode"); - return false; - } - - fd =3D open(LINUX_SYS_STATE_FILE, O_RDONLY); - if (fd < 0) { - return false; - } - - ret =3D read(fd, buf, sizeof(buf) - 1); - close(fd); - if (ret <=3D 0) { - return false; - } - buf[ret] =3D '\0'; - - if (strstr(buf, sysfile_str)) { - return true; - } - return false; -} - -static void linux_sys_state_suspend(SuspendMode mode, Error **errp) -{ - g_autoptr(GError) local_gerr =3D NULL; - const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; - const char *sysfile_str =3D sysfile_strs[mode]; - - if (!sysfile_str) { - error_setg(errp, "unknown guest suspend mode"); - return; - } - - if (!g_file_set_contents(LINUX_SYS_STATE_FILE, sysfile_str, - -1, &local_gerr)) { - error_setg(errp, "suspend: cannot write to '%s': %s", - LINUX_SYS_STATE_FILE, local_gerr->message); - return; - } -} - -static void guest_suspend(SuspendMode mode, Error **errp) -{ - Error *local_err =3D NULL; - bool mode_supported =3D false; - - if (systemd_supports_mode(mode, &local_err)) { - mode_supported =3D true; - systemd_suspend(mode, &local_err); - - if (!local_err) { - return; - } - } - - error_free(local_err); - local_err =3D NULL; - - if (pmutils_supports_mode(mode, &local_err)) { - mode_supported =3D true; - pmutils_suspend(mode, &local_err); - - if (!local_err) { - return; - } - } - - error_free(local_err); - local_err =3D NULL; - - if (linux_sys_state_supports_mode(mode, &local_err)) { - mode_supported =3D true; - linux_sys_state_suspend(mode, &local_err); - } - - if (!mode_supported) { - error_free(local_err); - error_setg(errp, - "the requested suspend mode is not supported by the gue= st"); - } else { - error_propagate(errp, local_err); - } -} - -void qmp_guest_suspend_disk(Error **errp) -{ - guest_suspend(SUSPEND_MODE_DISK, errp); -} - -void qmp_guest_suspend_ram(Error **errp) -{ - guest_suspend(SUSPEND_MODE_RAM, errp); -} - -void qmp_guest_suspend_hybrid(Error **errp) -{ - guest_suspend(SUSPEND_MODE_HYBRID, errp); -} - #endif /* __linux__ */ =20 #if defined(__linux__) || defined(__FreeBSD__) --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790802; cv=none; d=zohomail.com; s=zohoarc; b=lFJKvvxWKDLGTLE0nuIYTkv/UBrxZqciDfeHIXjUct0ADapdCZuexAUxaVmhAk+YgaTRWkuJ5M0Kpih30XWCmEbr8PJL0tH4CV2BFFkeBd4qmYe25+uLNtYWIeHfMG9kQAn5r8hEVwQKo2Usf83ZRmAzrL/DSvngzY6VfAAWkjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790802; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hUn1UsHO5lwBdEAr8Dk++qFef7WJuUYdQh18Vqp4Zcg=; b=YaSmeR+YBJhQAEYhT0JxHzD35oQ2K5DN8aZvzvmIo2uxOtxf1WpV4F62n7pHePMEALTXw8kBrxV7dS4mRX4zkNhiXzU5biFf7vQyMCdEYzJKchbS2DLFa7jabGnVK+r0JAAVCKfQ9vEtUdqoWg3MI70xEiehE8KAGXfD/R7Zzxo= 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+importer2=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 1720790802024802.2162816733896; Fri, 12 Jul 2024 06:26:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGHO-00031x-AQ; Fri, 12 Jul 2024 09:25:43 -0400 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 1sSGHA-0002AH-U7 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGH6-0003ku-JN for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:28 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-yCq2yZO_MI-JQRHmIL4UXg-1; Fri, 12 Jul 2024 09:25:21 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 32E281955F44; Fri, 12 Jul 2024 13:25:20 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6ADE51955F40; Fri, 12 Jul 2024 13:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790723; 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: in-reply-to:in-reply-to:references:references; bh=hUn1UsHO5lwBdEAr8Dk++qFef7WJuUYdQh18Vqp4Zcg=; b=dCC+RrS24AgO6k9H8GJu70+2EhHF4mq2sLEPi2TUdSxE9nba7TryL/8jJcfen2qX3HgakM /pjg3GmVebTHEJ/5/iEG3vZo9fzb1btyjjMf9MuJKjRjCro27byL5A5nz8O2X8MdIx+shp ebzBIVCrrExyy+TKKyoXW7PlIiJ16MM= X-MC-Unique: yCq2yZO_MI-JQRHmIL4UXg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk , Manos Pitsidianakis Subject: [PATCH v3 04/22] qga: move linux fs/disk command impls to commands-linux.c Date: Fri, 12 Jul 2024 14:24:41 +0100 Message-ID: <20240712132459.3974109-5-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790804023116300 The qmp_guest_{fstrim, get_fsinfo, get_disks} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 904 ++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 909 ------------------------------------------- 2 files changed, 904 insertions(+), 909 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 3fabf54882..084e6c9e85 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -14,10 +14,21 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qga-qapi-commands.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" #include "commands-common.h" #include "cutils.h" #include #include +#include +#include +#include "block/nvme.h" + +#ifdef CONFIG_LIBUDEV +#include +#endif + +#include =20 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) static int dev_major_minor(const char *devpath, @@ -286,6 +297,899 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) } #endif /* CONFIG_FSFREEZE */ =20 +#if defined(CONFIG_FSFREEZE) + +static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) +{ + char *path; + char *dpath; + char *driver =3D NULL; + char buf[PATH_MAX]; + ssize_t len; + + path =3D g_strndup(syspath, pathlen); + dpath =3D g_strdup_printf("%s/driver", path); + len =3D readlink(dpath, buf, sizeof(buf) - 1); + if (len !=3D -1) { + buf[len] =3D 0; + driver =3D g_path_get_basename(buf); + } + g_free(dpath); + g_free(path); + return driver; +} + +static int compare_uint(const void *_a, const void *_b) +{ + unsigned int a =3D *(unsigned int *)_a; + unsigned int b =3D *(unsigned int *)_b; + + return a < b ? -1 : a > b ? 1 : 0; +} + +/* Walk the specified sysfs and build a sorted list of host or ata numbers= */ +static int build_hosts(char const *syspath, char const *host, bool ata, + unsigned int *hosts, int hosts_max, Error **errp) +{ + char *path; + DIR *dir; + struct dirent *entry; + int i =3D 0; + + path =3D g_strndup(syspath, host - syspath); + dir =3D opendir(path); + if (!dir) { + error_setg_errno(errp, errno, "opendir(\"%s\")", path); + g_free(path); + return -1; + } + + while (i < hosts_max) { + entry =3D readdir(dir); + if (!entry) { + break; + } + if (ata && sscanf(entry->d_name, "ata%d", hosts + i) =3D=3D 1) { + ++i; + } else if (!ata && sscanf(entry->d_name, "host%d", hosts + i) =3D= =3D 1) { + ++i; + } + } + + qsort(hosts, i, sizeof(hosts[0]), compare_uint); + + g_free(path); + closedir(dir); + return i; +} + +/* + * Store disk device info for devices on the PCI bus. + * Returns true if information has been stored, or false for failure. + */ +static bool build_guest_fsinfo_for_pci_dev(char const *syspath, + GuestDiskAddress *disk, + Error **errp) +{ + unsigned int pci[4], host, hosts[8], tgt[3]; + int i, nhosts =3D 0, pcilen; + GuestPCIAddress *pciaddr =3D disk->pci_controller; + bool has_ata =3D false, has_host =3D false, has_tgt =3D false; + char *p, *q, *driver =3D NULL; + bool ret =3D false; + + p =3D strstr(syspath, "/devices/pci"); + if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n", + pci, pci + 1, pci + 2, pci + 3, &pcilen) < 4) { + g_debug("only pci device is supported: sysfs path '%s'", syspath); + return false; + } + + p +=3D 12 + pcilen; + while (true) { + driver =3D get_pci_driver(syspath, p - syspath, errp); + if (driver && (g_str_equal(driver, "ata_piix") || + g_str_equal(driver, "sym53c8xx") || + g_str_equal(driver, "virtio-pci") || + g_str_equal(driver, "ahci") || + g_str_equal(driver, "nvme") || + g_str_equal(driver, "xhci_hcd") || + g_str_equal(driver, "ehci-pci"))) { + break; + } + + g_free(driver); + if (sscanf(p, "/%x:%x:%x.%x%n", + pci, pci + 1, pci + 2, pci + 3, &pcilen) =3D=3D = 4) { + p +=3D pcilen; + continue; + } + + g_debug("unsupported driver or sysfs path '%s'", syspath); + return false; + } + + p =3D strstr(syspath, "/target"); + if (p && sscanf(p + 7, "%*u:%*u:%*u/%*u:%u:%u:%u", + tgt, tgt + 1, tgt + 2) =3D=3D 3) { + has_tgt =3D true; + } + + p =3D strstr(syspath, "/ata"); + if (p) { + q =3D p + 4; + has_ata =3D true; + } else { + p =3D strstr(syspath, "/host"); + q =3D p + 5; + } + if (p && sscanf(q, "%u", &host) =3D=3D 1) { + has_host =3D true; + nhosts =3D build_hosts(syspath, p, has_ata, hosts, + ARRAY_SIZE(hosts), errp); + if (nhosts < 0) { + goto cleanup; + } + } + + pciaddr->domain =3D pci[0]; + pciaddr->bus =3D pci[1]; + pciaddr->slot =3D pci[2]; + pciaddr->function =3D pci[3]; + + if (strcmp(driver, "ata_piix") =3D=3D 0) { + /* a host per ide bus, target*:0::0 */ + if (!has_host || !has_tgt) { + g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); + goto cleanup; + } + for (i =3D 0; i < nhosts; i++) { + if (host =3D=3D hosts[i]) { + disk->bus_type =3D GUEST_DISK_BUS_TYPE_IDE; + disk->bus =3D i; + disk->unit =3D tgt[1]; + break; + } + } + if (i >=3D nhosts) { + g_debug("no host for '%s' (driver '%s')", syspath, driver); + goto cleanup; + } + } else if (strcmp(driver, "sym53c8xx") =3D=3D 0) { + /* scsi(LSI Logic): target*:0::0 */ + if (!has_tgt) { + g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); + goto cleanup; + } + disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; + disk->unit =3D tgt[1]; + } else if (strcmp(driver, "virtio-pci") =3D=3D 0) { + if (has_tgt) { + /* virtio-scsi: target*:0:0: */ + disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; + disk->unit =3D tgt[2]; + } else { + /* virtio-blk: 1 disk per 1 device */ + disk->bus_type =3D GUEST_DISK_BUS_TYPE_VIRTIO; + } + } else if (strcmp(driver, "ahci") =3D=3D 0) { + /* ahci: 1 host per 1 unit */ + if (!has_host || !has_tgt) { + g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); + goto cleanup; + } + for (i =3D 0; i < nhosts; i++) { + if (host =3D=3D hosts[i]) { + disk->unit =3D i; + disk->bus_type =3D GUEST_DISK_BUS_TYPE_SATA; + break; + } + } + if (i >=3D nhosts) { + g_debug("no host for '%s' (driver '%s')", syspath, driver); + goto cleanup; + } + } else if (strcmp(driver, "nvme") =3D=3D 0) { + disk->bus_type =3D GUEST_DISK_BUS_TYPE_NVME; + } else if (strcmp(driver, "ehci-pci") =3D=3D 0 || strcmp(driver, "xhci= _hcd") =3D=3D 0) { + disk->bus_type =3D GUEST_DISK_BUS_TYPE_USB; + } else { + g_debug("unknown driver '%s' (sysfs path '%s')", driver, syspath); + goto cleanup; + } + + ret =3D true; + +cleanup: + g_free(driver); + return ret; +} + +/* + * Store disk device info for non-PCI virtio devices (for example s390x + * channel I/O devices). Returns true if information has been stored, or + * false for failure. + */ +static bool build_guest_fsinfo_for_nonpci_virtio(char const *syspath, + GuestDiskAddress *disk, + Error **errp) +{ + unsigned int tgt[3]; + char *p; + + if (!strstr(syspath, "/virtio") || !strstr(syspath, "/block")) { + g_debug("Unsupported virtio device '%s'", syspath); + return false; + } + + p =3D strstr(syspath, "/target"); + if (p && sscanf(p + 7, "%*u:%*u:%*u/%*u:%u:%u:%u", + &tgt[0], &tgt[1], &tgt[2]) =3D=3D 3) { + /* virtio-scsi: target*:0:: */ + disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; + disk->bus =3D tgt[0]; + disk->target =3D tgt[1]; + disk->unit =3D tgt[2]; + } else { + /* virtio-blk: 1 disk per 1 device */ + disk->bus_type =3D GUEST_DISK_BUS_TYPE_VIRTIO; + } + + return true; +} + +/* + * Store disk device info for CCW devices (s390x channel I/O devices). + * Returns true if information has been stored, or false for failure. + */ +static bool build_guest_fsinfo_for_ccw_dev(char const *syspath, + GuestDiskAddress *disk, + Error **errp) +{ + unsigned int cssid, ssid, subchno, devno; + char *p; + + p =3D strstr(syspath, "/devices/css"); + if (!p || sscanf(p + 12, "%*x/%x.%x.%x/%*x.%*x.%x/", + &cssid, &ssid, &subchno, &devno) < 4) { + g_debug("could not parse ccw device sysfs path: %s", syspath); + return false; + } + + disk->ccw_address =3D g_new0(GuestCCWAddress, 1); + disk->ccw_address->cssid =3D cssid; + disk->ccw_address->ssid =3D ssid; + disk->ccw_address->subchno =3D subchno; + disk->ccw_address->devno =3D devno; + + if (strstr(p, "/virtio")) { + build_guest_fsinfo_for_nonpci_virtio(syspath, disk, errp); + } + + return true; +} + +/* Store disk device info specified by @sysfs into @fs */ +static void build_guest_fsinfo_for_real_device(char const *syspath, + GuestFilesystemInfo *fs, + Error **errp) +{ + GuestDiskAddress *disk; + GuestPCIAddress *pciaddr; + bool has_hwinf; +#ifdef CONFIG_LIBUDEV + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; +#endif + + pciaddr =3D g_new0(GuestPCIAddress, 1); + pciaddr->domain =3D -1; /* -1 means field is inv= alid */ + pciaddr->bus =3D -1; + pciaddr->slot =3D -1; + pciaddr->function =3D -1; + + disk =3D g_new0(GuestDiskAddress, 1); + disk->pci_controller =3D pciaddr; + disk->bus_type =3D GUEST_DISK_BUS_TYPE_UNKNOWN; + +#ifdef CONFIG_LIBUDEV + udev =3D udev_new(); + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udev =3D=3D NULL || udevice =3D=3D NULL) { + g_debug("failed to query udev"); + } else { + const char *devnode, *serial; + devnode =3D udev_device_get_devnode(udevice); + if (devnode !=3D NULL) { + disk->dev =3D g_strdup(devnode); + } + serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); + if (serial !=3D NULL && *serial !=3D 0) { + disk->serial =3D g_strdup(serial); + } + } + + udev_unref(udev); + udev_device_unref(udevice); +#endif + + if (strstr(syspath, "/devices/pci")) { + has_hwinf =3D build_guest_fsinfo_for_pci_dev(syspath, disk, errp); + } else if (strstr(syspath, "/devices/css")) { + has_hwinf =3D build_guest_fsinfo_for_ccw_dev(syspath, disk, errp); + } else if (strstr(syspath, "/virtio")) { + has_hwinf =3D build_guest_fsinfo_for_nonpci_virtio(syspath, disk, = errp); + } else { + g_debug("Unsupported device type for '%s'", syspath); + has_hwinf =3D false; + } + + if (has_hwinf || disk->dev || disk->serial) { + QAPI_LIST_PREPEND(fs->disk, disk); + } else { + qapi_free_GuestDiskAddress(disk); + } +} + +static void build_guest_fsinfo_for_device(char const *devpath, + GuestFilesystemInfo *fs, + Error **errp); + +/* Store a list of slave devices of virtual volume specified by @syspath i= nto + * @fs */ +static void build_guest_fsinfo_for_virtual_device(char const *syspath, + GuestFilesystemInfo *fs, + Error **errp) +{ + Error *err =3D NULL; + DIR *dir; + char *dirpath; + struct dirent *entry; + + dirpath =3D g_strdup_printf("%s/slaves", syspath); + dir =3D opendir(dirpath); + if (!dir) { + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "opendir(\"%s\")", dirpath); + } + g_free(dirpath); + return; + } + + for (;;) { + errno =3D 0; + entry =3D readdir(dir); + if (entry =3D=3D NULL) { + if (errno) { + error_setg_errno(errp, errno, "readdir(\"%s\")", dirpath); + } + break; + } + + if (entry->d_type =3D=3D DT_LNK) { + char *path; + + g_debug(" slave device '%s'", entry->d_name); + path =3D g_strdup_printf("%s/slaves/%s", syspath, entry->d_nam= e); + build_guest_fsinfo_for_device(path, fs, &err); + g_free(path); + + if (err) { + error_propagate(errp, err); + break; + } + } + } + + g_free(dirpath); + closedir(dir); +} + +static bool is_disk_virtual(const char *devpath, Error **errp) +{ + g_autofree char *syspath =3D realpath(devpath, NULL); + + if (!syspath) { + error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); + return false; + } + return strstr(syspath, "/devices/virtual/block/") !=3D NULL; +} + +/* Dispatch to functions for virtual/real device */ +static void build_guest_fsinfo_for_device(char const *devpath, + GuestFilesystemInfo *fs, + Error **errp) +{ + ERRP_GUARD(); + g_autofree char *syspath =3D NULL; + bool is_virtual =3D false; + + syspath =3D realpath(devpath, NULL); + if (!syspath) { + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); + return; + } + + /* ENOENT: This devpath may not exist because of container config = */ + if (!fs->name) { + fs->name =3D g_path_get_basename(devpath); + } + return; + } + + if (!fs->name) { + fs->name =3D g_path_get_basename(syspath); + } + + g_debug(" parse sysfs path '%s'", syspath); + is_virtual =3D is_disk_virtual(syspath, errp); + if (*errp !=3D NULL) { + return; + } + if (is_virtual) { + build_guest_fsinfo_for_virtual_device(syspath, fs, errp); + } else { + build_guest_fsinfo_for_real_device(syspath, fs, errp); + } +} + +#ifdef CONFIG_LIBUDEV + +/* + * Wrapper around build_guest_fsinfo_for_device() for getting just + * the disk address. + */ +static GuestDiskAddress *get_disk_address(const char *syspath, Error **err= p) +{ + g_autoptr(GuestFilesystemInfo) fs =3D NULL; + + fs =3D g_new0(GuestFilesystemInfo, 1); + build_guest_fsinfo_for_device(syspath, fs, errp); + if (fs->disk !=3D NULL) { + return g_steal_pointer(&fs->disk->value); + } + return NULL; +} + +static char *get_alias_for_syspath(const char *syspath) +{ + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; + char *ret =3D NULL; + + udev =3D udev_new(); + if (udev =3D=3D NULL) { + g_debug("failed to query udev"); + goto out; + } + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udevice =3D=3D NULL) { + g_debug("failed to query udev for path: %s", syspath); + goto out; + } else { + const char *alias =3D udev_device_get_property_value( + udevice, "DM_NAME"); + /* + * NULL means there was an error and empty string means there is no + * alias. In case of no alias we return NULL instead of empty stri= ng. + */ + if (alias =3D=3D NULL) { + g_debug("failed to query udev for device alias for: %s", + syspath); + } else if (*alias !=3D 0) { + ret =3D g_strdup(alias); + } + } + +out: + udev_unref(udev); + udev_device_unref(udevice); + return ret; +} + +static char *get_device_for_syspath(const char *syspath) +{ + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; + char *ret =3D NULL; + + udev =3D udev_new(); + if (udev =3D=3D NULL) { + g_debug("failed to query udev"); + goto out; + } + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udevice =3D=3D NULL) { + g_debug("failed to query udev for path: %s", syspath); + goto out; + } else { + ret =3D g_strdup(udev_device_get_devnode(udevice)); + } + +out: + udev_unref(udev); + udev_device_unref(udevice); + return ret; +} + +static void get_disk_deps(const char *disk_dir, GuestDiskInfo *disk) +{ + g_autofree char *deps_dir =3D NULL; + const gchar *dep; + GDir *dp_deps =3D NULL; + + /* List dependent disks */ + deps_dir =3D g_strdup_printf("%s/slaves", disk_dir); + g_debug(" listing entries in: %s", deps_dir); + dp_deps =3D g_dir_open(deps_dir, 0, NULL); + if (dp_deps =3D=3D NULL) { + g_debug("failed to list entries in %s", deps_dir); + return; + } + disk->has_dependencies =3D true; + while ((dep =3D g_dir_read_name(dp_deps)) !=3D NULL) { + g_autofree char *dep_dir =3D NULL; + char *dev_name; + + /* Add dependent disks */ + dep_dir =3D g_strdup_printf("%s/%s", deps_dir, dep); + dev_name =3D get_device_for_syspath(dep_dir); + if (dev_name !=3D NULL) { + g_debug(" adding dependent device: %s", dev_name); + QAPI_LIST_PREPEND(disk->dependencies, dev_name); + } + } + g_dir_close(dp_deps); +} + +/* + * Detect partitions subdirectory, name is "" or + * "p" + * + * @disk_name -- last component of /sys path (e.g. sda) + * @disk_dir -- sys path of the disk (e.g. /sys/block/sda) + * @disk_dev -- device node of the disk (e.g. /dev/sda) + */ +static GuestDiskInfoList *get_disk_partitions( + GuestDiskInfoList *list, + const char *disk_name, const char *disk_dir, + const char *disk_dev) +{ + GuestDiskInfoList *ret =3D list; + struct dirent *de_disk; + DIR *dp_disk =3D NULL; + size_t len =3D strlen(disk_name); + + dp_disk =3D opendir(disk_dir); + while ((de_disk =3D readdir(dp_disk)) !=3D NULL) { + g_autofree char *partition_dir =3D NULL; + char *dev_name; + GuestDiskInfo *partition; + + if (!(de_disk->d_type & DT_DIR)) { + continue; + } + + if (!(strncmp(disk_name, de_disk->d_name, len) =3D=3D 0 && + ((*(de_disk->d_name + len) =3D=3D 'p' && + isdigit(*(de_disk->d_name + len + 1))) || + isdigit(*(de_disk->d_name + len))))) { + continue; + } + + partition_dir =3D g_strdup_printf("%s/%s", + disk_dir, de_disk->d_name); + dev_name =3D get_device_for_syspath(partition_dir); + if (dev_name =3D=3D NULL) { + g_debug("Failed to get device name for syspath: %s", + disk_dir); + continue; + } + partition =3D g_new0(GuestDiskInfo, 1); + partition->name =3D dev_name; + partition->partition =3D true; + partition->has_dependencies =3D true; + /* Add parent disk as dependent for easier tracking of hierarchy */ + QAPI_LIST_PREPEND(partition->dependencies, g_strdup(disk_dev)); + + QAPI_LIST_PREPEND(ret, partition); + } + closedir(dp_disk); + + return ret; +} + +static void get_nvme_smart(GuestDiskInfo *disk) +{ + int fd; + GuestNVMeSmart *smart; + NvmeSmartLog log =3D {0}; + struct nvme_admin_cmd cmd =3D { + .opcode =3D NVME_ADM_CMD_GET_LOG_PAGE, + .nsid =3D NVME_NSID_BROADCAST, + .addr =3D (uintptr_t)&log, + .data_len =3D sizeof(log), + .cdw10 =3D NVME_LOG_SMART_INFO | (1 << 15) /* RAE bit */ + | (((sizeof(log) >> 2) - 1) << 16) + }; + + fd =3D qga_open_cloexec(disk->name, O_RDONLY, 0); + if (fd =3D=3D -1) { + g_debug("Failed to open device: %s: %s", disk->name, g_strerror(er= rno)); + return; + } + + if (ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd)) { + g_debug("Failed to get smart: %s: %s", disk->name, g_strerror(errn= o)); + close(fd); + return; + } + + disk->smart =3D g_new0(GuestDiskSmart, 1); + disk->smart->type =3D GUEST_DISK_BUS_TYPE_NVME; + + smart =3D &disk->smart->u.nvme; + smart->critical_warning =3D log.critical_warning; + smart->temperature =3D lduw_le_p(&log.temperature); /* unaligned field= */ + smart->available_spare =3D log.available_spare; + smart->available_spare_threshold =3D log.available_spare_threshold; + smart->percentage_used =3D log.percentage_used; + smart->data_units_read_lo =3D le64_to_cpu(log.data_units_read[0]); + smart->data_units_read_hi =3D le64_to_cpu(log.data_units_read[1]); + smart->data_units_written_lo =3D le64_to_cpu(log.data_units_written[0]= ); + smart->data_units_written_hi =3D le64_to_cpu(log.data_units_written[1]= ); + smart->host_read_commands_lo =3D le64_to_cpu(log.host_read_commands[0]= ); + smart->host_read_commands_hi =3D le64_to_cpu(log.host_read_commands[1]= ); + smart->host_write_commands_lo =3D le64_to_cpu(log.host_write_commands[= 0]); + smart->host_write_commands_hi =3D le64_to_cpu(log.host_write_commands[= 1]); + smart->controller_busy_time_lo =3D le64_to_cpu(log.controller_busy_tim= e[0]); + smart->controller_busy_time_hi =3D le64_to_cpu(log.controller_busy_tim= e[1]); + smart->power_cycles_lo =3D le64_to_cpu(log.power_cycles[0]); + smart->power_cycles_hi =3D le64_to_cpu(log.power_cycles[1]); + smart->power_on_hours_lo =3D le64_to_cpu(log.power_on_hours[0]); + smart->power_on_hours_hi =3D le64_to_cpu(log.power_on_hours[1]); + smart->unsafe_shutdowns_lo =3D le64_to_cpu(log.unsafe_shutdowns[0]); + smart->unsafe_shutdowns_hi =3D le64_to_cpu(log.unsafe_shutdowns[1]); + smart->media_errors_lo =3D le64_to_cpu(log.media_errors[0]); + smart->media_errors_hi =3D le64_to_cpu(log.media_errors[1]); + smart->number_of_error_log_entries_lo =3D + le64_to_cpu(log.number_of_error_log_entries[0]); + smart->number_of_error_log_entries_hi =3D + le64_to_cpu(log.number_of_error_log_entries[1]); + + close(fd); +} + +static void get_disk_smart(GuestDiskInfo *disk) +{ + if (disk->address + && (disk->address->bus_type =3D=3D GUEST_DISK_BUS_TYPE_NVME)) { + get_nvme_smart(disk); + } +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + GuestDiskInfoList *ret =3D NULL; + GuestDiskInfo *disk; + DIR *dp =3D NULL; + struct dirent *de =3D NULL; + + g_debug("listing /sys/block directory"); + dp =3D opendir("/sys/block"); + if (dp =3D=3D NULL) { + error_setg_errno(errp, errno, "Can't open directory \"/sys/block\"= "); + return NULL; + } + while ((de =3D readdir(dp)) !=3D NULL) { + g_autofree char *disk_dir =3D NULL, *line =3D NULL, + *size_path =3D NULL; + char *dev_name; + Error *local_err =3D NULL; + if (de->d_type !=3D DT_LNK) { + g_debug(" skipping entry: %s", de->d_name); + continue; + } + + /* Check size and skip zero-sized disks */ + g_debug(" checking disk size"); + size_path =3D g_strdup_printf("/sys/block/%s/size", de->d_name); + if (!g_file_get_contents(size_path, &line, NULL, NULL)) { + g_debug(" failed to read disk size"); + continue; + } + if (g_strcmp0(line, "0\n") =3D=3D 0) { + g_debug(" skipping zero-sized disk"); + continue; + } + + g_debug(" adding %s", de->d_name); + disk_dir =3D g_strdup_printf("/sys/block/%s", de->d_name); + dev_name =3D get_device_for_syspath(disk_dir); + if (dev_name =3D=3D NULL) { + g_debug("Failed to get device name for syspath: %s", + disk_dir); + continue; + } + disk =3D g_new0(GuestDiskInfo, 1); + disk->name =3D dev_name; + disk->partition =3D false; + disk->alias =3D get_alias_for_syspath(disk_dir); + QAPI_LIST_PREPEND(ret, disk); + + /* Get address for non-virtual devices */ + bool is_virtual =3D is_disk_virtual(disk_dir, &local_err); + if (local_err !=3D NULL) { + g_debug(" failed to check disk path, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err =3D NULL; + /* Don't try to get the address */ + is_virtual =3D true; + } + if (!is_virtual) { + disk->address =3D get_disk_address(disk_dir, &local_err); + if (local_err !=3D NULL) { + g_debug(" failed to get device info, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err =3D NULL; + } + } + + get_disk_deps(disk_dir, disk); + get_disk_smart(disk); + ret =3D get_disk_partitions(ret, de->d_name, disk_dir, dev_name); + } + + closedir(dp); + + return ret; +} + +#else + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +#endif + +/* Return a list of the disk device(s)' info which @mount lies on */ +static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount, + Error **errp) +{ + GuestFilesystemInfo *fs =3D g_malloc0(sizeof(*fs)); + struct statvfs buf; + unsigned long used, nonroot_total, fr_size; + char *devpath =3D g_strdup_printf("/sys/dev/block/%u:%u", + mount->devmajor, mount->devminor); + + fs->mountpoint =3D g_strdup(mount->dirname); + fs->type =3D g_strdup(mount->devtype); + build_guest_fsinfo_for_device(devpath, fs, errp); + + if (statvfs(fs->mountpoint, &buf) =3D=3D 0) { + fr_size =3D buf.f_frsize; + used =3D buf.f_blocks - buf.f_bfree; + nonroot_total =3D used + buf.f_bavail; + fs->used_bytes =3D used * fr_size; + fs->total_bytes =3D nonroot_total * fr_size; + fs->total_bytes_privileged =3D buf.f_blocks * fr_size; + + fs->has_total_bytes =3D true; + fs->has_total_bytes_privileged =3D true; + fs->has_used_bytes =3D true; + } + + g_free(devpath); + + return fs; +} + +GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) +{ + FsMountList mounts; + struct FsMount *mount; + GuestFilesystemInfoList *ret =3D NULL; + Error *local_err =3D NULL; + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return NULL; + } + + QTAILQ_FOREACH(mount, &mounts, next) { + g_debug("Building guest fsinfo for '%s'", mount->dirname); + + QAPI_LIST_PREPEND(ret, build_guest_fsinfo(mount, &local_err)); + if (local_err) { + error_propagate(errp, local_err); + qapi_free_GuestFilesystemInfoList(ret); + ret =3D NULL; + break; + } + } + + free_fs_mount_list(&mounts); + return ret; +} +#endif /* CONFIG_FSFREEZE */ + +#if defined(CONFIG_FSTRIM) +/* + * Walk list of mounted file systems in the guest, and trim them. + */ +GuestFilesystemTrimResponse * +qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) +{ + GuestFilesystemTrimResponse *response; + GuestFilesystemTrimResult *result; + int ret =3D 0; + FsMountList mounts; + struct FsMount *mount; + int fd; + struct fstrim_range r; + + slog("guest-fstrim called"); + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, errp)) { + return NULL; + } + + response =3D g_malloc0(sizeof(*response)); + + QTAILQ_FOREACH(mount, &mounts, next) { + result =3D g_malloc0(sizeof(*result)); + result->path =3D g_strdup(mount->dirname); + + QAPI_LIST_PREPEND(response->paths, result); + + fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd =3D=3D -1) { + result->error =3D g_strdup_printf("failed to open: %s", + strerror(errno)); + continue; + } + + /* We try to cull filesystems we know won't work in advance, but o= ther + * filesystems may not implement fstrim for less obvious reasons. + * These will report EOPNOTSUPP; while in some other cases ENOTTY + * will be reported (e.g. CD-ROMs). + * Any other error means an unexpected error. + */ + r.start =3D 0; + r.len =3D -1; + r.minlen =3D has_minimum ? minimum : 0; + ret =3D ioctl(fd, FITRIM, &r); + if (ret =3D=3D -1) { + if (errno =3D=3D ENOTTY || errno =3D=3D EOPNOTSUPP) { + result->error =3D g_strdup("trim not supported"); + } else { + result->error =3D g_strdup_printf("failed to trim: %s", + strerror(errno)); + } + close(fd); + continue; + } + + result->has_minimum =3D true; + result->minimum =3D r.minlen; + result->has_trimmed =3D true; + result->trimmed =3D r.len; + close(fd); + } + + free_fs_mount_list(&mounts); + return response; +} +#endif /* CONFIG_FSTRIM */ =20 #define LINUX_SYS_STATE_FILE "/sys/power/state" #define SUSPEND_SUPPORTED 0 diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ef21da63be..98aafc45f3 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -24,23 +24,12 @@ #include "qemu/base64.h" #include "qemu/cutils.h" #include "commands-common.h" -#include "block/nvme.h" #include "cutils.h" =20 #ifdef HAVE_UTMPX #include #endif =20 -#if defined(__linux__) -#include -#include -#include - -#ifdef CONFIG_LIBUDEV -#include -#endif -#endif - #ifdef HAVE_GETIFADDRS #include #include @@ -842,904 +831,6 @@ static void guest_fsfreeze_cleanup(void) } #endif =20 -/* linux-specific implementations. avoid this if at all possible. */ -#if defined(__linux__) -#if defined(CONFIG_FSFREEZE) - -static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) -{ - char *path; - char *dpath; - char *driver =3D NULL; - char buf[PATH_MAX]; - ssize_t len; - - path =3D g_strndup(syspath, pathlen); - dpath =3D g_strdup_printf("%s/driver", path); - len =3D readlink(dpath, buf, sizeof(buf) - 1); - if (len !=3D -1) { - buf[len] =3D 0; - driver =3D g_path_get_basename(buf); - } - g_free(dpath); - g_free(path); - return driver; -} - -static int compare_uint(const void *_a, const void *_b) -{ - unsigned int a =3D *(unsigned int *)_a; - unsigned int b =3D *(unsigned int *)_b; - - return a < b ? -1 : a > b ? 1 : 0; -} - -/* Walk the specified sysfs and build a sorted list of host or ata numbers= */ -static int build_hosts(char const *syspath, char const *host, bool ata, - unsigned int *hosts, int hosts_max, Error **errp) -{ - char *path; - DIR *dir; - struct dirent *entry; - int i =3D 0; - - path =3D g_strndup(syspath, host - syspath); - dir =3D opendir(path); - if (!dir) { - error_setg_errno(errp, errno, "opendir(\"%s\")", path); - g_free(path); - return -1; - } - - while (i < hosts_max) { - entry =3D readdir(dir); - if (!entry) { - break; - } - if (ata && sscanf(entry->d_name, "ata%d", hosts + i) =3D=3D 1) { - ++i; - } else if (!ata && sscanf(entry->d_name, "host%d", hosts + i) =3D= =3D 1) { - ++i; - } - } - - qsort(hosts, i, sizeof(hosts[0]), compare_uint); - - g_free(path); - closedir(dir); - return i; -} - -/* - * Store disk device info for devices on the PCI bus. - * Returns true if information has been stored, or false for failure. - */ -static bool build_guest_fsinfo_for_pci_dev(char const *syspath, - GuestDiskAddress *disk, - Error **errp) -{ - unsigned int pci[4], host, hosts[8], tgt[3]; - int i, nhosts =3D 0, pcilen; - GuestPCIAddress *pciaddr =3D disk->pci_controller; - bool has_ata =3D false, has_host =3D false, has_tgt =3D false; - char *p, *q, *driver =3D NULL; - bool ret =3D false; - - p =3D strstr(syspath, "/devices/pci"); - if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n", - pci, pci + 1, pci + 2, pci + 3, &pcilen) < 4) { - g_debug("only pci device is supported: sysfs path '%s'", syspath); - return false; - } - - p +=3D 12 + pcilen; - while (true) { - driver =3D get_pci_driver(syspath, p - syspath, errp); - if (driver && (g_str_equal(driver, "ata_piix") || - g_str_equal(driver, "sym53c8xx") || - g_str_equal(driver, "virtio-pci") || - g_str_equal(driver, "ahci") || - g_str_equal(driver, "nvme") || - g_str_equal(driver, "xhci_hcd") || - g_str_equal(driver, "ehci-pci"))) { - break; - } - - g_free(driver); - if (sscanf(p, "/%x:%x:%x.%x%n", - pci, pci + 1, pci + 2, pci + 3, &pcilen) =3D=3D = 4) { - p +=3D pcilen; - continue; - } - - g_debug("unsupported driver or sysfs path '%s'", syspath); - return false; - } - - p =3D strstr(syspath, "/target"); - if (p && sscanf(p + 7, "%*u:%*u:%*u/%*u:%u:%u:%u", - tgt, tgt + 1, tgt + 2) =3D=3D 3) { - has_tgt =3D true; - } - - p =3D strstr(syspath, "/ata"); - if (p) { - q =3D p + 4; - has_ata =3D true; - } else { - p =3D strstr(syspath, "/host"); - q =3D p + 5; - } - if (p && sscanf(q, "%u", &host) =3D=3D 1) { - has_host =3D true; - nhosts =3D build_hosts(syspath, p, has_ata, hosts, - ARRAY_SIZE(hosts), errp); - if (nhosts < 0) { - goto cleanup; - } - } - - pciaddr->domain =3D pci[0]; - pciaddr->bus =3D pci[1]; - pciaddr->slot =3D pci[2]; - pciaddr->function =3D pci[3]; - - if (strcmp(driver, "ata_piix") =3D=3D 0) { - /* a host per ide bus, target*:0::0 */ - if (!has_host || !has_tgt) { - g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); - goto cleanup; - } - for (i =3D 0; i < nhosts; i++) { - if (host =3D=3D hosts[i]) { - disk->bus_type =3D GUEST_DISK_BUS_TYPE_IDE; - disk->bus =3D i; - disk->unit =3D tgt[1]; - break; - } - } - if (i >=3D nhosts) { - g_debug("no host for '%s' (driver '%s')", syspath, driver); - goto cleanup; - } - } else if (strcmp(driver, "sym53c8xx") =3D=3D 0) { - /* scsi(LSI Logic): target*:0::0 */ - if (!has_tgt) { - g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); - goto cleanup; - } - disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; - disk->unit =3D tgt[1]; - } else if (strcmp(driver, "virtio-pci") =3D=3D 0) { - if (has_tgt) { - /* virtio-scsi: target*:0:0: */ - disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; - disk->unit =3D tgt[2]; - } else { - /* virtio-blk: 1 disk per 1 device */ - disk->bus_type =3D GUEST_DISK_BUS_TYPE_VIRTIO; - } - } else if (strcmp(driver, "ahci") =3D=3D 0) { - /* ahci: 1 host per 1 unit */ - if (!has_host || !has_tgt) { - g_debug("invalid sysfs path '%s' (driver '%s')", syspath, driv= er); - goto cleanup; - } - for (i =3D 0; i < nhosts; i++) { - if (host =3D=3D hosts[i]) { - disk->unit =3D i; - disk->bus_type =3D GUEST_DISK_BUS_TYPE_SATA; - break; - } - } - if (i >=3D nhosts) { - g_debug("no host for '%s' (driver '%s')", syspath, driver); - goto cleanup; - } - } else if (strcmp(driver, "nvme") =3D=3D 0) { - disk->bus_type =3D GUEST_DISK_BUS_TYPE_NVME; - } else if (strcmp(driver, "ehci-pci") =3D=3D 0 || strcmp(driver, "xhci= _hcd") =3D=3D 0) { - disk->bus_type =3D GUEST_DISK_BUS_TYPE_USB; - } else { - g_debug("unknown driver '%s' (sysfs path '%s')", driver, syspath); - goto cleanup; - } - - ret =3D true; - -cleanup: - g_free(driver); - return ret; -} - -/* - * Store disk device info for non-PCI virtio devices (for example s390x - * channel I/O devices). Returns true if information has been stored, or - * false for failure. - */ -static bool build_guest_fsinfo_for_nonpci_virtio(char const *syspath, - GuestDiskAddress *disk, - Error **errp) -{ - unsigned int tgt[3]; - char *p; - - if (!strstr(syspath, "/virtio") || !strstr(syspath, "/block")) { - g_debug("Unsupported virtio device '%s'", syspath); - return false; - } - - p =3D strstr(syspath, "/target"); - if (p && sscanf(p + 7, "%*u:%*u:%*u/%*u:%u:%u:%u", - &tgt[0], &tgt[1], &tgt[2]) =3D=3D 3) { - /* virtio-scsi: target*:0:: */ - disk->bus_type =3D GUEST_DISK_BUS_TYPE_SCSI; - disk->bus =3D tgt[0]; - disk->target =3D tgt[1]; - disk->unit =3D tgt[2]; - } else { - /* virtio-blk: 1 disk per 1 device */ - disk->bus_type =3D GUEST_DISK_BUS_TYPE_VIRTIO; - } - - return true; -} - -/* - * Store disk device info for CCW devices (s390x channel I/O devices). - * Returns true if information has been stored, or false for failure. - */ -static bool build_guest_fsinfo_for_ccw_dev(char const *syspath, - GuestDiskAddress *disk, - Error **errp) -{ - unsigned int cssid, ssid, subchno, devno; - char *p; - - p =3D strstr(syspath, "/devices/css"); - if (!p || sscanf(p + 12, "%*x/%x.%x.%x/%*x.%*x.%x/", - &cssid, &ssid, &subchno, &devno) < 4) { - g_debug("could not parse ccw device sysfs path: %s", syspath); - return false; - } - - disk->ccw_address =3D g_new0(GuestCCWAddress, 1); - disk->ccw_address->cssid =3D cssid; - disk->ccw_address->ssid =3D ssid; - disk->ccw_address->subchno =3D subchno; - disk->ccw_address->devno =3D devno; - - if (strstr(p, "/virtio")) { - build_guest_fsinfo_for_nonpci_virtio(syspath, disk, errp); - } - - return true; -} - -/* Store disk device info specified by @sysfs into @fs */ -static void build_guest_fsinfo_for_real_device(char const *syspath, - GuestFilesystemInfo *fs, - Error **errp) -{ - GuestDiskAddress *disk; - GuestPCIAddress *pciaddr; - bool has_hwinf; -#ifdef CONFIG_LIBUDEV - struct udev *udev =3D NULL; - struct udev_device *udevice =3D NULL; -#endif - - pciaddr =3D g_new0(GuestPCIAddress, 1); - pciaddr->domain =3D -1; /* -1 means field is inv= alid */ - pciaddr->bus =3D -1; - pciaddr->slot =3D -1; - pciaddr->function =3D -1; - - disk =3D g_new0(GuestDiskAddress, 1); - disk->pci_controller =3D pciaddr; - disk->bus_type =3D GUEST_DISK_BUS_TYPE_UNKNOWN; - -#ifdef CONFIG_LIBUDEV - udev =3D udev_new(); - udevice =3D udev_device_new_from_syspath(udev, syspath); - if (udev =3D=3D NULL || udevice =3D=3D NULL) { - g_debug("failed to query udev"); - } else { - const char *devnode, *serial; - devnode =3D udev_device_get_devnode(udevice); - if (devnode !=3D NULL) { - disk->dev =3D g_strdup(devnode); - } - serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); - if (serial !=3D NULL && *serial !=3D 0) { - disk->serial =3D g_strdup(serial); - } - } - - udev_unref(udev); - udev_device_unref(udevice); -#endif - - if (strstr(syspath, "/devices/pci")) { - has_hwinf =3D build_guest_fsinfo_for_pci_dev(syspath, disk, errp); - } else if (strstr(syspath, "/devices/css")) { - has_hwinf =3D build_guest_fsinfo_for_ccw_dev(syspath, disk, errp); - } else if (strstr(syspath, "/virtio")) { - has_hwinf =3D build_guest_fsinfo_for_nonpci_virtio(syspath, disk, = errp); - } else { - g_debug("Unsupported device type for '%s'", syspath); - has_hwinf =3D false; - } - - if (has_hwinf || disk->dev || disk->serial) { - QAPI_LIST_PREPEND(fs->disk, disk); - } else { - qapi_free_GuestDiskAddress(disk); - } -} - -static void build_guest_fsinfo_for_device(char const *devpath, - GuestFilesystemInfo *fs, - Error **errp); - -/* Store a list of slave devices of virtual volume specified by @syspath i= nto - * @fs */ -static void build_guest_fsinfo_for_virtual_device(char const *syspath, - GuestFilesystemInfo *fs, - Error **errp) -{ - Error *err =3D NULL; - DIR *dir; - char *dirpath; - struct dirent *entry; - - dirpath =3D g_strdup_printf("%s/slaves", syspath); - dir =3D opendir(dirpath); - if (!dir) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "opendir(\"%s\")", dirpath); - } - g_free(dirpath); - return; - } - - for (;;) { - errno =3D 0; - entry =3D readdir(dir); - if (entry =3D=3D NULL) { - if (errno) { - error_setg_errno(errp, errno, "readdir(\"%s\")", dirpath); - } - break; - } - - if (entry->d_type =3D=3D DT_LNK) { - char *path; - - g_debug(" slave device '%s'", entry->d_name); - path =3D g_strdup_printf("%s/slaves/%s", syspath, entry->d_nam= e); - build_guest_fsinfo_for_device(path, fs, &err); - g_free(path); - - if (err) { - error_propagate(errp, err); - break; - } - } - } - - g_free(dirpath); - closedir(dir); -} - -static bool is_disk_virtual(const char *devpath, Error **errp) -{ - g_autofree char *syspath =3D realpath(devpath, NULL); - - if (!syspath) { - error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); - return false; - } - return strstr(syspath, "/devices/virtual/block/") !=3D NULL; -} - -/* Dispatch to functions for virtual/real device */ -static void build_guest_fsinfo_for_device(char const *devpath, - GuestFilesystemInfo *fs, - Error **errp) -{ - ERRP_GUARD(); - g_autofree char *syspath =3D NULL; - bool is_virtual =3D false; - - syspath =3D realpath(devpath, NULL); - if (!syspath) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); - return; - } - - /* ENOENT: This devpath may not exist because of container config = */ - if (!fs->name) { - fs->name =3D g_path_get_basename(devpath); - } - return; - } - - if (!fs->name) { - fs->name =3D g_path_get_basename(syspath); - } - - g_debug(" parse sysfs path '%s'", syspath); - is_virtual =3D is_disk_virtual(syspath, errp); - if (*errp !=3D NULL) { - return; - } - if (is_virtual) { - build_guest_fsinfo_for_virtual_device(syspath, fs, errp); - } else { - build_guest_fsinfo_for_real_device(syspath, fs, errp); - } -} - -#ifdef CONFIG_LIBUDEV - -/* - * Wrapper around build_guest_fsinfo_for_device() for getting just - * the disk address. - */ -static GuestDiskAddress *get_disk_address(const char *syspath, Error **err= p) -{ - g_autoptr(GuestFilesystemInfo) fs =3D NULL; - - fs =3D g_new0(GuestFilesystemInfo, 1); - build_guest_fsinfo_for_device(syspath, fs, errp); - if (fs->disk !=3D NULL) { - return g_steal_pointer(&fs->disk->value); - } - return NULL; -} - -static char *get_alias_for_syspath(const char *syspath) -{ - struct udev *udev =3D NULL; - struct udev_device *udevice =3D NULL; - char *ret =3D NULL; - - udev =3D udev_new(); - if (udev =3D=3D NULL) { - g_debug("failed to query udev"); - goto out; - } - udevice =3D udev_device_new_from_syspath(udev, syspath); - if (udevice =3D=3D NULL) { - g_debug("failed to query udev for path: %s", syspath); - goto out; - } else { - const char *alias =3D udev_device_get_property_value( - udevice, "DM_NAME"); - /* - * NULL means there was an error and empty string means there is no - * alias. In case of no alias we return NULL instead of empty stri= ng. - */ - if (alias =3D=3D NULL) { - g_debug("failed to query udev for device alias for: %s", - syspath); - } else if (*alias !=3D 0) { - ret =3D g_strdup(alias); - } - } - -out: - udev_unref(udev); - udev_device_unref(udevice); - return ret; -} - -static char *get_device_for_syspath(const char *syspath) -{ - struct udev *udev =3D NULL; - struct udev_device *udevice =3D NULL; - char *ret =3D NULL; - - udev =3D udev_new(); - if (udev =3D=3D NULL) { - g_debug("failed to query udev"); - goto out; - } - udevice =3D udev_device_new_from_syspath(udev, syspath); - if (udevice =3D=3D NULL) { - g_debug("failed to query udev for path: %s", syspath); - goto out; - } else { - ret =3D g_strdup(udev_device_get_devnode(udevice)); - } - -out: - udev_unref(udev); - udev_device_unref(udevice); - return ret; -} - -static void get_disk_deps(const char *disk_dir, GuestDiskInfo *disk) -{ - g_autofree char *deps_dir =3D NULL; - const gchar *dep; - GDir *dp_deps =3D NULL; - - /* List dependent disks */ - deps_dir =3D g_strdup_printf("%s/slaves", disk_dir); - g_debug(" listing entries in: %s", deps_dir); - dp_deps =3D g_dir_open(deps_dir, 0, NULL); - if (dp_deps =3D=3D NULL) { - g_debug("failed to list entries in %s", deps_dir); - return; - } - disk->has_dependencies =3D true; - while ((dep =3D g_dir_read_name(dp_deps)) !=3D NULL) { - g_autofree char *dep_dir =3D NULL; - char *dev_name; - - /* Add dependent disks */ - dep_dir =3D g_strdup_printf("%s/%s", deps_dir, dep); - dev_name =3D get_device_for_syspath(dep_dir); - if (dev_name !=3D NULL) { - g_debug(" adding dependent device: %s", dev_name); - QAPI_LIST_PREPEND(disk->dependencies, dev_name); - } - } - g_dir_close(dp_deps); -} - -/* - * Detect partitions subdirectory, name is "" or - * "p" - * - * @disk_name -- last component of /sys path (e.g. sda) - * @disk_dir -- sys path of the disk (e.g. /sys/block/sda) - * @disk_dev -- device node of the disk (e.g. /dev/sda) - */ -static GuestDiskInfoList *get_disk_partitions( - GuestDiskInfoList *list, - const char *disk_name, const char *disk_dir, - const char *disk_dev) -{ - GuestDiskInfoList *ret =3D list; - struct dirent *de_disk; - DIR *dp_disk =3D NULL; - size_t len =3D strlen(disk_name); - - dp_disk =3D opendir(disk_dir); - while ((de_disk =3D readdir(dp_disk)) !=3D NULL) { - g_autofree char *partition_dir =3D NULL; - char *dev_name; - GuestDiskInfo *partition; - - if (!(de_disk->d_type & DT_DIR)) { - continue; - } - - if (!(strncmp(disk_name, de_disk->d_name, len) =3D=3D 0 && - ((*(de_disk->d_name + len) =3D=3D 'p' && - isdigit(*(de_disk->d_name + len + 1))) || - isdigit(*(de_disk->d_name + len))))) { - continue; - } - - partition_dir =3D g_strdup_printf("%s/%s", - disk_dir, de_disk->d_name); - dev_name =3D get_device_for_syspath(partition_dir); - if (dev_name =3D=3D NULL) { - g_debug("Failed to get device name for syspath: %s", - disk_dir); - continue; - } - partition =3D g_new0(GuestDiskInfo, 1); - partition->name =3D dev_name; - partition->partition =3D true; - partition->has_dependencies =3D true; - /* Add parent disk as dependent for easier tracking of hierarchy */ - QAPI_LIST_PREPEND(partition->dependencies, g_strdup(disk_dev)); - - QAPI_LIST_PREPEND(ret, partition); - } - closedir(dp_disk); - - return ret; -} - -static void get_nvme_smart(GuestDiskInfo *disk) -{ - int fd; - GuestNVMeSmart *smart; - NvmeSmartLog log =3D {0}; - struct nvme_admin_cmd cmd =3D { - .opcode =3D NVME_ADM_CMD_GET_LOG_PAGE, - .nsid =3D NVME_NSID_BROADCAST, - .addr =3D (uintptr_t)&log, - .data_len =3D sizeof(log), - .cdw10 =3D NVME_LOG_SMART_INFO | (1 << 15) /* RAE bit */ - | (((sizeof(log) >> 2) - 1) << 16) - }; - - fd =3D qga_open_cloexec(disk->name, O_RDONLY, 0); - if (fd =3D=3D -1) { - g_debug("Failed to open device: %s: %s", disk->name, g_strerror(er= rno)); - return; - } - - if (ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd)) { - g_debug("Failed to get smart: %s: %s", disk->name, g_strerror(errn= o)); - close(fd); - return; - } - - disk->smart =3D g_new0(GuestDiskSmart, 1); - disk->smart->type =3D GUEST_DISK_BUS_TYPE_NVME; - - smart =3D &disk->smart->u.nvme; - smart->critical_warning =3D log.critical_warning; - smart->temperature =3D lduw_le_p(&log.temperature); /* unaligned field= */ - smart->available_spare =3D log.available_spare; - smart->available_spare_threshold =3D log.available_spare_threshold; - smart->percentage_used =3D log.percentage_used; - smart->data_units_read_lo =3D le64_to_cpu(log.data_units_read[0]); - smart->data_units_read_hi =3D le64_to_cpu(log.data_units_read[1]); - smart->data_units_written_lo =3D le64_to_cpu(log.data_units_written[0]= ); - smart->data_units_written_hi =3D le64_to_cpu(log.data_units_written[1]= ); - smart->host_read_commands_lo =3D le64_to_cpu(log.host_read_commands[0]= ); - smart->host_read_commands_hi =3D le64_to_cpu(log.host_read_commands[1]= ); - smart->host_write_commands_lo =3D le64_to_cpu(log.host_write_commands[= 0]); - smart->host_write_commands_hi =3D le64_to_cpu(log.host_write_commands[= 1]); - smart->controller_busy_time_lo =3D le64_to_cpu(log.controller_busy_tim= e[0]); - smart->controller_busy_time_hi =3D le64_to_cpu(log.controller_busy_tim= e[1]); - smart->power_cycles_lo =3D le64_to_cpu(log.power_cycles[0]); - smart->power_cycles_hi =3D le64_to_cpu(log.power_cycles[1]); - smart->power_on_hours_lo =3D le64_to_cpu(log.power_on_hours[0]); - smart->power_on_hours_hi =3D le64_to_cpu(log.power_on_hours[1]); - smart->unsafe_shutdowns_lo =3D le64_to_cpu(log.unsafe_shutdowns[0]); - smart->unsafe_shutdowns_hi =3D le64_to_cpu(log.unsafe_shutdowns[1]); - smart->media_errors_lo =3D le64_to_cpu(log.media_errors[0]); - smart->media_errors_hi =3D le64_to_cpu(log.media_errors[1]); - smart->number_of_error_log_entries_lo =3D - le64_to_cpu(log.number_of_error_log_entries[0]); - smart->number_of_error_log_entries_hi =3D - le64_to_cpu(log.number_of_error_log_entries[1]); - - close(fd); -} - -static void get_disk_smart(GuestDiskInfo *disk) -{ - if (disk->address - && (disk->address->bus_type =3D=3D GUEST_DISK_BUS_TYPE_NVME)) { - get_nvme_smart(disk); - } -} - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - GuestDiskInfoList *ret =3D NULL; - GuestDiskInfo *disk; - DIR *dp =3D NULL; - struct dirent *de =3D NULL; - - g_debug("listing /sys/block directory"); - dp =3D opendir("/sys/block"); - if (dp =3D=3D NULL) { - error_setg_errno(errp, errno, "Can't open directory \"/sys/block\"= "); - return NULL; - } - while ((de =3D readdir(dp)) !=3D NULL) { - g_autofree char *disk_dir =3D NULL, *line =3D NULL, - *size_path =3D NULL; - char *dev_name; - Error *local_err =3D NULL; - if (de->d_type !=3D DT_LNK) { - g_debug(" skipping entry: %s", de->d_name); - continue; - } - - /* Check size and skip zero-sized disks */ - g_debug(" checking disk size"); - size_path =3D g_strdup_printf("/sys/block/%s/size", de->d_name); - if (!g_file_get_contents(size_path, &line, NULL, NULL)) { - g_debug(" failed to read disk size"); - continue; - } - if (g_strcmp0(line, "0\n") =3D=3D 0) { - g_debug(" skipping zero-sized disk"); - continue; - } - - g_debug(" adding %s", de->d_name); - disk_dir =3D g_strdup_printf("/sys/block/%s", de->d_name); - dev_name =3D get_device_for_syspath(disk_dir); - if (dev_name =3D=3D NULL) { - g_debug("Failed to get device name for syspath: %s", - disk_dir); - continue; - } - disk =3D g_new0(GuestDiskInfo, 1); - disk->name =3D dev_name; - disk->partition =3D false; - disk->alias =3D get_alias_for_syspath(disk_dir); - QAPI_LIST_PREPEND(ret, disk); - - /* Get address for non-virtual devices */ - bool is_virtual =3D is_disk_virtual(disk_dir, &local_err); - if (local_err !=3D NULL) { - g_debug(" failed to check disk path, ignoring error: %s", - error_get_pretty(local_err)); - error_free(local_err); - local_err =3D NULL; - /* Don't try to get the address */ - is_virtual =3D true; - } - if (!is_virtual) { - disk->address =3D get_disk_address(disk_dir, &local_err); - if (local_err !=3D NULL) { - g_debug(" failed to get device info, ignoring error: %s", - error_get_pretty(local_err)); - error_free(local_err); - local_err =3D NULL; - } - } - - get_disk_deps(disk_dir, disk); - get_disk_smart(disk); - ret =3D get_disk_partitions(ret, de->d_name, disk_dir, dev_name); - } - - closedir(dp); - - return ret; -} - -#else - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -#endif - -/* Return a list of the disk device(s)' info which @mount lies on */ -static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount, - Error **errp) -{ - GuestFilesystemInfo *fs =3D g_malloc0(sizeof(*fs)); - struct statvfs buf; - unsigned long used, nonroot_total, fr_size; - char *devpath =3D g_strdup_printf("/sys/dev/block/%u:%u", - mount->devmajor, mount->devminor); - - fs->mountpoint =3D g_strdup(mount->dirname); - fs->type =3D g_strdup(mount->devtype); - build_guest_fsinfo_for_device(devpath, fs, errp); - - if (statvfs(fs->mountpoint, &buf) =3D=3D 0) { - fr_size =3D buf.f_frsize; - used =3D buf.f_blocks - buf.f_bfree; - nonroot_total =3D used + buf.f_bavail; - fs->used_bytes =3D used * fr_size; - fs->total_bytes =3D nonroot_total * fr_size; - fs->total_bytes_privileged =3D buf.f_blocks * fr_size; - - fs->has_total_bytes =3D true; - fs->has_total_bytes_privileged =3D true; - fs->has_used_bytes =3D true; - } - - g_free(devpath); - - return fs; -} - -GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) -{ - FsMountList mounts; - struct FsMount *mount; - GuestFilesystemInfoList *ret =3D NULL; - Error *local_err =3D NULL; - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return NULL; - } - - QTAILQ_FOREACH(mount, &mounts, next) { - g_debug("Building guest fsinfo for '%s'", mount->dirname); - - QAPI_LIST_PREPEND(ret, build_guest_fsinfo(mount, &local_err)); - if (local_err) { - error_propagate(errp, local_err); - qapi_free_GuestFilesystemInfoList(ret); - ret =3D NULL; - break; - } - } - - free_fs_mount_list(&mounts); - return ret; -} -#endif /* CONFIG_FSFREEZE */ - -#if defined(CONFIG_FSTRIM) -/* - * Walk list of mounted file systems in the guest, and trim them. - */ -GuestFilesystemTrimResponse * -qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) -{ - GuestFilesystemTrimResponse *response; - GuestFilesystemTrimResult *result; - int ret =3D 0; - FsMountList mounts; - struct FsMount *mount; - int fd; - struct fstrim_range r; - - slog("guest-fstrim called"); - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, errp)) { - return NULL; - } - - response =3D g_malloc0(sizeof(*response)); - - QTAILQ_FOREACH(mount, &mounts, next) { - result =3D g_malloc0(sizeof(*result)); - result->path =3D g_strdup(mount->dirname); - - QAPI_LIST_PREPEND(response->paths, result); - - fd =3D qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd =3D=3D -1) { - result->error =3D g_strdup_printf("failed to open: %s", - strerror(errno)); - continue; - } - - /* We try to cull filesystems we know won't work in advance, but o= ther - * filesystems may not implement fstrim for less obvious reasons. - * These will report EOPNOTSUPP; while in some other cases ENOTTY - * will be reported (e.g. CD-ROMs). - * Any other error means an unexpected error. - */ - r.start =3D 0; - r.len =3D -1; - r.minlen =3D has_minimum ? minimum : 0; - ret =3D ioctl(fd, FITRIM, &r); - if (ret =3D=3D -1) { - if (errno =3D=3D ENOTTY || errno =3D=3D EOPNOTSUPP) { - result->error =3D g_strdup("trim not supported"); - } else { - result->error =3D g_strdup_printf("failed to trim: %s", - strerror(errno)); - } - close(fd); - continue; - } - - result->has_minimum =3D true; - result->minimum =3D r.minlen; - result->has_trimmed =3D true; - result->trimmed =3D r.len; - close(fd); - } - - free_fs_mount_list(&mounts); - return response; -} -#endif /* CONFIG_FSTRIM */ - -#endif /* __linux__ */ - #if defined(__linux__) || defined(__FreeBSD__) void qmp_guest_set_user_password(const char *username, const char *password, --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790832; cv=none; d=zohomail.com; s=zohoarc; b=PePVBoDCQwFDHsVI4jytuvFLqRC8EANHrz37CK1KFb0jwJh4oVfm7lhKZPupXFLrAP01mKFRsRJFgD6sE42Ct8MNIQ2aEHS0P3pLy4J51RR85lADb00ByA2v01NQ8D1p8UxSWAtIUbBl5bUF37A2WH9B6ko3oQhZGOfeM/AIdS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790832; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Iff7MwXFHB5Wb/dYGR6Gzh5ZIQoOnBEqwIUmrBRHZBE=; b=Ura+5xoXK4xtJENRX/MsqiDzl8vIpGLFJcah4E8ES8tqmnGZpFdPLqqEdDMJj0AFsBCvVG2bOnZILLAsfrpkLS9mwTw2hEmpAwRzC3ZZem34J9NK1DK+D9aQZsDldow3pETAlfEMshREj2E8ZY7TeL7/Wtg7RH3br/XAndeMNys= 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+importer2=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 1720790832395177.27870641852599; Fri, 12 Jul 2024 06:27:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI1-0005xw-8S; Fri, 12 Jul 2024 09:26:21 -0400 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 1sSGHB-0002C7-C1 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGH8-0003l2-EU for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:29 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-NAbRZCydOC6Yg_3bqQFivA-1; Fri, 12 Jul 2024 09:25:24 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8DBA319560B3; Fri, 12 Jul 2024 13:25:23 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8405F1955F40; Fri, 12 Jul 2024 13:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790725; 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: in-reply-to:in-reply-to:references:references; bh=Iff7MwXFHB5Wb/dYGR6Gzh5ZIQoOnBEqwIUmrBRHZBE=; b=DQEY/Ufq/wSLpaWu7dQnOqOURS+gD0oNlhnZQqFb08tOrWZW9lDkHP0iBTlBf4K3FVg8Su 92Rn/TuwV4DifwxRNBoYEKubongdKhv+f5no2NnTKp3QVyEdPzkwlC0eulv15NFIUuTa5a jEzwo+d3tg/zZES4dMjZbHjttM2A+5w= X-MC-Unique: NAbRZCydOC6Yg_3bqQFivA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 05/22] qga: move linux disk/cpu stats command impls to commands-linux.c Date: Fri, 12 Jul 2024 14:24:42 +0100 Message-ID: <20240712132459.3974109-6-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790834191116300 The qmp_guest_{diskstats,cpustats} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c This also removes a "#ifdef CONFIG_LINUX" that was nested inside a "#ifdef __linux__". Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 195 ++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 199 ------------------------------------------- 2 files changed, 195 insertions(+), 199 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 084e6c9e85..c0e8bd4062 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -1594,3 +1594,198 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLi= st *vcpus, Error **errp) =20 return processed; } + +#define MAX_NAME_LEN 128 +static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp) +{ + GuestDiskStatsInfoList *head =3D NULL, **tail =3D &head; + const char *diskstats =3D "/proc/diskstats"; + FILE *fp; + size_t n; + char *line =3D NULL; + + fp =3D fopen(diskstats, "r"); + if (fp =3D=3D NULL) { + error_setg_errno(errp, errno, "open(\"%s\")", diskstats); + return NULL; + } + + while (getline(&line, &n, fp) !=3D -1) { + g_autofree GuestDiskStatsInfo *diskstatinfo =3D NULL; + g_autofree GuestDiskStats *diskstat =3D NULL; + char dev_name[MAX_NAME_LEN]; + unsigned int ios_pgr, tot_ticks, rq_ticks, wr_ticks, dc_ticks, fl_= ticks; + unsigned long rd_ios, rd_merges_or_rd_sec, rd_ticks_or_wr_sec, wr_= ios; + unsigned long wr_merges, rd_sec_or_wr_ios, wr_sec; + unsigned long dc_ios, dc_merges, dc_sec, fl_ios; + unsigned int major, minor; + int i; + + i =3D sscanf(line, "%u %u %s %lu %lu %lu" + "%lu %lu %lu %lu %u %u %u %u" + "%lu %lu %lu %u %lu %u", + &major, &minor, dev_name, + &rd_ios, &rd_merges_or_rd_sec, &rd_sec_or_wr_ios, + &rd_ticks_or_wr_sec, &wr_ios, &wr_merges, &wr_sec, + &wr_ticks, &ios_pgr, &tot_ticks, &rq_ticks, + &dc_ios, &dc_merges, &dc_sec, &dc_ticks, + &fl_ios, &fl_ticks); + + if (i < 7) { + continue; + } + + diskstatinfo =3D g_new0(GuestDiskStatsInfo, 1); + diskstatinfo->name =3D g_strdup(dev_name); + diskstatinfo->major =3D major; + diskstatinfo->minor =3D minor; + + diskstat =3D g_new0(GuestDiskStats, 1); + if (i =3D=3D 7) { + diskstat->has_read_ios =3D true; + diskstat->read_ios =3D rd_ios; + diskstat->has_read_sectors =3D true; + diskstat->read_sectors =3D rd_merges_or_rd_sec; + diskstat->has_write_ios =3D true; + diskstat->write_ios =3D rd_sec_or_wr_ios; + diskstat->has_write_sectors =3D true; + diskstat->write_sectors =3D rd_ticks_or_wr_sec; + } + if (i >=3D 14) { + diskstat->has_read_ios =3D true; + diskstat->read_ios =3D rd_ios; + diskstat->has_read_sectors =3D true; + diskstat->read_sectors =3D rd_sec_or_wr_ios; + diskstat->has_read_merges =3D true; + diskstat->read_merges =3D rd_merges_or_rd_sec; + diskstat->has_read_ticks =3D true; + diskstat->read_ticks =3D rd_ticks_or_wr_sec; + diskstat->has_write_ios =3D true; + diskstat->write_ios =3D wr_ios; + diskstat->has_write_sectors =3D true; + diskstat->write_sectors =3D wr_sec; + diskstat->has_write_merges =3D true; + diskstat->write_merges =3D wr_merges; + diskstat->has_write_ticks =3D true; + diskstat->write_ticks =3D wr_ticks; + diskstat->has_ios_pgr =3D true; + diskstat->ios_pgr =3D ios_pgr; + diskstat->has_total_ticks =3D true; + diskstat->total_ticks =3D tot_ticks; + diskstat->has_weight_ticks =3D true; + diskstat->weight_ticks =3D rq_ticks; + } + if (i >=3D 18) { + diskstat->has_discard_ios =3D true; + diskstat->discard_ios =3D dc_ios; + diskstat->has_discard_merges =3D true; + diskstat->discard_merges =3D dc_merges; + diskstat->has_discard_sectors =3D true; + diskstat->discard_sectors =3D dc_sec; + diskstat->has_discard_ticks =3D true; + diskstat->discard_ticks =3D dc_ticks; + } + if (i >=3D 20) { + diskstat->has_flush_ios =3D true; + diskstat->flush_ios =3D fl_ios; + diskstat->has_flush_ticks =3D true; + diskstat->flush_ticks =3D fl_ticks; + } + + diskstatinfo->stats =3D g_steal_pointer(&diskstat); + QAPI_LIST_APPEND(tail, diskstatinfo); + diskstatinfo =3D NULL; + } + free(line); + fclose(fp); + return head; +} + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + return guest_get_diskstats(errp); +} + +GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) +{ + GuestCpuStatsList *head =3D NULL, **tail =3D &head; + const char *cpustats =3D "/proc/stat"; + int clk_tck =3D sysconf(_SC_CLK_TCK); + FILE *fp; + size_t n; + char *line =3D NULL; + + fp =3D fopen(cpustats, "r"); + if (fp =3D=3D NULL) { + error_setg_errno(errp, errno, "open(\"%s\")", cpustats); + return NULL; + } + + while (getline(&line, &n, fp) !=3D -1) { + GuestCpuStats *cpustat =3D NULL; + GuestLinuxCpuStats *linuxcpustat; + int i; + unsigned long user, system, idle, iowait, irq, softirq, steal, gue= st; + unsigned long nice, guest_nice; + char name[64]; + + i =3D sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", + name, &user, &nice, &system, &idle, &iowait, &irq, &sof= tirq, + &steal, &guest, &guest_nice); + + /* drop "cpu 1 2 3 ...", get "cpuX 1 2 3 ..." only */ + if ((i =3D=3D EOF) || strncmp(name, "cpu", 3) || (name[3] =3D=3D '= \0')) { + continue; + } + + if (i < 5) { + slog("Parsing cpu stat from %s failed, see \"man proc\"", cpus= tats); + break; + } + + cpustat =3D g_new0(GuestCpuStats, 1); + cpustat->type =3D GUEST_CPU_STATS_TYPE_LINUX; + + linuxcpustat =3D &cpustat->u.q_linux; + linuxcpustat->cpu =3D atoi(&name[3]); + linuxcpustat->user =3D user * 1000 / clk_tck; + linuxcpustat->nice =3D nice * 1000 / clk_tck; + linuxcpustat->system =3D system * 1000 / clk_tck; + linuxcpustat->idle =3D idle * 1000 / clk_tck; + + if (i > 5) { + linuxcpustat->has_iowait =3D true; + linuxcpustat->iowait =3D iowait * 1000 / clk_tck; + } + + if (i > 6) { + linuxcpustat->has_irq =3D true; + linuxcpustat->irq =3D irq * 1000 / clk_tck; + linuxcpustat->has_softirq =3D true; + linuxcpustat->softirq =3D softirq * 1000 / clk_tck; + } + + if (i > 8) { + linuxcpustat->has_steal =3D true; + linuxcpustat->steal =3D steal * 1000 / clk_tck; + } + + if (i > 9) { + linuxcpustat->has_guest =3D true; + linuxcpustat->guest =3D guest * 1000 / clk_tck; + } + + if (i > 10) { + linuxcpustat->has_guest =3D true; + linuxcpustat->guest =3D guest * 1000 / clk_tck; + linuxcpustat->has_guestnice =3D true; + linuxcpustat->guestnice =3D guest_nice * 1000 / clk_tck; + } + + QAPI_LIST_APPEND(tail, cpustat); + } + + free(line); + fclose(fp); + return head; +} diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 98aafc45f3..5da60e65ab 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1195,205 +1195,6 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_in= fo(Error **errp) return info; } =20 -#define MAX_NAME_LEN 128 -static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp) -{ -#ifdef CONFIG_LINUX - GuestDiskStatsInfoList *head =3D NULL, **tail =3D &head; - const char *diskstats =3D "/proc/diskstats"; - FILE *fp; - size_t n; - char *line =3D NULL; - - fp =3D fopen(diskstats, "r"); - if (fp =3D=3D NULL) { - error_setg_errno(errp, errno, "open(\"%s\")", diskstats); - return NULL; - } - - while (getline(&line, &n, fp) !=3D -1) { - g_autofree GuestDiskStatsInfo *diskstatinfo =3D NULL; - g_autofree GuestDiskStats *diskstat =3D NULL; - char dev_name[MAX_NAME_LEN]; - unsigned int ios_pgr, tot_ticks, rq_ticks, wr_ticks, dc_ticks, fl_= ticks; - unsigned long rd_ios, rd_merges_or_rd_sec, rd_ticks_or_wr_sec, wr_= ios; - unsigned long wr_merges, rd_sec_or_wr_ios, wr_sec; - unsigned long dc_ios, dc_merges, dc_sec, fl_ios; - unsigned int major, minor; - int i; - - i =3D sscanf(line, "%u %u %s %lu %lu %lu" - "%lu %lu %lu %lu %u %u %u %u" - "%lu %lu %lu %u %lu %u", - &major, &minor, dev_name, - &rd_ios, &rd_merges_or_rd_sec, &rd_sec_or_wr_ios, - &rd_ticks_or_wr_sec, &wr_ios, &wr_merges, &wr_sec, - &wr_ticks, &ios_pgr, &tot_ticks, &rq_ticks, - &dc_ios, &dc_merges, &dc_sec, &dc_ticks, - &fl_ios, &fl_ticks); - - if (i < 7) { - continue; - } - - diskstatinfo =3D g_new0(GuestDiskStatsInfo, 1); - diskstatinfo->name =3D g_strdup(dev_name); - diskstatinfo->major =3D major; - diskstatinfo->minor =3D minor; - - diskstat =3D g_new0(GuestDiskStats, 1); - if (i =3D=3D 7) { - diskstat->has_read_ios =3D true; - diskstat->read_ios =3D rd_ios; - diskstat->has_read_sectors =3D true; - diskstat->read_sectors =3D rd_merges_or_rd_sec; - diskstat->has_write_ios =3D true; - diskstat->write_ios =3D rd_sec_or_wr_ios; - diskstat->has_write_sectors =3D true; - diskstat->write_sectors =3D rd_ticks_or_wr_sec; - } - if (i >=3D 14) { - diskstat->has_read_ios =3D true; - diskstat->read_ios =3D rd_ios; - diskstat->has_read_sectors =3D true; - diskstat->read_sectors =3D rd_sec_or_wr_ios; - diskstat->has_read_merges =3D true; - diskstat->read_merges =3D rd_merges_or_rd_sec; - diskstat->has_read_ticks =3D true; - diskstat->read_ticks =3D rd_ticks_or_wr_sec; - diskstat->has_write_ios =3D true; - diskstat->write_ios =3D wr_ios; - diskstat->has_write_sectors =3D true; - diskstat->write_sectors =3D wr_sec; - diskstat->has_write_merges =3D true; - diskstat->write_merges =3D wr_merges; - diskstat->has_write_ticks =3D true; - diskstat->write_ticks =3D wr_ticks; - diskstat->has_ios_pgr =3D true; - diskstat->ios_pgr =3D ios_pgr; - diskstat->has_total_ticks =3D true; - diskstat->total_ticks =3D tot_ticks; - diskstat->has_weight_ticks =3D true; - diskstat->weight_ticks =3D rq_ticks; - } - if (i >=3D 18) { - diskstat->has_discard_ios =3D true; - diskstat->discard_ios =3D dc_ios; - diskstat->has_discard_merges =3D true; - diskstat->discard_merges =3D dc_merges; - diskstat->has_discard_sectors =3D true; - diskstat->discard_sectors =3D dc_sec; - diskstat->has_discard_ticks =3D true; - diskstat->discard_ticks =3D dc_ticks; - } - if (i >=3D 20) { - diskstat->has_flush_ios =3D true; - diskstat->flush_ios =3D fl_ios; - diskstat->has_flush_ticks =3D true; - diskstat->flush_ticks =3D fl_ticks; - } - - diskstatinfo->stats =3D g_steal_pointer(&diskstat); - QAPI_LIST_APPEND(tail, diskstatinfo); - diskstatinfo =3D NULL; - } - free(line); - fclose(fp); - return head; -#else - g_debug("disk stats reporting available only for Linux"); - return NULL; -#endif -} - -GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) -{ - return guest_get_diskstats(errp); -} - -GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) -{ - GuestCpuStatsList *head =3D NULL, **tail =3D &head; - const char *cpustats =3D "/proc/stat"; - int clk_tck =3D sysconf(_SC_CLK_TCK); - FILE *fp; - size_t n; - char *line =3D NULL; - - fp =3D fopen(cpustats, "r"); - if (fp =3D=3D NULL) { - error_setg_errno(errp, errno, "open(\"%s\")", cpustats); - return NULL; - } - - while (getline(&line, &n, fp) !=3D -1) { - GuestCpuStats *cpustat =3D NULL; - GuestLinuxCpuStats *linuxcpustat; - int i; - unsigned long user, system, idle, iowait, irq, softirq, steal, gue= st; - unsigned long nice, guest_nice; - char name[64]; - - i =3D sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", - name, &user, &nice, &system, &idle, &iowait, &irq, &sof= tirq, - &steal, &guest, &guest_nice); - - /* drop "cpu 1 2 3 ...", get "cpuX 1 2 3 ..." only */ - if ((i =3D=3D EOF) || strncmp(name, "cpu", 3) || (name[3] =3D=3D '= \0')) { - continue; - } - - if (i < 5) { - slog("Parsing cpu stat from %s failed, see \"man proc\"", cpus= tats); - break; - } - - cpustat =3D g_new0(GuestCpuStats, 1); - cpustat->type =3D GUEST_CPU_STATS_TYPE_LINUX; - - linuxcpustat =3D &cpustat->u.q_linux; - linuxcpustat->cpu =3D atoi(&name[3]); - linuxcpustat->user =3D user * 1000 / clk_tck; - linuxcpustat->nice =3D nice * 1000 / clk_tck; - linuxcpustat->system =3D system * 1000 / clk_tck; - linuxcpustat->idle =3D idle * 1000 / clk_tck; - - if (i > 5) { - linuxcpustat->has_iowait =3D true; - linuxcpustat->iowait =3D iowait * 1000 / clk_tck; - } - - if (i > 6) { - linuxcpustat->has_irq =3D true; - linuxcpustat->irq =3D irq * 1000 / clk_tck; - linuxcpustat->has_softirq =3D true; - linuxcpustat->softirq =3D softirq * 1000 / clk_tck; - } - - if (i > 8) { - linuxcpustat->has_steal =3D true; - linuxcpustat->steal =3D steal * 1000 / clk_tck; - } - - if (i > 9) { - linuxcpustat->has_guest =3D true; - linuxcpustat->guest =3D guest * 1000 / clk_tck; - } - - if (i > 10) { - linuxcpustat->has_guest =3D true; - linuxcpustat->guest =3D guest * 1000 / clk_tck; - linuxcpustat->has_guestnice =3D true; - linuxcpustat->guestnice =3D guest_nice * 1000 / clk_tck; - } - - QAPI_LIST_APPEND(tail, cpustat); - } - - free(line); - fclose(fp); - return head; -} =20 #else /* defined(__linux__) */ =20 --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790790; cv=none; d=zohomail.com; s=zohoarc; b=JoC6TIPXEMEACJdL121dQVNTMinoCB1WXXJdKD8F3ezOja5z71wjVnf3DtUHry/XEZmwz6QiSq8gJoWEcDp0DqRnjv/HMas4iSilCznVKp8rjNRtRoPsvFYKJwgsDsPUjQNWUBy7MyjdCAIGHre9eJNVYOjvmNDSk5i+99+YmWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4pLNMZgzEcZH+ABN0fSwaZBCtEDFrs9igcxkhnnQzco=; b=QS70VxV4GpI9EcW0X/qoRttgN/YtXtMRL1LzZ6OnOCEmdJY8O1MCzWr3Re6GOboIeOHQKZSf4ev5xXKwP6n3/8sdd1IopBnZ4Dk6XQDx4Nurhl5uczMKYcZ5yn4/LQBWNgyKOve/b1pcIIV2qap/XHgb23Ye56N4klqnLSP4uiE= 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+importer2=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 1720790790895763.8756469579583; Fri, 12 Jul 2024 06:26:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGHk-0004gw-SD; Fri, 12 Jul 2024 09:26:04 -0400 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 1sSGHG-0002ZD-Op for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHE-0003q3-0L for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:34 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-hm4I8hclNr656ERGDDGGDw-1; Fri, 12 Jul 2024 09:25:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE3461955F69; Fri, 12 Jul 2024 13:25:26 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C72AB1955F40; Fri, 12 Jul 2024 13:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790731; 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: in-reply-to:in-reply-to:references:references; bh=4pLNMZgzEcZH+ABN0fSwaZBCtEDFrs9igcxkhnnQzco=; b=JEGJrELHK/dxhHQj1iynbxtZqP8G//ecI0jcThiuDSn7NhNA98DkHC/q1ueBJvqomVFm57 3ATHyXS5+A++N6ZF9KtskLOKPYhLzRD3zuM5IsO33JfTg6jD8eDQVOZweCU77LTnpsKMms eQhi2J83a2FcNp8TxQUmPk66RcwdgyA= X-MC-Unique: hm4I8hclNr656ERGDDGGDw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 06/22] qga: move linux memory block command impls to commands-linux.c Date: Fri, 12 Jul 2024 14:24:43 +0100 Message-ID: <20240712132459.3974109-7-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790791982116300 The qmp_guest_{set,get}_{memory_blocks,block_info} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c This also removes a "#ifdef CONFIG_LINUX" that was nested inside a "#ifdef __linux__". Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 308 ++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 311 +------------------------------------------ 2 files changed, 309 insertions(+), 310 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index c0e8bd4062..73b13fbaf6 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -1595,6 +1595,314 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLi= st *vcpus, Error **errp) return processed; } =20 + +static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, + int size, Error **errp) +{ + int fd; + int res; + + errno =3D 0; + fd =3D openat(dirfd, pathname, O_RDONLY); + if (fd =3D=3D -1) { + error_setg_errno(errp, errno, "open sysfs file \"%s\"", pathname); + return; + } + + res =3D pread(fd, buf, size, 0); + if (res =3D=3D -1) { + error_setg_errno(errp, errno, "pread sysfs file \"%s\"", pathname); + } else if (res =3D=3D 0) { + error_setg(errp, "pread sysfs file \"%s\": unexpected EOF", pathna= me); + } + close(fd); +} + +static void ga_write_sysfs_file(int dirfd, const char *pathname, + const char *buf, int size, Error **errp) +{ + int fd; + + errno =3D 0; + fd =3D openat(dirfd, pathname, O_WRONLY); + if (fd =3D=3D -1) { + error_setg_errno(errp, errno, "open sysfs file \"%s\"", pathname); + return; + } + + if (pwrite(fd, buf, size, 0) =3D=3D -1) { + error_setg_errno(errp, errno, "pwrite sysfs file \"%s\"", pathname= ); + } + + close(fd); +} + +/* Transfer online/offline status between @mem_blk and the guest system. + * + * On input either @errp or *@errp must be NULL. + * + * In system-to-@mem_blk direction, the following @mem_blk fields are acce= ssed: + * - R: mem_blk->phys_index + * - W: mem_blk->online + * - W: mem_blk->can_offline + * + * In @mem_blk-to-system direction, the following @mem_blk fields are acce= ssed: + * - R: mem_blk->phys_index + * - R: mem_blk->online + *- R: mem_blk->can_offline + * Written members remain unmodified on error. + */ +static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memb= lk, + GuestMemoryBlockResponse *result, + Error **errp) +{ + char *dirpath; + int dirfd; + char *status; + Error *local_err =3D NULL; + + if (!sys2memblk) { + DIR *dp; + + if (!result) { + error_setg(errp, "Internal error, 'result' should not be NULL"= ); + return; + } + errno =3D 0; + dp =3D opendir("/sys/devices/system/memory/"); + /* if there is no 'memory' directory in sysfs, + * we think this VM does not support online/offline memory block, + * any other solution? + */ + if (!dp) { + if (errno =3D=3D ENOENT) { + result->response =3D + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORT= ED; + } + goto out1; + } + closedir(dp); + } + + dirpath =3D g_strdup_printf("/sys/devices/system/memory/memory%" PRId6= 4 "/", + mem_blk->phys_index); + dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); + if (dirfd =3D=3D -1) { + if (sys2memblk) { + error_setg_errno(errp, errno, "open(\"%s\")", dirpath); + } else { + if (errno =3D=3D ENOENT) { + result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_NOT_= FOUND; + } else { + result->response =3D + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; + } + } + g_free(dirpath); + goto out1; + } + g_free(dirpath); + + status =3D g_malloc0(10); + ga_read_sysfs_file(dirfd, "state", status, 10, &local_err); + if (local_err) { + /* treat with sysfs file that not exist in old kernel */ + if (errno =3D=3D ENOENT) { + error_free(local_err); + if (sys2memblk) { + mem_blk->online =3D true; + mem_blk->can_offline =3D false; + } else if (!mem_blk->online) { + result->response =3D + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORT= ED; + } + } else { + if (sys2memblk) { + error_propagate(errp, local_err); + } else { + error_free(local_err); + result->response =3D + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; + } + } + goto out2; + } + + if (sys2memblk) { + char removable =3D '0'; + + mem_blk->online =3D (strncmp(status, "online", 6) =3D=3D 0); + + ga_read_sysfs_file(dirfd, "removable", &removable, 1, &local_err); + if (local_err) { + /* if no 'removable' file, it doesn't support offline mem blk = */ + if (errno =3D=3D ENOENT) { + error_free(local_err); + mem_blk->can_offline =3D false; + } else { + error_propagate(errp, local_err); + } + } else { + mem_blk->can_offline =3D (removable !=3D '0'); + } + } else { + if (mem_blk->online !=3D (strncmp(status, "online", 6) =3D=3D 0)) { + const char *new_state =3D mem_blk->online ? "online" : "offlin= e"; + + ga_write_sysfs_file(dirfd, "state", new_state, strlen(new_stat= e), + &local_err); + if (local_err) { + error_free(local_err); + result->response =3D + GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; + goto out2; + } + + result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_SUCCESS; + result->has_error_code =3D false; + } /* otherwise pretend successful re-(on|off)-lining */ + } + g_free(status); + close(dirfd); + return; + +out2: + g_free(status); + close(dirfd); +out1: + if (!sys2memblk) { + result->has_error_code =3D true; + result->error_code =3D errno; + } +} + +GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) +{ + GuestMemoryBlockList *head, **tail; + Error *local_err =3D NULL; + struct dirent *de; + DIR *dp; + + head =3D NULL; + tail =3D &head; + + dp =3D opendir("/sys/devices/system/memory/"); + if (!dp) { + /* it's ok if this happens to be a system that doesn't expose + * memory blocks via sysfs, but otherwise we should report + * an error + */ + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "Can't open directory" + "\"/sys/devices/system/memory/\""); + } + return NULL; + } + + /* Note: the phys_index of memory block may be discontinuous, + * this is because a memblk is the unit of the Sparse Memory design, w= hich + * allows discontinuous memory ranges (ex. NUMA), so here we should + * traverse the memory block directory. + */ + while ((de =3D readdir(dp)) !=3D NULL) { + GuestMemoryBlock *mem_blk; + + if ((strncmp(de->d_name, "memory", 6) !=3D 0) || + !(de->d_type & DT_DIR)) { + continue; + } + + mem_blk =3D g_malloc0(sizeof *mem_blk); + /* The d_name is "memoryXXX", phys_index is block id, same as XXX= */ + mem_blk->phys_index =3D strtoul(&de->d_name[6], NULL, 10); + mem_blk->has_can_offline =3D true; /* lolspeak ftw */ + transfer_memory_block(mem_blk, true, NULL, &local_err); + if (local_err) { + break; + } + + QAPI_LIST_APPEND(tail, mem_blk); + } + + closedir(dp); + if (local_err =3D=3D NULL) { + /* there's no guest with zero memory blocks */ + if (head =3D=3D NULL) { + error_setg(errp, "guest reported zero memory blocks!"); + } + return head; + } + + qapi_free_GuestMemoryBlockList(head); + error_propagate(errp, local_err); + return NULL; +} + +GuestMemoryBlockResponseList * +qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) +{ + GuestMemoryBlockResponseList *head, **tail; + Error *local_err =3D NULL; + + head =3D NULL; + tail =3D &head; + + while (mem_blks !=3D NULL) { + GuestMemoryBlockResponse *result; + GuestMemoryBlock *current_mem_blk =3D mem_blks->value; + + result =3D g_malloc0(sizeof(*result)); + result->phys_index =3D current_mem_blk->phys_index; + transfer_memory_block(current_mem_blk, false, result, &local_err); + if (local_err) { /* should never happen */ + goto err; + } + + QAPI_LIST_APPEND(tail, result); + mem_blks =3D mem_blks->next; + } + + return head; +err: + qapi_free_GuestMemoryBlockResponseList(head); + error_propagate(errp, local_err); + return NULL; +} + +GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) +{ + Error *local_err =3D NULL; + char *dirpath; + int dirfd; + char *buf; + GuestMemoryBlockInfo *info; + + dirpath =3D g_strdup_printf("/sys/devices/system/memory/"); + dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); + if (dirfd =3D=3D -1) { + error_setg_errno(errp, errno, "open(\"%s\")", dirpath); + g_free(dirpath); + return NULL; + } + g_free(dirpath); + + buf =3D g_malloc0(20); + ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); + close(dirfd); + if (local_err) { + g_free(buf); + error_propagate(errp, local_err); + return NULL; + } + + info =3D g_new0(GuestMemoryBlockInfo, 1); + info->size =3D strtol(buf, NULL, 16); /* the unit is bytes */ + + g_free(buf); + + return info; +} + #define MAX_NAME_LEN 128 static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp) { diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 5da60e65ab..2a3bef7445 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -887,316 +887,7 @@ void qmp_guest_set_user_password(const char *username, } #endif /* __linux__ || __FreeBSD__ */ =20 -#ifdef __linux__ -static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, - int size, Error **errp) -{ - int fd; - int res; - - errno =3D 0; - fd =3D openat(dirfd, pathname, O_RDONLY); - if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "open sysfs file \"%s\"", pathname); - return; - } - - res =3D pread(fd, buf, size, 0); - if (res =3D=3D -1) { - error_setg_errno(errp, errno, "pread sysfs file \"%s\"", pathname); - } else if (res =3D=3D 0) { - error_setg(errp, "pread sysfs file \"%s\": unexpected EOF", pathna= me); - } - close(fd); -} - -static void ga_write_sysfs_file(int dirfd, const char *pathname, - const char *buf, int size, Error **errp) -{ - int fd; - - errno =3D 0; - fd =3D openat(dirfd, pathname, O_WRONLY); - if (fd =3D=3D -1) { - error_setg_errno(errp, errno, "open sysfs file \"%s\"", pathname); - return; - } - - if (pwrite(fd, buf, size, 0) =3D=3D -1) { - error_setg_errno(errp, errno, "pwrite sysfs file \"%s\"", pathname= ); - } - - close(fd); -} - -/* Transfer online/offline status between @mem_blk and the guest system. - * - * On input either @errp or *@errp must be NULL. - * - * In system-to-@mem_blk direction, the following @mem_blk fields are acce= ssed: - * - R: mem_blk->phys_index - * - W: mem_blk->online - * - W: mem_blk->can_offline - * - * In @mem_blk-to-system direction, the following @mem_blk fields are acce= ssed: - * - R: mem_blk->phys_index - * - R: mem_blk->online - *- R: mem_blk->can_offline - * Written members remain unmodified on error. - */ -static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memb= lk, - GuestMemoryBlockResponse *result, - Error **errp) -{ - char *dirpath; - int dirfd; - char *status; - Error *local_err =3D NULL; - - if (!sys2memblk) { - DIR *dp; - - if (!result) { - error_setg(errp, "Internal error, 'result' should not be NULL"= ); - return; - } - errno =3D 0; - dp =3D opendir("/sys/devices/system/memory/"); - /* if there is no 'memory' directory in sysfs, - * we think this VM does not support online/offline memory block, - * any other solution? - */ - if (!dp) { - if (errno =3D=3D ENOENT) { - result->response =3D - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORT= ED; - } - goto out1; - } - closedir(dp); - } - - dirpath =3D g_strdup_printf("/sys/devices/system/memory/memory%" PRId6= 4 "/", - mem_blk->phys_index); - dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); - if (dirfd =3D=3D -1) { - if (sys2memblk) { - error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - } else { - if (errno =3D=3D ENOENT) { - result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_NOT_= FOUND; - } else { - result->response =3D - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; - } - } - g_free(dirpath); - goto out1; - } - g_free(dirpath); - - status =3D g_malloc0(10); - ga_read_sysfs_file(dirfd, "state", status, 10, &local_err); - if (local_err) { - /* treat with sysfs file that not exist in old kernel */ - if (errno =3D=3D ENOENT) { - error_free(local_err); - if (sys2memblk) { - mem_blk->online =3D true; - mem_blk->can_offline =3D false; - } else if (!mem_blk->online) { - result->response =3D - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORT= ED; - } - } else { - if (sys2memblk) { - error_propagate(errp, local_err); - } else { - error_free(local_err); - result->response =3D - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; - } - } - goto out2; - } - - if (sys2memblk) { - char removable =3D '0'; - - mem_blk->online =3D (strncmp(status, "online", 6) =3D=3D 0); - - ga_read_sysfs_file(dirfd, "removable", &removable, 1, &local_err); - if (local_err) { - /* if no 'removable' file, it doesn't support offline mem blk = */ - if (errno =3D=3D ENOENT) { - error_free(local_err); - mem_blk->can_offline =3D false; - } else { - error_propagate(errp, local_err); - } - } else { - mem_blk->can_offline =3D (removable !=3D '0'); - } - } else { - if (mem_blk->online !=3D (strncmp(status, "online", 6) =3D=3D 0)) { - const char *new_state =3D mem_blk->online ? "online" : "offlin= e"; - - ga_write_sysfs_file(dirfd, "state", new_state, strlen(new_stat= e), - &local_err); - if (local_err) { - error_free(local_err); - result->response =3D - GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; - goto out2; - } - - result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_SUCCESS; - result->has_error_code =3D false; - } /* otherwise pretend successful re-(on|off)-lining */ - } - g_free(status); - close(dirfd); - return; - -out2: - g_free(status); - close(dirfd); -out1: - if (!sys2memblk) { - result->has_error_code =3D true; - result->error_code =3D errno; - } -} - -GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) -{ - GuestMemoryBlockList *head, **tail; - Error *local_err =3D NULL; - struct dirent *de; - DIR *dp; - - head =3D NULL; - tail =3D &head; - - dp =3D opendir("/sys/devices/system/memory/"); - if (!dp) { - /* it's ok if this happens to be a system that doesn't expose - * memory blocks via sysfs, but otherwise we should report - * an error - */ - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "Can't open directory" - "\"/sys/devices/system/memory/\""); - } - return NULL; - } - - /* Note: the phys_index of memory block may be discontinuous, - * this is because a memblk is the unit of the Sparse Memory design, w= hich - * allows discontinuous memory ranges (ex. NUMA), so here we should - * traverse the memory block directory. - */ - while ((de =3D readdir(dp)) !=3D NULL) { - GuestMemoryBlock *mem_blk; - - if ((strncmp(de->d_name, "memory", 6) !=3D 0) || - !(de->d_type & DT_DIR)) { - continue; - } - - mem_blk =3D g_malloc0(sizeof *mem_blk); - /* The d_name is "memoryXXX", phys_index is block id, same as XXX= */ - mem_blk->phys_index =3D strtoul(&de->d_name[6], NULL, 10); - mem_blk->has_can_offline =3D true; /* lolspeak ftw */ - transfer_memory_block(mem_blk, true, NULL, &local_err); - if (local_err) { - break; - } - - QAPI_LIST_APPEND(tail, mem_blk); - } - - closedir(dp); - if (local_err =3D=3D NULL) { - /* there's no guest with zero memory blocks */ - if (head =3D=3D NULL) { - error_setg(errp, "guest reported zero memory blocks!"); - } - return head; - } - - qapi_free_GuestMemoryBlockList(head); - error_propagate(errp, local_err); - return NULL; -} - -GuestMemoryBlockResponseList * -qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) -{ - GuestMemoryBlockResponseList *head, **tail; - Error *local_err =3D NULL; - - head =3D NULL; - tail =3D &head; - - while (mem_blks !=3D NULL) { - GuestMemoryBlockResponse *result; - GuestMemoryBlock *current_mem_blk =3D mem_blks->value; - - result =3D g_malloc0(sizeof(*result)); - result->phys_index =3D current_mem_blk->phys_index; - transfer_memory_block(current_mem_blk, false, result, &local_err); - if (local_err) { /* should never happen */ - goto err; - } - - QAPI_LIST_APPEND(tail, result); - mem_blks =3D mem_blks->next; - } - - return head; -err: - qapi_free_GuestMemoryBlockResponseList(head); - error_propagate(errp, local_err); - return NULL; -} - -GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) -{ - Error *local_err =3D NULL; - char *dirpath; - int dirfd; - char *buf; - GuestMemoryBlockInfo *info; - - dirpath =3D g_strdup_printf("/sys/devices/system/memory/"); - dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); - if (dirfd =3D=3D -1) { - error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - g_free(dirpath); - return NULL; - } - g_free(dirpath); - - buf =3D g_malloc0(20); - ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); - close(dirfd); - if (local_err) { - g_free(buf); - error_propagate(errp, local_err); - return NULL; - } - - info =3D g_new0(GuestMemoryBlockInfo, 1); - info->size =3D strtol(buf, NULL, 16); /* the unit is bytes */ - - g_free(buf); - - return info; -} - - -#else /* defined(__linux__) */ +#ifndef __linux__ =20 void qmp_guest_suspend_disk(Error **errp) { --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790769; cv=none; d=zohomail.com; s=zohoarc; b=mj4u9C07LJCz/5Sy7wT+cJTm7m2LsX/8eDHxZBfv4EYbZmQ6sxgCqyIxk3t3c+t5bnmrT5tBdtPyhxKuZD4/lFyQTc7fZKfDCENiIvStuXjEddQLcmO5Avajinpp6IqMvlR8in3j/HeJ6YoVyg5xBgdEjw+0Wv2PjDzXT5S4G1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790769; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iRSe/YzoH9Rhej0RUrw4QjNxQSFXekPD7YTrSp4mDRw=; b=kOG4p6OGg5grXW+SaOAjvapidw7J2hzDLukt23xZwP8WdYXF4y6B68bnDe5Tzf2UmjZhIAz32Hws3wjsz6YG48D74wBPJwuLL7J20/HO+j9d4KPdJYNz8TwTYcTRDfN+TFv9wYxH4AUAMogi3/wF36+6vMysH3GB9PbN4Z7okV4= 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+importer2=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 17207907696761004.4544274761026; Fri, 12 Jul 2024 06:26:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGHS-0003KL-HP; Fri, 12 Jul 2024 09:25:46 -0400 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 1sSGHI-0002jn-N5 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHG-0003wc-8A for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:35 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-vytljU4UPd68Xmy9kGt3iw-1; Fri, 12 Jul 2024 09:25:31 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1717A19560AD; Fri, 12 Jul 2024 13:25:30 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 14FA01955F40; Fri, 12 Jul 2024 13:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790733; 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: in-reply-to:in-reply-to:references:references; bh=iRSe/YzoH9Rhej0RUrw4QjNxQSFXekPD7YTrSp4mDRw=; b=AyNQvv92TMvXiMBbE0nf0IZnhrGIZVreMx19xi6dyq/K5wXACGuehCfoDOrG/DYClzMMBH uOu7JvNLGfKPlIb4BC99RoTmJ3SJ/eZJ4MnikwpfPuSKSgNGq5AzJiY2tJm+zgMBb1ghfs 3oPqtrouO8kyQUzLx1oU1jF+QD5n4ac= X-MC-Unique: vytljU4UPd68Xmy9kGt3iw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 07/22] qga: move CONFIG_FSFREEZE/TRIM to be meson defined options Date: Fri, 12 Jul 2024 14:24:44 +0100 Message-ID: <20240712132459.3974109-8-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790769867116300 Defining these at the meson level allows them to be used a conditional tests in the QAPI schemas. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- meson.build | 15 +++++++++++++++ qga/commands-common.h | 9 --------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 6a93da48e1..3f125d1b02 100644 --- a/meson.build +++ b/meson.build @@ -2186,6 +2186,19 @@ have_virtfs_proxy_helper =3D get_option('virtfs_prox= y_helper') \ .require(libcap_ng.found(), error_message: 'the virtfs proxy helper re= quires libcap-ng') \ .allowed() =20 +qga_fsfreeze =3D false +qga_fstrim =3D false +if host_os =3D=3D 'linux' + if cc.has_header_symbol('linux/fs.h', 'FIFREEZE') + qga_fsfreeze =3D true + endif + if cc.has_header_symbol('linux/fs.h', 'FITRIM') + qga_fstrim =3D true + endif +elif host_os =3D=3D 'freebsd' and cc.has_header_symbol('ufs/ffs/fs.h', 'UF= SSUSPEND') + qga_fsfreeze =3D true +endif + if get_option('block_drv_ro_whitelist') =3D=3D '' config_host_data.set('CONFIG_BDRV_RO_WHITELIST', '') else @@ -2422,6 +2435,8 @@ config_host_data.set('CONFIG_DEBUG_TCG', get_option('= debug_tcg')) config_host_data.set('CONFIG_DEBUG_REMAP', get_option('debug_remap')) config_host_data.set('CONFIG_QOM_CAST_DEBUG', get_option('qom_cast_debug')) config_host_data.set('CONFIG_REPLICATION', get_option('replication').allow= ed()) +config_host_data.set('CONFIG_FSFREEZE', qga_fsfreeze) +config_host_data.set('CONFIG_FSTRIM', qga_fstrim) =20 # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) diff --git a/qga/commands-common.h b/qga/commands-common.h index 8c1c56aac9..263e7c0525 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -15,19 +15,10 @@ =20 #if defined(__linux__) #include -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#ifdef FITRIM -#define CONFIG_FSTRIM -#endif #endif /* __linux__ */ =20 #ifdef __FreeBSD__ #include -#ifdef UFSSUSPEND -#define CONFIG_FSFREEZE -#endif #endif /* __FreeBSD__ */ =20 #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790834; cv=none; d=zohomail.com; s=zohoarc; b=GskuCaUbC1oVrHA10STnvCIA+gJS7WHHyfgX26JXerH6c0UGX7Np3iCfGcSGK6AjvDgpfxxs/KMLST3YqeyZYCEwocF1CbnksglW7geNqKMZBg4ZQsLrttNn+bIRMBkPlJC+4GWzZv3szYHdCHjZaCIjqO0Gqfxp/onfvWmrGfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790834; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BsypKy0RLH8U+aksh5lUjY4xuLFGqR/cckyvbjG+Bos=; b=OSyyGT0+EOQCqZgaHlhHZm2NPQCP6qch/+LfoXII9YkcQ5soyxTQGBciwwivG7zoWSTI51tEoYVc+WB4JgEabmNAnNLeNVQcwlwD2EyfydUtqHJW/JXZHrQ9ZkggEdjb4oWLnHD7Hk4fFu6rwB+85ee/8O7drxsIimM0avN1/ts= 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+importer2=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 1720790834323374.40825813989284; Fri, 12 Jul 2024 06:27:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI6-0006gr-57; Fri, 12 Jul 2024 09:26:26 -0400 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 1sSGHO-0003Bb-Nr for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHI-0003yE-II for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:42 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-bvhLKrrEPH6kLAZe3vjlqg-1; Fri, 12 Jul 2024 09:25:34 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4927B19560B1; Fri, 12 Jul 2024 13:25:33 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59BE11955E70; Fri, 12 Jul 2024 13:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790735; 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: in-reply-to:in-reply-to:references:references; bh=BsypKy0RLH8U+aksh5lUjY4xuLFGqR/cckyvbjG+Bos=; b=Cg8kgp3mBllpiTRTZhFbgliwD6SV1OGeS9F/c9/4ty+H0P1+O16T7y2J5ftGYRZ73vxWOn Vk4rSd7RX2cxRk6EHb+AvBLwuGAVhUw6HyUlwXqT0uHJ9CyracrPtmGn0HvS9amqQBkKGk quTYX4dMwODcqj7binUc2WhWF74dTGo= X-MC-Unique: bvhLKrrEPH6kLAZe3vjlqg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 08/22] qga: conditionalize schema for commands unsupported on Windows Date: Fri, 12 Jul 2024 14:24:45 +0100 Message-ID: <20240712132459.3974109-9-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790836175116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the commands on Windows. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This also fixes an accidental inconsistency where some commands (guest-get-diskstats & guest-get-cpustats) are implemented as stubs, yet not added to the blockedrpc list. Those change their error message from {"class": "GenericError, "desc": "this feature or command is not curren= tly supported"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} The final additional benefit is that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 2 +- qga/commands-win32.c | 56 +------------------------------------------- qga/qapi-schema.json | 45 +++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 71 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 2a3bef7445..0dd8555867 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1280,7 +1280,7 @@ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) "guest-get-memory-blocks", "guest-set-memory-blocks", "guest-get-memory-block-info", NULL}; - char **p =3D (char **)list; + const char **p =3D list; =20 while (*p) { blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 9fe670d5b4..2533e4c748 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1494,11 +1494,6 @@ out: } } =20 -void qmp_guest_suspend_hybrid(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - static IP_ADAPTER_ADDRESSES *guest_get_adapters_addresses(Error **errp) { IP_ADAPTER_ADDRESSES *adptr_addrs =3D NULL; @@ -1862,12 +1857,6 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error= **errp) return NULL; } =20 -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return -1; -} - static gchar * get_net_error_message(gint error) { @@ -1969,46 +1958,15 @@ done: g_free(rawpasswddata); } =20 -GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestMemoryBlockResponseList * -qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { - const char *list_unsupported[] =3D { - "guest-suspend-hybrid", - "guest-set-vcpus", - "guest-get-memory-blocks", "guest-set-memory-blocks", - "guest-get-memory-block-info", - NULL}; - char **p =3D (char **)list_unsupported; - - while (*p) { - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); - } - if (!vss_init(true)) { g_debug("vss_init failed, vss commands are going to be disabled"); const char *list[] =3D { "guest-get-fsinfo", "guest-fsfreeze-status", "guest-fsfreeze-freeze", "guest-fsfreeze-thaw", NULL}; - p =3D (char **)list; + char **p =3D (char **)list; =20 while (*p) { blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); @@ -2505,15 +2463,3 @@ char *qga_get_host_name(Error **errp) =20 return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL); } - -GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 1273d85bb5..2f0215afc7 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -637,7 +637,8 @@ # # Since: 1.1 ## -{ 'command': 'guest-suspend-hybrid', 'success-response': false } +{ 'command': 'guest-suspend-hybrid', 'success-response': false, + 'if': 'CONFIG_POSIX' } =20 ## # @GuestIpAddressType: @@ -807,7 +808,8 @@ ## { 'command': 'guest-set-vcpus', 'data': {'vcpus': ['GuestLogicalProcessor'] }, - 'returns': 'int' } + 'returns': 'int', + 'if': 'CONFIG_POSIX' } =20 ## # @GuestDiskBusType: @@ -1100,7 +1102,8 @@ { 'struct': 'GuestMemoryBlock', 'data': {'phys-index': 'uint64', 'online': 'bool', - '*can-offline': 'bool'} } + '*can-offline': 'bool'}, + 'if': 'CONFIG_POSIX' } =20 ## # @guest-get-memory-blocks: @@ -1116,7 +1119,8 @@ # Since: 2.3 ## { 'command': 'guest-get-memory-blocks', - 'returns': ['GuestMemoryBlock'] } + 'returns': ['GuestMemoryBlock'], + 'if': 'CONFIG_POSIX' } =20 ## # @GuestMemoryBlockResponseType: @@ -1139,7 +1143,8 @@ ## { 'enum': 'GuestMemoryBlockResponseType', 'data': ['success', 'not-found', 'operation-not-supported', - 'operation-failed'] } + 'operation-failed'], + 'if': 'CONFIG_POSIX' } =20 ## # @GuestMemoryBlockResponse: @@ -1157,7 +1162,8 @@ { 'struct': 'GuestMemoryBlockResponse', 'data': { 'phys-index': 'uint64', 'response': 'GuestMemoryBlockResponseType', - '*error-code': 'int' }} + '*error-code': 'int' }, + 'if': 'CONFIG_POSIX'} =20 ## # @guest-set-memory-blocks: @@ -1188,7 +1194,8 @@ ## { 'command': 'guest-set-memory-blocks', 'data': {'mem-blks': ['GuestMemoryBlock'] }, - 'returns': ['GuestMemoryBlockResponse'] } + 'returns': ['GuestMemoryBlockResponse'], + 'if': 'CONFIG_POSIX' } =20 ## # @GuestMemoryBlockInfo: @@ -1200,7 +1207,8 @@ # Since: 2.3 ## { 'struct': 'GuestMemoryBlockInfo', - 'data': {'size': 'uint64'} } + 'data': {'size': 'uint64'}, + 'if': 'CONFIG_POSIX' } =20 ## # @guest-get-memory-block-info: @@ -1212,7 +1220,8 @@ # Since: 2.3 ## { 'command': 'guest-get-memory-block-info', - 'returns': 'GuestMemoryBlockInfo' } + 'returns': 'GuestMemoryBlockInfo', + 'if': 'CONFIG_POSIX' } =20 ## # @GuestExecStatus: @@ -1702,7 +1711,8 @@ 'data': {'name': 'str', 'major': 'uint64', 'minor': 'uint64', - 'stats': 'GuestDiskStats' } } + 'stats': 'GuestDiskStats' }, + 'if': 'CONFIG_POSIX' } =20 ## # @guest-get-diskstats: @@ -1714,7 +1724,8 @@ # Since: 7.1 ## { 'command': 'guest-get-diskstats', - 'returns': ['GuestDiskStatsInfo'] + 'returns': ['GuestDiskStatsInfo'], + 'if': 'CONFIG_POSIX' } =20 ## @@ -1727,7 +1738,8 @@ # Since: 7.1 ## { 'enum': 'GuestCpuStatsType', - 'data': [ 'linux' ] } + 'data': [ 'linux' ], + 'if': 'CONFIG_POSIX' } =20 =20 ## @@ -1772,7 +1784,8 @@ '*steal': 'uint64', '*guest': 'uint64', '*guestnice': 'uint64' - } } + }, + 'if': 'CONFIG_POSIX' } =20 ## # @GuestCpuStats: @@ -1786,7 +1799,8 @@ { 'union': 'GuestCpuStats', 'base': { 'type': 'GuestCpuStatsType' }, 'discriminator': 'type', - 'data': { 'linux': 'GuestLinuxCpuStats' } } + 'data': { 'linux': 'GuestLinuxCpuStats' }, + 'if': 'CONFIG_POSIX' } =20 ## # @guest-get-cpustats: @@ -1798,5 +1812,6 @@ # Since: 7.1 ## { 'command': 'guest-get-cpustats', - 'returns': ['GuestCpuStats'] + 'returns': ['GuestCpuStats'], + 'if': 'CONFIG_POSIX' } --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790858; cv=none; d=zohomail.com; s=zohoarc; b=KDiSKn+n2QjBjxEmuRU2MAcfPIYsi25NQy+CEgVwcy8ynfppCYunYu806hNWzkvuggAEOVLWV3jypWaxoeTyh2oyXPSLmmp5JIhULnYUbGK+xdmShtIGQ8FHp71urXUxbK2eE1KRvM0NvvLV6P4KddyNqtbbOwSnXVq0pctCAr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790858; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LMocrPKBkxb4IefkH5Yl3RE8g5kN91WIxpEaSC2Az4Y=; b=mbFc6beKkv7GOmg0AUs28Voy5e0wz1Pj+VxkN039nsgwGJkjmjTydXJtcyb1kiHHYirICW5tFWWDjDPT4gvJUCTVo1vFYsZmYDwLKJ/9mbyUiPeR2fPNvhUk+UHcAplLI17U11rxCgZmXTkv5lD8af7lk/wP1WjNXpFXYRDyzOk= 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+importer2=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 1720790858034686.5002680574577; Fri, 12 Jul 2024 06:27:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI7-0006sX-El; Fri, 12 Jul 2024 09:26:28 -0400 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 1sSGHV-0003i7-FU for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHM-0003yi-EC for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:42 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-8dazIf9SPLqK05bTj3UlEg-1; Fri, 12 Jul 2024 09:25:37 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD25E1955F44; Fri, 12 Jul 2024 13:25:36 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CE8BE1955E76; Fri, 12 Jul 2024 13:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790739; 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: in-reply-to:in-reply-to:references:references; bh=LMocrPKBkxb4IefkH5Yl3RE8g5kN91WIxpEaSC2Az4Y=; b=efenYCqHNneW/2mudhZ8yanKZcxPkGEQlsrMht3TqUlzdZAFOJ6cEZ/0PoBe0Zg3dr3a4a R6u4E9KNl38vp2/dfuSdhgj/ry2kGrAvAyW+64za8NIhbBNzkZgQT6eNDJK27IJhWljWnN l9+wfLToowVnfXX3SVPCenlgtsRiyYE= X-MC-Unique: 8dazIf9SPLqK05bTj3UlEg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 09/22] qga: conditionalize schema for commands unsupported on non-Linux POSIX Date: Fri, 12 Jul 2024 14:24:46 +0100 Message-ID: <20240712132459.3974109-10-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790858262116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the commands on non-Linux POSIX platforms The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 66 -------------------------------------------- qga/qapi-schema.json | 30 +++++++++++--------- 2 files changed, 17 insertions(+), 79 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 0dd8555867..559d71ffae 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -887,56 +887,6 @@ void qmp_guest_set_user_password(const char *username, } #endif /* __linux__ || __FreeBSD__ */ =20 -#ifndef __linux__ - -void qmp_guest_suspend_disk(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - -void qmp_guest_suspend_ram(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - -void qmp_guest_suspend_hybrid(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return -1; -} - -GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestMemoryBlockResponseList * -qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -#endif - #ifdef HAVE_GETIFADDRS static GuestNetworkInterface * guest_find_interface(GuestNetworkInterfaceList *head, @@ -1272,22 +1222,6 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { -#if !defined(__linux__) - { - const char *list[] =3D { - "guest-suspend-disk", "guest-suspend-ram", - "guest-suspend-hybrid", "guest-get-vcpus", "guest-set-vcpus", - "guest-get-memory-blocks", "guest-set-memory-blocks", - "guest-get-memory-block-info", - NULL}; - const char **p =3D list; - - while (*p) { - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); - } - } -#endif - #if !defined(HAVE_GETIFADDRS) blockedrpcs =3D g_list_append(blockedrpcs, g_strdup("guest-network-get-interfaces")); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 2f0215afc7..38483652ac 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -566,7 +566,8 @@ # # Since: 1.1 ## -{ 'command': 'guest-suspend-disk', 'success-response': false } +{ 'command': 'guest-suspend-disk', 'success-response': false, + 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } } =20 ## # @guest-suspend-ram: @@ -602,7 +603,8 @@ # # Since: 1.1 ## -{ 'command': 'guest-suspend-ram', 'success-response': false } +{ 'command': 'guest-suspend-ram', 'success-response': false, + 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } } =20 ## # @guest-suspend-hybrid: @@ -638,7 +640,7 @@ # Since: 1.1 ## { 'command': 'guest-suspend-hybrid', 'success-response': false, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestIpAddressType: @@ -751,7 +753,8 @@ { 'struct': 'GuestLogicalProcessor', 'data': {'logical-id': 'int', 'online': 'bool', - '*can-offline': 'bool'} } + '*can-offline': 'bool'}, + 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } } =20 ## # @guest-get-vcpus: @@ -766,7 +769,8 @@ # Since: 1.5 ## { 'command': 'guest-get-vcpus', - 'returns': ['GuestLogicalProcessor'] } + 'returns': ['GuestLogicalProcessor'], + 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } } =20 ## # @guest-set-vcpus: @@ -809,7 +813,7 @@ { 'command': 'guest-set-vcpus', 'data': {'vcpus': ['GuestLogicalProcessor'] }, 'returns': 'int', - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestDiskBusType: @@ -1103,7 +1107,7 @@ 'data': {'phys-index': 'uint64', 'online': 'bool', '*can-offline': 'bool'}, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @guest-get-memory-blocks: @@ -1120,7 +1124,7 @@ ## { 'command': 'guest-get-memory-blocks', 'returns': ['GuestMemoryBlock'], - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestMemoryBlockResponseType: @@ -1144,7 +1148,7 @@ { 'enum': 'GuestMemoryBlockResponseType', 'data': ['success', 'not-found', 'operation-not-supported', 'operation-failed'], - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestMemoryBlockResponse: @@ -1163,7 +1167,7 @@ 'data': { 'phys-index': 'uint64', 'response': 'GuestMemoryBlockResponseType', '*error-code': 'int' }, - 'if': 'CONFIG_POSIX'} + 'if': 'CONFIG_LINUX'} =20 ## # @guest-set-memory-blocks: @@ -1195,7 +1199,7 @@ { 'command': 'guest-set-memory-blocks', 'data': {'mem-blks': ['GuestMemoryBlock'] }, 'returns': ['GuestMemoryBlockResponse'], - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestMemoryBlockInfo: @@ -1208,7 +1212,7 @@ ## { 'struct': 'GuestMemoryBlockInfo', 'data': {'size': 'uint64'}, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @guest-get-memory-block-info: @@ -1221,7 +1225,7 @@ ## { 'command': 'guest-get-memory-block-info', 'returns': 'GuestMemoryBlockInfo', - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestExecStatus: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790861; cv=none; d=zohomail.com; s=zohoarc; b=J9nC1NWIfyVRdSpzh1E/taxt2QC7tj51z8KYYGnySQ9kj/5c6nPYwr5kQb47V7XJoAjkPbkAZ8W1pFrtXaY09fXrZAocMOwZtjauJCg/aRY2hpzmkROuExsUIAnC13pumPRm8N2Y6ApCx3ZivYcHe5AvxNEbPNmsyzp5qU2TzNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790861; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lwJ1OB2L/SUx9ijm5m9sgHwcgsrAmSlmkYXEO159lfk=; b=Ib15otQ4G4LnlX6M1xcYLpprXvtRxKK3zogNb0l0fmA4nTr1iixFCWdEgrHYeVgpQ0eE/1mR26dLUEo+SGGtnFJFR01IdiMYXp/A6Skgz+Y9ph/RmDi1OvMXciEdwhL/71nR8ziEmxhIEhSzA2zDM3FaRe+Hw8zE8boLftV7o3M= 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+importer2=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 1720790861873760.2118404979452; Fri, 12 Jul 2024 06:27:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI5-0006Wu-4F; Fri, 12 Jul 2024 09:26:25 -0400 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 1sSGHV-0003jY-Qn for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHR-0003zV-LI for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:48 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240-gizsp8V8MjSuaDFTHMryNQ-1; Fri, 12 Jul 2024 09:25:41 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F033719560B0; Fri, 12 Jul 2024 13:25:39 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 36F4A1955F40; Fri, 12 Jul 2024 13:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790743; 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: in-reply-to:in-reply-to:references:references; bh=lwJ1OB2L/SUx9ijm5m9sgHwcgsrAmSlmkYXEO159lfk=; b=F+LBnQUNpOWq5aNPr6mQntviKM68rVcqwYSI2j+0FRNxZFkSoRjfYgkWcCVaBNrhEyLpE1 DW6DczxYcJOwnJqTNKV+Z8TBsCCAmqcjRhCfgfePh47avI4dcnAU/RgRuL0KZ3qnxPgSI1 Ccw5vGVhFgGmZMrE1MdTqG/Ks1QOPRU= X-MC-Unique: gizsp8V8MjSuaDFTHMryNQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 10/22] qga: conditionalize schema for commands requiring getifaddrs Date: Fri, 12 Jul 2024 14:24:47 +0100 Message-ID: <20240712132459.3974109-11-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790862306116300 Rather than creating stubs for every comamnd that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the network interface command on POSIX platforms lacking getifaddrs(). The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 13 ------------- qga/qapi-schema.json | 15 ++++++++++----- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 559d71ffae..09d08ee2ca 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1142,14 +1142,6 @@ error: return NULL; } =20 -#else - -GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - #endif /* HAVE_GETIFADDRS */ =20 #if !defined(CONFIG_FSFREEZE) @@ -1222,11 +1214,6 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { -#if !defined(HAVE_GETIFADDRS) - blockedrpcs =3D g_list_append(blockedrpcs, - g_strdup("guest-network-get-interfaces")); -#endif - #if !defined(CONFIG_FSFREEZE) { const char *list[] =3D { diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 38483652ac..79ed4f0e21 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -654,7 +654,8 @@ # Since: 1.1 ## { 'enum': 'GuestIpAddressType', - 'data': [ 'ipv4', 'ipv6' ] } + 'data': [ 'ipv4', 'ipv6' ], + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_GETIFADDRS'] } } =20 ## # @GuestIpAddress: @@ -670,7 +671,8 @@ { 'struct': 'GuestIpAddress', 'data': {'ip-address': 'str', 'ip-address-type': 'GuestIpAddressType', - 'prefix': 'int'} } + 'prefix': 'int'}, + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_GETIFADDRS'] } } =20 ## # @GuestNetworkInterfaceStat: @@ -702,7 +704,8 @@ 'tx-packets': 'uint64', 'tx-errs': 'uint64', 'tx-dropped': 'uint64' - } } + }, + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_GETIFADDRS'] } } =20 ## # @GuestNetworkInterface: @@ -722,7 +725,8 @@ 'data': {'name': 'str', '*hardware-address': 'str', '*ip-addresses': ['GuestIpAddress'], - '*statistics': 'GuestNetworkInterfaceStat' } } + '*statistics': 'GuestNetworkInterfaceStat' }, + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_GETIFADDRS'] } } =20 ## # @guest-network-get-interfaces: @@ -734,7 +738,8 @@ # Since: 1.1 ## { 'command': 'guest-network-get-interfaces', - 'returns': ['GuestNetworkInterface'] } + 'returns': ['GuestNetworkInterface'], + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_GETIFADDRS'] } } =20 ## # @GuestLogicalProcessor: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790812; cv=none; d=zohomail.com; s=zohoarc; b=G/cU2VbzBt9hULkG7xVG2Cub9qUr8viGEMWKC43KuAqAQ3aWnwORPXH1ilf2Uw2dEcQKVeHdtBXnVCj0glQoGO1eTnUoElVdh84Kn6QtOeOxlLUvpcroT+lSX1nMZxtDEp+vodkuXY+gO58hjDC36d9KOrGDaiiI54RNbFDyJnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790812; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8YQlXuPkumiNt54Meho56UU15L0ZjYDK4I06MzYQc2s=; b=iOrb7xrzNbi3+odSMEqb2BwMyT+LdeXsrNBB+tt2tbRzrSY4GbG1llHApNaCn4otpoGAIOUE15FgL1NpjIuuVq6AtVIpFFyo1+FU26EUYV1A/zsuadZwKNmU+tcO3in8A13/Zn2JediNN4x7Cx7smq2Sinke+0KyMdePEVui/Cg= 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+importer2=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 1720790812776509.6187035748461; Fri, 12 Jul 2024 06:26:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIA-0007Cx-I4; Fri, 12 Jul 2024 09:26:30 -0400 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 1sSGHd-0004G2-9z for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHV-00040D-Gt for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:25:52 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-RLVY2lj1ORGPVAYVZYvAUw-1; Fri, 12 Jul 2024 09:25:44 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 884331955F2B; Fri, 12 Jul 2024 13:25:43 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 617CD1955F40; Fri, 12 Jul 2024 13:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790748; 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: in-reply-to:in-reply-to:references:references; bh=8YQlXuPkumiNt54Meho56UU15L0ZjYDK4I06MzYQc2s=; b=MtQGNmxdLmSO/gtOEvi+GfGyyFCR4eL7u8Pp6TwSDigYpqm2i4VYQDpMyoIf2kVW5XoGA4 U8WSaTf5ZnrxRv+LvkGZH9Eu8xEICjJXV++vYNRhcobtB1ONq0U5VbAd9a2aSRrAnWvkqN pvthLYZLbL3jlnLC8yVtwg+3UwbstmI= X-MC-Unique: RLVY2lj1ORGPVAYVZYvAUw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 11/22] qga: conditionalize schema for commands requiring linux/win32 Date: Fri, 12 Jul 2024 14:24:48 +0100 Message-ID: <20240712132459.3974109-12-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790814078116300 Some commands were blocked based on CONFIG_FSFREEZE, but their impl had nothing todo with CONFIG_FSFREEZE, and were instead either Linux-only, or Win+Linux-only. Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the stats and fsinfo commands on platforms that can't support them. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-bsd.c | 24 ----------------------- qga/commands-posix.c | 30 ++--------------------------- qga/qapi-schema.json | 45 +++++++++++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 69 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index 17bddda1cf..9ce48af311 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -149,30 +149,6 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) } return ret; } - -GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} #endif /* CONFIG_FSFREEZE */ =20 #ifdef HAVE_GETIFADDRS diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 09d08ee2ca..838dc3cf98 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1146,12 +1146,6 @@ error: =20 #if !defined(CONFIG_FSFREEZE) =20 -GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) { error_setg(errp, QERR_UNSUPPORTED); @@ -1181,25 +1175,6 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) =20 return 0; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - #endif /* CONFIG_FSFREEZE */ =20 #if !defined(CONFIG_FSTRIM) @@ -1217,10 +1192,9 @@ GList *ga_command_init_blockedrpcs(GList *blockedrpc= s) #if !defined(CONFIG_FSFREEZE) { const char *list[] =3D { - "guest-get-fsinfo", "guest-fsfreeze-status", + "guest-fsfreeze-status", "guest-fsfreeze-freeze", "guest-fsfreeze-freeze-list", - "guest-fsfreeze-thaw", "guest-get-fsinfo", - "guest-get-disks", NULL}; + "guest-fsfreeze-thaw", NULL}; char **p =3D (char **)list; =20 while (*p) { diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 79ed4f0e21..9bd5aa53bc 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -870,7 +870,8 @@ { 'enum': 'GuestDiskBusType', 'data': [ 'ide', 'fdc', 'scsi', 'virtio', 'xen', 'usb', 'uml', 'sata', 'sd', 'unknown', 'ieee1394', 'ssa', 'fibre', 'raid', 'iscsi', - 'sas', 'mmc', 'virtual', 'file-backed-virtual', 'nvme' ] } + 'sas', 'mmc', 'virtual', 'file-backed-virtual', 'nvme' ], + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 =20 ## @@ -888,7 +889,8 @@ ## { 'struct': 'GuestPCIAddress', 'data': {'domain': 'int', 'bus': 'int', - 'slot': 'int', 'function': 'int'} } + 'slot': 'int', 'function': 'int'}, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestCCWAddress: @@ -907,7 +909,8 @@ 'data': {'cssid': 'int', 'ssid': 'int', 'subchno': 'int', - 'devno': 'int'} } + 'devno': 'int'}, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestDiskAddress: @@ -936,7 +939,8 @@ 'bus-type': 'GuestDiskBusType', 'bus': 'int', 'target': 'int', 'unit': 'int', '*serial': 'str', '*dev': 'str', - '*ccw-address': 'GuestCCWAddress'} } + '*ccw-address': 'GuestCCWAddress'}, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestNVMeSmart: @@ -973,7 +977,8 @@ 'media-errors-lo': 'uint64', 'media-errors-hi': 'uint64', 'number-of-error-log-entries-lo': 'uint64', - 'number-of-error-log-entries-hi': 'uint64' } } + 'number-of-error-log-entries-hi': 'uint64' }, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestDiskSmart: @@ -987,7 +992,8 @@ { 'union': 'GuestDiskSmart', 'base': { 'type': 'GuestDiskBusType' }, 'discriminator': 'type', - 'data': { 'nvme': 'GuestNVMeSmart' } } + 'data': { 'nvme': 'GuestNVMeSmart' }, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestDiskInfo: @@ -1012,7 +1018,8 @@ { 'struct': 'GuestDiskInfo', 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'], '*address': 'GuestDiskAddress', '*alias': 'str', - '*smart': 'GuestDiskSmart'} } + '*smart': 'GuestDiskSmart'}, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @guest-get-disks: @@ -1025,7 +1032,8 @@ # Since: 5.2 ## { 'command': 'guest-get-disks', - 'returns': ['GuestDiskInfo'] } + 'returns': ['GuestDiskInfo'], + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @GuestFilesystemInfo: @@ -1051,7 +1059,8 @@ { 'struct': 'GuestFilesystemInfo', 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str', '*used-bytes': 'uint64', '*total-bytes': 'uint64', - '*total-bytes-privileged': 'uint64', 'disk': ['GuestDiskAddress= ']} } + '*total-bytes-privileged': 'uint64', 'disk': ['GuestDiskAddress= ']}, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @guest-get-fsinfo: @@ -1064,7 +1073,8 @@ # Since: 2.2 ## { 'command': 'guest-get-fsinfo', - 'returns': ['GuestFilesystemInfo'] } + 'returns': ['GuestFilesystemInfo'], + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } =20 ## # @guest-set-user-password: @@ -1703,7 +1713,8 @@ '*ios-pgr': 'uint64', '*total-ticks': 'uint64', '*weight-ticks': 'uint64' - } } + }, + 'if': 'CONFIG_LINUX' } =20 ## # @GuestDiskStatsInfo: @@ -1721,7 +1732,7 @@ 'major': 'uint64', 'minor': 'uint64', 'stats': 'GuestDiskStats' }, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @guest-get-diskstats: @@ -1734,7 +1745,7 @@ ## { 'command': 'guest-get-diskstats', 'returns': ['GuestDiskStatsInfo'], - 'if': 'CONFIG_POSIX' + 'if': 'CONFIG_LINUX' } =20 ## @@ -1748,7 +1759,7 @@ ## { 'enum': 'GuestCpuStatsType', 'data': [ 'linux' ], - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 =20 ## @@ -1794,7 +1805,7 @@ '*guest': 'uint64', '*guestnice': 'uint64' }, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @GuestCpuStats: @@ -1809,7 +1820,7 @@ 'base': { 'type': 'GuestCpuStatsType' }, 'discriminator': 'type', 'data': { 'linux': 'GuestLinuxCpuStats' }, - 'if': 'CONFIG_POSIX' } + 'if': 'CONFIG_LINUX' } =20 ## # @guest-get-cpustats: @@ -1822,5 +1833,5 @@ ## { 'command': 'guest-get-cpustats', 'returns': ['GuestCpuStats'], - 'if': 'CONFIG_POSIX' + 'if': 'CONFIG_LINUX' } --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790843; cv=none; d=zohomail.com; s=zohoarc; b=AZBQR2vHLtnh+n9l8UCA/JMXL+seIxGL0thgEquv4pjGNMbpVaxwLs7RiXYgxWWHROZVl07zorXokVil5FdPhcqIWgS6vdYRMXjsVKRPoTZ/h/HcCq9SiXXX1LZz8zuXjzVvfueYwizJiVGzvtONDumlUGFT8I+U76k2h6eXBno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790843; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9hjSTgqO3TPO5hRUa5ZpFZcoNmez3TFLbRU8bn+RmeQ=; b=QhOP5IbE8iM/hAiDydhZZID0yd1Z/CAQlNHQgoJktjUu724OZ6ofYzDzmaAVAy1vBCutxXwT9ap7DYBXzQKaD7ni+gUH5QaJU+0Yao2DZW5ucHJfS+2ROW5h1cNYeKennUu9c4Y8mEiHJfMyXbqzInA36CKc8mIo7DbkfNoRQJI= 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+importer2=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 1720790843475751.9017032471911; Fri, 12 Jul 2024 06:27:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIB-0007KN-IH; Fri, 12 Jul 2024 09:26:31 -0400 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 1sSGHj-0004fm-12 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHa-00040Z-SI for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:00 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-zfWAQiupMWacgrz3Anxraw-1; Fri, 12 Jul 2024 09:25:47 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B2DCC196CDEF; Fri, 12 Jul 2024 13:25:46 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EFD6D1955E70; Fri, 12 Jul 2024 13:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790750; 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: in-reply-to:in-reply-to:references:references; bh=9hjSTgqO3TPO5hRUa5ZpFZcoNmez3TFLbRU8bn+RmeQ=; b=VzkLHz1cITWmG2/oXM8kNYqc7KgMWw1KkmaC6IWQZ2tSPlcddnNli3CezRYx7TVxmsZxA2 CzqewUB0LeXbA6hysQFf1ZwmIy8cPJ9+PWA9WtyzUyKHrXTaZUbkLDsVF7xKhrCWPdeF+P cfcqCaKdgUPOSv2Om49APJtVpfTVnRA= X-MC-Unique: zfWAQiupMWacgrz3Anxraw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 12/22] qga: conditionalize schema for commands only supported on Windows Date: Fri, 12 Jul 2024 14:24:49 +0100 Message-ID: <20240712132459.3974109-13-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790844162116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the commands on non-Windows. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 9 --------- qga/qapi-schema.json | 15 ++++++++++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 838dc3cf98..b7f96aa005 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1207,8 +1207,6 @@ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) blockedrpcs =3D g_list_append(blockedrpcs, g_strdup("guest-fstrim")); #endif =20 - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup("guest-get-devices= ")); - return blockedrpcs; } =20 @@ -1419,13 +1417,6 @@ GuestOSInfo *qmp_guest_get_osinfo(Error **errp) return info; } =20 -GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return NULL; -} - #ifndef HOST_NAME_MAX # ifdef _POSIX_HOST_NAME_MAX # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 9bd5aa53bc..de3fc46d2e 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1527,7 +1527,8 @@ # @pci: PCI device ## { 'enum': 'GuestDeviceType', - 'data': [ 'pci' ] } + 'data': [ 'pci' ], + 'if': 'CONFIG_WIN32' } =20 ## # @GuestDeviceIdPCI: @@ -1539,7 +1540,8 @@ # Since: 5.2 ## { 'struct': 'GuestDeviceIdPCI', - 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' } } + 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' }, + 'if': 'CONFIG_WIN32' } =20 ## # @GuestDeviceId: @@ -1553,7 +1555,8 @@ { 'union': 'GuestDeviceId', 'base': { 'type': 'GuestDeviceType' }, 'discriminator': 'type', - 'data': { 'pci': 'GuestDeviceIdPCI' } } + 'data': { 'pci': 'GuestDeviceIdPCI' }, + 'if': 'CONFIG_WIN32' } =20 ## # @GuestDeviceInfo: @@ -1574,7 +1577,8 @@ '*driver-date': 'int', '*driver-version': 'str', '*id': 'GuestDeviceId' - } } + }, + 'if': 'CONFIG_WIN32' } =20 ## # @guest-get-devices: @@ -1586,7 +1590,8 @@ # Since: 5.2 ## { 'command': 'guest-get-devices', - 'returns': ['GuestDeviceInfo'] } + 'returns': ['GuestDeviceInfo'], + 'if': 'CONFIG_WIN32' } =20 ## # @GuestAuthorizedKeys: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790881; cv=none; d=zohomail.com; s=zohoarc; b=hGr1RDm4wxS9Zsxb2Ci44TWdmyFnrErq6MYDEOktFMvOIHhUS53aqvkK4BqAkyTyadcuhL8vSXysuSvpVt93RtIildRqcRXhiZ6kEz33p17WMbHF3akFlOMquUJ1sxOiAjQV5UMWbalPUgJsY1aGSr+M9tf7vZ6wyzp9pznM/Kc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790881; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KR+2hPAcBkEIYK+A9sH2IOoCtm2Ywh+XKS0L4i0CLBU=; b=Srrrrogn/TgYAY66J1V7jF6OEowbi4pK+3uvUw6a+nS/Eb2wV4/JqFOVkvRMBVlXy47nXHbeyw/VAPnzN2zK5f2LQpH2ngQKCoGH50ztwQJ8g2+IU/5XX/NSsM7K4GMd2O3Gshv6cTpot3U6piiLH+ozZfdgGxCghiiuR5bS9ds= 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+importer2=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 1720790881829720.1772362709456; Fri, 12 Jul 2024 06:28:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI2-00067N-8O; Fri, 12 Jul 2024 09:26:22 -0400 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 1sSGHj-0004fr-2l for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHc-00040g-R5 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:01 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-GP0CvwrYPpCBHnTPmZAkUQ-1; Fri, 12 Jul 2024 09:25:51 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 338E219560B2; Fri, 12 Jul 2024 13:25:50 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 26A341955F40; Fri, 12 Jul 2024 13:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790754; 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: in-reply-to:in-reply-to:references:references; bh=KR+2hPAcBkEIYK+A9sH2IOoCtm2Ywh+XKS0L4i0CLBU=; b=CN2ckHPDuJoxEFbSqNDXlLdagecBo9rD7AhM0xWJonk6s/tbLLEeODZCGSHqKWY2HUFS+Y IJovN0Bscz/a7aM5ZoE1GD2KQH2fbZ09xpAB9izh3pQ2B9Vw/fYUaypeshlfTPLI1d2N8b nfPdNnwTWZLCnGHr4wNNOP8wcy1DnsE= X-MC-Unique: GP0CvwrYPpCBHnTPmZAkUQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 13/22] qga: conditionalize schema for commands requiring fsfreeze Date: Fri, 12 Jul 2024 14:24:50 +0100 Message-ID: <20240712132459.3974109-14-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790882354116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the schema to fully exclude generation of the filesystem freezing commands on POSIX platforms lacking the required APIs. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 47 -------------------------------------------- qga/qapi-schema.json | 15 +++++++++----- 2 files changed, 10 insertions(+), 52 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index b7f96aa005..9207cb7a8f 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1144,39 +1144,6 @@ error: =20 #endif /* HAVE_GETIFADDRS */ =20 -#if !defined(CONFIG_FSFREEZE) - -GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return 0; -} - -int64_t qmp_guest_fsfreeze_freeze(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return 0; -} - -int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, - strList *mountpoints, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return 0; -} - -int64_t qmp_guest_fsfreeze_thaw(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return 0; -} -#endif /* CONFIG_FSFREEZE */ - #if !defined(CONFIG_FSTRIM) GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) @@ -1189,20 +1156,6 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { -#if !defined(CONFIG_FSFREEZE) - { - const char *list[] =3D { - "guest-fsfreeze-status", - "guest-fsfreeze-freeze", "guest-fsfreeze-freeze-list", - "guest-fsfreeze-thaw", NULL}; - char **p =3D (char **)list; - - while (*p) { - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); - } - } -#endif - #if !defined(CONFIG_FSTRIM) blockedrpcs =3D g_list_append(blockedrpcs, g_strdup("guest-fstrim")); #endif diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index de3fc46d2e..62462f092c 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -412,7 +412,8 @@ # Since: 0.15.0 ## { 'enum': 'GuestFsfreezeStatus', - 'data': [ 'thawed', 'frozen' ] } + 'data': [ 'thawed', 'frozen' ], + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSFREEZE'] } } =20 ## # @guest-fsfreeze-status: @@ -429,7 +430,8 @@ # Since: 0.15.0 ## { 'command': 'guest-fsfreeze-status', - 'returns': 'GuestFsfreezeStatus' } + 'returns': 'GuestFsfreezeStatus', + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSFREEZE'] } } =20 ## # @guest-fsfreeze-freeze: @@ -451,7 +453,8 @@ # Since: 0.15.0 ## { 'command': 'guest-fsfreeze-freeze', - 'returns': 'int' } + 'returns': 'int', + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSFREEZE'] } } =20 ## # @guest-fsfreeze-freeze-list: @@ -471,7 +474,8 @@ ## { 'command': 'guest-fsfreeze-freeze-list', 'data': { '*mountpoints': ['str'] }, - 'returns': 'int' } + 'returns': 'int', + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSFREEZE'] } } =20 ## # @guest-fsfreeze-thaw: @@ -488,7 +492,8 @@ # Since: 0.15.0 ## { 'command': 'guest-fsfreeze-thaw', - 'returns': 'int' } + 'returns': 'int', + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSFREEZE'] } } =20 ## # @GuestFilesystemTrimResult: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790854; cv=none; d=zohomail.com; s=zohoarc; b=GrUKl5bjs5b12V+djYtzaHugisEPP/wgSEfu7vlBeLeUsRwJprlBwRp2IgWGlhK5SY0x+CUs13+LZeJ082dE5OF2jsslf5Qbmsso3TjDYyLsioIO2oSY8pvCsWyEF4H1JeEm30PDss+DYIIDMOL7eAEfwCUX/vQrtuwsXQMZKTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790854; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=drcvdI3Sgud7lXkxoulsFG0PxIzW9TIqU8jDisNYR3M=; b=H0bNUnltAEgUTf8VpACRz4AJWfiuRJOYqJ+RvJYyeAldgnidqAXeS47XV2itJwzYfTCSRCJv6s3m8Bpm+cym84c46GCZPMbJ8Lr5SFrgwxqVgB6PPBaLIBjhOanbRYb8tCVucAd/UnWfpNNkG5BpNBwqt6su+mM2vOiCaQL6mHg= 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+importer2=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 1720790854869947.7845279849181; Fri, 12 Jul 2024 06:27:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIC-0007OK-Bi; Fri, 12 Jul 2024 09:26:32 -0400 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 1sSGHo-00052x-9F for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHi-00043q-PX for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:04 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-26ZOWBT-Ny-U1IPWun5KxA-1; Fri, 12 Jul 2024 09:25:54 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C04D5196E094; Fri, 12 Jul 2024 13:25:53 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C4281955F40; Fri, 12 Jul 2024 13:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790759; 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: in-reply-to:in-reply-to:references:references; bh=drcvdI3Sgud7lXkxoulsFG0PxIzW9TIqU8jDisNYR3M=; b=RpWFrXkAylqAeDz1JQ5PXKn3qvijEvw2gVAQI+mpn/Mwh0FcfX3tiAreiW6XGtoK7spNWj 6i60flkTmEfRWw7EQxOlqSgn2TJUOlNhg98htvy2veNKtboVs7w4CrOy6LKCHVMdOe7WZv /n4vwdXn5ZwJiPMqfQaRACDpPjiVD7o= X-MC-Unique: 26ZOWBT-Ny-U1IPWun5KxA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 14/22] qga: conditionalize schema for commands requiring fstrim Date: Fri, 12 Jul 2024 14:24:51 +0100 Message-ID: <20240712132459.3974109-15-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790856204116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the filesystem trimming commands on POSIX platforms lacking required APIs. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 13 ------------- qga/qapi-schema.json | 9 ++++++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9207cb7a8f..d92fa0ec87 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1144,22 +1144,9 @@ error: =20 #endif /* HAVE_GETIFADDRS */ =20 -#if !defined(CONFIG_FSTRIM) -GuestFilesystemTrimResponse * -qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} -#endif - /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { -#if !defined(CONFIG_FSTRIM) - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup("guest-fstrim")); -#endif - return blockedrpcs; } =20 diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 62462f092c..21c65d1806 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -510,7 +510,8 @@ ## { 'struct': 'GuestFilesystemTrimResult', 'data': {'path': 'str', - '*trimmed': 'int', '*minimum': 'int', '*error': 'str'} } + '*trimmed': 'int', '*minimum': 'int', '*error': 'str'}, + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSTRIM'] } } =20 ## # @GuestFilesystemTrimResponse: @@ -520,7 +521,8 @@ # Since: 2.4 ## { 'struct': 'GuestFilesystemTrimResponse', - 'data': {'paths': ['GuestFilesystemTrimResult']} } + 'data': {'paths': ['GuestFilesystemTrimResult']}, + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSTRIM'] } } =20 ## # @guest-fstrim: @@ -542,7 +544,8 @@ ## { 'command': 'guest-fstrim', 'data': { '*minimum': 'int' }, - 'returns': 'GuestFilesystemTrimResponse' } + 'returns': 'GuestFilesystemTrimResponse', + 'if': { 'any': ['CONFIG_WIN32', 'CONFIG_FSTRIM'] } } =20 ## # @guest-suspend-disk: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790855; cv=none; d=zohomail.com; s=zohoarc; b=FAIS5XevWVnTp58josxgtMtFgRg64TM8DV1e40etAlTzRhbl+9ybYumbGjiv773HQSpm81aI5lSQYmBCRJCpu/2LYMvazhy2fZwg6Gu0aF1qZ4ZAWaKlkfnpLe4iLLruKA9MCX3po+vIhAxX1Uf3EiBRibgkafYN8agf6iIdDns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790855; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ux4jQEssSgP1WjWj6X1MvmPAw8nL5wwCnlHZ9HHlwYE=; b=WAHjE9ZSTq+XM2jpaw9yO9+/n1LW9BYpYGS9bhkVDrifw5fOQOZs/GVyOtkGRuhk8gvs55Fm5LavahBKKjC2QpkYVRjImMcjlXBcmV/JJM1yxMnMb0OpYvdMgYd5o6BecWUAvVQBc7MPu/ytY/uYVFhuP24ed4fruUbrvUYdI4A= 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+importer2=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 17207908557621012.2413156617715; Fri, 12 Jul 2024 06:27:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI3-0006Ia-9j; Fri, 12 Jul 2024 09:26:23 -0400 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 1sSGHn-0004yl-D6 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHi-00045a-Uf for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:05 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-c3m_t392PQ-FkGeBtx1kzA-1; Fri, 12 Jul 2024 09:25:58 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5780D1956046; Fri, 12 Jul 2024 13:25:57 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4FBCE1955F40; Fri, 12 Jul 2024 13:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790762; 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: in-reply-to:in-reply-to:references:references; bh=Ux4jQEssSgP1WjWj6X1MvmPAw8nL5wwCnlHZ9HHlwYE=; b=DwfEfH5feifiSvaLurgPSspNSBn1FHPV2YtoZsq7VH3DD0Twub60ESe86h/zkpV/SOUe9L fSSMa+yLA7UFle9bczhE317W1P4rGyQ8tbWiSq/3eIz3QifpvYSgIkTp6n6ZdeXBzLZKSk zHfrd2vgMuy2ObLCAp01De8WuBWAXEs= X-MC-Unique: c3m_t392PQ-FkGeBtx1kzA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 15/22] qga: conditionalize schema for commands requiring libudev Date: Fri, 12 Jul 2024 14:24:52 +0100 Message-ID: <20240712132459.3974109-16-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790856208116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the schema to fully exclude generation of the filesystem trimming commands on POSIX platforms lacking required APIs. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-linux.c | 8 -------- qga/qapi-schema.json | 8 ++++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 73b13fbaf6..89bdcded01 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -1049,14 +1049,6 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) return ret; } =20 -#else - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - #endif =20 /* Return a list of the disk device(s)' info which @mount lies on */ diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 21c65d1806..cf1ad42519 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -986,7 +986,7 @@ 'media-errors-hi': 'uint64', 'number-of-error-log-entries-lo': 'uint64', 'number-of-error-log-entries-hi': 'uint64' }, - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } } =20 ## # @GuestDiskSmart: @@ -1001,7 +1001,7 @@ 'base': { 'type': 'GuestDiskBusType' }, 'discriminator': 'type', 'data': { 'nvme': 'GuestNVMeSmart' }, - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } } =20 ## # @GuestDiskInfo: @@ -1027,7 +1027,7 @@ 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'], '*address': 'GuestDiskAddress', '*alias': 'str', '*smart': 'GuestDiskSmart'}, - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } } =20 ## # @guest-get-disks: @@ -1041,7 +1041,7 @@ ## { 'command': 'guest-get-disks', 'returns': ['GuestDiskInfo'], - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } } + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } } =20 ## # @GuestFilesystemInfo: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790845; cv=none; d=zohomail.com; s=zohoarc; b=i8kCxOms3njUWktNqBKkUl8A3W7y3UK4sdrC/zWd5QkFAX+LwrYhIhCa0zYAoOULyRRyzjhjujgTX7hx+AFLnFe5uG9HZKp3aLOWnqFsIYx60oRj8cjh3/bqdNOmK4yS7NJGVZqLp7wjo+g4HuD0jGFeY6/wpile+3ktQ0Kw4dA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790845; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LKiW/PJQjzg+wco7ZHKYyA6/B0Qsnp2aMu6ZygpJONk=; b=doKMIFLopdfdNsk2tyyqzktjfgF5x06LEIAedCQfxvZURP+0rCMRObRkle31cFk07zxWlYaGDDu634FgIM+SASfXG9CnyAXWBQNFYv7FY557cgmqyEoIMtcsq8GpEEGkMTyxIxmCBVOYPua1ph1IAhqT1sZXz606cOSslEYoBRM= 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+importer2=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 1720790845204655.5998741951973; Fri, 12 Jul 2024 06:27:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI6-0006ko-D9; Fri, 12 Jul 2024 09:26:26 -0400 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 1sSGHz-0005oX-1a for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHn-00047J-2D for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:18 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-cHUea_lCMAuZh-EoBAF9Ag-1; Fri, 12 Jul 2024 09:26:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CEC101955F66; Fri, 12 Jul 2024 13:26:00 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 03AE61955F40; Fri, 12 Jul 2024 13:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790765; 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: in-reply-to:in-reply-to:references:references; bh=LKiW/PJQjzg+wco7ZHKYyA6/B0Qsnp2aMu6ZygpJONk=; b=PN4mqJEZcZarrfLtVQ7fkjChAV6zov5uSTkwri962Bt+PfAXG6FU6zLf9evcRiRLuzQfWX nC+vMxdxQhZPLfXhVuXbE2sdEw4jBezQjG1avZ4txey9f9DC1+MScKauyUezhDM3p4nrRp ak6Glu2X2xJkhZKYGoBLAvHkgfU+E28= X-MC-Unique: cHUea_lCMAuZh-EoBAF9Ag-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 16/22] qga: conditionalize schema for commands requiring utmpx Date: Fri, 12 Jul 2024 14:24:53 +0100 Message-ID: <20240712132459.3974109-17-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790846160116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the get-users command on POSIX platforms lacking required APIs. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/commands-posix.c | 10 +--------- qga/qapi-schema.json | 6 ++++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d92fa0ec87..a353f64ae6 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1212,15 +1212,7 @@ GuestUserList *qmp_guest_get_users(Error **errp) return head; } =20 -#else - -GuestUserList *qmp_guest_get_users(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} - -#endif +#endif /* HAVE_UTMPX */ =20 /* Replace escaped special characters with their real values. The replacem= ent * is done in place -- returned value is in the original string. diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index cf1ad42519..0662a68c43 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1414,7 +1414,8 @@ # Since: 2.10 ## { 'struct': 'GuestUser', - 'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' } } + 'data': { 'user': 'str', 'login-time': 'number', '*domain': 'str' }, + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_UTMPX' ] } } =20 ## # @guest-get-users: @@ -1426,7 +1427,8 @@ # Since: 2.10 ## { 'command': 'guest-get-users', - 'returns': ['GuestUser'] } + 'returns': ['GuestUser'], + 'if': { 'any': ['CONFIG_WIN32', 'HAVE_UTMPX' ] } } =20 ## # @GuestTimezone: --=20 2.45.1 From nobody Sun Dec 29 00:17:02 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790832; cv=none; d=zohomail.com; s=zohoarc; b=IM8mo4+Mqv16ioDvEXNunk/fIsVle2lnQQshI0fO0x7/CZw9CjBEVPlZ0ywhUb69tLu4m+BZS/lfTLEG1e/j5socbgwGYHkZJgB+l9/JNRwF0lyCHf8Eu5GXX/7xS2/j8f912/M/+Ya6pfVA6gTDnNbRhLigM58P6MOwQPGBZE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790832; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ir30cxELunmhB1gW2KAFyOCiF5YHCy37RVASmkAT6Ak=; b=eIEdQ3kFEeAusGPMI3ldnabzkhdWs3nvdQWFOinusOZBPQpnb9SMwe+S4RWqIq5dvqqKVxmkrHjly21bWIFMiFH8uOG/OnIoZz2GbbcE+9vPPyDPyrZ7IseRVP4RPELyZhqp+C+n2wszImgI5usdC7gs6dF3DQMZPjFDYJliBZo= 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+importer2=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 17207908324651014.4469228036014; Fri, 12 Jul 2024 06:27:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGI9-0006vT-IK; Fri, 12 Jul 2024 09:26:29 -0400 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 1sSGI0-0005uR-Jh for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHr-00047s-GV for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:20 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-XSVsMQnwOsKufKxbbs74Mw-1; Fri, 12 Jul 2024 09:26:04 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 058A81955E9C; Fri, 12 Jul 2024 13:26:04 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2EFD01955E70; Fri, 12 Jul 2024 13:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790769; 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: in-reply-to:in-reply-to:references:references; bh=ir30cxELunmhB1gW2KAFyOCiF5YHCy37RVASmkAT6Ak=; b=XVZNZZjN+SUAAOczc3fLZwy3gtEVIhi5NkWD6+YjCNEn54vWZO6IPtAA7lueJBa4dcQSb/ vd+aXRKJ/9LL3eIRWnYrRDe/tDT15YWo8Icmc7M4D1XYeNMYJpRCe76AKGG7SQa+vylCXf aJbbjGRud/08UNyVVzc1bnDz0SEOCl4= X-MC-Unique: XSVsMQnwOsKufKxbbs74Mw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 17/22] qga: conditionalize schema for commands not supported on other UNIX Date: Fri, 12 Jul 2024 14:24:54 +0100 Message-ID: <20240712132459.3974109-18-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790834129116300 Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the QAPI schema to fully exclude generation of the commands on other UNIX. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been foun= d"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 1 + qga/commands-posix.c | 8 -------- qga/qapi-schema.json | 3 ++- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 3f125d1b02..efc47612a3 100644 --- a/meson.build +++ b/meson.build @@ -2275,6 +2275,7 @@ config_host_data.set('CONFIG_ATTR', libattr.found()) config_host_data.set('CONFIG_BDRV_WHITELIST_TOOLS', get_option('block_drv_= whitelist_in_tools')) config_host_data.set('CONFIG_BRLAPI', brlapi.found()) config_host_data.set('CONFIG_BSD', host_os in bsd_oses) +config_host_data.set('CONFIG_FREEBSD', host_os =3D=3D 'freebsd') config_host_data.set('CONFIG_CAPSTONE', capstone.found()) config_host_data.set('CONFIG_COCOA', cocoa.found()) config_host_data.set('CONFIG_DARWIN', host_os =3D=3D 'darwin') diff --git a/qga/commands-posix.c b/qga/commands-posix.c index a353f64ae6..f4104f2760 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -877,14 +877,6 @@ void qmp_guest_set_user_password(const char *username, return; } } -#else /* __linux__ || __FreeBSD__ */ -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} #endif /* __linux__ || __FreeBSD__ */ =20 #ifdef HAVE_GETIFADDRS diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 0662a68c43..c763163fcd 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1109,7 +1109,8 @@ # Since: 2.3 ## { 'command': 'guest-set-user-password', - 'data': { 'username': 'str', 'password': 'str', 'crypted': 'bool' } } + 'data': { 'username': 'str', 'password': 'str', 'crypted': 'bool' }, + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD'] } } =20 ## # @GuestMemoryBlock: --=20 2.45.1 From nobody Sun Dec 29 00:17:03 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790862; cv=none; d=zohomail.com; s=zohoarc; b=ZE1hjvlSX23DDF4oiGQ055MOPtL6fkUQfmDHDKD/Juk4Uj13Zvukdor9O2zfR0K4cENJrcs24Gkfr4a3ubrIenonf5Nl4oiGUZHBzApz6MKP11sITIkxkHLv2r/NtzsT/mr6r942+AivEcrlP5syLfFUy6i9jNCEq0Oj1RsTKBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790862; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0WJa62CP+U612UEJMJQxscpa1kenQilxCwETI/f7mjQ=; b=n41uKLBs+MwPslN2y7Qvp8h1Jr3HgZmcL7dzMZLsQwweHZW+7YpvOk5r265J9dEyiPzwKNyovPcC+1U8wcTFJiFX2vexmEg5TgD2Wq2YjZCt6LlFk3GdE2inh40SEtRcVoi9ILshPQXMLbKj6n8jgg61Q6IPiwItbMb/aWMpUs8= 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+importer2=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 1720790862222510.54414464543333; Fri, 12 Jul 2024 06:27:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIE-0007bp-1u; Fri, 12 Jul 2024 09:26:34 -0400 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 1sSGIA-0007BY-7d for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGHr-00047y-Ro for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:29 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-mebbcQbTMXmv5axu63VcfA-1; Fri, 12 Jul 2024 09:26:08 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E1F631955BCC; Fri, 12 Jul 2024 13:26:07 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A2BB1955F40; Fri, 12 Jul 2024 13:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790770; 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: in-reply-to:in-reply-to:references:references; bh=0WJa62CP+U612UEJMJQxscpa1kenQilxCwETI/f7mjQ=; b=G8e6Co5lh2qkdjLGtG5Hrlp5Z3h58MMMqfzroWtkUD/WsKHgtP6uXyWtul/3ZXSQ5vMuhv ChM9d2HcwrZ8NoY84JCBhpjGNDXuPN1T+skUOPuXMi4KYmvh7NylypK8kAwG0SSEmTc0ub 3eLYaqqMHfa2tRpaaIkKliqqZNCI/AA= X-MC-Unique: mebbcQbTMXmv5axu63VcfA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk , Manos Pitsidianakis Subject: [PATCH v3 18/22] qga: don't disable fsfreeze commands if vss_init fails Date: Fri, 12 Jul 2024 14:24:55 +0100 Message-ID: <20240712132459.3974109-19-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790864217116300 The fsfreeze commands are already written to report an error if vss_init() fails. Reporting a more specific error message is more helpful than a generic "command is disabled" message, which cannot between an admin config decision and lack of platform support. Reviewed-by: Manos Pitsidianakis Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-win32.c | 18 +++--------------- qga/main.c | 4 ++++ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 2533e4c748..5866cc2e3c 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1203,7 +1203,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error *= *errp) GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) { if (!vss_initialized()) { - error_setg(errp, QERR_UNSUPPORTED); + error_setg(errp, "fsfreeze not possible as VSS failed to initializ= e"); return 0; } =20 @@ -1231,7 +1231,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mount= points, Error *local_err =3D NULL; =20 if (!vss_initialized()) { - error_setg(errp, QERR_UNSUPPORTED); + error_setg(errp, "fsfreeze not possible as VSS failed to initializ= e"); return 0; } =20 @@ -1266,7 +1266,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) int i; =20 if (!vss_initialized()) { - error_setg(errp, QERR_UNSUPPORTED); + error_setg(errp, "fsfreeze not possible as VSS failed to initializ= e"); return 0; } =20 @@ -1961,18 +1961,6 @@ done: /* add unsupported commands to the list of blocked RPCs */ GList *ga_command_init_blockedrpcs(GList *blockedrpcs) { - if (!vss_init(true)) { - g_debug("vss_init failed, vss commands are going to be disabled"); - const char *list[] =3D { - "guest-get-fsinfo", "guest-fsfreeze-status", - "guest-fsfreeze-freeze", "guest-fsfreeze-thaw", NULL}; - char **p =3D (char **)list; - - while (*p) { - blockedrpcs =3D g_list_append(blockedrpcs, g_strdup(*p++)); - } - } - return blockedrpcs; } =20 diff --git a/qga/main.c b/qga/main.c index f4d5f15bb3..17b6ce18ac 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1395,6 +1395,10 @@ static GAState *initialize_agent(GAConfig *config, i= nt socket_activation) " '%s': %s", config->state_dir, strerror(errno)); return NULL; } + + if (!vss_init(true)) { + g_debug("vss_init failed, vss commands will not function"); + } #endif =20 if (ga_is_frozen(s)) { --=20 2.45.1 From nobody Sun Dec 29 00:17:03 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790847; cv=none; d=zohomail.com; s=zohoarc; b=QQ0STyP9VFGDKia4K0XiOydsO76G49u7gwKMfuP6aVIaMix2estNHwXvkLYh2VtWmgE56zWPq3tPgbotGstIbQOg1T9qCXC7ozD6sybo4r+Dn8MxrK4qn+ylFaywnPcQZELHnBJVAxYRycIk0uYXSu2YM6KCYjKm968XuHEa/EM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790847; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9NUmTgpU41SaaCKY5XV7OQJhiAR/vcFVnTAaCjl0v1w=; b=ZMWLGYoe+JFxgHt6TXVFoXRgEFPwJqA1B9c3+FEU3CvYO5gbwXIEevkd1Ss/XbGisrB267alwNT1231fRcUCMMIZPg2FBkDEXQiVpAc0R3tkQGXwGfudq/87gW9fTxJQGofZQcUlFyXgQUWQXjjg0muE+HidjXISv5bV2l5Bn/M= 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+importer2=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 1720790845937302.6246819340961; Fri, 12 Jul 2024 06:27:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIE-0007h7-Ko; Fri, 12 Jul 2024 09:26:34 -0400 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 1sSGI2-00066Y-1L for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGI0-00048j-CN for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:21 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-2uRvpM13PiyxFEt87IEhww-1; Fri, 12 Jul 2024 09:26:15 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 448611935860; Fri, 12 Jul 2024 13:26:14 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3ED441955F40; Fri, 12 Jul 2024 13:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790777; 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: in-reply-to:in-reply-to:references:references; bh=9NUmTgpU41SaaCKY5XV7OQJhiAR/vcFVnTAaCjl0v1w=; b=ESi5vvkpzrVtp6I2ot4s2zt6C858iojiB2St52FNRUbBp7/DPaajXb+mAuoNLf4d+K5aY3 e8dhC2uQLR3MWT+4mJoedj6ogDjQv1jD4HucsdaAMB5SH1paa15qh0sjfc5kil60phdJQM R0IrvObbabp4ncZoW0iT8u5KlRzKWdA= X-MC-Unique: 2uRvpM13PiyxFEt87IEhww-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 19/22] qga: move declare of QGAConfig struct to top of file Date: Fri, 12 Jul 2024 14:24:56 +0100 Message-ID: <20240712132459.3974109-20-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790848151116300 It is referenced by QGAState already, and it is clearer to declare all data types at the top of the file, rather than have them mixed with code later. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/main.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/qga/main.c b/qga/main.c index 17b6ce18ac..647d27037c 100644 --- a/qga/main.c +++ b/qga/main.c @@ -70,6 +70,28 @@ typedef struct GAPersistentState { =20 typedef struct GAConfig GAConfig; =20 +struct GAConfig { + char *channel_path; + char *method; + char *log_filepath; + char *pid_filepath; +#ifdef CONFIG_FSFREEZE + char *fsfreeze_hook; +#endif + char *state_dir; +#ifdef _WIN32 + const char *service; +#endif + gchar *bliststr; /* blockedrpcs may point to this string */ + gchar *aliststr; /* allowedrpcs may point to this string */ + GList *blockedrpcs; + GList *allowedrpcs; + int daemonize; + GLogLevelFlags log_level; + int dumpconf; + bool retry_path; +}; + struct GAState { JSONMessageParser parser; GMainLoop *main_loop; @@ -996,28 +1018,6 @@ static GList *split_list(const gchar *str, const gcha= r *delim) return list; } =20 -struct GAConfig { - char *channel_path; - char *method; - char *log_filepath; - char *pid_filepath; -#ifdef CONFIG_FSFREEZE - char *fsfreeze_hook; -#endif - char *state_dir; -#ifdef _WIN32 - const char *service; -#endif - gchar *bliststr; /* blockedrpcs may point to this string */ - gchar *aliststr; /* allowedrpcs may point to this string */ - GList *blockedrpcs; - GList *allowedrpcs; - int daemonize; - GLogLevelFlags log_level; - int dumpconf; - bool retry_path; -}; - static void config_load(GAConfig *config) { GError *gerr =3D NULL; --=20 2.45.1 From nobody Sun Dec 29 00:17:03 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790884; cv=none; d=zohomail.com; s=zohoarc; b=fGbVh9xKvczwXbKTFg96FmwtFQv4qJWJMNolov9iyn/AwYyGAmvQRn4JMP3JnIEqNONPpTXT4V8Nc7bzbJRh50iENNMZer0ZDgOMurRU2MAt+fsa9FsX6Fx71eWPbB6ejUR4Ih9K8bFhXe4UXpgmO8l7Ajn3qE6xWzGtgNINyQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790884; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/6XX/rtBVy5jvbRdlEHEE/dU/YJA/r3GDb8mgAfd004=; b=KLa8bT85e4iNx2svYxQkucLR1PDwaHzMY4f+SO3RMvlIdOgAOuYIKqYwsgVt3byViTKbRNACIT8Ml+k6ywq6FSQR8Hq8m5y04M1lWOeihi6ZDGowzsRXpe4x2iIdLBySPXObDTvIePIfHNugfIby4nBgFjvs/ur5YNV7YyMMoNI= 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+importer2=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 1720790884540557.0706168463583; Fri, 12 Jul 2024 06:28:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIL-0008DO-G0; Fri, 12 Jul 2024 09:26:43 -0400 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 1sSGI4-0006W4-MZ for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGI2-0004A1-Ty for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:24 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-CluE9-ACNDaULNKMAluK3A-1; Fri, 12 Jul 2024 09:26:18 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9F49E1955F44; Fri, 12 Jul 2024 13:26:17 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C66DB1955F40; Fri, 12 Jul 2024 13:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790782; 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: in-reply-to:in-reply-to:references:references; bh=/6XX/rtBVy5jvbRdlEHEE/dU/YJA/r3GDb8mgAfd004=; b=h/lk+q6Q/OB15pTVDYzr3ionqAnuxE14evqiUdjryg7E6suEODmySUCPJhgUCEwNI6sdpZ yhP/VImFMc/eLrTezKcCwxA75nosR39kNAhTSPnCmXxH/36TEpgC2Qc47aVhiqWUmLAZu2 mAsFrasvRMh35vh/Axsp2k4BSMKp+k8= X-MC-Unique: CluE9-ACNDaULNKMAluK3A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 20/22] qga: remove pointless 'blockrpcs_key' variable Date: Fri, 12 Jul 2024 14:24:57 +0100 Message-ID: <20240712132459.3974109-21-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790886349116300 This variable was used to support back compat for the old config file key name, and became redundant after the following change: commit a7a2d636ae4549ef0551134d4bf8e084a14431c4 Author: Philippe Mathieu-Daud=C3=A9 Date: Thu May 30 08:36:43 2024 +0200 qga: Remove deprecated 'blacklist' argument / config key Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel P. Berrang=C3=A9 --- qga/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/qga/main.c b/qga/main.c index 647d27037c..6ff022a85d 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1023,7 +1023,6 @@ static void config_load(GAConfig *config) GError *gerr =3D NULL; GKeyFile *keyfile; g_autofree char *conf =3D g_strdup(g_getenv("QGA_CONF")) ?: get_reloca= ted_path(QGA_CONF_DEFAULT); - const gchar *blockrpcs_key =3D "block-rpcs"; =20 /* read system config */ keyfile =3D g_key_file_new(); @@ -1071,9 +1070,9 @@ static void config_load(GAConfig *config) g_key_file_get_boolean(keyfile, "general", "retry-path", &gerr= ); } =20 - if (g_key_file_has_key(keyfile, "general", blockrpcs_key, NULL)) { + if (g_key_file_has_key(keyfile, "general", "block-rpcs", NULL)) { config->bliststr =3D - g_key_file_get_string(keyfile, "general", blockrpcs_key, &gerr= ); + g_key_file_get_string(keyfile, "general", "block-rpcs", &gerr); config->blockedrpcs =3D g_list_concat(config->blockedrpcs, split_list(config->bliststr, ","= )); } @@ -1084,7 +1083,7 @@ static void config_load(GAConfig *config) split_list(config->aliststr, ","= )); } =20 - if (g_key_file_has_key(keyfile, "general", blockrpcs_key, NULL) && + if (g_key_file_has_key(keyfile, "general", "block-rpcs", NULL) && g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) { g_critical("wrong config, using 'block-rpcs' and 'allow-rpcs' keys= at" " the same time is not allowed"); --=20 2.45.1 From nobody Sun Dec 29 00:17:03 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790842; cv=none; d=zohomail.com; s=zohoarc; b=UtMtmHQYzn6Z9rIwK0AO2VUsXqpfJGKqD71jCpFaoPxYB9K9vOgBwwSEc5PqLl1lyviAexcJXqt8oYkBpQanvoMLlSWoii6jd5EG3tdMLpb7nYTOG6bdqe/tyq4C5Ho2x1E+lZODZ6z6UQEzL4GRAQd/hYVzQBouS2byl0/Ghk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790842; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4goqqyBZ3QazmnV7R1nhqGzsByXJk6xmXK1TsVjDDE0=; b=mt4G8Gd9TPuis7Mes9wF78EBImWwNs0cLPm9vM0QeRs72H8Mp1E6fnUjJ5Jz56nRSiRBdtvdVVXVjZkWk2BkAdCyIBKs0h12tvqzdP3uI5oxaCXUpiOT0XEPqaIDOw3P+oSUxYOK3hsQTHVFGseAIUVz2UDUOqWlFU3dpxVorTI= 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+importer2=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 1720790842581781.4804196235474; Fri, 12 Jul 2024 06:27:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIO-0000I9-Jd; Fri, 12 Jul 2024 09:26:44 -0400 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 1sSGIA-0007DF-FQ for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGI8-0004Ap-FE for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:30 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-148-Ge8CcbuONn2zU6VD3aFvwg-1; Fri, 12 Jul 2024 09:26:22 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 715FD19560B1; Fri, 12 Jul 2024 13:26:21 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 14C331955E70; Fri, 12 Jul 2024 13:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790786; 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: in-reply-to:in-reply-to:references:references; bh=4goqqyBZ3QazmnV7R1nhqGzsByXJk6xmXK1TsVjDDE0=; b=hQbmuWzkvEy8ewey0P0bakWhKOUoaWiPNWgWMFAfCTIMWyCQCz2RkA7PuH9eV5QaJz8H7B zTmBzqN7bJdS7xVTYc+Q7fuesmT1Hn7WCnC7fb8wuCvaWWR6B7Vkn+AaVNH/j0sfCGmLxC XkscK8Viuhe7S1Unz46tvlqlL52DBtA= X-MC-Unique: Ge8CcbuONn2zU6VD3aFvwg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 21/22] qga: allow configuration file path via the cli Date: Fri, 12 Jul 2024 14:24:58 +0100 Message-ID: <20240712132459.3974109-22-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790844181116300 Allowing the user to set the QGA_CONF environment variable to change the default configuration file path is very unusual practice, made more obscure since this ability is not documented. This introduces the more normal '-c PATH' / '--config=3DPATH' command line argument approach. This requires that we parse the comamnd line twice, since we want the command line arguments to take priority over the configuration file settings in general. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- docs/interop/qemu-ga.rst | 5 +++++ qga/main.c | 43 ++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/docs/interop/qemu-ga.rst b/docs/interop/qemu-ga.rst index 72fb75a6f5..e42b370319 100644 --- a/docs/interop/qemu-ga.rst +++ b/docs/interop/qemu-ga.rst @@ -33,6 +33,11 @@ Options =20 .. program:: qemu-ga =20 +.. option:: -c, --config=3DPATH + + Configuration file path (the default is |CONFDIR|\ ``/qemu-ga.conf``, + unless overriden by the QGA_CONF environment variable) + .. option:: -m, --method=3DMETHOD =20 Transport method: one of ``unix-listen``, ``virtio-serial``, or diff --git a/qga/main.c b/qga/main.c index 6ff022a85d..6ae911eb15 100644 --- a/qga/main.c +++ b/qga/main.c @@ -248,12 +248,16 @@ static void usage(const char *cmd) #ifdef CONFIG_FSFREEZE g_autofree char *fsfreeze_hook =3D get_relocated_path(QGA_FSFREEZE_HOO= K_DEFAULT); #endif + g_autofree char *conf_path =3D get_relocated_path(QGA_CONF_DEFAULT); =20 printf( "Usage: %s [-m -p ] []\n" "QEMU Guest Agent " QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n" "\n" +" -c, --config=3DPATH configuration file path (default is\n" +" %s/qemu-ga.conf\n" +" unless overriden by the QGA_CONF environment variable= )\n" " -m, --method transport method: one of unix-listen, virtio-serial,\= n" " isa-serial, or vsock-listen (virtio-serial is the def= ault)\n" " -p, --path device/socket path (the default for virtio-serial is:= \n" @@ -294,8 +298,8 @@ QEMU_COPYRIGHT "\n" " plug/unplug, etc.)\n" " -h, --help display this help and exit\n" "\n" -QEMU_HELP_BOTTOM "\n" - , cmd, QGA_VIRTIO_PATH_DEFAULT, QGA_SERIAL_PATH_DEFAULT, +QEMU_HELP_BOTTOM "\n", + cmd, conf_path, QGA_VIRTIO_PATH_DEFAULT, QGA_SERIAL_PATH_DEFAULT, dfl_pathnames.pidfile, #ifdef CONFIG_FSFREEZE fsfreeze_hook, @@ -1018,15 +1022,14 @@ static GList *split_list(const gchar *str, const gc= har *delim) return list; } =20 -static void config_load(GAConfig *config) +static void config_load(GAConfig *config, const char *confpath, bool requi= red) { GError *gerr =3D NULL; GKeyFile *keyfile; - g_autofree char *conf =3D g_strdup(g_getenv("QGA_CONF")) ?: get_reloca= ted_path(QGA_CONF_DEFAULT); =20 /* read system config */ keyfile =3D g_key_file_new(); - if (!g_key_file_load_from_file(keyfile, conf, 0, &gerr)) { + if (!g_key_file_load_from_file(keyfile, confpath, 0, &gerr)) { goto end; } if (g_key_file_has_key(keyfile, "general", "daemon", NULL)) { @@ -1092,10 +1095,10 @@ static void config_load(GAConfig *config) =20 end: g_key_file_free(keyfile); - if (gerr && - !(gerr->domain =3D=3D G_FILE_ERROR && gerr->code =3D=3D G_FILE_ERR= OR_NOENT)) { + if (gerr && (required || + !(gerr->domain =3D=3D G_FILE_ERROR && gerr->code =3D=3D G= _FILE_ERROR_NOENT))) { g_critical("error loading configuration from path: %s, %s", - conf, gerr->message); + confpath, gerr->message); exit(EXIT_FAILURE); } g_clear_error(&gerr); @@ -1167,12 +1170,13 @@ static void config_dump(GAConfig *config) =20 static void config_parse(GAConfig *config, int argc, char **argv) { - const char *sopt =3D "hVvdm:p:l:f:F::b:a:s:t:Dr"; + const char *sopt =3D "hVvdc:m:p:l:f:F::b:a:s:t:Dr"; int opt_ind =3D 0, ch; bool block_rpcs =3D false, allow_rpcs =3D false; const struct option lopt[] =3D { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, + { "config", 1, NULL, 'c' }, { "dump-conf", 0, NULL, 'D' }, { "logfile", 1, NULL, 'l' }, { "pidfile", 1, NULL, 'f' }, @@ -1192,6 +1196,26 @@ static void config_parse(GAConfig *config, int argc,= char **argv) { "retry-path", 0, NULL, 'r' }, { NULL, 0, NULL, 0 } }; + g_autofree char *confpath =3D g_strdup(g_getenv("QGA_CONF")) ?: + get_relocated_path(QGA_CONF_DEFAULT); + bool confrequired =3D false; + + while ((ch =3D getopt_long(argc, argv, sopt, lopt, NULL)) !=3D -1) { + switch (ch) { + case 'c': + g_free(confpath); + confpath =3D g_strdup(optarg); + confrequired =3D true; + break; + default: + break; + } + } + + config_load(config, confpath, confrequired); + + /* Reset for second pass */ + optind =3D 1; =20 while ((ch =3D getopt_long(argc, argv, sopt, lopt, &opt_ind)) !=3D -1)= { switch (ch) { @@ -1582,7 +1606,6 @@ int main(int argc, char **argv) qga_qmp_init_marshal(&ga_commands); =20 init_dfl_pathnames(); - config_load(config); config_parse(config, argc, argv); =20 if (config->pid_filepath =3D=3D NULL) { --=20 2.45.1 From nobody Sun Dec 29 00:17:03 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720790861; cv=none; d=zohomail.com; s=zohoarc; b=laJMe83u+I+0ExgOqyLD5FWqFV89epcHfO9xY7MHRQrl5d15KYRgejkJ9GW6Xfs+5p3L9Hg9FYcprZ4Q6uUq6IaO3Tw7XVmAyKocR+Xa9JI04W9keHyu55YdstDWo7oAJDdtZaUxlwbCAavRX42PWm0JL4U3e85zT2PTnvC0+ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720790861; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IxwMPr18DwYtTlNkl5hng7w3xTEyRUqI/jLVnfYZ18c=; b=a4cmq7noOn6whDIzD46R2vmyyx2Td1HNmFobUng2Geh5mEftH+zuZG2jlz81qlX7542DCw6/DrSpG32iyhspmBw1ejLB4TTRdGuTJzkc6zKCqFlfgae8hZgbkYq7wkEJy+F/3qPRZ6VnEZUqNmjGt+koibtN8v7deCLfAbumDm8= 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+importer2=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 1720790861420743.2334731672792; Fri, 12 Jul 2024 06:27:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSGIQ-0000Wx-DP; Fri, 12 Jul 2024 09:26:46 -0400 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 1sSGIC-0007Qa-O5 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSGIA-0004BF-Ce for qemu-devel@nongnu.org; Fri, 12 Jul 2024 09:26:32 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-obPOXoqsNEiaY81ff3d3jQ-1; Fri, 12 Jul 2024 09:26:25 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 994721955F2B; Fri, 12 Jul 2024 13:26:24 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.56]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BBE2F1955F40; Fri, 12 Jul 2024 13:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720790788; 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: in-reply-to:in-reply-to:references:references; bh=IxwMPr18DwYtTlNkl5hng7w3xTEyRUqI/jLVnfYZ18c=; b=X+sLy4nFP3FW3bfxPT4bDub38dj7Y3xvPL5EEFhdepjr2EHnVdkbHv5dL3MthWCAKzw7o1 Y6PU5Ez8dh7oCXC7PHz8El/O6WAXBeXwCDcmL1z0bHpe+NqYAWycY/5HN1wOHCtLeWwfLp wefrVz3AXtUdDq15uoG+eNgjaHYjNHE= X-MC-Unique: obPOXoqsNEiaY81ff3d3jQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Konstantin Kostiuk Subject: [PATCH v3 22/22] qga: centralize logic for disabling/enabling commands Date: Fri, 12 Jul 2024 14:24:59 +0100 Message-ID: <20240712132459.3974109-23-berrange@redhat.com> In-Reply-To: <20240712132459.3974109-1-berrange@redhat.com> References: <20240712132459.3974109-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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.138, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720790862349116300 It is confusing having many different pieces of code enabling and disabling commands, and it is not clear that they all have the same semantics, especially wrt prioritization of the block/allow lists. The code attempted to prevent the user from setting both the block and allow lists concurrently, however, the logic was flawed as it checked settings in the configuration file separately from the command line arguments. Thus it was possible to set a block list in the config file and an allow list via a command line argument. The --dump-conf option also creates a configuration file with both keys present, even if unset, which means it is creating a config that cannot actually be loaded again. Centralizing the code in a single method "ga_apply_command_filters" will provide a strong guarantee of consistency and clarify the intended behaviour. With this there is no compelling technical reason to prevent concurrent setting of both the allow and block lists, so this flawed restriction is removed. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- docs/interop/qemu-ga.rst | 14 +++++ qga/commands-posix.c | 6 -- qga/commands-win32.c | 6 -- qga/main.c | 128 +++++++++++++++++---------------------- 4 files changed, 70 insertions(+), 84 deletions(-) diff --git a/docs/interop/qemu-ga.rst b/docs/interop/qemu-ga.rst index e42b370319..fb75cfd8d4 100644 --- a/docs/interop/qemu-ga.rst +++ b/docs/interop/qemu-ga.rst @@ -28,6 +28,20 @@ configuration options on the command line. For the same = key, the last option wins, but the lists accumulate (see below for configuration file format). =20 +If an allowed RPCs list is defined in the configuration, then all +RPCs will be blocked by default, except for the allowed list. + +If a blocked RPCs list is defined in the configuration, then all +RPCs will be allowed by default, except for the blocked list. + +If both allowed and blocked RPCs lists are defined in the configuration, +then all RPCs will be blocked by default, then the allowed list will +be applied, followed by the blocked list. + +While filesystems are frozen, all except for a designated safe set +of RPCs will blocked, regardless of what the general configuration +declares. + Options ------- =20 diff --git a/qga/commands-posix.c b/qga/commands-posix.c index f4104f2760..578d29f228 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1136,12 +1136,6 @@ error: =20 #endif /* HAVE_GETIFADDRS */ =20 -/* add unsupported commands to the list of blocked RPCs */ -GList *ga_command_init_blockedrpcs(GList *blockedrpcs) -{ - return blockedrpcs; -} - /* register init/cleanup routines for stateful command groups */ void ga_command_state_init(GAState *s, GACommandState *cs) { diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 5866cc2e3c..61b36da469 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1958,12 +1958,6 @@ done: g_free(rawpasswddata); } =20 -/* add unsupported commands to the list of blocked RPCs */ -GList *ga_command_init_blockedrpcs(GList *blockedrpcs) -{ - return blockedrpcs; -} - /* register init/cleanup routines for stateful command groups */ void ga_command_state_init(GAState *s, GACommandState *cs) { diff --git a/qga/main.c b/qga/main.c index 6ae911eb15..b8f7b1e4a3 100644 --- a/qga/main.c +++ b/qga/main.c @@ -423,60 +423,79 @@ static gint ga_strcmp(gconstpointer str1, gconstpoint= er str2) return strcmp(str1, str2); } =20 -/* disable commands that aren't safe for fsfreeze */ -static void ga_disable_not_allowed_freeze(const QmpCommand *cmd, void *opa= que) +static bool ga_command_is_allowed(const QmpCommand *cmd, GAState *state) { - bool allowed =3D false; int i =3D 0; + GAConfig *config =3D state->config; const char *name =3D qmp_command_name(cmd); + /* Fallback policy is allow everything */ + bool allowed =3D true; =20 - while (ga_freeze_allowlist[i] !=3D NULL) { - if (strcmp(name, ga_freeze_allowlist[i]) =3D=3D 0) { + if (config->allowedrpcs) { + /* + * If an allow-list is given, this changes the fallback + * policy to deny everything + */ + allowed =3D false; + + if (g_list_find_custom(config->allowedrpcs, name, ga_strcmp) !=3D = NULL) { allowed =3D true; } - i++; } - if (!allowed) { - g_debug("disabling command: %s", name); - qmp_disable_command(&ga_commands, name, "the agent is in frozen st= ate"); - } -} =20 -/* [re-]enable all commands, except those explicitly blocked by user */ -static void ga_enable_non_blocked(const QmpCommand *cmd, void *opaque) -{ - GAState *s =3D opaque; - GList *blockedrpcs =3D s->blockedrpcs; - GList *allowedrpcs =3D s->allowedrpcs; - const char *name =3D qmp_command_name(cmd); - - if (g_list_find_custom(blockedrpcs, name, ga_strcmp) =3D=3D NULL) { - if (qmp_command_is_enabled(cmd)) { - return; + /* + * If both allowedrpcs and blockedrpcs are set, the blocked + * list will take priority + */ + if (config->blockedrpcs) { + if (g_list_find_custom(config->blockedrpcs, name, ga_strcmp) !=3D = NULL) { + allowed =3D false; } + } =20 - if (allowedrpcs && - g_list_find_custom(allowedrpcs, name, ga_strcmp) =3D=3D NULL) { - return; - } + /* + * If frozen, this filtering must take priority over + * absolutely everything + */ + if (state->frozen) { + allowed =3D false; =20 - g_debug("enabling command: %s", name); - qmp_enable_command(&ga_commands, name); + while (ga_freeze_allowlist[i] !=3D NULL) { + if (strcmp(name, ga_freeze_allowlist[i]) =3D=3D 0) { + allowed =3D true; + } + i++; + } } + + return allowed; } =20 -/* disable commands that aren't allowed */ -static void ga_disable_not_allowed(const QmpCommand *cmd, void *opaque) +static void ga_apply_command_filters_iter(const QmpCommand *cmd, void *opa= que) { - GList *allowedrpcs =3D opaque; + GAState *state =3D opaque; + bool want =3D ga_command_is_allowed(cmd, state); + bool have =3D qmp_command_is_enabled(cmd); const char *name =3D qmp_command_name(cmd); =20 - if (g_list_find_custom(allowedrpcs, name, ga_strcmp) =3D=3D NULL) { + if (want =3D=3D have) { + return; + } + + if (have) { g_debug("disabling command: %s", name); qmp_disable_command(&ga_commands, name, "the command is not allowe= d"); + } else { + g_debug("enabling command: %s", name); + qmp_enable_command(&ga_commands, name); } } =20 +static void ga_apply_command_filters(GAState *state) +{ + qmp_for_each_command(&ga_commands, ga_apply_command_filters_iter, stat= e); +} + static bool ga_create_file(const char *path) { int fd =3D open(path, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR); @@ -509,15 +528,14 @@ void ga_set_frozen(GAState *s) if (ga_is_frozen(s)) { return; } - /* disable all forbidden (for frozen state) commands */ - qmp_for_each_command(&ga_commands, ga_disable_not_allowed_freeze, NULL= ); g_warning("disabling logging due to filesystem freeze"); - ga_disable_logging(s); s->frozen =3D true; if (!ga_create_file(s->state_filepath_isfrozen)) { g_warning("unable to create %s, fsfreeze may not function properly= ", s->state_filepath_isfrozen); } + ga_apply_command_filters(s); + ga_disable_logging(s); } =20 void ga_unset_frozen(GAState *s) @@ -549,12 +567,12 @@ void ga_unset_frozen(GAState *s) } =20 /* enable all disabled, non-blocked and allowed commands */ - qmp_for_each_command(&ga_commands, ga_enable_non_blocked, s); s->frozen =3D false; if (!ga_delete_file(s->state_filepath_isfrozen)) { g_warning("unable to delete %s, fsfreeze may not function properly= ", s->state_filepath_isfrozen); } + ga_apply_command_filters(s); } =20 #ifdef CONFIG_FSFREEZE @@ -1086,13 +1104,6 @@ static void config_load(GAConfig *config, const char= *confpath, bool required) split_list(config->aliststr, ","= )); } =20 - if (g_key_file_has_key(keyfile, "general", "block-rpcs", NULL) && - g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) { - g_critical("wrong config, using 'block-rpcs' and 'allow-rpcs' keys= at" - " the same time is not allowed"); - exit(EXIT_FAILURE); - } - end: g_key_file_free(keyfile); if (gerr && (required || @@ -1172,7 +1183,6 @@ static void config_parse(GAConfig *config, int argc, = char **argv) { const char *sopt =3D "hVvdc:m:p:l:f:F::b:a:s:t:Dr"; int opt_ind =3D 0, ch; - bool block_rpcs =3D false, allow_rpcs =3D false; const struct option lopt[] =3D { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, @@ -1268,7 +1278,6 @@ static void config_parse(GAConfig *config, int argc, = char **argv) } config->blockedrpcs =3D g_list_concat(config->blockedrpcs, split_list(optarg, ",")); - block_rpcs =3D true; break; } case 'a': { @@ -1278,7 +1287,6 @@ static void config_parse(GAConfig *config, int argc, = char **argv) } config->allowedrpcs =3D g_list_concat(config->allowedrpcs, split_list(optarg, ",")); - allow_rpcs =3D true; break; } #ifdef _WIN32 @@ -1319,12 +1327,6 @@ static void config_parse(GAConfig *config, int argc,= char **argv) exit(EXIT_FAILURE); } } - - if (block_rpcs && allow_rpcs) { - g_critical("wrong commandline, using --block-rpcs and --allow-rpcs= at the" - " same time is not allowed"); - exit(EXIT_FAILURE); - } } =20 static void config_free(GAConfig *config) @@ -1435,7 +1437,6 @@ static GAState *initialize_agent(GAConfig *config, in= t socket_activation) s->deferred_options.log_filepath =3D config->log_filepath; } ga_disable_logging(s); - qmp_for_each_command(&ga_commands, ga_disable_not_allowed_freeze, = NULL); } else { if (config->daemonize) { become_daemon(config->pid_filepath); @@ -1459,25 +1460,6 @@ static GAState *initialize_agent(GAConfig *config, i= nt socket_activation) return NULL; } =20 - if (config->allowedrpcs) { - qmp_for_each_command(&ga_commands, ga_disable_not_allowed, config-= >allowedrpcs); - s->allowedrpcs =3D config->allowedrpcs; - } - - /* - * Some commands can be blocked due to system limitation. - * Initialize blockedrpcs list even if allowedrpcs specified. - */ - config->blockedrpcs =3D ga_command_init_blockedrpcs(config->blockedrpc= s); - if (config->blockedrpcs) { - GList *l =3D config->blockedrpcs; - s->blockedrpcs =3D config->blockedrpcs; - do { - g_debug("disabling command: %s", (char *)l->data); - qmp_disable_command(&ga_commands, l->data, NULL); - l =3D g_list_next(l); - } while (l); - } s->command_state =3D ga_command_state_new(); ga_command_state_init(s, s->command_state); ga_command_state_init_all(s->command_state); @@ -1503,6 +1485,8 @@ static GAState *initialize_agent(GAConfig *config, in= t socket_activation) } #endif =20 + ga_apply_command_filters(s); + ga_state =3D s; return s; } --=20 2.45.1