From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCyAl-0006r0-08 for qemu-devel@nongnu.org; Tue, 05 Mar 2013 15:09:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCyAi-00027x-SI for qemu-devel@nongnu.org; Tue, 05 Mar 2013 15:09:14 -0500 Received: from mail-oa0-f46.google.com ([209.85.219.46]:34303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCyAi-00027o-Ib for qemu-devel@nongnu.org; Tue, 05 Mar 2013 15:09:12 -0500 Received: by mail-oa0-f46.google.com with SMTP id k1so11472805oag.5 for ; Tue, 05 Mar 2013 12:09:12 -0800 (PST) Sender: fluxion Date: Tue, 5 Mar 2013 14:09:37 -0600 From: mdroth Message-ID: <20130305200937.GG21850@vm> References: <1362435597-20018-1-git-send-email-lersek@redhat.com> <1362435597-20018-4-git-send-email-lersek@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1362435597-20018-4-git-send-email-lersek@redhat.com> Subject: Re: [Qemu-devel] [PATCH 3/3] qga: implement qmp_guest_set_vcpus() for Linux with sysfs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com On Mon, Mar 04, 2013 at 11:19:57PM +0100, Laszlo Ersek wrote: > > Signed-off-by: Laszlo Ersek > --- > qga/commands-posix.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 51 insertions(+), 0 deletions(-) > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index d4b6bdc..1848df8 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -40,6 +40,7 @@ extern char **environ; > #include > #include > #include > +#include > > #ifdef FIFREEZE > #define CONFIG_FSFREEZE > @@ -1178,7 +1179,57 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) > > void qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) > { > +#if defined(__linux__) > + const GuestLogicalProcessorList *entry; > + Error *local_err = NULL; > + > + for (entry = vcpus; local_err == NULL && entry != NULL; > + entry = entry->next) { > + const GuestLogicalProcessor *vcpu; > + > + vcpu = entry->value; > + if (vcpu->logical_id == 0) { > + if (!vcpu->online) { > + error_setg(&local_err, > + "unable to offline logical processor #0"); > + } > + } else { > + char *buf; > + FILE *f; > + > + buf = g_strdup_printf("/sys/devices/system/cpu/cpu%"PRId64 > + "/online", vcpu->logical_id); > + f = fopen(buf, "r+"); > + if (f == NULL) { > + error_setg_errno(&local_err, errno, "fopen(\"%s\", \"r+\")", > + buf); > + } else { > + unsigned online; > + > + if (fscanf(f, "%u", &online) != 1) { > + error_setg(&local_err, "failed to read or parse \"%s\"", > + buf); > + } else if ((online != 0) != vcpu->online) { > + errno = 0; > + rewind(f); > + if (errno != 0 || > + fprintf(f, "%u\n", (unsigned)vcpu->online) < 0) { Similar to comments in patch 2: is this supposed to be similar to the /sys/devices/system/cpu/{probe,release} entries currently documented? > + error_setg_errno(&local_err, errno, > + "rewind()/fprintf() on \"%s\"", buf); > + } > + } > + > + if (fclose(f) == EOF && local_err == NULL) { > + error_setg_errno(&local_err, errno, "fclose(\"%s\")", buf); > + } > + } > + g_free(buf); > + } > + } > + error_propagate(errp, local_err); > +#else > error_set(errp, QERR_UNSUPPORTED); > +#endif > } > > /* register init/cleanup routines for stateful command groups */ > -- > 1.7.1 >