| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright(c) 2017 Intel Corporation. All rights reserved. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of version 2 of the GNU General Public License as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 9 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 11 | | - * General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | #include <linux/pagemap.h> |
|---|
| 14 | 6 | #include <linux/module.h> |
|---|
| 15 | 7 | #include <linux/mount.h> |
|---|
| 8 | +#include <linux/pseudo_fs.h> |
|---|
| 16 | 9 | #include <linux/magic.h> |
|---|
| 17 | 10 | #include <linux/genhd.h> |
|---|
| 18 | 11 | #include <linux/pfn_t.h> |
|---|
| .. | .. |
|---|
| 22 | 15 | #include <linux/uio.h> |
|---|
| 23 | 16 | #include <linux/dax.h> |
|---|
| 24 | 17 | #include <linux/fs.h> |
|---|
| 18 | +#include "dax-private.h" |
|---|
| 25 | 19 | |
|---|
| 26 | 20 | static dev_t dax_devt; |
|---|
| 27 | 21 | DEFINE_STATIC_SRCU(dax_srcu); |
|---|
| .. | .. |
|---|
| 52 | 46 | int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size, |
|---|
| 53 | 47 | pgoff_t *pgoff) |
|---|
| 54 | 48 | { |
|---|
| 55 | | - phys_addr_t phys_off = (get_start_sect(bdev) + sector) * 512; |
|---|
| 49 | + sector_t start_sect = bdev ? get_start_sect(bdev) : 0; |
|---|
| 50 | + phys_addr_t phys_off = (start_sect + sector) * 512; |
|---|
| 56 | 51 | |
|---|
| 57 | 52 | if (pgoff) |
|---|
| 58 | 53 | *pgoff = PHYS_PFN(phys_off); |
|---|
| .. | .. |
|---|
| 65 | 60 | #if IS_ENABLED(CONFIG_FS_DAX) |
|---|
| 66 | 61 | struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) |
|---|
| 67 | 62 | { |
|---|
| 68 | | - if (!blk_queue_dax(bdev->bd_queue)) |
|---|
| 63 | + if (!blk_queue_dax(bdev->bd_disk->queue)) |
|---|
| 69 | 64 | return NULL; |
|---|
| 70 | | - return fs_dax_get_by_host(bdev->bd_disk->disk_name); |
|---|
| 65 | + return dax_get_by_host(bdev->bd_disk->disk_name); |
|---|
| 71 | 66 | } |
|---|
| 72 | 67 | EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev); |
|---|
| 73 | 68 | #endif |
|---|
| 74 | 69 | |
|---|
| 75 | | -/** |
|---|
| 76 | | - * __bdev_dax_supported() - Check if the device supports dax for filesystem |
|---|
| 77 | | - * @bdev: block device to check |
|---|
| 78 | | - * @blocksize: The block size of the device |
|---|
| 79 | | - * |
|---|
| 80 | | - * This is a library function for filesystems to check if the block device |
|---|
| 81 | | - * can be mounted with dax option. |
|---|
| 82 | | - * |
|---|
| 83 | | - * Return: true if supported, false if unsupported |
|---|
| 84 | | - */ |
|---|
| 85 | | -bool __bdev_dax_supported(struct block_device *bdev, int blocksize) |
|---|
| 70 | +bool __generic_fsdax_supported(struct dax_device *dax_dev, |
|---|
| 71 | + struct block_device *bdev, int blocksize, sector_t start, |
|---|
| 72 | + sector_t sectors) |
|---|
| 86 | 73 | { |
|---|
| 87 | | - struct dax_device *dax_dev; |
|---|
| 88 | 74 | bool dax_enabled = false; |
|---|
| 89 | | - struct request_queue *q; |
|---|
| 90 | | - pgoff_t pgoff; |
|---|
| 91 | | - int err, id; |
|---|
| 92 | | - pfn_t pfn; |
|---|
| 93 | | - long len; |
|---|
| 75 | + pgoff_t pgoff, pgoff_end; |
|---|
| 94 | 76 | char buf[BDEVNAME_SIZE]; |
|---|
| 77 | + void *kaddr, *end_kaddr; |
|---|
| 78 | + pfn_t pfn, end_pfn; |
|---|
| 79 | + sector_t last_page; |
|---|
| 80 | + long len, len2; |
|---|
| 81 | + int err, id; |
|---|
| 95 | 82 | |
|---|
| 96 | 83 | if (blocksize != PAGE_SIZE) { |
|---|
| 97 | | - pr_debug("%s: error: unsupported blocksize for dax\n", |
|---|
| 84 | + pr_info("%s: error: unsupported blocksize for dax\n", |
|---|
| 98 | 85 | bdevname(bdev, buf)); |
|---|
| 99 | 86 | return false; |
|---|
| 100 | 87 | } |
|---|
| 101 | 88 | |
|---|
| 102 | | - q = bdev_get_queue(bdev); |
|---|
| 103 | | - if (!q || !blk_queue_dax(q)) { |
|---|
| 104 | | - pr_debug("%s: error: request queue doesn't support dax\n", |
|---|
| 105 | | - bdevname(bdev, buf)); |
|---|
| 106 | | - return false; |
|---|
| 107 | | - } |
|---|
| 108 | | - |
|---|
| 109 | | - err = bdev_dax_pgoff(bdev, 0, PAGE_SIZE, &pgoff); |
|---|
| 110 | | - if (err) { |
|---|
| 111 | | - pr_debug("%s: error: unaligned partition for dax\n", |
|---|
| 112 | | - bdevname(bdev, buf)); |
|---|
| 113 | | - return false; |
|---|
| 114 | | - } |
|---|
| 115 | | - |
|---|
| 116 | | - dax_dev = dax_get_by_host(bdev->bd_disk->disk_name); |
|---|
| 117 | 89 | if (!dax_dev) { |
|---|
| 118 | | - pr_debug("%s: error: device does not support dax\n", |
|---|
| 90 | + pr_debug("%s: error: dax unsupported by block device\n", |
|---|
| 91 | + bdevname(bdev, buf)); |
|---|
| 92 | + return false; |
|---|
| 93 | + } |
|---|
| 94 | + |
|---|
| 95 | + err = bdev_dax_pgoff(bdev, start, PAGE_SIZE, &pgoff); |
|---|
| 96 | + if (err) { |
|---|
| 97 | + pr_info("%s: error: unaligned partition for dax\n", |
|---|
| 98 | + bdevname(bdev, buf)); |
|---|
| 99 | + return false; |
|---|
| 100 | + } |
|---|
| 101 | + |
|---|
| 102 | + last_page = PFN_DOWN((start + sectors - 1) * 512) * PAGE_SIZE / 512; |
|---|
| 103 | + err = bdev_dax_pgoff(bdev, last_page, PAGE_SIZE, &pgoff_end); |
|---|
| 104 | + if (err) { |
|---|
| 105 | + pr_info("%s: error: unaligned partition for dax\n", |
|---|
| 119 | 106 | bdevname(bdev, buf)); |
|---|
| 120 | 107 | return false; |
|---|
| 121 | 108 | } |
|---|
| 122 | 109 | |
|---|
| 123 | 110 | id = dax_read_lock(); |
|---|
| 124 | | - len = dax_direct_access(dax_dev, pgoff, 1, NULL, &pfn); |
|---|
| 125 | | - dax_read_unlock(id); |
|---|
| 111 | + len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn); |
|---|
| 112 | + len2 = dax_direct_access(dax_dev, pgoff_end, 1, &end_kaddr, &end_pfn); |
|---|
| 126 | 113 | |
|---|
| 127 | | - put_dax(dax_dev); |
|---|
| 128 | | - |
|---|
| 129 | | - if (len < 1) { |
|---|
| 130 | | - pr_debug("%s: error: dax access failed (%ld)\n", |
|---|
| 131 | | - bdevname(bdev, buf), len); |
|---|
| 114 | + if (len < 1 || len2 < 1) { |
|---|
| 115 | + pr_info("%s: error: dax access failed (%ld)\n", |
|---|
| 116 | + bdevname(bdev, buf), len < 1 ? len : len2); |
|---|
| 117 | + dax_read_unlock(id); |
|---|
| 132 | 118 | return false; |
|---|
| 133 | 119 | } |
|---|
| 134 | 120 | |
|---|
| .. | .. |
|---|
| 143 | 129 | */ |
|---|
| 144 | 130 | WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API)); |
|---|
| 145 | 131 | dax_enabled = true; |
|---|
| 146 | | - } else if (pfn_t_devmap(pfn)) { |
|---|
| 147 | | - struct dev_pagemap *pgmap; |
|---|
| 132 | + } else if (pfn_t_devmap(pfn) && pfn_t_devmap(end_pfn)) { |
|---|
| 133 | + struct dev_pagemap *pgmap, *end_pgmap; |
|---|
| 148 | 134 | |
|---|
| 149 | 135 | pgmap = get_dev_pagemap(pfn_t_to_pfn(pfn), NULL); |
|---|
| 150 | | - if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX) |
|---|
| 136 | + end_pgmap = get_dev_pagemap(pfn_t_to_pfn(end_pfn), NULL); |
|---|
| 137 | + if (pgmap && pgmap == end_pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX |
|---|
| 138 | + && pfn_t_to_page(pfn)->pgmap == pgmap |
|---|
| 139 | + && pfn_t_to_page(end_pfn)->pgmap == pgmap |
|---|
| 140 | + && pfn_t_to_pfn(pfn) == PHYS_PFN(__pa(kaddr)) |
|---|
| 141 | + && pfn_t_to_pfn(end_pfn) == PHYS_PFN(__pa(end_kaddr))) |
|---|
| 151 | 142 | dax_enabled = true; |
|---|
| 152 | 143 | put_dev_pagemap(pgmap); |
|---|
| 144 | + put_dev_pagemap(end_pgmap); |
|---|
| 145 | + |
|---|
| 153 | 146 | } |
|---|
| 147 | + dax_read_unlock(id); |
|---|
| 154 | 148 | |
|---|
| 155 | 149 | if (!dax_enabled) { |
|---|
| 156 | | - pr_debug("%s: error: dax support not enabled\n", |
|---|
| 150 | + pr_info("%s: error: dax support not enabled\n", |
|---|
| 157 | 151 | bdevname(bdev, buf)); |
|---|
| 158 | 152 | return false; |
|---|
| 159 | 153 | } |
|---|
| 160 | 154 | return true; |
|---|
| 155 | +} |
|---|
| 156 | +EXPORT_SYMBOL_GPL(__generic_fsdax_supported); |
|---|
| 157 | + |
|---|
| 158 | +/** |
|---|
| 159 | + * __bdev_dax_supported() - Check if the device supports dax for filesystem |
|---|
| 160 | + * @bdev: block device to check |
|---|
| 161 | + * @blocksize: The block size of the device |
|---|
| 162 | + * |
|---|
| 163 | + * This is a library function for filesystems to check if the block device |
|---|
| 164 | + * can be mounted with dax option. |
|---|
| 165 | + * |
|---|
| 166 | + * Return: true if supported, false if unsupported |
|---|
| 167 | + */ |
|---|
| 168 | +bool __bdev_dax_supported(struct block_device *bdev, int blocksize) |
|---|
| 169 | +{ |
|---|
| 170 | + struct dax_device *dax_dev; |
|---|
| 171 | + struct request_queue *q; |
|---|
| 172 | + char buf[BDEVNAME_SIZE]; |
|---|
| 173 | + bool ret; |
|---|
| 174 | + int id; |
|---|
| 175 | + |
|---|
| 176 | + q = bdev_get_queue(bdev); |
|---|
| 177 | + if (!q || !blk_queue_dax(q)) { |
|---|
| 178 | + pr_debug("%s: error: request queue doesn't support dax\n", |
|---|
| 179 | + bdevname(bdev, buf)); |
|---|
| 180 | + return false; |
|---|
| 181 | + } |
|---|
| 182 | + |
|---|
| 183 | + dax_dev = dax_get_by_host(bdev->bd_disk->disk_name); |
|---|
| 184 | + if (!dax_dev) { |
|---|
| 185 | + pr_debug("%s: error: device does not support dax\n", |
|---|
| 186 | + bdevname(bdev, buf)); |
|---|
| 187 | + return false; |
|---|
| 188 | + } |
|---|
| 189 | + |
|---|
| 190 | + id = dax_read_lock(); |
|---|
| 191 | + ret = dax_supported(dax_dev, bdev, blocksize, 0, |
|---|
| 192 | + i_size_read(bdev->bd_inode) / 512); |
|---|
| 193 | + dax_read_unlock(id); |
|---|
| 194 | + |
|---|
| 195 | + put_dax(dax_dev); |
|---|
| 196 | + |
|---|
| 197 | + return ret; |
|---|
| 161 | 198 | } |
|---|
| 162 | 199 | EXPORT_SYMBOL_GPL(__bdev_dax_supported); |
|---|
| 163 | 200 | #endif |
|---|
| .. | .. |
|---|
| 167 | 204 | DAXDEV_ALIVE, |
|---|
| 168 | 205 | /* gate whether dax_flush() calls the low level flush routine */ |
|---|
| 169 | 206 | DAXDEV_WRITE_CACHE, |
|---|
| 207 | + /* flag to check if device supports synchronous flush */ |
|---|
| 208 | + DAXDEV_SYNC, |
|---|
| 170 | 209 | }; |
|---|
| 171 | 210 | |
|---|
| 172 | 211 | /** |
|---|
| .. | .. |
|---|
| 284 | 323 | } |
|---|
| 285 | 324 | EXPORT_SYMBOL_GPL(dax_direct_access); |
|---|
| 286 | 325 | |
|---|
| 326 | +bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev, |
|---|
| 327 | + int blocksize, sector_t start, sector_t len) |
|---|
| 328 | +{ |
|---|
| 329 | + if (!dax_dev) |
|---|
| 330 | + return false; |
|---|
| 331 | + |
|---|
| 332 | + if (!dax_alive(dax_dev)) |
|---|
| 333 | + return false; |
|---|
| 334 | + |
|---|
| 335 | + return dax_dev->ops->dax_supported(dax_dev, bdev, blocksize, start, len); |
|---|
| 336 | +} |
|---|
| 337 | +EXPORT_SYMBOL_GPL(dax_supported); |
|---|
| 338 | + |
|---|
| 287 | 339 | size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, |
|---|
| 288 | 340 | size_t bytes, struct iov_iter *i) |
|---|
| 289 | 341 | { |
|---|
| .. | .. |
|---|
| 303 | 355 | return dax_dev->ops->copy_to_iter(dax_dev, pgoff, addr, bytes, i); |
|---|
| 304 | 356 | } |
|---|
| 305 | 357 | EXPORT_SYMBOL_GPL(dax_copy_to_iter); |
|---|
| 358 | + |
|---|
| 359 | +int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, |
|---|
| 360 | + size_t nr_pages) |
|---|
| 361 | +{ |
|---|
| 362 | + if (!dax_alive(dax_dev)) |
|---|
| 363 | + return -ENXIO; |
|---|
| 364 | + /* |
|---|
| 365 | + * There are no callers that want to zero more than one page as of now. |
|---|
| 366 | + * Once users are there, this check can be removed after the |
|---|
| 367 | + * device mapper code has been updated to split ranges across targets. |
|---|
| 368 | + */ |
|---|
| 369 | + if (nr_pages != 1) |
|---|
| 370 | + return -EIO; |
|---|
| 371 | + |
|---|
| 372 | + return dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages); |
|---|
| 373 | +} |
|---|
| 374 | +EXPORT_SYMBOL_GPL(dax_zero_page_range); |
|---|
| 306 | 375 | |
|---|
| 307 | 376 | #ifdef CONFIG_ARCH_HAS_PMEM_API |
|---|
| 308 | 377 | void arch_wb_cache_pmem(void *addr, size_t size); |
|---|
| .. | .. |
|---|
| 335 | 404 | } |
|---|
| 336 | 405 | EXPORT_SYMBOL_GPL(dax_write_cache_enabled); |
|---|
| 337 | 406 | |
|---|
| 407 | +bool __dax_synchronous(struct dax_device *dax_dev) |
|---|
| 408 | +{ |
|---|
| 409 | + return test_bit(DAXDEV_SYNC, &dax_dev->flags); |
|---|
| 410 | +} |
|---|
| 411 | +EXPORT_SYMBOL_GPL(__dax_synchronous); |
|---|
| 412 | + |
|---|
| 413 | +void __set_dax_synchronous(struct dax_device *dax_dev) |
|---|
| 414 | +{ |
|---|
| 415 | + set_bit(DAXDEV_SYNC, &dax_dev->flags); |
|---|
| 416 | +} |
|---|
| 417 | +EXPORT_SYMBOL_GPL(__set_dax_synchronous); |
|---|
| 418 | + |
|---|
| 338 | 419 | bool dax_alive(struct dax_device *dax_dev) |
|---|
| 339 | 420 | { |
|---|
| 340 | 421 | lockdep_assert_held(&dax_srcu); |
|---|
| .. | .. |
|---|
| 365 | 446 | spin_lock(&dax_host_lock); |
|---|
| 366 | 447 | hlist_del_init(&dax_dev->list); |
|---|
| 367 | 448 | spin_unlock(&dax_host_lock); |
|---|
| 368 | | - |
|---|
| 369 | | - dax_dev->private = NULL; |
|---|
| 370 | 449 | } |
|---|
| 371 | 450 | EXPORT_SYMBOL_GPL(kill_dax); |
|---|
| 451 | + |
|---|
| 452 | +void run_dax(struct dax_device *dax_dev) |
|---|
| 453 | +{ |
|---|
| 454 | + set_bit(DAXDEV_ALIVE, &dax_dev->flags); |
|---|
| 455 | +} |
|---|
| 456 | +EXPORT_SYMBOL_GPL(run_dax); |
|---|
| 372 | 457 | |
|---|
| 373 | 458 | static struct inode *dax_alloc_inode(struct super_block *sb) |
|---|
| 374 | 459 | { |
|---|
| .. | .. |
|---|
| 389 | 474 | return container_of(inode, struct dax_device, inode); |
|---|
| 390 | 475 | } |
|---|
| 391 | 476 | |
|---|
| 392 | | -static void dax_i_callback(struct rcu_head *head) |
|---|
| 477 | +static void dax_free_inode(struct inode *inode) |
|---|
| 393 | 478 | { |
|---|
| 394 | | - struct inode *inode = container_of(head, struct inode, i_rcu); |
|---|
| 395 | 479 | struct dax_device *dax_dev = to_dax_dev(inode); |
|---|
| 396 | | - |
|---|
| 397 | 480 | kfree(dax_dev->host); |
|---|
| 398 | 481 | dax_dev->host = NULL; |
|---|
| 399 | 482 | if (inode->i_rdev) |
|---|
| .. | .. |
|---|
| 404 | 487 | static void dax_destroy_inode(struct inode *inode) |
|---|
| 405 | 488 | { |
|---|
| 406 | 489 | struct dax_device *dax_dev = to_dax_dev(inode); |
|---|
| 407 | | - |
|---|
| 408 | 490 | WARN_ONCE(test_bit(DAXDEV_ALIVE, &dax_dev->flags), |
|---|
| 409 | 491 | "kill_dax() must be called before final iput()\n"); |
|---|
| 410 | | - call_rcu(&inode->i_rcu, dax_i_callback); |
|---|
| 411 | 492 | } |
|---|
| 412 | 493 | |
|---|
| 413 | 494 | static const struct super_operations dax_sops = { |
|---|
| 414 | 495 | .statfs = simple_statfs, |
|---|
| 415 | 496 | .alloc_inode = dax_alloc_inode, |
|---|
| 416 | 497 | .destroy_inode = dax_destroy_inode, |
|---|
| 498 | + .free_inode = dax_free_inode, |
|---|
| 417 | 499 | .drop_inode = generic_delete_inode, |
|---|
| 418 | 500 | }; |
|---|
| 419 | 501 | |
|---|
| 420 | | -static struct dentry *dax_mount(struct file_system_type *fs_type, |
|---|
| 421 | | - int flags, const char *dev_name, void *data) |
|---|
| 502 | +static int dax_init_fs_context(struct fs_context *fc) |
|---|
| 422 | 503 | { |
|---|
| 423 | | - return mount_pseudo(fs_type, "dax:", &dax_sops, NULL, DAXFS_MAGIC); |
|---|
| 504 | + struct pseudo_fs_context *ctx = init_pseudo(fc, DAXFS_MAGIC); |
|---|
| 505 | + if (!ctx) |
|---|
| 506 | + return -ENOMEM; |
|---|
| 507 | + ctx->ops = &dax_sops; |
|---|
| 508 | + return 0; |
|---|
| 424 | 509 | } |
|---|
| 425 | 510 | |
|---|
| 426 | 511 | static struct file_system_type dax_fs_type = { |
|---|
| 427 | | - .name = "dax", |
|---|
| 428 | | - .mount = dax_mount, |
|---|
| 429 | | - .kill_sb = kill_anon_super, |
|---|
| 512 | + .name = "dax", |
|---|
| 513 | + .init_fs_context = dax_init_fs_context, |
|---|
| 514 | + .kill_sb = kill_anon_super, |
|---|
| 430 | 515 | }; |
|---|
| 431 | 516 | |
|---|
| 432 | 517 | static int dax_test(struct inode *inode, void *data) |
|---|
| .. | .. |
|---|
| 488 | 573 | } |
|---|
| 489 | 574 | |
|---|
| 490 | 575 | struct dax_device *alloc_dax(void *private, const char *__host, |
|---|
| 491 | | - const struct dax_operations *ops) |
|---|
| 576 | + const struct dax_operations *ops, unsigned long flags) |
|---|
| 492 | 577 | { |
|---|
| 493 | 578 | struct dax_device *dax_dev; |
|---|
| 494 | 579 | const char *host; |
|---|
| 495 | 580 | dev_t devt; |
|---|
| 496 | 581 | int minor; |
|---|
| 497 | 582 | |
|---|
| 583 | + if (ops && !ops->zero_page_range) { |
|---|
| 584 | + pr_debug("%s: error: device does not provide dax" |
|---|
| 585 | + " operation zero_page_range()\n", |
|---|
| 586 | + __host ? __host : "Unknown"); |
|---|
| 587 | + return ERR_PTR(-EINVAL); |
|---|
| 588 | + } |
|---|
| 589 | + |
|---|
| 498 | 590 | host = kstrdup(__host, GFP_KERNEL); |
|---|
| 499 | 591 | if (__host && !host) |
|---|
| 500 | | - return NULL; |
|---|
| 592 | + return ERR_PTR(-ENOMEM); |
|---|
| 501 | 593 | |
|---|
| 502 | 594 | minor = ida_simple_get(&dax_minor_ida, 0, MINORMASK+1, GFP_KERNEL); |
|---|
| 503 | 595 | if (minor < 0) |
|---|
| .. | .. |
|---|
| 511 | 603 | dax_add_host(dax_dev, host); |
|---|
| 512 | 604 | dax_dev->ops = ops; |
|---|
| 513 | 605 | dax_dev->private = private; |
|---|
| 606 | + if (flags & DAXDEV_F_SYNC) |
|---|
| 607 | + set_dax_synchronous(dax_dev); |
|---|
| 608 | + |
|---|
| 514 | 609 | return dax_dev; |
|---|
| 515 | 610 | |
|---|
| 516 | 611 | err_dev: |
|---|
| 517 | 612 | ida_simple_remove(&dax_minor_ida, minor); |
|---|
| 518 | 613 | err_minor: |
|---|
| 519 | 614 | kfree(host); |
|---|
| 520 | | - return NULL; |
|---|
| 615 | + return ERR_PTR(-ENOMEM); |
|---|
| 521 | 616 | } |
|---|
| 522 | 617 | EXPORT_SYMBOL_GPL(alloc_dax); |
|---|
| 523 | 618 | |
|---|
| .. | .. |
|---|
| 584 | 679 | |
|---|
| 585 | 680 | void *dax_get_private(struct dax_device *dax_dev) |
|---|
| 586 | 681 | { |
|---|
| 682 | + if (!test_bit(DAXDEV_ALIVE, &dax_dev->flags)) |
|---|
| 683 | + return NULL; |
|---|
| 587 | 684 | return dax_dev->private; |
|---|
| 588 | 685 | } |
|---|
| 589 | 686 | EXPORT_SYMBOL_GPL(dax_get_private); |
|---|
| .. | .. |
|---|
| 597 | 694 | inode_init_once(inode); |
|---|
| 598 | 695 | } |
|---|
| 599 | 696 | |
|---|
| 600 | | -static int __dax_fs_init(void) |
|---|
| 697 | +static int dax_fs_init(void) |
|---|
| 601 | 698 | { |
|---|
| 602 | 699 | int rc; |
|---|
| 603 | 700 | |
|---|
| .. | .. |
|---|
| 607 | 704 | init_once); |
|---|
| 608 | 705 | if (!dax_cache) |
|---|
| 609 | 706 | return -ENOMEM; |
|---|
| 610 | | - |
|---|
| 611 | | - rc = register_filesystem(&dax_fs_type); |
|---|
| 612 | | - if (rc) |
|---|
| 613 | | - goto err_register_fs; |
|---|
| 614 | 707 | |
|---|
| 615 | 708 | dax_mnt = kern_mount(&dax_fs_type); |
|---|
| 616 | 709 | if (IS_ERR(dax_mnt)) { |
|---|
| .. | .. |
|---|
| 622 | 715 | return 0; |
|---|
| 623 | 716 | |
|---|
| 624 | 717 | err_mount: |
|---|
| 625 | | - unregister_filesystem(&dax_fs_type); |
|---|
| 626 | | - err_register_fs: |
|---|
| 627 | 718 | kmem_cache_destroy(dax_cache); |
|---|
| 628 | 719 | |
|---|
| 629 | 720 | return rc; |
|---|
| 630 | 721 | } |
|---|
| 631 | 722 | |
|---|
| 632 | | -static void __dax_fs_exit(void) |
|---|
| 723 | +static void dax_fs_exit(void) |
|---|
| 633 | 724 | { |
|---|
| 634 | 725 | kern_unmount(dax_mnt); |
|---|
| 635 | | - unregister_filesystem(&dax_fs_type); |
|---|
| 726 | + rcu_barrier(); |
|---|
| 636 | 727 | kmem_cache_destroy(dax_cache); |
|---|
| 637 | 728 | } |
|---|
| 638 | 729 | |
|---|
| 639 | | -static int __init dax_fs_init(void) |
|---|
| 730 | +static int __init dax_core_init(void) |
|---|
| 640 | 731 | { |
|---|
| 641 | 732 | int rc; |
|---|
| 642 | 733 | |
|---|
| 643 | | - rc = __dax_fs_init(); |
|---|
| 734 | + rc = dax_fs_init(); |
|---|
| 644 | 735 | if (rc) |
|---|
| 645 | 736 | return rc; |
|---|
| 646 | 737 | |
|---|
| 647 | 738 | rc = alloc_chrdev_region(&dax_devt, 0, MINORMASK+1, "dax"); |
|---|
| 648 | 739 | if (rc) |
|---|
| 649 | | - __dax_fs_exit(); |
|---|
| 650 | | - return rc; |
|---|
| 740 | + goto err_chrdev; |
|---|
| 741 | + |
|---|
| 742 | + rc = dax_bus_init(); |
|---|
| 743 | + if (rc) |
|---|
| 744 | + goto err_bus; |
|---|
| 745 | + return 0; |
|---|
| 746 | + |
|---|
| 747 | +err_bus: |
|---|
| 748 | + unregister_chrdev_region(dax_devt, MINORMASK+1); |
|---|
| 749 | +err_chrdev: |
|---|
| 750 | + dax_fs_exit(); |
|---|
| 751 | + return 0; |
|---|
| 651 | 752 | } |
|---|
| 652 | 753 | |
|---|
| 653 | | -static void __exit dax_fs_exit(void) |
|---|
| 754 | +static void __exit dax_core_exit(void) |
|---|
| 654 | 755 | { |
|---|
| 756 | + dax_bus_exit(); |
|---|
| 655 | 757 | unregister_chrdev_region(dax_devt, MINORMASK+1); |
|---|
| 656 | 758 | ida_destroy(&dax_minor_ida); |
|---|
| 657 | | - __dax_fs_exit(); |
|---|
| 759 | + dax_fs_exit(); |
|---|
| 658 | 760 | } |
|---|
| 659 | 761 | |
|---|
| 660 | 762 | MODULE_AUTHOR("Intel Corporation"); |
|---|
| 661 | 763 | MODULE_LICENSE("GPL v2"); |
|---|
| 662 | | -subsys_initcall(dax_fs_init); |
|---|
| 663 | | -module_exit(dax_fs_exit); |
|---|
| 764 | +subsys_initcall(dax_core_init); |
|---|
| 765 | +module_exit(dax_core_exit); |
|---|