From patchwork Wed May 9 07:47:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10388301 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 2639860170 for ; Wed, 9 May 2018 07:48:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A00528E08 for ; Wed, 9 May 2018 07:48:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EBD628E65; Wed, 9 May 2018 07:48:49 +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 D545028E08 for ; Wed, 9 May 2018 07:48:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C97B36B0337; Wed, 9 May 2018 03:48:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C1E6D6B033A; Wed, 9 May 2018 03:48:46 -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 AC2626B033B; Wed, 9 May 2018 03:48:46 -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 6920E6B0337 for ; Wed, 9 May 2018 03:48:46 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id 35-v6so3291246pla.18 for ; Wed, 09 May 2018 00:48:46 -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=Bvdc7/hSpKVDdn0jSk2vkQxVQS0zu+oT0+xHMjs3AhY=; b=mUiQJ1opd7noiaIKvfh9TA5eQ6hVfR4o13cn01bZOlE+MmC/lsdAZPfjiiAlTj1qoL Yq+HcOsA0HWwx+rvb4c+EpCglmDDtqiX3kulFbOd+JNNQ+EFxoNpL1oPL2dzHgqiFwmu x9g52zlMWrbBm3mc9YjTCgyZnIhEOakqO7fv6TCkTVLhrDljFP7wgI7vu1PEQe/MzhxY 2R50k1qOuMCMKfTEKhF8vjENc2EpPShswvQLVq8HLtO597Ez4X3N72VCn97bn2KiWfJI h5bwhytCdMo8mMuQwPXjAcZpsB+bZoiIAxSULZ1s4QMqbUJCfdiElLdpQ3fUi0cqwI5S GfWg== X-Gm-Message-State: ALQs6tBev/ahj9/Fco0WwgQh3myqyT2WgBJU8Ov4WuuuVRBopi/jMJPn U2jARDmDlCWzE1oZQgO3IqWY2NqKn1GyJKKIrjjEAGW8VuzdQO8hoq4B/bsF06U7sDfaxLugFew eWv1aq4yuXJI+KvbYS80HgkTTLyr5vaUZkcLVTMXGB0N28OQrHuf64wHboBUlzhY= X-Received: by 2002:a63:b95d:: with SMTP id v29-v6mr24643759pgo.417.1525852126100; Wed, 09 May 2018 00:48:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoNwBnWI2hd5uMQhbicBfAvwNSy8lVUabnp6KOc8eow8b9XslqwFYRZmzYJei9b96kZpz9/ X-Received: by 2002:a63:b95d:: with SMTP id v29-v6mr24643720pgo.417.1525852125168; Wed, 09 May 2018 00:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525852125; cv=none; d=google.com; s=arc-20160816; b=DMRzxf1ElaGNgo9AweyuFrrhncS5swbba3jc42evtfzcRGQdg4QmIvnIlhNuxxA8uR zJGL+InALl7MJHGdQsuZv2CL/ToESF9smIuZJqhO22uZyfYvCSAN5s++yD63kIjBMNfK vZBaJddW8Mu0PvOV3ZV2JsEW5HI44RhV7FXMfKPWuXpyst2yZtikK6pDH4aoDNF5H+/e uBgBe5AD0kd0gAoUidrXfZ1CbgFyUSoSuyg3CsCxaMT+ueJgORB+aQ5GWIWH0ku3NZgn 8zSy6u2B+TD8fwuOxBynJ+duZQeFOD8QOXJlce5CfNILxMBCeTskZkOI+XrsICpgSckv cDVA== 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=Bvdc7/hSpKVDdn0jSk2vkQxVQS0zu+oT0+xHMjs3AhY=; b=V3fR7bAoWjHvDf3NM72YdIXVjgsc0luERRXlHG2xGsPxu54p5qxBgKm4dOCxyIWLxU AloDm/DgyZhpnODzka0WKgc85DVBw3JQgCTPlLIQm9+f1/uLqfAUc05MEqTOFuYf7NU4 vwnXuq0s075l4ks/WfwBeCCBSCZDOg9oqIN40ri3yVsxi/rZHvBiwhOuoBWA0Z3I7PDt 1xFw17MthM7Gk+GKUq421tO2eVRfYwhIIyl/Rqw346a/D/SEzfzRWmsiWpb8jURe2k1+ l18yaS60Muq/Vd6TPDm5VbxyvZJsaSaEVjb0j+oRrBtcYJHmxucidZRH5AdjO7CQyRmG xlfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=PfoOa0zk; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+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 a90-v6si20129979plc.329.2018.05.09.00.48.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 00:48:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+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=PfoOa0zk; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+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=Bvdc7/hSpKVDdn0jSk2vkQxVQS0zu+oT0+xHMjs3AhY=; b=PfoOa0zkyGKVPyQ8dBVCrDoW9 igPwPDPhoy5HOIym/d0JX7w613DMPwBYgWVm9C66VKR3BYUhIP7K1WQzCM7Lw45/7Z9sM+kL+vBsQ D+qUTbfpattWspfzbGEkQ5qPf/3TjVi8bLNXLx5UxoRKNJ5Rwv77P8XcrdxZM5WLKBdRUbbD7n2S1 CZYaenPwGy6YSpzRbBe56e3JOO2fYtucwaLlD4gFqZtV21juHxGvoLHotnHVJ6BkrGIuA4zEm8PXI 1StXnTg0jz1/cTFEYz5je7dsjQTihDJ9eCoNlEgoWP8fUv5axS01Vm4hSOnN0PGMUiS3DKxzTDr7i 3/OcNMCOA==; Received: from 213-225-15-246.nat.highway.a1.net ([213.225.15.246] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGJq7-0000wn-W1; Wed, 09 May 2018 07:48:44 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/33] fs: factor out a __generic_write_end helper Date: Wed, 9 May 2018 09:47:59 +0200 Message-Id: <20180509074830.16196-3-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509074830.16196-1-hch@lst.de> References: <20180509074830.16196-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 --- fs/buffer.c | 68 +++++++++++++++++++++++++++------------------------ fs/internal.h | 2 ++ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 249b83fafe48..923391702f51 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,42 +2150,12 @@ 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); + /* * block_is_partially_uptodate checks whether buffers within a page are * uptodate or not. 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