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