* [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
@ 2020-11-19 6:08 Lin Ma
2020-11-19 6:12 ` no-reply
0 siblings, 1 reply; 6+ messages in thread
From: Lin Ma @ 2020-11-19 6:08 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth, 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
{"execute":"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 <lma@suse.com>
---
qga/commands-posix.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index c089e38120..6452e14a0f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2466,15 +2466,15 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
int64_t current;
GuestLogicalProcessorList *head, **link;
- long sc_max;
+ long max_loop_count;
Error *local_err = NULL;
current = 0;
head = NULL;
link = &head;
- sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
+ max_loop_count = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
- while (local_err == NULL && current < sc_max) {
+ while (local_err == NULL && current < max_loop_count) {
GuestLogicalProcessor *vcpu;
GuestLogicalProcessorList *entry;
int64_t id = current++;
@@ -2491,6 +2491,8 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
*link = entry;
link = &entry->next;
}
+ else
+ max_loop_count += 1;
g_free(path);
}
--
2.29.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
2020-11-19 6:08 [PATCH] qga: Correct loop count in qmp_guest_get_vcpus() Lin Ma
@ 2020-11-19 6:12 ` no-reply
0 siblings, 0 replies; 6+ messages in thread
From: no-reply @ 2020-11-19 6:12 UTC (permalink / raw)
To: lma; +Cc: lma, qemu-devel, mdroth
Patchew URL: https://patchew.org/QEMU/20201119060833.25328-1-lma@suse.com/
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 20201119060833.25328-1-lma@suse.com
Subject: [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/20201119060833.25328-1-lma@suse.com -> patchew/20201119060833.25328-1-lma@suse.com
Switched to a new branch 'test'
1dd28de qga: Correct loop count in qmp_guest_get_vcpus()
=== OUTPUT BEGIN ===
ERROR: else should follow close brace '}'
#91: FILE: qga/commands-posix.c:2494:
}
+ else
ERROR: braces {} are necessary even for single statement blocks
#91: FILE: qga/commands-posix.c:2494:
+ else
+ max_loop_count += 1;
total: 2 errors, 0 warnings, 26 lines checked
Commit 1dd28de20dce (qga: Correct loop count in qmp_guest_get_vcpus()) has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/20201119060833.25328-1-lma@suse.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
2020-11-20 9:28 ` Lin Ma
@ 2020-11-20 9:48 ` Marc-André Lureau
0 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2020-11-20 9:48 UTC (permalink / raw)
To: Lin Ma; +Cc: Michael Roth, QEMU, Lin Ma
[-- Attachment #1: Type: text/plain, Size: 4935 bytes --]
Hi
On Fri, Nov 20, 2020 at 1:28 PM Lin Ma <lma@suse.de> wrote:
> On 2020-11-19 14:46, Marc-André Lureau wrote:
> > Hi
> >
> > On Thu, Nov 19, 2020 at 12:48 PM Lin Ma <lma@suse.com> wrote:
> >
> >> 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
> >> {"execute":"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 <lma@suse.com>
> >> ---
> >> qga/commands-posix.c | 8 +++++---
> >> 1 file changed, 5 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> >> index 3bffee99d4..accc893373 100644
> >> --- a/qga/commands-posix.c
> >> +++ b/qga/commands-posix.c
> >> @@ -2182,15 +2182,15 @@ GuestLogicalProcessorList
> >> *qmp_guest_get_vcpus(Error **errp)
> >> {
> >> int64_t current;
> >> GuestLogicalProcessorList *head, **link;
> >> - long sc_max;
> >> + long max_loop_count;
> >> Error *local_err = NULL;
> >>
> >> current = 0;
> >> head = NULL;
> >> link = &head;
> >> - sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
> >> + max_loop_count = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
> >>
> >> - while (local_err == NULL && current < sc_max) {
> >> + while (local_err == NULL && current < max_loop_count) {
> >> GuestLogicalProcessor *vcpu;
> >> GuestLogicalProcessorList *entry;
> >> int64_t id = current++;
> >> @@ -2206,6 +2206,8 @@ GuestLogicalProcessorList
> >> *qmp_guest_get_vcpus(Error
> >> **errp)
> >> entry->value = vcpu;
> >> *link = entry;
> >> link = &entry->next;
> >> + } else {
> >> + max_loop_count += 1;
> >>
> >
> > This looks like a recipe for infinite loop on error.
> Emm...It is possible.
> >
> > Shouldn't we loop over all the /sys/devices/system/cpu/cpu#/ instead?
> Originally I'd like to use the function fnmatch to handle pattern cpu#
> to
> loop over all of the /sys/devices/system/cpu/cpu#/, But it introduces
> the
> header file fnmatch.h and make things complicated a little.
>
>
Why use fnmatch?
g_dir_open & g_dir_read_name, then you can sscanf for the matching entries.
> >
> > (possibly parse /sys/devices/system/cpu/present, but I doubt it's
> > necessary)
> IMO the 'present' won't help.
>
> I'm about to post the V2, I made tiny change in the V2, Please help to
> review.
>
> BTW, The local_err will be set in case of error, right? It could avoid
> infinite loop.
>
> I think it should.
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 7632 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
2020-11-19 14:46 ` Marc-André Lureau
@ 2020-11-20 9:28 ` Lin Ma
2020-11-20 9:48 ` Marc-André Lureau
0 siblings, 1 reply; 6+ messages in thread
From: Lin Ma @ 2020-11-20 9:28 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: Michael Roth, QEMU, Lin Ma
On 2020-11-19 14:46, Marc-André Lureau wrote:
> Hi
>
> On Thu, Nov 19, 2020 at 12:48 PM Lin Ma <lma@suse.com> wrote:
>
>> 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
>> {"execute":"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 <lma@suse.com>
>> ---
>> qga/commands-posix.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
>> index 3bffee99d4..accc893373 100644
>> --- a/qga/commands-posix.c
>> +++ b/qga/commands-posix.c
>> @@ -2182,15 +2182,15 @@ GuestLogicalProcessorList
>> *qmp_guest_get_vcpus(Error **errp)
>> {
>> int64_t current;
>> GuestLogicalProcessorList *head, **link;
>> - long sc_max;
>> + long max_loop_count;
>> Error *local_err = NULL;
>>
>> current = 0;
>> head = NULL;
>> link = &head;
>> - sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
>> + max_loop_count = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
>>
>> - while (local_err == NULL && current < sc_max) {
>> + while (local_err == NULL && current < max_loop_count) {
>> GuestLogicalProcessor *vcpu;
>> GuestLogicalProcessorList *entry;
>> int64_t id = current++;
>> @@ -2206,6 +2206,8 @@ GuestLogicalProcessorList
>> *qmp_guest_get_vcpus(Error
>> **errp)
>> entry->value = vcpu;
>> *link = entry;
>> link = &entry->next;
>> + } else {
>> + max_loop_count += 1;
>>
>
> This looks like a recipe for infinite loop on error.
Emm...It is possible.
>
> Shouldn't we loop over all the /sys/devices/system/cpu/cpu#/ instead?
Originally I'd like to use the function fnmatch to handle pattern cpu#
to
loop over all of the /sys/devices/system/cpu/cpu#/, But it introduces
the
header file fnmatch.h and make things complicated a little.
>
> (possibly parse /sys/devices/system/cpu/present, but I doubt it's
> necessary)
IMO the 'present' won't help.
I'm about to post the V2, I made tiny change in the V2, Please help to
review.
BTW, The local_err will be set in case of error, right? It could avoid
infinite loop.
Thanks a lot,
Lin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
2020-11-19 8:45 Lin Ma
@ 2020-11-19 14:46 ` Marc-André Lureau
2020-11-20 9:28 ` Lin Ma
0 siblings, 1 reply; 6+ messages in thread
From: Marc-André Lureau @ 2020-11-19 14:46 UTC (permalink / raw)
To: Lin Ma; +Cc: QEMU, Michael Roth
[-- Attachment #1: Type: text/plain, Size: 3835 bytes --]
Hi
On Thu, Nov 19, 2020 at 12:48 PM Lin Ma <lma@suse.com> wrote:
> 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
> {"execute":"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 <lma@suse.com>
> ---
> qga/commands-posix.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 3bffee99d4..accc893373 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -2182,15 +2182,15 @@ GuestLogicalProcessorList
> *qmp_guest_get_vcpus(Error **errp)
> {
> int64_t current;
> GuestLogicalProcessorList *head, **link;
> - long sc_max;
> + long max_loop_count;
> Error *local_err = NULL;
>
> current = 0;
> head = NULL;
> link = &head;
> - sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
> + max_loop_count = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
>
> - while (local_err == NULL && current < sc_max) {
> + while (local_err == NULL && current < max_loop_count) {
> GuestLogicalProcessor *vcpu;
> GuestLogicalProcessorList *entry;
> int64_t id = current++;
> @@ -2206,6 +2206,8 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error
> **errp)
> entry->value = vcpu;
> *link = entry;
> link = &entry->next;
> + } else {
> + max_loop_count += 1;
>
This looks like a recipe for infinite loop on error.
Shouldn't we loop over all the /sys/devices/system/cpu/cpu#/ instead?
(possibly parse /sys/devices/system/cpu/present, but I doubt it's necessary)
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 5562 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] qga: Correct loop count in qmp_guest_get_vcpus()
@ 2020-11-19 8:45 Lin Ma
2020-11-19 14:46 ` Marc-André Lureau
0 siblings, 1 reply; 6+ messages in thread
From: Lin Ma @ 2020-11-19 8:45 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth, 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
{"execute":"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 <lma@suse.com>
---
qga/commands-posix.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 3bffee99d4..accc893373 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2182,15 +2182,15 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
int64_t current;
GuestLogicalProcessorList *head, **link;
- long sc_max;
+ long max_loop_count;
Error *local_err = NULL;
current = 0;
head = NULL;
link = &head;
- sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
+ max_loop_count = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
- while (local_err == NULL && current < sc_max) {
+ while (local_err == NULL && current < max_loop_count) {
GuestLogicalProcessor *vcpu;
GuestLogicalProcessorList *entry;
int64_t id = current++;
@@ -2206,6 +2206,8 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
entry->value = vcpu;
*link = entry;
link = &entry->next;
+ } else {
+ max_loop_count += 1;
}
g_free(path);
}
--
2.26.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-11-20 9:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 6:08 [PATCH] qga: Correct loop count in qmp_guest_get_vcpus() Lin Ma
2020-11-19 6:12 ` no-reply
2020-11-19 8:45 Lin Ma
2020-11-19 14:46 ` Marc-André Lureau
2020-11-20 9:28 ` Lin Ma
2020-11-20 9:48 ` Marc-André Lureau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.