Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp760821ybl; Thu, 22 Aug 2019 04:35:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqywnqd4hqY/+ff2g26EGoMg/KivVSBWHa0b/FLoj9XPRPflgVxgTHYltVGjVb/UNI/lmVIR X-Received: by 2002:a17:902:1121:: with SMTP id d30mr32637217pla.174.1566473724686; Thu, 22 Aug 2019 04:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566473724; cv=none; d=google.com; s=arc-20160816; b=mwKF6MY7/sOFlNX/xT9SazgR7sEkXuA1EvQ7dpCcCtayyv9dLjHMM/1Qu87RaknxNE H+A9VSnUxTamAVp4hWv/6OrqpfHrD8lGeadcOxg3kSIs73n95sdtk72SAc9cGzijzM+Y vSx5dPObbT9pi3/33XCE2FUAqylLo+02iQnjmx3gz11mVKj2Jfun+VpdGGlt2gYgfxL7 WR9VDix5kYpsDSAQF4zuU/wN9ZiQ0g8xb1wo6LztGEUacK1z+ZlkAwNhJotZzvkEJjhl K1ZtiJsoYbhxNCZIq2C42R8ZOyoh7layOgbxGTPE+swru3bgq49m8DbAWTOI2aZYtqYj Nvhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=20y8QC7R6t0IGb5Wrdbux5c0c2oCVqxmDr+q12FCKEs=; b=R1mHHwGedbudtOYVBlJ3aGkx3I//bY/3JDElWT/5CNc7PCySX6/Pkp72f1NpV9ZUly ytjXxMgaR/PzO9q6cZBlvk6gahHqfaokvKehqLLe39lm1HGO8k9bCrA8AjcApsc84bLH arFwZGN5S6GavQT4nLMeWmVaa0tMlH3/dSka/uv3t+NdEvUa9RcQzo92XO0IypXClS7l iIJ8wd15t8P2B0jEP+/2bVjRZFA1VVgrWJYW4XcCeuA15zxS8st9D62nfWhiAusSk+fP mv2eJA0N7HZX5ORKfRAJC+pFOEf1+e8EwsHPbDH30gKxTk5kiac7XZR+kyr7h+5WceQj lefw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v14si16429092pgl.386.2019.08.22.04.35.09; Thu, 22 Aug 2019 04:35:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733097AbfHVJPw (ORCPT + 99 others); Thu, 22 Aug 2019 05:15:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60520 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728080AbfHVJPw (ORCPT ); Thu, 22 Aug 2019 05:15:52 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0078881DEB for ; Thu, 22 Aug 2019 09:15:52 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id a17so2919905wrw.3 for ; Thu, 22 Aug 2019 02:15:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=20y8QC7R6t0IGb5Wrdbux5c0c2oCVqxmDr+q12FCKEs=; b=ZKdAB2SdZdgJlb/HYi9ZvdJXoYLnX8SszzlIEcOl3ug0vDtm3gi+0y/lB4JCs9rJW+ ocZJwMrL3sUqNPDyqV7TIrIogGntiti3e/FMl1p264s70haoHbFZuRvtGcMYaSpl7EsG 8RcBEXh1FvXsY/Gj0LXOc0/t9p4xW1IumCioKkW3meoidut3gV9XwUrFVipgdik5ER7f EXrpd0IXHNi6P+oscIoDTB4jocmxVlye1lEc0DSGYt89CViySJNHiJZrWpO0ymZ3fZUE nd5f06n91GGYY35DjEvX6Lh4ydPu95WPTRKrsjK4Jk1YNIa9n6p1WNxhxW5QEFoFaxbp hcSA== X-Gm-Message-State: APjAAAUUpG4otU8RlufYRpzi+gOZ9xMzeQFbP/U+EvaGDa5upXZsCD8t p1oHahhJb3ctPzihR6ofaMKrShgI9zjD2WG8Q1yTSX4tzlEts+H5cE+COVCJo+ewr+m+uLWlLk9 Tu0JS0JnIwhHEJFNRY4Px2PLy X-Received: by 2002:adf:e710:: with SMTP id c16mr2290129wrm.292.1566465350615; Thu, 22 Aug 2019 02:15:50 -0700 (PDT) X-Received: by 2002:adf:e710:: with SMTP id c16mr2290089wrm.292.1566465350391; Thu, 22 Aug 2019 02:15:50 -0700 (PDT) Received: from steredhat (host80-221-dynamic.18-79-r.retail.telecomitalia.it. [79.18.221.80]) by smtp.gmail.com with ESMTPSA id l9sm2678299wmi.29.2019.08.22.02.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 02:15:49 -0700 (PDT) Date: Thu, 22 Aug 2019 11:15:46 +0200 From: Stefano Garzarella To: Stefan Hajnoczi Cc: netdev@vger.kernel.org, kvm@vger.kernel.org, Dexuan Cui , virtualization@lists.linux-foundation.org, "David S. Miller" , Jorgen Hansen , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 11/11] vsock_test: wait for the remote to close the connection Message-ID: <20190822091546.qcns2kot6tzju7yv@steredhat> References: <20190801152541.245833-1-sgarzare@redhat.com> <20190801152541.245833-12-sgarzare@redhat.com> <20190820082828.GA9855@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190820082828.GA9855@stefanha-x1.localdomain> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 20, 2019 at 09:28:28AM +0100, Stefan Hajnoczi wrote: > On Thu, Aug 01, 2019 at 05:25:41PM +0200, Stefano Garzarella wrote: > > +/* Wait for the remote to close the connection */ > > +void vsock_wait_remote_close(int fd) > > +{ > > + struct epoll_event ev; > > + int epollfd, nfds; > > + > > + epollfd = epoll_create1(0); > > + if (epollfd == -1) { > > + perror("epoll_create1"); > > + exit(EXIT_FAILURE); > > + } > > + > > + ev.events = EPOLLRDHUP | EPOLLHUP; > > + ev.data.fd = fd; > > + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) { > > + perror("epoll_ctl"); > > + exit(EXIT_FAILURE); > > + } > > + > > + nfds = epoll_wait(epollfd, &ev, 1, TIMEOUT * 1000); > > + if (nfds == -1) { > > + perror("epoll_wait"); > > + exit(EXIT_FAILURE); > > + } > > + > > + if (nfds == 0) { > > + fprintf(stderr, "epoll_wait timed out\n"); > > + exit(EXIT_FAILURE); > > + } > > + > > + assert(nfds == 1); > > + assert(ev.events & (EPOLLRDHUP | EPOLLHUP)); > > + assert(ev.data.fd == fd); > > + > > + close(epollfd); > > +} > > Please use timeout_begin()/timeout_end() so that the test cannot hang. > I used the TIMEOUT macro in the epoll_wait() to avoid the hang. Do you think is better to use the timeout_begin()/timeout_end()? In this case, should I remove the timeout in the epoll_wait()? > > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > > index 64adf45501ca..a664675bec5a 100644 > > --- a/tools/testing/vsock/vsock_test.c > > +++ b/tools/testing/vsock/vsock_test.c > > @@ -84,6 +84,11 @@ static void test_stream_client_close_server(const struct test_opts *opts) > > > > control_expectln("CLOSED"); > > > > + /* Wait for the remote to close the connection, before check > > + * -EPIPE error on send. > > + */ > > + vsock_wait_remote_close(fd); > > Is control_expectln("CLOSED") still necessary now that we're waiting for > the poll event? The control message was an attempt to wait until the > other side closed the socket. Right, I'll remove it in the v3 Thanks, Stefano