From patchwork Fri May 6 00:29:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kani, Toshi" X-Patchwork-Id: 9028731 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A2B1B9F1C1 for ; Fri, 6 May 2016 00:40:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EF8A203EC for ; Fri, 6 May 2016 00:40:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 843A3203EB for ; Fri, 6 May 2016 00:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756913AbcEFAi7 (ORCPT ); Thu, 5 May 2016 20:38:59 -0400 Received: from g1t5424.austin.hp.com ([15.216.225.54]:38245 "EHLO g1t5424.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758010AbcEFAi6 (ORCPT ); Thu, 5 May 2016 20:38:58 -0400 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g1t5424.austin.hp.com (Postfix) with ESMTP id E4AAE5B; Fri, 6 May 2016 00:38:56 +0000 (UTC) Received: from misato.fc.hp.com (misato.fc.hp.com [16.78.168.61]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id D941A44; Fri, 6 May 2016 00:38:55 +0000 (UTC) From: Toshi Kani To: dan.j.williams@intel.com, jack@suse.cz, david@fromorbit.com, viro@zeniv.linux.org.uk Cc: axboe@fb.com, hch@infradead.org, boaz@plexistor.com, tytso@mit.edu, adilger.kernel@dilger.ca, ross.zwisler@linux.intel.com, toshi.kani@hpe.com, micah.parrish@hpe.com, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] block: Add bdev_supports_dax() for dax mount checks Date: Thu, 5 May 2016 18:29:53 -0600 Message-Id: <1462494596-20938-3-git-send-email-toshi.kani@hpe.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1462494596-20938-1-git-send-email-toshi.kani@hpe.com> References: <1462494596-20938-1-git-send-email-toshi.kani@hpe.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-9.0 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 DAX imposes additional requirements to a device. Add bdev_supports_dax() which performs all the precondition checks necessary for filesystem to mount the device with dax option. Also add a new check to verify if a partition is aligned by 4KB. When a partition is unaligned, any dax read/write access fails, except for metadata update. Signed-off-by: Toshi Kani Cc: Alexander Viro Cc: Jens Axboe Cc: "Theodore Ts'o" Cc: Andreas Dilger Cc: Jan Kara Cc: Dave Chinner Cc: Dan Williams Cc: Ross Zwisler Cc: Christoph Hellwig Cc: Boaz Harrosh Reviewed-by: Christoph Hellwig --- fs/block_dev.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 43 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/block_dev.c b/fs/block_dev.c index 7be17c4..e51a2c3 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -509,6 +509,48 @@ long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax) } EXPORT_SYMBOL_GPL(bdev_direct_access); +/** + * bdev_supports_dax() - Check if the block device supports DAX + * @sb: The superblock of the device + * @blocksize: The block size of the device + * + * Return: negative errno if unsupported, 0 if supported. + */ +int bdev_supports_dax(struct super_block *sb, int blocksize) +{ + struct blk_dax_ctl dax = { + .sector = 0, + .size = PAGE_SIZE, + }; + int err; + + if (blocksize != PAGE_SIZE) { + vfs_msg(sb, KERN_ERR, "error: unsupported blocksize for dax"); + return -EINVAL; + } + + err = bdev_direct_access(sb->s_bdev, &dax); + if (err < 0) { + switch (err) { + case -EOPNOTSUPP: + vfs_msg(sb, KERN_ERR, + "error: device does not support dax"); + break; + case -EINVAL: + vfs_msg(sb, KERN_ERR, + "error: unaligned partition for dax"); + break; + default: + vfs_msg(sb, KERN_ERR, + "error: dax access failed (%d)", err); + } + return err; + } + + return 0; +} +EXPORT_SYMBOL_GPL(bdev_supports_dax); + /* * pseudo-fs */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 78c48ab..6a792aa 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1688,6 +1688,7 @@ extern int bdev_read_page(struct block_device *, sector_t, struct page *); extern int bdev_write_page(struct block_device *, sector_t, struct page *, struct writeback_control *); extern long bdev_direct_access(struct block_device *, struct blk_dax_ctl *); +extern int bdev_supports_dax(struct super_block *, int); #else /* CONFIG_BLOCK */ struct block_device;