From patchwork Wed Jun 1 21:01:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12867236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 967CCCCA479 for ; Wed, 1 Jun 2022 21:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbiFAVB5 (ORCPT ); Wed, 1 Jun 2022 17:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiFAVBz (ORCPT ); Wed, 1 Jun 2022 17:01:55 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894AC34B9C for ; Wed, 1 Jun 2022 14:01:54 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 251INehb008370 for ; Wed, 1 Jun 2022 14:01:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=5yh7bJ43zWawOb4heVTpXC/CGgCWptHJL+luNQUKZk8=; b=Hb4u4VI4+HqIbREptSYISF37ee5WH7G2UhrsgYnaVn9M1VbVf/3oPo+9LG/Hg53XsDHf OFvif8yn9lOYgJsl+13VXhC8j5A5d474Z+JGYTbn+6uvCMHtVn6oPWbXoT/+ZPle1hcl nkXri9gI21BytzWLmgZmB4g6aIUJnXNYuXo= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ge5vcm8yc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 01 Jun 2022 14:01:54 -0700 Received: from twshared10560.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 1 Jun 2022 14:01:52 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id D5A49FEB23A1; Wed, 1 Jun 2022 14:01:42 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , Subject: [PATCH v7 06/15] iomap: Return error code from iomap_write_iter() Date: Wed, 1 Jun 2022 14:01:32 -0700 Message-ID: <20220601210141.3773402-7-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220601210141.3773402-1-shr@fb.com> References: <20220601210141.3773402-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: -W4vK19ln1_hODJ-bJJL43Hqq16Bfjau X-Proofpoint-ORIG-GUID: -W4vK19ln1_hODJ-bJJL43Hqq16Bfjau X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-01_08,2022-06-01_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Change the signature of iomap_write_iter() to return an error code. In case we cannot allocate a page in iomap_write_begin(), we will not retry the memory alloction in iomap_write_begin(). Signed-off-by: Stefan Roesch --- fs/iomap/buffered-io.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index b06a5c24a4db..e96ab9a3072c 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -754,12 +754,13 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, return ret; } -static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) +static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i, loff_t *processed) { loff_t length = iomap_length(iter); loff_t pos = iter->pos; ssize_t written = 0; long status = 0; + int error = 0; struct address_space *mapping = iter->inode->i_mapping; unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0; @@ -774,9 +775,9 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) bytes = min_t(unsigned long, PAGE_SIZE - offset, iov_iter_count(i)); again: - status = balance_dirty_pages_ratelimited_flags(mapping, + error = balance_dirty_pages_ratelimited_flags(mapping, bdp_flags); - if (unlikely(status)) + if (unlikely(error)) break; if (bytes > length) @@ -793,12 +794,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) * faulting the user page. */ if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { - status = -EFAULT; + error = -EFAULT; break; } - status = iomap_write_begin(iter, pos, bytes, &folio); - if (unlikely(status)) + error = iomap_write_begin(iter, pos, bytes, &folio); + if (unlikely(error)) break; page = folio_file_page(folio, pos >> PAGE_SHIFT); @@ -829,7 +830,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) length -= status; } while (iov_iter_count(i) && length); - return written ? written : status; + *processed = written ? written : error; + return error; } ssize_t @@ -843,12 +845,15 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, .flags = IOMAP_WRITE, }; int ret; + int error = 0; if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; - while ((ret = iomap_iter(&iter, ops)) > 0) - iter.processed = iomap_write_iter(&iter, i); + while ((ret = iomap_iter(&iter, ops)) > 0) { + if (error != -EAGAIN) + error = iomap_write_iter(&iter, i, &iter.processed); + } if (iter.pos == iocb->ki_pos) return ret; return iter.pos - iocb->ki_pos;