From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: Re: [PATCH v3 19/28] tools/libxl: Convert a legacy stream if needed Date: Mon, 13 Jul 2015 15:51:13 +0100 Message-ID: <21923.53345.222120.747892@mariner.uk.xensource.com> References: <1436788907-1921-1-git-send-email-andrew.cooper3@citrix.com> <1436788907-1921-20-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1436788907-1921-20-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Wei Liu , Ian Campbell , Xen-devel List-Id: xen-devel@lists.xenproject.org Andrew Cooper writes ("[PATCH v3 19/28] tools/libxl: Convert a legacy stream if needed"): > For backwards compatibility, a legacy stream needs converting before > it can be read by the v2 stream logic. > > This causes the v2 stream logic to need to juggle two parallel tasks. > check_all_finished() is introduced for the purpose of joining the > tasks in both success and error cases. ... > + /* If we started a conversion helper, we took ownership of its carefd. */ > + if (stream->chs.v2_carefd) > + libxl__carefd_close(stream->chs.v2_carefd); This would be more obviously correct (or at least more obviously never leak a carefd) if you set v2_carefd to NULL here, and asserted its NULLness at the end of check_all_finished just before making the callback. (I looked to see if you initialised it to NULL as well; you don't, but the existing code is not consistent about whether it works on systems where all-bits-0 is not NULL, and I think it unlikely that Xen would ever be made to work on such a system.) > + /* Don't fire the callback until all our parallel tasks have stopped. */ > + if (!libxl__stream_read_inuse(stream) && > + !libxl__conversion_helper_inuse(&stream->chs)) > + stream->completion_callback(egc, stream, stream->rc); I think this would be clearer if the sense of the if was reversed, so: + /* Don't fire the callback until all our parallel tasks have stopped. */ + if (libxl__stream_read_inuse(stream) || + libxl__conversion_helper_inuse(&stream->chs)) + return; + + /* At last! */ + stream->completion_callback(egc, stream, stream->rc); But this is a matter of taste, so feel free to leave it as it is. Ian.