From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAJYb-0003v8-75 for qemu-devel@nongnu.org; Wed, 01 Jul 2015 11:04:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAJYV-0000rO-Lu for qemu-devel@nongnu.org; Wed, 01 Jul 2015 11:04:13 -0400 References: <1435761950-26714-1-git-send-email-stefanha@redhat.com> <5593FD66.5020002@redhat.com> From: Paolo Bonzini Message-ID: <5594015C.20104@redhat.com> Date: Wed, 1 Jul 2015 17:03:56 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] block/mirror: limit qiov to IOV_MAX elements List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu block , qemu-devel , Stefan Hajnoczi On 01/07/2015 16:59, Stefan Hajnoczi wrote: > I found it annoying to write it backwards too, but it's for consistency: > > if (s->buf_free_count < nb_chunks + added_chunks) { > trace_mirror_break_buf_busy(s, nb_chunks, s->in_flight); > break; > } > if (IOV_MAX < nb_chunks + added_chunks) { > trace_mirror_break_iov_max(s, nb_chunks, added_chunks); > break; > } > > It's the same type of check as s->buf_free_count (which isn't modified > by this loop either so it's a yoda conditional). Hmm, right. The problem goes back to: while (nb_chunks == 0 && s->buf_free_count < added_chunks) { trace_mirror_yield_buf_busy(s, nb_chunks, s->in_flight); qemu_coroutine_yield(); } where s->buf_free_count _is_ modified by the loop. The if below: if (s->buf_free_count < nb_chunks + added_chunks) { trace_mirror_break_buf_busy(s, nb_chunks, s->in_flight); break; } is written as a < check for consistency, and the one you add exacerbates the problem. If you want you can change the < to > in the "while" loop as well; otherwise the patch is okay as is. Paolo