From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQuqc-0001zd-Qm for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:39:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQuqY-00016L-UC for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:39:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQuqY-000168-PC for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:39:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 5F46D14CAB3 for ; Wed, 3 Feb 2016 10:39:38 +0000 (UTC) Date: Wed, 3 Feb 2016 10:39:34 +0000 From: "Daniel P. Berrange" Message-ID: <20160203103934.GD30222@redhat.com> References: <1452599056-27357-1-git-send-email-berrange@redhat.com> <1452599056-27357-12-git-send-email-berrange@redhat.com> <20160202184601.GD4498@work-vm> <20160203100558.GB30222@redhat.com> <20160203102949.GF2376@work-vm> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160203102949.GF2376@work-vm> Subject: Re: [Qemu-devel] [PATCH v1 11/22] migration: convert fd socket protocol to use QIOChannel Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: Amit Shah , qemu-devel@nongnu.org, Juan Quintela On Wed, Feb 03, 2016 at 10:29:50AM +0000, Dr. David Alan Gilbert wrote: > * Daniel P. Berrange (berrange@redhat.com) wrote: > > On Tue, Feb 02, 2016 at 06:46:01PM +0000, Dr. David Alan Gilbert wrote: > > > > void fd_start_incoming_migration(const char *infd, Error **errp) > > > > { > > > > - int fd; > > > > QEMUFile *f; > > > > + QIOChannel *ioc; > > > > + int fd; > > > > > > > > DPRINTF("Attempting to start an incoming migration via fd\n"); > > > > > > > > fd = strtol(infd, NULL, 0); > > > > if (fd_is_socket(fd)) { > > > > - f = qemu_fopen_socket(fd, "rb"); > > > > + ioc = QIO_CHANNEL(qio_channel_socket_new_fd(fd, errp)); > > > > + if (!ioc) { > > > > + close(fd); > > > > + return; > > > > + } > > > > > > Wouldn't it be better to move this check outside of this if, so that > > > you test the output of both the socket_new_fd and the file_new_fd ? > > > > qio_channel_file_new_fd() can never fail - only the socket_new_fd can > > fail (when trying to query the sockaddr_t data). > > OK, I'm not too fussed about this bit, but: > 1) It's easier to read - one level less of nesting > 2) It avoids making an assumption about qio_channel_file_new_fd() never > failing, which is something you happen to know but you treat as > API; it costs nothing to avoid making that assumption. Note that qio_channel_file_new_fd() does not accept a 'Error **errp' since there is no failure condition. So if we pushed the failure check up it'd be feel like a logic error as we'd be introducing a error return path from the method where 'errp' may not be set. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|