mirror of https://github.com/xqemu/xqemu.git
qga: ignore non present cpus when handling qmp_guest_get_vcpus()
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-vcpus': 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 <imammedo@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
0692b03ee1
commit
b4bf912a6c
|
@ -2035,61 +2035,56 @@ static long sysconf_exact(int name, const char *name_str, Error **errp)
|
||||||
* Written members remain unmodified on error.
|
* Written members remain unmodified on error.
|
||||||
*/
|
*/
|
||||||
static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
|
static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
|
||||||
Error **errp)
|
char *dirpath, Error **errp)
|
||||||
{
|
{
|
||||||
char *dirpath;
|
int fd;
|
||||||
|
int res;
|
||||||
int dirfd;
|
int dirfd;
|
||||||
|
static const char fn[] = "online";
|
||||||
|
|
||||||
dirpath = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
|
||||||
vcpu->logical_id);
|
|
||||||
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
|
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
|
||||||
if (dirfd == -1) {
|
if (dirfd == -1) {
|
||||||
error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
|
error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
|
||||||
|
if (fd == -1) {
|
||||||
|
if (errno != ENOENT) {
|
||||||
|
error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
|
||||||
|
} else if (sys2vcpu) {
|
||||||
|
vcpu->online = true;
|
||||||
|
vcpu->can_offline = false;
|
||||||
|
} else if (!vcpu->online) {
|
||||||
|
error_setg(errp, "logical processor #%" PRId64 " can't be "
|
||||||
|
"offlined", vcpu->logical_id);
|
||||||
|
} /* otherwise pretend successful re-onlining */
|
||||||
} else {
|
} else {
|
||||||
static const char fn[] = "online";
|
unsigned char status;
|
||||||
int fd;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
|
res = pread(fd, &status, 1, 0);
|
||||||
if (fd == -1) {
|
if (res == -1) {
|
||||||
if (errno != ENOENT) {
|
error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
|
||||||
error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
|
} else if (res == 0) {
|
||||||
} else if (sys2vcpu) {
|
error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
|
||||||
vcpu->online = true;
|
fn);
|
||||||
vcpu->can_offline = false;
|
} else if (sys2vcpu) {
|
||||||
} else if (!vcpu->online) {
|
vcpu->online = (status != '0');
|
||||||
error_setg(errp, "logical processor #%" PRId64 " can't be "
|
vcpu->can_offline = true;
|
||||||
"offlined", vcpu->logical_id);
|
} else if (vcpu->online != (status != '0')) {
|
||||||
} /* otherwise pretend successful re-onlining */
|
status = '0' + vcpu->online;
|
||||||
} else {
|
if (pwrite(fd, &status, 1, 0) == -1) {
|
||||||
unsigned char status;
|
error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
|
||||||
|
fn);
|
||||||
|
}
|
||||||
|
} /* otherwise pretend successful re-(on|off)-lining */
|
||||||
|
|
||||||
res = pread(fd, &status, 1, 0);
|
res = close(fd);
|
||||||
if (res == -1) {
|
|
||||||
error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn);
|
|
||||||
} else if (res == 0) {
|
|
||||||
error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath,
|
|
||||||
fn);
|
|
||||||
} else if (sys2vcpu) {
|
|
||||||
vcpu->online = (status != '0');
|
|
||||||
vcpu->can_offline = true;
|
|
||||||
} else if (vcpu->online != (status != '0')) {
|
|
||||||
status = '0' + vcpu->online;
|
|
||||||
if (pwrite(fd, &status, 1, 0) == -1) {
|
|
||||||
error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath,
|
|
||||||
fn);
|
|
||||||
}
|
|
||||||
} /* otherwise pretend successful re-(on|off)-lining */
|
|
||||||
|
|
||||||
res = close(fd);
|
|
||||||
g_assert(res == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
res = close(dirfd);
|
|
||||||
g_assert(res == 0);
|
g_assert(res == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(dirpath);
|
res = close(dirfd);
|
||||||
|
g_assert(res == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
||||||
|
@ -2107,17 +2102,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
||||||
while (local_err == NULL && current < sc_max) {
|
while (local_err == NULL && current < sc_max) {
|
||||||
GuestLogicalProcessor *vcpu;
|
GuestLogicalProcessor *vcpu;
|
||||||
GuestLogicalProcessorList *entry;
|
GuestLogicalProcessorList *entry;
|
||||||
|
int64_t id = current++;
|
||||||
|
char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
||||||
|
id);
|
||||||
|
|
||||||
vcpu = g_malloc0(sizeof *vcpu);
|
if (g_file_test(path, G_FILE_TEST_EXISTS)) {
|
||||||
vcpu->logical_id = current++;
|
vcpu = g_malloc0(sizeof *vcpu);
|
||||||
vcpu->has_can_offline = true; /* lolspeak ftw */
|
vcpu->logical_id = id;
|
||||||
transfer_vcpu(vcpu, true, &local_err);
|
vcpu->has_can_offline = true; /* lolspeak ftw */
|
||||||
|
transfer_vcpu(vcpu, true, path, &local_err);
|
||||||
entry = g_malloc0(sizeof *entry);
|
entry = g_malloc0(sizeof *entry);
|
||||||
entry->value = vcpu;
|
entry->value = vcpu;
|
||||||
|
*link = entry;
|
||||||
*link = entry;
|
link = &entry->next;
|
||||||
link = &entry->next;
|
}
|
||||||
|
g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_err == NULL) {
|
if (local_err == NULL) {
|
||||||
|
@ -2138,7 +2137,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)
|
||||||
|
|
||||||
processed = 0;
|
processed = 0;
|
||||||
while (vcpus != NULL) {
|
while (vcpus != NULL) {
|
||||||
transfer_vcpu(vcpus->value, false, &local_err);
|
char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
|
||||||
|
vcpus->value->logical_id);
|
||||||
|
|
||||||
|
transfer_vcpu(vcpus->value, false, path, &local_err);
|
||||||
|
g_free(path);
|
||||||
if (local_err != NULL) {
|
if (local_err != NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue