|
|
b11fdf |
From 34ff13c0974bf94c3e61b0b8af8134a6933194ea Mon Sep 17 00:00:00 2001
|
|
|
b11fdf |
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
|
|
|
b11fdf |
Date: Thu, 15 Nov 2018 09:45:19 +0100
|
|
|
b11fdf |
Subject: [PATCH 1/5] qga: ignore non present cpus when handling
|
|
|
b11fdf |
qmp_guest_get_vcpus()
|
|
|
b11fdf |
MIME-Version: 1.0
|
|
|
b11fdf |
Content-Type: text/plain; charset=UTF-8
|
|
|
b11fdf |
Content-Transfer-Encoding: 8bit
|
|
|
b11fdf |
|
|
|
b11fdf |
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
b11fdf |
Message-id: <20181115094519.22641-1-marcandre.lureau@redhat.com>
|
|
|
b11fdf |
Patchwork-id: 83030
|
|
|
b11fdf |
O-Subject: [RHEL-7.7 qemu-guest-agent PATCH] qga: ignore non present cpus when handling qmp_guest_get_vcpus()
|
|
|
b11fdf |
Bugzilla: 1611062
|
|
|
b11fdf |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
b11fdf |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
b11fdf |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
b11fdf |
|
|
|
b11fdf |
From: Igor Mammedov <imammedo@redhat.com>
|
|
|
b11fdf |
|
|
|
b11fdf |
If VM has VCPUs plugged sparselly (for example a VM started with
|
|
|
b11fdf |
3 VCPUs (cpu0, cpu1 and cpu2) and then cpu1 was hotunplugged so
|
|
|
b11fdf |
only cpu0 and cpu2 are present), QGA will rise a error
|
|
|
b11fdf |
error: internal error: unable to execute QEMU agent command 'guest-get-vcpus':
|
|
|
b11fdf |
open("/sys/devices/system/cpu/cpu1/"): No such file or directory
|
|
|
b11fdf |
when
|
|
|
b11fdf |
virsh vcpucount FOO --guest
|
|
|
b11fdf |
is executed.
|
|
|
b11fdf |
Fix it by ignoring non present CPUs when fetching CPUs status from sysfs.
|
|
|
b11fdf |
|
|
|
b11fdf |
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
b11fdf |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
b11fdf |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
b11fdf |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
b11fdf |
|
|
|
b11fdf |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1611062
|
|
|
b11fdf |
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=19189361
|
|
|
b11fdf |
|
|
|
b11fdf |
(cherry picked from commit b4bf912a6c19449e68af7b4173a8c6da21904d99)
|
|
|
b11fdf |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
b11fdf |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
b11fdf |
---
|
|
|
b11fdf |
qga/commands-posix.c | 115 ++++++++++++++++++++++++++-------------------------
|
|
|
b11fdf |
1 file changed, 59 insertions(+), 56 deletions(-)
|
|
|
b11fdf |
|
|
|
b11fdf |
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
|
|
|
b11fdf |
index 26c1863..f4d9380 100644
|
|
|
b11fdf |
--- a/qga/commands-posix.c
|
|
|
b11fdf |
+++ b/qga/commands-posix.c
|
|
|
b11fdf |
@@ -1913,61 +1913,56 @@ static long sysconf_exact(int name, const char *name_str, Error **errp)
|
|
|
b11fdf |
* Written members remain unmodified on error.
|
|
|
b11fdf |
*/
|
|
|
b11fdf |
static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
|
|
|
b11fdf |
- Error **errp)
|
|
|
b11fdf |
+ char *dirpath, Error **errp)
|
|
|
b11fdf |
{
|
|
|
b11fdf |
- char *dirpath;
|
|
|
b11fdf |
+ int fd;
|
|
|
b11fdf |
+ int res;
|
|
|
b11fdf |
int dirfd;
|
|
|
b11fdf |
+ static const char fn[] = "online";
|
|
|
b11fdf |
|
|
|
b11fdf |
- dirpath = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
|
|
b11fdf |
- vcpu->logical_id);
|
|
|
b11fdf |
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
|
|
|
b11fdf |
if (dirfd == -1) {
|
|
|
b11fdf |
error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
|
|
|
b11fdf |
- } else {
|
|
|
b11fdf |
- static const char fn[] = "online";
|
|
|
b11fdf |
- int fd;
|
|
|
b11fdf |
- int res;
|
|
|
b11fdf |
-
|
|
|
b11fdf |
- fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
|
|
|
b11fdf |
- if (fd == -1) {
|
|
|
b11fdf |
- if (errno != ENOENT) {
|
|
|
b11fdf |
- error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
|
|
|
b11fdf |
- } else if (sys2vcpu) {
|
|
|
b11fdf |
- vcpu->online = true;
|
|
|
b11fdf |
- vcpu->can_offline = false;
|
|
|
b11fdf |
- } else if (!vcpu->online) {
|
|
|
b11fdf |
- error_setg(errp, "logical processor #%" PRId64 " can't be "
|
|
|
b11fdf |
- "offlined", vcpu->logical_id);
|
|
|
b11fdf |
- } /* otherwise pretend successful re-onlining */
|
|
|
b11fdf |
- } else {
|
|
|
b11fdf |
- unsigned char status;
|
|
|
b11fdf |
-
|
|
|
b11fdf |
- res = pread(fd, &status, 1, 0);
|
|
|
b11fdf |
- if (res == -1) {
|
|
|
b11fdf |
- error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
|
|
|
b11fdf |
- } else if (res == 0) {
|
|
|
b11fdf |
- error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
|
|
|
b11fdf |
- fn);
|
|
|
b11fdf |
- } else if (sys2vcpu) {
|
|
|
b11fdf |
- vcpu->online = (status != '0');
|
|
|
b11fdf |
- vcpu->can_offline = true;
|
|
|
b11fdf |
- } else if (vcpu->online != (status != '0')) {
|
|
|
b11fdf |
- status = '0' + vcpu->online;
|
|
|
b11fdf |
- if (pwrite(fd, &status, 1, 0) == -1) {
|
|
|
b11fdf |
- error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
|
|
|
b11fdf |
- fn);
|
|
|
b11fdf |
- }
|
|
|
b11fdf |
- } /* otherwise pretend successful re-(on|off)-lining */
|
|
|
b11fdf |
+ return;
|
|
|
b11fdf |
+ }
|
|
|
b11fdf |
|
|
|
b11fdf |
- res = close(fd);
|
|
|
b11fdf |
- g_assert(res == 0);
|
|
|
b11fdf |
- }
|
|
|
b11fdf |
+ fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
|
|
|
b11fdf |
+ if (fd == -1) {
|
|
|
b11fdf |
+ if (errno != ENOENT) {
|
|
|
b11fdf |
+ error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
|
|
|
b11fdf |
+ } else if (sys2vcpu) {
|
|
|
b11fdf |
+ vcpu->online = true;
|
|
|
b11fdf |
+ vcpu->can_offline = false;
|
|
|
b11fdf |
+ } else if (!vcpu->online) {
|
|
|
b11fdf |
+ error_setg(errp, "logical processor #%" PRId64 " can't be "
|
|
|
b11fdf |
+ "offlined", vcpu->logical_id);
|
|
|
b11fdf |
+ } /* otherwise pretend successful re-onlining */
|
|
|
b11fdf |
+ } else {
|
|
|
b11fdf |
+ unsigned char status;
|
|
|
b11fdf |
+
|
|
|
b11fdf |
+ res = pread(fd, &status, 1, 0);
|
|
|
b11fdf |
+ if (res == -1) {
|
|
|
b11fdf |
+ error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
|
|
|
b11fdf |
+ } else if (res == 0) {
|
|
|
b11fdf |
+ error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
|
|
|
b11fdf |
+ fn);
|
|
|
b11fdf |
+ } else if (sys2vcpu) {
|
|
|
b11fdf |
+ vcpu->online = (status != '0');
|
|
|
b11fdf |
+ vcpu->can_offline = true;
|
|
|
b11fdf |
+ } else if (vcpu->online != (status != '0')) {
|
|
|
b11fdf |
+ status = '0' + vcpu->online;
|
|
|
b11fdf |
+ if (pwrite(fd, &status, 1, 0) == -1) {
|
|
|
b11fdf |
+ error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
|
|
|
b11fdf |
+ fn);
|
|
|
b11fdf |
+ }
|
|
|
b11fdf |
+ } /* otherwise pretend successful re-(on|off)-lining */
|
|
|
b11fdf |
|
|
|
b11fdf |
- res = close(dirfd);
|
|
|
b11fdf |
+ res = close(fd);
|
|
|
b11fdf |
g_assert(res == 0);
|
|
|
b11fdf |
}
|
|
|
b11fdf |
|
|
|
b11fdf |
- g_free(dirpath);
|
|
|
b11fdf |
+ res = close(dirfd);
|
|
|
b11fdf |
+ g_assert(res == 0);
|
|
|
b11fdf |
}
|
|
|
b11fdf |
|
|
|
b11fdf |
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
|
|
b11fdf |
@@ -1985,17 +1980,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
|
|
b11fdf |
while (local_err == NULL && current < sc_max) {
|
|
|
b11fdf |
GuestLogicalProcessor *vcpu;
|
|
|
b11fdf |
GuestLogicalProcessorList *entry;
|
|
|
b11fdf |
-
|
|
|
b11fdf |
- vcpu = g_malloc0(sizeof *vcpu);
|
|
|
b11fdf |
- vcpu->logical_id = current++;
|
|
|
b11fdf |
- vcpu->has_can_offline = true; /* lolspeak ftw */
|
|
|
b11fdf |
- transfer_vcpu(vcpu, true, &local_err);
|
|
|
b11fdf |
-
|
|
|
b11fdf |
- entry = g_malloc0(sizeof *entry);
|
|
|
b11fdf |
- entry->value = vcpu;
|
|
|
b11fdf |
-
|
|
|
b11fdf |
- *link = entry;
|
|
|
b11fdf |
- link = &entry->next;
|
|
|
b11fdf |
+ int64_t id = current++;
|
|
|
b11fdf |
+ char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
|
|
b11fdf |
+ id);
|
|
|
b11fdf |
+
|
|
|
b11fdf |
+ if (g_file_test(path, G_FILE_TEST_EXISTS)) {
|
|
|
b11fdf |
+ vcpu = g_malloc0(sizeof *vcpu);
|
|
|
b11fdf |
+ vcpu->logical_id = id;
|
|
|
b11fdf |
+ vcpu->has_can_offline = true; /* lolspeak ftw */
|
|
|
b11fdf |
+ transfer_vcpu(vcpu, true, path, &local_err);
|
|
|
b11fdf |
+ entry = g_malloc0(sizeof *entry);
|
|
|
b11fdf |
+ entry->value = vcpu;
|
|
|
b11fdf |
+ *link = entry;
|
|
|
b11fdf |
+ link = &entry->next;
|
|
|
b11fdf |
+ }
|
|
|
b11fdf |
+ g_free(path);
|
|
|
b11fdf |
}
|
|
|
b11fdf |
|
|
|
b11fdf |
if (local_err == NULL) {
|
|
|
b11fdf |
@@ -2016,7 +2015,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)
|
|
|
b11fdf |
|
|
|
b11fdf |
processed = 0;
|
|
|
b11fdf |
while (vcpus != NULL) {
|
|
|
b11fdf |
- transfer_vcpu(vcpus->value, false, &local_err);
|
|
|
b11fdf |
+ char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
|
|
b11fdf |
+ vcpus->value->logical_id);
|
|
|
b11fdf |
+
|
|
|
b11fdf |
+ transfer_vcpu(vcpus->value, false, path, &local_err);
|
|
|
b11fdf |
+ g_free(path);
|
|
|
b11fdf |
if (local_err != NULL) {
|
|
|
b11fdf |
break;
|
|
|
b11fdf |
}
|
|
|
b11fdf |
--
|
|
|
b11fdf |
1.8.3.1
|
|
|
b11fdf |
|