Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp496708ybm; Thu, 28 May 2020 08:03:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOegNyiY5KKfDGtQBIIoUPRAqyuJcSKwxGjTd26yjBgbkMAVbzpb25H2AQ/fbj6wI1tVXv X-Received: by 2002:aa7:cb8d:: with SMTP id r13mr3550794edt.12.1590678210585; Thu, 28 May 2020 08:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590678210; cv=none; d=google.com; s=arc-20160816; b=ZdthfvXH4ls1opeD7oOiw9z68r3nVh9gEGTjRWm7FXEWYTLCLxCbQNS4eiKHlMMRfF gMGE9A+bwzQPrawSUsTVFWyhFjYG1HivGnd4BG1ilcU32Rfi6aagTVJWYv/ygadWbwi5 UjrktZdV3wApEBvb7d7nU57voH1eSb3V4ZR4G8FhTnt239XRArTXxlSY46loVWsF3nNX m+i3kAkhI/LyNHaJwjF2HFxlXXR5as91J2NPwjXHS0ELbeEMI3w/vtEhr7Vttj0sFqxh 5dsoMI8/rqB5hdmRAFt3W6R1Xh0MA7E+j2q9NugTe9OyCtdTE/GENm5p0UKzMFdV7ouD kfGA== 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=EEQCwOaxg+PgKULBj56dBQt5JEdPdogZnu3c/mU0WyI=; b=nEHLQ7sMlGpoFYZT065KHvZKCUtbiPw0WsSWLcLC65a+Qm9X46iE+uvKBwLzJm72Bh wGP2FqduuHE4l17CkOuog1BsQLYuHujg9t+aVoBEzw8MksI3kvjnF+WlVWGZLhLpOzhW 3CIHRYXD/7Bgpx2yOznDfuRkxivesqBENwJbNvb32m6ZoJWc8OYBw9oKlAhj9aKE9iuT zDrE384virwzxNaz+6IOUgwbTKf8g90T6rMUHL+HqLMXX0xHP6wkj+3xRIGFmiFRP0d5 XUn+feTWx8eb5l8ql42yN00je3CrcqoYZpw2Z5lUfDRIF4rSvulM0Z6raPi4RCtBttcN cIMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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. [23.128.96.18]) by mx.google.com with ESMTP id c2si3908203edm.499.2020.05.28.08.03.04; Thu, 28 May 2020 08:03:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S2404105AbgE1PBJ (ORCPT + 99 others); Thu, 28 May 2020 11:01:09 -0400 Received: from mga11.intel.com ([192.55.52.93]:27832 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404027AbgE1PAQ (ORCPT ); Thu, 28 May 2020 11:00:16 -0400 IronPort-SDR: RmpXFIbRbAZtkQhduLruqW2A01MKw/2Q8WHb3VpM2OztlPN1aR1VmRS5SIHd9gAMg+qjMEs6A1 nXC4eMeAOfzA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 08:00:08 -0700 IronPort-SDR: u4B2T39OHPzCu99pkfNmTrzIcsDmNQoNoFn4oedhF8dLDDZn3uHDzU6lRaQdpDmeMkD6VhlCJ/ SedLHmvlGqmQ== X-IronPort-AV: E=Sophos;i="5.73,445,1583222400"; d="scan'208";a="256185421" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 08:00:07 -0700 From: ira.weiny@intel.com To: linux-ext4@vger.kernel.org, Andreas Dilger , "Theodore Y. Ts'o" , Jan Kara , Eric Biggers Cc: Ira Weiny , Al Viro , Dan Williams , Dave Chinner , Christoph Hellwig , Jeff Moyer , "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V5 4/9] fs/ext4: Update ext4_should_use_dax() Date: Thu, 28 May 2020 07:59:58 -0700 Message-Id: <20200528150003.828793-5-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200528150003.828793-1-ira.weiny@intel.com> References: <20200528150003.828793-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Ira Weiny S_DAX should only be enabled when the underlying block device supports dax. Cache the underlying support for DAX in the super block and modify ext4_should_use_dax() to check for device support prior to the over riding mount option. While we are at it change the function to ext4_should_enable_dax() as this better reflects the ask as well as matches xfs. Reviewed-by: Jan Kara Signed-off-by: Ira Weiny --- Changes from V3: Add a sb DAX supported flag for performance Changes from RFC Change function name to 'should enable' Clean up bool conversion Reorder this for better bisect-ability --- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 15 ++++++++++----- fs/ext4/super.c | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 6c65fa2f5e00..3fdd044304a0 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb) */ #define EXT4_FLAGS_RESIZING 0 #define EXT4_FLAGS_SHUTDOWN 1 +#define EXT4_FLAGS_BDEV_IS_DAX 2 static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi) { diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index a10ff12194db..6532870f6a0b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4398,10 +4398,10 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) !ext4_test_inode_state(inode, EXT4_STATE_XATTR)); } -static bool ext4_should_use_dax(struct inode *inode) +static bool ext4_should_enable_dax(struct inode *inode) { - if (!test_opt(inode->i_sb, DAX_ALWAYS)) - return false; + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); + if (!S_ISREG(inode->i_mode)) return false; if (ext4_should_journal_data(inode)) @@ -4412,7 +4412,12 @@ static bool ext4_should_use_dax(struct inode *inode) return false; if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY)) return false; - return true; + if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) + return false; + if (test_opt(inode->i_sb, DAX_ALWAYS)) + return true; + + return false; } void ext4_set_inode_flags(struct inode *inode) @@ -4430,7 +4435,7 @@ void ext4_set_inode_flags(struct inode *inode) new_fl |= S_NOATIME; if (flags & EXT4_DIRSYNC_FL) new_fl |= S_DIRSYNC; - if (ext4_should_use_dax(inode)) + if (ext4_should_enable_dax(inode)) new_fl |= S_DAX; if (flags & EXT4_ENCRYPT_FL) new_fl |= S_ENCRYPTED; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 7b99c44d0a91..f7d76dcaedfe 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4092,13 +4092,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount; } + if (bdev_dax_supported(sb->s_bdev, blocksize)) + set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags); + if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) { if (ext4_has_feature_inline_data(sb)) { ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem" " that may contain inline data"); goto failed_mount; } - if (!bdev_dax_supported(sb->s_bdev, blocksize)) { + if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) { ext4_msg(sb, KERN_ERR, "DAX unsupported by block device."); goto failed_mount; -- 2.25.1