qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v1 11/22] migration: convert fd socket protocol


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH v1 11/22] migration: convert fd socket protocol to use QIOChannel
Date: Wed, 3 Feb 2016 10:39:34 +0000
User-agent: Mutt/1.5.24 (2015-08-30)

On Wed, Feb 03, 2016 at 10:29:50AM +0000, Dr. David Alan Gilbert wrote:
> * Daniel P. Berrange (address@hidden) 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 :|



reply via email to

[Prev in Thread] Current Thread [Next in Thread]