From patchwork Wed Feb 17 03:34:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 8333951 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9A1B5C02AA for ; Wed, 17 Feb 2016 03:35:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9860B202FE for ; Wed, 17 Feb 2016 03:35:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A6F0202F2 for ; Wed, 17 Feb 2016 03:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965141AbcBQDf1 (ORCPT ); Tue, 16 Feb 2016 22:35:27 -0500 Received: from mga01.intel.com ([192.55.52.88]:7996 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965093AbcBQDfE (ORCPT ); Tue, 16 Feb 2016 22:35:04 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 16 Feb 2016 19:34:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,458,1449561600"; d="scan'208";a="916486867" Received: from rzwisler-desk.amr.corp.intel.com (HELO phyrexia.intel.com) ([10.254.20.43]) by fmsmga002.fm.intel.com with ESMTP; 16 Feb 2016 19:34:41 -0800 From: Ross Zwisler To: linux-kernel@vger.kernel.org Cc: Dan Williams , "J. Bruce Fields" , "Theodore Ts'o" , Alexander Viro , Andreas Dilger , Andrew Morton , Dave Chinner , Jan Kara , Jeff Layton , Jens Axboe , Matthew Wilcox , linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-nvdimm@lists.01.org, xfs@oss.sgi.com, Jan Kara , Jens Axboe , Al Viro , Ross Zwisler , Matthew Wilcox Subject: [PATCH v3 6/6] block: use dax_do_io() if blkdev_dax_capable() Date: Tue, 16 Feb 2016 20:34:19 -0700 Message-Id: <1455680059-20126-7-git-send-email-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455680059-20126-1-git-send-email-ross.zwisler@linux.intel.com> References: <1455680059-20126-1-git-send-email-ross.zwisler@linux.intel.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dan Williams Setting S_DAX on an inode requires that the inode participate in the DAX-fsync mechanism which expects to use the pagecache for tracking potentially dirty cpu cachelines. However, dax_do_io() participates in the standard pagecache sync semantics and arranges for dirty pages to be flushed through the driver when a direct-IO operation accesses the same ranges. It should always be valid to use the dax_do_io() path regardless of whether the block_device inode has S_DAX set. In either case dirty pages or dirty cachelines are made durable before the direct-IO operation proceeds. Cc: Jan Kara Cc: Jens Axboe Cc: Al Viro Cc: Dave Chinner Cc: Ross Zwisler Cc: Matthew Wilcox Signed-off-by: Dan Williams Signed-off-by: Ross Zwisler --- block/ioctl.c | 1 + fs/block_dev.c | 3 ++- include/linux/fs.h | 31 +++++++++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index d8996bb..7c64286 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -434,6 +434,7 @@ bool blkdev_dax_capable(struct block_device *bdev) return true; } +EXPORT_SYMBOL(blkdev_dax_capable); #endif static int blkdev_flushbuf(struct block_device *bdev, fmode_t mode, diff --git a/fs/block_dev.c b/fs/block_dev.c index 826b164..0e937dd 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -166,8 +166,9 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset) { struct file *file = iocb->ki_filp; struct inode *inode = bdev_file_inode(file); + struct block_device *bdev = I_BDEV(inode); - if (IS_DAX(inode)) + if (blkdev_dax_capable(bdev)) return dax_do_io(iocb, inode, iter, offset, blkdev_get_block, NULL, DIO_SKIP_DIO_COUNT); return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter, offset, diff --git a/include/linux/fs.h b/include/linux/fs.h index ae68100..a3f5ee8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -830,7 +830,14 @@ static inline unsigned imajor(const struct inode *inode) return MAJOR(inode->i_rdev); } +#ifdef CONFIG_BLOCK extern struct block_device *I_BDEV(struct inode *inode); +#else +static inline struct block_device *I_BDEV(struct inode *inode) +{ + return NULL; +} +#endif struct fown_struct { rwlock_t lock; /* protects pid, uid, euid fields */ @@ -2306,15 +2313,6 @@ extern struct super_block *freeze_bdev(struct block_device *); extern void emergency_thaw_all(void); extern int thaw_bdev(struct block_device *bdev, struct super_block *sb); extern int fsync_bdev(struct block_device *); -#ifdef CONFIG_FS_DAX -extern bool blkdev_dax_capable(struct block_device *bdev); -#else -static inline bool blkdev_dax_capable(struct block_device *bdev) -{ - return false; -} -#endif - extern struct super_block *blockdev_superblock; static inline bool sb_is_blkdev_sb(struct super_block *sb) @@ -2902,9 +2900,22 @@ extern int generic_show_options(struct seq_file *m, struct dentry *root); extern void save_mount_options(struct super_block *sb, char *options); extern void replace_mount_options(struct super_block *sb, char *options); +#ifdef CONFIG_FS_DAX +extern bool blkdev_dax_capable(struct block_device *bdev); +#else +static inline bool blkdev_dax_capable(struct block_device *bdev) +{ + return false; +} +#endif + static inline bool io_is_direct(struct file *filp) { - return (filp->f_flags & O_DIRECT) || IS_DAX(filp->f_mapping->host); + struct inode *inode = filp->f_mapping->host; + + return (filp->f_flags & O_DIRECT) || IS_DAX(inode) + || (S_ISBLK(file_inode(filp)->i_mode) + && blkdev_dax_capable(I_BDEV(inode))); } static inline int iocb_flags(struct file *file)