Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp148138ybb; Tue, 7 Apr 2020 19:09:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJmhUfZd3RJTNdimAGbre0mMOFzi1T8PRQODySMVBa3TVabK82Ssao9S/NXQeew1JMqxubh X-Received: by 2002:a54:4e13:: with SMTP id a19mr867615oiy.108.1586311746241; Tue, 07 Apr 2020 19:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586311746; cv=none; d=google.com; s=arc-20160816; b=tg3dkymxX/Jz905KYkPactr+3crTpgoXWCpzIzQ7lzYfevLt1RndFXx9ZDguQyYBNa Jn5h71HSjIB1I/4OiafqfnFhDHfmS8NbOVX1PNu67KFkLSpbJOeAPgEPhYHre4utWflT 8tn5IS85R2nLN6dMEeVw0lF1XU803e7Q7BlHhh/8AhylVw8i//QVd0JQ5Oh+mRD3mXhJ TziMJWQ8xqJ6l4eCwXa8scUM/J1Mw+iynYqAIzMymg+ZNK8aK5qm4H4oeOY17vFQVoga /LoFA+g5yNEfxJD5C4m6SQKDRAnrxE2LqsJ+8KYurtjNUCDWFAyr7a2LAwRAP5ZrYDg1 pXQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fbcKC19RduR/NjL9x36a5e7NvLs/bl/Y2+okuoev3HA=; b=LCfAP8UrbmevkMDPvD5qG2LQsCOqpv4uR+uGmnOrvM/U/YdF8aXsJj/FmIEv18zs8U DZ2U4ICf8XwWaFc0W+U5G4af4xqvDM3nPdsXCQkVhVr0UyhHZ2/Xn/ouoAMHO6oEUCFW 6S1zkIWGW1KcagUf/pk4fyiQPPeHJLD+3+7g0pUFl6R3I735p7a6Em/wkjR8nZZPfbsP 0lc2FNd5ecAWtx8uGg2sIj90cWsZzpmSp9Rak0RInOGQucYFM3Og1Df+auPZpm3q7IzF p2Xb1XjIu0/jmOoFS+3fNKiu+SA965o0v62VUqJr/vUhXauTa6oarH0lh7VHtriEz2ps yfqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n190si1344869oig.207.2020.04.07.19.08.35; Tue, 07 Apr 2020 19:09:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbgDHCId (ORCPT + 99 others); Tue, 7 Apr 2020 22:08:33 -0400 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:45690 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbgDHCId (ORCPT ); Tue, 7 Apr 2020 22:08:33 -0400 Received: from dread.disaster.area (pa49-180-164-3.pa.nsw.optusnet.com.au [49.180.164.3]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id F2BAD3A468E; Wed, 8 Apr 2020 12:08:28 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1jM08h-0006Rc-CC; Wed, 08 Apr 2020 12:08:27 +1000 Date: Wed, 8 Apr 2020 12:08:27 +1000 From: Dave Chinner To: ira.weiny@intel.com Cc: linux-kernel@vger.kernel.org, "Darrick J. Wong" , Dan Williams , Christoph Hellwig , "Theodore Y. Ts'o" , Jan Kara , Jeff Moyer , linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH V6 6/8] fs/xfs: Combine xfs_diflags_to_linux() and xfs_diflags_to_iflags() Message-ID: <20200408020827.GI24067@dread.disaster.area> References: <20200407182958.568475-1-ira.weiny@intel.com> <20200407182958.568475-7-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200407182958.568475-7-ira.weiny@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=W5xGqiek c=1 sm=1 tr=0 a=K0+o7W9luyMo1Ua2eXjR1w==:117 a=K0+o7W9luyMo1Ua2eXjR1w==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=cl8xLZFz6L8A:10 a=QyXUC8HyAAAA:8 a=7-415B0cAAAA:8 a=mrSnfaagpdeFiFMTPqoA:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Apr 07, 2020 at 11:29:56AM -0700, ira.weiny@intel.com wrote: > From: Ira Weiny > > The functionality in xfs_diflags_to_linux() and xfs_diflags_to_iflags() are > nearly identical. The only difference is that *_to_linux() is called after > inode setup and disallows changing the DAX flag. > > Combining them can be done with a flag which indicates if this is the initial > setup to allow the DAX flag to be properly set only at init time. > > So remove xfs_diflags_to_linux() and call the modified xfs_diflags_to_iflags() > directly. > > While we are here simplify xfs_diflags_to_iflags() to take struct xfs_inode and > use xfs_ip2xflags() to ensure future diflags are included correctly. > > Signed-off-by: Ira Weiny > > --- > Changes from V5: > The functions are no longer identical so we can only combine > them rather than deleting one completely. This is reflected in > the new init parameter. > --- > fs/xfs/xfs_inode.h | 1 + > fs/xfs/xfs_ioctl.c | 33 +-------------------------------- > fs/xfs/xfs_iops.c | 42 +++++++++++++++++++++++++++--------------- > 3 files changed, 29 insertions(+), 47 deletions(-) > > diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h > index 492e53992fa9..e76ed9ca17f7 100644 > --- a/fs/xfs/xfs_inode.h > +++ b/fs/xfs/xfs_inode.h > @@ -466,6 +466,7 @@ int xfs_break_layouts(struct inode *inode, uint *iolock, > /* from xfs_iops.c */ > extern void xfs_setup_inode(struct xfs_inode *ip); > extern void xfs_setup_iops(struct xfs_inode *ip); > +extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init); > > /* > * When setting up a newly allocated inode, we need to call > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c > index d42de92cb283..c6cd92ef4a05 100644 > --- a/fs/xfs/xfs_ioctl.c > +++ b/fs/xfs/xfs_ioctl.c > @@ -1100,37 +1100,6 @@ xfs_flags2diflags2( > return di_flags2; > } > > -STATIC void > -xfs_diflags_to_linux( > - struct xfs_inode *ip) > -{ > - struct inode *inode = VFS_I(ip); > - unsigned int xflags = xfs_ip2xflags(ip); > - > - if (xflags & FS_XFLAG_IMMUTABLE) > - inode->i_flags |= S_IMMUTABLE; > - else > - inode->i_flags &= ~S_IMMUTABLE; > - if (xflags & FS_XFLAG_APPEND) > - inode->i_flags |= S_APPEND; > - else > - inode->i_flags &= ~S_APPEND; > - if (xflags & FS_XFLAG_SYNC) > - inode->i_flags |= S_SYNC; > - else > - inode->i_flags &= ~S_SYNC; > - if (xflags & FS_XFLAG_NOATIME) > - inode->i_flags |= S_NOATIME; > - else > - inode->i_flags &= ~S_NOATIME; > -#if 0 /* disabled until the flag switching races are sorted out */ > - if (xflags & FS_XFLAG_DAX) > - inode->i_flags |= S_DAX; > - else > - inode->i_flags &= ~S_DAX; > -#endif So this variant will set the flag in the inode if the disk inode flag is set, otherwise it will clear it. It does it with if/else branches. > diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c > index e07f7b641226..a4ac8568c8c7 100644 > --- a/fs/xfs/xfs_iops.c > +++ b/fs/xfs/xfs_iops.c > @@ -1259,7 +1259,7 @@ xfs_inode_supports_dax( > return xfs_inode_buftarg(ip)->bt_daxdev != NULL; > } > > -STATIC bool > +static bool > xfs_inode_enable_dax( > struct xfs_inode *ip) > { This belongs in the previous patch. > @@ -1272,26 +1272,38 @@ xfs_inode_enable_dax( > return false; > } > > -STATIC void > +void > xfs_diflags_to_iflags( > - struct inode *inode, > - struct xfs_inode *ip) > + struct xfs_inode *ip, > + bool init) > { > - uint16_t flags = ip->i_d.di_flags; > - > - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | > - S_NOATIME | S_DAX); And this code cleared all the flags in the inode first, then set them if the disk inode flag is set. This does not require branches, resulting in more readable code and better code generation. > + struct inode *inode = VFS_I(ip); > + uint diflags = xfs_ip2xflags(ip); > > - if (flags & XFS_DIFLAG_IMMUTABLE) > + if (diflags & FS_XFLAG_IMMUTABLE) > inode->i_flags |= S_IMMUTABLE; > - if (flags & XFS_DIFLAG_APPEND) > + else > + inode->i_flags &= ~S_IMMUTABLE; > + if (diflags & FS_XFLAG_APPEND) > inode->i_flags |= S_APPEND; > - if (flags & XFS_DIFLAG_SYNC) > + else > + inode->i_flags &= ~S_APPEND; > + if (diflags & FS_XFLAG_SYNC) > inode->i_flags |= S_SYNC; > - if (flags & XFS_DIFLAG_NOATIME) > + else > + inode->i_flags &= ~S_SYNC; > + if (diflags & FS_XFLAG_NOATIME) > inode->i_flags |= S_NOATIME; > - if (xfs_inode_enable_dax(ip)) > - inode->i_flags |= S_DAX; > + else > + inode->i_flags &= ~S_NOATIME; > + > + /* Only toggle the dax flag when initializing */ > + if (init) { > + if (xfs_inode_enable_dax(ip)) > + inode->i_flags |= S_DAX; > + else > + inode->i_flags &= ~S_DAX; > + } > } IOWs, this: struct inode *inode = VFS_I(ip); unsigned int xflags = xfs_ip2xflags(ip); unsigned int flags = 0; if (xflags & FS_XFLAG_IMMUTABLE) flags |= S_IMMUTABLE; if (xflags & FS_XFLAG_APPEND) flags |= S_APPEND; if (xflags & FS_XFLAG_SYNC) flags |= S_SYNC; if (xflags & FS_XFLAG_NOATIME) flags |= S_NOATIME; if ((xflags & FS_XFLAG_DAX) && init) flags |= S_DAX; inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME); inode->i_flags |= flags; ends up being much easier to read and results in better code generation. And we don't need to clear the S_DAX flag when "init" is set, because we are starting from an inode that has no flags set (because init!)... Cheers, Dave. -- Dave Chinner david@fromorbit.com