qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>,
	Markus Armbruster <armbru@redhat.com>
Cc: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/4] net/socket: Convert error report message to Error
Date: Wed, 3 May 2017 19:47:33 +0800	[thread overview]
Message-ID: <ea3f29d7-a769-d6fb-7331-6a90aff94e8e@redhat.com> (raw)
In-Reply-To: <d997f3b8-9cb9-09d8-14de-71c848cf18c2@cn.fujitsu.com>



On 2017年05月03日 16:59, Mao Zhongyi wrote:
>
>
> On 05/03/2017 04:54 PM, Markus Armbruster wrote:
>> Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
>>
>>> Hi, Markus,Daniel
>>>
>>> On 04/28/2017 04:02 PM, Markus Armbruster wrote:
>>>> "Daniel P. Berrange" <berrange@redhat.com> writes:
>>>>
>>>>> On Thu, Apr 27, 2017 at 06:24:17PM +0200, Markus Armbruster wrote:
>>>>>> No review, just an observation.
>>>>>>
>>>>>> Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
>>>>>>
>>>>>>> Currently, net_socket_mcast_create(), net_socket_fd_init_dgram() 
>>>>>>> and
>>>>>>> net_socket_fd_init() use the function such as fprintf(), 
>>>>>>> perror() to
>>>>>>> report an error message.
>>>>>>>
>>>>>>> Now, convert these functions to Error.
>>>>>>>
>>>>>>> CC: jasowang@redhat.com, armbru@redhat.com
>>>>>>> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
>>>>>>> ---
>>>>>>>  net/socket.c | 66 
>>>>>>> +++++++++++++++++++++++++++++++++++++-----------------------
>>>>>>>  1 file changed, 41 insertions(+), 25 deletions(-)
>>>>>>>
>>>>>>> diff --git a/net/socket.c b/net/socket.c
>>>>>>> index b0decbe..559e09a 100644
>>>>>>> --- a/net/socket.c
>>>>>>> +++ b/net/socket.c
>>>>>> [...]
>>>>>>> @@ -433,25 +437,27 @@ static NetSocketState 
>>>>>>> *net_socket_fd_init_stream(NetClientState *peer,
>>>>>>>
>>>>>>>  static NetSocketState *net_socket_fd_init(NetClientState *peer,
>>>>>>>                                            const char *model, 
>>>>>>> const char *name,
>>>>>>> -                                          int fd, int 
>>>>>>> is_connected)
>>>>>>> +                                          int fd, int 
>>>>>>> is_connected,
>>>>>>> +                                          Error **errp)
>>>>>>>  {
>>>>>>>      int so_type = -1, optlen=sizeof(so_type);
>>>>>>>
>>>>>>>      if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
>>>>>>>          (socklen_t *)&optlen)< 0) {
>>>>>>> -        fprintf(stderr, "qemu: error: getsockopt(SO_TYPE) for 
>>>>>>> fd=%d failed\n",
>>>>>>> +        error_setg(errp, "qemu: error: getsockopt(SO_TYPE) for 
>>>>>>> fd=%d failed",
>>>>>>>                  fd);
>>>>>>>          closesocket(fd);
>>>>>>>          return NULL;
>>>>>>>      }
>>>>>>>      switch(so_type) {
>>>>>>>      case SOCK_DGRAM:
>>>>>>> -        return net_socket_fd_init_dgram(peer, model, name, fd, 
>>>>>>> is_connected);
>>>>>>> +        return net_socket_fd_init_dgram(peer, model, name, fd, 
>>>>>>> is_connected, errp);
>>>>>>>      case SOCK_STREAM:
>>>>>>>          return net_socket_fd_init_stream(peer, model, name, fd, 
>>>>>>> is_connected);
>>>>>>>      default:
>>>>>>>          /* who knows ... this could be a eg. a pty, do warn and 
>>>>>>> continue as stream */
>>>>>>> -        fprintf(stderr, "qemu: warning: socket type=%d for 
>>>>>>> fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
>>>>>>> +        error_setg(errp, "qemu: warning: socket type=%d for 
>>>>>>> fd=%d is not SOCK_DGRAM"
>>>>>>> +                   " or SOCK_STREAM", so_type, fd);
>>>>>>
>>>>>> Not this patches problem: this case is odd, and the comment is 
>>>>>> bogus.
>>>>>> If @fd really was a pty, getsockopt() would fail with ENOTSOCK, 
>>>>>> wouldn't
>>>>>> it?  If @fd is a socket, but neither SOCK_DGRAM nor SOCK_STREAM (say
>>>>>> SOCK_RAW), why is it safe to continue as if it was SOCK_STREAM?  
>>>>>> Jason?
>>>>>
>>>>> IMHO it is a problem with this patch. Previously we merely printed
>>>>> a warning & carried on, which is conceptually ok in general, though
>>>>> dubious here for the reason you say.
>>>>>
>>>>> Now we are filling an Error **errp object, and carrying on - this is
>>>>> conceptually broken anywhere. If an Error ** is filled, we must 
>>>>> return.
>>>>> If we want to carry on, we shouldn't fill Error **.
>>>>
>>>> You're right.
>>>>
>>>>>>>          return net_socket_fd_init_stream(peer, model, name, fd, 
>>>>>>> is_connected);
>>>>>
>>>>> IMHO, we just kill this and put return NULL here. If there is a 
>>>>> genuine
>>>>> reason to support something like SOCK_RAW, it should be explicitly
>>>>> handled, because this default: case will certainly break 
>>>>> SOCK_SEQPACKET
>>>>> and SOCK_RDM which can't be treated as streams.
>>>>
>>>> It's either magic or misguided defensive programming. Probably the
>>>> latter, but I'd like to hear Jason's opinion.
>>>>
>>>> If it's *necessary* magic, we can't use error_setg().  Else, we should
>>>> drop the default, and insert a closesocket(fd) before the final return
>>>> NULL.
>>>
>>> As Daniel said, although the previous printed warning message is
>>> dubious, but it is conceptually ok in general. Simply filling it to
>>> Error ** is problematic. Of course, as you said drop the default case,
>>> there will be no problem. But really to do that?
>>
>> Since Jason hasn't spoken up, I suggest you follow Dan's recommendation
>> and insert a patch to drop the default case before your error rework.
>>
>>
>>
>
> I see, will drop the 'default' case in a separated patch.
>
> Thanks.

Sorry for the late. I agree to drop the default. Even SOCK_RAW could not 
work as stream and any type should be supported explicitly.

Thanks

  reply	other threads:[~2017-05-03 11:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26  8:04 [Qemu-devel] [PATCH v2 0/4] Convert non-blocking connect and fix its error reporting Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 1/4] net/socket: Convert the non-blocking connection mechanism to QIOchannel Mao Zhongyi
2017-04-27 15:46   ` Markus Armbruster
2017-04-27 16:19     ` Markus Armbruster
2017-04-27 16:22       ` Daniel P. Berrange
2017-05-03  7:02     ` Mao Zhongyi
2017-04-27 16:20   ` Daniel P. Berrange
2017-05-03  7:02     ` Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 2/4] net/socket: Improve -net socket error reporting Mao Zhongyi
2017-04-27 16:10   ` Markus Armbruster
2017-05-03  7:07     ` Mao Zhongyi
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 3/4] net/socket: Convert error report message to Error Mao Zhongyi
2017-04-27 16:24   ` Markus Armbruster
2017-04-27 16:30     ` Daniel P. Berrange
2017-04-28  8:02       ` Markus Armbruster
2017-05-03  7:09         ` Mao Zhongyi
2017-05-03  8:37           ` Daniel P. Berrange
2017-05-03  8:37             ` Mao Zhongyi
2017-05-03  8:54           ` Markus Armbruster
2017-05-03  8:59             ` Mao Zhongyi
2017-05-03 11:47               ` Jason Wang [this message]
2017-04-26  8:04 ` [Qemu-devel] [PATCH v2 4/4] net/net: Convert parse_host_port() " Mao Zhongyi
2017-04-27 16:25 ` [Qemu-devel] [PATCH v2 0/4] Convert non-blocking connect and fix its error reporting Markus Armbruster
2017-05-03  7:12   ` Mao Zhongyi
2017-05-05 16:39 ` Daniel P. Berrange
2017-05-09  1:26   ` Mao Zhongyi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ea3f29d7-a769-d6fb-7331-6a90aff94e8e@redhat.com \
    --to=jasowang@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=maozy.fnst@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).