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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 D7BF7C433E6 for ; Tue, 2 Feb 2021 00:26:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB55064E8D for ; Tue, 2 Feb 2021 00:26:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbhBBA0W (ORCPT ); Mon, 1 Feb 2021 19:26:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbhBBA0V (ORCPT ); Mon, 1 Feb 2021 19:26:21 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21F37C061786 for ; Mon, 1 Feb 2021 16:25:41 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id 6so18557321wri.3 for ; Mon, 01 Feb 2021 16:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qIoqyE4Fpaf6vuFNVJumhbJQpn+cWb3TqLJpyRoKHzs=; b=vIvSXiLO3V1b39+4D364pOljLPUhZPoCOA6bSZOd69B4glgvUgA8XzT92N7OpbZ9ex O/4IySeuH4cXzb3eUItCoeW29N7betoKgeCr45hF3jY92zZJ7+TJmLUdIzwt7VPBlfiH on7NaxBpt+QOlE1CKjieSV1ZXgHm3yqIu/JPKxFqKtX7yFaRpMYoyRB2BFIIEUpt2l2f th2eWLVONALKDSPVrTb9+BjFDDTKaiJkkwvgZkgctr28b4rAjtDmXTnRj6sw6HBn5E/d g2ilMQC+c6IdShA2nckqLbIk5sEk9/MkVOdP/bGbxd1RkiqPqdvLv2zpvQmBrNXHny1W OzDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qIoqyE4Fpaf6vuFNVJumhbJQpn+cWb3TqLJpyRoKHzs=; b=CRj4oyqTDj8VwjA73LFQM/AjLqu4IcltSQUArRIhw96r39SX2olU5TJaQmGwNDe/rI LqG1MsEHcgDqb/9Yg2MppN3zUO2GzRKjClYZHcrWColLtHS3OopKhkoaYwTMWMb7ux2w a0yICaHZTG2f8nW5BjOWWh8oz0gESKGGXtynGLGt7V+NUeZflZx2aldRIDnkImyZJkhk XO7yUtJy4FDguhdBBgMrzmzl9/SBgcMEPH2psp1muLQDwHsAcxsv+r0RheC7ao2ecjM/ VQNdgNzcVPsiE6p+q7KKXcnbgq9fHCqkEE1G17AKJT2WEL4H1fvcfBSy3LMetvQ9D7bD o0Ag== X-Gm-Message-State: AOAM5329InoEV+YGy/tJk824k9bLqsZJTCHyDT9iIhO+RQ7dpFa9BdWH eALBkYjJn/uM0v87OJPhEMc= X-Google-Smtp-Source: ABdhPJynzrM/W6pGHqaLYqQOM9LOt9uuvMckaOkRIHBHAnxF37O2oZA9dNiM/3HwF90G9dsh5ilx4w== X-Received: by 2002:adf:df12:: with SMTP id y18mr20933242wrl.141.1612225539940; Mon, 01 Feb 2021 16:25:39 -0800 (PST) Received: from localhost.localdomain ([185.69.145.241]) by smtp.gmail.com with ESMTPSA id n187sm851740wmf.29.2021.02.01.16.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 16:25:39 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org Subject: [PATCH 5/8] io_uring: further simplify do_read error parsing Date: Tue, 2 Feb 2021 00:21:43 +0000 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org First, instead of checking iov_iter_count(iter) for 0 to find out that all needed bytes were read, just compare returned code against io_size. It's more reliable and arguably cleaner. Also, place the half-read case into an else branch and delete an extra label. Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 866e0ea83dbe..1d1fa1f77332 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3552,19 +3552,18 @@ static int io_read(struct io_kiocb *req, bool force_nonblock, /* some cases will consume bytes even on error returns */ iov_iter_revert(iter, io_size - iov_iter_count(iter)); ret = 0; - goto copy_iov; - } else if (ret <= 0) { + } else if (ret <= 0 || ret == io_size) { /* make sure -ERESTARTSYS -> -EINTR is done */ goto done; - } + } else { + /* we did blocking attempt. no retry. */ + if (!force_nonblock || (req->file->f_flags & O_NONBLOCK) || + !(req->flags & REQ_F_ISREG)) + goto done; - /* read it all, or we did blocking attempt. no retry. */ - if (!iov_iter_count(iter) || !force_nonblock || - (req->file->f_flags & O_NONBLOCK) || !(req->flags & REQ_F_ISREG)) - goto done; + io_size -= ret; + } - io_size -= ret; -copy_iov: ret2 = io_setup_async_rw(req, iovec, inline_vecs, iter, true); if (ret2) { ret = ret2; -- 2.24.0