From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752699AbdJTOln (ORCPT ); Fri, 20 Oct 2017 10:41:43 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:43516 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752585AbdJTOll (ORCPT ); Fri, 20 Oct 2017 10:41:41 -0400 Subject: Re: [PATCH v5 10/13] xen/pvcalls: implement recvmsg To: Stefano Stabellini References: <1507336227-20477-1-git-send-email-sstabellini@kernel.org> <1507336227-20477-10-git-send-email-sstabellini@kernel.org> <318acfff-0d58-fa4b-29eb-29a5d6f0bddf@oracle.com> Cc: xen-devel@lists.xen.org, linux-kernel@vger.kernel.org, jgross@suse.com, Stefano Stabellini From: Boris Ostrovsky Message-ID: Date: Fri, 20 Oct 2017 10:43:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/19/2017 09:38 PM, Stefano Stabellini wrote: > On Tue, 17 Oct 2017, Boris Ostrovsky wrote: >>> + >>> +int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, >>> + int flags) >>> +{ >>> + struct pvcalls_bedata *bedata; >>> + int ret; >>> + struct sock_mapping *map; >>> + >>> + if (flags & (MSG_CMSG_CLOEXEC|MSG_ERRQUEUE|MSG_OOB|MSG_TRUNC)) >>> + return -EOPNOTSUPP; >>> + >>> + pvcalls_enter(); >>> + if (!pvcalls_front_dev) { >>> + pvcalls_exit(); >>> + return -ENOTCONN; >>> + } >>> + bedata = dev_get_drvdata(&pvcalls_front_dev->dev); >>> + >>> + map = (struct sock_mapping *) sock->sk->sk_send_head; >>> + if (!map) { >>> + pvcalls_exit(); >>> + return -ENOTSOCK; >>> + } >>> + >>> + mutex_lock(&map->active.in_mutex); >>> + if (len > XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER)) >>> + len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER); >>> + >>> + while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) { >>> + wait_event_interruptible(map->active.inflight_conn_req, >>> + pvcalls_front_read_todo(map)); >>> + } >>> + ret = __read_ring(map->active.ring, &map->active.data, >>> + &msg->msg_iter, len, flags); >>> + >>> + if (ret > 0) >>> + notify_remote_via_irq(map->active.irq); >>> + if (ret == 0) >>> + ret = -EAGAIN; >> Why not 0? The manpage says: >> >> EAGAIN or EWOULDBLOCK >> The socket is marked nonblocking and the receive >> operation would block, or a receive timeout >> had been set and the timeout expired before data was >> received. POSIX.1 allows either error to >> be returned for this case, and does not require these >> constants to have the same value, so a >> portable application should check for both possibilities. >> >> >> I don't think either of these conditions is true here. >> >> (Again, should have noticed this earlier, sorry) > In case the socket is MSG_DONTWAIT, then we should return -EAGAIN here. > However, it is true that if the socket is not MSG_DONTWAIT, then > returning 0 would make more sense. > > So I'll do: > > if (ret == 0) > ret = (flags & MSG_DONTWAIT) ? -EAGAIN : 0; Sure. With that Reviewed-by: Boris Ostrovsky