Received: from eggs.gnu.org ([2001:4830:134:3::10]:53179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoWvU-0003rX-Ta for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoWvP-0008Kx-MN for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:26:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoWvP-0008Kl-8V for qemu-devel@nongnu.org; Tue, 20 Oct 2015 09:25:59 -0400 From: Juan Quintela In-Reply-To: <1443515898-3594-26-git-send-email-dgilbert@redhat.com> (David Alan Gilbert's message of "Tue, 29 Sep 2015 09:37:49 +0100") References: <1443515898-3594-1-git-send-email-dgilbert@redhat.com> <1443515898-3594-26-git-send-email-dgilbert@redhat.com> Date: Tue, 20 Oct 2015 15:25:56 +0200 Message-ID: <87y4exr7rv.fsf@neno.neno> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v8 25/54] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream Reply-To: quintela@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" Cc: aarcange@redhat.com, liang.z.li@intel.com, qemu-devel@nongnu.org, luis@cs.umu.se, bharata@linux.vnet.ibm.com, amit.shah@redhat.com, pbonzini@redhat.com "Dr. David Alan Gilbert (git)" wrote: > From: "Dr. David Alan Gilbert" > > MIG_CMD_PACKAGED is a migration command that wraps a chunk of migration > stream inside a package whose length can be determined purely by reading > its header. The destination guarantees that the whole MIG_CMD_PACKAGED > is read off the stream prior to parsing the contents. > > This is used by postcopy to load device state (from the package) > while leaving the main stream free to receive memory pages. > > Signed-off-by: Dr. David Alan Gilbert > Reviewed-by: Amit Shah Reviewed-by: Juan Quintela But I propose the change below > + size_t len = qsb_get_length(qsb); .... > + /* all the data follows (concatinating the iov's) */ > + for (cur_iov = 0; cur_iov < qsb->n_iov; cur_iov++) { > + /* The iov entries are partially filled */ > + size_t towrite = (qsb->iov[cur_iov].iov_len > len) ? > + len : > + qsb->iov[cur_iov].iov_len; Or something have been very wrong here, or qsb->iov[cur_iov].iov_len can never be > len. So this should be the same than: size_t towrite = MIN(qsb->iov[cur_iov].iov_len, len); right? > + len -= towrite; > + > + if (!towrite) { > + break; > + } This should never happen, right? And if we want to be extra safe, > + QEMUFile *packf = qemu_bufopen("r", qsb); > + > + ret = qemu_loadvm_state_main(packf, mis); > + trace_loadvm_handle_cmd_packaged_main(ret); > + qemu_fclose(packf); > + qsb_free(qsb); Migration code is re-entrant!!!!! Who would have guessed O:-) Later, Juan.