From patchwork Thu Sep 23 13:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 12512917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73166C433EF for ; Thu, 23 Sep 2021 13:24:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57F9F61216 for ; Thu, 23 Sep 2021 13:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241260AbhIWNZd (ORCPT ); Thu, 23 Sep 2021 09:25:33 -0400 Received: from sender2-op-o12.zoho.com.cn ([163.53.93.243]:17222 "EHLO sender2-op-o12.zoho.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241252AbhIWNZd (ORCPT ); Thu, 23 Sep 2021 09:25:33 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1632402521; cv=none; d=zoho.com.cn; s=zohoarc; b=LtT4AHvjKfjxM7qfFR64EaDXeRwB+/cGDrDpPbwsQpxOy9zU9S/34b9tcckTWtPRC99AFBxe4FcaVqr1Uj/UN3hKhKg1h8vL6QxnRLBoNpV0P2g63VPQspXv2qjNvZW21/WRc0M3YzJIgEErJ2ElGnTzX/Mpa3IsiMjtrSGEC7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1632402521; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XsUohhYVPknp/XYAaV7893wjUc9cOlm8DY/Vt5qPhmQ=; b=FZdUAfgRvEjoF5w4JyAviHQETBr1ci/Y8SnblybEi/0LWK5d3aFFN9xTY586aGoFtbmw6OyHq3a5zpS5nMzls52AY6lw9HEHZTbZHiIZw+pT8q69FGam1LPJ+XkUkb4CMOMKsi/5IQZftPqGOkd6WDwfCsVisLm9Wt8I6VOeRAU= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1632402521; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=XsUohhYVPknp/XYAaV7893wjUc9cOlm8DY/Vt5qPhmQ=; b=J1CY3iOba+GXjdL6LsJYfjWo0tJEIuJUg9Pz9U+pHROXjA9a2Rsu2AQ+m9g4SrqV WizDKlrtcKcL5qhJovXGJI74s5Nh41Fl0UU8EKQS5yeuiqnrgwgmhTAZv8FN+HdRh/P UDcIVxHoK3jjQtUiQfOr7zd9ChTCWPJCdjjSz7NE= Received: from localhost.localdomain (81.71.33.115 [81.71.33.115]) by mx.zoho.com.cn with SMTPS id 1632402520332669.3406501896101; Thu, 23 Sep 2021 21:08:40 +0800 (CST) From: Chengguang Xu To: miklos@szeredi.hu, jack@suse.cz, amir73il@gmail.com Cc: linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, Chengguang Xu Message-ID: <20210923130814.140814-7-cgxu519@mykernel.net> Subject: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Date: Thu, 23 Sep 2021 21:08:10 +0800 X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210923130814.140814-1-cgxu519@mykernel.net> References: <20210923130814.140814-1-cgxu519@mykernel.net> MIME-Version: 1.0 X-ZohoCNMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Implement overlayfs' ->write_inode to sync dirty data and redirty overlayfs' inode if necessary. Signed-off-by: Chengguang Xu --- fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 2ab77adf7256..cddae3ca2fa5 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode) clear_inode(inode); } +static int ovl_write_inode(struct inode *inode, + struct writeback_control *wbc) +{ + struct ovl_fs *ofs = inode->i_sb->s_fs_info; + struct inode *upper = ovl_inode_upper(inode); + unsigned long iflag = 0; + int ret = 0; + + if (!upper) + return 0; + + if (!ovl_should_sync(ofs)) + return 0; + + if (upper->i_sb->s_op->write_inode) + ret = upper->i_sb->s_op->write_inode(inode, wbc); + + if (mapping_writably_mapped(upper->i_mapping) || + mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK)) + iflag |= I_DIRTY_PAGES; + + iflag |= upper->i_state & I_DIRTY_ALL; + + if (iflag) + ovl_mark_inode_dirty(inode); + + return ret; +} + static const struct super_operations ovl_super_operations = { .alloc_inode = ovl_alloc_inode, .free_inode = ovl_free_inode, .destroy_inode = ovl_destroy_inode, .drop_inode = generic_delete_inode, .evict_inode = ovl_evict_inode, + .write_inode = ovl_write_inode, .put_super = ovl_put_super, .sync_fs = ovl_sync_fs, .statfs = ovl_statfs,