From patchwork Wed May 30 09:59:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10438197 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 6A5CA602CC for ; Wed, 30 May 2018 10:00:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57F63288B7 for ; Wed, 30 May 2018 10:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ACF1288E8; Wed, 30 May 2018 10:00:27 +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=unavailable 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 D2EF6288F1 for ; Wed, 30 May 2018 10:00:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D815D6B0279; Wed, 30 May 2018 06:00:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D29466B027A; Wed, 30 May 2018 06:00:24 -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 C3EC86B027B; Wed, 30 May 2018 06:00:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 7C6C06B0279 for ; Wed, 30 May 2018 06:00:24 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id c3-v6so9798458plz.7 for ; Wed, 30 May 2018 03:00:24 -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=CPBqNX1OslqxxiFdfNh8Xc+H8fl7hon5UFfCb1bkmrLirghMqh12vGYfjPlUMCT3sk NB/KDjeVN7nAoVtGij/AvkKwPFWQnHlCtuDDgQsTU317L9gwEYbaK2Aeflf3oB2QHarw gnxCWWDqHgxCWimbUL8HS5v7VYo5hSc4nXDSRsdQmgZ+TGLTMLJ+dnzC+zICdMhVJVLR Sie/V3fqHyAkrOkpNmqMVfGQMAcIAA4Fi5ZwHVOxhFQBcIXrEXyWWAfIQSNOs1EgGvWg Lf0Z0oaE2e5oI4QwV0Llly/d1DGYhtW8D8NerYT2c3bkusQ5cQn77w/5XJvBamgvk/io g9QA== X-Gm-Message-State: ALKqPwd5s0fv7CXCn8U0/d63yJ1aJLYw3/tpZht2EzGhRxIpiJQZBkSK CMEQoi/mh4SnOYXXW1ATa0CrQ2cz112x6Mfb/CZqHHOlz1huhLV6RMInX/xDJkJ6o5Pdpp80sv0 h/3ipn8yc8nd6Iih6azd0i3lOtmPPTWa4gXdSAQsX7XOX88/RVXgpXjuAeW5LOxE= X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr2196983plk.41.1527674424194; Wed, 30 May 2018 03:00:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIcKNHgOuKMFgCN5VkAbCnKZFscwMBLgrj30Zt/G2SnHvwLS839/E1x5/0+3XwFNLfStYJX X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr2196918plk.41.1527674423390; Wed, 30 May 2018 03:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527674423; cv=none; d=google.com; s=arc-20160816; b=dp81RDn6+FsJ8BwDmw8dWECVdfuOgUCWg9gJRHVy0kq/erJ9IyRopMh9XS0ZWwnSwW +UTOUnf45mzmDCtu9MEqZI6wcj/hVxIGYXPlVIxSDrapGbBUxoT5dnqgVi0UZ4Ts6GaA ZqsNF+0s7+7xSiwWcQScf9tKRX/k7tRfQNxcIJuDxazyM2N8hcWngcp+KyJVgVFa/+BH G/tW7fxdKRO8eNSw1p/U4XaZzDe5vGYEjcMvgIh7enFY3ka7VVY2Hm3kQ2bYLgr9IM1f WsRQm4HDimy6FB/BQDl1I0oLAEw6HrMmmAXd9j4mnDuJlHsDJMSPIU2/PFZyqV6K+lrr wyjA== 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=noXb2FZVe7RrQ/8BJOUnW7JrQckiaJtmz5+oAjeCdUw1Af90i0ZGJNJtMer0xgZ+21 C9H/Z5CJXqq6LirBTO6flZCubqG9i4ZKF+aU/yXwg8fID4Y8V/GqmtWvDjSig1uTzgNi yq00Ns29JaE7waLCtJqDHToA3rvF58f55uY8pK3USEq/Pma5z6sRPhcfFkhlC7Gzbjox PuQGeBoB3nWEkVorkmiiSSj6KmowdG0+jfTLQx0ZcL/gzRyUmP4D1EWR0145Aitx+yj1 0LrSqbdLVMsvJTh7yZLoZj9qVJnpeJVKOn0kr+XGti/oVffnJdRbGoBS5rAFTk11w4BU obAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=jXKWeLW6; spf=pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+1f4557cc97fec8e307c5+5393+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 i135-v6si9077204pgc.118.2018.05.30.03.00.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 03:00:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+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=jXKWeLW6; spf=pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+1f4557cc97fec8e307c5+5393+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=jXKWeLW6LWgyZWwxjUQZbeHyc VljzjgfOkn7PwOHHOJg3sK/cJ7ejxUafCp/1w1BsZTOB8RygfhAvnuq1mXTrGJtjolzLaoK9yy7Pc QBYwApazGoZHexvCiNH2q6mzQ6scu1h1eG+mq5vfBqlEF6SXXAQTUOikZBtWdsVY26jvy6ISLLSUB n7BAWUmFsuHM3UtSlX/VZUhws3pkmIt46mt88KYrBqz65MNa5sqTKGTdHaDjt9x8C3qqj0yFzT3S4 BRoEbk2uN2b1gOMJJ7TDF7X4DJeXtGd6XlyAte4Fea0f2avjqNtv3TjjqE3i3hhD2U1j2mrcNHSiK 2yLpU03CA==; Received: from 213-225-38-123.nat.highway.a1.net ([213.225.38.123] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fNxu0-0007Xg-Ua; Wed, 30 May 2018 10:00:21 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/18] fs: factor out a __generic_write_end helper Date: Wed, 30 May 2018 11:59:56 +0200 Message-Id: <20180530100013.31358-2-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530100013.31358-1-hch@lst.de> References: <20180530100013.31358-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: Brian Foster 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