From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15A5AC433DB for ; Fri, 15 Jan 2021 18:23:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 730AA222B3 for ; Fri, 15 Jan 2021 18:23:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 730AA222B3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0TlD-0004BY-72 for qemu-devel@archiver.kernel.org; Fri, 15 Jan 2021 13:23:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Tjr-0003jQ-N2 for qemu-devel@nongnu.org; Fri, 15 Jan 2021 13:22:23 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:33966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Tjp-0006Pz-BJ for qemu-devel@nongnu.org; Fri, 15 Jan 2021 13:22:23 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10FIFIQY184960; Fri, 15 Jan 2021 18:21:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=corp-2020-01-29; bh=6OINlLcpNa1Y/C632EF6vEq9c4oBBQaEYw0eJoGiBuY=; b=Chc/fS4izfVv6NYSGLpOTVDcb59SNyZwf0WPMtE7yVB4Vf4XNoKgDJ+LDiJduY3MxnQk p+PGHsQMHJlnZm7MfTDietc1mW9Lnx1Kci+3F8NftSvMm/7pIDOyEqrveLQS4zcnTHGb U7D9VuA4WXbQs7gFzp3Jw3mTkhLl0fkPaqgBomel2LVQUODvjlef0trXiV6YIELgbNO4 PBICNm7jSYnmqqMq/L8ImnQJQn9wSImZDMvs3mE4pn0fYIPTRyPQ7qFypV68buPg/3BV bd0v+jUPfVonwtuLbVXVnre6Btrtk5lc15+qBNLLU/S0gvAR3SKszXxyEbGpntFDoHLQ 3Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 360kvke4gh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 18:21:07 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10FIF9vx060465; Fri, 15 Jan 2021 18:19:06 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 360keq7y3h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 18:19:06 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 10FIJ4Dk029583; Fri, 15 Jan 2021 18:19:04 GMT Received: from dhcp-10-39-219-53.vpn.oracle.com (/10.39.219.53) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Jan 2021 10:19:03 -0800 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Subject: Re: [PATCH v19 08/20] io: add qio_channel_readv_full_all_eof & qio_channel_readv_full_all helpers From: Jag Raman In-Reply-To: <20210115092017.GA334489@stefanha-x1.localdomain> Date: Fri, 15 Jan 2021 13:19:01 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: References: <02a82c80a35ab60b98028c85aa94f688a2843943.1610638428.git.jag.raman@oracle.com> <20210114162729.GB306329@stefanha-x1.localdomain> <20210114180035.GY1643043@redhat.com> <1DE4BD83-5AD6-4F70-8702-03DE1548DBED@oracle.com> <20210115092017.GA334489@stefanha-x1.localdomain> To: Stefan Hajnoczi X-Mailer: Apple Mail (2.3654.40.0.2.32) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9865 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150110 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9865 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150110 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Elena Ufimtseva , Fam Zheng , Swapnil Ingle , John G Johnson , qemu-level , Gerd Hoffmann , quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, alex.williamson@redhat.com, thanos.makatos@nutanix.com, kwolf@redhat.com, =?utf-8?B?IkRhbmllbCBQLiBCZXJyYW5nw6ki?= , mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" > On Jan 15, 2021, at 4:20 AM, Stefan Hajnoczi = wrote: >=20 > On Thu, Jan 14, 2021 at 01:24:37PM -0500, Jag Raman wrote: >>=20 >>=20 >>> On Jan 14, 2021, at 1:00 PM, Daniel P. Berrang=C3=A9 = wrote: >>>=20 >>> On Thu, Jan 14, 2021 at 12:55:58PM -0500, Jag Raman wrote: >>>>=20 >>>>=20 >>>>> On Jan 14, 2021, at 11:27 AM, Stefan Hajnoczi = wrote: >>>>>=20 >>>>> On Thu, Jan 14, 2021 at 10:40:03AM -0500, Jagannathan Raman wrote: >>>>>> +int qio_channel_readv_full_all(QIOChannel *ioc, >>>>>> + const struct iovec *iov, >>>>>> + size_t niov, >>>>>> + int **fds, size_t *nfds, >>>>>> + Error **errp) >>>>>> { >>>>>> - int ret =3D qio_channel_readv_all_eof(ioc, iov, niov, errp); >>>>>> + int ret =3D qio_channel_readv_full_all_eof(ioc, iov, niov, = fds, nfds, errp); >>>>>>=20 >>>>>> if (ret =3D=3D 0) { >>>>>> - ret =3D -1; >>>>>> error_setg(errp, >>>>>> "Unexpected end-of-file before all bytes were = read"); >>>>>=20 >>>>> qio_channel_readv_full_all_eof() can read file descriptors but no = data >>>>> and return 0. >>>>>=20 >>>>> Here that case is converted into an error and the file descriptors >>>>> aren't closed, freed, and fds/nfds isn't cleared. >>>>=20 >>>> That=E2=80=99s a valid point. I=E2=80=99m wondering if the fix for = this case should be in >>>> qio_channel_readv_full_all_eof(), instead of here. >>>>=20 >>>> qio_channel_readv_full_all_eof() should probably return error (-1) = if the >>>> amount of data read does not match iov_size(). If the caller is = only expecting >>>> to read fds, and not any data, it would indicate that by setting = iov to NULL >>>> and/or setting niov=3D0. If the caller is setting these parameters, = it means it is >>>> expecting data.Does that sound good? >>>=20 >>> The API spec for the existing _eof() methods says: >>>=20 >>> * The function will wait for all requested data >>> * to be read, yielding from the current coroutine >>> * if required. >>> * >>> * If end-of-file occurs before any data is read, >>> * no error is reported; otherwise, if it occurs >>> * before all requested data has been read, an error >>> * will be reported. >>>=20 >>>=20 >>> IOW, return '0' is *only* valid if we've not read anything. I = consider >>> file descriptors to be something. >>>=20 >>> IOW, qio_channel_readv_full_all_eof must only return 0, if it didn't >>> read any data and also didn't receive any file descriptors. So yeah, >>> we must return -1 in the scenario Stefan describes >>=20 >> That makes sense to me. Reading =E2=80=9Cfds" is something, which is = different >> from our previous understanding. I thought data only meant iov, and = not fds. >>=20 >> So the return values for qio_channel_readv_full_all_eof() would be: >> - =E2=80=980=E2=80=99 only if EOF is reached without reading any fds = and data. >> - =E2=80=981=E2=80=99 if all data that the caller expects are read = (even if the caller reads >> fds exclusively, without any iovs) >> - =E2=80=98-1=E2=80=99 otherwise, considered as error >>=20 >> qio_channel_readv_full_all() would return: >> - =E2=80=980=E2=80=99 if all the data that caller expects are read >> - =E2=80=98-1=E2=80=99 otherwise, considered as error >>=20 >> Hey Stefan, >>=20 >> Does this sound good to you? >=20 > The while (nlocal_iov > 0) loop only runs if the caller has requested = to > read at least some data, so the fds-only case doesn't work yet. >=20 > This suggests that no current QEMU code relies on the fds-only case. > Therefore you could change the doc comment to clarify this instead of > adding support for this case to the code. >=20 > But if you would to fully support the fds-only case that would be even > better. >=20 > Stefan We are working on sending the next revision out. We could handle the fds-only case by altering the while loop condition to be: ((nlocal_iov > 0) || local_fds) For reference, we would need to handle the following cases: len < 0; !partial, !*nfds =3D> ret =3D -1; len =3D 0; !partial, !*nfds =3D> ret =3D 0; len < 0; partial, !*nfds =3D> ret =3D -1; errmsg; len =3D 0; partial, !*nfds =3D> ret =3D -1; errmsg; len < 0; partial, *nfds =3D> ret =3D -1; errmsg, clearfds len < 0; !partial, *nfds =3D> ret =3D -1; errmsg, clearfds len =3D 0; partial, *nfds =3D> ret =3D -1; errmsg, clearfds len =3D 0; !partial, *nfds =3D> ret =3D -1; errmsg, clearfds len =3D 0; !niov; (nfds && *nfds) =3D> ret =3D 1 /* fds-only */ len > 0 =3D> ret 1 Thank you! -- Jag=