From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604367049; cv=pass; d=zohomail.com; s=zohoarc; b=bCkb7rc25DoqWzdjNox+AcpDdtVLaDnvTnUeEBqC6apRu+v+HDx150FJ17yl8TTW2wJl0N1bYLbThS1WmxfTuiH5jxjqnP2VRReDJCT1SHjk2N3ZX1ETjCj4JEE4KdTbAnQ10OsFxhjxopg1FD26xJNjx0kR365WpijcCXb151I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604367049; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1sIAs+TJldLQL+HX0R1AdIOP64eRzzVdoUrAbd0UWjo=; b=Ta/s1VDQJu1g7/gomH+2+DKjKhBiaa30+TczfROTLl+9yyTM/9uavb8Enq0yLZr2pQ6u/A7oP9J/H727ntd7u0gB45JilCgbqN0tQMXZRUGQWyeFK9eQELY/dUz2ACVopeSpYaxm3+9zXswfAJKRjiNPNqPtMPiuK6CoWDyMtUw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604367049538984.2741246842168; Mon, 2 Nov 2020 17:30:49 -0800 (PST) Received: from localhost ([::1]:60580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl9r-0002AL-Vi for importer@patchew.org; Mon, 02 Nov 2020 20:30:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksV-0006Yz-PH for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:51 -0500 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:64832 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksU-0005WU-6T for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:51 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:21 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:21 +0000 Received: from localhost (165.204.77.11) by SA9PR13CA0229.namprd13.prod.outlook.com (2603:10b6:806:25::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Tue, 3 Nov 2020 01:12:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UxmDMFLEnwCQsSFjTKmI7rwvLbtY8K6ULEqlJYJnUGtPGq9GXKOkzq/+U3iti165pTjMfVqoxpo5/1uxyE6WYpstJ8SlYGr5EFLQJWByCcpWoOYL/WXuSiytFFqjWGoVZd/B1A45IjNweiSe+n2fyScZY0CloguKLqgo5gVjt3TbSCLARVaoI97UWPRawAcsDY+Ax6gtSqQ/P9p7lOoQynb4cVE+EY9KHdGtO0AmYhNtKhBm67ZYuwouLoQgPOugowimCOe8egKgo/Iw4SkwAuMYkYpJxeJPEK/fZdXI3H7VLL5t53oE3/P8zSeYoYcwmgCR1DHnop7NxS1OstjKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1sIAs+TJldLQL+HX0R1AdIOP64eRzzVdoUrAbd0UWjo=; b=LILiTc7Lti37a7lIsXhnnonbRcUf5lW16Ir5ikj6W2TbHUir4JHG+VKSPqS7PlkXnEdHIsU9EdUKyn53MqAR4BQak+Zj3dYSDqgcg9goFIjJfBmbx1V9DQBq6cgHqT12y5FIcufBwqAmGXkSkFLYjNlhMzir3awWsGJ8ogVxBvPzvBy6v6P9cFp2dfYaMHxDoq9YtwD2CNE3J4IuDJoRr9GJlBoY97uSw+IPyV6c3R2dp9sa2TjW95GUVEdWIshz2Fwqr18ZB7wohq9KD7rgtszrOoUt4SwbEjSJo/BtJYtZZ1cVUIsv+euukJZoKo1ZeoyNY30Shng2pSYOe3o3zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1sIAs+TJldLQL+HX0R1AdIOP64eRzzVdoUrAbd0UWjo=; b=N1vI6kQ0BiMPQNLhBaT6cm68lwgXlmlVm5jt4NEjwc6OzTxhDGzqn4uc6848jlrk/GPuJXe08cWHfoN/Ye0K7bOSRNv+d+8gQmFzTDwPA02xGC5JSPXwecDzub9WqwW5e/SzyjZUK1zs5SaTan3UG+Q+txEGY31J4SBNgTupPWU= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 01/12] qga: Rename guest-get-devices return member 'address' to 'id' Date: Mon, 2 Nov 2020 19:11:23 -0600 Message-Id: <20201103011134.887744-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA9PR13CA0229.namprd13.prod.outlook.com (2603:10b6:806:25::24) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9fc71738-e445-45fc-533e-08d87f9583c2 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:419; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JE66Qskuo0zQDcSd/13q965q7dAkLJpXqpWdU3Q60g7GVVxA4sBGdscsgXdeH5PfqHaFwEgnmgYskZCeC9niDKoCEsjArQ290cc6ZRmU7QmA7SBvMnp/zQOx5goJQdlNE1URRouYdw54YFsmEBW47vkpJ1DzbpjXkO5L2eNo3XETn93LdGXO8MpSLuVOrJQCuVDWy3eW8Gjy1lTcR+diM4G7UCuL/ld4lZ9ChLULE3NfOuIoW1ffKywQ+Wn4lwHbtZJw2n7p+RaAy+X8zA2apLV0UDxJUtfAtdO8DGO0alA1xgVD25Khpx2ghTOGzE4QSwvb/uVAXsj0x+JhhxWIzA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(83380400001)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CovVqaiv5DMleMjsQ6LHcd2nUrDhFUjbyM7EjUPTdlmUBYUFrJ68P/0WUFLTlKChu3I8RkGyxZ5WgygHwnXMVuwbLMMK2PCZlhJ3ZfzjjMX+fSOsrzlpybJjM8FFu9hntMQ2AtoSM0EvBswBnyeNCA85pXK8yYf5u8qD6640xLhO3bpKBOcwJutEBnNSjro3gV/H37ucA4H32iGmmxvoYw0Kw6+++0SYOdoJNYxkzO9ZYhVUsNfPP8o1LnBVv39NneB5EoSAZiIZjDp5uK2WfuowP+iGS2i35O9y877DiTwFw9xnpv4PnoYKchsDfju1VzHzCM73Mkqpx4HFrbhx9wT8np7lRzXJWDPRIkvJI6480fMBlKOp0uwxXXewwo7la+l5Y+mkLr++kTmTTyd2qZVAL8fAGJwM6aWB5vZJs5N6tYQv266RXiamqOVAajaRB5tap6JVetMS9gmMvXFUG5wMK3WoXlMJk1jFxbNX72A2N3aeQxyvd/p+cgrNgfOUCQ5+Gz+gpyoLKwi9icJAMZYVvEUgHEtFqyPznyBycQ+U8twlFdkwtew7P6gOQy2qZKI1je/FBU6rQhA2nOxCZVbY6hl4Hyt32UxHTWgXHLb/UvTFHSNZLL2v6LctCtcKtX+hU7nc1l9M0aB6FH7ZlA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fc71738-e445-45fc-533e-08d87f9583c2 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:21.1923 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: d8qqt2klFEa6FKHIoctakupewKNOuxDpli3AulP5HNbD2WWNnmYx8qkcW2NUkS2TUoY0OWURd36AnccmFionRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.58; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:23 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Markus Armbruster Member 'address' is union GuestDeviceAddress with a single branch GuestDeviceAddressPCI, containing PCI vendor ID and device ID. This is not a PCI address. Type GuestPCIAddress is. Messed up in recent commit 2e4211cee4 "qga: add command guest-get-devices for reporting VirtIO devices". Rename type GuestDeviceAddressPCI to GuestDeviceIdPCI, type GuestDeviceAddress to GuestDeviceId, and member 'address' to 'id'. Document the member properly while there. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Michael Roth --- qga/commands-win32.c | 16 ++++++++-------- qga/qapi-schema.json | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0c3c05484f..879b02b6c3 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2390,22 +2390,22 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **= errp) } for (j =3D 0; hw_ids[j] !=3D NULL; j++) { GMatchInfo *match_info; - GuestDeviceAddressPCI *address; + GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0, &match_info)) { continue; } skip =3D false; =20 - address =3D g_new0(GuestDeviceAddressPCI, 1); + id =3D g_new0(GuestDeviceIdPCI, 1); vendor_id =3D g_match_info_fetch(match_info, 1); device_id =3D g_match_info_fetch(match_info, 2); - address->vendor_id =3D g_ascii_strtoull(vendor_id, NULL, 16); - address->device_id =3D g_ascii_strtoull(device_id, NULL, 16); + id->vendor_id =3D g_ascii_strtoull(vendor_id, NULL, 16); + id->device_id =3D g_ascii_strtoull(device_id, NULL, 16); =20 - device->address =3D g_new0(GuestDeviceAddress, 1); - device->has_address =3D true; - device->address->type =3D GUEST_DEVICE_ADDRESS_KIND_PCI; - device->address->u.pci.data =3D address; + device->id =3D g_new0(GuestDeviceId, 1); + device->has_id =3D true; + device->id->type =3D GUEST_DEVICE_ID_KIND_PCI; + device->id->u.pci.data =3D id; =20 g_match_info_free(match_info); break; diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index cec98c7e06..f2c81cda2b 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1257,26 +1257,26 @@ 'returns': 'GuestOSInfo' } =20 ## -# @GuestDeviceAddressPCI: +# @GuestDeviceIdPCI: # # @vendor-id: vendor ID # @device-id: device ID # # Since: 5.2 ## -{ 'struct': 'GuestDeviceAddressPCI', +{ 'struct': 'GuestDeviceIdPCI', 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' } } =20 ## -# @GuestDeviceAddress: +# @GuestDeviceId: # -# Address of the device -# - @pci: address of PCI device, since: 5.2 +# Id of the device +# - @pci: PCI ID, since: 5.2 # # Since: 5.2 ## -{ 'union': 'GuestDeviceAddress', - 'data': { 'pci': 'GuestDeviceAddressPCI' } } +{ 'union': 'GuestDeviceId', + 'data': { 'pci': 'GuestDeviceIdPCI' } } =20 ## # @GuestDeviceInfo: @@ -1284,6 +1284,7 @@ # @driver-name: name of the associated driver # @driver-date: driver release date in format YYYY-MM-DD # @driver-version: driver version +# @id: device ID # # Since: 5.2 ## @@ -1292,7 +1293,7 @@ 'driver-name': 'str', '*driver-date': 'str', '*driver-version': 'str', - '*address': 'GuestDeviceAddress' + '*id': 'GuestDeviceId' } } =20 ## --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366199; cv=pass; d=zohomail.com; s=zohoarc; b=ehfaBR84mF88/EhCt0TxFNzd/RbVawmaMzeGxI2tkpleFyEGfGIMK69o/B+7kkgl2cJ587bSjlak4vpSr2vEyAhSG/JnoQZFYQHiPCQykZqByUYxQm7PDXdBVt84FbrrrCz/SY7pl/WNvbHd7SgpGg4vf68kw1zBkTP/HewpD4w= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366199; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T8O8TEJqM9sAjKrgZxD2Qze0Mz6pcAyVSjw/Ml6CHMk=; b=ddg22bt5Dw216yo+8uaIhD4CimLJce8Y36Cf2C52gTDOvQrQZ9fyGkRxeEQbbeKMJCQ9NPDCCSmhaSrXPNUCykquznWnctLVXeOzq9LahicCOMMIpOdUNS4woEH/pJlcRCijp+MWsVCT+1KATIVNOKTJyrpVNZhO+ndsHYRGmkk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366199984405.92720444930967; Mon, 2 Nov 2020 17:16:39 -0800 (PST) Received: from localhost ([::1]:36072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZkwA-0008P9-RN for importer@patchew.org; Mon, 02 Nov 2020 20:16:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksX-0006c1-JX for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:53 -0500 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:64832 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksW-0005WU-2S for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:53 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:24 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:24 +0000 Received: from localhost (165.204.77.11) by SA9PR13CA0226.namprd13.prod.outlook.com (2603:10b6:806:25::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Tue, 3 Nov 2020 01:12:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NTqY3kRWKh2Dgh5mBuLPfTGsWMsD48ATck8O2qQsa2c5xIRV8mTXqsxiSGb/vlRIhHc7vZeI7xdS0ZUToIr51TLa7oOnHrP/EtVLumPr2FqZ1s0bXHn/faHAP0miTo1as9a29b7mhF+IeOzkiHaltvV9GNpfZ6BH8whj7An1AzzThfyVt7e/XN0jsAX0P4UqQaUVicnZui7LoU8u1ngpldnA7ONWZIQ5wj9FpCOiHkpEpgJUaESz0LfDYnaRCZDusxoXW4HWzN0YC6aSRyCkdLZ/SsPvgZDCJHMmPpvgeADDrxqTTx/jvDBvIc80CLHCSCqjCiLiegSI9pMocF0Xgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T8O8TEJqM9sAjKrgZxD2Qze0Mz6pcAyVSjw/Ml6CHMk=; b=PxHLEw8a7v01EP75fQB+gFUWaGUiFYQirn0MayZDz2HeAiTM/NmJ7taAWGvlhoQO6RzeIVnvhE99mCWZWXkOiotSNWVZWGIwpMfU11PP8kg7gupYS4VCbaHFhO0xoLfwpJLJ4rwPBwAgfqBs8ndSMH28lrRXs2E0qch9CLqEnYPSNjycnocwVufmI6sk7bTTSIbrLCbF4Gb8WB99//RwdI8EuR/SS6bX0dFT3IUbVp3yqas8ms1SLZhfZmup55W3onwc4Huo7tIlPcSFfGxrZtgKGyc/mo/0qD0r3YLMaqiEX+yWK7Uz2Mgf6mQZLTc8Tocl8vQDKTMT4QG/Q6eH7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T8O8TEJqM9sAjKrgZxD2Qze0Mz6pcAyVSjw/Ml6CHMk=; b=rQljEs4IpQD2cUiY6OyDPpHNrXzMScfVthK8ETbCQ4c+gvjvnQDjCJC1IVShatlwRyRHU6jrr0Zl9ti8WhsPQ/MUjw3owFEMQEHEv3Jm6B/NcaRS7s+wvZG6mkW/VNVPnLdIyWq6HHJeWpvt0uUpZkMBlAopZC/B8ydNrsLeN2M= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 02/12] qga: Use common time encoding for guest-get-devices 'driver-date' Date: Mon, 2 Nov 2020 19:11:24 -0600 Message-Id: <20201103011134.887744-3-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA9PR13CA0226.namprd13.prod.outlook.com (2603:10b6:806:25::21) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b64cbae6-7eaf-4652-f9f6-08d87f958598 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:60; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EV0LKqNhghtYIgFCL4mbqB8Pd7dr+lnZXOC7ksfVqhljxs8M3K5ANO1FW+55oimE0C+IEMYIBsPB2FaGjOWAbucm9LMOEo3uYXw3ST5Fk1h0oG6CUfNPmXDQaqHFBMqqJtlRtXrB/701EBMf/47SOYdutHWHDI02oj/VVx3fHlzlRtc6hGGm/RQkXWRggMZe13gPXOg+YEksrsH+CFAQD0XTDOoCsQZkQnNxjxsayEqvMo9PwH8ngnSPx6LLLCSvK/sETUhokK/c55kI1+2fZRiTwZr/xwDfJ23zgJbpvSbC7P9SS/3lnmdygywgD54vsHR1shB7sRxn5EjPaECnpQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(83380400001)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: HsVhfMtcvLbJZySQE5nw7C14PvDjhXCyG/96Bv3FG8H/oWRa7azCiB7BeAysStwkYuXJqBmulPuVQuTfBf2GO5v5b5quN9rOE7e9O2TQ1uYGI8AwCN1Nl5WO+Qf72AoP/ChBfQ7bs8Jkn1qGw0jFLHAv3bSBAIrDoKPeZEDy/d5gIMmC6adMNhwfrrSJlssBc+HFB2oKe+EogZHUiFh0ods+PcfYMquLe0x8xXxV24rQEzETYJoHzM4DoS3R1dss+VnCnvRAbPdEpNszAzBmivJvsCDOE5l6jPZDklfCLLQA/FFIOe3nsorUA6sdi4/BVSP5N/12MOg7c8qtdtgK1zb6AewrNhK2c17g1Owm/169Xr+CyOHbVtFR/jAIpMOZEXNWDnZuHi5fQB1dPk8KYawhje5WMXF0JuBIhOgfmPL/IOk/ck0irxR6Svwi5edf0uAchqc5uTScENxI8FuxSP/6zaFMwEom1qUl2pI5I7sOJAcfRBdxaiRDjv9p+j+AUNf0y7pi1+AGGgSYVAdJNvVL2+arOo2C/vgJEwezkE2DSyrPRRWoThSQTqyf7HEf+t70+GLSV7MK0+fWA2K1EK1f8xutYKsRG78VcG4AKR3UmMk8qcjvSNYcZJQ+MneTEFsTb+iUSkgJyNMSPLoduw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b64cbae6-7eaf-4652-f9f6-08d87f958598 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:24.3435 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sYnXiv8rogEWI+xD1gy5DolQOXBHrJFbW4BK5BgGmJUTJRElzfi6tyDq9CS0ObtdjmbtxKj2mjO0Q7dnnTv1Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.58; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:23 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Markus Armbruster guest-get-devices returns 'driver-date' as string in the format YYYY-MM-DD. Goes back to recent commit 2e4211cee4 "qga: add command guest-get-devices for reporting VirtIO devices". We should avoid use of multiple encodings for the same kind of data. Especially string encodings. Change it to return nanoseconds since the epoch, like guest-get-time does. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/commands-win32.c | 19 +++++++++++-------- qga/qapi-schema.json | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 879b02b6c3..b01616a992 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1641,6 +1641,12 @@ out: return head; } =20 +static int64_t filetime_to_ns(const FILETIME *tf) +{ + return ((((int64_t)tf->dwHighDateTime << 32) | tf->dwLowDateTime) + - W32_FT_OFFSET) * 100; +} + int64_t qmp_guest_get_time(Error **errp) { SYSTEMTIME ts =3D {0}; @@ -1657,8 +1663,7 @@ int64_t qmp_guest_get_time(Error **errp) return -1; } =20 - return ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime) - - W32_FT_OFFSET) * 100; + return filetime_to_ns(&tf); } =20 void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) @@ -2363,7 +2368,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) slog("enumerating devices"); for (i =3D 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++)= { bool skip =3D true; - SYSTEMTIME utc_date; g_autofree LPWSTR name =3D NULL; g_autofree LPFILETIME date =3D NULL; g_autofree LPWSTR version =3D NULL; @@ -2434,13 +2438,12 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **= errp) slog("failed to get driver date"); continue; } - FileTimeToSystemTime(date, &utc_date); - device->driver_date =3D g_strdup_printf("%04d-%02d-%02d", - utc_date.wYear, utc_date.wMonth, utc_date.wDay); + device->driver_date =3D filetime_to_ns(date); device->has_driver_date =3D true; =20 - slog("driver: %s\ndriver version: %s,%s\n", device->driver_name, - device->driver_date, device->driver_version); + slog("driver: %s\ndriver version: %" PRId64 ",%s\n", + device->driver_name, device->driver_date, + device->driver_version); item =3D g_new0(GuestDeviceInfoList, 1); item->value =3D g_steal_pointer(&device); if (!cur_item) { diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index f2c81cda2b..c7bfb8bf6a 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1282,7 +1282,7 @@ # @GuestDeviceInfo: # # @driver-name: name of the associated driver -# @driver-date: driver release date in format YYYY-MM-DD +# @driver-date: driver release date, in nanoseconds since the epoch # @driver-version: driver version # @id: device ID # @@ -1291,7 +1291,7 @@ { 'struct': 'GuestDeviceInfo', 'data': { 'driver-name': 'str', - '*driver-date': 'str', + '*driver-date': 'int', '*driver-version': 'str', '*id': 'GuestDeviceId' } } --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366561; cv=pass; d=zohomail.com; s=zohoarc; b=Odv9DTu9ShbcHgCJrsFTfBHQHhTCQoX3pAj5HcyuaXtebeDaXybeGsIMx51tyzEIVE36tAtaxK9JjTHhQaA1B2pOZC9v74gVuiSqxZ0xjV/OG6fcfmFWTOf+Iuz+Wz1M181xeLPMMIUdmThIzijifI7u03TfJ+p3XC7HYmZNpE0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366561; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UVOT+Ji/XN+UthHk4J8n5dOXuOASmrPvPQAuUjq7el8=; b=fV1YrCgZbGUNCXbI70hC9GCEDs13QtdQ1/evg8dEqbnwqFEI60slK/F5eKejndvOEgfAq30AiZ82QPjaz5BYaUWAzFSbCL1j5FOu8RJQYffIgPoCqpE8dVJHPTCO5azAay8JI+PFJg6rQjGsa47GVEm88uy7vhGR5vuQh7t1c7U= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366561005268.14964353390417; Mon, 2 Nov 2020 17:22:41 -0800 (PST) Received: from localhost ([::1]:44506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl1z-0003jP-SE for importer@patchew.org; Mon, 02 Nov 2020 20:22:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksc-0006eO-F4 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:04 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksZ-0005Yp-C1 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:56 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:27 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:27 +0000 Received: from localhost (165.204.77.11) by SA0PR11CA0008.namprd11.prod.outlook.com (2603:10b6:806:d3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:12:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DXlsDg3xH5BwYboSh02F0yS2JQfoubi3HyxRdFD7AFUUnRp6qlmvacXnQr4TzoHW9TuHYp9adCQipC+kcr1E3ZmuytlurBsq8RzC0+GGV3f4EBd5YKzqqGL6WzI9tlaPIa4jhYEVHNislkmj/MAWGUCLrujnBGYdb3S3EF+BfZftRJADnXYhP9tfItxY7S7stpoUhnEu+ePFl+Vd10j8GOp8LJr2YUEPwerVZvrHX1JHFEc8N8qbLjuj1WAQ6bGWKV1ui47XPlzYSnjD1xDA8vA126iOqlg3qZolYIrpi0TvZRlBS/kRQFFspW2bozRTqM/Pqsn1ZUKyjcgXriCTAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UVOT+Ji/XN+UthHk4J8n5dOXuOASmrPvPQAuUjq7el8=; b=JMJyTisuSzJvVplPp01WwYaPgSeGouJibjVqNCLPMTy/pWEObvfAHk/XL+vUnY+rOHTi6tTJWOsQUN/gIj6EMo9K9dJqPT1DiLyY8QmOJeph/n9RYqvGCZxheg7Suog4kxd075o+MY5D0JVe/4PyqfQQpEPtsIWRJ5RQO0DFWrlQ9BtzfWxntifEtgiBEqRGOa97tojkpKrJsoP3yr6krsA9epqwtsE1AharYJ76kBL1d5bgaVAh0ugn7++tRNCBVYMFefTyhky8cj/sDEjfZaXI+9yamaH/Cfj0VYZU4ccIe5RTQ70LKv9wDnMjn55MdukIBotNJ5/lr4TxDQz2UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UVOT+Ji/XN+UthHk4J8n5dOXuOASmrPvPQAuUjq7el8=; b=RfxoJ30oeDw6UoRQYIN1fArZxeqkrv1Ztv6JdC4mJySkknZfF6quKEnd1Qef78ZarmLGEMSyBNfASpd2w++3GzXs2S4yoxm8pONo/9pO0SJzQGUnSA9xiY2J133YTYENh5V3KeYotJUaQxpkgElhcGSdMVbh7QkLG2BQGzTsMEM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 03/12] qga-win: Fix guest-get-devices error API violations Date: Mon, 2 Nov 2020 19:11:25 -0600 Message-Id: <20201103011134.887744-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA0PR11CA0008.namprd11.prod.outlook.com (2603:10b6:806:d3::13) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c2f5fac4-1329-471d-54eb-08d87f958750 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wKjG9BhYFo4MsueLZlWV5x4KKb8CfXbtL/mqw2o1goTZipNAg2NSFHwX4MO4M3bx2sDFJcwftfd4doTjL/7CiTVMgmHnONHvhphkf76dyMqPIVgEFIE3sZZgI+/IMrxNBZA8eIci5kjIj05rvRz0kLCJofVQDsAiWn5gFkRNFMsVJ7EBSR+7dHLUlEDcdjJzS02w6nAsgJmhfU5sgmq5zbQ5L+C1HhmLxKE9I7srG5ONvOXaISpQNwCKjMreLWFdYTjFk5K2kznq3Bh8xEU4Pjid4gPFIP0WcX4GKB4657tWhW6NWts4D4PcXqs1QqX7 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(83380400001)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: q9Z3p1E0V14ps5mD/AIV6dNmb7AwQNE/H5inB6z6tuXe0XeREkMRT8gg5Q9fn9ujyVw7oHA3qaOPH7taBR3q1XnRCK25IZm6p0CXQa4LRDkAx94AAakyUPI7Yv7BuAG02B0wCAHepiOjJVi+REk6LDmjvgTf7Z68c8G9lD4A7stx5oT5hj7X0MOcmtTYM4Uj2n/uTHaNSw0opjcMv42qI92SPdFWhcwzgnAJCctwrA3nOjLtvgt8tpK5T4Komj9l5LdZ8mTuyPOE87K9xWjzefWpbv89CpsLG1wVZSbvEBUjs4IyZR2evQezBC9b+Fq046WjluS5HMeRWGErxU+1eCAdpofgIyy8uXpmNmpuHAuKQFuj7tB9dLcCb4KlDEYh99v9COqzMJ3asfJs/MfmX4jQP5cJ1eHr6BHkQtKVeEGFYsyA6GcQiplMJ96NuiK777Q8+UwkXQ/vIR968ojBOlc6UPKQZ3UtoE9rhw0mnWXRhXE7AOn+zN0sX3ld6R58OpFcdhhKJeQ1EOQklGWMybVz3+cAhBly68c1ATnU+VV7hOKvbFEvWCVfNY/MIAjpOGyg2pOMMM3A43oprRCemB0razrMceF80+fQfcPFuy9vPJSpACJvbyRNJQLC1rC54LapeN0RJrbS6K/DQq1YFA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2f5fac4-1329-471d-54eb-08d87f958750 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:27.2149 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RpJ86uVZeHDfKvdDBYzoM0sF0Vg5xztX79mrlMl+wo6p6i1Rp20WqAqEWFM1FVYU9i7Vp+MyAU7Cqna9t9jPmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Markus Armbruster The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call. qmp_guest_get_devices() is wrong that way: it calls error_setg() in a loop. If no iteration fails, the function returns a value and sets no error. Okay. If exactly one iteration fails, the function returns a value and sets an error. Wrong. If multiple iterations fail, the function trips error_setv()'s assertion. Fix it to return immediately on error. Perhaps the failure to convert the driver version to UTF-8 should not be an error. We could simply not report the botched version string instead. Drop a superfluous continue while there. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/commands-win32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index b01616a992..1efe3ba076 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2385,7 +2385,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) device->driver_name =3D g_utf16_to_utf8(name, -1, NULL, NULL, NULL= ); if (device->driver_name =3D=3D NULL) { error_setg(errp, "conversion to utf8 failed (driver name)"); - continue; + return NULL; } slog("querying device: %s", device->driver_name); hw_ids =3D ga_get_hardware_ids(dev_info_data.DevInst); @@ -2428,7 +2428,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) NULL, NULL); if (device->driver_version =3D=3D NULL) { error_setg(errp, "conversion to utf8 failed (driver version)"); - continue; + return NULL; } device->has_driver_version =3D true; =20 @@ -2452,7 +2452,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) cur_item->next =3D item; cur_item =3D item; } - continue; } =20 if (dev_info !=3D INVALID_HANDLE_VALUE) { --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366602; cv=pass; d=zohomail.com; s=zohoarc; b=aM0V5mNrIBDKsuG/CH+ipn/MV05aFEFJTYLQ0oKqZy4V08zID8yE7QRsC9ev8DLa3KivCtzmy2lVZpUwTvlo/KfXokJtMIAZC1lE5YKRsYqcSBsrL8TiuUs6EMbBmUT5r+ZHKk9J/44D5cR6LYCrx69U4CIk5d7qLfcTdDavDLo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1gqDMia7c4BktleQtq4MXU98cKjxCSJ/JIUaGfLlL6E=; b=O6axdK5+WSRMIy4aJgFk3zMWTzlEhJ/uaVn1uanA0AB9m5yOx+tUHoVJbav7WAq1gsg45v3OcII/+LUaAvgA1DFsF3Hxvjs7bhq4kqk2Mmbhqy696Mo6rawjbiyEyv9urQlnhxTb3Wr+JGcyy5YHtWFnmhW0Tue2tDmVYmB7emw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366602869180.53497205492783; Mon, 2 Nov 2020 17:23:22 -0800 (PST) Received: from localhost ([::1]:45858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl2Y-0004Jh-Tg for importer@patchew.org; Mon, 02 Nov 2020 20:23:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksi-0006f6-Ou for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:04 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksc-0005Yp-PB for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:00 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:30 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:30 +0000 Received: from localhost (165.204.77.11) by SA0PR11CA0002.namprd11.prod.outlook.com (2603:10b6:806:d3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:12:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkyQv0eSJzgbGNpM5F9r2fUbJdc77zf1bom0zZuvlW5o3mpoTlsB3jp5U+fXZ1k/fuP0NdxTLtZp31QYThT+F20waU8yAZTFAVDVgfoupP9+zX8nAYssO52lT+bJTJ3v3Z7QLTml9cy+lohlblWcU+RDq3hL+g8cfeuk97A/zsKsHP35nRw0J1ivDRqyT8BfwP6w30JjU7W0vG9J2rV4eb5uBtFIJ6e+AbX9Fs98nff9cJvpMAXXq9M2zpDcpWGoCgiostHNfYLE8W2+UyBHHpc20mlJLCuIUaBtQ12PgDUs0pjcXLUgjtvqJnx4RF0rar1RuT2IZXaCjBzWkH+lPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1gqDMia7c4BktleQtq4MXU98cKjxCSJ/JIUaGfLlL6E=; b=DKtIW7jT7oax636SXuZsN1IuvNgfqyFPeG6gZgdB90ggjaJOMYYUMRbn3JnVLCuCnVfwFAsJqwAneQnD/JxwMoK/Iny22g9VHZsKr+tDxM9/Tum+BaNOiDje519z/QxwGHnt+VAh2jjzxgmzfVdrsafKS3p1IgN2j4hgDCCPe8Wu4aC11awDhNZm0bbmEIyUt45HI5U2cpzZAKsjWZoh68B0ZiY843zPfaZiSoFWrfgXGf7HsGyHp6ja/fRxABibw49TFFGqRSoxcOd+Cl3728Qr3yPW3628gnhHYpGDMz69A6g5KGkxFngFNr3TYIOegUyNO/7z0FyeECKRM6m+Dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1gqDMia7c4BktleQtq4MXU98cKjxCSJ/JIUaGfLlL6E=; b=rrhHQJsfuWVpeCLKgQGVJZ8U9TZDoGb1kkdoE2JW/0t8G73Wf8BIecWCEm1b46Hn/fWYOPLfVQ8dotSi5qFMMFCHp2SdZnLbv2JJsAUGc8VRm+YQjWR6kMcQ56RTM8trxtINQqFdMleXjpIuKnbWe01nwqJUjxdnlbKUsOFi6U0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 04/12] qga: Flatten simple union GuestDeviceId Date: Mon, 2 Nov 2020 19:11:26 -0600 Message-Id: <20201103011134.887744-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA0PR11CA0002.namprd11.prod.outlook.com (2603:10b6:806:d3::7) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b8e7634c-3db2-45ad-1eac-08d87f958916 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PZNl1igfe7Luv+s86zNbiEsZgfNZcqQw2UEfYrR2dvmbi/ZTyjGJdzeEHdOMHKBobI1K+h2jNqZpLzkBt3t/l0MIwir0VLrvyGc71eh+6nRvx2xJKtDigZ14ugTiZy3XId6o0HyEQ0ptENvcpG6CItTMESeLrBeBxxNfLW/K6vf24HASlF+pdDvAD2HoBnY2bNE/m5Sik0J4LQNjG2uZxfh8j+0Sr7KuZk6LOw9As47RaFapW/dnonE8KJSmOxcPJ9pxME3sNBbiOyyMzVS7ypEakZMDhZ3yllMLLO0lZn5BXQ4hzBpZuCKo0B8LolyP5VMF37foMkJPc7xNrAKoTA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MWJ7fc/i1UrflMM5apT9q7vBxeT/WVSxHCG35gRKVmg0AqR4czSCVOLpizQl9WcyFf4SirGQPv3SHa1DJ+slGveZpFMRsAm9wil6EbM3zwN9fjL2rY3plgE0ivQ5+wAI34qiKbosc18tA4I3SFFPj8e0MfdhXGrc23b6Kl9nJ0VW50FZg/CunugBsf9VWx0nBESutXKNjUxWhKTChgx6L3kaZYvzOEjpsNVEKMlD7+oeTGcnOktSvL0SYYOYaMvAtvLeukgukNvV1ifVXT0Y8pWAujnTl1ThPumQHvfPZiei1P6lutNB0vo4cOu1gUAcIR5i2OFALp0sNucZJWv8szQQJUzl1N5Gcy+OSrd3UopZ+MgxYT2rnQO2kysTHvGJhrvlTXkQpOTbNIcov3OUqFUo8r+aWCxUjCxe0jPuE0ufmo1giLnhnUDgZeQcjimc71RxwvsG7e/Znc+6hRWt8c8yGRyGnW/srNzQySGkmFBq8uDiWYDdLkLHOgmbRJWK4dwFPMMcj8MIMITjfdldgsacBX3wMd0aiimYngnz7Z4UeCzVFkW04N6f9+n5UGtwI4WAUFexJPPTQ+abmELz2LBr0Tw8a4URZFTlCsZlURqiKmoV9RVDZBIysXAbP3e4tlH6Ym/S2saKam93Ig9YAA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8e7634c-3db2-45ad-1eac-08d87f958916 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:30.1251 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IpliANdpVBktPPc/9gU1VXhOqLXowWBJyEtK9kZWc/MP+yIUFnhq5y8EHpDmsd4+8S5DKTITe75OHFGDkz6LRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Markus Armbruster Simple unions are simpler than flat unions in the schema, but more complicated in C and on the QMP wire: there's extra indirection in C and extra nesting on the wire, both pointless. They should be avoided in new code. GuestDeviceId was recently added for guest-get-devices. Convert it to a flat union. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Michael Roth --- qga/commands-win32.c | 9 ++++----- qga/qapi-schema.json | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 1efe3ba076..0c33d48aaa 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2400,16 +2400,15 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **= errp) } skip =3D false; =20 - id =3D g_new0(GuestDeviceIdPCI, 1); vendor_id =3D g_match_info_fetch(match_info, 1); device_id =3D g_match_info_fetch(match_info, 2); - id->vendor_id =3D g_ascii_strtoull(vendor_id, NULL, 16); - id->device_id =3D g_ascii_strtoull(device_id, NULL, 16); =20 device->id =3D g_new0(GuestDeviceId, 1); device->has_id =3D true; - device->id->type =3D GUEST_DEVICE_ID_KIND_PCI; - device->id->u.pci.data =3D id; + device->id->type =3D GUEST_DEVICE_TYPE_PCI; + id =3D &device->id->u.pci; + id->vendor_id =3D g_ascii_strtoull(vendor_id, NULL, 16); + id->device_id =3D g_ascii_strtoull(device_id, NULL, 16); =20 g_match_info_free(match_info); break; diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index c7bfb8bf6a..fe10631e4c 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1256,6 +1256,12 @@ { 'command': 'guest-get-osinfo', 'returns': 'GuestOSInfo' } =20 +## +# @GuestDeviceType: +## +{ 'enum': 'GuestDeviceType', + 'data': [ 'pci' ] } + ## # @GuestDeviceIdPCI: # @@ -1276,6 +1282,8 @@ # Since: 5.2 ## { 'union': 'GuestDeviceId', + 'base': { 'type': 'GuestDeviceType' }, + 'discriminator': 'type', 'data': { 'pci': 'GuestDeviceIdPCI' } } =20 ## --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604367378; cv=pass; d=zohomail.com; s=zohoarc; b=XtE288nbEGRUFvXkZ36xdNHF/OWB8Ve8TUQekvC1o9eSRLdH/958pxN0MAwF+Y+GlwOafiwOATq3t5RpW9FWQ9dowxtHtTccbbgxuPLJMYuXuUHFlIsmEcSTssL/kFR+7CA6pRXj328OFgIZ8tAv1lmCjUY9NnpvlIgSsrXf4oo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604367378; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=waizySm79FyW0klesiTXmFKAcmtlT2Hov5IiZncGR9A=; b=h5xcGfr0bXNhtqfQdxuvZyXsstl4CKu5B4hdzRpOBSrUWKVSUvndUBoftQVRVJMbb7i8fR59S1QTSby6CgOTzn4ShIKuozGLrJ6DSyqo6Ol9IMhMjv1hztfuUyz0ne0KKntdJitb43DVDRnL6Y1d8C2k8/b0V48E1R+QpWSOf0c= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604367378657554.8326279449298; Mon, 2 Nov 2020 17:36:18 -0800 (PST) Received: from localhost ([::1]:37544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZlFB-0004fh-Ae for importer@patchew.org; Mon, 02 Nov 2020 20:36:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksk-0006h8-Lf for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:06 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksj-0005Yp-1s for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:06 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:32 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:32 +0000 Received: from localhost (165.204.77.11) by SA0PR11CA0003.namprd11.prod.outlook.com (2603:10b6:806:d3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:12:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wq7SrpjLZlMXt+3Og0l8OV3crfp/2u8zzg73wQKSx02/LUBgyP3sc5hALgVwOOC48R4fCjGjkAJdz/iEwfgzNxAPFUQ/OUKEegTpMF5NLZsUWZH2TbkofTZKh2P0UGmud0VdI7Mi2OLYKv2rCzhWzoVcN/PIkWe3iAvBUX44VpazF/W9UmDpmcLR/2YZVfnzwL8fNZmo7VOatLoc4hDpQDiCYyJphYg1xmHlUOq6hTC6G4fIYJ1IdXeGMncsQYXdoUgZID+PtQ7w+o7SxUZ2eDI3ioMzhFp0koL/Aqq+oy9FjFJsTEaaaDvRbwT4GVBGmdcDzg9H4d5LzQtLlMyL/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=waizySm79FyW0klesiTXmFKAcmtlT2Hov5IiZncGR9A=; b=fH3uOCrGQQ+Kxs1bEgKEBMM/DbLdyvuwi809qyiXgfM86GfC9QfdSM+ARWbiz0d3x5JjrnIzYRN2NV+yue3yPCEqVYlXUajHYqmTW/fWIn1Cyw+h2U7nvWyJKpj0L7nG7PEnZHDtAeeghEv60NNUpHvIrTm4aYqVmKu4ojnkAglNskpSbm7Ie6WzRe0W4v5Tubfw1PFgcErGYI/Zfdy2BLSrmNwxaeFh6XAZSNb8x6ohAGF/opauRyria0HVjcvgRwyXs84qzw+zzh6CLQTJEo0pQtDteXH/2LWu2b5rWg5+GZ2yFJN3D0Q9vikyaPzAlU0jOIbKW+TSz3W3RqXcbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=waizySm79FyW0klesiTXmFKAcmtlT2Hov5IiZncGR9A=; b=kSbqQ0qoOJZ/2fQO2XW7+UQOEVD/MVk4te0R183qWlK4tpu5QF2Ij/u5nNtCT0b8tKI06pWK/OCRCwrINeFt3GuR9K/rGaOcRlxv60IEipzepKKmHMivGBYljZ/8vl2VG1NTWKqrPhFibpuQ2CYtm/VdFYcztskN8reTK2CMhOI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 05/12] qga: add command guest-get-disks Date: Mon, 2 Nov 2020 19:11:27 -0600 Message-Id: <20201103011134.887744-6-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA0PR11CA0003.namprd11.prod.outlook.com (2603:10b6:806:d3::8) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 123f4b29-4b33-4b92-3c65-08d87f958a7f X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u7JkmyECrmYdqUnANEps6J/OVj/MVx6L3m8EOQbKTabmJWwCwttlIwiqc3ymslnZzKWvtIfWZXy/AgaUY8azVrSES3asgnZ2LYONV2TFp48qepgFZ+c9ArKGDJSqZqnJtOGnfWZyMwGJSOTYf+j7kSE67hDSD9XPm41ZxJCGzXH7/ba6YgzrfhOVsd0o1NIa76iHc5sjEyRZvzY1ClVOBBTx9++X4x+RIwVMV2ZdSl+6Fl+2TmX/Be5U9gUvysUmiMGQMaP/1fLwxfzzzkyL1eDgeQb909+K9ttJTlgLng0So9qjlRSMU+WQ/NYp/uN3s0pYaICbbaf/JqdY+1YJlA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: U/+frQjJgB3IaFmO5tFZM6WQG8OsHpF+fw1u605LhPfIRQRX+jh0jRgrO4lIpD3DGA6zZt/YYrKZaf4Er7sVxAuJ2nCeDNWWR1I3vihrJLY5JhINqMjr5sNtAOfsdxWOd3rhJiIVsCsyUPEaRD1pHEIFxZSZCvrXRbtvfMPqVSKP9z5MYA4AmYK9DcmsKSa3sARzYPiqOv1xLdPr7UxMYObxq4t/DzTHrKmj0E3L6NLKDiZglf6zljsJTteTwaBshl5kW2UCL7KWPDe1Cdt8UcPyQUE4FZd7JEWRFI9UAJP9vdLeOxNf0g5FzSZz5W5tU5EbxDPwi1tLvCsNnWF/ueTUDQET9CZM7ebHNzW/Fu/4ZIunpo3lFHXDfBLInFcoBcgVRrYsHJ3FoUH9z9xPkWcXbAaCi565jyvjGrv1RdhBNUFprhONhtGR0lodeZtZa4m9ALQ00Ar7feynzMhuv1vU5Cv9Vr9Zn60vXUa4uF5R+d/0JMpHLJZ6OIFBW5k6ERegLJzNK8ipdgL6FtWF9yZHIkBvJhL/hHH5TAdAq5HD8Q0g0KlbKYEz3F6359N+zSYYgc49KmPISzxgzkWA8twsmJSFaxZCsOAhxzqeUAIgHq2rcHsuXNwyFtOBdRF2ZD9k8aLaWqRTUD/wZr/WQw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 123f4b29-4b33-4b92-3c65-08d87f958a7f X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:32.5016 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NjsIvBLPsBne6Qck/OZtXK4qldrUqS0TtM6Z/pxtVrpDG0y4BIULC83tODuFP1IG0zNlmOFf7Yxfa/wsJ1wiWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Add API and stubs for new guest-get-disks command. The command guest-get-fsinfo can be used to list information about disks and partitions but it is limited only to mounted disks with filesystem. This new command should allow listing information about disks of the VM regardles whether they are mounted or not. This can be usefull for management applications for mapping virtualized devices or pass-through devices to device names in the guest OS. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/commands-posix.c | 6 ++++++ qga/commands-win32.c | 6 ++++++ qga/qapi-schema.json | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 3bffee99d4..422144bcff 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -3051,3 +3051,9 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) =20 return NULL; } + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0c33d48aaa..f7bdd5a8b5 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2458,3 +2458,9 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) } return head; } + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index fe10631e4c..e123a000be 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -865,6 +865,37 @@ 'bus': 'int', 'target': 'int', 'unit': 'int', '*serial': 'str', '*dev': 'str'} } =20 +## +# @GuestDiskInfo: +# +# @name: device node (Linux) or device UNC (Windows) +# @partition: whether this is a partition or disk +# @dependents: list of dependent devices; e.g. for LVs of the LVM this will +# hold the list of PVs, for LUKS encrypted volume this will +# contain the disk where the volume is placed. (Linux) +# @address: disk address information (only for non-virtual devices) +# @alias: optional alias assigned to the disk, on Linux this is a name ass= igned +# by device mapper +# +# Since 5.2 +## +{ 'struct': 'GuestDiskInfo', + 'data': {'name': 'str', 'partition': 'bool', 'dependents': ['str'], + '*address': 'GuestDiskAddress', '*alias': 'str'} } + +## +# @guest-get-disks: +# +# Returns: The list of disks in the guest. For Windows these are only the +# physical disks. On Linux these are all root block devices of +# non-zero size including e.g. removable devices, loop devices, +# NBD, etc. +# +# Since: 5.2 +## +{ 'command': 'guest-get-disks', + 'returns': ['GuestDiskInfo'] } + ## # @GuestFilesystemInfo: # --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366826; cv=pass; d=zohomail.com; s=zohoarc; b=eF++1ppu+Ln4qI//JtzTLXn3I/CzjiYAcWxJF5PSD2HvshdI3AnJNEtiFPY2mTiItENJhxax6nFdx35rAo/YkcLioLKMIaOPvnhQm9OZHyUgR6ZujEHLSkIpLCyGXlTFBQHy51NBxP3oLcwaPIod9mSV8Lx4I7+wVtB1FKY1pGk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366826; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iVteiaszyvTJI5WzzsQ6wCqwI7QUBVQMc+lGITsCvwI=; b=EObFfdiqd5Ep2c8LksFrU+sON1gYli7PBsR8iQ8PEaYYHPgPUhKcX9DCXiWgmzbmb9hP2BGNKxF1tBVHxxigOGox+LteNHL2aIhWYYOKwY8FDkwyk5VcbTvqyOaqIp4pmTbwP/h3rr7BgfDC0Q8jMaNA5kIXP46Y+yZH+N/YWG0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366826951736.7292537264009; Mon, 2 Nov 2020 17:27:06 -0800 (PST) Received: from localhost ([::1]:53146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl6H-0007Tf-PV for importer@patchew.org; Mon, 02 Nov 2020 20:27:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksm-0006iT-Vw for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:09 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksk-0005Yp-Vb for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:08 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:35 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:35 +0000 Received: from localhost (165.204.77.11) by SN4PR0801CA0003.namprd08.prod.outlook.com (2603:10b6:803:29::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:12:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F8JXJs9tTwXpafbZYvMaqS+4b9op4rlLk9PIM346t2LBheiDiq6bhcbq4CCYo6AkaLfFY+cEzC0dtAjeAl19Rg5CyPW0ZO9kpynGmwJIgLqR/N35GMRMFRA2EZw1XaiPzvkYgGyX2G/6mqlVyfbHDJVRNfzeqPNDzcFn08bTL9EKm2rlvEgwWDleCFiyh9Gp1RZfp8UTk80I7ZA9bKbOByZsn+jLVOpIscHfPm8vX1qUJ0uxDSnU7PWg2MG8u5CNmfqXx9HS+AIjRR9Hm/qpfszjhUh5Ay/n0QqPxlX7ebya6BJ51joljQLlWf+kD0OnA/UKKCvJb5c+m1Jn4Blt/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iVteiaszyvTJI5WzzsQ6wCqwI7QUBVQMc+lGITsCvwI=; b=TXhWh4A2SIq7iT5ja9MgXIluKD5CJIS0DWJH6xKpRqzmfCKCIM/hdGCGZbiOuXMcatsttLSZKQVIHbwZsbkUjnsWxDJIimZL9lQSEt7aauSSae7F+yNhV8q3xQd+/MWnfvx2vZF9hcJlyftr6TngTcEYkseHcs0rH4KQLvmOrq0nhSh6CQ/UyPWx/J7qMmuTpzTxUHR+Rpmlqv8fgZocvL5ZLjYVR6+Rwfa7Sz+ZOL8PvIlrJwwcp5Tl89f9emRiNJLDHEIWCTrtu0gH+2MCg6heNgzDTdDkSzoMn2n/WNt+PqFnXwFYzkpQmKSFIS1DLgxrRZ5VZ2+B7lysqsjc3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iVteiaszyvTJI5WzzsQ6wCqwI7QUBVQMc+lGITsCvwI=; b=PMvgrtMq3mZCBx/91YHlAgzbT/Vrrpi6ClysQUTeQDv0bVT8hrNCYxnLyzzsHeFSPibHARUFOxw7cvNYWDkYO9C7xICfFYl4GAOZb9BcRoyu3x3B2t/8t1e2I9yZlkXGO5qMPV2JOxgrNAafzlalrOdC3WtufSP7ug5j1KC3VNk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 06/12] qga: add implementation of guest-get-disks for Linux Date: Mon, 2 Nov 2020 19:11:28 -0600 Message-Id: <20201103011134.887744-7-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0801CA0003.namprd08.prod.outlook.com (2603:10b6:803:29::13) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e3287366-2307-47a1-0b52-08d87f958c7a X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:619; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cxx7+ZSPqkRQoj0HcbeTiCEHa8gJoyxYv3oC/OsF0lUY9l6qtjxqpLObRcUAC1AyC0GiNnbH7OYt5gLpAK32razNCmH2y3wxcnwlpWwi1PDUesgD5bGUL3dH/6jqAWk8gS/jFTy9Q2ZipEr3rKTxdTbJP+vxH/Z7R+Uc/AlszuX0AYbKDwsndMySBDxXIBJuyXmYiEKxPbf2hgyCEqCWWRqDChSZmsg7jc+xD2EdJFoZeUtO/L8hnUaKFafJ7QdXzb9aJQDwbRGXZFwaBuQc7UoqH84BumzUBx9tDvjVxsLvuO+523WsqnsOrK1zII2b X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(30864003)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: z/D7Izrxo9Op9JYrpyE+6si4t8siYXmUJMbNSFUurpL52phaLzpFR+bEhRiPnkB6GS4lwTHeejLni+ez30TYIvFsVXc9+W5Mqx8gamQWF5UktIjlQ5dRfWKnWIlZEcf3gq8r2LWL5ubZrZs7xT3tMllI7UzdCNZOSXzKGl83BbUWoRCMrqcfOfA48AZ8dpEzhH328E08kxY6SF8r2E7d3CArhKn2In2YxFpY3FCxgdhMmNE1mx3To8dXbktjS+ZIJjttcMiR/B9CUh00kgNnrTkrw+DmWUmH236wZSf4ivECGDatYELrutqA4rVDzyssjSCvgggZpCARdYhaDzOLX8YP8VgWSAxPGug+wcJpLo09pz1z8xcuFlGWVwqlN+ULOd1Os7rmAaMkMVl7AZoKZas6KAsbPrU4yWbedg1YTJhq3dvswtN+wIB/QI6QRJOSJwRvAcO1fUKGgxwU8vYcDrAUFlAMUYLUjwbabLX+BPO9V7uu+/b/4IrtdL56oyHuu3AkNdS44ixdUkcn5ppkFKtZh6LPRD0mdWkLMSHEjK5qYf1Wt4BdCl5tw1dp+vfBN4ipF1DrM6kYeF1UV92DUT4U+k32/ijP7b3m0DYjQspLJFkhpCLI5+5Sf9nAbhEK8QDcpZoeZblo6QgmbKAJ5w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3287366-2307-47a1-0b52-08d87f958c7a X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:35.8728 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 83TzZQfBWfJcbRYZa9TXfzb3wmddCmLgqRdWAkWKljQxlQykerntvN1XErhGo7bCSOA6SA0lnxtXR/9OCji+vg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD The command lists all disks (real and virtual) as well as disk partitions. For each disk the list of dependent disks is also listed and /dev path is used as a handle so it can be matched with "name" field of other returned disk entries. For disk partitions the "dependents" list is populated with the the parent device for easier tracking of hierarchy. Example output: { "return": [ ... { "name": "/dev/dm-0", "partition": false, "dependents": [ "/dev/sda2" ], "alias": "luks-7062202e-5b9b-433e-81e8-6628c40da9f7" }, { "name": "/dev/sda2", "partition": true, "dependents": [ "/dev/sda" ] }, { "name": "/dev/sda", "partition": false, "address": { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", "bus-type": "sata", ... "dev": "/dev/sda", "target": 0 }, "dependents": [] }, ... ] } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Marc-Andr=C3=A9 Lureau *add missing stub for !defined(CONFIG_FSFREEZE) *remove unused deps_dir variable Signed-off-by: Michael Roth --- qga/commands-posix.c | 303 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 292 insertions(+), 11 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 422144bcff..3711080d07 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1150,13 +1150,27 @@ static void build_guest_fsinfo_for_virtual_device(c= har const *syspath, closedir(dir); } =20 +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) { - char *syspath =3D realpath(devpath, NULL); + ERRP_GUARD(); + g_autofree char *syspath =3D NULL; + bool is_virtual =3D false; =20 + syspath =3D realpath(devpath, NULL); if (!syspath) { error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); return; @@ -1167,16 +1181,281 @@ static void build_guest_fsinfo_for_device(char con= st *devpath, } =20 g_debug(" parse sysfs path '%s'", syspath); - - if (strstr(syspath, "/devices/virtual/block/")) { + 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; =20 - free(syspath); + 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; } =20 +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; + } + while ((dep =3D g_dir_read_name(dp_deps)) !=3D NULL) { + g_autofree char *dep_dir =3D NULL; + strList *dep_item =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); + dep_item =3D g_new0(strList, 1); + dep_item->value =3D dev_name; + dep_item->next =3D disk->dependents; + disk->dependents =3D dep_item; + } + } + 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 *item, *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; + /* Add parent disk as dependent for easier tracking of hierarchy */ + partition->dependents =3D g_new0(strList, 1); + partition->dependents->value =3D g_strdup(disk_dev); + + item =3D g_new0(GuestDiskInfoList, 1); + item->value =3D partition; + item->next =3D ret; + ret =3D item; + + } + closedir(dp_disk); + + return ret; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + GuestDiskInfoList *item, *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); + disk->has_alias =3D (disk->alias !=3D NULL); + item =3D g_new0(GuestDiskInfoList, 1); + item->value =3D disk; + item->next =3D ret; + ret =3D item; + + /* 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; + } else if (disk->address !=3D NULL) { + disk->has_address =3D true; + } + } + + get_disk_deps(disk_dir, disk); + ret =3D get_disk_partitions(ret, de->d_name, disk_dir, dev_name); + } + 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) @@ -2773,6 +3052,13 @@ 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; +} + #endif /* CONFIG_FSFREEZE */ =20 #if !defined(CONFIG_FSTRIM) @@ -2809,7 +3095,8 @@ GList *ga_command_blacklist_init(GList *blacklist) const char *list[] =3D { "guest-get-fsinfo", "guest-fsfreeze-status", "guest-fsfreeze-freeze", "guest-fsfreeze-freeze-list", - "guest-fsfreeze-thaw", "guest-get-fsinfo", NULL}; + "guest-fsfreeze-thaw", "guest-get-fsinfo", + "guest-get-disks", NULL}; char **p =3D (char **)list; =20 while (*p) { @@ -3051,9 +3338,3 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) =20 return NULL; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366220; cv=pass; d=zohomail.com; s=zohoarc; b=HbA74ADtaxH27aUk0HSdMaft0CGil75qgokmZYaunJDnNxIFIoy1/mBM58Nj4M8QkSY9kHZcIgBLSZAIH8+JjOMexUhqzlN3sMfPC80iwZz/Kf5d8T469hOgEL0sxFa3ks7fOFYZODjmP8xfID0Bk9FJYF7k1p/5PEahFvvE/w8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366220; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OE2J8ejvlIA4aWrHVkoErkL61tROkH+vRjXCeNj3n7A=; b=lZEvyhauIc+RkSkSVwI/k5LynYwCLBhsAUWPdmh5b/ugW8bkYijWSjSPUBxYIa3B14yYyxuyz1ri22AerY0f5yWdNJJhb7p3kf1VuCr2BrQHzVia7/uzrrmdyY27K0Uo7mQKx3+CndZLUTZvhPJHXduoNmxQAQcs5MUW9GZ+knI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366220926624.1638983190239; Mon, 2 Nov 2020 17:17:00 -0800 (PST) Received: from localhost ([::1]:36510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZkwT-0000Ch-0k for importer@patchew.org; Mon, 02 Nov 2020 20:16:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZkso-0006mU-W5 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:11 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksn-0005Yp-95 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:10 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:38 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:38 +0000 Received: from localhost (165.204.77.11) by SN4PR0801CA0001.namprd08.prod.outlook.com (2603:10b6:803:29::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:12:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OFlNtRSW1pELxC7OHNHZoPXB+FoiG9pCz/2iar1vGFLLh8b7AEisvVxpNdzAPOIe/EGHJHolXY/NJy4fT21AceHjiw8NIV2rtuSOSEUAT6McThytDIRUrg/a31Ek85nDD7ar1tWGoZCYOjsGKxCGe+8XeoWCqgyAnpVS7hOunVwV6ubwvyPNc1cHg+8k0ynH1fGfWdEuyroeEVBUlBwRUbbsYsK/fgfR2Ei7I5U+vdD6XcgQB2KG9/aocT30SYitKVKDG8o+7kwz3GvW1FAsuAiibOI7AOEyr4GGuqjSSE/MTkxxdFvHIxCgCDKsBSAA2Q1eXjNUFmKS1fGKA+7WNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OE2J8ejvlIA4aWrHVkoErkL61tROkH+vRjXCeNj3n7A=; b=I8hp3bk+dHZzpO18qV7BAS24+5PQP5awVGJeW3xIKeufVTKBViZO9kIbJoODAxdpm+T2Ej5sc/osVGCN3DOXpLdsFjnslhN+sonixt/6UhOqYc5RrvCWj7AbgsWXmWSC33UWSwtb4KfzMo/DJCNkuuKzWHWWB6CBXbqgBzlNNbHC0Az2lambVgYxTN6XOxrfWOtL4gjLNEIqsTzTArmuzD31X6hkKWLk+qfP+IK3xr7rNhrWMwc4aQrx8+nr4BwgDVVgSnaDK5j6BRe0hvmbMa7+ldU6NP3VowhDpxfBteRN2CcWYh8pa6jiDWfdn5QlrkvkgNX1KnWX7Nbhe6XyBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OE2J8ejvlIA4aWrHVkoErkL61tROkH+vRjXCeNj3n7A=; b=EyQ8vyNoYQWyDpKP0oJH2OquX1ynpwQsmqR9MQFOCiRk2PUnhouif4kdreNF+frnJinwrbtAVY5Dsm64EDgAiQYVH9oq/fPe8iILTcCrMyqpHNNgtbPhMYrUj2iHAqjRr6AlgVBvDeK2L014+dXQE8mhprE55tZktmlJ2V7DLNM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 07/12] qga: add implementation of guest-get-disks for Windows Date: Mon, 2 Nov 2020 19:11:29 -0600 Message-Id: <20201103011134.887744-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0801CA0001.namprd08.prod.outlook.com (2603:10b6:803:29::11) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b7aac0bd-af8b-4a47-84fd-08d87f958e03 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kRO5KFRcCbynh4n7k7JyMPY4alPucktAUgm41AFwdHlOqVgZReJj3Xj+1cS4K/ofZ7230QRGUleAqFQvbp/VIuhg7rvwBRYiNT8W1zq/e8DRuTYYWKvYxbortK6dH+myMKmP+LgqXL0RLF3S/O1imGIQqybMv1CL9z8QZGVVrb+14jSMaD4SrWSXGYDKNBbvsRCmOD8PM6CxKWyeqTrIowyiuA+zF7NzK76VKAZhCj4wqw1smOaX+afo0P7v7XUabW9zYerKYIzIDvhejEr0ES70QUNtWWQWkf/4DZLmaftEcRJ6H8nAQQ7FJMBX4bypPJthQjPnQlOzNQ3VdZEQfA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(36756003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +D/ubJtEsraa+sq1FrE+vYdXzUvlT04uSUMbX17dnGl0ux9QPWMnXZE0n/EPrkbGBbDjBDuAWx+c6l++igHZ7jDJvpLnU0/+OHcvozX30ue+3m50tvTTNcPSXmzfEbryyC+Ov+J6wxzzISQYiMsRK8U5pfUGhlCFWB1OLAW0ENHDutglxHFs/PQgXkKQFpmKtuJmVUNfitWcgr7Yk7cQw2D+0hBUKkckSCcBXnquikPAKaxtZQSeDoo9oEhueGERGjY957pi007bUrWhKo7ASm4I8L3LoNhtYPcJS+Ug+hy+Ji6C4kXGyOn+ptT30UNzuxIkT9POfv7hiXMQcp/daDnjOR69Pev+jvp1ddnBHY1O6OQFBN/NkFHQSQLLtqXyQ2ofoCXVOg1iGStVNqhLCsq4Bua9U3bebEA2h2d1yzzaE6p2Be26cWC4juZV5QkZSFa5UtyZZ/3EMNTXwz8ITCF0JjXuF0XUhTqiry+EuHn7p0CdI5/tKts7LQfxG7PESxAQapBHiLZOYj6iwzGsgSmRYw3b0Hg10yM2C4xIYNrW3iX4vkczUbSgz0kdCIZdE48FRR8YfKaijxTZcvl3AYP2JAE8CwkgTLZPjlKQWYB+U13Onjf5fj2j+U8GE41U4uvgQiIu2I2cL+S5xl64xw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7aac0bd-af8b-4a47-84fd-08d87f958e03 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:38.4744 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aLScvA6wPkZnOG9QLV0GVurHgtuZhEMTk9OByaTexs37LGbHfu4S5qpTg0221bJOmKAt7Aacl+WdTg9q62umLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD The command lists all the physical disk drives. Unlike for Linux partitions and virtual volumes are not listed. Example output: { "return": [ { "name": "\\\\.\\PhysicalDrive0", "partition": false, "address": { "serial": "QM00001", "bus-type": "sata", ... }, "dependents": [] } ] } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Michael Roth --- qga/commands-win32.c | 107 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 6 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index f7bdd5a8b5..300b87c859 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -979,6 +979,101 @@ out: return list; } =20 +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + ERRP_GUARD(); + GuestDiskInfoList *new =3D NULL, *ret =3D NULL; + HDEVINFO dev_info; + SP_DEVICE_INTERFACE_DATA dev_iface_data; + int i; + + dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, + DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if (dev_info =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to get device tree"= ); + return NULL; + } + + g_debug("enumerating devices"); + dev_iface_data.cbSize =3D sizeof(SP_DEVICE_INTERFACE_DATA); + for (i =3D 0; + SetupDiEnumDeviceInterfaces(dev_info, NULL, &GUID_DEVINTERFACE_DIS= K, + i, &dev_iface_data); + i++) { + GuestDiskAddress *address =3D NULL; + GuestDiskInfo *disk =3D NULL; + Error *local_err =3D NULL; + g_autofree PSP_DEVICE_INTERFACE_DETAIL_DATA + pdev_iface_detail_data =3D NULL; + STORAGE_DEVICE_NUMBER sdn; + HANDLE dev_file; + DWORD size =3D 0; + BOOL result; + int attempt; + + g_debug(" getting device path"); + for (attempt =3D 0, result =3D FALSE; attempt < 2 && !result; atte= mpt++) { + result =3D SetupDiGetDeviceInterfaceDetail(dev_info, + &dev_iface_data, pdev_iface_detail_data, size, &size, NULL= ); + if (result) { + break; + } + if (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) { + pdev_iface_detail_data =3D g_realloc(pdev_iface_detail_dat= a, + size); + pdev_iface_detail_data->cbSize =3D + sizeof(*pdev_iface_detail_data); + } else { + g_debug("failed to get device interface details"); + break; + } + } + if (!result) { + g_debug("skipping device"); + continue; + } + + g_debug(" device: %s", pdev_iface_detail_data->DevicePath); + dev_file =3D CreateFile(pdev_iface_detail_data->DevicePath, 0, + FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (!DeviceIoControl(dev_file, IOCTL_STORAGE_GET_DEVICE_NUMBER, + NULL, 0, &sdn, sizeof(sdn), &size, NULL)) { + CloseHandle(dev_file); + debug_error("failed to get storage device number"); + continue; + } + CloseHandle(dev_file); + + disk =3D g_new0(GuestDiskInfo, 1); + disk->name =3D g_strdup_printf("\\\\.\\PhysicalDrive%lu", + sdn.DeviceNumber); + + g_debug(" number: %lu", sdn.DeviceNumber); + address =3D g_malloc0(sizeof(GuestDiskAddress)); + address->has_dev =3D true; + address->dev =3D g_strdup(disk->name); + get_single_disk_info(sdn.DeviceNumber, address, &local_err); + if (local_err) { + g_debug("failed to get disk info: %s", + error_get_pretty(local_err)); + error_free(local_err); + qapi_free_GuestDiskAddress(address); + address =3D NULL; + } else { + disk->address =3D address; + disk->has_address =3D true; + } + + new =3D g_malloc0(sizeof(GuestDiskInfoList)); + new->value =3D disk; + new->next =3D ret; + ret =3D new; + } + + SetupDiDestroyDeviceInfoList(dev_info); + return ret; +} + #else =20 static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **err= p) @@ -986,6 +1081,12 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) return NULL; } =20 +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + #endif /* CONFIG_QGA_NTDDSCSI */ =20 static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp) @@ -2458,9 +2559,3 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **er= rp) } return head; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366570; cv=pass; d=zohomail.com; s=zohoarc; b=BKWN9Nb3IszqXtjMYPvvL3tuqzWjy9P6wMf1eYWoT6waj573ZtHiwYh8AjVHHtpjvkyJt4PlbFGRwuro8I3z8/BKybOudDnFCiFcw2QYC7A50r/2FOa3EXnL62nGbHzLfjcLfULsRajgSRJFMZe9ZhgYeQf0oRrWG0bZvp3B7ic= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366570; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dxNQWgIru2r1B471fgC0ReHA9FdKC5m11LQJgXkIMtI=; b=fC/zDumqyffvAapHmCbWwmwj0ZQZuh2jr3Gc2SdkYu3o6aWzJ5KiqCwkx0Svte0t08lmrQG7KJeFXuU8wyYw7rK1ew209Z+QkGdKD4wxLPQQJfI5AdP4g3KMm06lFDJPgM/xue+ew3M3HdlF5PoS2ON3BVy3WUkkmt4WcuCV6o0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366570752997.3833501778045; Mon, 2 Nov 2020 17:22:50 -0800 (PST) Received: from localhost ([::1]:44920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl29-0003tw-K5 for importer@patchew.org; Mon, 02 Nov 2020 20:22:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksr-0006rt-BS for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:13 -0500 Received: from mail-mw2nam10on2055.outbound.protection.outlook.com ([40.107.94.55]:25952 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksp-0005Yp-Qv for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:13:13 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:41 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:41 +0000 Received: from localhost (165.204.77.11) by SN4PR0801CA0004.namprd08.prod.outlook.com (2603:10b6:803:29::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 01:12:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XAWIxKuhimvr8k9U9MALQVcjAM+mpSYakH1lVK02EEmhC4QuKhTPOuQtkUqA4vsNV72M3M3MjsPuaQdG1TsMw0sVqcc56IdPZhjy0sbEx/ibVUWoQlV+tAqgNW/Ew6ZEzvIzMC7nkJiqBMH1Wx4F1kdpMqYMy5um6Uc2/hxsgY6hqw/MKMb+q4qO9L0K62LrVxtycdH5s/OCvSS4LC56T3kajwDE+jHkwODya0Mj80HXpzzn2UayoVm1uwcS6+hqYnDaxX+Syc82Flm2m3CQWvjnKrY6U5mTe8LCUsL9GjBMHJnXFF0m6DXPFzpcpL7CkxVYvtGGprx6tOMBzjD+uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dxNQWgIru2r1B471fgC0ReHA9FdKC5m11LQJgXkIMtI=; b=X3vFsSbShmAXD3YXJxZVvZMb7wVwABNyPGtJDgIG7enJ9awIuuwP85VolXzS2xChYuU/rlxjTQfXVxm7Kb9OhHd2SJN4+uJMhFuyDYMZDIxecWnA57CjiX1WonFOrs4YCp2UokMU/cKrpVMgjwsI/4cI87wl0/XOthHX/PwSyEZjGJCJ1C/Kdfmf8ygVKaUi9tuaJexq4AjPBTHgp+y1i+7A9qDkqVzr/6D1tiI7QOzv7uSQu2wxzpNR3GrUgka2Ais/p9lN2EMIncW7AjcX1FbbADlhqSEFUwMj3Ss7+HzvoXbztQctuTWgX3zYIdVrIAH40MWQp6B8A000X9/EwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dxNQWgIru2r1B471fgC0ReHA9FdKC5m11LQJgXkIMtI=; b=ftkoy3NF/mXiRDiBj1Ymt4SROB7YlV5FJml1UVjxYl9sNrsrseXcMT24A82XIZurzDQgfVgRfiNbK7g9LN/d8QPcXt/qJljzOM+Vl35Hri430/stPSSByZhT1nJ38HCfHSCaCl+Z2UxdYzpGRICi2lrt/TEXil7GH/u8gEJOGTA= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 08/12] glib-compat: add g_unix_get_passwd_entry_qemu() Date: Mon, 2 Nov 2020 19:11:30 -0600 Message-Id: <20201103011134.887744-9-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0801CA0004.namprd08.prod.outlook.com (2603:10b6:803:29::14) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1d0c6307-92ee-4e85-af3b-08d87f958fb7 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u/kuLEiHPZF4TKLF4L7sGI7EJiYO5ZMgH2yyW6mu8CvRZnWYizIhl3Tv6XQAwNmuHaR1pAuqiPcC0V2KcbvAc2huxTR1+NejNmlFhwYLQYh0Co6ALLbqbE3wAHlTtf+ufpYsf3g9nUSW7SjjGnaVft8ewrKHEbbIh0lhBWHnYqEPazh1AmbQrx/4l2EwCdHW6Q5ibBEdbKiqGqrQ+wFrMq+rb65giAGuwUkmMJlKvUJOfUNZhFt9ll6cJyKXzd3G+T/UUOo1cbOIyyk45jIQtoTWZpvAZ2JWTiF8XQWhuGSNC64y8s/D9Avisxo7QBkWyqwxsg6X3E1BdACmEXEJDw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(4326008)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MsieuqxQFjLaEIBtOwro3vEE2iyLP+i/Np9oIS79f1Stt9OgeyCQgGgPT2NMsfppKNFZWmm4KGc5zr1xuQt/4L9kSG6XGem72A7vUtABlfhyeg/BpiOb0K1+h0RQMf6LtfTMsnYKpgBU/hlWjdh4JbZLxNuitbgTA1AHVmnz7HKiJZJ4lRRz6a8sfpzj0+Vo2XSUce946nNHOW8Ohjt6kZWWBB5sgvU0Q8I4gA+3TY/RHtAJFRgzv6B+p0yeZPkgjaZCcSJnrB1dRBzA3ODQmC1wAfn3jCKiKaZ+XDXcd4gQqNYMSAoN6Rxy9mArZ818yC3i3QZgvSy/v/IpN0TJeGrDgAqBp/HBbT4YqjZ127TE2uNAFdrJEC6p5l6nhfJ+iGHOn8vMYbzJVoccFtx7veKSLj9QC+xMn6JzL2N8U2Re+Mnm0ZmngpQJ+6UvGUHlIS7LDZs78JL6muWEMVklss3DQhBc9u+03bQvDM/7pJjKmm69/iRzUR6hEC4ojTAzqbRE//EvKDxIwWdol4eyw8y+KPrfZR3EnJUXN87rO+GY7bN9j0kThkz+MUUA29G7QJrwMTZGK7TPp7i72Nlt67QGbh3zI41NgTEIfF+r0Pp0iTQwDixZSAUqAHvBcncydwiV9rQsn276JpdY4eeoqw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d0c6307-92ee-4e85-af3b-08d87f958fb7 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:41.3289 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Iwsx0e8EdIMdZKE8aHYYr6mxjEX8+SRV9ANYD4Pr74rtIF/e2iZBMBkjFzu3Ccy4okZhuwLE+9sEMQV+wGQwcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.55; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:53 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Privoznik , peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Marc-Andr=C3=A9 Lureau The glib function was introduced in 2.64. It's a safer version of getpwnam, and also simpler to use than getpwnam_r. Currently, it's only use by the next patch in qemu-ga, which doesn't (well well...) need the thread safety guarantees. Since the fallback version is still unsafe, I would rather keep the _qemu postfix, to make sure it's not being misused by mistake. When/if necessary, we can implement a safer fallback and drop the _qemu suffix. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Michal Privoznik Signed-off-by: Michael Roth --- include/glib-compat.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 0b0ec76299..64e68aa730 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -30,6 +30,11 @@ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" =20 #include +#if defined(G_OS_UNIX) +#include +#include +#include +#endif =20 /* * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allow= ing @@ -72,6 +77,27 @@ gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); #endif =20 +#if defined(G_OS_UNIX) +/* Note: The fallback implementation is not MT-safe, and it returns a copy= of + * the libc passwd (must be g_free() after use) but not the content. Becau= se of + * these important differences the caller must be aware of, it's not #defi= ne for + * GLib API substitution. */ +static inline struct passwd * +g_unix_get_passwd_entry_qemu(const gchar *user_name, GError **error) +{ +#if GLIB_CHECK_VERSION(2, 64, 0) + return g_unix_get_passwd_entry(user_name, error); +#else + struct passwd *p =3D getpwnam(user_name); + if (!p) { + g_set_error_literal(error, G_UNIX_ERROR, 0, g_strerror(errno)); + return NULL; + } + return (struct passwd *)g_memdup(p, sizeof(*p)); +#endif +} +#endif /* G_OS_UNIX */ + #pragma GCC diagnostic pop =20 #endif --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604367153; cv=pass; d=zohomail.com; s=zohoarc; b=RjkHBCZ5hLCRVyaTkKPO4/7jfQYFd/F2PLEpXas8kE5lwGRJ4/kXfs0sNZzOPKhZSujCqvqaqJHm3MumeIcEOKqZpjGRdhuTrz4yQQrtHAA1friKjIFHG3t/1PpwviZIOzC+Rm6/2/dnU3uclOK1HZAMj2Jn2Razu0r3Xq/hvB4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604367153; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KbCvfrBHw1Tq7c4oWrWY0XirTx01iPkh9MhsS9wBa9k=; b=UfhfWfSPhUxwSeK+niWl6QZO5wHtpsZ882lSYIHtg9MdxEN4T931TgKwwnvt401XO3glRQERkTYWaCNf/DCIhIR2rEkr7XVIy3Vw/SefEsbaDZCVvkK48W049/11mQ3ommIlvg9pq22T3NcOatueqZEcs8ax2LND3TccQnEJC9g= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604367153801775.4029609506725; Mon, 2 Nov 2020 17:32:33 -0800 (PST) Received: from localhost ([::1]:34354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZlBU-0003C1-0Q for importer@patchew.org; Mon, 02 Nov 2020 20:32:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZl6B-00081k-NA for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:27:00 -0500 Received: from mail-co1nam04on062d.outbound.protection.outlook.com ([2a01:111:f400:fe4d::62d]:16551 helo=NAM04-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZl69-00077M-5v for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:26:59 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:11:50 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:11:50 +0000 Received: from localhost (165.204.77.11) by SN6PR08CA0036.namprd08.prod.outlook.com (2603:10b6:805:66::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 01:11:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TL0AaS3fvGviKq7m4cKsMhaJhmyB3sW+k6ZvsvHXszITTrLKpOvXxk8bYWuFrbXEnXDBJJzC9aTtAXdUWGLMeFA2qxUfIjAK42RMFODwCBsNipJ7vqYK8ZUE6fF5NW2tjS1D4+1W8/9pMks+BAQkOGjqgcIQCfjrKbQHck7h1fzhxI8w67IajiWWGd1plJGTjNozfwMdb6r4HhCkyqfMXF50DL5h2lPRrgF4bBlOtbAg0dQAf8uD9DqFoLpqXQL1uh+OcrSVpvfZerDnqajR+S782nxu60VIMwr7H6oNFWigvSM/cyKq5UkTpZnu32VX8c97dC8zyB4Oo9nt183vlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KbCvfrBHw1Tq7c4oWrWY0XirTx01iPkh9MhsS9wBa9k=; b=TiDxa12zpFfr7U9Q8YhOqJUJUKMXZXTmXMSOvTNosYf8rDQd7ZqWIGh2CrRHwhajOOZ+MAZsETusfjs7owFK5WwESVXrlcA7lvxrxUNf6Oq73yuE7UtzC7Dum69DSKConQJHgQR3ujEOHxr9T4G9xuyTe427jUcKgdu2d+bAS9ISo2nmpj8p33hkDrm/pGaKFlXJYNZ4+pme4T/cYULAT4VuBNIivbAYHQxQZ8sBNipiPHJ+4NAdm4y9okrzdhV+2ZM2D6q3ueJ+unfab5iHvN/xHBgeiDKq/3/ZpAbUXnb9zmnLiESQe8lNGWz1Rl6MKC1W8Yzo17TkYJmgH0TtIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KbCvfrBHw1Tq7c4oWrWY0XirTx01iPkh9MhsS9wBa9k=; b=fK4RHEp05cwfXAToDGoLURrRI+ae4ijgSZKdIWfJlBlb4abq0i0P9Yy4hQDl0qQlQ6ci8XDWNB6mcyiQdePPCxxCGV4rn3bhw/vCZID2+Q4Rz/rHf3yvgxO2bdkJLxVr/EKs2w6kTVySB/WZ8e9Pd7DqlULg7NJ4GzZ4xb9hins= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 09/12] qga: add ssh-{add,remove}-authorized-keys Date: Mon, 2 Nov 2020 19:11:31 -0600 Message-Id: <20201103011134.887744-10-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN6PR08CA0036.namprd08.prod.outlook.com (2603:10b6:805:66::49) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ab0a5460-73f4-47ff-0576-08d87f95707b X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1751; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6VuTTVfetvnl2Cxgrqi9htuOZH8n6RVi2W7hcoQpwK3HqDobj4zKavYut1OiwYCBGSV+NOZUzJyadZnq60lHuVFy7/eUoJSp8mOQzFLcyheL9nF29r5C+OwoPiVRquYlJBMV5OZNA10i0d57iIQCDv8QSv+48dW5sDjQg+iHeUK1yBQSvCYSWrTZOBYgEGRhKE/Q2/RbZ4+qZADOSjXuPaIVZ7R794ULSVJsh2JLfrWRIytlGQxsrZrccp2Xz7W2AI29Ri0M8GzKWEnrBc/RDxUiXMw+fsMdd5pJDli8G14wffZgaclWdu+Fg5z35z2g/4gh5cSfeS/L+dKr6HrMXBq0oLrY3XrVsrNz0xeGOnZQnWoW4u4tWU2Eh5tf1ybwaclxSAKR/6FjIqtC7HE5dQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(30864003)(36756003)(54906003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(966005)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vjt+3zfZh8rcSDKnzeWa4qVKOIHvpsiC+yGEHLCDSUz76NMwHkk+p/noerqpAwtNR6N+5qjb2thIAxSNIZllwgjxZlMrdm1fibfzcSu0hBanJ0zy7EXTzG5oLjt3S2GenAD0ZHc2s9k90N0kZVB54QHbgraozGVHDk52lGtNes/Ouc03j9oN6Cf5SyuQxqQeYiooUEdKxG5Yyaj/eAGXygjBFeKkXzPNZzPNt/+Ws7tekUMIhzAGwsYSs2DZJtyCFfolEoOdop1eT/fda0qNgV8fT/ZySygs1jK0jaO4akEEHA5jcN62u6yWYqbLlQyQnhPOyU5nHD8yAubniwoB2PTXRzmsVCwKeMBh64//lf2qUlwb51XxxYRBWtKfGvCSfhVEFi0VPwOHBXJbhGoVCGbvGAYlAWrYiXcfm0J51MjUZzUUKJ0EOqUCVMA8Nf2353erZ7QfHJ7bVZ6OT3Tty7JqtXkUnUHFXu534qBPlRgalw07LoU9mFGVBQsjv9urOMB0QGBxCwc+WMJ8AyK6kwD+yv0JRKDiO1vG4Yx7ptkjBxRTh7gx1Nxfm2yIaXGiFAKhMrWWWLp39Jq6H0sC7E2O3AK0YfA7234gJVFzFwqXvhU+x/KIn7Cy8a2bV7wecijsn5vhsAslnhGCqBp3mw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab0a5460-73f4-47ff-0576-08d87f95707b X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:11:50.3119 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wNl7vw5qLjSLT+4OMZsjDE9dnblykVrctHxLUxZWjnS7X+MYVhMHY21kfuSZzXg3B3jJonoW0bzN7XTjzRtQcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a01:111:f400:fe4d::62d; envelope-from=Michael.Roth@amd.com; helo=NAM04-CO1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Privoznik , peter.maydell@linaro.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Marc-Andr=C3=A9 Lureau Add new commands to add and remove SSH public keys from ~/.ssh/authorized_keys. I took a different approach for testing, including the unit tests right with the code. I wanted to overwrite the function to get the user details, I couldn't easily do that over QMP. Furthermore, I prefer having unit tests very close to the code, and unit files that are domain specific (commands-posix is too crowded already). FWIW, that coding/testing style is Rust-style (where tests can or should even be part of the documentation!). Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1885332 Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 *squashed in fix-ups for setting file ownership and use of QAPI conditionals for CONFIG_POSIX instead of stub definitions *disable qga-ssh-test for now due to G_TEST_OPTION_ISOLATE_DIRS triggering leak detector in build-oss-fuzz Signed-off-by: Michael Roth --- qga/commands-posix-ssh.c | 407 +++++++++++++++++++++++++++++++++++++++ qga/meson.build | 25 ++- qga/qapi-schema.json | 35 ++++ 3 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 qga/commands-posix-ssh.c diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c new file mode 100644 index 0000000000..a7bc9a1c24 --- /dev/null +++ b/qga/commands-posix-ssh.c @@ -0,0 +1,407 @@ + /* + * This work is licensed under the terms of the GNU GPL, version 2 or lat= er. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" + +#include +#include +#include +#include + +#include "qapi/error.h" +#include "qga-qapi-commands.h" + +#ifdef QGA_BUILD_UNIT_TEST +static struct passwd * +test_get_passwd_entry(const gchar *user_name, GError **error) +{ + struct passwd *p; + int ret; + + if (!user_name || g_strcmp0(user_name, g_get_user_name())) { + g_set_error(error, G_UNIX_ERROR, 0, "Invalid user name"); + return NULL; + } + + p =3D g_new0(struct passwd, 1); + p->pw_dir =3D (char *)g_get_home_dir(); + p->pw_uid =3D geteuid(); + p->pw_gid =3D getegid(); + + ret =3D g_mkdir_with_parents(p->pw_dir, 0700); + g_assert_cmpint(ret, =3D=3D, 0); + + return p; +} + +#define g_unix_get_passwd_entry_qemu(username, err) \ + test_get_passwd_entry(username, err) +#endif + +static struct passwd * +get_passwd_entry(const char *username, Error **errp) +{ + g_autoptr(GError) err =3D NULL; + struct passwd *p; + + ERRP_GUARD(); + + p =3D g_unix_get_passwd_entry_qemu(username, &err); + if (p =3D=3D NULL) { + error_setg(errp, "failed to lookup user '%s': %s", + username, err->message); + return NULL; + } + + return p; +} + +static bool +mkdir_for_user(const char *path, const struct passwd *p, + mode_t mode, Error **errp) +{ + ERRP_GUARD(); + + if (g_mkdir(path, mode) =3D=3D -1) { + error_setg(errp, "failed to create directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + if (chown(path, p->pw_uid, p->pw_gid) =3D=3D -1) { + error_setg(errp, "failed to set ownership of directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + if (chmod(path, mode) =3D=3D -1) { + error_setg(errp, "failed to set permissions of directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + return true; +} + +static bool +check_openssh_pub_key(const char *key, Error **errp) +{ + ERRP_GUARD(); + + /* simple sanity-check, we may want more? */ + if (!key || key[0] =3D=3D '#' || strchr(key, '\n')) { + error_setg(errp, "invalid OpenSSH public key: '%s'", key); + return false; + } + + return true; +} + +static bool +check_openssh_pub_keys(strList *keys, size_t *nkeys, Error **errp) +{ + size_t n =3D 0; + strList *k; + + ERRP_GUARD(); + + for (k =3D keys; k !=3D NULL; k =3D k->next) { + if (!check_openssh_pub_key(k->value, errp)) { + return false; + } + n++; + } + + if (nkeys) { + *nkeys =3D n; + } + return true; +} + +static bool +write_authkeys(const char *path, const GStrv keys, + const struct passwd *p, Error **errp) +{ + g_autofree char *contents =3D NULL; + g_autoptr(GError) err =3D NULL; + + ERRP_GUARD(); + + contents =3D g_strjoinv("\n", keys); + if (!g_file_set_contents(path, contents, -1, &err)) { + error_setg(errp, "failed to write to '%s': %s", path, err->message= ); + return false; + } + + if (chown(path, p->pw_uid, p->pw_gid) =3D=3D -1) { + error_setg(errp, "failed to set ownership of directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + if (chmod(path, 0600) =3D=3D -1) { + error_setg(errp, "failed to set permissions of '%s': %s", + path, g_strerror(errno)); + return false; + } + + return true; +} + +static GStrv +read_authkeys(const char *path, Error **errp) +{ + g_autoptr(GError) err =3D NULL; + g_autofree char *contents =3D NULL; + + ERRP_GUARD(); + + if (!g_file_get_contents(path, &contents, NULL, &err)) { + error_setg(errp, "failed to read '%s': %s", path, err->message); + return NULL; + } + + return g_strsplit(contents, "\n", -1); + +} + +void +qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys, + Error **errp) +{ + g_autofree struct passwd *p =3D NULL; + g_autofree char *ssh_path =3D NULL; + g_autofree char *authkeys_path =3D NULL; + g_auto(GStrv) authkeys =3D NULL; + strList *k; + size_t nkeys, nauthkeys; + + ERRP_GUARD(); + + if (!check_openssh_pub_keys(keys, &nkeys, errp)) { + return; + } + + p =3D get_passwd_entry(username, errp); + if (p =3D=3D NULL) { + return; + } + + ssh_path =3D g_build_filename(p->pw_dir, ".ssh", NULL); + authkeys_path =3D g_build_filename(ssh_path, "authorized_keys", NULL); + + authkeys =3D read_authkeys(authkeys_path, NULL); + if (authkeys =3D=3D NULL) { + if (!g_file_test(ssh_path, G_FILE_TEST_IS_DIR) && + !mkdir_for_user(ssh_path, p, 0700, errp)) { + return; + } + } + + nauthkeys =3D authkeys ? g_strv_length(authkeys) : 0; + authkeys =3D g_realloc_n(authkeys, nauthkeys + nkeys + 1, sizeof(char = *)); + memset(authkeys + nauthkeys, 0, (nkeys + 1) * sizeof(char *)); + + for (k =3D keys; k !=3D NULL; k =3D k->next) { + if (g_strv_contains((const gchar * const *)authkeys, k->value)) { + continue; + } + authkeys[nauthkeys++] =3D g_strdup(k->value); + } + + write_authkeys(authkeys_path, authkeys, p, errp); +} + +void +qmp_guest_ssh_remove_authorized_keys(const char *username, strList *keys, + Error **errp) +{ + g_autofree struct passwd *p =3D NULL; + g_autofree char *authkeys_path =3D NULL; + g_autofree GStrv new_keys =3D NULL; /* do not own the strings */ + g_auto(GStrv) authkeys =3D NULL; + GStrv a; + size_t nkeys =3D 0; + + ERRP_GUARD(); + + if (!check_openssh_pub_keys(keys, NULL, errp)) { + return; + } + + p =3D get_passwd_entry(username, errp); + if (p =3D=3D NULL) { + return; + } + + authkeys_path =3D g_build_filename(p->pw_dir, ".ssh", + "authorized_keys", NULL); + if (!g_file_test(authkeys_path, G_FILE_TEST_EXISTS)) { + return; + } + authkeys =3D read_authkeys(authkeys_path, errp); + if (authkeys =3D=3D NULL) { + return; + } + + new_keys =3D g_new0(char *, g_strv_length(authkeys) + 1); + for (a =3D authkeys; *a !=3D NULL; a++) { + strList *k; + + for (k =3D keys; k !=3D NULL; k =3D k->next) { + if (g_str_equal(k->value, *a)) { + break; + } + } + if (k !=3D NULL) { + continue; + } + + new_keys[nkeys++] =3D *a; + } + + write_authkeys(authkeys_path, new_keys, p, errp); +} + + +#ifdef QGA_BUILD_UNIT_TEST +#if GLIB_CHECK_VERSION(2, 60, 0) +static const strList test_key2 =3D { + .value =3D (char *)"algo key2 comments" +}; + +static const strList test_key1_2 =3D { + .value =3D (char *)"algo key1 comments", + .next =3D (strList *)&test_key2, +}; + +static char * +test_get_authorized_keys_path(void) +{ + return g_build_filename(g_get_home_dir(), ".ssh", "authorized_keys", N= ULL); +} + +static void +test_authorized_keys_set(const char *contents) +{ + g_autoptr(GError) err =3D NULL; + g_autofree char *path =3D NULL; + int ret; + + path =3D g_build_filename(g_get_home_dir(), ".ssh", NULL); + ret =3D g_mkdir_with_parents(path, 0700); + g_assert_cmpint(ret, =3D=3D, 0); + g_free(path); + + path =3D test_get_authorized_keys_path(); + g_file_set_contents(path, contents, -1, &err); + g_assert_no_error(err); +} + +static void +test_authorized_keys_equal(const char *expected) +{ + g_autoptr(GError) err =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *contents =3D NULL; + + path =3D test_get_authorized_keys_path(); + g_file_get_contents(path, &contents, NULL, &err); + g_assert_no_error(err); + + g_assert_cmpstr(contents, =3D=3D, expected); +} + +static void +test_invalid_user(void) +{ + Error *err =3D NULL; + + qmp_guest_ssh_add_authorized_keys("", NULL, &err); + error_free_or_abort(&err); + + qmp_guest_ssh_remove_authorized_keys("", NULL, &err); + error_free_or_abort(&err); +} + +static void +test_invalid_key(void) +{ + strList key =3D { + .value =3D (char *)"not a valid\nkey" + }; + Error *err =3D NULL; + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), &key, &err); + error_free_or_abort(&err); + + qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), &key, &err); + error_free_or_abort(&err); +} + +static void +test_add_keys(void) +{ + Error *err =3D NULL; + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)&test_key2, &err); + g_assert_null(err); + + test_authorized_keys_equal("algo key2 comments"); + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)&test_key1_2, &err); + g_assert_null(err); + + /* key2 came first, and should'nt be duplicated */ + test_authorized_keys_equal("algo key2 comments\n" + "algo key1 comments"); +} + +static void +test_remove_keys(void) +{ + Error *err =3D NULL; + static const char *authkeys =3D + "algo key1 comments\n" + /* originally duplicated */ + "algo key1 comments\n" + "# a commented line\n" + "algo some-key another\n"; + + test_authorized_keys_set(authkeys); + qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), + (strList *)&test_key2, &err); + g_assert_null(err); + test_authorized_keys_equal(authkeys); + + qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), + (strList *)&test_key1_2, &err); + g_assert_null(err); + test_authorized_keys_equal("# a commented line\n" + "algo some-key another\n"); +} + +int main(int argc, char *argv[]) +{ + setlocale(LC_ALL, ""); + + g_test_init(&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); + + g_test_add_func("/qga/ssh/invalid_user", test_invalid_user); + g_test_add_func("/qga/ssh/invalid_key", test_invalid_key); + g_test_add_func("/qga/ssh/add_keys", test_add_keys); + g_test_add_func("/qga/ssh/remove_keys", test_remove_keys); + + return g_test_run(); +} +#else +int main(int argc, char *argv[]) +{ + g_test_message("test skipped, needs glib >=3D 2.60"); + return 0; +} +#endif /* GLIB_2_60 */ +#endif /* BUILD_UNIT_TEST */ diff --git a/qga/meson.build b/qga/meson.build index cd08bd953a..635de9af41 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -35,7 +35,9 @@ qga_ss.add(files( )) qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'channel-posix.c', - 'commands-posix.c')) + 'commands-posix.c', + 'commands-posix-ssh.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', @@ -87,3 +89,24 @@ else endif =20 alias_target('qemu-ga', all_qga) + +test_env =3D environment() +test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) + +# disable qga-ssh-test for now. glib's G_TEST_OPTION_ISOLATE_DIRS triggers +# the leak detector in build-oss-fuzz Gitlab CI test. we should re-enable +# this when an alternative is implemented or when the underlying glib +# issue is identified/fix +#if 'CONFIG_POSIX' in config_host +if false + qga_ssh_test =3D executable('qga-ssh-test', + files('commands-posix-ssh.c'), + dependencies: [qemuutil], + c_args: ['-DQGA_BUILD_UNIT_TEST']) + + test('qga-ssh-test', + qga_ssh_test, + env: test_env, + suite: ['unit', 'qga']) +endif diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index e123a000be..a2727ed86b 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1346,3 +1346,38 @@ ## { 'command': 'guest-get-devices', 'returns': ['GuestDeviceInfo'] } + +## +# @guest-ssh-add-authorized-keys: +# +# @username: the user account to add the authorized keys +# @keys: the public keys to add (in OpenSSH/sshd(8) authorized_keys format) +# +# Append public keys to user .ssh/authorized_keys on Unix systems (not +# implemented for other systems). +# +# Returns: Nothing on success. +# +# Since: 5.2 +## +{ 'command': 'guest-ssh-add-authorized-keys', + 'data': { 'username': 'str', 'keys': ['str'] }, + 'if': 'defined(CONFIG_POSIX)' } + +## +# @guest-ssh-remove-authorized-keys: +# +# @username: the user account to remove the authorized keys +# @keys: the public keys to remove (in OpenSSH/sshd(8) authorized_keys for= mat) +# +# Remove public keys from the user .ssh/authorized_keys on Unix systems (n= ot +# implemented for other systems). It's not an error if the key is already +# missing. +# +# Returns: Nothing on success. +# +# Since: 5.2 +## +{ 'command': 'guest-ssh-remove-authorized-keys', + 'data': { 'username': 'str', 'keys': ['str'] }, + 'if': 'defined(CONFIG_POSIX)' } --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366169; cv=pass; d=zohomail.com; s=zohoarc; b=IRYu8PMzoV2W+dwi3Ea8v+ngAk2iqLNuWEuS+5b4NhHTutYLFta/4mL0EsuqBtTupd33TGHDJeubnQBP2OAyINWPP5sSRK1pynDCu3f4dhBZ+5ey270ebOQuaY5FQINBBIYcy891daSLAj+yylbWBZaYQE861mqmGF0ju0ruPGg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366169; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sOKzbp4eQTrLJKMVG7F12JqubO9M4LB6ia5BxwcGHCI=; b=nqPrIsJAPB/KapFQuuoV2DiOVgGajSdx05uUljJaTeJA4nwtx2wYqiol4G60z6DRf33M6sUTRjaQYfMXHPU1ZcIkHuKwq2Aj6foqWGpxWhJtqI8m+R6mDzKRjJIYXcHhheYRO4qiSdh9blEsfXui+aRta1GBVrrEeBPvo3Txuvg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366169545791.6583165136741; Mon, 2 Nov 2020 17:16:09 -0800 (PST) Received: from localhost ([::1]:35078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZkvg-0007sY-3y for importer@patchew.org; Mon, 02 Nov 2020 20:16:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZks8-0006NJ-S2 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:29 -0500 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:64832 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZks4-0005WU-V5 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:26 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:11:53 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:11:53 +0000 Received: from localhost (165.204.77.11) by SN2PR01CA0020.prod.exchangelabs.com (2603:10b6:804:2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 01:11:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kiCAxiFEZAB2uFF4RkxXCAkwXtOzWVeexyHuKVl9S76eguuXcUU45tTpegdIDlcFhaBXyJOXHRyi+2+cp4UoMx6CWzmLr0KOcNYCFyXd55hZSMyqPk4REf2CvjmsJjzQvIwIFPW/j+6zsavhJkXLFLHQfJvjVEfflPbCcDrp04vRc94C7v49WvpeHR8EypKSw+mtDSOY3lgYwzkHcdQDtfg4BV1MrykTg8+cECuTPzDIz0xH2CfstSwMcDVZLNHUq8hWe4lZ/IYsci9egHcumtBbnQO9GUtFl2auNRKivoqw8a8drhVFXWdQw6P5HX30VXMhoOtVu1zQFLL/v00Isg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sOKzbp4eQTrLJKMVG7F12JqubO9M4LB6ia5BxwcGHCI=; b=SGtGLvMZCtQOspGfg4aGFVgSjb0jLK7lVU8xUn2Wcsb75OncjrKQeeaYKycxoJZ7/BzITZnbH1P0NfevaZSA8RT8AogvYLAo+3Jxd8Kqw2EuEYxWxGOMtkn9FMhKK0GGzxL2muZmI1EPp579nScoH+TrUn80MlQl5Q3Q8Hgz/fQem/iJbzmHRTo7txH/IDnp2NRqAM+IZpqKyHbDBSytp+ZzuKwSYCO/lvjRM7EXTRUoDmrsTzGuV5cjnbSLUDKGQs0CUJoQWKzco0t5wYor5sGGQI/u/5ONPIvFgvESrPKhRuYunW3ggZ+BEjVlVKxTs8BPW2kQLKKqBaJ2TM+QzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sOKzbp4eQTrLJKMVG7F12JqubO9M4LB6ia5BxwcGHCI=; b=MmSodb/pZVBPOZR1brtJDnLta0qgGEFWPvnMH/SPLBcPKu+ABULuluMQRwkowuAcKW+sgPzZJIXwMFbcKIZoma/V8rFaGIzwtMa10ZM39ZNEPHJ+j/zAX/qRB+aL06DkbsHbWfZWGIg6crfSFzI3KItovAddtC6EgcJh7/wCHJ8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 10/12] qga: add *reset argument to ssh-add-authorized-keys Date: Mon, 2 Nov 2020 19:11:32 -0600 Message-Id: <20201103011134.887744-11-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN2PR01CA0020.prod.exchangelabs.com (2603:10b6:804:2::30) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8f21812d-aa13-4073-dd25-08d87f95730a X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YAvtu5e0+7UL7fDHS2UAnMsqvruismmtQSzkzVHQzXr+8OshdY1z6bJfjeGvrriqJ8+exzmkGDTWqYo5bdtW/ujdFwAE8LY+bQacRWeqqTWLjuvET4kyTRPFi5kwjyguZvQ6j1IWUrlS9LPBCNSPxEJZmv+Yfph19uknmE/Ht+x7cUcyFD6+9aN/KawSmMKBAugZ5zrs2+MLNZW4fEJOZK+kCnAGchrwmAblIxoemLdzVSbTJZpe6gSMBFLqZSgVr6JyNzjb8jhAJkTt5hsSYDWGYXof7o6dhWCH+7f8tkxSZW1aNaLbEEiJiOEqm6EdalE0meVjz9QciQ5zHojqBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(36756003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6ps5593vQrTf4VJJrTdDukqM5lj6Vwj+L4jHVx27LVFqCEffi4tHmL/UtgfhVRmp81Kb7sCVw6ve7cOBLy6+beaCrE2gkF4ihHIJtCxguOiCry+EKpZMO5nCywVTphvW3+dKXrxGo648IRffQnVfE6lXleQPvcd0SDKbiO4oh2tqnnJfaduRJI1Gjp2SAocOLUp+iPGM6SgT93pAb0VbnaXUcwfp5jKgt1aW72oWS2W/Wvbn8eZbiwrI3wczxM2SouPTkzq5XGrD/epv7W5iavwnPvkxxjYJuMST1W6yaN2fq9R+5Gyv2fEgXP/ozpcYSOh7tZZcpBtyawTvfJW74lDCG2eyXnmEJ5LeiXwugLXNK+E7+AHmNKqTwlW9Ow0NeXh9/yvWoX3giiCHI9f+KNj+WKxkJgeSPbwKFB5ZtlosapfZXzZ2/8zT+SLESXU3tgTh1EXNCz0T8HHt3jtIxhQWrD7Mm2UNv/yGbt/+P+d8fNMZv8PXDZdeyVRqoa28tiO4NeqY3Tek03vwCTfZaUVYAuJ8P3j1qXUHh4g7ausdFpHJPoWTcCFpGU3hbNPY11trzMVVo2s63HxbdR6apMYbJ8JjkcM17sX2WHiJFeCh9UDcA0eeVMGlIgEJXJ1R7GDKX0ykO8GymiNZAebpfQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f21812d-aa13-4073-dd25-08d87f95730a X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:11:53.2012 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /8dZK36NbVpLolqY8ZKnBcHzqo28roUtpTca7Vmg3tshG8PbEpSr/UH7KYgVVMMqdfP+S4QAHLXoEaV21edwpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.58; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:23 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Marc-Andr=C3=A9 Lureau I prefer 'reset' over 'clear', since 'clear' and keys may have some other relations or meaning. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/commands-posix-ssh.c | 53 ++++++++++++++++++++++++++++++++++++---- qga/qapi-schema.json | 3 ++- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c index a7bc9a1c24..f974bc4b64 100644 --- a/qga/commands-posix-ssh.c +++ b/qga/commands-posix-ssh.c @@ -168,6 +168,7 @@ read_authkeys(const char *path, Error **errp) =20 void qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys, + bool has_reset, bool reset, Error **errp) { g_autofree struct passwd *p =3D NULL; @@ -178,6 +179,7 @@ qmp_guest_ssh_add_authorized_keys(const char *username,= strList *keys, size_t nkeys, nauthkeys; =20 ERRP_GUARD(); + reset =3D has_reset && reset; =20 if (!check_openssh_pub_keys(keys, &nkeys, errp)) { return; @@ -191,7 +193,9 @@ qmp_guest_ssh_add_authorized_keys(const char *username,= strList *keys, ssh_path =3D g_build_filename(p->pw_dir, ".ssh", NULL); authkeys_path =3D g_build_filename(ssh_path, "authorized_keys", NULL); =20 - authkeys =3D read_authkeys(authkeys_path, NULL); + if (!reset) { + authkeys =3D read_authkeys(authkeys_path, NULL); + } if (authkeys =3D=3D NULL) { if (!g_file_test(ssh_path, G_FILE_TEST_IS_DIR) && !mkdir_for_user(ssh_path, p, 0700, errp)) { @@ -318,7 +322,7 @@ test_invalid_user(void) { Error *err =3D NULL; =20 - qmp_guest_ssh_add_authorized_keys("", NULL, &err); + qmp_guest_ssh_add_authorized_keys("", NULL, FALSE, FALSE, &err); error_free_or_abort(&err); =20 qmp_guest_ssh_remove_authorized_keys("", NULL, &err); @@ -333,7 +337,8 @@ test_invalid_key(void) }; Error *err =3D NULL; =20 - qmp_guest_ssh_add_authorized_keys(g_get_user_name(), &key, &err); + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), &key, + FALSE, FALSE, &err); error_free_or_abort(&err); =20 qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), &key, &err); @@ -346,13 +351,17 @@ test_add_keys(void) Error *err =3D NULL; =20 qmp_guest_ssh_add_authorized_keys(g_get_user_name(), - (strList *)&test_key2, &err); + (strList *)&test_key2, + FALSE, FALSE, + &err); g_assert_null(err); =20 test_authorized_keys_equal("algo key2 comments"); =20 qmp_guest_ssh_add_authorized_keys(g_get_user_name(), - (strList *)&test_key1_2, &err); + (strList *)&test_key1_2, + FALSE, FALSE, + &err); g_assert_null(err); =20 /* key2 came first, and should'nt be duplicated */ @@ -360,6 +369,39 @@ test_add_keys(void) "algo key1 comments"); } =20 +static void +test_add_reset_keys(void) +{ + Error *err =3D NULL; + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)&test_key1_2, + FALSE, FALSE, + &err); + g_assert_null(err); + + /* reset with key2 only */ + test_authorized_keys_equal("algo key1 comments\n" + "algo key2 comments"); + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)&test_key2, + TRUE, TRUE, + &err); + g_assert_null(err); + + test_authorized_keys_equal("algo key2 comments"); + + /* empty should clear file */ + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)NULL, + TRUE, TRUE, + &err); + g_assert_null(err); + + test_authorized_keys_equal(""); +} + static void test_remove_keys(void) { @@ -393,6 +435,7 @@ int main(int argc, char *argv[]) g_test_add_func("/qga/ssh/invalid_user", test_invalid_user); g_test_add_func("/qga/ssh/invalid_key", test_invalid_key); g_test_add_func("/qga/ssh/add_keys", test_add_keys); + g_test_add_func("/qga/ssh/add_reset_keys", test_add_reset_keys); g_test_add_func("/qga/ssh/remove_keys", test_remove_keys); =20 return g_test_run(); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index a2727ed86b..4ddea898fa 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1352,6 +1352,7 @@ # # @username: the user account to add the authorized keys # @keys: the public keys to add (in OpenSSH/sshd(8) authorized_keys format) +# @reset: ignore the existing content, set it with the given keys only # # Append public keys to user .ssh/authorized_keys on Unix systems (not # implemented for other systems). @@ -1361,7 +1362,7 @@ # Since: 5.2 ## { 'command': 'guest-ssh-add-authorized-keys', - 'data': { 'username': 'str', 'keys': ['str'] }, + 'data': { 'username': 'str', 'keys': ['str'], '*reset': 'bool' }, 'if': 'defined(CONFIG_POSIX)' } =20 ## --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366504; cv=pass; d=zohomail.com; s=zohoarc; b=B/wfa2d0ya6sk/NDec8CkR8YV8+NBGPDSlDuROTVclyNNBLECfz2UN1JfGfIH2N3E9mPR4K8Wn1+z0W9efTzKcDGKAnnQhWhPIOZlBQoMSAPuXnmWZn3x3IxJ/o4/7vKlDdzPki6HZTPXeRRMzs5DhM1Ol2CToI7sor9hXdv5bg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366504; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uLYNCImMe2utqvDZqwMheGO5CLksdSPZ6Oc6wmQm9/Q=; b=Cpx34KDMLEnHlZgptGKpTZkLZaycNh2kY1JlXwDJHqopP9XUxxKeFu2kGrW4xXZNNLPvoL9PMng7tzuXuiAorvCPIBO/REiQ+Z7za8ArW+sytU46fjApl8ChgSQFgTlCmKy+0uD0TDG6TOkO8TPj7pI9bUiblk6HdKfdsmtDE6U= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366504040695.4760782621513; Mon, 2 Nov 2020 17:21:44 -0800 (PST) Received: from localhost ([::1]:43462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl14-0003Fx-Iq for importer@patchew.org; Mon, 02 Nov 2020 20:21:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksR-0006RH-0c for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:47 -0500 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:64832 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksM-0005WU-0p for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:44 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:14 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:14 +0000 Received: from localhost (165.204.77.11) by SN4PR0801CA0023.namprd08.prod.outlook.com (2603:10b6:803:29::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 01:12:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DS1JQeFb+O/cloX/uk0gzpugVpMpFzQAyqzAKru5efAu8B1HJAlUmjY1fbNQLFmocwbtUH6dX+GzpNWt5iKLM7zksua8UXLInfZCnjOIymdVCl/ARpu7ozf6YWkRWfUmMDBa6TREF8Mumwm0N5wEKJk78up9Tu9qOgOKFp6+ugwAsLZqS5Kiupk7CQYRzIQpZXAe/X8xOB1jAUQnvDcguhtVNyTr3XWP26E9Az4HL2LtqS3HvPLQxMktPa7857I4wh1M+CkAB+rvMaQGPus9hoUGhsrM7fXBEVwEdHTMNtsS2yW/bZqKrS4CqSDpq1D5HAbi0AxCqIoxF5Qp4I1+IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLYNCImMe2utqvDZqwMheGO5CLksdSPZ6Oc6wmQm9/Q=; b=oeKrGuP7YkrJtRWMswmASlfJFqKXN/VQEcCOcDbcjk/gEkz4+0mA/pkRlQArYAmaDlytGJNubxq8FmYmV3y+2R3Fdr8oQcr79OTCJuwRsexyoqGCSge+bV2CLpTd38Fs+VbhbcddjWaADLktoqB3PTpk5nVVZFfL69dO6L9eE+GUYEHqrH9OImf/cCDbdETiYZSfBjWMkSuPQlETXLJCcb7ieuE4oFSvR6fLMXem1q1S90UMmyLYRVnJGCQobv2mxRcClC0sQTNCkEVo1ws/qQygEP2Ln0NQyqXPiwJxW9VBnV++WuktgV2HszZGpw2TciaW4y60R7Gk22ANPzc4+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLYNCImMe2utqvDZqwMheGO5CLksdSPZ6Oc6wmQm9/Q=; b=A7PrcLOPGSWAlX6eQW0uw5bky9cBmkqoRe36D2OFZELh7/I2GLzT4mT/oWWsPlV50AffabwpI6xzMSl82r4hgJ3icsUPYqkbXEBFJlFc7Dyo1YvORl/UKr0JT80+J8seM/DPFXQjnz04GzPlyqtLpU6twSTRspZVly2ptbcoZbQ= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 11/12] meson: minor simplification Date: Mon, 2 Nov 2020 19:11:33 -0600 Message-Id: <20201103011134.887744-12-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0801CA0023.namprd08.prod.outlook.com (2603:10b6:803:29::33) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0c046609-13a2-4b8c-337c-08d87f957fc4 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:262; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vRwHHExzjpdH1hv8MWsnW7/gdVufUpSJ5dhuz03N213i11p50V0XdYn8k6IrABExHfSl9PeAYra6s8VdDjR81JtRAwXx7toq4ljiuH4ZoOrTKMqBIJEif/l7wQJ4jxpYJyyqMXja6VUP4kQd65clheWHqDBMw28TOFJhgGYVJLhR/rhtTU6X59wdIADN169mejHwUdESI1WDKbwd7J30+91Ed0o2rBfXIGEC1WeDXb0BNTxULUR48JJ9DxoTtxtwyhNi73GPgW+CeyjOqPyKiMtwcX9dTntEvgNGFc47KHhIImgHMzRwsdXfrCkZazFe1G/RmddmoVkruzL1bcNXQQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(4744005)(36756003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hy0ByobZ1uxaV0jjWAr//PY2FQs3UWxOGB87I0fagPLVciNyd100VzXxeQNPkU6CpAAAdw2niQEabl/43R0/hO55bE5AyptBnqlyhpkPFFT/XzJ0QGVO3Jl2tD29yfJHQbePQcd6IyoPGf81EwxMa3DNHwsQUzYYx57etow2iUCmEulfJxTggF22J14Rb9sSbyIYo0FhoejiUfTO0MraHn7b2nIQK7LxNheGqFHiJyYMSLr0wp62z4lQ+7J6sAMiEs8EKmpqndmvkjTax0PU9laMyXDhvT7AwtLDoZ4c4ZJO13jAUCdeHVoVgI2739nrAelXVOnXVF5AT8MBSzt90ZfmSMq02Eqwk1AaY4BZD5dQP2z9xDqx84+HSjs25d0kDZh3xg32M6e8erPUuEH79ul1T95vqXJpINzLYMNUBjU8u1dYkbfwJ+Pu7KhLCjYGtzWFK1KKdG30fm8+BWWVRXWIqDUKvmqqBfrYTDkQ7J/pK4STcppLuSJZykJipR5B4KB87fw/sIEV1EQBS1GnOjlTsIogkLPy9Xl/NZkHIJDvUtpuCxZSFJ0VQfJBIogNzDYMea8LVfuP2bK2OtOWiq4Am/NaDB4THi6R1KCJYTS6IWxP6/8iumTzLkGS42u4FM4E8itIyWBiUMZnD63CjA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c046609-13a2-4b8c-337c-08d87f957fc4 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:14.5017 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6HOkaqBrSS4sBhgIo+SC2JQ3+NBUxTNFOSNQVX7QghEt+5sxC07Px2S3hKhulKkH4euYPhCMDR8sK4+jDSxCiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.58; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:23 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/meson.build | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/qga/meson.build b/qga/meson.build index 635de9af41..4cb3b3f259 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -22,12 +22,7 @@ qga_qapi_files =3D custom_target('QGA QAPI files', depend_files: qapi_gen_depends) =20 qga_ss =3D ss.source_set() -i =3D 0 -foreach output: qga_qapi_outputs - qga_ss.add(qga_qapi_files[i]) - i =3D i + 1 -endforeach - +qga_ss.add(qga_qapi_files.to_list()) qga_ss.add(files( 'commands.c', 'guest-agent-command-state.c', --=20 2.25.1 From nobody Wed May 15 19:47:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) ARC-Seal: i=2; a=rsa-sha256; t=1604366781; cv=pass; d=zohomail.com; s=zohoarc; b=Hmw+0doAyJ06O+r4tqGCArSUcSI+aP/GAOjxbHCeCkA50cHb5Rgi4rUnxJq/IH+8Dw4/WBa6rOxQO9SVPN1rHzgcVo1cnjaNd93xXDKnbBsQ9XcJAsAlABHsO4bFCa20LOIes1JNNcUcWyKqY4nR1gkiH+F8BbwhmlzbnoU7cAA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604366781; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ppi/Xh995pP+WTM9r/wbc0QZQ9H8XIWE/UmcUBhTc9c=; b=mzco7SSeCJOKf5O0jzZv6u3syoqUllg3OwrUJn6cc+D72GKRwzLcMFp0p5pfr+7hfyMK0wM36dZyT26Ltbu8jgM6EaAYzgMnUSQ5nzadTSkF0sUEAeKcqIlox8LTE7PBssI0my5338rOEGux384aTiyc1/3bH6FGd45F71rK4Go= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=amd.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604366781211800.5109812831956; Mon, 2 Nov 2020 17:26:21 -0800 (PST) Received: from localhost ([::1]:51924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZl5Y-0006wz-2h for importer@patchew.org; Mon, 02 Nov 2020 20:26:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksT-0006Vx-QV for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:49 -0500 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:64832 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZksR-0005WU-JE for qemu-devel@nongnu.org; Mon, 02 Nov 2020 20:12:49 -0500 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5001.namprd12.prod.outlook.com (2603:10b6:610:61::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 01:12:18 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 01:12:18 +0000 Received: from localhost (165.204.77.11) by SA9PR13CA0229.namprd13.prod.outlook.com (2603:10b6:806:25::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Tue, 3 Nov 2020 01:12:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJ6dXhOGvh+oogKpK8YFGk5hL2h+UvNS9x+x9QWEk40GOIB8mJ2TMBBmNBP5Z3KjSSEzpK/sqikGOc3ve0lTx6LKXSP8dTCQkYkMcNggLwNjYT7U3BEIq8UNKLzq0VSu6YYAGZXh0LAxupxVzIUSWpFPWuanXKfG4ZIpEJ4sngCOMgzt4rGrI0HUOe97tbiV8cLzol63Q1fXIqg9CYK58PNBn009RP+/L4dF7H2KiPRWVdEkkzSTECi4mueFDBte3OaejWUzNtnGBfulAv26dsy0lIsbm9z0EPvk6UUgE8DVh72xNxe36cejWcgKJcejV1koi5p3bqkAXOgFfdDXkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ppi/Xh995pP+WTM9r/wbc0QZQ9H8XIWE/UmcUBhTc9c=; b=MG7rW2bEKwWme1gfVxoBG2aaW16Ccs/u7k+nysfZoO86+adIdbDREsU+5F95kUjoxWUncgD8q90H8rfmWFOvqzfX73E3pYalGJDxvnqyke0S94L/dnx0pK2ZpmleZWca3UJKidyFZLwTxQS4dYTuBSZxbvXU9/+IgvbiCaazYEpPSxjLvnvJ6d0q4N1GVuNkhsuo5xB8/4/yUasmZXZSIexyOc2TAV4uEQO2mP2k/5IxHi/QYuE/Yj1vSTaCNsqCivII5x+gatYvQFxEIdMieoaugJMd0fZNqEwAkocevAnkWOaobZMbxhlsIpFJmhSSs1PdJss60SBbJc6KvK3Euw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ppi/Xh995pP+WTM9r/wbc0QZQ9H8XIWE/UmcUBhTc9c=; b=ZztAKNAr9H6qVbFijIXZFGnAzzGbVF3cBYDU5UQJm0AgUYyy7F4FPs+E1QVpk/T24LeSIHG/icxUoKg5j8sBVC2UOZCSh4bpt+0hLl9u/DnSBpYA085CjS8MUjTJB66YY6Zo+TiT8WxdGvq5absQjoZR1kEmMLBizxdDCuv4wjk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v2 12/12] qga: add ssh-get-authorized-keys Date: Mon, 2 Nov 2020 19:11:34 -0600 Message-Id: <20201103011134.887744-13-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com> References: <20201103011134.887744-1-michael.roth@amd.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA9PR13CA0229.namprd13.prod.outlook.com (2603:10b6:806:25::24) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e3a6afe0-db66-495a-da51-08d87f9581f5 X-MS-TrafficTypeDiagnostic: CH2PR12MB5001: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dzDSbDgZay7/mRfS8odVpLsKxVyPdbnoCrsE4SChY0NScCwa934SNMvaiGIiFhH/uXLRj2x/hXp/rAmlY5O0pXpv8A91mVCfAv6N4L12WWad5fjWKYxLhNY5QfUsKpgpHF/VFBjSj3DKNLgp6caPS6HOHFkUkF3Z4qkmIKKMt/q8I/JDlbof1YfH6y7jfCMgFIs+wyU1yN9MQfXHmSvcu+wTX3gakWBgBgMPF0WlO5j26AUjim548A9LBxoWLWrIq8dpq6Nd25hkhVY46uZUMUvfjz5w9Upd+HGV2KoskhbThMDt2gw2NtZPiQCqRXza5OPEjy6dbWUpkBAKUDCWUQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(136003)(376002)(346002)(396003)(26005)(44832011)(66556008)(66476007)(66946007)(8936002)(86362001)(6486002)(6666004)(83380400001)(4326008)(36756003)(2906002)(8676002)(5660300002)(52116002)(478600001)(186003)(316002)(6916009)(1076003)(16526019)(2616005)(956004)(6496006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8qJZlrXOCaxueqdHKxlI/Dkawqf8DVRP5EbmI3ImH4x1dvCOwxJznxfS0nU6fl+TzJU51S6ay+KY8ijso0mnQoicuIci1WKEg1sE7FkJ/zHqcvRcNT/li5hzioEEIAv3rv2rpvWigfmcTZC0yaJO0b7/5amTc2xkzWg3Xca4YkxQ35t1cLP8wVgCkvv8hG6KUfXoZtC7jkkr1I0BGtujHhNpbmvs3wPoxpmpq46cQzflIkUsaOzX/5jVh2kpiunybj+RqWgadx81IEb64UrAlFkFin4HcTZLAbxhCOczvwepFfPFByp+bwbYqqi1Ge6sOIzgTlBfFYVNzz2fuhuLFgC4Q+OQK9YYJ5t+d6b6VDl/I42Yq3xDHfDxwpvd2D2xgiiWm03CFSyUbyYmqsRyzlffSCXyp+XbFdKVxp5R4Yi/0CfNXqEg6I+NxhxEPzan567jofrdc6AozMt2pbutpSi5n3xC1DWcyC5haw2qStPCn8QHOrOsBKfP2PzI+hyLWNfAs8372gcjQfUeyZumVbfpTB8ANkohuDHOoKlBayBSD4zEhufqfDxixJqB/+NuzLqrSj6sETmTLMNoViX7hSaSL1wOQyuATXgVdDCthAkrNzj5HDUyVCzLzWe6gN0Eo/9TRYpUrD7DUekqLghJog== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3a6afe0-db66-495a-da51-08d87f9581f5 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 01:12:18.1765 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: R/P/rb3Ag2RT3iuov4gWh/UH3JR1k6yJW/RImsufSi9yn+VYWMjTm+wpFultMS4dgKVCJ66OXA9ZHaqGxVyk1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5001 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=40.107.94.58; envelope-from=Michael.Roth@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 20:12:23 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amdcloud.onmicrosoft.com) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau *fix-up merge conflicts due to qga-ssh-test being disabled in earlier patch due to G_TEST_OPTION_ISOLATE_DIRS triggering build-oss-fuzz leak detector. Signed-off-by: Michael Roth --- qga/commands-posix-ssh.c | 66 ++++++++++++++++++++++++++++++++++++++++ qga/meson.build | 11 +++++-- qga/qapi-schema.json | 31 +++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c index f974bc4b64..4d75cb0113 100644 --- a/qga/commands-posix-ssh.c +++ b/qga/commands-posix-ssh.c @@ -268,6 +268,46 @@ qmp_guest_ssh_remove_authorized_keys(const char *usern= ame, strList *keys, write_authkeys(authkeys_path, new_keys, p, errp); } =20 +GuestAuthorizedKeys * +qmp_guest_ssh_get_authorized_keys(const char *username, Error **errp) +{ + g_autofree struct passwd *p =3D NULL; + g_autofree char *authkeys_path =3D NULL; + g_auto(GStrv) authkeys =3D NULL; + g_autoptr(GuestAuthorizedKeys) ret =3D NULL; + int i; + + ERRP_GUARD(); + + p =3D get_passwd_entry(username, errp); + if (p =3D=3D NULL) { + return NULL; + } + + authkeys_path =3D g_build_filename(p->pw_dir, ".ssh", + "authorized_keys", NULL); + authkeys =3D read_authkeys(authkeys_path, errp); + if (authkeys =3D=3D NULL) { + return NULL; + } + + ret =3D g_new0(GuestAuthorizedKeys, 1); + for (i =3D 0; authkeys[i] !=3D NULL; i++) { + strList *new; + + g_strstrip(authkeys[i]); + if (!authkeys[i][0] || authkeys[i][0] =3D=3D '#') { + continue; + } + + new =3D g_new0(strList, 1); + new->value =3D g_strdup(authkeys[i]); + new->next =3D ret->keys; + ret->keys =3D new; + } + + return g_steal_pointer (&ret); +} =20 #ifdef QGA_BUILD_UNIT_TEST #if GLIB_CHECK_VERSION(2, 60, 0) @@ -426,6 +466,31 @@ test_remove_keys(void) "algo some-key another\n"); } =20 +static void +test_get_keys(void) +{ + Error *err =3D NULL; + static const char *authkeys =3D + "algo key1 comments\n" + "# a commented line\n" + "algo some-key another\n"; + g_autoptr(GuestAuthorizedKeys) ret =3D NULL; + strList *k; + size_t len =3D 0; + + test_authorized_keys_set(authkeys); + + ret =3D qmp_guest_ssh_get_authorized_keys(g_get_user_name(), &err); + g_assert_null(err); + + for (len =3D 0, k =3D ret->keys; k !=3D NULL; k =3D k->next) { + g_assert(g_str_has_prefix(k->value, "algo ")); + len++; + } + + g_assert_cmpint(len, =3D=3D, 2); +} + int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); @@ -437,6 +502,7 @@ int main(int argc, char *argv[]) g_test_add_func("/qga/ssh/add_keys", test_add_keys); g_test_add_func("/qga/ssh/add_reset_keys", test_add_reset_keys); g_test_add_func("/qga/ssh/remove_keys", test_remove_keys); + g_test_add_func("/qga/ssh/get_keys", test_get_keys); =20 return g_test_run(); } diff --git a/qga/meson.build b/qga/meson.build index 4cb3b3f259..53ba6de5f8 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -95,8 +95,15 @@ test_env.set('G_TEST_BUILDDIR', meson.current_build_dir(= )) # issue is identified/fix #if 'CONFIG_POSIX' in config_host if false - qga_ssh_test =3D executable('qga-ssh-test', - files('commands-posix-ssh.c'), + srcs =3D [files('commands-posix-ssh.c')] + i =3D 0 + foreach output: qga_qapi_outputs + if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-= visit') + srcs +=3D qga_qapi_files[i] + endif + i =3D i + 1 + endforeach + qga_ssh_test =3D executable('qga-ssh-test', srcs, dependencies: [qemuutil], c_args: ['-DQGA_BUILD_UNIT_TEST']) =20 diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 4ddea898fa..6ca85f995f 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1347,6 +1347,37 @@ { 'command': 'guest-get-devices', 'returns': ['GuestDeviceInfo'] } =20 +## +# @GuestAuthorizedKeys: +# +# @keys: public keys (in OpenSSH/sshd(8) authorized_keys format) +# +# Since: 5.2 +## +{ 'struct': 'GuestAuthorizedKeys', + 'data': { + 'keys': ['str'] + }, + 'if': 'defined(CONFIG_POSIX)' } + + +## +# @guest-ssh-get-authorized-keys: +# +# @username: the user account to add the authorized keys +# +# Return the public keys from user .ssh/authorized_keys on Unix systems (n= ot +# implemented for other systems). +# +# Returns: @GuestAuthorizedKeys +# +# Since: 5.2 +## +{ 'command': 'guest-ssh-get-authorized-keys', + 'data': { 'username': 'str' }, + 'returns': 'GuestAuthorizedKeys', + 'if': 'defined(CONFIG_POSIX)' } + ## # @guest-ssh-add-authorized-keys: # --=20 2.25.1