From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCzNK-00018e-Vz for qemu-devel@nongnu.org; Tue, 05 Mar 2013 16:26:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCzN8-00081H-Ch for qemu-devel@nongnu.org; Tue, 05 Mar 2013 16:26:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCzH0-0006t6-Ii for qemu-devel@nongnu.org; Tue, 05 Mar 2013 16:19:46 -0500 Message-ID: <51366164.8020806@redhat.com> Date: Tue, 05 Mar 2013 14:19:32 -0700 From: Eric Blake MIME-Version: 1.0 References: <1362435597-20018-1-git-send-email-lersek@redhat.com> <1362435597-20018-4-git-send-email-lersek@redhat.com> In-Reply-To: <1362435597-20018-4-git-send-email-lersek@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2CMADELXMAOKDSCPXUCOG" 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: qemu-devel@nongnu.org, pbonzini@redhat.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2CMADELXMAOKDSCPXUCOG Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/04/2013 03:19 PM, Laszlo Ersek wrote: > Signed-off-by: Laszlo Ersek > --- > qga/commands-posix.c | 51 ++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 1 files changed, 51 insertions(+), 0 deletions(-) >=20 > 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 > =20 > #ifdef FIFREEZE > #define CONFIG_FSFREEZE > @@ -1178,7 +1179,57 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(E= rror **errp) > =20 > void qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **err= p) > { > +#if defined(__linux__) > + const GuestLogicalProcessorList *entry; > + Error *local_err =3D NULL; > + > + for (entry =3D vcpus; local_err =3D=3D NULL && entry !=3D NULL; > + entry =3D entry->next) { > + const GuestLogicalProcessor *vcpu; > + > + vcpu =3D entry->value; > + if (vcpu->logical_id =3D=3D 0) { > + if (!vcpu->online) { > + error_setg(&local_err, > + "unable to offline logical processor #0"); > + } This is not quite accurate; my understanding is that there are setups where cpu0 can be offlined. More accurate would be to reject attempts to offline ANY cpu where the cpu/cpuNN/online file does not exist (which will catch the fact that cpu0 must always be on for the hardware you are testing with). > + } else { > + char *buf; > + FILE *f; > + > + buf =3D g_strdup_printf("/sys/devices/system/cpu/cpu%"PRId= 64 > + "/online", vcpu->logical_id); > + f =3D fopen(buf, "r+"); > + if (f =3D=3D NULL) { > + error_setg_errno(&local_err, errno, "fopen(\"%s\", \"r= +\")", > + buf); Again, if the file doesn't exist, but the user asked for online, then this should not be an error. > + } else { > + unsigned online; > + > + if (fscanf(f, "%u", &online) !=3D 1) { > + error_setg(&local_err, "failed to read or parse \"= %s\"", > + buf); Does doing a scan of the file's existing contents buy us any safety? Why not just blindly write into the file, instead of first reading it? > + } else if ((online !=3D 0) !=3D vcpu->online) { > + errno =3D 0; > + rewind(f); > + if (errno !=3D 0 || > + fprintf(f, "%u\n", (unsigned)vcpu->online) < 0= ) { Do you really want to be printing NUL or \1? I though the kernel interface expected the literal character '0' or '1' (in ascii, \x30 or \x31). Why even bother with stdio buffering? Wouldn't it be simpler to open()/write() instead of fopen()/fprintf()? > + error_setg_errno(&local_err, errno, > + "rewind()/fprintf() on \"%s\"= ", buf); > + } > + } > + > + if (fclose(f) =3D=3D EOF && local_err =3D=3D 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 > } > =20 > /* register init/cleanup routines for stateful command groups */ >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2CMADELXMAOKDSCPXUCOG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRNmFkAAoJEKeha0olJ0NqW3MH/1pEYPG5rdFaIrlwU9IjmKLY LAAOltqB8R8XT046FILHHScz6kTbjtobwrlCMajRnEhCRbZcZ6Hkr/QYb3TgBL1Y zrLGtz60eFSGMnwEXPuTYHmbi6vz8vppZkkfVAPe79u5c+SZOx8dwsnZnMwa4QNd 5r9ZxtOtyWyJArIa4oETle7d6qBkKayuEAa02TzisWpXxKZ5UV3t2Dmdse4tsemB 4+yfjg6yX+QiH/mxc2cC0oiklKApR7i3Q387FKDLvUnfJaMoETn5Cf9pWmjeRXNY oVGHDJBZHCv5cnG98iF6Ub3INHm+3LnHr15ULrgt1cOPUKftfHnoMmmw4HxVbSM= =MBl7 -----END PGP SIGNATURE----- ------enig2CMADELXMAOKDSCPXUCOG--