From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KeAO9-0001EL-GU for qemu-devel@nongnu.org; Fri, 12 Sep 2008 11:16:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KeAO8-0001DT-UQ for qemu-devel@nongnu.org; Fri, 12 Sep 2008 11:16:49 -0400 Received: from [199.232.76.173] (port=35327 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeAO8-0001DI-Pf for qemu-devel@nongnu.org; Fri, 12 Sep 2008 11:16:48 -0400 Received: from yx-out-1718.google.com ([74.125.44.153]:5102) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KeAO8-00007N-Mo for qemu-devel@nongnu.org; Fri, 12 Sep 2008 11:16:48 -0400 Received: by yx-out-1718.google.com with SMTP id 3so325256yxi.82 for ; Fri, 12 Sep 2008 08:16:47 -0700 (PDT) Message-ID: Date: Fri, 12 Sep 2008 18:16:47 +0300 From: "Blue Swirl" Subject: Re: [Qemu-devel] [PATCH 8/10] Introduce a buffered QEMUFile wrapper In-Reply-To: <1220989802-13706-9-git-send-email-aliguori@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1220989802-13706-1-git-send-email-aliguori@us.ibm.com> <1220989802-13706-9-git-send-email-aliguori@us.ibm.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Chris Wright , Uri Lublin , Anthony Liguori , kvm@vger.kernel.org On 9/9/08, Anthony Liguori wrote: > This patch introduces a buffered QEMUFile wrapper. This allows QEMUFile's to be > rate limited. It also allows makes it easier to implement a QEMUFile that is > asynchronous. > > The only real non-obvious part of the API is the "frozen" concept. If the backend > returns EAGAIN, the QEMUFile is said to be "frozen". This means no additional > output will be sent to the backend until the file is unfrozen. qemu_file_put_notify > can be used to unfreeze a frozen file. > > A synchronous interface is also provided to wait for an unfreeze event. This is > used during the final part of live migration when the VM is no longer running. > +static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) > +{ > + QEMUFileBuffered *s = opaque; > + size_t offset = 0; > + ssize_t ret; > + > + if (s->has_error) > + return -EINVAL; > + > + s->freeze_output = 0; > + > + buffered_flush(s); > + > + while (offset < size) { > + if (s->bytes_xfer > s->xfer_limit) > + break; > + > + ret = s->put_buffer(s->opaque, buf + offset, size - offset); > + if (ret == -EAGAIN) { > + s->freeze_output = 1; > + break; > + } > + > + if (ret <= 0) { > + s->has_error = 1; > + break; > + } > + > + offset += ret; > + s->bytes_xfer += ret; > + } > + > + buffered_append(s, buf + offset, size - offset); > + > + return offset; > +} I'd change the types of the return value and parameter "size" to ssize_t.