Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3209594ybg; Sun, 20 Oct 2019 09:00:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFUpGRf6YGt5oW0uVoUThXNMUadTFrn2UMTrrlOU2wgyy+701EnNjuZCm3qGOK4Q/pQ+iB X-Received: by 2002:a17:906:60c2:: with SMTP id f2mr18019376ejk.21.1571587243049; Sun, 20 Oct 2019 09:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571587243; cv=none; d=google.com; s=arc-20160816; b=mzh85d3HlweKZigbX9MiTJSHSFwNLClvaOAHlIuQW70ztp19+N0HyWlCsZqXktSebN 0OQbvj4a/sWZbHSP2BjpAX9ECrLgNpdI2KMYFy10bu2DyRodjjfxgajblOq3Gs5m08gc hSgzVUpcBNnfv2xTe+GdWeu9ur6IQ3uePPUqcEFrWUsBUE/KYbaHpsUUw9/KdtbQfnpY 1WM1eSJ9poC9vsksZkXgMZ945ReH9EkVID71mlHRSQteOsyzcYOEfBoTmYkeHWUoHkrW A4r84h9Ik0xNAN+w/jWogS/lLrYB0mbRmK2tLWv/hNmPEHNYhT/Czr1qilaYqM0vMKXz yXaQ== 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; bh=MQxXbVJ60C/4Cw4bcjTHttltCj927qcPeYMkjq165Vw=; b=OxSowWQKxFxtkoWTB92drCeoo4Gw3izj0vtE2t/REgcA1bGtzVMZa/vG87PAXQyMjO xi2o/5dQ0JH82T6naZv4oLmbtGn7ALTVY6j59Q7UFaBVhx0O30Zn5MmG1PETqz9dOuEf dzWWMi/spQy8mnj4jPpv9B9/xJjEHFKnnNGen69JY2UyomTUsyZVmkysC/DTTilv7OyA wVIaHkx9v9sLbPisvw1iC0aHLBIU98VZdo7hugPkTa1qypnuI10Vtf7oihRfkXPPCMDM 9fA1JpksstpIYsRPsSHQWG6k5czmnX/9oBCA+xk5O90TK3mkCOvjt3AmfiPqY4uboXC+ /HMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) 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 (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si8220380edw.51.2019.10.20.09.00.19; Sun, 20 Oct 2019 09:00:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) 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 S1726720AbfJTQAD (ORCPT + 99 others); Sun, 20 Oct 2019 12:00:03 -0400 Received: from mga04.intel.com ([192.55.52.120]:32418 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbfJTQAB (ORCPT ); Sun, 20 Oct 2019 12:00:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2019 09:00:00 -0700 X-IronPort-AV: E=Sophos;i="5.67,320,1566889200"; d="scan'208";a="209275529" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.157]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2019 09:00:00 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org Cc: Ira Weiny , Alexander Viro , "Darrick J. Wong" , Dan Williams , Dave Chinner , Christoph Hellwig , "Theodore Y. Ts'o" , Jan Kara , linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 5/5] fs/xfs: Allow toggle of physical DAX flag Date: Sun, 20 Oct 2019 08:59:35 -0700 Message-Id: <20191020155935.12297-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191020155935.12297-1-ira.weiny@intel.com> References: <20191020155935.12297-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 Switching between DAX and non-DAX on a file is racy with respect to data operations. However, if no data is involved the flag is safe to switch. Allow toggling the physical flag if a file is empty. The file length check is not racy with respect to other operations as it is performed under XFS_MMAPLOCK_EXCL and XFS_IOLOCK_EXCL locks. Signed-off-by: Ira Weiny --- fs/xfs/xfs_ioctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index d3a7340d3209..3839684c249b 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -33,6 +33,7 @@ #include "xfs_sb.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "libxfs/xfs_dir2.h" #include #include @@ -1232,12 +1233,10 @@ xfs_diflags_to_linux( 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 } static int @@ -1320,6 +1319,12 @@ xfs_ioctl_setattr_dax_invalidate( /* lock, flush and invalidate mapping in preparation for flag change */ xfs_ilock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); + + if (i_size_read(inode) != 0) { + error = -EOPNOTSUPP; + goto out_unlock; + } + error = filemap_write_and_wait(inode->i_mapping); if (error) goto out_unlock; -- 2.20.1