From patchwork Wed Mar 17 03:22:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 12144635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E46CCC433DB for ; Wed, 17 Mar 2021 03:24:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8164861481 for ; Wed, 17 Mar 2021 03:24:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8164861481 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMMmt-0006cL-LV for qemu-devel@archiver.kernel.org; Tue, 16 Mar 2021 23:23:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMMlj-0005K5-Le for qemu-devel@nongnu.org; Tue, 16 Mar 2021 23:22:47 -0400 Received: from mail-eopbgr750053.outbound.protection.outlook.com ([40.107.75.53]:4470 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMMlh-00011A-Dz for qemu-devel@nongnu.org; Tue, 16 Mar 2021 23:22:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oEAXonHL1CjxVVgkNr2Q/ZzdEJj0Hd1MK/ZSMxOo0Nv1NIrNo1hFop5jtw4jvdf+nX814bhbLLMaYriYSq0PSzBPm3sZEYoWP4ilieq/Q6UTgyksXGrm15+jlqwe7scx55pc4QGcIglyAuvyQcxfcBIgyXhUXMNseRwoTHFLvQoLYC2mTVUJ4GyEGf8fZ/Ji4RBUOuyM0MxrJeSMvmbVdn70aeFwg7oDrL1do+kGwJ4pn7kDIGk0v0mdnsrTgylaXEBA4rPeVLMHyOP1mLkKXYMne85ywT5CHWNGniM5oe48H7fTLscFn0E9b7bm28MwTPC0jlQzdRPrTBUfvDyQCA== 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=BLVHNmWfKpS5wSleofmGWUNZKm7XvJTuwf1TL5fCeJQ=; b=PQMX4alW4OFh/6G96q/GnrJdt0cbkM1sS79CLU4KFp3qvJ9wgxx8zOQpG0ZAYClwum0QHfB8VCQKMWwiaNuOEMZ+nGFIRYApcATQppO//lFV2FdVJnviOWl4tpQbC4ngrYrUTYe2ZSk6O4R63qjvm2MK/BXXEDKeNUFZrTHlGiwytqV4hqBXcAAtMwpgrK+F1HgOdY2pesdkNguuyMzQVOAnFhlRfTd7uWR39FyZB06xKaosEDCcYQN/aHSz9NiywlpR1Sy+qtaI7CEO0gAiEu21kMmhMRJ8oiIwxGW16nXvl7WGiENgbeLaVvrqBM6vitXxE8vaXZYgRuASnWnB2A== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BLVHNmWfKpS5wSleofmGWUNZKm7XvJTuwf1TL5fCeJQ=; b=H0MIYfEd41WYdXHOb0/Od1nL6dGDht2qm+BZ3JvLeRPm8t6i16/czh/m/StZafZFj4HOHdO95EMNs24YG9Lbrov3zPkIBoWNozZeOwE1Yrp28o0Dkv6BUW0wjDYckdXxO6fwMpD4mSKJlpCZw+JnZP7Ce8jl16pOQ63C7IsiIWM= 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 CH2PR12MB4954.namprd12.prod.outlook.com (2603:10b6:610:63::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 17 Mar 2021 03:22:37 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::81f6:605c:f345:b99f]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::81f6:605c:f345:b99f%3]) with mapi id 15.20.3955.018; Wed, 17 Mar 2021 03:22:36 +0000 From: Michael Roth To: qemu-devel@nongnu.org Subject: [PULL for-6.0 1/6] qga: Correct loop count in qmp_guest_get_vcpus() Date: Tue, 16 Mar 2021 22:22:12 -0500 Message-Id: <20210317032217.1460684-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210317032217.1460684-1-michael.roth@amd.com> References: <20210317032217.1460684-1-michael.roth@amd.com> X-Originating-IP: [165.204.84.11] X-ClientProxiedBy: BN9PR03CA0304.namprd03.prod.outlook.com (2603:10b6:408:112::9) 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.84.11) by BN9PR03CA0304.namprd03.prod.outlook.com (2603:10b6:408:112::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Wed, 17 Mar 2021 03:22:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 12d4e74f-0cbf-468d-309a-08d8e8f3e986 X-MS-TrafficTypeDiagnostic: CH2PR12MB4954: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:651; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eyCuQ07y2TDcYd7RCOmAyrVekbgDCPIH2NpOVByLL06OTVw7gp4PjKHIUe6U2Gwmi+YbJhXoExoM2s04DIxH+4H+dQ3JLwjUK+EvgO2TRMHCBE3KM/oMq73yuz3DT5K74Ij5cfuyFd/x/3l5Cv2c3HFyxRoB/Wk7YCmVGwBpaaTLxwaBITUFIGIXovKSlUiP8h59XAcm572pNlGruUuZuJIt2+d+19qOWIMnX7MzlsIVoNME1laDZkVGLUfWFuzYuBoLetzx83tf0aADA+K2gKHJLo4SXwQf5cdEFzDgvLV4DL2PA6PkH2mxM89BTBCQbPuNwDuI8/Fihz+vN1MuL/5uRTGwfzRECs82yY6ldj9drBpwZve+mOcRMWdxWdSJ7nY03p+KT4qiRzoXoIRrJQALqDUcGyRUJOGwddtLuCSjGM4BHZE+u7lN2h6T9PKzn43IJQxZZ2yqtsU18nsJAwU51iljwFAQkbTQngAw4L9QaJpUHxzQsskLbLfVxKIyARLVljkc1cGjSjwQI3sFqIBVNohUrn7zJtCjouWxAa4m1JBoICE4g5KdwslhKhgH 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)(396003)(376002)(136003)(39860400002)(346002)(366004)(186003)(8676002)(8936002)(4326008)(478600001)(316002)(26005)(66946007)(54906003)(83380400001)(1076003)(2616005)(66476007)(956004)(66556008)(86362001)(6916009)(36756003)(44832011)(6666004)(6486002)(52116002)(16526019)(6496006)(5660300002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?PZiNAw4fMKCBRQdP95ebtfZK7KuEpw?= =?utf-8?q?zaoL1t+Mj5fdfhl+Eb2StVXPGi2HrzAXjFFn8hQUKeLBG6ymIsY8XXZE0nDYjnTfb?= =?utf-8?q?BhxGNT+LHFBa9wCXIc+liPCwVsytiGlth60f+6TR6wj+YJOCwV11kryDAy0Kr1FMW?= =?utf-8?q?V+ZYm5TajeJOaTljjbSwFfi/HX3Sbx8XOxJ1ZMcfE5Z8gsHbSPbm27UDmfi2kRhVn?= =?utf-8?q?ogAN/3AT5S5gqqO1luEm917nkkvhZOIHyz2a9d2SASrJ10L3NodpdUOgCPWAUFhEI?= =?utf-8?q?vM70WWdODmYz8vVpP2B8TbMmHobTMMppK/q4BkjMNfxW/u6LomwrOwEwBFz8qd7lW?= =?utf-8?q?1nLs8ESfR8hjbTojBqsO8ykQs7vjO4GrDApOMzH9/I9wdZZUnISgTP6no63dPV8Bd?= =?utf-8?q?GLaIedA+nUUf5GX8RcjjVvSNpqKQr90hCePIuMDhO2xYX/VMLXCIhLCL9SkiO8hs8?= =?utf-8?q?Vk+jHsd8bGEtOLaz5bnF6DJ2F02AaST6OefZ4vt/yQTp+m2ngG/8hX7a8QDvHLr0O?= =?utf-8?q?PvhGnC/SoHRp3ntwudyFPceiiKckI2A/dH81y/GkyHfbDJHOeADxEUBlS8yLIMvXT?= =?utf-8?q?eACZAviYtpD24g2aNsZYwNu0d9NJBVZXgaWQ6+WflWfXv7hEXGwFGnrqwrV4/zTwL?= =?utf-8?q?O2+H4ySoaJCE/W5Eg8FWpV23It1C0l/srqvcw8YsaSOO80JdNAHm/bQpXofLNx5DK?= =?utf-8?q?mB4kXNBxK9wmqt03EyTPcaFWXRnxKZU4jXIE9v3cnIYCgLm5PVpYFhE4CASELMNQJ?= =?utf-8?q?zI9dt+1xj1LVlU2yxh3ksD8BcweRYz3xi0YIJ+7UgBnS7tZsq53VcsGUkpcpzEq2K?= =?utf-8?q?0Jxfd/gRfLr8TsWvzl6LaZVO3x+RCB0PW+LEB8B7EE8IGZyYgkttlj+sdae+aKuSG?= =?utf-8?q?8Vj/Wb6GQnmFewqcjWKYHMBoN7Egn5lI9teB5qiSWrxjvET1xtGQ2NcHBlNt3AAjH?= =?utf-8?q?LGvZw8PrqIIQlDONzOvDzLMJ3yvT7GntQ6dPNuIYpoov+0awMBTGj7F77Gu8Rtpmd?= =?utf-8?q?j+oVVxupZ5eS+7TPHkXmOyr7MKfZ5PeZmTQqYjK1FQ8++a7Bov88GhM+veKhkH4Dh?= =?utf-8?q?z+R7tdfBZUaWFy43Cv3VmpyuCdF00h+kGzWq0GSQ6VXsymAqEFhxsrU0xDZnHvAF6?= =?utf-8?q?t1IIWn11w4Ui3qU776dRBmWyLfjFLvykd31y/nCsIDiPfciTaBeVwMn5YzMoAfmDc?= =?utf-8?q?kPmvkYPI7dtfwZWMetiXN8g169043NkHyB89NIAeiQDIy1Bh8dTXsevjtzx/7KTPw?= =?utf-8?q?VeeLY4QaAkBXe9?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12d4e74f-0cbf-468d-309a-08d8e8f3e986 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2021 03:22:36.8096 (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: O/PykS3gHDxI+ADeLJ+4ucV1zMw56+JLKSPBNqix4csvXBP2hgt4kHKmKZGz9vYc1MNdy0UMQklkhnSBO5cM/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4954 Received-SPF: softfail client-ip=40.107.75.53; envelope-from=Michael.Roth@amd.com; helo=NAM02-BL2-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.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_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Lin Ma Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lin Ma The guest-get-vcpus returns incorrect vcpu info in case we hotunplug vcpus(not the last one). e.g.: A VM has 4 VCPUs: cpu0 + 3 hotunpluggable online vcpus(cpu1, cpu2 and cpu3). Hotunplug cpu2, Now only cpu0, cpu1 and cpu3 are present & online. ./qmp-shell /tmp/qmp-monitor.sock (QEMU) query-hotpluggable-cpus {"return": [ {"props": {"core-id": 0, "thread-id": 0, "socket-id": 3}, "vcpus-count": 1, "qom-path": "/machine/peripheral/cpu3", "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 2}, "vcpus-count": 1, "qom-path": "/machine/peripheral/cpu2", "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 1}, "vcpus-count": 1, "qom-path": "/machine/peripheral/cpu1", "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]", "type": "host-x86_64-cpu"} ]} (QEMU) device_del id=cpu2 {"return": {}} (QEMU) query-hotpluggable-cpus {"return": [ {"props": {"core-id": 0, "thread-id": 0, "socket-id": 3}, "vcpus-count": 1, "qom-path": "/machine/peripheral/cpu3", "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 2}, "vcpus-count": 1, "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 1}, "vcpus-count": 1, "qom-path": "/machine/peripheral/cpu1", "type": "host-x86_64-cpu"}, {"props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]", "type": "host-x86_64-cpu"} ]} Before: ./qmp-shell -N /tmp/qmp-ga.sock Welcome to the QMP low-level shell! Connected (QEMU) guest-get-vcpus {"return": [ {"online": true, "can-offline": false, "logical-id": 0}, {"online": true, "can-offline": true, "logical-id": 1}]} After: ./qmp-shell -N /tmp/qmp-ga.sock Welcome to the QMP low-level shell! Connected (QEMU) guest-get-vcpus {"return": [ {"online": true, "can-offline": false, "logical-id": 0}, {"online": true, "can-offline": true, "logical-id": 1}, {"online": true, "can-offline": true, "logical-id": 3}]} Signed-off-by: Lin Ma Reviewed-by: Marc-André Lureau *fix build breakage by using PRId64 for sscanf Signed-off-by: Michael Roth --- qga/commands-posix.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 3f18df1bb6..665735fd09 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2370,24 +2370,6 @@ error: return NULL; } -#define SYSCONF_EXACT(name, errp) sysconf_exact((name), #name, (errp)) - -static long sysconf_exact(int name, const char *name_str, Error **errp) -{ - long ret; - - errno = 0; - ret = sysconf(name); - if (ret == -1) { - if (errno == 0) { - error_setg(errp, "sysconf(%s): value indefinite", name_str); - } else { - error_setg_errno(errp, errno, "sysconf(%s)", name_str); - } - } - return ret; -} - /* Transfer online/offline status between @vcpu and the guest system. * * On input either @errp or *@errp must be NULL. @@ -2458,30 +2440,33 @@ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) { - int64_t current; GuestLogicalProcessorList *head, **tail; - long sc_max; + const char *cpu_dir = "/sys/devices/system/cpu"; + const gchar *line; + g_autoptr(GDir) cpu_gdir = NULL; Error *local_err = NULL; - current = 0; head = NULL; tail = &head; - sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err); + cpu_gdir = g_dir_open(cpu_dir, 0, NULL); - while (local_err == NULL && current < sc_max) { - GuestLogicalProcessor *vcpu; - int64_t id = current++; - char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", - id); + if (cpu_gdir == NULL) { + error_setg_errno(errp, errno, "failed to list entries: %s", cpu_dir); + return NULL; + } - if (g_file_test(path, G_FILE_TEST_EXISTS)) { + while (local_err == NULL && (line = g_dir_read_name(cpu_gdir)) != NULL) { + GuestLogicalProcessor *vcpu; + int64_t id; + if (sscanf(line, "cpu%" PRId64, &id)) { + g_autofree char *path = g_strdup_printf("/sys/devices/system/cpu/" + "cpu%" PRId64 "/", id); vcpu = g_malloc0(sizeof *vcpu); vcpu->logical_id = id; vcpu->has_can_offline = true; /* lolspeak ftw */ transfer_vcpu(vcpu, true, path, &local_err); QAPI_LIST_APPEND(tail, vcpu); } - g_free(path); } if (local_err == NULL) {