Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp686548ybx; Tue, 5 Nov 2019 04:03:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyZ/ceVzlvl78xrBZ/JYB2k3WLjLDqmOc2WqKTSxeW7BXiUV9j7FS5TOXdH1Icm+1LI2JSz X-Received: by 2002:a17:906:edd2:: with SMTP id sb18mr11144631ejb.112.1572955424467; Tue, 05 Nov 2019 04:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572955424; cv=none; d=google.com; s=arc-20160816; b=gwu7LUnBuH5O60uuTaMOo++Boi6WJEheodJ2g27fskh2NCz6ZDXlPcqAoxXKcfr0sx MIjvdwn1T4peRvlHfDjp0TPtgx98k6s860vPh+GPTBGhJXM6JTlm2zpXEGDpU/1TYnjf PTCCX8GaRs2C4hSFPmNQjUIfEuut7+F99xf+6P8s4l+/SEZuJidUjtGHNUOg1cTVUZUV AYhvx0KUtCO4CnGoeuIlPCd/46nT9qDU69I0XFqc+h6OfFqX4Sp1jV01w1R0vE+L29Et KF7P2nSKg2cMpMwYnLb6FfugLIZHR5hisgvTt4pvYevQjlKIAgmMb5/biA56VxsItwu9 tQNA== 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=C4JTtLfW0Tocso0HHtIJVM1LwapQ7u0zpOXtwObQFvU=; b=u7abfBzt2RnB/C4+itVFxWpnB7kYDRPXm2nYXyYqtuoYs7HGhEw8u+uwlvsJaqTulZ YRlWuNMLc+BDJfCd0d6H8SX+tbMZaIKAvkSdgwIirLxff6nXnpECLsx9wdQlNqTdSKRM eUCLZ8VBW8/G5/4fYgrBGmZOVunB1UQxsrd2C09jHT0qEFrWxHqqBNE0raPws6oivFx9 I2HovGYVMdxhXnf2+imjys5E/U8t7OOR9+OqbTcF7IdljS6AgtVhThE+UdEKBOwDfTF7 i6WfGAHa7fVbYseV4C2ChH/OjfUJ5nHwRvmW2FPEordMajndZH8D9uEcpuoj1brp10jW 133A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=mYAc6W7n; 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 l15si9081455edb.81.2019.11.05.04.02.55; Tue, 05 Nov 2019 04:03:44 -0800 (PST) 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=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=mYAc6W7n; 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 S1726612AbfKEMCR (ORCPT + 99 others); Tue, 5 Nov 2019 07:02:17 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37703 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730816AbfKEMCQ (ORCPT ); Tue, 5 Nov 2019 07:02:16 -0500 Received: by mail-pl1-f195.google.com with SMTP id p13so9297380pll.4 for ; Tue, 05 Nov 2019 04:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=C4JTtLfW0Tocso0HHtIJVM1LwapQ7u0zpOXtwObQFvU=; b=mYAc6W7nwc4HxmM0tO6mmTrtCouBkNtp3MTioj+dDnC69pgwP4DOdEqBXSrz0287UW BWdFgzGMK/pCscuI3gI/11GR1CgmTp7qNI8BdLGgqY6vo8jdfAEgEUHmtCLZHMr/7rL1 4SWPJJ24UfORj7boiOKhQDhyac/DQfPYtRJfOa34y0nPxRVXJzaTbuBgTLpWSuBibR+E e1KEgHlgEhym9Qm7hpAhfHgvL0SJnE71JlQ4Fo4wqKgObhlrglsXS1iVC+QoP5umpD8l Dox8qpIpnceY3spsnuu1jHc22fOSAjCrWNY3t0GXGIkGcM/tndmHHZ+yCB88JT5akqCK eI/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=C4JTtLfW0Tocso0HHtIJVM1LwapQ7u0zpOXtwObQFvU=; b=RzAU/7A9ivLb/kEIAl+uGdIBXpsZwyW9W7bexzAHiHXgS27oLpIcwM7D7bPKDujH6W BI9wlEVD4eAvxpEQMKqmYCgip1Sws5I0lYu1X7kSYcjTCuNFn/ieVoYHVx1QJk0/BmBA GNJtN5QA9NBQV/l3f1IVgUH22IBxYEqhTqzTLqn1qXecDuCcPU2JpiaOiKSJzTNMuQcp 86jQTseyJsCHolk/6DcLu0kFTopARdsDuOXzxNWP+y2Vk/NwUxhSJYlIhaGUkBYUhNGA sYbKm9TwoA5vidPGKyJSfqEdLzqgxh+YuzWm0Dv65xjDSV6CkTqLNftU84EmFhm+FXIx A6OQ== X-Gm-Message-State: APjAAAW5VvYl4llWDkQjnayHQzAzBM70EJu9fOhu3P21VVZY/5fZukAz loz0icREq4WiXMgPyqmGXQsN X-Received: by 2002:a17:902:bcc7:: with SMTP id o7mr33399536pls.333.1572955335852; Tue, 05 Nov 2019 04:02:15 -0800 (PST) Received: from poseidon.bobrowski.net ([114.78.226.167]) by smtp.gmail.com with ESMTPSA id j14sm19921156pje.17.2019.11.05.04.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 04:02:14 -0800 (PST) Date: Tue, 5 Nov 2019 23:02:08 +1100 From: Matthew Bobrowski To: tytso@mit.edu, jack@suse.cz, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, riteshh@linux.ibm.com Subject: [PATCH v7 09/11] ext4: move inode extension check out from ext4_iomap_alloc() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Lift the inode extension/orphan list handling code out from ext4_iomap_alloc() and apply it within the ext4_dax_write_iter(). Signed-off-by: Matthew Bobrowski Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani --- fs/ext4/file.c | 24 +++++++++++++++++++++++- fs/ext4/inode.c | 22 ---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index ec54fec96a81..83ef9c9ed208 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -323,6 +323,8 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from) ssize_t ret; size_t count; loff_t offset; + handle_t *handle; + bool extend = false; struct inode *inode = file_inode(iocb->ki_filp); if (!inode_trylock(inode)) { @@ -342,8 +344,28 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from) offset = iocb->ki_pos; count = iov_iter_count(from); + + if (offset + count > EXT4_I(inode)->i_disksize) { + handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); + if (IS_ERR(handle)) { + ret = PTR_ERR(handle); + goto out; + } + + ret = ext4_orphan_add(handle, inode); + if (ret) { + ext4_journal_stop(handle); + goto out; + } + + extend = true; + ext4_journal_stop(handle); + } + ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops); - ret = ext4_handle_inode_extension(inode, offset, ret, count); + + if (extend) + ret = ext4_handle_inode_extension(inode, offset, ret, count); out: inode_unlock(inode); if (ret > 0) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 071a1f976aab..392085aa7809 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3494,7 +3494,6 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, unsigned int flags) { handle_t *handle; - u8 blkbits = inode->i_blkbits; int ret, dio_credits, retries = 0; /* @@ -3517,28 +3516,7 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, return PTR_ERR(handle); ret = ext4_map_blocks(handle, inode, map, EXT4_GET_BLOCKS_CREATE_ZERO); - if (ret < 0) - goto journal_stop; - - /* - * If we've allocated blocks beyond EOF, we need to ensure that they're - * truncated if we crash before updating the inode size metadata within - * ext4_iomap_end(). For faults, we don't need to do that (and cannot - * due to orphan list operations needing an inode_lock()). If we happen - * to instantiate blocks beyond EOF, it is because we race with a - * truncate operation, which already has added the inode onto the - * orphan list. - */ - if (!(flags & IOMAP_FAULT) && map->m_lblk + map->m_len > - (i_size_read(inode) + (1 << blkbits) - 1) >> blkbits) { - int err; - - err = ext4_orphan_add(handle, inode); - if (err < 0) - ret = err; - } -journal_stop: ext4_journal_stop(handle); if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry; -- 2.20.1