Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3064344ybb; Sun, 12 Apr 2020 23:05:10 -0700 (PDT) X-Google-Smtp-Source: APiQypKixbN5RKPctczNSiM4Ey7FgMvThtITiVrW72gJ7oTKBy95B9Ln7LsChJFOHKr2hYqQHyDu X-Received: by 2002:aed:2f83:: with SMTP id m3mr9587779qtd.10.1586757910702; Sun, 12 Apr 2020 23:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586757910; cv=none; d=google.com; s=arc-20160816; b=DGo/uGzZaZUA0kYv0fhedYApoJhrsQ6woKozXao1mi6vlQpB+0SZGXxT0jxP23ref1 KpqGjkX0akBiKzPitOaVd/GCjHHRuMXl+p4tGwk8XBf586z34bepk1GdT/nBu89/wg0N 2c2BZa1tp5Onr9fpANE1JZXMkGo7AAAbbTAcUTdRoHq7Fr5wv3OQLjwirkAX2EdH+LDU D4tCy06hr8pNPRhsxPM9R5sJN+NlISmuNnRt1wTZt7vheDm55uUGG1kEhJY8KVi9X57z rbTnk+wGMOgiWiIXn1qbEDzpXpWStP+kTbx1dXXwfg1NMNQv87XPa77g7RIeS6noXTM9 DYsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=BZsYRjDstkavMCp+85IEBolLgDQQVKPoRygja0Q/ip4=; b=kMPIWrKY0AHH0RNiastJHGzy8T3rlO7hmWWC7KV3O1vZLqi68G6tPuNd8j4fJ+s7lB 6sC42RWc66CK1Ps3ttNvYBtSwUKobotofMQfivt6JHp3UFA4m9kREtfWPx/wyjhql2i4 d/Uv7Nk6gLa05vNfQKkou8T54sW0cSIYKTXRsc/9vzXXfJFl7psMAa1d9aXsu/PE57iJ CSWQnIgxtFQtokns/NEaprttjxF6NNLHuYnnkbfy+yQj/ZP3kdmFOYDMZWCjL6DsaSu9 eIXjKlyaLY6svRhmjIyHiuzwxQv1QOJ+nvp7AfrHGCKJ8T0eigwwtJeWcppRchWljtQm sojQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 209.132.180.67 is neither permitted nor denied by best guess record for domain of linux-kernel-owner@vger.kernel.org) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org ([209.132.180.67]) by mx.google.com with ESMTP id z13si5115492qto.239.2020.04.12.23.04.56; Sun, 12 Apr 2020 23:05:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.132.180.67 is neither permitted nor denied by best guess record for domain of linux-kernel-owner@vger.kernel.org) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.132.180.67 is neither permitted nor denied by best guess record for domain of linux-kernel-owner@vger.kernel.org) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729001AbgDMFla (ORCPT + 99 others); Mon, 13 Apr 2020 01:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.18]:42674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbgDMFl2 (ORCPT ); Mon, 13 Apr 2020 01:41:28 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9381CC008675; Sun, 12 Apr 2020 22:41:28 -0700 (PDT) IronPort-SDR: L3Cx1cVaoHPl+ZsIohQ0LxhvxtyO/fKcneqS5ZYPmRRNwTmmyuykues87rK7cro8NLVuMaVtZi 4YY3QlomNygA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 22:41:28 -0700 IronPort-SDR: jlLNzIgrE5WxXjJwzEZr7q+aUTLJHr5nlnZyt88RsBzLXQMvc4ZefvjNFaSdW5IopL58tv28gw arUv7sIQamtQ== X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="243452863" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 22:41:28 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, "Darrick J. Wong" Cc: Ira Weiny , Dan Williams , Dave Chinner , 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: [PATCH V7 8/9] fs/xfs: Change xfs_ioctl_setattr_dax_invalidate() Date: Sun, 12 Apr 2020 22:40:45 -0700 Message-Id: <20200413054046.1560106-9-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200413054046.1560106-1-ira.weiny@intel.com> References: <20200413054046.1560106-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny We only support changing FS_XFLAG_DAX on directories. Files get their flag from the parent directory on creation only. So no data invalidation needs to happen. Alter the xfs_ioctl_setattr_dax_invalidate() to be xfs_ioctl_setattr_dax_validate(). xfs_ioctl_setattr_dax_validate() now validates that any FS_XFLAG_DAX change is ok. This also allows use to remove the join_flags logic. Signed-off-by: Ira Weiny --- Changes from v6: Fix completely broken implementation and update commit message. Use the new VFS layer I_DONTCACHE to facilitate inode eviction and S_DAX changing on drop_caches Changes from v5: New patch --- fs/xfs/xfs_ioctl.c | 102 +++++++-------------------------------------- 1 file changed, 16 insertions(+), 86 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index c6cd92ef4a05..ba42a5fb5b05 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1145,63 +1145,23 @@ xfs_ioctl_setattr_xflags( } /* - * If we are changing DAX flags, we have to ensure the file is clean and any - * cached objects in the address space are invalidated and removed. This - * requires us to lock out other IO and page faults similar to a truncate - * operation. The locks need to be held until the transaction has been committed - * so that the cache invalidation is atomic with respect to the DAX flag - * manipulation. + * Mark inodes with a changing FS_XFLAG_DAX, I_DONTCACHE */ -static int +static void xfs_ioctl_setattr_dax_invalidate( struct xfs_inode *ip, - struct fsxattr *fa, - int *join_flags) + struct fsxattr *fa) { - struct inode *inode = VFS_I(ip); - struct super_block *sb = inode->i_sb; - int error; - - *join_flags = 0; - - /* - * It is only valid to set the DAX flag on regular files and - * directories on filesystems where the block size is equal to the page - * size. On directories it serves as an inherited hint so we don't - * have to check the device for dax support or flush pagecache. - */ - if (fa->fsx_xflags & FS_XFLAG_DAX) { - struct xfs_buftarg *target = xfs_inode_buftarg(ip); - - if (!bdev_dax_supported(target->bt_bdev, sb->s_blocksize)) - return -EINVAL; - } - - /* If the DAX state is not changing, we have nothing to do here. */ - if ((fa->fsx_xflags & FS_XFLAG_DAX) && IS_DAX(inode)) - return 0; - if (!(fa->fsx_xflags & FS_XFLAG_DAX) && !IS_DAX(inode)) - return 0; + struct inode *inode = VFS_I(ip); if (S_ISDIR(inode->i_mode)) - return 0; - - /* lock, flush and invalidate mapping in preparation for flag change */ - xfs_ilock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); - error = filemap_write_and_wait(inode->i_mapping); - if (error) - goto out_unlock; - error = invalidate_inode_pages2(inode->i_mapping); - if (error) - goto out_unlock; - - *join_flags = XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL; - return 0; - -out_unlock: - xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); - return error; + return; + if (((fa->fsx_xflags & FS_XFLAG_DAX) && + !(ip->i_d.di_flags2 & XFS_DIFLAG2_DAX)) || + (!(fa->fsx_xflags & FS_XFLAG_DAX) && + (ip->i_d.di_flags2 & XFS_DIFLAG2_DAX))) + inode->i_state |= I_DONTCACHE; } /* @@ -1209,17 +1169,10 @@ xfs_ioctl_setattr_dax_invalidate( * have permission to do so. On success, return a clean transaction and the * inode locked exclusively ready for further operation specific checks. On * failure, return an error without modifying or locking the inode. - * - * The inode might already be IO locked on call. If this is the case, it is - * indicated in @join_flags and we take full responsibility for ensuring they - * are unlocked from now on. Hence if we have an error here, we still have to - * unlock them. Otherwise, once they are joined to the transaction, they will - * be unlocked on commit/cancel. */ static struct xfs_trans * xfs_ioctl_setattr_get_trans( - struct xfs_inode *ip, - int join_flags) + struct xfs_inode *ip) { struct xfs_mount *mp = ip->i_mount; struct xfs_trans *tp; @@ -1236,8 +1189,7 @@ xfs_ioctl_setattr_get_trans( goto out_unlock; xfs_ilock(ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | join_flags); - join_flags = 0; + xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); /* * CAP_FOWNER overrides the following restrictions: @@ -1258,8 +1210,6 @@ xfs_ioctl_setattr_get_trans( out_cancel: xfs_trans_cancel(tp); out_unlock: - if (join_flags) - xfs_iunlock(ip, join_flags); return ERR_PTR(error); } @@ -1386,7 +1336,6 @@ xfs_ioctl_setattr( struct xfs_dquot *pdqp = NULL; struct xfs_dquot *olddquot = NULL; int code; - int join_flags = 0; trace_xfs_ioctl_setattr(ip); @@ -1410,18 +1359,9 @@ xfs_ioctl_setattr( return code; } - /* - * Changing DAX config may require inode locking for mapping - * invalidation. These need to be held all the way to transaction commit - * or cancel time, so need to be passed through to - * xfs_ioctl_setattr_get_trans() so it can apply them to the join call - * appropriately. - */ - code = xfs_ioctl_setattr_dax_invalidate(ip, fa, &join_flags); - if (code) - goto error_free_dquots; + xfs_ioctl_setattr_dax_invalidate(ip, fa); - tp = xfs_ioctl_setattr_get_trans(ip, join_flags); + tp = xfs_ioctl_setattr_get_trans(ip); if (IS_ERR(tp)) { code = PTR_ERR(tp); goto error_free_dquots; @@ -1552,7 +1492,6 @@ xfs_ioc_setxflags( struct fsxattr fa; struct fsxattr old_fa; unsigned int flags; - int join_flags = 0; int error; if (copy_from_user(&flags, arg, sizeof(flags))) @@ -1569,18 +1508,9 @@ xfs_ioc_setxflags( if (error) return error; - /* - * Changing DAX config may require inode locking for mapping - * invalidation. These need to be held all the way to transaction commit - * or cancel time, so need to be passed through to - * xfs_ioctl_setattr_get_trans() so it can apply them to the join call - * appropriately. - */ - error = xfs_ioctl_setattr_dax_invalidate(ip, &fa, &join_flags); - if (error) - goto out_drop_write; + xfs_ioctl_setattr_dax_invalidate(ip, &fa); - tp = xfs_ioctl_setattr_get_trans(ip, join_flags); + tp = xfs_ioctl_setattr_get_trans(ip); if (IS_ERR(tp)) { error = PTR_ERR(tp); goto out_drop_write; -- 2.25.1