From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD2TL-0002Qh-DM for qemu-devel@nongnu.org; Tue, 05 Mar 2013 19:44:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UD2TI-0008N6-1O for qemu-devel@nongnu.org; Tue, 05 Mar 2013 19:44:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50349) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD2TH-0008Mu-Qi for qemu-devel@nongnu.org; Tue, 05 Mar 2013 19:44:39 -0500 Message-ID: <51369173.5060808@redhat.com> Date: Wed, 06 Mar 2013 01:44:35 +0100 From: Laszlo Ersek 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> <513681CB.9030306@redhat.com> In-Reply-To: <513681CB.9030306@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: Eric Blake Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com On 03/06/13 00:37, Eric Blake wrote: > 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). I'd be crucified on qemu-devel if I tried to pull off something like the above :) > 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] = { "01"[vcpu->online], '\n' }; > write(fd, buf, 2); The newline is probably not important. Anyway I'd prefer to avoid direct write()s with nbyte > 1 as I'd have to handle partial transfers, if for nothing else than principle. (IIRC avoiding that loop was my main motivation for stdio.) I guess I'll use open(O_DIRECTORY) + openat("online") + read(..., 1) + pwrite(..., 1, 0). RHEL-5 seems to support all of these (I can't find O_SEARCH in the manual there, which is why I'll probably omit it from open()). If people still complain then I can switch from open(directory) + openat("online") to lstat(directory) + open("/.../online"). Thanks Laszlo