Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4055288ybl; Mon, 12 Aug 2019 10:34:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoxGXQf/+tUIt8ohaxDtgVq53yrow+7JvUs4nSOSvrUsktGCJsUvJ4wq7hSTV0CAzbMH/N X-Received: by 2002:a17:90a:5884:: with SMTP id j4mr395085pji.142.1565631261396; Mon, 12 Aug 2019 10:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565631261; cv=none; d=google.com; s=arc-20160816; b=YJDTl8ZfIz3PF6TuvRdK3J9fb6eVhQqFaLXqfbf1lfifOUirFMDQRSY36LQtaZfWEB v17YdsdidhBHyd21P89cNqjP1LA1qSG7p56hHYHv0eASUGjmxSUYwFzfgsPtK3y5Ooi4 TQonMGjoPSDtwXTJAboDVXBgH9CgkxDxLVSS8oZKdzusk+K45YyBoD4QkjrXLaXjmA55 Q4FlQzripAy+MlaLACi2m2HVCtKE+NEgpZXyllzL3I1CMBHBAASAxVU2XF16PWPq5iHb BVDuOG9T1hDy0oJyQI1yM+itF0N8+qpDc5wnGHt6+DUR+XDyTuIJhuky28+4ZCA+X8ew 1CYw== 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:dkim-signature; bh=S7OxrYIMYsN/W+LCGLpx5eZGJ38yfnWGIGCyNhp6UUs=; b=veGW7fGvj6rs38d2HWNWtJypYxt+KagXKMpsjPGaBLkSVYi6be4a6R2iPTU/HZ0cD2 3tkDJU2wellg6xr9dicTdE+9jIvVWVbRsisI8xYE4RVagQ7LMkBhJ0qM95/XxIBWrfjh f0Mh7l4gc5kuLtz7MLIfbk9vsjrCiiWA2es2oJFFpO35AHNytyr9Xw2XLaB5JW2mNDHl PEM4bRoL/FPAL8wbINLH3cWhGhsyeguG2MDUftL6awkLWFZENnxzsk+LVSgPEfI4LZQx qmmkutdwQjhdV8jILAwaDhGPPpzcO0l0gIYzcTL6ZzaUUF2Ym6K9np4F3yZIUZcfm5CV ck0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=siMt8ySy; 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 i8si61652738pgs.87.2019.08.12.10.34.07; Mon, 12 Aug 2019 10:34:21 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=siMt8ySy; 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 S1727159AbfHLReE (ORCPT + 99 others); Mon, 12 Aug 2019 13:34:04 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58528 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbfHLReE (ORCPT ); Mon, 12 Aug 2019 13:34:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S7OxrYIMYsN/W+LCGLpx5eZGJ38yfnWGIGCyNhp6UUs=; b=siMt8ySyjx8VBRwG9UBLi9/9Q eIb2vh9FVKtsyto60QRv/soDWmLheyImHtVNWCTCsOAjn+g3q4wksfWYxRSHEfZ6WIwGnts20pFFb DleAN4say0ePpI4hO/xxlxbtaYjGav12UZcd4E7fnGV4db0tza9Om0sKNjOO1zpvig2fyWvQOT3k+ osaWOz1a5c/p946nTJXF1+1Pf1L0pmNuM3Oy/56p6Crxtk4xdzfHsf9Z/5YCRc3NNPsHqinMtHhMd Sr+SV+CLdX3J9s2m4G1hvrr+3RhG32WogKbPYeECTD6lGCgrYTqNU9i/yEkGT8DJgu2WfQrtmEmJ8 TjV45CCeA==; Received: from hch by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1hxECp-0000x8-Jr; Mon, 12 Aug 2019 17:34:03 +0000 Date: Mon, 12 Aug 2019 10:34:03 -0700 From: Christoph Hellwig To: Matthew Bobrowski Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz, tytso@mit.edu, riteshh@linux.ibm.com Subject: Re: [PATCH 4/5] ext4: introduce direct IO write code path using iomap infrastructure Message-ID: <20190812173403.GD24564@infradead.org> References: <581c3a2da89991e7ce5862d93dcfb23e1dc8ddc8.1565609891.git.mbobrowski@mbobrowski.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <581c3a2da89991e7ce5862d93dcfb23e1dc8ddc8.1565609891.git.mbobrowski@mbobrowski.org> User-Agent: Mutt/1.11.4 (2019-03-13) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org > + if (error) { > + if (offset + size > i_size_read(inode)) > + ext4_truncate_failed_write(inode); > + > + /* > + * The inode may have been placed onto the orphan list > + * as a result of an extension. However, an error may > + * have been encountered prior to being able to > + * complete the write operation. Perform any necessary > + * clean up in this case. > + */ > + if (!list_empty(&EXT4_I(inode)->i_orphan)) { > + handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); > + if (IS_ERR(handle)) { > + if (inode->i_nlink) > + ext4_orphan_del(NULL, inode); > + return PTR_ERR(handle); > + } > + > + if (inode->i_nlink) > + ext4_orphan_del(handle, inode); > + ext4_journal_stop(handle); > + } > + return error; I'd split this branch into a separate function just to keep the end_io handler tidy. > + if (ret == -EIOCBQUEUED && (unaligned_aio || extend)) > + inode_dio_wait(inode); > + > + if (ret >= 0 && iov_iter_count(from)) { > + overwrite ? inode_unlock_shared(inode) : inode_unlock(inode); > + return ext4_buffered_write_iter(iocb, from); > + } > +out: > + overwrite ? inode_unlock_shared(inode) : inode_unlock(inode); > + return ret; the ? : expression here is weird. I'd write this as: if (overwrite) inode_unlock_shared(inode); else inode_unlock(inode); if (ret >= 0 && iov_iter_count(from)) return ext4_buffered_write_iter(iocb, from); return ret; and handle the only place we jump to the current out label manually, as that always does an exclusive unlock anyway. > + if (IS_DAX(inode)) { > + ret = ext4_map_blocks(handle, inode, &map, > + EXT4_GET_BLOCKS_CREATE_ZERO); > + } else { > + /* > + * DAX and direct IO are the only two > + * operations currently supported with > + * IOMAP_WRITE. > + */ > + WARN_ON(!(flags & IOMAP_DIRECT)); > + if (round_down(offset, i_blocksize(inode)) >= > + i_size_read(inode)) { > + ret = ext4_map_blocks(handle, inode, &map, > + EXT4_GET_BLOCKS_CREATE); > + } else if (!ext4_test_inode_flag(inode, > + EXT4_INODE_EXTENTS)) { > + /* > + * We cannot fill holes in indirect > + * tree based inodes as that could > + * expose stale data in the case of a > + * crash. Use magic error code to > + * fallback to buffered IO. > + */ > + ret = ext4_map_blocks(handle, inode, &map, 0); > + if (ret == 0) > + ret = -ENOTBLK; > + } else { > + ret = ext4_map_blocks(handle, inode, &map, > + EXT4_GET_BLOCKS_IO_CREATE_EXT); > + } > + } I think this could be simplified down to something like: int flags = 0; ... /* * DAX and direct IO are the only two operations currently * supported with IOMAP_WRITE. */ WARN_ON(!IS_DAX(inode) && !(flags & IOMAP_DIRECT)); if (IS_DAX(inode)) flags = EXT4_GET_BLOCKS_CREATE_ZERO; else if (round_down(offset, i_blocksize(inode)) >= i_size_read(inode)) { flags = EXT4_GET_BLOCKS_CREATE; else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) flags = EXT4_GET_BLOCKS_IO_CREATE_EXT; /* * We cannot fill holes in indirect tree based inodes as that * could expose stale data in the case of a crash. Use the * magic error code to fallback to buffered IO. */ if (!flags && !ret) ret = -ENOTBLK; > @@ -3601,6 +3631,8 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, > static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, > ssize_t written, unsigned flags, struct iomap *iomap) > { > + if (flags & IOMAP_DIRECT && written == 0) > + return -ENOTBLK; This probably wants a comment, too. But do we actually ever end up here?