From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEA14C3DA45 for ; Fri, 12 Jul 2024 08:31:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSBgZ-0000CU-9X; Fri, 12 Jul 2024 04:31:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSBgT-0008PJ-5y for qemu-devel@nongnu.org; Fri, 12 Jul 2024 04:31:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSBgN-0006jb-7M for qemu-devel@nongnu.org; Fri, 12 Jul 2024 04:31:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720773066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eNxysIzpNpUsVYWY/XtUS6B42bIF67boJ1ZJIdS5J/M=; b=iF8SIr5dqbYrsi7kD9/do8d1F4wAKkLXmnuTjPd0f4NxFA81S2lVhxUx9xxBGwFEEOpVbA tE/yoRl6cwc0UFknUUBzAgPc1yU+FuadjyXuGDdu5DU6aWRB+8/clVGHGxxrBkD/5B7ldL RrQzSHtDuDjf9yh9ibkNAvR+/EzZCMk= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-X9hvoNK5MnWFrVRnb-dJjQ-1; Fri, 12 Jul 2024 04:31:02 -0400 X-MC-Unique: X9hvoNK5MnWFrVRnb-dJjQ-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-653306993a8so29759427b3.1 for ; Fri, 12 Jul 2024 01:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720773062; x=1721377862; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eNxysIzpNpUsVYWY/XtUS6B42bIF67boJ1ZJIdS5J/M=; b=Xmhkf1pL8Ps7hLSrVC+rDozqyFnHkMljBTmGo0J/Jj0oD+9k3NDkaIn1iXvgENlV5Q +PgkpS28eVdZUTZiCIigWD/MOJPdU/GFVK8uFxclmEvttdmZQim+VEOW0bYXgttKLTcb BourXrBH2F8DpQEC6UGt7/120Te5E4xYUNCEVYLWf+hfImOFfBd23beMbQTaNPoPAUGQ KvVw5IreuQAXAqO2W5MtPD4PTuTRaKaBHOIt2YMhWwwao3tMph4e7RXajiyW8W92S+ss lt+fTU0cR92umycutNjdvSPE3Fx3toqET5xNdwhtkG0JD3ajutFWFWqXxWR1g18rONmf Btdw== X-Gm-Message-State: AOJu0YwJvFVFl8O/UfVT6iO60/K5QeYC+XxIO3co9g5bvJsbjSMhrsiJ qCpMiKjhYv28p9747QyvWCP6pKckiZK1jYGEEm4K9jwac6Y0PUdT2fI8gKkOpwqfIdQm0seNvoY Nkp0uujJ/VKkya46ZN57zx3ZnFGsNnaFFtYpm5VUGtxSb4jOZSpDQdjqNdcMUa4SWr/AnCQ4FYr j1975jxowiBH1jiH1doaSVvkkxsQ8= X-Received: by 2002:a0d:eb8f:0:b0:645:44d:82cf with SMTP id 00721157ae682-658ee790cf8mr121660927b3.1.1720773061777; Fri, 12 Jul 2024 01:31:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcU25kLZ+HwdSvi8pgqfeV/ePoOsS/0FmgD7/b64ZQyHn53iIASs4L/jeGso1lZCByREsV24C07dhuS45iXAI= X-Received: by 2002:a0d:eb8f:0:b0:645:44d:82cf with SMTP id 00721157ae682-658ee790cf8mr121660717b3.1.1720773061356; Fri, 12 Jul 2024 01:31:01 -0700 (PDT) MIME-Version: 1.0 References: <20240613150127.1361931-1-berrange@redhat.com> <20240613150127.1361931-3-berrange@redhat.com> In-Reply-To: <20240613150127.1361931-3-berrange@redhat.com> From: Konstantin Kostiuk Date: Fri, 12 Jul 2024 11:30:50 +0300 Message-ID: Subject: Re: [PATCH v2 02/22] qga: move linux vcpu command impls to commands-linux.c To: =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= Cc: qemu-devel@nongnu.org, =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Michael Roth , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= , Thomas Huth , Paolo Bonzini , Manos Pitsidianakis Content-Type: multipart/alternative; boundary="0000000000000fbff7061d08b3b0" Received-SPF: pass client-ip=170.10.129.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --0000000000000fbff7061d08b3b0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Reviewed-by: Konstantin Kostiuk On Thu, Jun 13, 2024 at 6:02=E2=80=AFPM Daniel P. Berrang=C3=A9 wrote: > The qmp_guest_set_vcpus and qmp_guest_get_vcpus command impls in > commands-posix.c are surrounded by '#ifdef __linux__' so should > instead live in commands-linux.c > > Reviewed-by: Manos Pitsidianakis > Signed-off-by: Daniel P. Berrang=C3=A9 > --- > qga/commands-linux.c | 141 +++++++++++++++++++++++++++++++++++++++++++ > qga/commands-posix.c | 139 ------------------------------------------ > 2 files changed, 141 insertions(+), 139 deletions(-) > > diff --git a/qga/commands-linux.c b/qga/commands-linux.c > index 214e408fcd..78580ac39d 100644 > --- a/qga/commands-linux.c > +++ b/qga/commands-linux.c > @@ -13,6 +13,7 @@ > > #include "qemu/osdep.h" > #include "qapi/error.h" > +#include "qga-qapi-commands.h" > #include "commands-common.h" > #include "cutils.h" > #include > @@ -284,3 +285,143 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) > return i; > } > #endif /* CONFIG_FSFREEZE */ > + > +/* Transfer online/offline status between @vcpu and the guest system. > + * > + * On input either @errp or *@errp must be NULL. > + * > + * In system-to-@vcpu direction, the following @vcpu fields are accessed= : > + * - R: vcpu->logical_id > + * - W: vcpu->online > + * - W: vcpu->can_offline > + * > + * In @vcpu-to-system direction, the following @vcpu fields are accessed= : > + * - R: vcpu->logical_id > + * - R: vcpu->online > + * > + * Written members remain unmodified on error. > + */ > +static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, > + char *dirpath, Error **errp) > +{ > + int fd; > + int res; > + int dirfd; > + static const char fn[] =3D "online"; > + > + dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); > + if (dirfd =3D=3D -1) { > + error_setg_errno(errp, errno, "open(\"%s\")", dirpath); > + return; > + } > + > + 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 */ > + > + res =3D close(fd); > + g_assert(res =3D=3D 0); > + } > + > + res =3D close(dirfd); > + g_assert(res =3D=3D 0); > +} > + > +GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) > +{ > + GuestLogicalProcessorList *head, **tail; > + const char *cpu_dir =3D "/sys/devices/system/cpu"; > + const gchar *line; > + g_autoptr(GDir) cpu_gdir =3D NULL; > + Error *local_err =3D NULL; > + > + head =3D NULL; > + tail =3D &head; > + cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL); > + > + if (cpu_gdir =3D=3D NULL) { > + error_setg_errno(errp, errno, "failed to list entries: %s", > cpu_dir); > + return NULL; > + } > + > + while (local_err =3D=3D NULL && (line =3D g_dir_read_name(cpu_gdir))= !=3D > NULL) { > + GuestLogicalProcessor *vcpu; > + int64_t id; > + if (sscanf(line, "cpu%" PRId64, &id)) { > + g_autofree char *path =3D > g_strdup_printf("/sys/devices/system/cpu/" > + "cpu%" PRId64 "/", > id); > + 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); > + QAPI_LIST_APPEND(tail, vcpu); > + } > + } > + > + if (local_err =3D=3D NULL) { > + /* there's no guest with zero VCPUs */ > + g_assert(head !=3D NULL); > + return head; > + } > + > + qapi_free_GuestLogicalProcessorList(head); > + error_propagate(errp, local_err); > + return NULL; > +} > + > +int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error > **errp) > +{ > + int64_t processed; > + Error *local_err =3D NULL; > + > + processed =3D 0; > + while (vcpus !=3D NULL) { > + char *path =3D 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 !=3D NULL) { > + break; > + } > + ++processed; > + vcpus =3D vcpus->next; > + } > + > + if (local_err !=3D NULL) { > + if (processed =3D=3D 0) { > + error_propagate(errp, local_err); > + } else { > + error_free(local_err); > + } > + } > + > + return processed; > +} > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 76af98ba32..a8ef41f175 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -2003,145 +2003,6 @@ void qmp_guest_suspend_hybrid(Error **errp) > guest_suspend(SUSPEND_MODE_HYBRID, errp); > } > > -/* Transfer online/offline status between @vcpu and the guest system. > - * > - * On input either @errp or *@errp must be NULL. > - * > - * In system-to-@vcpu direction, the following @vcpu fields are accessed= : > - * - R: vcpu->logical_id > - * - W: vcpu->online > - * - W: vcpu->can_offline > - * > - * In @vcpu-to-system direction, the following @vcpu fields are accessed= : > - * - R: vcpu->logical_id > - * - R: vcpu->online > - * > - * Written members remain unmodified on error. > - */ > -static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, > - char *dirpath, Error **errp) > -{ > - int fd; > - int res; > - int dirfd; > - static const char fn[] =3D "online"; > - > - dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); > - if (dirfd =3D=3D -1) { > - error_setg_errno(errp, errno, "open(\"%s\")", dirpath); > - return; > - } > - > - 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 */ > - > - res =3D close(fd); > - g_assert(res =3D=3D 0); > - } > - > - res =3D close(dirfd); > - g_assert(res =3D=3D 0); > -} > - > -GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) > -{ > - GuestLogicalProcessorList *head, **tail; > - const char *cpu_dir =3D "/sys/devices/system/cpu"; > - const gchar *line; > - g_autoptr(GDir) cpu_gdir =3D NULL; > - Error *local_err =3D NULL; > - > - head =3D NULL; > - tail =3D &head; > - cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL); > - > - if (cpu_gdir =3D=3D NULL) { > - error_setg_errno(errp, errno, "failed to list entries: %s", > cpu_dir); > - return NULL; > - } > - > - while (local_err =3D=3D NULL && (line =3D g_dir_read_name(cpu_gdir))= !=3D > NULL) { > - GuestLogicalProcessor *vcpu; > - int64_t id; > - if (sscanf(line, "cpu%" PRId64, &id)) { > - g_autofree char *path =3D > g_strdup_printf("/sys/devices/system/cpu/" > - "cpu%" PRId64 "/", > id); > - 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); > - QAPI_LIST_APPEND(tail, vcpu); > - } > - } > - > - if (local_err =3D=3D NULL) { > - /* there's no guest with zero VCPUs */ > - g_assert(head !=3D NULL); > - return head; > - } > - > - qapi_free_GuestLogicalProcessorList(head); > - error_propagate(errp, local_err); > - return NULL; > -} > - > -int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error > **errp) > -{ > - int64_t processed; > - Error *local_err =3D NULL; > - > - processed =3D 0; > - while (vcpus !=3D NULL) { > - char *path =3D 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 !=3D NULL) { > - break; > - } > - ++processed; > - vcpus =3D vcpus->next; > - } > - > - if (local_err !=3D NULL) { > - if (processed =3D=3D 0) { > - error_propagate(errp, local_err); > - } else { > - error_free(local_err); > - } > - } > - > - return processed; > -} > #endif /* __linux__ */ > > #if defined(__linux__) || defined(__FreeBSD__) > -- > 2.45.1 > > --0000000000000fbff7061d08b3b0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On Thu, Jun 13, 2024 at 6:02=E2= =80=AFPM Daniel P. Berrang=C3=A9 <berrange@redhat.com> wrote:
The qmp_guest_set_vcpus and qmp_guest_get_vcpus command= impls in
commands-posix.c are surrounded by '#ifdef __linux__' so should
instead live in commands-linux.c

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Daniel P. Berrang=C3=A9 <berrange@redhat.com>
---
=C2=A0qga/commands-linux.c | 141 ++++++++++++++++++++++++++++++++++++++++++= +
=C2=A0qga/commands-posix.c | 139 ------------------------------------------=
=C2=A02 files changed, 141 insertions(+), 139 deletions(-)

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 214e408fcd..78580ac39d 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -13,6 +13,7 @@

=C2=A0#include "qemu/osdep.h"
=C2=A0#include "qapi/error.h"
+#include "qga-qapi-commands.h"
=C2=A0#include "commands-common.h"
=C2=A0#include "cutils.h"
=C2=A0#include <mntent.h>
@@ -284,3 +285,143 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp)
=C2=A0 =C2=A0 =C2=A0return i;
=C2=A0}
=C2=A0#endif /* CONFIG_FSFREEZE */
+
+/* Transfer online/offline status between @vcpu and the guest system.
+ *
+ * On input either @errp or *@errp must be NULL.
+ *
+ * In system-to-@vcpu direction, the following @vcpu fields are accessed:<= br> + * - R: vcpu->logical_id
+ * - W: vcpu->online
+ * - W: vcpu->can_offline
+ *
+ * In @vcpu-to-system direction, the following @vcpu fields are accessed:<= br> + * - R: vcpu->logical_id
+ * - R: vcpu->online
+ *
+ * Written members remain unmodified on error.
+ */
+static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 char *dirpath, Error **errp)
+{
+=C2=A0 =C2=A0 int fd;
+=C2=A0 =C2=A0 int res;
+=C2=A0 =C2=A0 int dirfd;
+=C2=A0 =C2=A0 static const char fn[] =3D "online";
+
+=C2=A0 =C2=A0 dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY);
+=C2=A0 =C2=A0 if (dirfd =3D=3D -1) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, "open(\&quo= t;%s\")", dirpath);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
+=C2=A0 =C2=A0 if (fd =3D=3D -1) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (errno !=3D ENOENT) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, &q= uot;open(\"%s/%s\")", dirpath, fn);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (sys2vcpu) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->online =3D true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->can_offline =3D false;<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (!vcpu->online) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "logical p= rocessor #%" PRId64 " can't be "
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"offlined", vcpu->logical_id);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } /* otherwise pretend successful re-onlining = */
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned char status;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 res =3D pread(fd, &status, 1, 0);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (res =3D=3D -1) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, &q= uot;pread(\"%s/%s\")", dirpath, fn);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (res =3D=3D 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "pread(\&q= uot;%s/%s\"): unexpected EOF", dirpath,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0fn);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (sys2vcpu) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->online =3D (status !=3D= '0');
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->can_offline =3D true; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (vcpu->online !=3D (status !=3D &= #39;0')) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D '0' + vcpu-&g= t;online;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (pwrite(fd, &status, 1, 0= ) =3D=3D -1) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(e= rrp, errno, "pwrite(\"%s/%s\")", dirpath,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fn);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } /* otherwise pretend successful re-(on|off)-= lining */
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 res =3D close(fd);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_assert(res =3D=3D 0);
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 res =3D close(dirfd);
+=C2=A0 =C2=A0 g_assert(res =3D=3D 0);
+}
+
+GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
+{
+=C2=A0 =C2=A0 GuestLogicalProcessorList *head, **tail;
+=C2=A0 =C2=A0 const char *cpu_dir =3D "/sys/devices/system/cpu";=
+=C2=A0 =C2=A0 const gchar *line;
+=C2=A0 =C2=A0 g_autoptr(GDir) cpu_gdir =3D NULL;
+=C2=A0 =C2=A0 Error *local_err =3D NULL;
+
+=C2=A0 =C2=A0 head =3D NULL;
+=C2=A0 =C2=A0 tail =3D &head;
+=C2=A0 =C2=A0 cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL);
+
+=C2=A0 =C2=A0 if (cpu_gdir =3D=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, "failed to = list entries: %s", cpu_dir);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 while (local_err =3D=3D NULL && (line =3D g_dir_read= _name(cpu_gdir)) !=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 GuestLogicalProcessor *vcpu;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 int64_t id;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (sscanf(line, "cpu%" PRId64, &= ;id)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_autofree char *path =3D g_strd= up_printf("/sys/devices/system/cpu/"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "cpu%" PRId64 "/", i= d);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu =3D g_malloc0(sizeof *vcpu)= ;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->logical_id =3D id;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->has_can_offline =3D tru= e; /* lolspeak ftw */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 transfer_vcpu(vcpu, true, path, = &local_err);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QAPI_LIST_APPEND(tail, vcpu); +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 if (local_err =3D=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* there's no guest with zero VCPUs */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_assert(head !=3D NULL);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return head;
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 qapi_free_GuestLogicalProcessorList(head);
+=C2=A0 =C2=A0 error_propagate(errp, local_err);
+=C2=A0 =C2=A0 return NULL;
+}
+
+int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp= )
+{
+=C2=A0 =C2=A0 int64_t processed;
+=C2=A0 =C2=A0 Error *local_err =3D NULL;
+
+=C2=A0 =C2=A0 processed =3D 0;
+=C2=A0 =C2=A0 while (vcpus !=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 char *path =3D g_strdup_printf("/sys/devi= ces/system/cpu/cpu%" PRId64 "/",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0vcpus->value-= >logical_id);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 transfer_vcpu(vcpus->value, false, path, &a= mp;local_err);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_free(path);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (local_err !=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ++processed;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpus =3D vcpus->next;
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 if (local_err !=3D NULL) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (processed =3D=3D 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_propagate(errp, local_err)= ;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_free(local_err);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 return processed;
+}
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 76af98ba32..a8ef41f175 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2003,145 +2003,6 @@ void qmp_guest_suspend_hybrid(Error **errp)
=C2=A0 =C2=A0 =C2=A0guest_suspend(SUSPEND_MODE_HYBRID, errp);
=C2=A0}

-/* Transfer online/offline status between @vcpu and the guest system.
- *
- * On input either @errp or *@errp must be NULL.
- *
- * In system-to-@vcpu direction, the following @vcpu fields are accessed:<= br> - * - R: vcpu->logical_id
- * - W: vcpu->online
- * - W: vcpu->can_offline
- *
- * In @vcpu-to-system direction, the following @vcpu fields are accessed:<= br> - * - R: vcpu->logical_id
- * - R: vcpu->online
- *
- * Written members remain unmodified on error.
- */
-static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 char *dirpath, Error **errp)
-{
-=C2=A0 =C2=A0 int fd;
-=C2=A0 =C2=A0 int res;
-=C2=A0 =C2=A0 int dirfd;
-=C2=A0 =C2=A0 static const char fn[] =3D "online";
-
-=C2=A0 =C2=A0 dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY);
-=C2=A0 =C2=A0 if (dirfd =3D=3D -1) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, "open(\&quo= t;%s\")", dirpath);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
-=C2=A0 =C2=A0 if (fd =3D=3D -1) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (errno !=3D ENOENT) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, &q= uot;open(\"%s/%s\")", dirpath, fn);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (sys2vcpu) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->online =3D true;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->can_offline =3D false;<= br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (!vcpu->online) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "logical p= rocessor #%" PRId64 " can't be "
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"offlined", vcpu->logical_id);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } /* otherwise pretend successful re-onlining = */
-=C2=A0 =C2=A0 } else {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned char status;
-
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 res =3D pread(fd, &status, 1, 0);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (res =3D=3D -1) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, &q= uot;pread(\"%s/%s\")", dirpath, fn);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (res =3D=3D 0) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "pread(\&q= uot;%s/%s\"): unexpected EOF", dirpath,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0fn);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (sys2vcpu) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->online =3D (status !=3D= '0');
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->can_offline =3D true; -=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (vcpu->online !=3D (status !=3D &= #39;0')) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D '0' + vcpu-&g= t;online;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (pwrite(fd, &status, 1, 0= ) =3D=3D -1) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(e= rrp, errno, "pwrite(\"%s/%s\")", dirpath,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fn);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } /* otherwise pretend successful re-(on|off)-= lining */
-
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 res =3D close(fd);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_assert(res =3D=3D 0);
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 res =3D close(dirfd);
-=C2=A0 =C2=A0 g_assert(res =3D=3D 0);
-}
-
-GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
-{
-=C2=A0 =C2=A0 GuestLogicalProcessorList *head, **tail;
-=C2=A0 =C2=A0 const char *cpu_dir =3D "/sys/devices/system/cpu";=
-=C2=A0 =C2=A0 const gchar *line;
-=C2=A0 =C2=A0 g_autoptr(GDir) cpu_gdir =3D NULL;
-=C2=A0 =C2=A0 Error *local_err =3D NULL;
-
-=C2=A0 =C2=A0 head =3D NULL;
-=C2=A0 =C2=A0 tail =3D &head;
-=C2=A0 =C2=A0 cpu_gdir =3D g_dir_open(cpu_dir, 0, NULL);
-
-=C2=A0 =C2=A0 if (cpu_gdir =3D=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg_errno(errp, errno, "failed to = list entries: %s", cpu_dir);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 while (local_err =3D=3D NULL && (line =3D g_dir_read= _name(cpu_gdir)) !=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 GuestLogicalProcessor *vcpu;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 int64_t id;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (sscanf(line, "cpu%" PRId64, &= ;id)) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_autofree char *path =3D g_strd= up_printf("/sys/devices/system/cpu/"
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "cpu%" PRId64 "/", i= d);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu =3D g_malloc0(sizeof *vcpu)= ;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->logical_id =3D id;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpu->has_can_offline =3D tru= e; /* lolspeak ftw */
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 transfer_vcpu(vcpu, true, path, = &local_err);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QAPI_LIST_APPEND(tail, vcpu); -=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 if (local_err =3D=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* there's no guest with zero VCPUs */
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_assert(head !=3D NULL);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return head;
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 qapi_free_GuestLogicalProcessorList(head);
-=C2=A0 =C2=A0 error_propagate(errp, local_err);
-=C2=A0 =C2=A0 return NULL;
-}
-
-int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp= )
-{
-=C2=A0 =C2=A0 int64_t processed;
-=C2=A0 =C2=A0 Error *local_err =3D NULL;
-
-=C2=A0 =C2=A0 processed =3D 0;
-=C2=A0 =C2=A0 while (vcpus !=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 char *path =3D g_strdup_printf("/sys/devi= ces/system/cpu/cpu%" PRId64 "/",
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0vcpus->value-= >logical_id);
-
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 transfer_vcpu(vcpus->value, false, path, &a= mp;local_err);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 g_free(path);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (local_err !=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 ++processed;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 vcpus =3D vcpus->next;
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 if (local_err !=3D NULL) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (processed =3D=3D 0) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_propagate(errp, local_err)= ;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_free(local_err);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
-=C2=A0 =C2=A0 }
-
-=C2=A0 =C2=A0 return processed;
-}
=C2=A0#endif /* __linux__ */

=C2=A0#if defined(__linux__) || defined(__FreeBSD__)
--
2.45.1

--0000000000000fbff7061d08b3b0--