From nobody Thu Nov 6 12:12:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540912343151287.05036495702257; Tue, 30 Oct 2018 08:12:23 -0700 (PDT) Received: from localhost ([::1]:53798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVgr-00018X-Lx for importer@patchew.org; Tue, 30 Oct 2018 11:12:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGn-00088z-C3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGk-00016K-Kc for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:24 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:36193) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGi-00011u-KE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:21 -0400 Received: by mail-qt1-x842.google.com with SMTP id u34-v6so13729479qth.3 for ; Tue, 30 Oct 2018 07:45:20 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id t36-v6sm14558958qth.83.2018.10.30.07.45.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=LpTgEoBzLWh5gaBsqbep4KHzAjFwJtBKJMmuhSdiqCa4W20prSUaANlDOyrqNOE3TN ouHS9RILRaFpk16FSvFoO98v3GnBwb0wu9WLmHK1JA+GPLCwyJfBcHgn+8FLK252DPg+ BOClQKl2Tzi2fucvfunyyr4hwHJaK457p6F5nmgVqw1ZjaOF6caqmZ89734iqTLmlzlm CqVz6d1PxB1Ai2OeRQucMVKOfcjNFP+Nxk7dM0w7EYNOOlZFZJJC+KqK3D9JNZG7hvmO Kv/BXNt9ww37ild4kq47FQtb3Et3TZrnLLPSYJ9wPRpPhlOZwKc/mOjBqbJsKBQdBhBG NkCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=QsueKvaDqB3LjEfAoT1K8azcKL+hUb6970GwnsQ4UUB9eqagvncdfYBeiqZaW9CUqR YB2iGsSxT0T2ht5nlJz8i9AEpdyHT48eUwAyUiX78KS2to+LlQAVJ03YwASRTnpcwkIo 7ULzd7SVBCMH/JCKlBwWBSXdaquEkF/1S+qX6Fb/UQPkTuhm/e2QBaZ/Z4yLWd8alW+G AUR8weyu1bclnCsOIhEXBobE1dQDEgcOIP8Hb5H791RLMxu971TvmVQTxhdVEdGDhRfB uLjriJG/9k4S3jge1K17QIxLwVbzRDC6OhqIdzNSAh0c+1wIpMOs7DfQAPgkbCzpYMPJ tivQ== X-Gm-Message-State: AGRZ1gJ6+QaW5ZdxWu8GsYnat4VBPk86Ze+a0Z+UEP22wykK4AKblnTo D2uj9ZgPoe1XKv6YUCuxl+lz+nn4 X-Google-Smtp-Source: AJdET5eTLOLRWg+KSfw9IAWTIuOr+//fvA2nxypKdgyMLpqCIyomBFuCn6OOR8voUfi3BzDjsp08kw== X-Received: by 2002:ac8:3f3b:: with SMTP id c56-v6mr2504344qtk.33.1540910718379; Tue, 30 Oct 2018 07:45:18 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:37 -0500 Message-Id: <20181030144358.23144-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::842 Subject: [Qemu-devel] [PULL 03/24] qga: ignore non present cpus when handling qmp_guest_get_vcpus() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Igor Mammedov If VM has VCPUs plugged sparselly (for example a VM started with 3 VCPUs (cpu0, cpu1 and cpu2) and then cpu1 was hotunplugged so only cpu0 and cpu2 are present), QGA will rise a error error: internal error: unable to execute QEMU agent command 'guest-get-vc= pus': open("/sys/devices/system/cpu/cpu1/"): No such file or directory when virsh vcpucount FOO --guest is executed. Fix it by ignoring non present CPUs when fetching CPUs status from sysfs. Signed-off-by: Igor Mammedov Reviewed-by: Laszlo Ersek Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth --- qga/commands-posix.c | 115 ++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 37e8a2d791..42d30f078e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2035,61 +2035,56 @@ static long sysconf_exact(int name, const char *nam= e_str, Error **errp) * Written members remain unmodified on error. */ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, - Error **errp) + char *dirpath, Error **errp) { - char *dirpath; + int fd; + int res; int dirfd; + static const char fn[] =3D "online"; =20 - dirpath =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", - vcpu->logical_id); dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); if (dirfd =3D=3D -1) { error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - } else { - static const char fn[] =3D "online"; - int fd; - int res; - - fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); - if (fd =3D=3D -1) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, = fn); - } else if (sys2vcpu) { - vcpu->online =3D true; - vcpu->can_offline =3D false; - } else if (!vcpu->online) { - error_setg(errp, "logical processor #%" PRId64 " can't be " - "offlined", vcpu->logical_id); - } /* otherwise pretend successful re-onlining */ - } else { - unsigned char status; - - res =3D pread(fd, &status, 1, 0); - if (res =3D=3D -1) { - error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath,= fn); - } else if (res =3D=3D 0) { - error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpa= th, - fn); - } else if (sys2vcpu) { - vcpu->online =3D (status !=3D '0'); - vcpu->can_offline =3D true; - } else if (vcpu->online !=3D (status !=3D '0')) { - status =3D '0' + vcpu->online; - if (pwrite(fd, &status, 1, 0) =3D=3D -1) { - error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dir= path, - fn); - } - } /* otherwise pretend successful re-(on|off)-lining */ + return; + } =20 - res =3D close(fd); - g_assert(res =3D=3D 0); - } + fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); + if (fd =3D=3D -1) { + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); + } else if (sys2vcpu) { + vcpu->online =3D true; + vcpu->can_offline =3D false; + } else if (!vcpu->online) { + error_setg(errp, "logical processor #%" PRId64 " can't be " + "offlined", vcpu->logical_id); + } /* otherwise pretend successful re-onlining */ + } else { + unsigned char status; + + res =3D pread(fd, &status, 1, 0); + if (res =3D=3D -1) { + error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); + } else if (res =3D=3D 0) { + error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, + fn); + } else if (sys2vcpu) { + vcpu->online =3D (status !=3D '0'); + vcpu->can_offline =3D true; + } else if (vcpu->online !=3D (status !=3D '0')) { + status =3D '0' + vcpu->online; + if (pwrite(fd, &status, 1, 0) =3D=3D -1) { + error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, + fn); + } + } /* otherwise pretend successful re-(on|off)-lining */ =20 - res =3D close(dirfd); + res =3D close(fd); g_assert(res =3D=3D 0); } =20 - g_free(dirpath); + res =3D close(dirfd); + g_assert(res =3D=3D 0); } =20 GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) @@ -2107,17 +2102,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Erro= r **errp) while (local_err =3D=3D NULL && current < sc_max) { GuestLogicalProcessor *vcpu; GuestLogicalProcessorList *entry; - - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D current++; - vcpu->has_can_offline =3D true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, &local_err); - - entry =3D g_malloc0(sizeof *entry); - entry->value =3D vcpu; - - *link =3D entry; - link =3D &entry->next; + int64_t id =3D current++; + char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", + id); + + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + vcpu =3D g_malloc0(sizeof *vcpu); + vcpu->logical_id =3D id; + vcpu->has_can_offline =3D true; /* lolspeak ftw */ + transfer_vcpu(vcpu, true, path, &local_err); + entry =3D g_malloc0(sizeof *entry); + entry->value =3D vcpu; + *link =3D entry; + link =3D &entry->next; + } + g_free(path); } =20 if (local_err =3D=3D NULL) { @@ -2138,7 +2137,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLis= t *vcpus, Error **errp) =20 processed =3D 0; while (vcpus !=3D NULL) { - transfer_vcpu(vcpus->value, false, &local_err); + char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", + vcpus->value->logical_id); + + transfer_vcpu(vcpus->value, false, path, &local_err); + g_free(path); if (local_err !=3D NULL) { break; } --=20 2.17.1