Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp754004ybg; Thu, 19 Mar 2020 08:10:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsbwveQGABr0MdcsQT6Q1mC0nX4PRNrJjW39W4qmoPGgJYbF+Mo+Wct9akUmhXVwKmSuZWV X-Received: by 2002:aca:2b04:: with SMTP id i4mr2747494oik.61.1584630653403; Thu, 19 Mar 2020 08:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584630653; cv=none; d=google.com; s=arc-20160816; b=TZt9/t/4QSq66WiJpo0+6oxSd+plNL6utJpHY+oHSyuKsAb/qOAaDexC9pgbetaxVb i8j5GVwfxn5oyeDcTE31qqKZRuvrYM5EdSBkVu9ojzaX+25yWtSZiLBuob/un7Gtwjqs dWOOwfGOwCurBgqY/0yR7Hx/HFq15HpsJU3Q/MuQ2qoDXs/ERsEt4vPuXYGumqdA+TJy 6Wq+SCNuzvjKDyuQ/bynIQtGsAqVrJa/Gr/0VzR7JTwaayeZvoTgDbAOyRB+h+njs5Pb +gNpZJwCZIhsma02GDvfp1I/xZonmvc2WOS+ZETYL+DVLUn4n7jrVACqJsFKSS8/oZPk EETA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=TVGLrAxTioH3D0/LeC0l7Y2xVSAalc5UKbKN0ODKIQk=; b=KuESQvTbM09n0hgUFK3ASai2D7rr8pC3tTzzydmtoTP5EGqxijsBgnLY1S3/JpoWDh EcIXwitMUh3x2JrjEcz/mf6uUa3u3RQU/IYg6jxFKIBOU8h/eExD1Yb7QIp5c6zNoSxc pWYg62YcVy9CshUgtzKhe2gt3hmxN3Ah9UvH7HkKsjXkO5FAcj0DrnCQqyxUidNUu7uC +Tx9MkB4lFr5DZUC5YDXNVyKlIpDh3skQFAJLmyuo/wzjXmCbSSl4AxeEuE1qXOHzD+C 1E8HtGtNVQ8jxBmAPSDs9LSv2ox/qJNn79uHwJF8wH4Ch092H7CXBZ7KYSRUveZCktws Q+Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si1373780otr.322.2020.03.19.08.10.32; Thu, 19 Mar 2020 08:10:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbgCSPIM (ORCPT + 99 others); Thu, 19 Mar 2020 11:08:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:56254 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPIM (ORCPT ); Thu, 19 Mar 2020 11:08:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1085CACC2; Thu, 19 Mar 2020 15:08:10 +0000 (UTC) Date: Thu, 19 Mar 2020 10:08:05 -0500 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: riteshh@linux.ibm.com, linux-ext4@vger.kernel.org, hch@infradead.org, darrick.wong@oracle.com, willy@infradead.org Subject: [PATCH v2] iomap: return partial I/O count on error in iomap_dio_bio_actor Message-ID: <20200319150805.uaggnfue5xgaougx@fiona> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20180716 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently, I/Os that complete with an error indicate this by passing written == 0 to the iomap_end function. However, btrfs needs to know how many bytes were written for its own accounting. Change the convention to pass the number of bytes which were actually written, and change the only user (ext4) to check for a short write instead of a zero length write. For filesystems that do not define ->iomap_end(), check for dio->error again after the iomap_apply() call to diagnose the error. Changes since v1: - Considerate of iov_iter rollback functions - Double check errors for filesystems not implementing iomap_end() Signed-off-by: Goldwyn Rodrigues diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fa0ff78..d52c70f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3475,7 +3475,7 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, * the I/O. Any blocks that may have been allocated in preparation for * the direct I/O will be reused during buffered I/O. */ - if (flags & (IOMAP_WRITE | IOMAP_DIRECT) && written == 0) + if (flags & (IOMAP_WRITE | IOMAP_DIRECT) && written < length) return -ENOTBLK; return 0; diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 41c1e7c..b5f4d4a 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -264,7 +264,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, size_t n; if (dio->error) { iov_iter_revert(dio->submit.iter, copied); - copied = ret = 0; + ret = dio->error; goto out; } @@ -325,8 +325,17 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, iomap_dio_zero(dio, iomap, pos, fs_block_size - pad); } out: - /* Undo iter limitation to current extent */ - iov_iter_reexpand(dio->submit.iter, orig_count - copied); + /* + * Undo iter limitation to current extent + * If there is an error, undo the entire extent. However, return the + * bytes copied so far for filesystems such as btrfs to account for + * submitted I/O. + */ + if (ret < 0) + iov_iter_reexpand(dio->submit.iter, orig_count); + else + iov_iter_reexpand(dio->submit.iter, orig_count - copied); + if (copied) return copied; return ret; @@ -499,6 +508,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, do { ret = iomap_apply(inode, pos, count, flags, ops, dio, iomap_dio_actor); + + if (ret >= 0 && dio->error) + ret = dio->error; + if (ret <= 0) { /* magic error code to fall back to buffered I/O */ if (ret == -ENOTBLK) { -- Goldwyn