From patchwork Sat Jan 28 08:37:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9543079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 754DB604A0 for ; Sat, 28 Jan 2017 08:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6964C27F07 for ; Sat, 28 Jan 2017 08:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E3F6282F5; Sat, 28 Jan 2017 08:41:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3A5327F07 for ; Sat, 28 Jan 2017 08:41:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C97F882002; Sat, 28 Jan 2017 00:41:10 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 775AB82002 for ; Sat, 28 Jan 2017 00:41:09 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP; 28 Jan 2017 00:41:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,300,1477983600"; d="scan'208"; a="1100030741" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by fmsmga001.fm.intel.com with ESMTP; 28 Jan 2017 00:41:08 -0800 Subject: [RFC PATCH 11/17] dm: add dax_operations support (producer) From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 28 Jan 2017 00:37:03 -0800 Message-ID: <148559262335.11180.461652469893258568.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <148559256378.11180.8957776806175202312.stgit@dwillia2-desk3.amr.corp.intel.com> References: <148559256378.11180.8957776806175202312.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: snitzer@redhat.com, mawilcox@microsoft.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@lst.de Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Setup a dax_inode to have the same lifetime as the dm block device and add a ->direct_access() method that is equivalent to dm_blk_direct_access(). Once fs/dax.c has been converted to use dax_operations the old dm_blk_direct_access() will be removed. This enabling is only for the top-level dm representation to upper layers. Sub-sequent patches are needed to convert the bottom layer interface to backing devices. Signed-off-by: Dan Williams --- drivers/md/Kconfig | 1 + drivers/md/dm-core.h | 3 +++ drivers/md/dm.c | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index b7767da50c26..1de8372d9459 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -200,6 +200,7 @@ config BLK_DEV_DM_BUILTIN config BLK_DEV_DM tristate "Device mapper support" select BLK_DEV_DM_BUILTIN + select DAX ---help--- Device-mapper is a low level volume manager. It works by allowing people to specify mappings for ranges of logical sectors. Various diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h index 40ceba1fe8be..f6eb8d8db646 100644 --- a/drivers/md/dm-core.h +++ b/drivers/md/dm-core.h @@ -24,6 +24,8 @@ struct dm_kobject_holder { struct completion completion; }; +struct dax_inode; + /* * DM core internal structure that used directly by dm.c and dm-rq.c * DM targets must _not_ deference a mapped_device to directly access its members! @@ -58,6 +60,7 @@ struct mapped_device { struct target_type *immutable_target_type; struct gendisk *disk; + struct dax_inode *dax_inode; char name[16]; void *interface_ptr; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index db934b1dba9d..1b3d9253e92c 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -905,10 +906,10 @@ int dm_set_target_max_io_len(struct dm_target *ti, sector_t len) } EXPORT_SYMBOL_GPL(dm_set_target_max_io_len); -static long dm_blk_direct_access(struct block_device *bdev, sector_t sector, - void **kaddr, pfn_t *pfn, long size) +static long __dm_direct_access(struct mapped_device *md, phys_addr_t dev_addr, + void **kaddr, pfn_t *pfn, long size) { - struct mapped_device *md = bdev->bd_disk->private_data; + sector_t sector = dev_addr >> SECTOR_SHIFT; struct dm_table *map; struct dm_target *ti; int srcu_idx; @@ -932,6 +933,23 @@ static long dm_blk_direct_access(struct block_device *bdev, sector_t sector, return min(ret, size); } +static long dm_blk_direct_access(struct block_device *bdev, sector_t sector, + void **kaddr, pfn_t *pfn, long size) +{ + struct mapped_device *md = bdev->bd_disk->private_data; + + return __dm_direct_access(md, sector << SECTOR_SHIFT, kaddr, pfn, size); +} + +static long dm_dax_direct_access(struct dax_inode *dax_inode, + phys_addr_t dev_addr, void **kaddr, pfn_t *pfn, + long size) +{ + struct mapped_device *md = dax_inode_get_private(dax_inode); + + return __dm_direct_access(md, dev_addr, kaddr, pfn, size); +} + /* * A target may call dm_accept_partial_bio only from the map routine. It is * allowed for all bio types except REQ_PREFLUSH. @@ -1376,6 +1394,7 @@ static int next_free_minor(int *minor) } static const struct block_device_operations dm_blk_dops; +static const struct dax_operations dm_dax_ops; static void dm_wq_work(struct work_struct *work); @@ -1423,6 +1442,12 @@ static void cleanup_mapped_device(struct mapped_device *md) if (md->bs) bioset_free(md->bs); + if (md->dax_inode) { + kill_dax_inode(md->dax_inode); + put_dax_inode(md->dax_inode); + md->dax_inode = NULL; + } + if (md->disk) { spin_lock(&_minor_lock); md->disk->private_data = NULL; @@ -1450,6 +1475,7 @@ static void cleanup_mapped_device(struct mapped_device *md) static struct mapped_device *alloc_dev(int minor) { int r, numa_node_id = dm_get_numa_node(); + struct dax_inode *dax_inode; struct mapped_device *md; void *old_md; @@ -1514,6 +1540,12 @@ static struct mapped_device *alloc_dev(int minor) md->disk->queue = md->queue; md->disk->private_data = md; sprintf(md->disk->disk_name, "dm-%d", minor); + + dax_inode = alloc_dax_inode(md, md->disk->disk_name, &dm_dax_ops); + if (!dax_inode) + goto bad; + md->dax_inode = dax_inode; + add_disk(md->disk); format_dev_t(md->name, MKDEV(_major, minor)); @@ -2735,6 +2767,10 @@ static const struct block_device_operations dm_blk_dops = { .owner = THIS_MODULE }; +static const struct dax_operations dm_dax_ops = { + .direct_access = dm_dax_direct_access, +}; + /* * module hooks */