From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD1Qf-0007H7-6V for qemu-devel@nongnu.org; Tue, 05 Mar 2013 18:37:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UD1Qd-0006cZ-VJ for qemu-devel@nongnu.org; Tue, 05 Mar 2013 18:37:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD1Qd-0006be-LM for qemu-devel@nongnu.org; Tue, 05 Mar 2013 18:37:51 -0500 Message-ID: <513681CB.9030306@redhat.com> Date: Tue, 05 Mar 2013 16:37:47 -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> <51366164.8020806@redhat.com> <51367E77.30404@redhat.com> In-Reply-To: <51367E77.30404@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2EMNDMKIQHQBMKTMSXXCS" 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) ------enig2EMNDMKIQHQBMKTMSXXCS Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/05/2013 04:23 PM, Laszlo Ersek wrote: > For an already online CPU: >=20 > # dd of=3D/sys/devices/system/cpu/cpu1/online bs=3D1 count=3D1 <<<1 > dd: writing `/sys/devices/system/cpu/cpu1/online': Invalid argument > [...] So we really do have to read existing state to avoid an error when the user didn't request a state change. Thanks for the research, and a convincing answer :) >>> + 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). >=20 > I'm using the %u conversion specifier, which turns the unsigned int > argument into decimal string representation. Same as %d for signed int.= I guess I had in my mind %c instead of %u; still, I can't help but wonder if fprintf() and buffering is overkill, compared to just doing something like this: write(fd, &"01"[vcpu->online], 1); (okay, I hope you would favor readability over my compact representation, but you get the point). Oh, and I guess I didn't check whether a trailing newline is essential to the kernel interpreting the input, so maybe it would have to be more like: char buf[2] =3D { "01"[vcpu->online], '\n' }; write(fd, buf, 2); --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2EMNDMKIQHQBMKTMSXXCS 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/ iQEcBAEBCAAGBQJRNoHMAAoJEKeha0olJ0NqrYUIAKlSSWbjSu2Y+x+DDWj9xgs/ /BnTTFxhaImcDzCW/LZh46A8jQ430JfdB0iHDrvrsGLbKziLXp38NdzpR7QNQcac vvQ/1f6VdBMFBsl7XbHVsLCrns2Tmn3Vs4JMS3mrHLpqQuLjvx9LgjgCSs6ZT/Pk Q7Y53XFy6rj+KUfbJBzd9e9iKOvb0/TEg4uMQZ+fZ36nuk1Nu9C10T0plKn5h85c x5Nc1u+F50Fw/81nMUUiEUBoe/xuAo6MdBLqfpR1WWDWBBz9KxeQt6JT/txtw3ZG CplTic2FcaNHGrb+36Z3qUzyWidpzIYLdEQNmEOjjfolQtOiu2W5xDe8ib3+wTE= =CZ+m -----END PGP SIGNATURE----- ------enig2EMNDMKIQHQBMKTMSXXCS--