From patchwork Wed May 23 14:43:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10421463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E5D96032A for ; Wed, 23 May 2018 14:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F11B28733 for ; Wed, 23 May 2018 14:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 140322843C; Wed, 23 May 2018 14:44:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D73E287E9 for ; Wed, 23 May 2018 14:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D3E46B000C; Wed, 23 May 2018 10:44:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9AA2B6B000D; Wed, 23 May 2018 10:44:12 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 871976B000E; Wed, 23 May 2018 10:44:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 47FC06B000C for ; Wed, 23 May 2018 10:44:12 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id j14-v6so13160790pfn.11 for ; Wed, 23 May 2018 07:44:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=03cweNY80UybEbcUD3SJpAofvksdsz3p0/LSshvbD+g=; b=ORsAb1lDLjGX3GEQGEiY09PNwtmSSiHlZqiEL4lS/2YyzY9Rkae8UHDYAzrVuiUhJT MT2i312b/vgcSNhVZxB1pTvdywwm4YQhsSfGy61k12mYkNVKi0IaAFDfUkkh1GCAH3EP lbW2Q4JUhWSe9kFa9OYJ276NcIJHsYAZNboZNDJoQ8zlN4jKX9FLEF90LjKP4bEQK2vu y0qZI8Yio56jv+pVH0VUkhDGxI+BbDPyhTWhqKRqiz6xeCiggR2pSLx0yaY58XApPr2U /LFzz6vh6g3+H3t/A9NU8xVTGeEabkg0WJAyoQ4NMgGCmHhLpEMbszK0QCIVwlUwNamk Wk0A== X-Gm-Message-State: ALKqPwf8rpKObRRT1zTwoLKWad3YVrtBej6Fdh8ukZKuaJ9+Pb3NDI/i Zt1PCPuJH9LfYVZvZ4JjGASrdzSJT42/OT6KRTI2mpqM5zIFxLSBevw7sA1872t5+XpzjvYr5zT qqbrFczp6NAVps3kiV85z7GZhm82VOFfjdmSo/fkrzMhCDZyOajmuM0aHd9DLpBI= X-Received: by 2002:a63:7747:: with SMTP id s68-v6mr2568151pgc.338.1527086651981; Wed, 23 May 2018 07:44:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJkS+cdG3ZTa22dKWoLZseGTSj3VTl9V7t1trD9DCEjOUBNN2lK5wWdnTF+PS0cEuTfihF X-Received: by 2002:a63:7747:: with SMTP id s68-v6mr2568104pgc.338.1527086650891; Wed, 23 May 2018 07:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527086650; cv=none; d=google.com; s=arc-20160816; b=c4mPwQp6GYlHVWvSzSa2/omzxl3pwpsvUBU8x1xvQA4Qed75rGRmkV+8Jgj9E0C2fY 5vraHBQdraF13R3oe/nrbgNjDz5obf0qejFUjA/GxTlHU4rM1B/C1T3Y2BZO4TF0O8hf H6lyxTkOF2wXl0+RaOltFQktf0KMbhow7ek/DRYyle4kUdJ0HUZfQEjZU2jg2/ckngBe pcL1lti7jTPuxwNb3KM8GE5cukhG2EwKmxR/GwC0LkpccIQISVYY8MSCN+1WE+V8h9dn kNGEt/UgA7f4YwXtw+MwktQq67WXoDeNaHsiHuXvZvAtdeBWZ3eOilFfdzTpsyhqvcuW 2qGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=03cweNY80UybEbcUD3SJpAofvksdsz3p0/LSshvbD+g=; b=mNPT8HmfzNBF1uRUPI9O/1bU4YoOhFdHSnQSz3LKKW74+xoFN5pbQNIBsNbUFVT/dJ PmpjSMNwn33oLbo+f/02g1QC9pIlngCzJPs9i/KMIic3w26SkPXAM9ooSI5krJsbG0Dq Cvw+GCqE7kkXtCeF1wsxuc5PUmzGAPw98S6M/r+0rCbhM5U/I/r6z3epHRtwb5VcUqiZ K9otzKywGG+d/E7cf1EgbjzWcmSfypeo70KYJGs4Z/aQYdMfUlZuQmtTDtG/Xr//40/V UBK8MD1o7Dy5Iv38cfLKyzgeZyUwge19ZzqdHeAmaUumV+JPFeci0b/LHiXsM2DBThq2 1XFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Mp/dYyp1; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id t128-v6si14810365pgc.582.2018.05.23.07.44.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 07:44:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Mp/dYyp1; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: 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=03cweNY80UybEbcUD3SJpAofvksdsz3p0/LSshvbD+g=; b=Mp/dYyp1SGtpxW2+9JfV3/wmD nd9BE7ssb1Ci+GOLSX7LvLWyGJdYtg+RGu8M4f3FigUKnmdMNQxmSgMO9n/75CNgZX6pfgKVG1jAC RrdU0ebjW2mTz3fxUqdlqVvKaEecWWWJ/H6iGvChrSDdXcj13DPhSEU5FyY7RdofXNcih/UNTdvaB xitO49DghAcwLvIcBlZJ2+HRVMkB7tJ9qqeFmZFaRMJ2zjKr4HDuQlcmaRnvw86FTV9z2NHqZKn+X QlejY3OI+OGto0s1395upE0rhEBapzJDM37F9yL9L4moVtThTZfWEYW6fwn49Ro16tlbHCAkQOqhj 5AlMm8Tww==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLUzn-00007q-AW; Wed, 23 May 2018 14:44:07 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/34] fs: factor out a __generic_write_end helper Date: Wed, 23 May 2018 16:43:25 +0200 Message-Id: <20180523144357.18985-3-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523144357.18985-1-hch@lst.de> References: <20180523144357.18985-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Bits of the buffer.c based write_end implementations that don't know about buffer_heads and can be reused by other implementations. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/buffer.c | 67 +++++++++++++++++++++++++++------------------------ fs/internal.h | 2 ++ 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 249b83fafe48..bd964b2ad99a 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2076,6 +2076,40 @@ int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len, } EXPORT_SYMBOL(block_write_begin); +int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, + struct page *page) +{ + loff_t old_size = inode->i_size; + bool i_size_changed = false; + + /* + * No need to use i_size_read() here, the i_size cannot change under us + * because we hold i_rwsem. + * + * But it's important to update i_size while still holding page lock: + * page writeout could otherwise come in and zero beyond i_size. + */ + if (pos + copied > inode->i_size) { + i_size_write(inode, pos + copied); + i_size_changed = true; + } + + unlock_page(page); + put_page(page); + + if (old_size < pos) + pagecache_isize_extended(inode, old_size, pos); + /* + * Don't mark the inode dirty under page lock. First, it unnecessarily + * makes the holding time of page lock longer. Second, it forces lock + * ordering of page lock and transaction start for journaling + * filesystems. + */ + if (i_size_changed) + mark_inode_dirty(inode); + return copied; +} + int block_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) @@ -2116,39 +2150,8 @@ int generic_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { - struct inode *inode = mapping->host; - loff_t old_size = inode->i_size; - int i_size_changed = 0; - copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); - - /* - * No need to use i_size_read() here, the i_size - * cannot change under us because we hold i_mutex. - * - * But it's important to update i_size while still holding page lock: - * page writeout could otherwise come in and zero beyond i_size. - */ - if (pos+copied > inode->i_size) { - i_size_write(inode, pos+copied); - i_size_changed = 1; - } - - unlock_page(page); - put_page(page); - - if (old_size < pos) - pagecache_isize_extended(inode, old_size, pos); - /* - * Don't mark the inode dirty under page lock. First, it unnecessarily - * makes the holding time of page lock longer. Second, it forces lock - * ordering of page lock and transaction start for journaling - * filesystems. - */ - if (i_size_changed) - mark_inode_dirty(inode); - - return copied; + return __generic_write_end(mapping->host, pos, copied, page); } EXPORT_SYMBOL(generic_write_end); diff --git a/fs/internal.h b/fs/internal.h index e08972db0303..b955232d3d49 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -43,6 +43,8 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait) extern void guard_bio_eod(int rw, struct bio *bio); extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, get_block_t *get_block, struct iomap *iomap); +int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, + struct page *page); /* * char_dev.c