From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH] qemu: qemu_fopen_fd: differentiate between reader and writer user Date: Sun, 12 Oct 2008 17:18:08 -0500 Message-ID: <48F277A0.8040407@codemonkey.ws> References: <1223829030-14962-1-git-send-email-uril@qumranet.com> <48F22BF1.3000608@redhat.com> <48F23D4D.2050709@codemonkey.ws> <48F23F42.10405@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Uri Lublin , kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mail-gx0-f16.google.com ([209.85.217.16]:36128 "EHLO mail-gx0-f16.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753505AbYJLWSN (ORCPT ); Sun, 12 Oct 2008 18:18:13 -0400 Received: by gxk9 with SMTP id 9so2901335gxk.13 for ; Sun, 12 Oct 2008 15:18:12 -0700 (PDT) In-Reply-To: <48F23F42.10405@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Avi Kivity wrote: > Anthony Liguori wrote: > >>> The proposed patch is less that ideal IMO as it introduces >>> limitations on what you can do with a file. An alternative >>> implementation would add a read/write mode to the buffer, based on >>> the last access type. When switching from read to write, we drop the >>> buffer, and when switching from write to read, we flush it and then >>> drop it. This is more complex but results in a cleaner API. >>> >> I would think a better solution would introduce two buffers, one for >> read and one for write. That way, you can have a proper bidirectional >> stream. >> >> > > Complexity goes way up. Now you need to intercept reads that go to the > write buffer, and vice versa. > Yeah, Uri: instead of passing an argument to qemu_fopen_ops, it may be better to direct the cases where we do a write and set a flag. Then in the fflush() function, only do the put_buffer if the is_write flag is set. Also, having checks and the read and write functions to determine if the is_write flag is set along with whether buf_index > 0 that fprintf()'d and aborted would be good for debugging. Regards, Anthony Liguori