Received: by 2002:a17:90a:37e8:0:0:0:0 with SMTP id v95csp4243062pjb; Mon, 21 Oct 2019 02:21:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0CSJmQL8FQQ8VDrVRdZXqlU6AR0rZGKIlqXMxDYUXNeUDUU7vetoMhZd0PTjXwbkcZa7Q X-Received: by 2002:a05:6402:1b1a:: with SMTP id by26mr23813240edb.178.1571649670724; Mon, 21 Oct 2019 02:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571649670; cv=none; d=google.com; s=arc-20160816; b=CfCQeoST4kaYKIbIGAXkjsHy1siSEyh6D2R8RAGmrDPFuDF7jcR95b/TMwSNdHEPcO mRhqdptK2UxfP7sdZCu5k+i2t1ogdtWxWJ2KnrXpk8plQi0NCMxqWzWEs8xmPsImvRe1 sVC9J09w3XsUdYokopwxHHRwOOOBM+ZTupHlitPDzLhndYG88GbHR++QafPw+RQIWHb1 Z4tSsYnC9DCkff8DprVeIZJ0p81f+LOAckUdDY8qUGCGIl12Zstw7KMfMJ3CO9t2GhLd znMlbxRPCPdtJ5oOC11sYnhv/UMYU/S8toYnhFMXGQgspcU2FpdouFHVtYYKkUzqlg4Y g5Qw== 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=14Kemxr7lge9hljjqfibah/1nIDd0rrIrEFWCQLuEzY=; b=E3/hQmzQpXb2uDOq14rbokv4aQBXUR8S7pZySwDvhvsdErVuoOJwcfRexipb6rDaX9 ijpny5v8PGdrkkxY1zq55U4HS2VwabxqARX0ZscmROTWDZboWvPbN3cFV7gYrKb1/Vbx DO0sFYdmNczJpOPtzHy2mLcvYEDmvqBIcYlaJeveJPeaRNeAYeZA8jQgk+mQTT7AosOh IIfWPs+mO0GOg8VY7GTFf0T88mWrZhTGHPEBAVBoJzaCIdDMctkzDzhnRHKd7ZaUAcNT Li6k+P+z2oHmRH3EWyR+7Mmpvsoh0yD8LbE4P/uHcN/xxGGra4zLYBWPoBh3j8ASIsdq Us9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=1cviomBF; 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 e24si1021346ede.392.2019.10.21.02.20.46; Mon, 21 Oct 2019 02:21:10 -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=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=1cviomBF; 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 S1727403AbfJUJUp (ORCPT + 99 others); Mon, 21 Oct 2019 05:20:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37619 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfJUJUo (ORCPT ); Mon, 21 Oct 2019 05:20:44 -0400 Received: by mail-pl1-f195.google.com with SMTP id u20so6325240plq.4 for ; Mon, 21 Oct 2019 02:20:44 -0700 (PDT) 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=14Kemxr7lge9hljjqfibah/1nIDd0rrIrEFWCQLuEzY=; b=1cviomBFXuaJ3UL4IfzswfJQCNXYohWbh+Bra0LiHQ8+rtey2VTsoBXr3aMYl0voUz 3YeJ1p1+f7m3Mvc5v29JKHhV+5h/otmPs5Q97H1+gtiz4lDQ0yU7JhoaWFeZxnrxoqyW 2g+sJ7cI4iklRw8oW2j/qgjAM+duC7UL0TVPCJxvIrQOaw6P2gLzbln4+/7UUlqppM+c MaDk1XGOl3EbfQCUUmCtAt/SEi91kAHPLqcj5EcdSja5yxTqj9bYC1EhmqKYSb4Nru5e OD7bu8xgRBERCMYOqbqEZmdtZWNfXGwRhW0YVAkiNTiGukuHFMe4gdyqs9tVa5eZogh+ M14w== 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=14Kemxr7lge9hljjqfibah/1nIDd0rrIrEFWCQLuEzY=; b=jVjnYrDJ2XYUWkIogCuwWjBtypBbHuJ5hlIDTU9k3u61aBAruX4c5cIp0ftF97zW4j bEwWWqeqrAVJy6klceqmmeVnjgvI194HitiaAoHYR49a/nJGdnEr66a5dUsYL642NWfp IevwKWsk2DP0/BarfaiPQZV3A5P9atpiZHD6IrMy170YXFTFxQK7Hm0zkODckISZRqHS k6+34YdEbbQSrbKb0d/whBmhpgfKq7ANs31e11RTspLydGdJUgqRpRV5M7emdttcC6Or D/cURkU/RTOzutOKRizDLHKqfF28oZzinM9LqTq8QDVPio6I0i9FTxdNmMOkIEeR58QV xlOw== X-Gm-Message-State: APjAAAXruD8kSeDu262Hwh6J2Mno0jnifO9lEvFApETeoh3RMIqLjwCk +uSzkAfs8OPuIE6ma8rNx6zO X-Received: by 2002:a17:902:9881:: with SMTP id s1mr24240292plp.18.1571649644096; Mon, 21 Oct 2019 02:20:44 -0700 (PDT) Received: from athena.bobrowski.net (n1-41-199-60.bla2.nsw.optusnet.com.au. [1.41.199.60]) by smtp.gmail.com with ESMTPSA id q3sm15422277pgj.54.2019.10.21.02.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 02:20:43 -0700 (PDT) Date: Mon, 21 Oct 2019 20:20:37 +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, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: [PATCH v5 10/12] 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() function. Signed-off-by: Matthew Bobrowski Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani --- fs/ext4/file.c | 21 ++++++++++++++++++++- fs/ext4/inode.c | 22 ---------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 6ddf00265988..65e758ae02d0 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -304,6 +304,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)) { @@ -323,8 +325,25 @@ 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, ret, offset, count); + if (extend) + ret = ext4_handle_inode_extension(inode, ret, offset, count); out: inode_unlock(inode); if (ret > 0) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f79d15e8d3c6..a37112efe3fb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3443,7 +3443,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; /* @@ -3466,28 +3465,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 have 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 the 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 ----