Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1683936pxb; Thu, 7 Oct 2021 12:50:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylyzr8BMk1LNh1PeGry7Dt8AtfObD0QvGQHbNjcedxUG+Ux/YmmGoSL2THHck9IL/mysK5 X-Received: by 2002:a17:902:a613:b0:13d:d95c:c892 with SMTP id u19-20020a170902a61300b0013dd95cc892mr5610994plq.35.1633636204239; Thu, 07 Oct 2021 12:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633636204; cv=none; d=google.com; s=arc-20160816; b=JnkRXhsvjIs2M+0vCY73j3klB4ddRC4S85ct3R/a9Aje9KDqZsPua1J7WzXvfXUhx0 XzdgBDWJorVzqzKZrGOwPD140GOyxxu/k4ej78nK12RNSs95PdVwgxuvf5J05j8OnwwM h3HYcqa++6Tdyc2JX8FN+niahhg0HuX/5g9DeRcT1LGo59GO1AjxmYmbDKI3dTp1fN5Y zPgiNof16/QF9bptmGBQ+HzhA9DhFATlXoB4JQbsFO3u8/kLo/UPbRKiWCn0FS1O/ofB SMSg/FTyJgSMAe2PxGPaDfJknz987y8g0r9wosjQUBF3RR8+58OrDQR0fqpWPe8R2qyF pHwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XM+aoTP+lFbICkxTuoQyaeaVXtWWuUoeMP/C/f0Vvkc=; b=nh3EyL8w4QxI5VPi1pQU8Bnslt2AZRYDrO8SLIPikQBOV5zMfuZiNzKUGQUipQHUlH Ji/GISGyWt8NR98arqjMn0M94SsRzw5zrAxWL4ZOr8LMLg4uIjt+ge+mjKxGw0eoNk6U taG7SDaL3NDSQD0CiXuBV0shife6Iz6rhD5G3FkD0FFoOaDqkwHWNLm9gceMikjxtQF9 3DQDb0t2gIdYRVUQ7dQkkGxm/crDQaekdbqr1yZ9X3ndZdswonVztBX1BIL7gSxR5jm2 T1FI+s0GDQx6m9oztZJ31PHC5DbTz0ZEZ+YYQ98oPjjHtKkUzbQipVvO90FdCQKXJl6/ SN8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=YvZDPpoS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si415420plh.392.2021.10.07.12.49.51; Thu, 07 Oct 2021 12:50:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=YvZDPpoS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbhJGSpd (ORCPT + 99 others); Thu, 7 Oct 2021 14:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243709AbhJGSpd (ORCPT ); Thu, 7 Oct 2021 14:45:33 -0400 Received: from mail-ua1-x931.google.com (mail-ua1-x931.google.com [IPv6:2607:f8b0:4864:20::931]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D1EC061760 for ; Thu, 7 Oct 2021 11:43:39 -0700 (PDT) Received: by mail-ua1-x931.google.com with SMTP id c33so4936381uae.9 for ; Thu, 07 Oct 2021 11:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XM+aoTP+lFbICkxTuoQyaeaVXtWWuUoeMP/C/f0Vvkc=; b=YvZDPpoS19oCaPvlFDJaVVZXyiDS8eAE/PtMejLFzRTa46q7dZjgMwO752wqeUVLu+ sCLOmUv3bMmlSEFmiFH0fGiZZ7ZEBb9m4DLzl4Kl2mFMooAxBqumNOscqCuqco4/dlop Ai3ls3XRxvUPmOjHxcJwD1RZ8zY5xQmn5QpRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XM+aoTP+lFbICkxTuoQyaeaVXtWWuUoeMP/C/f0Vvkc=; b=j3z/aoTo7KDhMRjSs99Zh9hitJSsumTJJBU2FBjCF5T4f4kePrT0vJZ6kGbtso090B yC4J1XAOIUBL0OJ6ttH3yQBU94opxR/M+56fjub/lf96hgGC3YWqrDNyLZvoCa9y3WNz 9qUjRohjQ3y6q9N6s3nOfwpfjeh4HLzsBD//Zy/q2C5G+nlZhKiclfH+0h6KN5ciuH66 K2CkaAdQ8TRWXWksVtcQtA2ZXkG3v6KQphIJOxxWLPB7X+DK8d6eUoVcWNhQMJZusrnL 0tAT28eJ/f1jxHRRTi2qB8qb6FpTzc42H3lUUzq3gX9Fm44rlc5LPI5Wm1iHJmHUO1n7 GTJg== X-Gm-Message-State: AOAM531ndw1ojUd6ZLUueN9UDdJWdD7kvFa54m30PxB8RlUgepkzbekq KxqbkDrRjE6nk0Zx4WQdT9e/U7AI2EZ7xYN07EZWJFfVvpA= X-Received: by 2002:ab0:3b12:: with SMTP id n18mr6709142uaw.9.1633632218203; Thu, 07 Oct 2021 11:43:38 -0700 (PDT) MIME-Version: 1.0 References: <20210923130814.140814-1-cgxu519@mykernel.net> <20210923130814.140814-5-cgxu519@mykernel.net> In-Reply-To: <20210923130814.140814-5-cgxu519@mykernel.net> From: Miklos Szeredi Date: Thu, 7 Oct 2021 20:43:27 +0200 Message-ID: Subject: Re: [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification To: Chengguang Xu Cc: Jan Kara , Amir Goldstein , linux-fsdevel@vger.kernel.org, overlayfs , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Sept 2021 at 15:08, Chengguang Xu wrote: > > Mark overlayfs' inode dirty on modification so that > we can recognize and collect target inodes for syncfs. > > Signed-off-by: Chengguang Xu > --- > fs/overlayfs/inode.c | 1 + > fs/overlayfs/overlayfs.h | 4 ++++ > fs/overlayfs/util.c | 21 +++++++++++++++++++++ > 3 files changed, 26 insertions(+) > > diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c > index d854e59a3710..4a03aceaeedc 100644 > --- a/fs/overlayfs/inode.c > +++ b/fs/overlayfs/inode.c > @@ -478,6 +478,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags) > if (upperpath.dentry) { > touch_atime(&upperpath); > inode->i_atime = d_inode(upperpath.dentry)->i_atime; > + ovl_mark_inode_dirty(inode); > } > } > return 0; > diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h > index 3894f3347955..5a016baa06dd 100644 > --- a/fs/overlayfs/overlayfs.h > +++ b/fs/overlayfs/overlayfs.h > @@ -276,6 +276,7 @@ static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs) > > > /* util.c */ > +void ovl_mark_inode_dirty(struct inode *inode); > int ovl_want_write(struct dentry *dentry); > void ovl_drop_write(struct dentry *dentry); > struct dentry *ovl_workdir(struct dentry *dentry); > @@ -529,6 +530,9 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to) > to->i_mtime = from->i_mtime; > to->i_ctime = from->i_ctime; > i_size_write(to, i_size_read(from)); > + > + if (ovl_inode_upper(to) && from->i_state & I_DIRTY_ALL) > + ovl_mark_inode_dirty(to); I'd be more comfortable with calling ovl_mark_inode_dirty() unconditionally. Checking if there's an upper seems to make no sense, since we should only be copying the attributes if something was changed, and then it is an upper inode. Checking dirty flags on upper inode actually makes this racy: - upper inode dirtied through overlayfs - inode writeback starts (e.g. background writeback) on upper inode - dirty flags are cleared - check for dirty flags in upper inode above indicates not dirty, ovl inode not dirtied - syncfs called, misses this inode - inode writeback completed after syncfs > } > > /* vfs inode flags copied from real to ovl inode */ > diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c > index f48284a2a896..5441eae2e345 100644 > --- a/fs/overlayfs/util.c > +++ b/fs/overlayfs/util.c > @@ -25,7 +25,14 @@ int ovl_want_write(struct dentry *dentry) > void ovl_drop_write(struct dentry *dentry) > { > struct ovl_fs *ofs = dentry->d_sb->s_fs_info; > + struct dentry *upper; > + > mnt_drop_write(ovl_upper_mnt(ofs)); > + if (d_inode(dentry)) { > + upper = ovl_dentry_upper(dentry); > + if (upper && d_inode(upper) && d_inode(upper)->i_state & I_DIRTY_ALL) > + ovl_mark_inode_dirty(d_inode(dentry)); ovl_want_write/ovl_drop_write means modification of the upper filesystem. It may or may not be the given dentry, so this is not the right place to clall ovl_mark_inode_dirty IMO. Better check all instances of these and see if there are cases where ovl_copyattr() doesn't handle inode dirtying, and do it explicitly there. > + } > } > > struct dentry *ovl_workdir(struct dentry *dentry) > @@ -1060,3 +1067,17 @@ int ovl_sync_status(struct ovl_fs *ofs) > > return errseq_check(&mnt->mnt_sb->s_wb_err, ofs->errseq); > } > + > +/* > + * We intentionally add I_DIRTY_SYNC flag regardless dirty flag > + * of upper inode so that we have chance to invoke ->write_inode > + * to re-dirty overlayfs' inode during writeback process. > + */ > +void ovl_mark_inode_dirty(struct inode *inode) > +{ > + struct inode *upper = ovl_inode_upper(inode); > + unsigned long iflag = I_DIRTY_SYNC; > + > + iflag |= upper->i_state & I_DIRTY_ALL; > + __mark_inode_dirty(inode, iflag); > +} I think ovl_mark_inode_dirty() can just call mark_inode_dirty(). And so that can go in "overlayfs.h" file as static inline. Thanks, Miklos