From patchwork Tue Oct 27 05:53:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C717D61C for ; Tue, 27 Oct 2020 07:52:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60AEB206DC for ; Tue, 27 Oct 2020 07:52:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="IbveM5vK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60AEB206DC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJma-000860-CT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:52:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvh-0007Et-GB for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:57 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvf-000447-QQ for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OwIj1aAbvAKpQVPVoFMqj8hFI04KQv6e8rPeEiC8zHBMY9hDKagn3WzmSlQM0xk066luNJI67sooA3NbZ6GcY8loF/dcPKRgNemCzV+403829QguQBU0FKCWfxC8Eh3OjXD5qvQ4IsUQhbynu/gunJCwDv9xU1O+MyKmkw5HORjdcVgRKJMiQJX9aDlWVgWAAnTZDqgiJcuTJwRr7DM7ApWnpa5u/JpgYZ0eY35TF1WuGJgenC1xslY5gLMe+J6wRgwm1/DSIo2b4YC64VRSIscuj67Vr7mpGpdMC6RzeZ9aeOT9VPF3OrlqVACO70zPykbq3Zp6z77gMQ6JOW2zCQ== 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=PUfjMX1iKDsM7ZCePmg+s3x5SxbP6F/fTp9cbFBMa4AhdlrynTIreJmXwg0YM+A4mUEpQISRw5CZba/R5B0JcdA4E13l7uOCADuePah6DIuCjFSf3gkLtwUtNyIvFFKD7cpFgXOSuhJCc00+HW99oGmYwcYRP37IBDtL5J1YhhsNJVudYJHFXyMBvdvNqjQ3Cefxo6z7zWNC+eVW74h2/w/3Y0PMRijOm9Nf+xzd/hDb8gFu2ZyWT3/LHZpBBhjQHlsOvrI1Nu0r8nsnajq2VfHSWkfiHkg2roamdMhLZt4dlNp2t8sI+jnhKqbZWoZTIzrrZRC9JPoxD3pw11cPsw== 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=IbveM5vKrLShqiwCeNaJVpfshYpOZ+caCmQvXWnDijYX6CTZXspnklVDYX/Xmw8/wdCHUgLKwekMBZZ+povD26BhGZ//x6XlbTiT4nbill6KD1rN4Bg2SbOm2cMGRSkMxC/a2LCoVM454EUT7cYxF7OO+9LvsLrGuLq2nc1QG4Q= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:43 +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.018; Tue, 27 Oct 2020 05:53:43 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 01/12] qga: Rename guest-get-devices return member 'address' to 'id' Date: Tue, 27 Oct 2020 00:53:06 -0500 Message-Id: <20201027055317.351868-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0103.namprd12.prod.outlook.com (2603:10b6:802:21::38) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0103.namprd12.prod.outlook.com (2603:10b6:802:21::38) 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, 27 Oct 2020 05:53:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 25bb597c-0e92-4c4a-9651-08d87a3ca97a X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: gk/QIje3EgZnKcYoFX9gEEl+FwUn83LjnuiKjUUGFl7TKCBVBXiZNQ9NJgYnvTraI/vMLAB7q77d4HECXVpg0agzqeujTNXtVmkdd7NtAXkv9lt6sYf/vAMbumQ1sd8LEcUGPauby9qAA/GOu/+VL1zOoG78v7yL4MJT8AP9O45GvBd8pji8oni0MK7nKXzduPhhAhLnQ+51W9c0qw5i1/LlvAG9CIiYllBGmwvRejr6o5479WvtkW2crCIYp4gpc1UUZJeXh82hWXDHy4n1oAk21kaR0yIK4AcduPNZObu2p/EGZ3R8oqF/k/bKimbEi4XCPwSyawHcA/vu+qcozQ== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CuF3pb/twRrROZ5jdvqCKGaisTtguL7JvQ0h0vBhL/k1pOGiPgofqF+gzgu9UVrJr1uRsr/jfN7bFAXbE5XHyPx6Mpm9cmT/KRQahxKQz7KeP8w5avITqK+wc4k1fPkUXtw2mIMf7ZUm2kIns2XRjx/zVOeQIy15p24Y4JFUIF4hY00cpWIY4LKBMtuvYSzTxz2AAJ0hIozPCMMZTRciW5pT9iaG7Fp2Eq4oXWX+hjqlwR7LZ2dgM7LlC3pRt/IDJbfAEQBKV2BqynXiPXLa/1vZdZS59ohkYstTx1KZsiNGLssJIZ6LbsV7ffjnpa00PwrESn+tsRKqKCQdjkeeLzI6xiIo6lJFvk5SaugujBjnA8Bx9GvGzBy5a6SPNSi/J+92tefirkcXyyb3f+ZWr7MHycvCCQvgB3Kj5yhu6iqY4h+h3gof36OQCb98oM4tCuqmdY+Mrju6ZsiyciILWntetweJYh8SrEN2xqUaj8P4p237xc9bj+s0aJxq8dGye/HmJHBRPs+AmcPlpj6zDRnp3RIqcaDCDHkRxvvKfOJUIJtZNo6ZsqX4KdrFHDO1EZQ6XvbY+7pOhmUB8ViBx4ZTZpZOHR5MLJKPf7cJcxV/sYvx+FU1i1s7vG5MVX3BLe8QCz9Siq5ANLVXQERfDA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25bb597c-0e92-4c4a-9651-08d87a3ca97a X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:43.5075 (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: qTSombhVo62QXCeRG5n3d5hJaSqO4EfVzZUpajzC/HgZlrqfdF4L5/wuoycAi6wpE877S3Io88ciQxigRNy+ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:43 -0400 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_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Lureau Reviewed-by: Philippe Mathieu-Daudé 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 = 0; hw_ids[j] != NULL; j++) { GMatchInfo *match_info; - GuestDeviceAddressPCI *address; + GuestDeviceIdPCI *id; if (!g_regex_match(device_pci_re, hw_ids[j], 0, &match_info)) { continue; } skip = false; - address = g_new0(GuestDeviceAddressPCI, 1); + id = g_new0(GuestDeviceIdPCI, 1); vendor_id = g_match_info_fetch(match_info, 1); device_id = g_match_info_fetch(match_info, 2); - address->vendor_id = g_ascii_strtoull(vendor_id, NULL, 16); - address->device_id = g_ascii_strtoull(device_id, NULL, 16); + id->vendor_id = g_ascii_strtoull(vendor_id, NULL, 16); + id->device_id = g_ascii_strtoull(device_id, NULL, 16); - device->address = g_new0(GuestDeviceAddress, 1); - device->has_address = true; - device->address->type = GUEST_DEVICE_ADDRESS_KIND_PCI; - device->address->u.pci.data = address; + device->id = g_new0(GuestDeviceId, 1); + device->has_id = true; + device->id->type = GUEST_DEVICE_ID_KIND_PCI; + device->id->u.pci.data = id; 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' } ## -# @GuestDeviceAddressPCI: +# @GuestDeviceIdPCI: # # @vendor-id: vendor ID # @device-id: device ID # # Since: 5.2 ## -{ 'struct': 'GuestDeviceAddressPCI', +{ 'struct': 'GuestDeviceIdPCI', 'data': { 'vendor-id': 'uint16', 'device-id': 'uint16' } } ## -# @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' } } ## # @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' } } ## From patchwork Tue Oct 27 05:53:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A95C61C for ; Tue, 27 Oct 2020 07:48:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6D1020738 for ; Tue, 27 Oct 2020 07:48:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="h2YAOLRR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6D1020738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJi9-00024H-BQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:48:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvj-0007Hl-5Q for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:59 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvh-000447-KL for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b8FeFhKgTzWmtdhQa2LA/CwsvuFv6vAl9uVUmEQVhnTRWi4HIPPZDXrmfjNvO5pj3FE/k16zryErqPyLVM5lEid+IfvWvd4a+ymfeysJVM4MaZr7kxfiiXlalAiQ5IIv/+qKIlO6NtD/HoQbTq6lqxwz8Eo0nUuEuhWu4sI/2diSQ7qkZBxfXob6Lz98TyAaHsvK7gRPqTCnbtaA+9aVTqcsFzMkVKp7Uxi2NaDzuW+80p8oT4yNWeB+gh9kW/ZIExk1VX+hXrxPevSoITiGFsovpmFQUszwvDKKtG1cyMqFjMs0vLg4PFhsVq7Afx34Swfx74+znZuIsKA7/U5jkA== 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=jztV5kZ/g3tKUVr9cjtitKHtLEMLwn+YhvMXYG296L/ALh3HJI3WB3NkXjbQ6iXbb7pIvzOcpY7d6GYpq2sWxjIcn1Hmk7j3YykGpU5ufygFTOy6JZLvosxZ9xYWm6AucsCpS4tKjf0hUHOeEn6ky3I5gze5ESJEFkWSbbhNBsAOb7hkzurVCDM6kSEEfRndIxCNs5IyADBq/JGgBtPxQH9Fdr4d0P0QczYb3MhHxRIcHcchY91nqVSNGJ77A8Rk31qQuNJByd1opYSIzB7j9B+Jm5YU9cjtU6tdMKveKNsQkOcSs04oPGL6PBUO2KY/oiA/RWSfc7f8HtuMsW5BLg== 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=h2YAOLRRcEVwIoknvxYgGYPhDIkgdJypqBeU6+fMK8whYRNyU522LBdwur+wNbSEeSgERT5EkaoccwffP8uyp/sNNSckz4bsoaiuvMQbH169hHHbq58IsX/g/Gn3YGgTq27Fd1/uyLINYE9shGQWdysFUCo96Hj749Ov78EXomk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:45 +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.018; Tue, 27 Oct 2020 05:53:44 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 02/12] qga: Use common time encoding for guest-get-devices 'driver-date' Date: Tue, 27 Oct 2020 00:53:07 -0500 Message-Id: <20201027055317.351868-3-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0101.namprd12.prod.outlook.com (2603:10b6:802:21::36) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0101.namprd12.prod.outlook.com (2603:10b6:802:21::36) 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, 27 Oct 2020 05:53:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 09d38608-5b6b-4015-8353-08d87a3caa4e X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: FUqyjglyUViEPjaKS4GD0wNENPkwtf/ZJWRI6gZWRUcdMoip76OSF9pBdxCNMl2HHbZG+G3Fx5PnTB0BE0JXFGh/uCTXAtiE7lmMiv6AfD0NzGmadJYOd8oCN+HDWDDhkseoNGgudPkULiKWRyuSxyyk8QgP2cAkI2Top8VNfeGBK+QyA/Oz2g7odyf7bx8CYZHMEYIHSdr8pA2Yjwhd9vYbEwMEXiozyBgZe4sxuIUIb1CUyhyDrejyfTKQfEiC10jS+pL0FzQ9S3KudymwrshoflrybeThmYerylBazBk1/3ujZTOTwCKnhotCLt+07d6KMzW9Z0kfLUqrEFUcUA== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: u+QLjzSCtHPuQfjMHXJI8Yd1qpbNJdA0eAuBSMF7kaRZ17WlvKo04HdjjBXOLZjS63tggzK1SFC546bPig1VpOSXlseCeV8wy4d280IMzsfi2j9gYPmz5OYYg+ZYoiCKMEKDkyn0H445KofTVQEO5ZgJXK4DgLx6VYSxaYUuW6TD6WKnYsVS/30ZjGoALWHfCB0b/fmadgBv6NNJLsc18AB9/lC+QMdJk4XSza5w8GoferJcd5tjl+RzO6y8MOFpxtVf3uHNMgPgi1BGYjU7Y/x12b3A2zf9AMNwPQopGK65P60rsYUU8dQfnRwECFPoinMRWUnpqsJfw/k68EQBLuJBYGQpAfjY8HhwVdk8Fk1H10+cJQRzScQEraWsr69CPcI80TleqGXfdlqwPtATeLT2M4bpDQE2eCV63yPQ+1yY4M9s4TaXLdRkX0sH33n8igs9Q5Fc4O3iTk4ZAemwq1YguUWW+CW8NRnfxM9/whiBW8x73rhpMMX8s8ArmNggBO0XKWFAWqV7oufjXxprkPSg8eKQyzkrjffuyQEYFOxvplhu4gThSbkz0gnD7an+hG7TabR2rxjVtPObYJhrMZSZbzQmZ3PW+7zAaG79OQ+KlUh0ImZWyALFHPHCMpjcW6sf+tbaljmt0t5dkG26Lg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09d38608-5b6b-4015-8353-08d87a3caa4e X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:44.8775 (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: 7ALpX/kV6YaiWMH1aQbRIMGV7bT3YCNK2wWVdaAxpOJy/dsqIZgCS1U4HQCu594+ee7DCGINhIxKfNTBkg+Q6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:44 -0400 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é 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; } +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 = {0}; @@ -1657,8 +1663,7 @@ int64_t qmp_guest_get_time(Error **errp) return -1; } - return ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime) - - W32_FT_OFFSET) * 100; + return filetime_to_ns(&tf); } void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) @@ -2363,7 +2368,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) slog("enumerating devices"); for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) { bool skip = true; - SYSTEMTIME utc_date; g_autofree LPWSTR name = NULL; g_autofree LPFILETIME date = NULL; g_autofree LPWSTR version = 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 = g_strdup_printf("%04d-%02d-%02d", - utc_date.wYear, utc_date.wMonth, utc_date.wDay); + device->driver_date = filetime_to_ns(date); device->has_driver_date = true; - 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 = g_new0(GuestDeviceInfoList, 1); item->value = 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' } } From patchwork Tue Oct 27 05:53:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8F7161C for ; Tue, 27 Oct 2020 07:54:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4701720738 for ; Tue, 27 Oct 2020 07:54:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="UJKbPKZ+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4701720738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJoE-0001QV-6o for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:54:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvk-0007K8-Qg for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:00 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvj-000447-A0 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eSgjNeQpNVwuJ+o4ylSZ1EmVOQn5SeY92T3h27fjisAOiRHgiTRy+0wtHKjgM3mEYmkOYTntW+7T5RstFORfM7bB1HWQP0fEHmaGGisXs+5m0/auvIb4KwnxWI6o46jQ6k4VoYmuo1mekL7/dDXLuQRMSeyv5oRfvwzz4tiJlT5ajJxTqtUEP2sksE9V+skSrOM7XdlK69Y9Wo30dfpH3wHrw6WIxRaG7HJchY6hl8hNKzL1/VoOKUAZHgydq4B9rz01FG+Iqo4uWA5psFP4Kz5WBxamoZIPmZ39ah8cuIeLMQzuJBIb5Nz7CykiZvCToNyaOvAh2K69bPKfdWEszA== 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=HL0ghsKEkeCz3XbAid8p89NyEpsk4DOmN5sAtb/yxtegDElaHgE4fFRMUwV7XQtb5wFy/cYjx2hju6RXbThkOicndQDSBvHs2dk6Cv8XZYp5OMiX9v9JbWVPcUaDXk8Am7wbB8jB6LfOjkWv3iSTIIZ2pfUR79nkrAUJmZhqwtPhEqMvMXstWi2/asF75bcDzUoAxY+I5LD4X386e+2XdT6Ws9MtCUFazhR0gbHJhuUgujGbF8XqblPgmrvJ4Y2O6nCktIcbASVPlBR+SFN9hQMmIJVyGdsg3FF7aHX5YOgMiPLDwAm41R73+qR9vjwZH+r85CWX3FJ6Nma0ERJ7hA== 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=UJKbPKZ+3xDWQBPzP1+TKXR+HJkBqXwGMsSnjxKy+DqBCiGgUkHEvOPObsl7F7qHqIhBMsK13Y356pkP965Jz3x00zuTMQSZFxfnkKS86Gb6BAI02KcfkLbrnnfhrAlRU01Bh4A4oKKnbeOxPH2bZFy4SzHV+ZyZ1yCaYpbNEbc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:46 +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.018; Tue, 27 Oct 2020 05:53:46 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 03/12] qga-win: Fix guest-get-devices error API violations Date: Tue, 27 Oct 2020 00:53:08 -0500 Message-Id: <20201027055317.351868-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0091.namprd12.prod.outlook.com (2603:10b6:802:21::26) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0091.namprd12.prod.outlook.com (2603:10b6:802:21::26) 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, 27 Oct 2020 05:53:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: de5cd4ca-fd0a-4756-6b11-08d87a3cab48 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: Qt5w/XGFAN8DnRnE0MJQG3p68PHxXEeoUeowe99ycGxyPuMG613Y0HVheJ9P3zgQkUHVWzBKlZs3IZPfiumq3slHAEjgZlnx6jzHCeq3FSwhor2k7pJpgf7mJXpbx7lyQD7E07kz8Lz/gF4w9ymYkv8GW2yisQa9wARnDOsuXj6GjxMN0LD/D76JLEbgUkhrn3swFZ96nFFrJzgI0eL1P3aQz3dmxCa5NRjcNytSPC8RBut8SpuGilKgahUJIQ148lvDJZtUmfKcv5xSlgLMo32xpFfqckunnsJp3OAzfjLYGNYQPe6hflILKMma6mkS 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: SsRRWHhjRj6vxl5mQtao8Vh2PsA3GxLS1qS2A2oaokD6cbi4SEdWUQ82sz8ajoTh4Lux+88DHBPmTupka6CCEhYU9ECdo0SBfqQ2QSvCX0Q7jCR3vsA6OdiUsUi5JcbhHOSRg7kyt9XqxWhxCEw1cA2teJjA4THqdxPycxusPdSgPgn3qRWPyIICkiIQ7B6FHi8nsT3LbvUzPHLvm4FtjIcqvfJ84+XRLfIH4XlRiPyTyfTZNks/KRVMLlm6UbCYuw6PS6Z33Us24rvNe+AUZDpp89097fwhNCokemQO6X169m0C8aOax5kzlIExa8IOWxLNyc0ZR4W+pItmJb/TmpKl6HprI9fRqKhwB1KOmxBH/AxnymrccZHc0xJ2L2Zg+SOGz+qsiHmVaWaOwqeXy8ac85/0pzvl8MmlcBFzay1daGIUH0zFB7cZzs8VX5hl6EH/c02nUxIo95UaHp5W30hLXpOiUMAeSz1xO/KqL8QqJhYpsiGDDY3KWjUBevbRa5RmQn3OxSS7v7h0c5XOpBQDS35QnKcG4ng2xWrHcUxxe2GBXYHK+zbbn+y0homkEUP9DzqE0KoiAdbc+wzrzmCCFu8X6RhC36Py+43G4GusbwPYHD310lBG9WUdFWnbDTZUkNq7vS/VTV06NJ8vLA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: de5cd4ca-fd0a-4756-6b11-08d87a3cab48 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:46.5142 (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: v/6JTYljWsdm29w7hVZFoKScV9K5rUxRNuaqEp98AIsw4Ydnh9L2BkVEYqGwlu3fmq45gB9rWPJTJASrk7an4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:45 -0400 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_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Marc-André 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 **errp) device->driver_name = g_utf16_to_utf8(name, -1, NULL, NULL, NULL); if (device->driver_name == NULL) { error_setg(errp, "conversion to utf8 failed (driver name)"); - continue; + return NULL; } slog("querying device: %s", device->driver_name); hw_ids = ga_get_hardware_ids(dev_info_data.DevInst); @@ -2428,7 +2428,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) NULL, NULL); if (device->driver_version == NULL) { error_setg(errp, "conversion to utf8 failed (driver version)"); - continue; + return NULL; } device->has_driver_version = true; @@ -2452,7 +2452,6 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) cur_item->next = item; cur_item = item; } - continue; } if (dev_info != INVALID_HANDLE_VALUE) { From patchwork Tue Oct 27 05:53:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3F7F61C for ; Tue, 27 Oct 2020 07:52:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73488206DC for ; Tue, 27 Oct 2020 07:52:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="fIlBlftB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73488206DC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJmb-00086v-EN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:52:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvm-0007MV-EV for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:02 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvk-000447-VN for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FgJ/uM9zksHwXuxMJM7AHs3K700SzyXS65c4/SZuxjEPCyQFsuevr4NEKPeMEMWLaKNBWoU7cy3dg982j4TdTuzrANDzlMJTh5+5+leJaiMXyHB7bmk+LI5Aalq0J8GkthQboLj0aUYslMKfb8D8h7EmQ8qGYfrl20qI4XjBrdvP+acOpKQ/4lvM9o9nsYiWhgFYv/0avbghxOQOF3uCyBHr9fGHOwunIxSygjs+pj1b2RnZ8IMWdvkQ/9cTrbK9vk8FnJaIhdHeiZGTO9W/6srDrD5iCkeAkbFQzvvW4fk+6HfRU6mQocMUoKU9TIuBDOi/ppWRPSzjbFjBo6laQQ== 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=XRa1EcYI3/ArhN/ptjqdHS/C9Ug6CAScseCTnA2eG+9DF2pHjnKb6Zy+qcXMVQwwTCe5Bq1lNT2oU8pwEd+HAhJSejlo2891+Spgz42IGqkPXxCz9h5AVX2JTpXBnJUfh4GUhoRF1UvmsAqkv/A9/YDQw1wjWwhuT1alpO5+Qd2xIir3mCWnXLDFmCqiBrvzStdjeu7oYKnjxqJtptYWs57fKFyoHe1lQ/MwDoks6p32JPep/U5g696tFqW/PNPVl22HjMR1K1Fq4JAdby/tXwBNFdJmIwxprkFzZQcqLABxIH8r3tKv9+HHvvkPA4+UhQv0GnwTs8XcTkXcXgs/Sw== 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=fIlBlftBAQBW67aGcvlem+lWgXLCnsXim7uz0c8t1C+O6KvLQRfzgXmvrdZEbMdWWHBPwdKb85iFUCbgy/AHKTwSUJwJIzvRW/ZY0hm/11bXZYG/wHylFnvW4DSd7Fy8cvJXUC8n06spHgHUf47ekmhVPBCZ+vNAg88ad2vz4R4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:47 +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.018; Tue, 27 Oct 2020 05:53:47 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 04/12] qga: Flatten simple union GuestDeviceId Date: Tue, 27 Oct 2020 00:53:09 -0500 Message-Id: <20201027055317.351868-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0102.namprd12.prod.outlook.com (2603:10b6:802:21::37) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0102.namprd12.prod.outlook.com (2603:10b6:802:21::37) 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, 27 Oct 2020 05:53:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 74d81e74-9cd6-4429-4775-08d87a3cac0f X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: H6b/F3xXa8CoQVZzF1mxcG6/jy96enxSwrLT0Vz/37H4BGHVTPiS0Hv+TJo7C6+Ti8NbA1uaqGa0a3B9vMqXQMgPBRYw8MsqpbXzEglzYao/RH60yvhM1tRjY9ZoZpstQqfbK2Ssp3k34zzEyj6C66vPbbwsn2T0uF4FBvUaeh/QbJImRlAcfOspdIwBu2kiiaH4zIi6IV4MCdXeq2DeifCekgAxsaQt2Q5Noqv6uFqi0ebmNSJkXJxC2ZRVP1SsNLvT/CLPKCFuZ58LHt3XDibH09kGZaeLWMM9MQurk/GOxkc20rWAhH2zcyGSmzeABe47yWrBgPJZALGittJaoA== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: pVqpyUBRredj446BWKMJvDA0lgzb8NZYJlXBoK9/lSSg/wz3V2Fj4cLmqPj5PZpuiNssIRrfMIbs3zwjyFnngg1n1OK9KKFGLYN/L3RrtvfT/aHVGmyn7Gtx1Grjy/mmuSL9UARkCNTx94tvYcuw2B1Y295JpeUraGGrSxkLDIdcauCZAxr6KO+GPqnkZsHpGYWR7/Uk0zCnbul36DaOWBApkf8Qh24+kyIrHVS7awQKIG/wuZBaxIr10QUGYYtean5+HYf4WsLd8Gt87CmsgprxmKFZs6uGI8FXv/lfIXF0it1k49bww8QpE2v9tPL86LT5ig1Kv92nncbbtjAdZfh+8I6yXcf3tzaROY7fpwsgPzKEKoD7BMnnQeuNFbKeUjTe77zhmFmiHfqVodcvgrISjiLNLGJuHKXxb5mbwpkT4VI5FXAbGQRu6cK0Jyz9t8LF85BvF2PYFpgKy2ar5NjtTtS1Reh6bBp/QBDfH0AT7+pUurAePI1PJzuMjFy2H+mGf4JzM9nz870Mtua/Wmig8OLCS+hvGNy31umyGFEeeJzu9B9paeSuPm7IJuRjaaM0B+/IvyY7VbzMS5WHGerHkv03Fe4APx1rSIXh8VcxpAo+PMfacEXKZCjFu6Fky+/csi20AXlDQHJav15tQA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74d81e74-9cd6-4429-4775-08d87a3cac0f X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:47.8115 (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: AGAAcIYpYAaasHzA47aBxmWSpUxgj25PQvALG0ivWv3Yi1ujO52xWqKWSsrqy0zhRMb3vYCntwobJJm3HEctaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:47 -0400 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_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Lureau Reviewed-by: Philippe Mathieu-Daudé 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 = false; - id = g_new0(GuestDeviceIdPCI, 1); vendor_id = g_match_info_fetch(match_info, 1); device_id = g_match_info_fetch(match_info, 2); - id->vendor_id = g_ascii_strtoull(vendor_id, NULL, 16); - id->device_id = g_ascii_strtoull(device_id, NULL, 16); device->id = g_new0(GuestDeviceId, 1); device->has_id = true; - device->id->type = GUEST_DEVICE_ID_KIND_PCI; - device->id->u.pci.data = id; + device->id->type = GUEST_DEVICE_TYPE_PCI; + id = &device->id->u.pci; + id->vendor_id = g_ascii_strtoull(vendor_id, NULL, 16); + id->device_id = g_ascii_strtoull(device_id, NULL, 16); 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' } +## +# @GuestDeviceType: +## +{ 'enum': 'GuestDeviceType', + 'data': [ 'pci' ] } + ## # @GuestDeviceIdPCI: # @@ -1276,6 +1282,8 @@ # Since: 5.2 ## { 'union': 'GuestDeviceId', + 'base': { 'type': 'GuestDeviceType' }, + 'discriminator': 'type', 'data': { 'pci': 'GuestDeviceIdPCI' } } ## From patchwork Tue Oct 27 05:53:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6ECDC139F for ; Tue, 27 Oct 2020 07:56:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 191C62224E for ; Tue, 27 Oct 2020 07:56:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="J5STsBI5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 191C62224E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJqY-0003Du-00 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:56:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvo-0007OK-80 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:04 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvm-000447-Ku for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jFbKKI0aPt8AB236yeSHdxOECJHhvUXT53wZbxWZY3OwZRbz4QqBE3ksr9vb4P01GnrjBXVAjS57FvIs9dw4xNpNht7TeF+NJtQGP2SqmE7hSV1ihG4pasaWmTcHD7XdUAaeaCJ1sAOi/rsTo1/UjPNeu5xluHTndWRn1Eiu5Hz0Lvqdvkp9iIYA5o+mhRA/nr8xR4srwsM523el4iTq5lyD0ImTyPN2t8adX9KCJ1J16LWsfLVhNP/0HHmsfv7clSW5qAwUQuMqrxE0kAt+gZt0g3bL1MVvEd+xzCJqLcu10AJfvstGnLoq4Hk9f4lybY0MUhOnX28tIlfv1TwHig== 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=TbrXdO3kSE51A803kAlXYfRNJat0MPWQjUrI0I3G1xQF+DhFtSZJnQGzGc/Fy/xP7LDyvsp2z76fLmUQtPFDyLHhVDl3Vw7jB5q2gfDxy7fFRB+nf+uE0QvgDyKkdOtoUKT9h/sE03hUsZqptlnk+QDShHPYCYj4O6njBDsgkNkK5GU6S0Lkf2JojxB07FhRkpluQaVP0LRZosGejLoSwVN7Q88c1dssvAhSR+f8aZSul49+UVh5zKmsKFQAioc1kxEIn46uHW/Ebv/tpeXi6j/CAREfAR1yO22peBzAQ2lXWoY2E0RXBoBsIiUE0JYPwyvJpb+hvUWKj506XiFUsw== 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=J5STsBI5F9ek1ZyZ11ZvuvQgdyDMo377I2O5oYQY46rtavAKuUt8Ih2Zgs1mhfU+twRXITU9AZpSHGzUsgpb9pwsgs0CW4dKsO7PUrz1M1UMNTCj/nC0grhjVMKJ5cFHbVTgug3ib+WlnGqKnDlCPN0PrlyfAzJtSDjjCsTcxi8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:49 +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.018; Tue, 27 Oct 2020 05:53:49 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 05/12] qga: add command guest-get-disks Date: Tue, 27 Oct 2020 00:53:10 -0500 Message-Id: <20201027055317.351868-6-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0114.namprd12.prod.outlook.com (2603:10b6:802:21::49) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0114.namprd12.prod.outlook.com (2603:10b6:802:21::49) 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, 27 Oct 2020 05:53:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 699d58ae-8556-41a8-d567-08d87a3cad24 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: SbjniElAQN5vU7LE2vCmYFiGU+TM/fWGE2EM9z813eiZO5+08/d5IeudJo4fqOlOMvSg1nlEchZ5whosRm8CkcHOqxc9+OmFtGvt/4gRnJxE/MEU/yVKX51RiRK8V0vLpPneTe2fTGsYLISgATw/gjkVxH7Q3SmA90e122nccmDaeuK1mN+DAXMFupouEnrQuA2SoDi7zJWgz2lZ/O1o4JtuzhBUPdG0Sw9jy4OydYiUAf9YlLjN4APKuqXGK7B69z+B+fKXJMBcaMudwGplA8FaUg4SUo9is4Xu+HLybvLep7KJJHmqz34EtkRvp2ll4ZIRsqRYP74WggAvXW7Umw== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7OuE/6AgdGBTlWK3uLZhdytdG89VD2S9dLznVaVar4R/jL3xY4Qhpa5JmoTkNQeUw9bHHHU3vwKt/c7A1IVvuTmTLMsv3NRg4w6B2W3kcb9diE4EBfIkECYJ+PMapn1hGzLXkxmx47TxYUl5ClqA58WQVd/bA//NFUteC4rNtxgHpZlTEtYkqzsb0CpJd+yP4kuxzd/rv+vFm60I6Lb8tqbH53jVLkDMtzf6DW9QUFLeVsN4DXONf4aU/y5dbpS/sLvwVVqSFsnnT+4gJf98/ynR4oPPNT5yjfyOIbfz8e/v+Ya0FITv9iMYda6oC2OzZN2rQAWa1i8gieiuyAS/O2XJK90nAkYtqOlyeUO889KwuKw45VO4e/OhUWzAOYpaEbFjrULJEvsOpq0lHcuVvZkdZbSzLM28JRTbvzgQmWPnJ3ma/I6Cj0YvO4t0R8zFgQGS2qCu9xQMF6PS4RB78JQbLtYt9UFz6O0Cbrwu4TPUybjv9nE+3UqE7Yf4Qc1DkEGSBiHqZPzGWZl7nZJRCcAAsQNQFP3KJb0h91ATFFCgauVj4erKRTX5HRJLq7a3azkMugkbRxStyio+FJJ9nrPR0+Dcgh//jeSsO6ZdzMlX6sjopTKjHcRlsPXpEATGIun7Uac173mTFSTdV+nAWg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 699d58ae-8556-41a8-d567-08d87a3cad24 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:49.6634 (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: zl4/k5AewjNdTMnbShBPj3jDgo3u+C7MIufpaNG+C+FMYJCWIFrR5xaI/EigTsG8i9Z62+XuekLVkcHT3RVf5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:49 -0400 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?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tomáš Golembiovský 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áš Golembiovský Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Marc-André 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 **errp) 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 **errp) } 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'} } +## +# @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 assigned +# 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: # From patchwork Tue Oct 27 05:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5022161C for ; Tue, 27 Oct 2020 07:58:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E44082224E for ; Tue, 27 Oct 2020 07:58:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="nukToy3Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E44082224E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJro-00048o-Pv for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:58:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvq-0007Pf-9K for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:06 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvo-000447-D4 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OEc1DHs3w3Ng3MnUBIu2gCbkQuwCi27fSzBAkgk8D/fhrGOl65lbfEQinjnlARVJ2/q+e6Um5kqrxXkqNuCqDYRdsFwsn4r2idyCnZtzMnNlkNrLzg2JH7HETDceCLv0hYpMypJSYH6DuYz1sUP+a4UEiXgn8oZzI1r1NrmP555W1hUZ59vFxkhkltQXlzP+2J6A+9xsZPzzNg54zBLbvOj/BkJrR7hPwam4pvayHchF9ybzc4E8iHTyAZ6qZcG8brRiIitL2XwEvkXu8NUkJOKBDRMM85ZOi89V7pQY6Pn3FqhZxYy/H8SobVJThRaE/Pav2GOG2CEpsQKn/CAExg== 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=zVAOZEe3ltdaN+xXNGEZE9xJWVazPAG0yk/RwS7lW8w=; b=V2+EiNmjSQgzsRoHPkt59mwC4LqLs7XqFOcKVzmoay4NFGpjqAXVhrmEtlEhpNfrQq/q1gcDoZjvDnM1AacPE5dlxp9J0abbudCmHuuLtBnYVmxgBhkOy3AkITq25pOVg4sKKqxq1Kean4cEchtnR5+xTQchfFX9qHRIdyOLbFDIxRyhGh8J+QjNzVQR1C2EWbgYIjowKd8/ZY51mfmFXcaYtQ/AhLrTNVNW5BSfbcnidMHWDRsFMij0x65ylpI0hilYtxqR0btmDJdv5xdWWPvtFgjcn5m7hDU7Lw1b7ZyW4lRPcW984Ncx3J7n+cEqmbBVgjyGNGuZk5Sgxrf4OA== 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=zVAOZEe3ltdaN+xXNGEZE9xJWVazPAG0yk/RwS7lW8w=; b=nukToy3ZORJPA2L7BwbJolDkNmaeV78AYaQZeGrD07L32UrOcHCZhRbSbbUVAXPHf1HFB1FDUq3VaPeV9VpW1T2jDXuMgORZtx7YvH8G0r7g3J5ZufHAz794PLjGvtZ5tDSP8H96ZLekhVcEHoJscWLPjQbpo+QOLDPnl5Ag5gI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:51 +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.018; Tue, 27 Oct 2020 05:53:51 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 06/12] qga: add implementation of guest-get-disks for Linux Date: Tue, 27 Oct 2020 00:53:11 -0500 Message-Id: <20201027055317.351868-7-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN1PR12CA0110.namprd12.prod.outlook.com (2603:10b6:802:21::45) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN1PR12CA0110.namprd12.prod.outlook.com (2603:10b6:802:21::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.23 via Frontend Transport; Tue, 27 Oct 2020 05:53:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 10df9f43-9ba3-46c6-cf41-08d87a3cadf4 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: +rPakAVOxK2hSje2oBHFX4lfieVpUvdMu7JkjL6a4APk1eGglxKI47ICWzdL6IBAFRdAkUiHGWpr4As7knJm2WMTFkGbZKl5w5OhL9MjM8c3pO9NKfr8byUDcvl9avu8RqMnBLQLjTJRN8NVJh6+KrPKfNkuNUuc2i9R9RW4h7jls7SFp26V9xIJ4MvY3nObLxy+uWO3oyGCCKvwrg8xAHftQun1dsqu7LCkgMAAq/1ZmEE+OX008HZDVhPMuKlvh7SutxsGHhIn+ngNoIxMJvrxzAHpqw+LNr+j3Y699iu4wdmlWqIc1toVSPH2gQAa 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(30864003)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cZ01zk0WsWmit/yceNYFF8FxORhFqwiHkgB0CgVULF7TmYv7EAa5O0vVIJ5XNFDRGhYz+zUS54jkuR4WTsNYSfuOqpAGCbQUneeLhHjI0Hzh6bAClC8nkSJIkcEtYgUluHW+JQyUt6FEGAzZ0Jjty9M610dgjUWOHbyJzvK5F+MYEcVU2KXEDmdLW97oPR53lHZ3S7OpE+WLTzZ2CzkeOBp0EmQcK1hdf0GoLfcknwi5UQzcvdL9aWjXDt9OmE6I6qT9Pc3+0u+cJot+ZnsKS3VQcrrR8orTW43i91HdIODThrc9cPHJAfGCCusxn2NsUorZQi4qsRbbXzsANnbTDTdEjCF28Pb6OF4sPVO2PbGAhRZivWEh7i85uzaRymjRuoGRIaMnMiT3Jik/eiWZsZdrSfl1b0ssEoLWxGIrTRAG+Ll8RxQ5NK1AFdoQGV8vmhlJBzj/bui0PD/OeVkG3/ZBGSKkAi6F4QsB5W2N9xQ/wC07HJfannEzCC8HBPM7RXfxnSryrm+jKjuy434Q+KgYse2FPM8j3kOjb/M6Ng0dAiESqe4ghhihB3p+PwRK/PLWy+5p0wyAjkXdY2Cxt1lqOJFgXFhOGvwLz2Nf4ZVhbcMe2mGrluAjA8K5VZCB5GzB0Htl3hiUSPIT5gGeMg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10df9f43-9ba3-46c6-cf41-08d87a3cadf4 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:50.9905 (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: LuOHo2ZHZ/zYvZUTPyoXfPwawIRsV2QP9qlH9poCr8kDzUakJQhA9rz80pH5E2jIeIECPastbTvXNY++99235g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:50 -0400 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?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , =?utf-8?q?M?= =?utf-8?q?arc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tomáš Golembiovský 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áš Golembiovský Reviewed-by: Marc-André Lureau Signed-off-by: Michael Roth --- qga/commands-posix.c | 296 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 285 insertions(+), 11 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 422144bcff..14683dfbd5 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1150,13 +1150,27 @@ static void build_guest_fsinfo_for_virtual_device(char const *syspath, closedir(dir); } +static bool is_disk_virtual(const char *devpath, Error **errp) +{ + g_autofree char *syspath = realpath(devpath, NULL); + + if (!syspath) { + error_setg_errno(errp, errno, "realpath(\"%s\")", devpath); + return false; + } + return strstr(syspath, "/devices/virtual/block/") != NULL; +} + /* Dispatch to functions for virtual/real device */ static void build_guest_fsinfo_for_device(char const *devpath, GuestFilesystemInfo *fs, Error **errp) { - char *syspath = realpath(devpath, NULL); + ERRP_GUARD(); + g_autofree char *syspath = NULL; + bool is_virtual = false; + syspath = 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 const *devpath, } g_debug(" parse sysfs path '%s'", syspath); - - if (strstr(syspath, "/devices/virtual/block/")) { + is_virtual = is_disk_virtual(syspath, errp); + if (*errp != 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 **errp) +{ + g_autoptr(GuestFilesystemInfo) fs = NULL; + + fs = g_new0(GuestFilesystemInfo, 1); + build_guest_fsinfo_for_device(syspath, fs, errp); + if (fs->disk != NULL) { + return g_steal_pointer(&fs->disk->value); + } + return NULL; +} + +static char *get_alias_for_syspath(const char *syspath) +{ + struct udev *udev = NULL; + struct udev_device *udevice = NULL; + char *ret = NULL; + + udev = udev_new(); + if (udev == NULL) { + g_debug("failed to query udev"); + goto out; + } + udevice = udev_device_new_from_syspath(udev, syspath); + if (udevice == NULL) { + g_debug("failed to query udev for path: %s", syspath); + goto out; + } else { + const char *alias = 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 string. + */ + if (alias == NULL) { + g_debug("failed to query udev for device alias for: %s", + syspath); + } else if (*alias != 0) { + ret = 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 = NULL; + struct udev_device *udevice = NULL; + char *ret = NULL; + + udev = udev_new(); + if (udev == NULL) { + g_debug("failed to query udev"); + goto out; + } + udevice = udev_device_new_from_syspath(udev, syspath); + if (udevice == NULL) { + g_debug("failed to query udev for path: %s", syspath); + goto out; + } else { + ret = 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 = NULL; + const gchar *dep; + GDir *dp_deps = NULL; + + /* List dependent disks */ + deps_dir = g_strdup_printf("%s/slaves", disk_dir); + g_debug(" listing entries in: %s", deps_dir); + dp_deps = g_dir_open(deps_dir, 0, NULL); + if (dp_deps == NULL) { + g_debug("failed to list entries in %s", deps_dir); + return; + } + while ((dep = g_dir_read_name(dp_deps)) != NULL) { + g_autofree char *dep_dir = NULL; + strList *dep_item = NULL; + char *dev_name; - free(syspath); + /* Add dependent disks */ + dep_dir = g_strdup_printf("%s/%s", deps_dir, dep); + dev_name = get_device_for_syspath(dep_dir); + if (dev_name != NULL) { + g_debug(" adding dependent device: %s", dev_name); + dep_item = g_new0(strList, 1); + dep_item->value = dev_name; + dep_item->next = disk->dependents; + disk->dependents = 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 = list; + struct dirent *de_disk; + DIR *dp_disk = NULL; + size_t len = strlen(disk_name); + + dp_disk = opendir(disk_dir); + while ((de_disk = readdir(dp_disk)) != NULL) { + g_autofree char *partition_dir = NULL; + char *dev_name; + GuestDiskInfo *partition; + + if (!(de_disk->d_type & DT_DIR)) { + continue; + } + + if (!(strncmp(disk_name, de_disk->d_name, len) == 0 && + ((*(de_disk->d_name + len) == 'p' && + isdigit(*(de_disk->d_name + len + 1))) || + isdigit(*(de_disk->d_name + len))))) { + continue; + } + + partition_dir = g_strdup_printf("%s/%s", + disk_dir, de_disk->d_name); + dev_name = get_device_for_syspath(partition_dir); + if (dev_name == NULL) { + g_debug("Failed to get device name for syspath: %s", + disk_dir); + continue; + } + partition = g_new0(GuestDiskInfo, 1); + partition->name = dev_name; + partition->partition = true; + /* Add parent disk as dependent for easier tracking of hierarchy */ + partition->dependents = g_new0(strList, 1); + partition->dependents->value = g_strdup(disk_dev); + + item = g_new0(GuestDiskInfoList, 1); + item->value = partition; + item->next = ret; + ret = item; + + } + closedir(dp_disk); + + return ret; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + GuestDiskInfoList *item, *ret = NULL; + GuestDiskInfo *disk; + DIR *dp = NULL; + struct dirent *de = NULL; + + g_debug("listing /sys/block directory"); + dp = opendir("/sys/block"); + if (dp == NULL) { + error_setg_errno(errp, errno, "Can't open directory \"/sys/block\""); + return NULL; + } + while ((de = readdir(dp)) != NULL) { + g_autofree char *disk_dir = NULL, *line = NULL, + *size_path = NULL, *deps_dir = NULL; + char *dev_name; + Error *local_err = NULL; + if (de->d_type != 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 = 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") == 0) { + g_debug(" skipping zero-sized disk"); + continue; + } + + g_debug(" adding %s", de->d_name); + disk_dir = g_strdup_printf("/sys/block/%s", de->d_name); + dev_name = get_device_for_syspath(disk_dir); + if (dev_name == NULL) { + g_debug("Failed to get device name for syspath: %s", + disk_dir); + continue; + } + disk = g_new0(GuestDiskInfo, 1); + disk->name = dev_name; + disk->partition = false; + disk->alias = get_alias_for_syspath(disk_dir); + disk->has_alias = (disk->alias != NULL); + item = g_new0(GuestDiskInfoList, 1); + item->value = disk; + item->next = ret; + ret = item; + + /* Get address for non-virtual devices */ + bool is_virtual = is_disk_virtual(disk_dir, &local_err); + if (local_err != NULL) { + g_debug(" failed to check disk path, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err = NULL; + /* Don't try to get the address */ + is_virtual = true; + } + if (!is_virtual) { + disk->address = get_disk_address(disk_dir, &local_err); + if (local_err != NULL) { + g_debug(" failed to get device info, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + local_err = NULL; + } else if (disk->address != NULL) { + disk->has_address = true; + } + } + + get_disk_deps(disk_dir, disk); + ret = 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) @@ -2809,7 +3088,8 @@ GList *ga_command_blacklist_init(GList *blacklist) const char *list[] = { "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 = (char **)list; while (*p) { @@ -3051,9 +3331,3 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) return NULL; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} From patchwork Tue Oct 27 05:53:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06B7061C for ; Tue, 27 Oct 2020 07:59:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 765742224E for ; Tue, 27 Oct 2020 07:59:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="P0nAb5SI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 765742224E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJtT-0005E8-AY for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:59:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvw-0007QR-1N for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:12 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvq-000447-H4 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSIOgVu0Zqff1ekTPruj32xvzyugRexUiXZCcY3XE4q78kkcPoILL4QTKYhV1gGtrkC9GNON8xHet9VIEFg+MEAb9Sok95pmgzlJ3IqAcnpsS6fXnDy0rVJepdes88HvrgCM0uEgNdTnthk/llC0YD1BXsbFwbGjHRE0RAFK2nVgZu8s2plG81VCyS3FqUSzZKc4/tpQZOm1EXhXT4pg7vdPico4710skuka5n3LRFHuRElUHOoENyZ/p1apwCihcGA1G4S4UVkK85DhP1Gy1mRtSw3dUTc/PBNGXEb5V9LVdmM952g44O4ofDqwTHo4HLtmS5FW7gxAo13vLun2VA== 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=Pkbf2E3mefRNZbsTn7ks+2gp+Azft97r6MHCJkDvnfucDZZh7ZobjwTRTm1AxD4J7nlBuDQoZIXOZ0mHPVf3AU4o6qER2FNhOHrtvN9VHUX+25I0tKim7deSwzaTqkUuXvgyMIe1EBeJh4MgcaZ5DvrHIOhFdUcYNLopcua75PPs5qwlzjeswGZAlWEk6ylet41FxiBm6uXxi5+mUKGaSsqeOsUohPA6EmARteOCOUhdmsrYbq9QZnu3SA28L8P+O3pm6dNJQqNWc8TG02xl5jEIQskVwL6wJWiO/0eJkDwWtIIP5JPjzg/iOqYxiiGNgOiEe2bsYorupfo9xGuNIw== 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=P0nAb5SIazDKO+ou1VK4eE+gFDkGtmlJ7sMB8sj1atVlvCMWEJpmOrkeE58+QNbvi4Z6CKMe5bsGHz5v5SnM4DNfJoMGn9RvZxfxCFy4SARXgBl7twGdLACUg1J4bAUTYDyMOcaTaAYADRD9q6WZyjEsdGvzAJtFJgIdnxHXW5w= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:52 +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.018; Tue, 27 Oct 2020 05:53:52 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 07/12] qga: add implementation of guest-get-disks for Windows Date: Tue, 27 Oct 2020 00:53:12 -0500 Message-Id: <20201027055317.351868-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: DM3PR08CA0016.namprd08.prod.outlook.com (2603:10b6:0:52::26) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by DM3PR08CA0016.namprd08.prod.outlook.com (2603:10b6:0:52::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.25 via Frontend Transport; Tue, 27 Oct 2020 05:53:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c9b15ecd-7b9b-42c8-ef36-08d87a3caeac X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: wN/gUgN+xtGNWpaPgvZZE3JFQ1o1f1ZLi4QvGySXB3yYnPuNoEJ7JZkDLSYjrpjwzb9iBgkWHqrFZozMPoZkwIit1g16DkQx3b5pq9bC9TZjnCJeFwmOdqjSCElaRXjSH5ClClCzGviAOWfnQO5qEH/aSDpdu06C7SWx0+TCff4QZEK7r3c1hFi5Tp5G0yESN9O8gstWD0y0PwTJmGQYOE+cxUSIzxZAV4KVPYv0V34oTOqNMkieyOBrMW9F9ezV2DeqA3FL1FkM8NoPmzlfP0Qld0SN7dGnJIubw6tRyAgST3+eCrbfiXEhfYAl4y3RhfbZF992UoxkIKuQS3QAHw== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hzWPWGZ4EyBh4rA2cjyDLLOWKWo9YAVhjI1LNCOexpF/tpA2OP2qf6SuTV+r79BoSzjgh+o6zvI/M5PBN2FG6tFmUtR+fpPtOGmnCcLl7K2KfuvtSY5LhePTYd9OeIqNRXeLyJL5X6cxThvg0STS0JBXjMpotdQ+A4L0sVzQw7HWQVMgoSP1ZVkke+ImxNWVNOH1ei7MczxDlSm2pPvSzAHGMY/3txkuK4OgryDrqPcZp88Ld/PiSfAS2yTRcNL75O/JWohUpA2DUrZTlozLPoSrNAp/KBWli12QxFz0r33QNfLj/9FwE2zAMFY/mVQjjPx/+azT/61I5D0ALwFV+kGN5R3q/oQA29bnt8ZUVaFlZuQ6DTVqguBHj12aHPyy0D4j3w9ZHeMJ/P1b4DAFZf+VYXCtbn85fYx1lH04+v6FEjjW6a2dVUrMZ673uqdSeNiOQy8o0Kx34bPS8uzQ1hDsGBlCdBTQs5VhrYa4hQmuqB6EwOyTVE/A7iHDy4COnnZFC7MYk1639kmlT/Zyjc5hH39Joqt61Qw5kPRmMDaXCFWjW1rUer8mRkVGFk9fx3QRSDr+ZpCTVBSfz2I11O5buoBlWnHMkf67sTMq4mB84Ek9Z35NwL+BIGuC+i+z1cKrVKgPBb1jTAfn3QkUTw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9b15ecd-7b9b-42c8-ef36-08d87a3caeac X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:52.2052 (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: qewXis3gS5rIUORLs6gKQGtW61QOgLHboV5bd5c0jfX89ZDC97i7UhVIkpLm0qEjvi9rWGfGf/LgkNtWo9XLww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:51 -0400 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?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tomáš Golembiovský 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áš Golembiovský 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; } +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + ERRP_GUARD(); + GuestDiskInfoList *new = NULL, *ret = NULL; + HDEVINFO dev_info; + SP_DEVICE_INTERFACE_DATA dev_iface_data; + int i; + + dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, + DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if (dev_info == INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to get device tree"); + return NULL; + } + + g_debug("enumerating devices"); + dev_iface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); + for (i = 0; + SetupDiEnumDeviceInterfaces(dev_info, NULL, &GUID_DEVINTERFACE_DISK, + i, &dev_iface_data); + i++) { + GuestDiskAddress *address = NULL; + GuestDiskInfo *disk = NULL; + Error *local_err = NULL; + g_autofree PSP_DEVICE_INTERFACE_DETAIL_DATA + pdev_iface_detail_data = NULL; + STORAGE_DEVICE_NUMBER sdn; + HANDLE dev_file; + DWORD size = 0; + BOOL result; + int attempt; + + g_debug(" getting device path"); + for (attempt = 0, result = FALSE; attempt < 2 && !result; attempt++) { + result = SetupDiGetDeviceInterfaceDetail(dev_info, + &dev_iface_data, pdev_iface_detail_data, size, &size, NULL); + if (result) { + break; + } + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + pdev_iface_detail_data = g_realloc(pdev_iface_detail_data, + size); + pdev_iface_detail_data->cbSize = + 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 = 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 = g_new0(GuestDiskInfo, 1); + disk->name = g_strdup_printf("\\\\.\\PhysicalDrive%lu", + sdn.DeviceNumber); + + g_debug(" number: %lu", sdn.DeviceNumber); + address = g_malloc0(sizeof(GuestDiskAddress)); + address->has_dev = true; + address->dev = 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 = NULL; + } else { + disk->address = address; + disk->has_address = true; + } + + new = g_malloc0(sizeof(GuestDiskInfoList)); + new->value = disk; + new->next = ret; + ret = new; + } + + SetupDiDestroyDeviceInfoList(dev_info); + return ret; +} + #else static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) @@ -986,6 +1081,12 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) return NULL; } +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + #endif /* CONFIG_QGA_NTDDSCSI */ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp) @@ -2458,9 +2559,3 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp) } return head; } - -GuestDiskInfoList *qmp_guest_get_disks(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} From patchwork Tue Oct 27 05:53:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1228261C for ; Tue, 27 Oct 2020 07:48:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A60FA20738 for ; Tue, 27 Oct 2020 07:48:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="xYH6p7zP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A60FA20738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJiu-0003Wa-Kz for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:48:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvz-0007RY-8B for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:16 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvw-000447-CH for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:54:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WdSi5kJvCh/v6ZJ5qKgkEvSScu08+TNmfGnssB/eVb67H/XZoebW6td07ZqtuC/a3UNYeLAB0hvvz72p7g0Ubw7QbktXav4Z9yo0c+AnPaxG/D1cBSMMgu9jy2+GHOEBcpuS2cWsbQyTbp/wew1TBdJgz+stLQ0Qig8nvWmfBcAaJSmpothAKozull10KpTlH80DYbzEW0VQNuYsYfN/Q2vfAs5q2cuff+SrXJvEJ53MrlZtJA3bj2qPkmxehKYu0dY9TpEgxGzEk3BczLRdlC9STgDmrH3CutVyZ9wGV0spfsTvfRRJ0FYrw7NIvhb/4gHKFuwLm7KbOpuriA02Zg== 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=h7su5AFn6hDwJuBnSptLefvfQ8URHvcqcRy/wi6WXDZCXxvRZyLESkEr/Tg/kdYAl3ZSrlabLt5YxpLxWtvYB+i12YT5IdryiyPP/ichVyKZXgNKvsJnldEGrqeVgGpctQgB4LhAi4P5pmrctyiKkqa2YRaSClFqD+R6KX+cvNmma6dWkr5tWyJYzijeljRCFAOiFbPwgLJkK7g5N7cUvhvhoKIs7Y0pFhrkyha9DTP8++JZf1/lHmKncXZSQrTfOILbvLB4IUmt4c7//sBB3igAfXNKhHlyiq7dGwvRSUNFfdDOM5yUWZfaaosDVWNi+ZNsT+owb4cXHtwZkQ2cuw== 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=xYH6p7zPOtqB0Zu9t/eXF/4konFwOMetgAFeUytLs+U4iGOKTVrSZ9vHW7v2ElK/Hp5mxuY+isZOsmqDxbOGs76Ilsg+ibgC1rt/25W3/NhcEEhBxfEAISMMzZTivnSWeHC82mJWEP/5matJVz1cSDAj3xrCY4XuGrAH4fl+6jo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53: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.018; Tue, 27 Oct 2020 05:53:53 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 08/12] glib-compat: add g_unix_get_passwd_entry_qemu() Date: Tue, 27 Oct 2020 00:53:13 -0500 Message-Id: <20201027055317.351868-9-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: DM3PR08CA0017.namprd08.prod.outlook.com (2603:10b6:0:52::27) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by DM3PR08CA0017.namprd08.prod.outlook.com (2603:10b6:0:52::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.23 via Frontend Transport; Tue, 27 Oct 2020 05:53:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6b230f32-f2b0-4280-cea5-08d87a3caf6c X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: o5f8VciL3WBAnqCV4pGSrlaHOM1akcHWFW8cTiWowTQA/rd6MtlDh7PjVNeizcQoBpVDXc+Xw1cn+yU2bn1NmxB2yRGzxNRri0w0FdMfRB9dztHOAMaywN3dFITqBfTNk2NLvGAuvV7jf0ZhNHUrlfFlILezRD0rqn8JuQGWEqFcXzcxNWimnz1Lq9EI3Mz3J6CFDenxbWvfo/jxGBzY5cPa2RjkgaNfF6xm5c7Ft1rkGskAha+W/itLKRV6hHKJ8ckUm9173kMfkhIowpER7SRTXPbM1tYwJU7zGMXwBzS4YJUp616N67elegDLIpd4CnyIsuN0hWX9RETjndqH8w== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: EA/stS32tPrW7J2UYr4tJQpdkQ2dYaCPu0SPNKn40vzo4cGAqy7iBigQ3/8YojeS60YpDxkfGwyahVUv3DgShpWUUUC3KGNke0h+l8UiNT193O1B3i0gPRW5LVM2r3vIfWQejHfMYH0//q85hMBdshMB6D05s5tmn0rURNhInI3p1jLpi+9hdYmMzmXD/w8eEv2ELPdQI70kqMToYgYfbZy9yYUQ0FS8j0ZJ7te4Sxpz9Pc465FOvK0nV2v4eSDQniN/iFpUus3Qi2qk4sP6Cx7mqql68gff1Y6KoirQjNI3CJpyWYDA4xNM7qfXpSeAJ33SSnOWIYz5DFjkFvzsQl/THGKqNUX8KZXGY/2D5mfl7lyPwwK152uC3il5/ztYIHSxiN1GbqPR2Zup5ulIABWQ8vD6VeqsvchDUcMXU3YV7kR/Pe3ZR26rNxWVV3nMQ5Ksi3viGV8jwDnrJ6nCWOGWRR22fDeI9mQKYb/RlvexEmcAeGpcFH37Amcqvp67Klzwf7qudCQl6DpwqQyXZD9WQ6GUA1OHbbjxXUx/xbV/RpkqersufQFTKlyawHa7bBRgCh+Gwjy81RfdFHVUzTNYkjfBrsx2OwKhjkXjNPTIs4brPP0rRR3W3/5FdhLjGV5dnQfCyf/y9i7Th3KENQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b230f32-f2b0-4280-cea5-08d87a3caf6c X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:53.4477 (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: YRdAUDWX5IImR0HqYGBn8KbDOQl9abEmKYOTfRFfv4Lp56O8qYauozQdOWWnM8qUKU4mD/jVLybgU0qBlHOgDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:54 -0400 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André 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é 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" #include +#if defined(G_OS_UNIX) +#include +#include +#include +#endif /* * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing @@ -72,6 +77,27 @@ gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); #endif +#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. Because of + * these important differences the caller must be aware of, it's not #define 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 = 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 #endif From patchwork Tue Oct 27 05:53:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859605 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A361961C for ; Tue, 27 Oct 2020 07:50:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1BEC220738 for ; Tue, 27 Oct 2020 07:50:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="B1bC+jC9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BEC220738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJkQ-0005XG-4V for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:50:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXIA0-0004eZ-UG for qemu-devel@nongnu.org; Tue, 27 Oct 2020 02:08:44 -0400 Received: from mail-eopbgr750081.outbound.protection.outlook.com ([40.107.75.81]:32774 helo=NAM02-BL2-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 1kXI9y-0001H2-GH for qemu-devel@nongnu.org; Tue, 27 Oct 2020 02:08:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ij+nHyuih3J2lY3q88sORRjamEXmqOfJUJ8ZZmLVsjbhMELB6bA7a7Sc1KVq/ZHSdeHIubh8Hiv/uMz1gKW2ayR+bs9rBNoVLse60OqG+YAyY6RnaixsgVGU/0K2S4pmIayZG/xD3FQRUOFezLc+GWCqJBHh6xYRB01rf68guTjJ+jyhQx0vCBjHOSM909hsVsV0rx3oKKj5Jq4LyxsXtcW5QSAQ9+HLVg9YGy1+RK2RJVTijVEQhUMrPumfchpzWsLvsdkQaB2ZpQ82tj2kNlBOm+Vln5u7h+PNd5jyXgs3hAHtyXMXXbEV0MQC9U5fyqj5KtzjvXYnOIKWCdHd9w== 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=U/DRVT7YUTTFAMmhTauvLeP9m7sc/3uDPVn0BMDPTTY=; b=kf3RA0XQyj2xHW8QPmmyAILEvRzc0vYrqrO6Jlpe/5V2U2AsbjBbtSJm91I31/Vwp1E5rslTtlGpKLLCOYSHOz4V3Ec5gGg6pW5S/KIw5lkXsxB5MwLZgvhfaZtFmxnzJIoZ5nFw6pNnnxThaAQUZEUznn6COG/g349VjaRymYHd5v+hm1UD7xcmLAyuOCCSzdbGrXtx6sYLrhOBOINj8G0/nw0UxMiNtSsm6M9QpQWVKEV+GFv2dKRN9mfS+2ewfdrVW+6X0WJe5P2fKtnNRRF8CifJhsumHNV/URTo5HE6rwd4O9IJW/+6lCdMsJxy6L1VP7pxXbC0qeI/zleqwA== 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=U/DRVT7YUTTFAMmhTauvLeP9m7sc/3uDPVn0BMDPTTY=; b=B1bC+jC98I+ki2aKFrI8c1YmJXZ639uz5apQxTPkA7GkzNL0FSEh34ydhZuqds8nYFDNZF4KoWUrswP/O57iOnm42j3P1hVl5sX7yvbtd25ocxQ8SEEfEpQLayM+aaq7tisvakMlkYMJw/vjN322hu0+YwV20Tyw9wh58ULDRX4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:36 +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.018; Tue, 27 Oct 2020 05:53:35 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 09/12] qga: add ssh-{add,remove}-authorized-keys Date: Tue, 27 Oct 2020 00:53:14 -0500 Message-Id: <20201027055317.351868-10-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SA9PR11CA0005.namprd11.prod.outlook.com (2603:10b6:806:6e::10) 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, 27 Oct 2020 05:53:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 551f857a-b53e-47fc-099a-08d87a3ca4a7 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1360; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h1Wn4NEDbPnsknR90gS9eIQKEQ/3D8vT5OYLeloPXI1y37LLlWGtooLH3tCG4tp/FfbSEYE3VwW9pj5d4f433V6JHj5wM3WhzRscSI9eEO+MgzoCLAUdQ4S/oGMR/q8FYyt3/1hiYfHdsG4msam45pgXDQG0eNJlA1Mo5cVe2boYG1R4tl4UkMXbxcb0EgNBEPksJEUacUldMM+TC1pDkQfQ+rcOtymht4z6ENKrXWdM70CWZTLT6ZgFsI+t8R5TYj6RnaL/Xrd2C94H7UOAqG8IvcqF8l4Q7ZvNCg3+LlstEdkp9RJyZf1MHc/dZTz5LpgECLmpmMqyc6Yug6j2PO6SlK1EaJazUC81wIPan65ATvw18TnnB7+sw0mbW21IZB4OyCcHp6ykTWyKwj/X2Q== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(54906003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(30864003)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(966005)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8s6ZvbSNjkGFvwxVMpbkzIocucGNVWwx8/8CqWHtSTel9kw9/RUAreZNNyoapr9dVpFQsLiaEqgnSUixCFSX6o8YNfV8G3igIzO8DqzZIfqrIfjH7Xt2s9VK07wH6oGplqC6ebAXjx8zct+e13/NwAPaICWV/Sw4KeQuDFMskY5lncpzBPXAjYI65dk66CUxTayxijdQDPXmJMEyQKE4xWVLEBWjOV67k/IfmzghVvXTEfJ06hyCkT0Mxbhv4IOsR+KJ+rgrGUokHLtTqTjeIiDqZpqD7lyuJaMeI4S+GReYpKdr5c9VWZ07Zt4c+Dx0gIDZ4vlSocnOgR8eiX5bPQbl9b6H0Hx7smKDpPEpdnCYxHG29xM7A2b10VmkSBSyOshYUpHKCwMAf/rS+FboWhQx3xCj01u3IiOCRKRklwYufV+UOSyLLzT4GyLuVqBJs8nCPhfS9Oz4VPFGFUUQM86clm4chNdTDbLUfyH+Ju3H6mtvRboMIcRfFNsVjqT/WDCSMZle+E0C+BDCs/9TOgok6N+PeaMPJ3Mgt0AZEObnuQoC0WUEnZZPz9966AFSOWAe3VOIxFMljiVz0ybttnPEPYiFh6EJ1bdvxYpvrPw76BYr1Ar4LvEQMeoQpt/D/8vGJw1sJsleFcuwYQprAA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551f857a-b53e-47fc-099a-08d87a3ca4a7 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:35.9220 (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: OllPmvV81/sYNNJxuq/p0BHffSuj/ESAIQZmvExqHp9XzFHBMDdq0BPClGlGkkSIo5mwL2SxuOONu+P/OPnG5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.75.81; envelope-from=Michael.Roth@amd.com; helo=NAM02-BL2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 02:08:40 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:57 -0400 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_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André 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=1885332 Signed-off-by: Marc-André Lureau Reviewed-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé *squashed in fix-ups for setting file ownership and use of QAPI conditionals for CONFIG_POSIX instead of stub definitions Signed-off-by: Michael Roth --- qga/commands-posix-ssh.c | 407 +++++++++++++++++++++++++++++++++++++++ qga/meson.build | 20 +- qga/qapi-schema.json | 35 ++++ 3 files changed, 461 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 later. + * 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 = g_new0(struct passwd, 1); + p->pw_dir = (char *)g_get_home_dir(); + p->pw_uid = geteuid(); + p->pw_gid = getegid(); + + ret = g_mkdir_with_parents(p->pw_dir, 0700); + g_assert_cmpint(ret, ==, 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 = NULL; + struct passwd *p; + + ERRP_GUARD(); + + p = g_unix_get_passwd_entry_qemu(username, &err); + if (p == 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) == -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) == -1) { + error_setg(errp, "failed to set ownership of directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + if (chmod(path, mode) == -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] == '#' || 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 = 0; + strList *k; + + ERRP_GUARD(); + + for (k = keys; k != NULL; k = k->next) { + if (!check_openssh_pub_key(k->value, errp)) { + return false; + } + n++; + } + + if (nkeys) { + *nkeys = n; + } + return true; +} + +static bool +write_authkeys(const char *path, const GStrv keys, + const struct passwd *p, Error **errp) +{ + g_autofree char *contents = NULL; + g_autoptr(GError) err = NULL; + + ERRP_GUARD(); + + contents = 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) == -1) { + error_setg(errp, "failed to set ownership of directory '%s': %s", + path, g_strerror(errno)); + return false; + } + + if (chmod(path, 0600) == -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 = NULL; + g_autofree char *contents = 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 = NULL; + g_autofree char *ssh_path = NULL; + g_autofree char *authkeys_path = NULL; + g_auto(GStrv) authkeys = NULL; + strList *k; + size_t nkeys, nauthkeys; + + ERRP_GUARD(); + + if (!check_openssh_pub_keys(keys, &nkeys, errp)) { + return; + } + + p = get_passwd_entry(username, errp); + if (p == NULL) { + return; + } + + ssh_path = g_build_filename(p->pw_dir, ".ssh", NULL); + authkeys_path = g_build_filename(ssh_path, "authorized_keys", NULL); + + authkeys = read_authkeys(authkeys_path, NULL); + if (authkeys == NULL) { + if (!g_file_test(ssh_path, G_FILE_TEST_IS_DIR) && + !mkdir_for_user(ssh_path, p, 0700, errp)) { + return; + } + } + + nauthkeys = authkeys ? g_strv_length(authkeys) : 0; + authkeys = g_realloc_n(authkeys, nauthkeys + nkeys + 1, sizeof(char *)); + memset(authkeys + nauthkeys, 0, (nkeys + 1) * sizeof(char *)); + + for (k = keys; k != NULL; k = k->next) { + if (g_strv_contains((const gchar * const *)authkeys, k->value)) { + continue; + } + authkeys[nauthkeys++] = 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 = NULL; + g_autofree char *authkeys_path = NULL; + g_autofree GStrv new_keys = NULL; /* do not own the strings */ + g_auto(GStrv) authkeys = NULL; + GStrv a; + size_t nkeys = 0; + + ERRP_GUARD(); + + if (!check_openssh_pub_keys(keys, NULL, errp)) { + return; + } + + p = get_passwd_entry(username, errp); + if (p == NULL) { + return; + } + + authkeys_path = g_build_filename(p->pw_dir, ".ssh", + "authorized_keys", NULL); + if (!g_file_test(authkeys_path, G_FILE_TEST_EXISTS)) { + return; + } + authkeys = read_authkeys(authkeys_path, errp); + if (authkeys == NULL) { + return; + } + + new_keys = g_new0(char *, g_strv_length(authkeys) + 1); + for (a = authkeys; *a != NULL; a++) { + strList *k; + + for (k = keys; k != NULL; k = k->next) { + if (g_str_equal(k->value, *a)) { + break; + } + } + if (k != NULL) { + continue; + } + + new_keys[nkeys++] = *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 = { + .value = (char *)"algo key2 comments" +}; + +static const strList test_key1_2 = { + .value = (char *)"algo key1 comments", + .next = (strList *)&test_key2, +}; + +static char * +test_get_authorized_keys_path(void) +{ + return g_build_filename(g_get_home_dir(), ".ssh", "authorized_keys", NULL); +} + +static void +test_authorized_keys_set(const char *contents) +{ + g_autoptr(GError) err = NULL; + g_autofree char *path = NULL; + int ret; + + path = g_build_filename(g_get_home_dir(), ".ssh", NULL); + ret = g_mkdir_with_parents(path, 0700); + g_assert_cmpint(ret, ==, 0); + g_free(path); + + path = 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 = NULL; + g_autofree char *path = NULL; + g_autofree char *contents = NULL; + + path = test_get_authorized_keys_path(); + g_file_get_contents(path, &contents, NULL, &err); + g_assert_no_error(err); + + g_assert_cmpstr(contents, ==, expected); +} + +static void +test_invalid_user(void) +{ + Error *err = 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 = { + .value = (char *)"not a valid\nkey" + }; + Error *err = 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 = 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 = NULL; + static const char *authkeys = + "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 >= 2.60"); + return 0; +} +#endif /* GLIB_2_60 */ +#endif /* BUILD_UNIT_TEST */ diff --git a/qga/meson.build b/qga/meson.build index cd08bd953a..6315bb357e 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,19 @@ else endif alias_target('qemu-ga', all_qga) + +test_env = environment() +test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) + +if 'CONFIG_POSIX' in config_host + qga_ssh_test = 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 format) +# +# Remove public keys from the user .ssh/authorized_keys on Unix systems (not +# 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)' } From patchwork Tue Oct 27 05:53:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859589 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECBB261C for ; Tue, 27 Oct 2020 07:47:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5205320738 for ; Tue, 27 Oct 2020 07:47:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="PlgReS2a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5205320738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJi0-0001jQ-UH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:47:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHva-00073q-Iq for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:50 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvY-000447-Bj for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h69hcZw2aYmqePSHtoGTYNgbBD0j2jo7VLI/dE3uZYgXyn7xMzPO7dmBy9XjBfa2+JtKHOCRg0ZzXbmPPqPA0pKMRluqjNSxEDGxvUxO+gY1sz85jK5tVUTgGjkWCZ0QFUnycscMTLuta7mNDLhCjN1Y5iJD0lObzUjZZ6tWUf+GKuIzUgO17Nl7lbOyODF5dHznyqkY3Dff2fL1v6p7T5mA+LFvDMqaoJspDBV8q/xm7LmHE2OrE3C1Gdu9qa8FPln9SRhEnf5+UZWNkos94LcfdWsa3kJWK6yk7gh7JReByBVXfG63VOzeipfEMps++1pEQMkz4yDSO4UlY0+WtQ== 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=PfaJ/wabXgF1mdm2K15QnaKJbXP5SUfKILqplZxVpuovhdy+fXGgcQxSQtyg+8cgBtgPUlIKS4D2Sd0V3uy8j7gt5VwpOzoLe/WTFbWNYqg0R3veHNg0gPlOHVZhnaaJuA8GBYeZhxhz4WLwU0dkdm02xXYmkspgq3jFvbSD5AksoTaWsgs1JM10+RMc8LpbVmyaLPg1dgr6qrpGOWLoHL7dxqM0I89UTOY3RuUqEAccVcCfLSADFJzGlv7vE6AUrTEcIneDKsf0CID/8/HauLNxCgOC7eMQfDyl8xv2QWODzA4qODGR8kXRxiTEoLIJuabgzhGKExM+PJ8wdRJxBA== 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=PlgReS2aQHP49gSQm/j5hgDPXsdqiWqvlRFbMx79TFa0ldTgAesZkSWt42dL7PV9HME/TFY4I1S5SBFCopYQPXAT8nXNIqgS9gUbXg1IAQaxIoLslzyxERDtlC/cV07tTWHc1LhB3igkPsDFXpDpyN+uJD4g9mVTyz6a1TBS+jQ= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:37 +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.018; Tue, 27 Oct 2020 05:53:37 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 10/12] qga: add *reset argument to ssh-add-authorized-keys Date: Tue, 27 Oct 2020 00:53:15 -0500 Message-Id: <20201027055317.351868-11-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: DM6PR07CA0046.namprd07.prod.outlook.com (2603:10b6:5:74::23) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by DM6PR07CA0046.namprd07.prod.outlook.com (2603:10b6:5:74::23) 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, 27 Oct 2020 05:53:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ce921660-1728-4fcb-5756-08d87a3ca5d0 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: /64xbMdXNuIwq1kF8bDuMeZpKA2hMImdquK6UaPqMVCQ8u0g2hYZyblcvWOjKR5LuaxsYyPT67GzEYkc8Bo45JvzGmW2LJ3w411ssrI4+6mM3zE4Hq2jrQz64Yvj6WEqECHdjPDRiAGPYvOUB4EV/aSAdNrdRLmiD46dh/o+IMlawsc2XXv432rQPdBmqOWrLKy4t2WRlvoot16CVMGuxUgvWssNcFYPg8PPhGDqzLqyK1CNR72cinV8HO5EazR1x7vICa9T9UbhvpjtyRkMvLftvaxw8QY4PcCofuDyvz/5iTBVFHoDFYOI1pH1DBTBHt6SgeL/V7qnKYQM5tzxnQ== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: qnV72S493Sslp0HLmyW0LgbbjqJnBl9uvhQiA0MEHuhQIW3QpL+rijCzf2NXUfbqXN/HMQXwvBzrUBOh5ECJ/3lhEdpY3ZI35CPsk+E/6kMGd6GoDrug1PmPnqjm+UJDqnahbZwN/HDPK89Mpem4gGpXdSVaEltEk6KZBP0IaRUmA9quArSzhQKR1/L/BMUv/IrCxYo3Ds+gkue3+CwyrnoTeI470J4/pDM/wa6oltZviEY09svbIH2cZvI3AlER/HQyvwdDYKKjAoYGa5C0R5GotWm3E4cCzog6SIyPENbfYvjitAaqbITFJB4ENmrPhKcUq14GN8ZmobBeU1Mt3jVVV9msp55K8oCl8ubDbc8EI7Ng+XGMKTPFHfRgH8fCkXBPaKepvtfJTf1IbBcx+tWJ4idQAo5ETnBfC6XCj/YK4UPgFY7HRKj+X9zTdvw6eZwjvwXeNMtYzchygHY8a+b5X+qLsC3C/OZE20x004JAw+CRn8kOsy+S8IdcqgpToWaIA4ufBmofaja+XtkGf3HbJrdg1Xve0zWXxCKWrIAnCfuOKHQPCkWATec2M4UCLDh4g2924betSbBAOrmKwd+sVznvHjC0IdPApxmyKWlf+YmZel4iHeSlWliZESZFUPNBwQkm2sIlZd+9BXSXww== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce921660-1728-4fcb-5756-08d87a3ca5d0 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:37.3636 (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: rDMPKNX4lz6wQGrBhyPybNZaf/tpQGvYEQZl5XSIYS9g+FEhHRyhLHQ+aHLl3mEhs5KnqQG2pVFh4QOq7Iob5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:19 -0400 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau I prefer 'reset' over 'clear', since 'clear' and keys may have some other relations or meaning. Signed-off-by: Marc-André 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) void qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys, + bool has_reset, bool reset, Error **errp) { g_autofree struct passwd *p = NULL; @@ -178,6 +179,7 @@ qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys, size_t nkeys, nauthkeys; ERRP_GUARD(); + reset = has_reset && reset; 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 = g_build_filename(p->pw_dir, ".ssh", NULL); authkeys_path = g_build_filename(ssh_path, "authorized_keys", NULL); - authkeys = read_authkeys(authkeys_path, NULL); + if (!reset) { + authkeys = read_authkeys(authkeys_path, NULL); + } if (authkeys == 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 = NULL; - qmp_guest_ssh_add_authorized_keys("", NULL, &err); + qmp_guest_ssh_add_authorized_keys("", NULL, FALSE, FALSE, &err); error_free_or_abort(&err); qmp_guest_ssh_remove_authorized_keys("", NULL, &err); @@ -333,7 +337,8 @@ test_invalid_key(void) }; Error *err = NULL; - 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); qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), &key, &err); @@ -346,13 +351,17 @@ test_add_keys(void) Error *err = NULL; qmp_guest_ssh_add_authorized_keys(g_get_user_name(), - (strList *)&test_key2, &err); + (strList *)&test_key2, + FALSE, FALSE, + &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); + (strList *)&test_key1_2, + FALSE, FALSE, + &err); g_assert_null(err); /* key2 came first, and should'nt be duplicated */ @@ -360,6 +369,39 @@ test_add_keys(void) "algo key1 comments"); } +static void +test_add_reset_keys(void) +{ + Error *err = 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); 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)' } ## From patchwork Tue Oct 27 05:53:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859603 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDB3614B7 for ; Tue, 27 Oct 2020 07:50:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98B6620738 for ; Tue, 27 Oct 2020 07:50:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="1o2qWm7+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98B6620738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJjz-0005Dk-N7 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:49:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvd-00079D-T0 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:53 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHvc-000447-DH for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GoZFOcvnnA1xSGUXzSLZAv/0/hnYQ27a4PYtykgnmbzmSXmVqHIl6Vxux3sfPUCB3EbK/f6Rp6IRGvWaBFoZaJrehr9c+lWMbpI6DvhiKQaSdJ6WTItND6jKyPitXduK+8filsNXff4Boxb0EN96b1Z6t0GdR29x8fF5qSYko/3WyUoVd3yIUUH7ccyZc83/cVTjvs7ozhZiKh0haWBkezVkJY4TA47FTgmCbbZReIMJsrKNciZ/O9CucKx82LVkg6jiW0hG6xtTCDVr7ECtFLBF1cA/KKMKN/bnF3ns+ddm6rcth3M4itkxIIAzJWkS2UMp3cPk/FXwV2UWuhxj6A== 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=VvURRAXY6tCDaFtyipFewJM06PhlZ7/CBjX8k6s9Ugs=; b=S5WBTjuC9JdiTxkIo3X47doAngKiEeSkWGhc5TQyH4HxKmPdfVmqs+a8QhUzAXOX7ayxnzsHuhQEOnaKXZNHpe3Bwv24xVCIJIRecavXHbud+KthmGFHe1Zx+1s4azfpOg2eFAeLQFZwevFJ4FS9Y6QrA91OY8hpWvbS4LPv/Q0clu8BqOt1phf7RzWlv9iPetgmYCC49ViaM87LZ4Ee0FgghLieIpi4PzDracDzh7jILyEQ/1f58GHz6p+jF2xuC4T9kEhlfPVBissgejULeBD73pd0qmUylJIDNsZ2dfOSnQe529G8ZAYlNX+ll+oS212lwOopvgQfjQyQrCAzIw== 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=VvURRAXY6tCDaFtyipFewJM06PhlZ7/CBjX8k6s9Ugs=; b=1o2qWm7+/WxHWJ7mylTKlLdsSexwZOinNqx6OxTovJWukTGZuLSfNfBwF6/mykIeoYzh5RI6D6qUkGGvUqLH3VWCdv9LWHcqH2xA3jJii7ggWu4ak/aYwltsTEFiDwp36EGnoenDRr8WCc3TX1sVBSt5QemX4A+QOCM8z7wW1Xw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:40 +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.018; Tue, 27 Oct 2020 05:53:40 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 11/12] meson: minor simplification Date: Tue, 27 Oct 2020 00:53:16 -0500 Message-Id: <20201027055317.351868-12-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN4PR0501CA0029.namprd05.prod.outlook.com (2603:10b6:803:40::42) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN4PR0501CA0029.namprd05.prod.outlook.com (2603:10b6:803:40::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.11 via Frontend Transport; Tue, 27 Oct 2020 05:53:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: da175b90-e27a-4813-7493-08d87a3ca7c4 X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: 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: djRaNK5tQVULPT+CQplKiuT588oX0U6K4k+jN2UBqYJSm39Vm8a7cap0T3dyKQFf8rrGxN3SWNFmEbv2O1ry2DmKWQ5p825PWuVMI8k9DasA1sLd96dEP2j+mEQx9xrada6W0EDiRI4hM55x3v1V7Iypif98bUccuKbaNPp5Qx+8MpQNhXK8v5ZjvgTYY42jOwu9+2tXw9w0O3sz2xXfrLrN4vYvJVlBulXeEswljkBSq/CUDWBnnLcUkdoI/5dY3/D6FZ51WCFXaKyD5xSHWV7zTAGa/k8cX02xlwJnxEJ6emhvpA9CPN8mkJ5FsQYFyPFFeHiE5d2ZzFF099zIkg== 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(4744005)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hqAKr42VqKxVFpEjkN1Z/rXgo0asRgcP/lL57xv7V5E65pedpZV1m5bExsYbxO1eM2zFYlsor0Dtwc/4xDXYWtHD+aMlFb1noM6KZpOVG9r6610LWkBCAyFqI/2bzVanShH+KTyRapq7t9z0nMWRC47tpEsFrrZeZvWTJ48ERlgMj3i+5qJHAFyBTupidGATNwBsrKQHlgj9C1ssXPH2oRQg2ehshGbaVKN86vG1vDH9CW2ZtSAaD+CxyeSKU74Qn/wgD2pSXB5m0A1LIe1zn9VaWpj7FiAU+PfK3JWwX8isrihxkT3wQFiHZrGFgqEh7uaAKUERwwkfrJHvMT56lVCJAU6MKl3OaQA94VaesoB7fg1m02bEyW+ByVbQ1ScpH/i1ASfhhXOugbrLJ7pbAyfCpvBiI6VyXhuDbiA+4wXp2Sm4awTVcQoY4DB8BwUWlAq1OUrFTqyGAr3T5d7AQH7MYemSx1q3xi/zc6cHtS417zF49ey7B8Jba39OQRiWQn0215d7sc89CKcnhXPuXMI/VjKuRnk9a1KBFIyxMI5scuHUbkNw80cB0e8z6xXl4S62uzCleN4OoGU9gDvzNkJTeEQu4x3lGMJgC8nbGQzJoY4G6zXqsIyvAfaG702r6myJGwsmNBagpzkelxwJ7g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: da175b90-e27a-4813-7493-08d87a3ca7c4 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:40.6481 (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: FqgtJ2zQ/Mqg5LG88BhJduWXgAaAa8fjM4wG4CcjAbLsJwFZankqN+mVY8VuA4cnIYoBGOmZB2xwKCkbEqBodQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:32 -0400 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André 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 6315bb357e..8340892139 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -22,12 +22,7 @@ qga_qapi_files = custom_target('QGA QAPI files', depend_files: qapi_gen_depends) qga_ss = ss.source_set() -i = 0 -foreach output: qga_qapi_outputs - qga_ss.add(qga_qapi_files[i]) - i = i + 1 -endforeach - +qga_ss.add(qga_qapi_files.to_list()) qga_ss.add(files( 'commands.c', 'guest-agent-command-state.c', From patchwork Tue Oct 27 05:53:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 11859601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64F48139F for ; Tue, 27 Oct 2020 07:50:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F165220738 for ; Tue, 27 Oct 2020 07:49:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="AaOmG6/9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F165220738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXJjy-0005Cq-Qn for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Oct 2020 03:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHvf-0007CH-NC for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:55 -0400 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:55041 helo=NAM10-BN7-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 1kXHve-000447-0l for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:53:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ETPnDkcE+61d7eljE4gwzVqF6HCRGg0grV6//ARpu5SvYakXJdWl4oQAj0LXRG2ofjXlRiT8exbPGvhhjFYEaadcePBhjCEzOvWz7rG/xcHz5czM2q+oSuBryoOsKpWsxuXHcFqtkmFsM8hT5TvgPvj82NTAVpZzPdvXt7rslQvflGZaokVLc0AMORopwnQHQgGDCSoIdTna/VRBxCkRBQqOZ919o603xEDalunvnO0YidSXQDRkFx4zuLVk17kMbUeFZgDLMeH4aKtqjWS4OQaBotiGot0uxjHE2XxdQS6cRRavFaADCndTr7oY/fQhzTYJH/kRZDFwKzByRjKWKg== 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=5vOCkIJkfN5Na4rMWYOwTpob84gyCO2id/T+cDNGFi8=; b=R4ti2aErHnAiMvg3QzD1HfrdzKIMpTvDPAUbTWtXFEj2tysXkDH9EwJQQZ2NMNFxU5KcGfc9hUYFAdzW7I1vpfqvEUtJwITF3Akta7/W8OE9XxL95ioDNhWceyCTWDtPzG82eMnHsPKBKbqvu1pA6rbf5ZS0B5jykgfgTyWJHsqFBJd6aBLywnYzbLonyKtdZbGt//QA3lVupxeuckCIrDuwl4z3aPDyjxAdo74Kxi7AJgShRfJ5m2j5ricifilTDn0VFupBN3GW0GCSlV5hk739QExrzxu6bPd7NlEG9Emj1HXMy+pgQ6566mDBsBnbGbGLYaNQuhPw5puoCz2Ihw== 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=5vOCkIJkfN5Na4rMWYOwTpob84gyCO2id/T+cDNGFi8=; b=AaOmG6/9IUi4cXkvt1SnfrETiAYlnEIMFOV+mTs2qlcMYOxddI8obU0csbWzJ/4grVQqj04rM86cQ0sKjcY0yUwyzuXzXYOxB/0+NBELxXXqa1UpRpZkRz8dBync8WjmQqwTNSA5v9XWQTikFknRZMPXD+EYfvy7WFTz2Mhkv8A= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB5004.namprd12.prod.outlook.com (2603:10b6:610:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Tue, 27 Oct 2020 05:53:42 +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.018; Tue, 27 Oct 2020 05:53:42 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL 12/12] qga: add ssh-get-authorized-keys Date: Tue, 27 Oct 2020 00:53:17 -0500 Message-Id: <20201027055317.351868-13-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027055317.351868-1-michael.roth@amd.com> References: <20201027055317.351868-1-michael.roth@amd.com> X-Originating-IP: [76.251.165.188] X-ClientProxiedBy: SN4PR0501CA0028.namprd05.prod.outlook.com (2603:10b6:803:40::41) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (76.251.165.188) by SN4PR0501CA0028.namprd05.prod.outlook.com (2603:10b6:803:40::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.9 via Frontend Transport; Tue, 27 Oct 2020 05:53:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 65ab5166-2486-433c-5eec-08d87a3ca8ab X-MS-TrafficTypeDiagnostic: CH2PR12MB5004: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DfppJNxBhU8Yq8q8nuJsYRmck6ylK5CaKpy+dxPoKft/VQeyqRP4Qvs1RC9G91av+CEwvCrvv4RrKEydAXi9TeLGhDo8rvhDI3A+hieQbRiTLhAxExAlW4aqEZGH8OEVDmWJ9o+FUgSV5EAYzi1Y841cdigYjXimG0r1V0etbStc7r+94/3uzorehpPfLsQLX7dVU0ZL9Uk80BFqAzzf9CRR1gqOSUBkKYzGrH04qsbvnMsPN1zCnb9Gf6Nvs/6QARj6S+kUWURN9VgBv1hdeJUnrRDfx0fj9CW8E7IIz03zt7vx/QeqP5rjgMoDaEzK 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)(39860400002)(346002)(376002)(366004)(396003)(136003)(316002)(956004)(2616005)(1076003)(8936002)(6496006)(5660300002)(86362001)(52116002)(66556008)(2906002)(6666004)(6916009)(478600001)(66476007)(26005)(66946007)(16526019)(8676002)(186003)(6486002)(4326008)(44832011)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: orMGfsyf70ogANhIwsQSfR7GTwCBjKN7HLCdEA2S0YhblMN4nrN1udgarYgJqmbX4jxQ+ZPT2J0V3UAZ+1LIK4Ojko5Ntfrp3bvNoakiL4dz98vN/B7K5kd2CqiN6gSwdIGF630bOB3rx64pgsjz/0sFSK9yCKcp1Un4tLDWgKgN6ly2WWHx4s/dc2qfByF3trJoc3p8Af/AalSKvc4n6fAEJAxDqu/la8f1wp4Uw1ox5jdjFQdzAbhjWxZ0WP6Kfvcq4L9o7yl0gL02zSDtT7qeHEJKqeRizPZQxRyJDPvmhBS4VDlkQzqci16yOt5vyukfgyQsAuVeQEEuO/pXjJqeRh8NGBgLRdrPqwB0nzq4Nz+qqrAV5QHUMW6tlqfqi9LwZQ4OsoWiBM7KlXHjD6URLh0QBlu5bHOvxEM0NRJF6CAE8EO87UjGSdUta+jYxYpDbtlVrE0Lfg3GHSkg0qPllrILLnAFruGsWuJZGyVHjckd1bEkXc3Q+i1Ag+LjYIxGWvzohtM2b7a+6zH00rpuP2ZSOZI4l64bTKG7uY4KPdiEAljDneai9eqzTTLme56u71rqlKA41gRu4eUcIWfmMU0y81LmzRBvVSgfvITPztNawR8LpcDMWnh8xC8kjqBlKg7Ii2hsp9qXKzGeXw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65ab5166-2486-433c-5eec-08d87a3ca8ab X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2020 05:53:42.1644 (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: FwPH/SzKMObwaqw7CdmwP76JNsbL4YV2/ygErFZ4xySnMIrtshe0X5eeNry46tEAIkXyIrUwu0uMUYqOSUsq3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5004 Received-SPF: none client-ip=40.107.92.50; envelope-from=Michael.Roth@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:53:47 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-Mailman-Approved-At: Tue, 27 Oct 2020 03:46:40 -0400 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André Lureau 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 *username, strList *keys, write_authkeys(authkeys_path, new_keys, p, errp); } +GuestAuthorizedKeys * +qmp_guest_ssh_get_authorized_keys(const char *username, Error **errp) +{ + g_autofree struct passwd *p = NULL; + g_autofree char *authkeys_path = NULL; + g_auto(GStrv) authkeys = NULL; + g_autoptr(GuestAuthorizedKeys) ret = NULL; + int i; + + ERRP_GUARD(); + + p = get_passwd_entry(username, errp); + if (p == NULL) { + return NULL; + } + + authkeys_path = g_build_filename(p->pw_dir, ".ssh", + "authorized_keys", NULL); + authkeys = read_authkeys(authkeys_path, errp); + if (authkeys == NULL) { + return NULL; + } + + ret = g_new0(GuestAuthorizedKeys, 1); + for (i = 0; authkeys[i] != NULL; i++) { + strList *new; + + g_strstrip(authkeys[i]); + if (!authkeys[i][0] || authkeys[i][0] == '#') { + continue; + } + + new = g_new0(strList, 1); + new->value = g_strdup(authkeys[i]); + new->next = ret->keys; + ret->keys = new; + } + + return g_steal_pointer (&ret); +} #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"); } +static void +test_get_keys(void) +{ + Error *err = NULL; + static const char *authkeys = + "algo key1 comments\n" + "# a commented line\n" + "algo some-key another\n"; + g_autoptr(GuestAuthorizedKeys) ret = NULL; + strList *k; + size_t len = 0; + + test_authorized_keys_set(authkeys); + + ret = qmp_guest_ssh_get_authorized_keys(g_get_user_name(), &err); + g_assert_null(err); + + for (len = 0, k = ret->keys; k != NULL; k = k->next) { + g_assert(g_str_has_prefix(k->value, "algo ")); + len++; + } + + g_assert_cmpint(len, ==, 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); return g_test_run(); } diff --git a/qga/meson.build b/qga/meson.build index 8340892139..80e7487f32 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -90,8 +90,15 @@ test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) if 'CONFIG_POSIX' in config_host - qga_ssh_test = executable('qga-ssh-test', - files('commands-posix-ssh.c'), + srcs = [files('commands-posix-ssh.c')] + i = 0 + foreach output: qga_qapi_outputs + if output.startswith('qga-qapi-types') or output.startswith('qga-qapi-visit') + srcs += qga_qapi_files[i] + endif + i = i + 1 + endforeach + qga_ssh_test = executable('qga-ssh-test', srcs, dependencies: [qemuutil], c_args: ['-DQGA_BUILD_UNIT_TEST']) 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'] } +## +# @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 (not +# 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: #