From patchwork Tue Nov 3 02:43:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=grKFi/Ea; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDkt0PgNz9sTD for ; Tue, 3 Nov 2020 13:49:10 +1100 (AEDT) Received: from localhost ([::1]:42770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmNg-0003SY-0o for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:49:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJn-0000mz-2n for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:07 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJj-0007gm-Gr for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:05 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GpXZWxQSB8tHyeSOA1YWlTLUcRDGJ6/gt9wEh3JtRpaFbFdBK1JQpdNttPcRk9Uc2lqUW2tQvkz/O6b0jx8f5V1qtCOuc8idSNArZcVMxiTEmG0YOZZ42BrK/owzehTdvoASx0KCHHddkPM6ye4QuEFuZh+sCjPUqc3YAXdSn3Nvychg1ejxxchP2+jiuGVs0wWz5BxVySPPA+HwGR67SVRg2DtZ91eswFqCp4e8JwquQkMF7oe2FCX39RaAss7g5uK49xbNk4Yytzk9oyyIv4PbDa3ytkytN8kCBhnFI49HkEUZgzfsJn2u0iCNQkV1w70tW6S4AQR0XlnfiEx2Ug== 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=MF8uJHV+kvQdtUUN80DCojNAYyI5id7fHEdWb+4CgOIm37NkTIO20EB6TlTYAByaqfzJA6wI4BZsSxLda+h8usaU39Ye9pivCa0EMH1sCpo2hAIa0l8L1x2udT4uah6p8lkeYu10+ogDYPdYlHmK99PQheb6MH/5rUXSGvNb8mnKHsysoQsPMDCLFOxhscFON5uZWnB++nubqwinvlY9XjgTEyScyW73A2pvlXdJ5BHZEmhPxAMlLkCS8/Hq8Z9qLd5F7ogWk8oTZnuzJphQtsnf5x9VKB0+51aGqixMIYW1NM7nhGdEGm3aEAjy965Cehzbp16VX+B4apV4iYDlTg== 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=grKFi/EajUKDGR8/SNfZTPZbiiqyD+w5K03Z9ImBKJMWEXNaAUUdCbWP0tnm1LevgQeGGLGu8Vnh6Iy/fDU8hhQ1d7fuSlucm05NFETfQPE/7iTz6jtRcg1mpxmDa0kmULJqBQbE1uaukXO3oL96TjLbHnNHoubSDCxoXg3LqSc= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:44: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.030; Tue, 3 Nov 2020 02:44:45 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 01/12] qga: Rename guest-get-devices return member 'address' to 'id' Date: Mon, 2 Nov 2020 20:43:33 -0600 Message-Id: <20201103024343.894221-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM5PR18CA0084.namprd18.prod.outlook.com (2603:10b6:3:3::22) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM5PR18CA0084.namprd18.prod.outlook.com (2603:10b6:3:3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 02:44:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a563f12d-0903-48a9-a170-08d87fa26c13 X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: OuDHr5LzKAxszBHdSNT5aPNk+mjQl0tHN9KFE36adNE2pq7wwG9xqTg2llk2FcRmAviVMPclk6xf2oNbKiSqUn3QlAhQ3XFLPIq24Jxetg00D4bsAh8fOU5HtviihkNs7pT+RRpY2EByLtmkuUaMGwqUiNvbSG55fQHOa1UhDtmkPfKzh+UPGRKwq3/cwcSXRf2TrwHdDGkrJZwcgTD5cnYWk9gMl7fCfeFa7CXYFdyZ2URIecaA0bKODHv1sr0Cu0TUWALC418Vs1zSqLNdGJj7szOcigQQE1qRuYPssK0F9OeHykSyUP2inP1zx+nxfx8MrwhEy8HV+9aonsj9jw== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JgHDInxqoDjZYve+ZIXvrjxDXgTPNv4HlkK+myyuhd1eKhc4PxlT0i01m1SsdvwB4qF9v4CZexOuxznhsiPPJgJ8OahruoZOOa0kU+t/D0zxr7aXUv2hRt+mwF3ygnxviSoXd0ztSkWyfWwsjgQqQsniPW75HW3IQWTaFgr8VM2ahBnvMq76d49Ef8OXAZv2kVjGkAzFWEfzfQxLBfVl0jnRXbe48hPDzduDtj5iXoFMukppMmYlQgbFPrHcLjzD6hEAIl1dAs9yBDkDk4uT3rYEjcNM4/nkCHprTi0h5GYxhAoFw4YfqQ1sq4FlaHqvaCkvzkJ7xOX3UDGlKJvGUtAaX/LStUYRZJDAKczsmWEdJMnsv4pmdjgLNTt9gcRxsd1HxfQByOWGyaySrAcm9UFnvQKZWn+RBhOEJKQmqWA+SMuL+uil3nXbofHH/qjrN/ihbMl0u+0aJPE9/+xsmd8awLjzN3bY+fFn+lxwLvbXlCWwVEE7Fimf+8a7GwKa4gUPj0YA/0FUtHSLkg3G/mdSZi+L7TQikz6O+RhhyVp6EwMAwDp/6TTIZhfFhC0nGi/aC8YM7dcor0GbPhqdj5KSYTDg/k9ZJshsbyO0BsyhJgcimddGK8y7xH4qK+lo2xZFnUSFESGQh7EENsg+GQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a563f12d-0903-48a9-a170-08d87fa26c13 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:44:44.9502 (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: v8W7FPWN9FcfigvLbVoQvknmKs/LnC4nkCYlUB4G3f9roa+ZJTFJUVDxjddvyUn8aU2ao/SL2l1yYHyawYfxug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Nov 3 02:43:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=hGh/C65A; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDsc3mGmz9sTD for ; Tue, 3 Nov 2020 13:55:00 +1100 (AEDT) Received: from localhost ([::1]:55066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmTK-0000CO-HM for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:54:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJq-0000pA-Fu for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:10 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJn-0007gm-SM for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fOZIUbdS4xo0oR3AZXlxIE8sG9Clg4sh1sKoOtMpCPuz+lGKEx2iIHNbGT9jGQj73WW2pWw7QtDzc++9+LILQB7vRefs8yggzhQrtn8G/oYsO42GjJfpJaBOdFW5g1R9K6rTpZ14ipdqSQwyzfNqRSTHJToaeB0iwFg4yKIrS1+jTYG9SvJUI6AbeetR1K/DrZK0g+QiM2EJlJ9Oym99Uzv/9aKrb436SmROqB2qQh2gZqCJTcVxw8/fmAn069bz46YM5qAlVxudVMsAtHDYNaJZWCDmqPQ6oZd+XlYFfe+iwhpMtpnPZQ6+QCWcQtTCOInFL4OW6hs5KQoScKycJQ== 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=EWnxPX0d/IxAjiVwypF88Sl4RQyn52FlNHa1l+80LzqmP5n0q+DwjxZo8dJIugApnZOrMjLMS1ojFtvKVmehAj+R6EATBt0FD7kLxqmB79NdvLqBMB7ciOTKS9h14aXE7r/hC2qN6arvzmbayJ5eEwKbg3dcReF+WsXsyCp4eSBOWmjivDwUm+i7EupJOC++Byud6sk54OnOCo/vfjkShOycAZOmlH+SJKiyY5RQoBGJH69aXToWNdF9dLjwdz2GxYejo9iXNExBYU3lZ6uDtsnnAlGxJn0h2iuGZZoefuNwmoC6wJ91dbcY/mMQ1c4/JNYaSdG9QCIHaw3vaKwC0A== 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=hGh/C65ArQXQsVwSdy3H19AbAtGM1bw72L42DfDYPx/sCZ8GsuDfeQxFxqpbFtJPZ3gvLpZ3nIqRY/GCYQkerlH6/6Cp5WBILFXm51GE596sfG1mtvnPTyhh71rRWy8+8aoPaCL1Y4Md0D6U92RM1cdWDJs3ShIb1a5QGWhb9MU= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:03 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:03 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 02/12] qga: Use common time encoding for guest-get-devices 'driver-date' Date: Mon, 2 Nov 2020 20:43:34 -0600 Message-Id: <20201103024343.894221-3-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM5PR18CA0079.namprd18.prod.outlook.com (2603:10b6:3:3::17) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM5PR18CA0079.namprd18.prod.outlook.com (2603:10b6:3:3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:45:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f199e9a6-2bdd-4978-7362-08d87fa27728 X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: vxK1Wm2MPDL9t7caED1bd+H2kbz61M/qHE2rUnDLDCpUc/X3pTrx6laHLnWczlmpLh0FNTG9CmPQqvXYoLRXOEPKHnOKFDNMfsjXcb764rC0sr1FMEZQVEFQi0rgiwoOA25GBT/TNoc/7mL76GroJfzeKLtm4AZxDIt4IkkGtkLF2sAacsSb9tc94KkhM0tkyBKykzLlsisu6IPyxB3zeZBM1uIVuSuxMLbil4hEtDPDhhB46QcQeBAHjdL7XLQrg7kiCsrPlQtkBCtZifmo030GqlQrmnfM1TalwqgcaO2RJHfLOL6oF3MJGfYUNuBYqW6KkUygYCMQC2ZQ5+zagw== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lRPv69uxN/avIhEaFkUgkrF7HIU58tORi5OkOOZAuH1nuoV8FhcB4wjy6Xojv0e/3X0aPb+9LoyoOwJ5Tm6si2mKVOCTVZCvIKnNGkTVbfjxEMkzbidubEM9tWebxEQ2JFSodsbzc4ZW3qUTd/k4/VByYW6NpzkAoZLGhhbuufUVSil4mMUZ890ktOt67pNugjzx7R3zFrrmOLLgGUxroEb23GPboL4VgYM/6BpX0ftZw30D9Vk+WtVnZW1A0VJ1d9t4Gpalmk+uRTQbNBqrecTLEu3gjwGnGlgniLiCAZViTx5xsY0J7u6ueYtrfli0ZK4cnx720jJ8inAjwXkuNCVZ9DtUIKwOaEYx3k/Qw81x0qCjOEbKY4Xdy88h4Wh60H30Pm0cp8OL1gUxUzXpxT3viH/oYjrqLRJz5QFjiPij2O2LQNgOLuVlRT1AnP4N/bKyhxfNxfgdtSmhfmr/ypfc6ifN0WDBie4yVKWiy0o8xFpDyh4iUyKcc0E4+0CjgDK5sXMpHx59OuSSqFeSeMT+Mrt1Qrdw6NmnESYZG1DfV2u40Vij71+QsQ0zjC25v4jMo5JXaWgaIMzsO+Q4JDQXO2lOhxg48MGCoDS1QFYWo2hMaV4/jl4R0oIhlIHdkxeDQZZN4Y/Y0QbKvckYPg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f199e9a6-2bdd-4978-7362-08d87fa27728 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:03.5545 (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: CvOIbANsVO3mZOpatzUfBTMnA0eu3vkYenwCvJ6U+tqTfiwRuWxMHdmowAgz4sXNvjPWaPUP+eU2BVWHfASP+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Nov 3 02:43:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=TIJwx6HD; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDpg03Mwz9sTD for ; Tue, 3 Nov 2020 13:52:24 +1100 (AEDT) Received: from localhost ([::1]:49064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmQn-00066Q-NG for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:52:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJs-0000sd-ER for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:12 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJq-0007gm-Px for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FdrdTrHXkhiLpOegsCIhAYtjf3m94b9ji4JvAaYCXElqYiv7xCVRMfzNfQi5+5vIKSSlW2IW8BEw0sb7H9JRBuERuv9JlLoBboJjPBekRF+8NZoEcLZ3DH7K7GbHzhWRZEqqmX8oGa2ZDN9wP94umE6q9R5ewRr7K4UeoFs7rfHPvqOKjqIU7plUxBi3bYclYEqTgyWF1xGUcjfVqbbLmbblvW2/QyOOOYl/DG1PlOoTkB1yBGfelmQsyogVQhALlxUl2Dl392t14rJntct2ZySUPbWqEGjTRvizzdcfouTir++n09VcVnGzOsknSKv0jlYYt2SGH0j7q7Cx3zsbxw== 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=K5X65DiPYi8QRL1OzvKEi3bge6PulJ74X63qH37ukVP62OYQss48ZVmyDWjrcNtsAWpYjIBPM4XnVNd0uVAtmoIXlEN4mCTwQ+EOn7wp0rkUC3LYu0CeCPvYDqQjMdzGpwi8x3qkWgNaeGDnC4My9gas5SyNslgIhmTWj/pZoprzNzTbzbhkpHhR/lTCS4u3mbMBGTUITFMBIYnmJhQ/k+Jy6GsXhckbM+1tt/EoY05tr5hsKLZ4+4mqJCCZ2xRAKoILcsvexHYdCIr1UnFnDpnmkvRoXcbbr2B+MlpMwk8r3Eml75eb2W/P1xXyHcNh0YUzHK3VL+vyi95GEIcaaQ== 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=TIJwx6HDzeSXwmcFcXUamek1yIids8qt8/hdwtoaTbhO18OoHlZX39Bicp9FNytECafdtHA6njGI5C+NlcVwUyNxdiE4xjTyfMewL7n/yVJAeljJw+SVSPCJ3APHeyVltetwc+xHcrZkmhCJElXdDG5AU/mwHWdv2FkTtxnf33A= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:06 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:06 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 03/12] qga-win: Fix guest-get-devices error API violations Date: Mon, 2 Nov 2020 20:43:35 -0600 Message-Id: <20201103024343.894221-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0501CA0070.namprd05.prod.outlook.com (2603:10b6:803:41::47) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SN4PR0501CA0070.namprd05.prod.outlook.com (2603:10b6:803:41::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Tue, 3 Nov 2020 02:45:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d6312fa0-85e6-4f76-9825-08d87fa278f6 X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: /qroMHNzFJXn5XshgiiPsYybM6YGdombIzd5ne4maAnVgSzJ3zIts5JWKg2JwtzCfBcuFPdpmuChUegwAhMz9jsYzIVt/Gs6FkZ4RRju2fLvoCmzi29nM8kXxX6I/6g0rxS9rn9jC2SF+U7DP4fE5ECo+FCJpbJkjUsICFBEOEOPH1RCDADBaGNqXhcDr+rCqAE3tts4KTs071/z+279EvbvGViLdpLgFuWS45SnHwvfH6dHohARzM/9jxrxaOm2syxDVq6049Eqar86B0/GnTlf0v2PfZ+q7WS8kcqRIqTcpAVyvSweH/6+wfOab7So 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: xlttWwYbdO5gjZz49GEwXfVhtACLNpWnskV3Q2nxsKgmWPakscgCAYF1V4y3ysUnKVwGIQTotak0zGWgLA0lReMYzNtzdyuV4beO8c1Sxhxfq5kjxY+T5MCYvs0ajlLNMlFDRO4IeWC5SrS4oMKXYh/4mdny0QYtrF5z+mEpxTddmuasa3romJyv2JfiMn/TEzDRdkovGlwGK/AA4YSkqKcbU89wHQRj6SJpb3VvxrjZdzPWiy35Q/Ml7QAPoh9fmWpz3Mt9c18dye0oPmRfaY8MQweAmXYDsqr6LyyaawoB4ZfxdYsBmsT5VSeO/Jb1YCK5nZIgaW7O2abrtjujSyvgak71bJPFGQCFzmxApb6RYYtnhs0Nx+WbXras4PzsSbtlyRvH/wfscJ94fw/d8+dNbaJMQ9b4imQZ1okqKeKVlmDC5nym97pwTT4F22S/wUr9XOLty7J8djDMdTfORnPrPA6HwxNeBRnlXqNl7LRfnzvuxeGpAZ8kXwDmpmTPyKMUK1q1mUH2GR5a6mfJMe45yH8dYni2p2ls58QeaTz/kkUwb29/eFN7ghzStZX7zZd4vWLlp5Y0TmaXPzqwI6pF8bo1Tr6EzzKzrvXfmZpnW/L/LRyR6Gn0r1waeIp4XwtlZFo4m+YDIxJSkAElBA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6312fa0-85e6-4f76-9825-08d87fa278f6 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:06.4806 (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: H4CYyFUhJAslXEH3yRUi3yb5GIBqEcnzN6IJWOGlB7pyejv3BWqFR8a9XQq1rXia4Aj3So/+//pumheUTIaEhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Nov 3 02:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=1XR2mZwD; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDrm4q94z9sVM for ; Tue, 3 Nov 2020 13:54:16 +1100 (AEDT) Received: from localhost ([::1]:53562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmSc-000800-NI for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:54:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJu-0000vS-Gi for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:14 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJs-0007gm-Pf for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LmPdPSzqCGGhAN9+QplPYbJX9v6zyPRDNOM3RkYRZp41XpTjD4Vvx+73oLr1R/HzKrLNfb+/4so0KQfd+WaT4qi+MxIpSXa6GDSb6aV/7DFz0YOLeLpr+pxL9jPbj7kpJVqm4PZyqR7xpwwwN8MW6cBhu8DjSTKAWUbpz7EiJPKA0/wZvKOGfCwpIVfsKRCy9YAaFHvLuc1SOoNd7s/Hyzzd8y/rbsnMbFYzJt0qrnfkomyZxHJOv9+49U0HVFMHUqpcMH5nUvRiGH/GaJ/R0eyLdqmpAUNMgJMraHnro9V01k/jUJ876jhOFT8+8bP+ABmLUHbkn/XuhF6RafWmdA== 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=bwn6PLLZkrfdXgLMnjFTX41O5R7ciuX8VOliBWmhsh976TBQiAjBtAGbMwD418P3mz6hiuR4Q/DWdK9RKRHFjjxcHtWNsB3NXvSUDeEMPiyOMhiTiZBLXyCusEGtTKEs0v43m22KEwEWYQ58xcut7tWdMYeyieH6YqDkkl+r3KNLUpO505xmil/Lzodb7wCrP32XWJKRa5yhx+3WZrTih6+Lte4R7RIdMeo+9NkaokK5Bel6rre6ElT4/bm5deZdCQ9m/UgKtiXPcgZs92PrFbh9n81YLewFxXPRz4OW6VXwzq6pKjyEeO2aWS0M99idkn7Yn+DxSGoRKv11KBRlgg== 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=1XR2mZwDJnuSjlYGwfrdwLV8Pe5Me0W0d8KkwdmFkMXvGUhMJUCsZjyY+WN0kq4NbxuaqM3Ydncl7fHNwpvI4ZqzHNDFErZONIuOm8g9L3ODjjBKlFQZFd0tzv3YgdkETbePDM+OZYtuFuZfFaplrEwVNiGQZw/Fd13JLue2bWU= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:09 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:09 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 04/12] qga: Flatten simple union GuestDeviceId Date: Mon, 2 Nov 2020 20:43:36 -0600 Message-Id: <20201103024343.894221-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0401CA0001.namprd04.prod.outlook.com (2603:10b6:803:21::11) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SN4PR0401CA0001.namprd04.prod.outlook.com (2603:10b6:803:21::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:45:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 252c55bf-7e1d-462b-5f56-08d87fa27acf X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: pyt0QSz+5ZaCSAqTt+cdp56A1HXgiGIAJXHybsaQvSso3NYfGHA210Du6awWRW/NYkqRknG2WJaKn1leVsToVXu8IyYqo+ILyFCha56uBfJhpJQbmiWZDa0s+h5G3PsQjFIQo6+0S+5V2G3OjCNfXCq3JieUFAOOdmHlHaUvzKvMHc7/fZBi6AJ3UoKNjOxuO0RzMZqLBBfZ7aY0GONNNLGBL27Fmoe2MxEoEozoKv3v9sCRFa7skhPgWIvh0QSPExFiR2WH/FfkLlya/nTaNdhV70P0IcJwxvlU9qv2DT01TjY0ybvh+Ht/Si7sob9tXZclVBvRsMmyRGI8uemDGA== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mxM2SpqMY1w4cziM8bED9lrPgkqE4mlam6u+vCz3UzBITjnl9kMoNVnjEpwiwJEYcTht7Zsik8WKutDPS5vo9J0UZWJ/VbxdsvZHJ0bVpKl1b/AaROWEr7hsINqkacYnk6A2p8DPsHegv9yyoK19dXrOMHK0cYkRsvfSaTEKIJ8tMFNo9gzVGcGnQH/oDr8wiiPgHnme1b4ewbGcOg/xNsXor5p9vPvIJRHDIIcIUaQedWxOIQm0ANbVgI0UZkVc2slGYvU50DIxGAT7nNqaTZq+deEjuriib3je6JVg7XiYwiscBWfn1SW7HjTvdQZeJu6K1NX73GcH62Bd0USAfBgFQgjbaZApk0KYx3mwmiRqERam+nhLnf7Gd4XIudCO6FXOft6Hi7w2S4dbIlT0p/Z2G5EyDm8GM3A9DE3pg1dDt6DzNPwWuilwvSK/c6+7K8IU6w7BctiBjPscSidby8A29IUUZjjB65UCtuaxzY5706F1c156//rOM1PiRVu2mMiJk4uqyodT9HwxIPcG12Gp+V/ckw/T/ZSLCZZWn9WLm4bUmK8I9xuU162HSMLJI1QqxmKYtjFCGjW3vR3xZn65QWzOAJMNkTNQIwZPwfg0LIQ2OIA41celfiKbb5rvPg3qkHAPBcPuFnZNBBLZhg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 252c55bf-7e1d-462b-5f56-08d87fa27acf X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:09.5820 (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: l/tI2KF4MO/cNgJRn9NUOcqL5h1HNjf/jCqwI80nI/CNkliFNqRJUbjFV3VKVzdAqaL+hfXMeNmeZKLCN+cVxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Nov 3 02:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=ETI+pb7z; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDwK2Qzsz9sTD for ; Tue, 3 Nov 2020 13:57:21 +1100 (AEDT) Received: from localhost ([::1]:59202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmVb-00024a-Bi for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:57:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJw-0000zM-Ky for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:16 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJu-0007gm-TT for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:16 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S+g7Cow+neqE7eaXCvd8DJuFzpJRP+sx2Uqix44olaLCAKfSDf1eIBR1CPq8Q5YpezRw53D4lDrO1yLn0MDSDV6BRS3yuprfUw2TiNQY+0BteUp4H4QPsVJGeoEfOR2ei1s/GOxL2Z9lIYUOE34Z4ScbOcbtw0Mqe5sSrm1cpkgNlkTetcWz6MwMQZz7KCkx96et0S1QsAFqPnnD15HbY3+T4fdCA3v9Czeigt/FkCiljDAGd/6sVzNBe3NmXK9Ks+z8qZu06ySu5Z+R0E2dfd+9gqN0OVLXDBFsOAZcmsVzF3lTgBid4X39B3n9ivrET7H68P6Cx17Vbs8mHjhXbQ== 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=Hh0ZYEXouCPimBgZk3jGuhpgg2laZrNM9SOMexI07P3DSkbT93MbWxBrZZWZHcWWbvOWXqwoez3QOfeIjEkHv/kQeYrMFUjLjfpOdQsHL2J1RyKk4tsVdoyUaA7tJvVGzfqjLTRBTUsZNvoP2Q12NqzwOgCXGKHa9KR+i3xytt4tBlxYzi6vOLS2OEZlCNIoXYgQ1Fiuyu2qDXmpPohgXOinBvnripDFjcgUPVVQwJstmQeW0zYdl5vmlqFeGnv5ROoNuFkHNmXQ/bby6IC3rMCCUXPbMkd1vjTnrd0u1209DwOANXXfLjbbOG6vKDoM+V3yfkrsJ427Mx8eZPtFOg== 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=ETI+pb7zHQom2suL2sAoUVDJQVuI0p42vAZrQ3YY9T5KWtX76b+a7zX0gMZWMa/DFoGJKm9iq+Aifrro4W5O+daEBMinUuZJSO8ceZJTOp6gOrfOevzVbo+LZnNnstfSVtKiIFGsl9QRsrcFSTizmslDCVVioNjvfMqmfDCpl7Q= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:12 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:12 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 05/12] qga: add command guest-get-disks Date: Mon, 2 Nov 2020 20:43:37 -0600 Message-Id: <20201103024343.894221-6-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0401CA0021.namprd04.prod.outlook.com (2603:10b6:803:21::31) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SN4PR0401CA0021.namprd04.prod.outlook.com (2603:10b6:803:21::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 02:45:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b2a6a157-8e1c-40ce-37a4-08d87fa27cc1 X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: 7kgLaOmUxLutgM84GrENOJzpjN35orhiS7Gtsl4L7n/EX5WF2qPJU29MWuIuzgPbUyBn+NSwbuFV8p2V6MMT6V9uNgaKme2gdpCZM9fdHXzKWtJPfrPMGWLqyaJNkxTsR93VRiUNsD9QfT4GrGJyV5VB+tCdq81UAtMebWspLkjinJDdyGOeQv3vcH6KfCGt3WM+N8inAzk1JRo1UhzuG63zqM9GYYLAGBOFa2WMUuTHEc6J+1nsE7bq/266O5rIx6mLCYPtof4ORznVJ9JDhYeVaOPbl8GMrsaEEIwX9MMjrcvmvmyRNoD2pwqITrieM2q5sFjrBi32Fz8xXSiA8Q== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: as8mNHfZxwp8WPbjrw8NDc5aybnWn4o0KMDogwi8sxYyiA3fEANMVuAxhbTrRgwCz/hF4tI8XEtN/w9D++evVV20A3BB2L1tpfAClY+onVXzHs/Mh6M7LG7FG9Y9vSx7SVJ9UIiX46rpdwTw+ZtDR8kQTFJrTcmMQzpOJp4rlNRvXTEAz6fmkNkferlx8OYgJ6lC7JDIHrc6jLZA8CrQ5iJSYII5RRRSEOz4bySZzzRFx3+qFSJJs5qLvlGpa5dTTrwxIyR6+XZyR/MajQqGv50qR/m6oy4xnsMUYx8wo4tVKwcILBB/cHXO9IZNILS3dqz1ynv0eWdGQa/yvhV7x8pEuJ5hRRQcR80qnbIZKjamyFQjKK2CcGvFb6OHkScQkCY28g/dyiZakqD3Lau6hkgTDVGh2J3W/8IRNcl5kTu5nTRZb8EndO9Rk/W+ek/6NxhsjHKvf6Hf/QCFoR4LZa2EI8VhV7aDwxKxdguCyooWGbMSKcLYA4t7OdXODsi7YeiqJVfuNL0oLME4B7eHdlAnks2jr5Q7SDdyESqOU9jBz2F4gJOvNCt1gnebhlTJL7iqpBLm2xFoYXhn2doRb63UaZOw8SENPp2MAaZtn80jAvsKgieObXs573dJjFS5OjLJqXCiz4b3+WoWhfYJog== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2a6a157-8e1c-40ce-37a4-08d87fa27cc1 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:12.8387 (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: mqkxi2ApmYk6jjjkQQ3YSEZXPtGHeA/YmGo1yM/tQc871AcGijVsE87c1n/t2fETO1Ir/kP1rKFc/bSvD/tm8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?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+incoming=patchwork.ozlabs.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 Nov 3 02:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=je4ZEO7E; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDky43Wqz9sTD for ; Tue, 3 Nov 2020 13:49:14 +1100 (AEDT) Received: from localhost ([::1]:43178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmNk-0003cT-Io for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:49:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJz-00013a-6e for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:19 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJw-0007gm-Uz for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g5k+3qvwb2/BvtRbBh4Hdb/mgV4gDKHRotQyOmIYUewCZ/l6zC3r+JA+gwJMaFr35rxo+nFRsXD5ReGrPm2xR7D9CoziGUtW3lbdH780VrSZg5g9QM/vYDY4N9lgeIzyTjNsQu8MVB80gyG/eufcewQfXAt4KEDsDEVHYMP5fBZJ7qePNLqfqhN71V75GwC0pmlydQQyIhrJfqVMUyaZAsnYLgzTa27RMLT7V25elaaPc+zW+7qRpcrcA8B8BDMtZ6jdfT2h676m6BLYShXaDRQHbUaR6qJYd9UORFUAKd1Vy8iMESR2sjk2awApCjMNNhpoo/zP7JJGcx/jg/PMgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iVteiaszyvTJI5WzzsQ6wCqwI7QUBVQMc+lGITsCvwI=; b=NrtAPOPhreAoubywiXhhZmImXLRH9yP8O3nhX5TmlQqpo4HFD1MtFi8o7pTn6YJVhgMRyt8wWassva+foW3y8r8IJKSZa+k2ondOLcyZtIjnv5o/4FSd96eMkqJXDnglHkvGMtRkRL1+ag2l6EeL7ihpve9ZYRbFp+nJYjkDazkv1QNpncSbcjho2y4hU+FGqDLqAt2Aj2X3cuOhxgZcexwypBZ0XGuwEb/XFvScKk07qD7f9Zij/xFpfX2P9ZuTQ8CT4b9y8LSNvJV2vXbuBmY6FgBZcq7R5YiJQKhQgy5fHPe38TL7Khm0nYDsU9oLL53FaLYm6qb9RbKQMa9g1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iVteiaszyvTJI5WzzsQ6wCqwI7QUBVQMc+lGITsCvwI=; b=je4ZEO7EK7gcLQ4Xgv/6qoH1st616sDKdTD4t4pkg3Q2SEi/tCDEoxMnMtGLvGgHI5SAcVbw9kgoCvLqASC0IkptfC0U94QfrDS9Zpie1SdyUBHvwkQ7UCNH1YDE3VuYGX0tpK2bh7EbUyZcav3Q6WKfJPUp091cBik6ZOl10Bo= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:15 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:15 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 06/12] qga: add implementation of guest-get-disks for Linux Date: Mon, 2 Nov 2020 20:43:38 -0600 Message-Id: <20201103024343.894221-7-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:45:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 87e63410-5fc7-4a28-ed81-08d87fa27e25 X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: KLEIFcBuurWc3XxUa+xSCK+yVUs//5RwDrsTSPMCWQGXoX5i5F/YofZTbCq4EqaryjyXqlnTqL+fQdiXwolCq6q9IpqU+ZOzdg3FprVd7n3p/roQAoq9ye1kErJv4fX5gEbPHU6aSLxQSVIv0ybpmioIJBMnpIMZNErIMitkSqeX6tkMfhc2cbeaA5LEOIOG3VM/SQR4w/dZyxuKeHIr1IrGbqzO31aAT/NVHE3dYwvUuJZGjQjCTSBTNT0vrD7oGS5WdFQO69AKB+SQOqwosdZ1eHrH81f5/9wgurWzyA9KdfOzXSvK+LgFkMUfATGA 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(30864003)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0XvQMCIKixC0Q8qkEOCUSt0sBGq+gVgQp7fID6qcxVXia7MldGQam8k6YyZOLSmKMD48uy4ahb1YsdxDsY6PX5XSla9p65WHkxfmUMLadh8EDUmb9y4leERxSRRcDKefusnzGLnY/hCzT2zcBfk/ltd4hcOdJx7QD9oLfn3Oa644eD8+TvXE1Irs//cUBLa/ZAOZ/56adM/Tumo0slGTwdftEzryqkBcmaBkoQhwuJYEyhHuMC/bvBz/dHxrymzpyru3b3pwzI6gxrwXtqZhpM3EVrzR/HPUVKHBwB4Jv4ItKNA1Ao0cI56VCvKwW/3tJ+h0WVCNM6HTWDIs78SLSeaLJBdRccLGKYGxjfKQfeGnBhgpoRzOUak6jULqLD5PN+W5lzXK8E+/VdK6bcwNuIZ/2eVXQSVbSth+fzSNEjiwpxUnHl6Pzj096QoYzrqjH557Au5YUikonxPmUW/xf5+3i75t06jese9spwWqwl7gBlvP9LPwS+LOc0oaT6VuJnSWXYim9J1byyW5vAn8fz6Gd2baioXdyELa22S52r8e5UVMuy44QMJth0D8ECo8Ky41mZvRh/czoLM1oqoWXh/BfZmnH6jae+Cxr3TTIb5wIE1lrZgq7gq3gehZj6A8eECEfUzECNZ5xm6z6Sw6JA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87e63410-5fc7-4a28-ed81-08d87fa27e25 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:15.2352 (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: vRjshPfYo3RxmKXacXXft0AZl78df0oPcZYNF+cZd0yMY71My7KRvusWDviERPFC9FS1tpKBMRSyF3M+Pcbn4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , =?utf-8?q?M?= =?utf-8?q?arc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 *add missing stub for !defined(CONFIG_FSFREEZE) *remove unused deps_dir variable Signed-off-by: Michael Roth --- qga/commands-posix.c | 303 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 292 insertions(+), 11 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 422144bcff..3711080d07 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1150,13 +1150,27 @@ static void build_guest_fsinfo_for_virtual_device(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; - free(syspath); + 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; + + /* 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; + 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) @@ -2773,6 +3052,13 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) return 0; } + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + #endif /* CONFIG_FSFREEZE */ #if !defined(CONFIG_FSTRIM) @@ -2809,7 +3095,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 +3338,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 Nov 3 02:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=bcE6SFc3; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDvc0Zb6z9sTD for ; Tue, 3 Nov 2020 13:56:44 +1100 (AEDT) Received: from localhost ([::1]:57686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmUz-0001Pu-Gg for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:56:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmK1-00017o-HI for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:21 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJz-0007gm-GS for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:21 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ndXcBJjCamVeglkm+ZHdMVYNV9Nq/C1ppGEu/8OVsjjP5W1T6p4gIWMSc58xO6OueNgHPV7yoc42MzM8f65RxzpYvfwddT4+Cjl2rdV1e3D7LxMrXOTfBu9kK84RzB9Q/1QAEohHq2h79Uu+Wzxb3FLopnH9f2k/sLu1YgZi0D1ZIwZ7qaIG7G5TK82YFLIkXHRR3x7Wvoye4qsp2AHywoMY3E1t5tAmcWI3/GTE4rDjx5hOSyQXz53/TucqS9kKDJ+NPCMPLAs//97RlqeuUVJgOLrW4pmMtX3b7DiBItmGfHza5nkEwM5C1qU0pklQNEiOJVuHqdsJyuwiRL0rYw== 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=DKOR+ErNMDoprABGGegS7uOuyVgFphuQZHX7S1JGNuMhKA5Ix0ehHg8GLG/TRM9oWLl+6WqkXObkCvEnjI2lMUK6ZqIE2+GTCBrisvbFHCv7/gBp6lg9dVHo09sCAbJ5QdBkMTaJzfAVKPAXuCb9OOqFuQDApuKnR7+87/wF5WkPEXGtQXU2urKvZnaR5HJgLOnZJCxHFQGvpuiy5e4sf1WjekD8NJ8IyBbGCX4GhBTx9EgKFqR3khwrJb6Qab3pW7rFWVo6zG7+JFCnTXeuIXRGBzYS+usFuNwBzACexSuxWS+E5Q3ocDr7xVFs7YCU3tj1ZGk6kQMKKoiJtjYQoQ== 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=bcE6SFc3CZ0S8pEoIS2alSpzPoGH/M8cs/dZ8O8hzpdRVTNJF7KzxRsvx9rrGSKDOKIpLzRXVa3P5dyIxtvOhtszeAYTkzwm99IB9bBPQa03BVMKty+Y7jns7nX+XYer7lhiSV1/SE5/jpOvhzt+tvBtovyndS4BIR0AxUBzJjw= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:18 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:18 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 07/12] qga: add implementation of guest-get-disks for Windows Date: Mon, 2 Nov 2020 20:43:39 -0600 Message-Id: <20201103024343.894221-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA0PR11CA0097.namprd11.prod.outlook.com (2603:10b6:806:d1::12) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SA0PR11CA0097.namprd11.prod.outlook.com (2603:10b6:806:d1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 02:45:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7fb4c1ad-efaa-42f7-b94a-08d87fa27fcc X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: KrE8WTKQhqOcr4kU4OLMUKVttEoVUXV8qodOaf9DbgdAzOY8VYfnyGbX2254p7DDiJp0Gn2TBN0p5q9kkr9txrP+cRcZgNiS2wJD3nepS568LLNm2Ko5QR/nnBHgDObRu6e6Ncoll6H5b5zoMaNAZugIk6XzVmpqtUBvf88Kb1gci3i6pBLKD26ZAac6K+kH5SeyOsB42DkkBNCN/vDE1y3zTlUN6fXWiqlAEkLRF5TaVd9n61YxZgmjL2sWPxKkQc6YcJsdyYh12SrjA7eQ+PSYfnWlK9+K1xR8GSEDhzhKumIOZwV5FB2+ewy64Ep/qVDEtcHT/XMkV0+RgR3J4g== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: U+mgMudajkWm9ecz0gOJ7HgLTZjGFPFjMbSRJi5LlqmL1ADm/lRYXOHpWAYVVOeCGetpPKtLXMlRZu1QsH2ZuLYTCwnMWGcdTEGbPZsPYnppo+cRaydYm4YV3YO8nJdcTrnJsvqD+vX/zbwe5wd68uKPEExkKpys0SqyVsX8g7M6ifKiZt5Lz005LjYWtg9Yn8btn0a71a8SPd9G+YrfS/fX2Owb2gjMpssNqvU9v71WToE6PdkhSOVu561eKWSq9Rt9qE39N8sjHDVgS04uWdqZ/y4pKYCaJ1SqAP5o6CHCOmuPPTxaUUyMmPX0Ka/4jdtww26beOrcckLakRBUqN94RjAu+mi2daCZZwB0KAsetMUfKm307xdAcLuo8GJMGDsGpfeqhHPEjyHHoaFVs//wq/q8S+xwBu05LwONw6eHLFOgzjIFNKdVeyTrGOYl12dT/2Fpo+NWu80c9xqtJOmgrFilWYHhnY2cPO6Eto8vvZ+xNgEi47I/DzE8HKVMS2ZlnxuZXNuURGp/0KY1VIWhF7VoghvUuRwGiCuGSYO/gb1+lNdjjknQTLUXBLcadsaO39YwkZ7vnPIuAFZ3Q0RCqk7HDBLU8F5U5KEML95KLqNXmyBAv1In/dqfQ9zYpItMllM46hjy3A+4OQ78+Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fb4c1ad-efaa-42f7-b94a-08d87fa27fcc X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:17.9473 (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: urEhWIMUbGl8EoaR24Hiprc2KEuX9StdMYenXKUG539q8mltu5x+SlntA/mL9BnwNdMqy+Z/mwjn9H+oUl/2Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Nov 3 02:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=r7I1wuVl; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDzB32YZz9sTD for ; Tue, 3 Nov 2020 13:59:50 +1100 (AEDT) Received: from localhost ([::1]:35158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmY0-0003up-Dc for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:59:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmK7-0001Du-I4 for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:29 -0500 Received: from mail-mw2nam12on2045.outbound.protection.outlook.com ([40.107.244.45]:27233 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmK3-0007wP-Qa for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YoWWW6H7YI2OrGcfLiYqqm/9HuITH+SSRcVTLgBAP2zL7stG5BzM/Uuo25qE1eY/nqAFCbQNRuQuR1sBjGBy9wuzs6fMr/vclIUz+CReOObwlFb9UiNfyg+1BY3btPL4dZczjgqsIGm9lpkRrWQt8iiYumn2Dq4YIm9qIxL7JnIlVNY4V72Jmflq/089CMg0BA3XObE+etUdkL37hczFlZXGg+H2uI703PQRvcxpIB29NmTCqpQx+HgWtYuUkuhl7XqffYcMWPlA1Xiz54bfeV8nHh4os4oigBgTDlEa5Awwn9TaFzPabayUHhFSFi1bq/cJg5aA6Hppso+sA6/aow== 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=CrZ5Ns3AxSK0gLKZmlixk1pPSvByMj+wnurEMMS6lcQ=; b=YwEyahlntwR+KmuHROUzmdAzt+oejYs2e5Ir3DILe60rARkmOMyAuaYOEIipUcFeU8OQvx1C8bUoGbZY4g/Sv575BNOxLckzTPVq24iWc412ggnHJkSHhhhh7alc1JDA/howIokO/JXfOKSWbEBamAdZ3tx8G1H5MCgdmJdkufDOhUXvfhN9doYhNgcixWcbiwXWS1Sdj9yI1w/rnNGl1YwDf53Jw1DlEIbfSNAdwd3vbPKVaiGvv/Y3lnm63vSfs9zpF5g8soIaioiRQF3UT/e3AsIbjloUlzhNMV/XjFnnudm4R7MoiYJ1iX8Xgnfmj7DDXL2/W49H5oyfd7lOmQ== 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=CrZ5Ns3AxSK0gLKZmlixk1pPSvByMj+wnurEMMS6lcQ=; b=r7I1wuVlWFZhfiIi85BvA+Zs4irdRJX1ZftSh7BqsLEe4pppR7SPAX4BwHhwqEr4DCDaeBeNr/oqw6H6U0Zx/XbU9TsAmG6rlNyd/HO8u1McxbPdjlkpKH+E/DwpxBKmzMjhprZ4LAEo9jnkOqmzs+6grQXSquvpFBywZCS7vME= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:45:21 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:45:21 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 08/12] glib-compat: add g_unix_get_passwd_entry_qemu() Date: Mon, 2 Nov 2020 20:43:40 -0600 Message-Id: <20201103024343.894221-9-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SA0PR11CA0119.namprd11.prod.outlook.com (2603:10b6:806:d1::34) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by SA0PR11CA0119.namprd11.prod.outlook.com (2603:10b6:806:d1::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 02:45:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d460bf25-7a48-401e-de4b-08d87fa281dd X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: GgldmuxzBE/5gW246KJrLy7SZ5ZqGOzjZzzch1vaP+93EqeoYn0sTTJMg9kK/AYFD11UzLMgghdchoUT7ILndrjSXKSseREs1X8yiXZs/vBgfZYAyvf+fVF2WwOMwriQWZO1r9YQw4ivFs4j22oqaT+Pvnx0JreRZd7YWL0uY580j1NW9UMO4uTzt6cGg2ygVagEsfC7TyiuJeT6wbuVumumkzjUysdMGBdFi3uy1c3QmInMrMO9mQ0ERBhzd6TjDYYsHDxav3uEs4Af7LzzDyM9X11PYcapfd87lN9hQE3gIk9YkWSdUWlrY4FHa7IU2YW1Zu4kMgynf7nUvvQ8tA== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ++g3rbD3J5H4W+p/1t+eJgnVCse2rVJu96adaj7kmBrBV6hlZScW1b0kQdA+GEgQDP7Ul5kSVUAUPyEoobu+i7GS/Q3IVZcjElINKOI1kaogIYxttelXWcPPeXqvgLfhUTlHGsFooNJOnZdvAQ50ZYmcp7mKbm+Z7VuIovQgn9c5uz/GXhPt3H98yPslVy/0Y/Hg3wtAGHov3LW6ZgABlrX4qhumWx0cVn9nxKvc6ZMOUtH9TmJyPtS7eYaeFKyz3yM0dIiVWVVhI3sXA4dLMMQQ5CMf9oO7PuWSW2BmU1IKjjA2Fsfw+zLtenwHrcIM81G9d5cEJraZRlB507r3shpghya2HzIE8koMRBuiRMOhoVaLdKo6qagrckgeCQVSrn/gOqv1qncaoGrRgYmT4qbmaV+bajQO1iz9XpJ1KLvRk/+sQGeS7wm/QEil4FHbGolYCwk5GaAYsqRO8FetU0NTI6CnBjbXG5DUhkdTXwfNGpKCnkyWUDTKIvaH8N4JP9gQ+QikrZJ6YBLzdlRXi4gwa+ML2KXIJtYzB7H6KY6emtKn+/nJiK0XJrh6/NNq5hE4KycYUzdJtiavZob7lvFUnpeFNvUiMwcakbyf1kftCYa2tOvdgi5OavoqAk2MiyA3enhKtOPT1e7JyBC/+Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d460bf25-7a48-401e-de4b-08d87fa281dd X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:45:21.4271 (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: +/Kf6WSaBIYdTXI1p2xWosdgJ8anpqK+lAYivzLMbDppJgmrC2LffcGyvCAMW7+jOWA2+/PZW2DCQy8p34U1Ow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.45; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:45:22 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Privoznik , peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 *fix checkpatch warnings about newlines before/after block comments Signed-off-by: Michael Roth --- include/glib-compat.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 0b0ec76299..695a96f7ea 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,29 @@ 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 Nov 3 02:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=1gk7RPx/; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDg85DGSz9sTL for ; Tue, 3 Nov 2020 13:45:53 +1100 (AEDT) Received: from localhost ([::1]:36528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmKT-0000fj-ON for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:45:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJL-0000fY-Em for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:39 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJI-0007gm-La for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:39 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JdbeYXRuIOQ44Le+TT+4NJcCRJN3vx1tAFRpLcgrEFJu92UR9H23SC0v68BUCJnr4qVw6tr/OIk+OIE9cK6GXZXxsQ2Jqf2e1/Osowuh3Hb2cZLIAFbOcaIWu6cTa1s6yjDKD2DRt6BbytWk8u1C1z6Qo5BEyzhSV7Gsk8ShTRXQAS2AphD+nqZzYqtkNXa58GbePHyh+nEPx5fqsNSyH99sKBmZRdbZSGXswsvjIpohgPMs1WB3pyas1b7W2fOa5zb/J/nfGitceQYBl6T8eEle7UhvGjSG3WVLm88yOQbbj+/VZdY418pm+Mk9ElAFDDEIT3Y+WBHr/PpaVFWzvA== 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=rE7JErgeuYA+dTbCF4pqLevJawUVbN6UgKVOCb2nu5s=; b=hvemE06mw4FQsCjUpd+aGZ1QvYU9L6aGm+03CTLg+X80L68ECb3lgVUnEi32y4POeSLMwh7IhM/E+m0t+wmCAgW9Afc60ZKFICTMBO9dBOxqWoerT8j14ob72U4KHIIZGO9m9Hjkngpifqph28lU3O+jcJdzolmO7kWxpSchO0MBlO/ITTLR8Am05QjOR1h0juPEa+GBlHVQYZnC/vVJPSc9W3VDDTWO12Yvz899NG4ZQzQBebv/p6yh7qU4bQqpQX+b+Zw4T40D6SN+IcUE5prd7WGq3jqs8su4Eiu1XQVwTNFqSKN4nPb4FqvFUsHkIgFWPRWBq6YKL27UAHZ0QA== 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=rE7JErgeuYA+dTbCF4pqLevJawUVbN6UgKVOCb2nu5s=; b=1gk7RPx/HVC9LvAoKjb6p5bxCt9ShzlJippk+A5dCbdXrRkKm8sPAGdMpmF2HYjRWdxPoqcdJnK1RhESQ4ze747nWNFRavEFGo18WHjuNSGDE72+p+l/N5yAfyUB0ZPxEeoUiSlrvvWhNRKOCUFxEFu8N5heu8e1BHPAqAaGmyo= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:44:32 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:44:31 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 09/12] qga: add ssh-{add,remove}-authorized-keys Date: Mon, 2 Nov 2020 20:43:41 -0600 Message-Id: <20201103024343.894221-10-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM3PR12CA0079.namprd12.prod.outlook.com (2603:10b6:0:57::23) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM3PR12CA0079.namprd12.prod.outlook.com (2603:10b6:0:57::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 02:44:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f3288c44-82f3-423b-bb53-08d87fa2644a X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1751; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: guE3Tapm1pTiAiNIPX0r4LU2lLLuI2VVXrw01Gx9PURgQ8ko+f9ReHC6b2VBrVg8AEIZi4Fau5TP6KcwTEwNQ9uWanfkCF0JT0rezO6muRurpdE8hcuYoSYGd9qQkt2I+4aqiAP+HdQiQaUFhudafPzaN+M1m52iomc91Tn016Wlu1TPv/zw0DDAf/WW6B4zyE2XvrNhIKZKoYtYlKDIvKAooaQcjUKgJh4eYm/ANT1dj9zEyL37VvB62lyc0gxgjYTh1CcGdkh3fJMcWkiUaDw8PIZv/dD3j6Ggm3r9zDt5loKa+ayW4L3I6LrpdS9g2mFjoJZ/8phsMhf4M4cnPoznbPb3FpZaaeHlB0FqzBucLTrbOUYRTmjnX3kNZzbtikrZ4IEWxQkKx0OXLVbIjg== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(30864003)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(966005)(52116002)(66476007)(4326008)(1076003)(83380400001)(54906003)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: X8ip4XVqaYLX78BBHDbcVhn2kagF74PezmBnqvOLilodUpOe2Ac/exNerVEWLnPkBeUQ2O8Nl6ORBTUdbpnCmJVqPnWxbmarGlD7+H1sQxpkq+9IHEXm3GbZ5LcBess/L5r7ziI2GODucxbrkIWBxA/rAJppJokTAVHio4DkZiXqP3ap72CWc/OHdSHffIXR6YAxGT7og0piE7iKt/T+6eMu+Cfx5tc9ZF85ZdMJaQur/lI2gKojkI+73U8oM98jwfWQTNCgK5sENrgA5XPN3O+PI895PnY66acmdV2HlID8r9fYBLe4rZpMtG86G3CsODDEr4dlusUvypM1IvvVut0wW5LyzsiTotl0/ZlZrH5fpLRs3MuSOFCPF7ps5o75sA5IgJx70b2sPC4C/Qco+wlku898zKjDLVWOESX/A758j9ipWSMXKc7i6htnaUU7Jyzh9A82BAaX4+0YR1L9zPq20s5yjgmYJEN9f1Fmpg77B94RUCHD328s0Kjfw6Dh+SmDBKugoQ075mg9gqjSz+p1lngbxwNIqm84cwpWLW88qBcZICyZrdHLvL2ERO8xqcWp6XdWYN3rqiHQl8J3qC9MoGQtu0BNkN16axATp4H+Mtsi3y4cKCtVTaiTXA/ViZv2jRea1rBGj15M9y3A+g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3288c44-82f3-423b-bb53-08d87fa2644a X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:44:31.8656 (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: Yey1s4HExbUDb/+iPoa8XoMJb3QP/5wIWDGJcsSWWt33vZ9q3yyiF4QPewM1+6HfDLi5wTBpJ8suW38f+mOUqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Privoznik , peter.maydell@linaro.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 *disable qga-ssh-test for now due to G_TEST_OPTION_ISOLATE_DIRS triggering leak detector in build-oss-fuzz *fix disallowed g_assert* usage reported by checkpatch Signed-off-by: Michael Roth --- qga/commands-posix-ssh.c | 407 +++++++++++++++++++++++++++++++++++++++ qga/meson.build | 25 ++- qga/qapi-schema.json | 35 ++++ 3 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 qga/commands-posix-ssh.c diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c new file mode 100644 index 0000000000..f74d89679c --- /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(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(ret == 0); + g_free(path); + + path = test_get_authorized_keys_path(); + g_file_set_contents(path, contents, -1, &err); + g_assert(err == NULL); +} + +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(err == NULL); + + g_assert(g_strcmp0(contents, expected) == 0); +} + +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(err == NULL); + + test_authorized_keys_equal("algo key2 comments"); + + qmp_guest_ssh_add_authorized_keys(g_get_user_name(), + (strList *)&test_key1_2, &err); + g_assert(err == NULL); + + /* 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(err == NULL); + test_authorized_keys_equal(authkeys); + + qmp_guest_ssh_remove_authorized_keys(g_get_user_name(), + (strList *)&test_key1_2, &err); + g_assert(err == NULL); + 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..635de9af41 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -35,7 +35,9 @@ qga_ss.add(files( )) qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'channel-posix.c', - 'commands-posix.c')) + 'commands-posix.c', + 'commands-posix-ssh.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', @@ -87,3 +89,24 @@ else endif 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()) + +# disable qga-ssh-test for now. glib's G_TEST_OPTION_ISOLATE_DIRS triggers +# the leak detector in build-oss-fuzz Gitlab CI test. we should re-enable +# this when an alternative is implemented or when the underlying glib +# issue is identified/fix +#if 'CONFIG_POSIX' in config_host +if false + qga_ssh_test = 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 Nov 3 02:43:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=3ywXb6oJ; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDkr3sfnz9sTD for ; Tue, 3 Nov 2020 13:49:08 +1100 (AEDT) Received: from localhost ([::1]:42710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmNe-0003R9-D1 for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:49:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJQ-0000g4-JC for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:46 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJM-0007gm-Gm for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:43 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K1z29ZAvtYTGCX3Fy0nMO7tH8yBdHdLUVP0KBX2zFmwodSapf7IQzG9twyOUDtg8oJI79EGQuiBpf/RiA+l9J+kJjVNTh0xNmslo/xcuAjRRqLMbZUUhUrmkp7fIeSINdsRKDsR6oaLaUZ9GYafkmpCFMrmtFLGspbwsPtUqXsXdo8zufa+jCPv66XSaLZXzNrYhigvB9fAZYPZ562gpVrB1eW595dLvRb811VY2Wlym9GDsFAjf56lBSq2lAO/RNHmdkHJmwhoTvgsJFQJrMyW98dLnAFxItLVK8bS6L25P5p37t4EgzsKXUn1hdQsha0865EnMguFFWiOrDQauIw== 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=tseNb57wpljKm04dFzmL/UoCYpD6m83klH8rkwG1M3w=; b=lhLekTF0+lyAxB5sgK92yrsMVTGbJx/V8dYrOazuucc0P9MLdqlR+TstIZFNVU2T3G3QJJLL9byUjnBCvjhc+4Z9mCFkAkTU4dVc3BqPN3eHSyw3Kfg6qRvbGuHvNJ2NV407Q5CUfufymCuq5073mePhSV4BIqDU1x4+7gZ/AG8MI4VVRGiZ4jPvDp/OmdeNm8tmNnj/EsNl3clEnB+CcV6l7YQcsYSksMmHUUjnu7xfO/VKfJxiFtgR+BrY5Klrixs9qwl0Vb2JilYbRONSBAJTp1Ww/NpcXsQ9I1dT0hZxeHSP0CGKX0bi0I6SIe3J//z3PV6wppvys6HYRUZsfA== 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=tseNb57wpljKm04dFzmL/UoCYpD6m83klH8rkwG1M3w=; b=3ywXb6oJrMQ/6u+yeTkApqYFyLfuHYBetC10ZXrknD/rqf8pS6v4uQaWIxcKmEKn+Y/QzxoMj6wzPqzeR5rDLBtQER6AnE1pgqS1Gsl3yJOVMd8ADOzT+L1HrQ2B6fas/aG6eMezjdPuWV6o1U4gx8huiUPX860cJHigPB0zyrc= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:44:34 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:44:34 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 10/12] qga: add *reset argument to ssh-add-authorized-keys Date: Mon, 2 Nov 2020 20:43:42 -0600 Message-Id: <20201103024343.894221-11-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM6PR02CA0110.namprd02.prod.outlook.com (2603:10b6:5:1b4::12) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM6PR02CA0110.namprd02.prod.outlook.com (2603:10b6:5:1b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:44:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0535de6f-acad-4045-6f15-08d87fa265ce X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: gTFGFfOEbtuMFfi8aQmTRiSv14fMo1YAwalkMAf6gnxLy1I43ExgAAifTUBueJ6USrzyqFIMLnNnLqzW3fuAhz3GB5XCItSYbzF0q5aEWBwWPOI1/RJwSQab00PMIbPW+YD+s4MPZ08u1MjQcD3uyzegwnzm9uY735DwsGfVa989Sb5+FaN51JtxjgShh54zU07NZlS6G9QunQNNay7v3aoaUzIBqdtEec7OrK7Cw9MEnQOezYl/om4Z19njFlOupqmGWRuQrBvVwFxAqjnUdfbVKzeSWbwNdOezr0Bcwgv6pX7ux7FhAaTjNMAuHO6Bw+sOP+oe89vH+8whGMAq0w== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0Yqi+vBZ2sAlWK5okk11HiXimhc+mHkuA2QxRTRIUpqPlE1SnxU3GiGhtjLqnwk9dapA8gHouQC3STUQ4+fIPyNlkZxpahvDrS+9nxHKQ3mC6f3w+bg31NC1FJ5bYYyozeM7Q24nZ8t2PLDcifBHPbpLSQRudnp5uNar7EnD14GHbq7IFa8DaRdOwUL4xKXMnBdLw2sGzW3D0DaGf30NLKyhifRk8THDc2IdMwgqUfeosn7wnHfShYWbqSWQukqfzw9TF9rNSJr9vjsyvVIy/Pb7V11t4D0UHTmYhiqNrtY8zfBCdIAxduZbNjtXk1qjSkJ2zzl535a1Di6uwqxOUMsr86NkzdxII/7QMTs6BD2D/ZpyqFoMvFNvWueYbbZN8tmJNZ4KWy/cDjE8VC+TzrKULuBXqMy7EpyNxwbSkICiqXcHR0KRNwOTknfpYrSYQCJGYw04FRqGgaCADgPxuRxfnaVetLUMSSulndxIPGPDVnWcqEkHQp2ZwqSueLmMCNDPTn0EUFD9oXcu9oHAS7eQZfbyA0nIwF1OUERcTNWTB7RlPR9q0gvFUSAz8yxC3hl/CqDnS4AlMDGaY5uQedzJQCMBiCrqc1ipy2uMfLiLXO/2mH3ZmCC0uX/pdiEQp6rb4X9AZzfuzJqMpwa2TQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0535de6f-acad-4045-6f15-08d87fa265ce X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:44:34.4184 (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: 3STnbTPYIbZtp7C44ytKe9cxOVhiAxzZzWplGH8W911cvus1qdoXmAyhnFDpzbPTtAyhOSz0w0Oz9w0yY1ViDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" I prefer 'reset' over 'clear', since 'clear' and keys may have some other relations or meaning. Signed-off-by: Marc-André Lureau *fix disallowed g_assert* usage reported by checkpatch 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 f74d89679c..362c9e8816 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(err == NULL); 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(err == NULL); /* 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(err == NULL); + + /* 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(err == NULL); + + 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(err == NULL); + + 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 Nov 3 02:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=08ayXLZZ; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDg85Vhjz9sVD for ; Tue, 3 Nov 2020 13:45:55 +1100 (AEDT) Received: from localhost ([::1]:36602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmKX-0000kC-LQ for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:45:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJd-0000jP-LH for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:58 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJV-0007gm-Sd for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:44:51 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hCRTvgBhovi4M4WSI2CNL+g0mRZOArur8nHbkZ0bLv8Uf7G7lgsXmg/cYxIcwheq1L9SxKsIugUobkFjrWdYoEoDOCdqW87hfD+NVIOLN6B2C07HKaUuqh6Nkj8apAsUr9gX8RPqnX3f5FZjYR+FxDoNtkQ8KhBEPbUjh7459Ae12QevgQc0l5UpzGf/dTShYimeBbkjFf/fG/9kq/CrBPgLgSYVx9eLvTJ3Jgt9KmHv+N1GiCw43iaUjigG1xEH5Ui8c7ikQU7L2L4B6Kv4jNmEKz9pi9gu9HojhKWeCi3jgaiUtEfaKHwj/czfK6hdkqGtsh/CoGZ0Hq4ExE5zCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLYNCImMe2utqvDZqwMheGO5CLksdSPZ6Oc6wmQm9/Q=; b=PZTwy5Y3Y3Wjpj5MOmJRmNIraReC/tSHxe1uETM8TtR8N/i77BI3xXwC5YL6Nj/Rm715rqeRupgDyEqBFIi4CnCSqj/KuwfPIGHs9nx3IObYkTZ3Iph0CtDcDcwuadpO6QN72sJ/PSIkgOT04nUPBVua9BCGChGrWPKYQ/mxSEDCZBD0HhkSdQ/bTGEqu5Njgx/zFQImtJ6uQcR12VIxM+OQH7BQW+QxoQJOdBrn8+p22iLpz++PCZdnMoz3AFs/fi7K78zyjUVFKC5nYMus+nmv/nFL/LwJqNrS5rfwUv7DG48mRXLuaxWBxiWZUYh9HOQIurx5ba0IZ4p7PdWs+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLYNCImMe2utqvDZqwMheGO5CLksdSPZ6Oc6wmQm9/Q=; b=08ayXLZZSHHu3Wbyxs/IZIGtEkCLIk1vfzsFqO8lojsez+VpfNxGbPOkl5jxXrMXQ6oeBi19aXN0t6lTdnZTy3KAAAavci669jrpsulMJgvd5AbOUYfZv4Id5UpVnXvPL/jTjLWaUQXtiuL0YXdmSgUObHO+m1NTDTuOAjv0f7s= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:44:39 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::f428:769b:3e9:8300%5]) with mapi id 15.20.3499.030; Tue, 3 Nov 2020 02:44:39 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 11/12] meson: minor simplification Date: Mon, 2 Nov 2020 20:43:43 -0600 Message-Id: <20201103024343.894221-12-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM6PR02CA0109.namprd02.prod.outlook.com (2603:10b6:5:1b4::11) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM6PR02CA0109.namprd02.prod.outlook.com (2603:10b6:5:1b4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:44:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 25e537ed-21fd-43fe-4a69-08d87fa268be X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: 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: UZ43V1T97YLO/WwWROrfxuP7U3nj9haQrRGVaIBJ87yCBLQBuqVbAkttUShY5EE+0Ij6DXvAQ9E3QKVTnCTEKKQy0XTD3zRp9AmpJpKsQtaSkvYcWofFIyWQuCCag9j76mvMSoeINB6kTyhx/X/U+YIkyatJVgx89QsDm0T3US+eKH1/YUJisiUCY8L+tNhhugZgcLCVMRE0axX4VY1YMyjSoh1p+CfRvhgkybthEe1q1h+YBVpbGgGSFmylwKa4vjmHGOcezIs7YWxd6D6LgQSf7zmafg5S7i90Mr9cSX2S+PjlpfgzD8J5J+r4gWjRrLCuObWZPRJunWUKXdx3dA== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(4744005)(86362001)(26005)(66556008)(956004)(66946007)(6666004)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6rQUW6PaxoJ+o0SP+0rzHUmuBa45H6h4jN2CN+SrpReRHXT9iH+etRPAYdVCw3hhS4e/oaJD+vce9Sy8A+5nF6w3AUNY8UAUWVx6WTQp55ME3s6Rph7bDO4we87OD+xp22UZokDCQtPHTTdiNkA6nMmybl00RF0J/VA0k42Z2/uhjtoMbB6VHe3pqRkSCr1Lmp/iO6ocFC9BK4DZEGa0P6Sgyy7kXxaY3Aky4G3kXg4mjS7rR0FzBZQg6eD4W8VMgjaWmIh01Ct03UO+2HstDx6/YMhlXq/P4CHOKIKECpZSDmLRznRw0Zyu2WdIIzMPi7U8uOlF/dUq/7IPTaZFEExo10Q4N8DwAy+62MUGiKzJZ0HHChDaHIQBCCyguVmdnbl6pZPMbojR1AOwruz6A/eeo0z1C9izeJ4S47fsjQf4GhLg+t7jnCZnTj7hy5jkXD+GdEKBlRAmy3ifEOmGOdTuO1o3sQZzMWOz2Rvn/OlSuun8UX49Fesy7kYSFRWMddhG+0TurhRbiJR8XBYgEBA5VpguqXueWF6SfRhm2EKFNIQyBjPITZajK9wmYZLAcwdGOEDz0IOk7ybpUR6mFT9qkj/dGZeGbWI+THxFReYXN/qOBT0ubnlxtEkPXXYBlyOZpZVGVtBEZrnLas4n4A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25e537ed-21fd-43fe-4a69-08d87fa268be X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:44:39.2611 (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: oULIy9iOvhk67GK9pgkrfcVE8QJXBoNVL9vZ0dS4LB3Q2IfDstpjvGK4pDIjSVrBpuO0/T5Uinm7Zn2OThPe7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 635de9af41..4cb3b3f259 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 Nov 3 02:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 1392593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-amdcloud-onmicrosoft-com header.b=hhBxzV5P; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CQDgB0vh0z9sTD for ; Tue, 3 Nov 2020 13:45:58 +1100 (AEDT) Received: from localhost ([::1]:36692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZmKa-0000n4-0z for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2020 21:45:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJi-0000lj-RE for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:04 -0500 Received: from mail-mw2nam12on2072.outbound.protection.outlook.com ([40.107.244.72]:13281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZmJe-0007gm-JN for qemu-devel@nongnu.org; Mon, 02 Nov 2020 21:45:01 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UMbUVNsCGpqEes33ra/77K+ziYkWLvRgf8Laos1sqmzvf7/Ox1h+FVELRcTl0cdTLEhSuNfoD+2xV/jTMjAyiBUqFtcabouC8sApwfF/GsSNhZZWLA5ZmVlVQ/ANEn7+sb0N+lh13gyFiriOObeQNdx8a0ap7UGjDnxmacQ/2h/CWCJ5HWP/stZdm0rnKp5MvgZgt/ukm9qoR5bdQx1Tigk5kRO2BexXFBWGJZbZnMztzk/irHtKxlKKq7AsBpUH/JB6K7my83oilvYxweY6OCKEfDtsON3iHXd5BpPIvuAcPrwg/Og4WoDCUg/XDszJO7JrZn/OQryGB9zwn6zj9w== 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=q5GkDq94uNC2fCpdfnTJMWf7SXZ9FCqm11p5oNx7M6M=; b=VcsmxKowUQDHwyADpL1UAbxaNcfbZ2XDxP++5pxBet3/QgY2cin8U8XefBH9Kkk2yp9LvMQkGJO70L8+pR6zhl0WH2Jsth8b0pKZEPmTFFY5b2xbBg3jYDHwJBNhxq/Fnp7lGbWNrOoIyzGVOzqCXMDdP+tS0S5VXipTqdLkXsiul4jzafGhgPTouUEgGrZAxjRsKEp5NhOOkcAFzJng0akHaFdY2uKpe3yNgP+a64Cu1TZLdk1pFpCMjjMpJm5jzaNbg5zRMWYSFcvi6PKMOWR5+XCkSdirvgolk1ukp/L6K2Jh/05xKbs5BhaAUeWZgPkP4SRwzlOsWjAE56os1g== 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=q5GkDq94uNC2fCpdfnTJMWf7SXZ9FCqm11p5oNx7M6M=; b=hhBxzV5PR8IdvwCQCQXkxzOeUUhvULu7JUiguPb2v7ZPgndXX0wQLjWvThjYdWVJOK5M8/6nIPtNpMoVmP7TrXcSLkl07BPKH2bOMqahNysvN3J790uHjKFOfzE831dtWtt/pcXbmNSyI8ute2+u7pIm3ZZYPupGpzgkeE8eRyk= 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 CH2PR12MB4311.namprd12.prod.outlook.com (2603:10b6:610:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Tue, 3 Nov 2020 02:44: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.030; Tue, 3 Nov 2020 02:44:42 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL v3 12/12] qga: add ssh-get-authorized-keys Date: Mon, 2 Nov 2020 20:43:44 -0600 Message-Id: <20201103024343.894221-13-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103024343.894221-1-michael.roth@amd.com> References: <20201103024343.894221-1-michael.roth@amd.com> X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: DM5PR18CA0086.namprd18.prod.outlook.com (2603:10b6:3:3::24) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (165.204.77.11) by DM5PR18CA0086.namprd18.prod.outlook.com (2603:10b6:3:3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Tue, 3 Nov 2020 02:44:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2dd2499f-711f-4fe6-e9cf-08d87fa26a7e X-MS-TrafficTypeDiagnostic: CH2PR12MB4311: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tCCb8NBq5Jzm7E9ghUCypE4Ou2ey9udXbZsGmhIHFs7pxzuH5DC3TBe4nxWUn7pL+CAi3N54yHPVQIrBI6VKNYJeSpkePOVWeEP97DM9sBk980A/eLil31EE5xTxYaq8D5L2bh3MlOBlhymnXRyspwtjxsY0d+1WEEmLp4m9EbgSDyOI9Nst7bI0rUyP8zultaHNdcTQLX2N8At/K/9DD+j3W1Pe2zfMrBZ7/vhw2jlaBuZ3rLrRWKmhoVs2v5QZzDcI8M2A3o0C7V3JFaANrJKJF/WcSefnoOCg49bRcSNrGT5IHJVOiV/v8+jzia87HXD6YmE2H4t9hn902WcPIQ== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(16526019)(186003)(5660300002)(8936002)(6916009)(8676002)(36756003)(478600001)(86362001)(26005)(66556008)(956004)(66946007)(6496006)(2616005)(6486002)(52116002)(66476007)(4326008)(1076003)(83380400001)(44832011)(316002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: xz9MM3n20Zi2SeOWnx4TZJ0C9kgyBoZgBGc82pczkwgNBaSRiIVzXAtBNWRP1RCvdvwaIDOI7xDJPS+dmVR7fEgGIkvy7PDz+WfTgTYCKsILOu2nzgTzTYVzxD6iITmYI/grk5OvPgQ9ALEMLdgcl2E/nW/dskasuNy3dTunr1xf4+fesPH6RdPGTVOgfGFBH93VlzX7rpaOuRjRRgvGL+G75EGGXlAAM808ied7DpU2QxughPeSgqwYNq/+yEFvmASP8+8HZmXGoT/TkrOfgMJvBawcjnX0+ueH1vihCE4IJuzpemvz+o07DPTpTSLJiPd9XdUxGQKq2MAp+3Tmbh7SxzZzzsPkyidW2LpueymwYyB+FtneYAR7Lc+IDNU4yDRHFvurBiZF8xTW4u1s/GZSXLxWi1gXx1xlJV4U6OT+Vj2JSXFBDtIlA6dXYVawtzvOh3AQdcyafTs3CdxczpcZdKRQycuvHIUkqnReFSFpb+cXiKUem07Ab/haHEXkZxjgben30VcT+o/8fZ/7Be5PilUrroUgWVDu6Q+MB35RWmDl7j3lWqfDQNq2WC2jPWkbjTO9TIr15m8oO6Ll5GSOW/qE50/8/aYeDShcpRgNHVfs/Wx6AhYmyzv2ME3Um2JuzvA+4L7KTVVTyPZp3Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dd2499f-711f-4fe6-e9cf-08d87fa26a7e X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 02:44:42.3048 (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: te8IbQ/H8qBTrXrSe9ggaT4bkLAbFCQBx6l4HXtD4LFq53e75iVv8zKmv+YIYZYfkM23bb95d7KdHS1LiecC5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4311 Received-SPF: none client-ip=40.107.244.72; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 21:44:34 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André Lureau *fix-up merge conflicts due to qga-ssh-test being disabled in earlier patch due to G_TEST_OPTION_ISOLATE_DIRS triggering build-oss-fuzz leak detector. *fix up style and disallowed g_assert* usage reported by checkpatch 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 362c9e8816..749167e82d 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(err == NULL); + + for (len = 0, k = ret->keys; k != NULL; k = k->next) { + g_assert(g_str_has_prefix(k->value, "algo ")); + len++; + } + + g_assert(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 4cb3b3f259..53ba6de5f8 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -95,8 +95,15 @@ test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) # issue is identified/fix #if 'CONFIG_POSIX' in config_host if false - qga_ssh_test = 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: #