]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/block_dev.c
rdma/cxgb4: Fix memory leaks during module exit
[karo-tx-linux.git] / fs / block_dev.c
index 9ccabe3bb7de1635ba3cac78751db68bb5ead93e..519599dddd3692ee373a9eb00d95d5757556ad42 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/magic.h>
+#include <linux/dax.h>
 #include <linux/buffer_head.h>
 #include <linux/swap.h>
 #include <linux/pagevec.h>
@@ -103,12 +104,11 @@ void invalidate_bdev(struct block_device *bdev)
 {
        struct address_space *mapping = bdev->bd_inode->i_mapping;
 
-       if (mapping->nrpages == 0)
-               return;
-
-       invalidate_bh_lrus();
-       lru_add_drain_all();    /* make sure all lru add caches are flushed */
-       invalidate_mapping_pages(mapping, 0, -1);
+       if (mapping->nrpages) {
+               invalidate_bh_lrus();
+               lru_add_drain_all();    /* make sure all lru add caches are flushed */
+               invalidate_mapping_pages(mapping, 0, -1);
+       }
        /* 99% of the time, we don't need to flush the cleancache on the bdev.
         * But, for the strange corners, lets be cautious
         */
@@ -717,120 +717,6 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
 }
 EXPORT_SYMBOL_GPL(bdev_write_page);
 
-/**
- * bdev_direct_access() - Get the address for directly-accessibly memory
- * @bdev: The device containing the memory
- * @dax: control and output parameters for ->direct_access
- *
- * If a block device is made up of directly addressable memory, this function
- * will tell the caller the PFN and the address of the memory.  The address
- * may be directly dereferenced within the kernel without the need to call
- * ioremap(), kmap() or similar.  The PFN is suitable for inserting into
- * page tables.
- *
- * Return: negative errno if an error occurs, otherwise the number of bytes
- * accessible at this address.
- */
-long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax)
-{
-       sector_t sector = dax->sector;
-       long avail, size = dax->size;
-       const struct block_device_operations *ops = bdev->bd_disk->fops;
-
-       /*
-        * The device driver is allowed to sleep, in order to make the
-        * memory directly accessible.
-        */
-       might_sleep();
-
-       if (size < 0)
-               return size;
-       if (!blk_queue_dax(bdev_get_queue(bdev)) || !ops->direct_access)
-               return -EOPNOTSUPP;
-       if ((sector + DIV_ROUND_UP(size, 512)) >
-                                       part_nr_sects_read(bdev->bd_part))
-               return -ERANGE;
-       sector += get_start_sect(bdev);
-       if (sector % (PAGE_SIZE / 512))
-               return -EINVAL;
-       avail = ops->direct_access(bdev, sector, &dax->addr, &dax->pfn, size);
-       if (!avail)
-               return -ERANGE;
-       if (avail > 0 && avail & ~PAGE_MASK)
-               return -ENXIO;
-       return min(avail, size);
-}
-EXPORT_SYMBOL_GPL(bdev_direct_access);
-
-/**
- * bdev_dax_supported() - Check if the device supports dax for filesystem
- * @sb: The superblock of the device
- * @blocksize: The block size of the device
- *
- * This is a library function for filesystems to check if the block device
- * can be mounted with dax option.
- *
- * Return: negative errno if unsupported, 0 if supported.
- */
-int bdev_dax_supported(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_dax_supported);
-
-/**
- * bdev_dax_capable() - Return if the raw device is capable for dax
- * @bdev: The device for raw block device access
- */
-bool bdev_dax_capable(struct block_device *bdev)
-{
-       struct blk_dax_ctl dax = {
-               .size = PAGE_SIZE,
-       };
-
-       if (!IS_ENABLED(CONFIG_FS_DAX))
-               return false;
-
-       dax.sector = 0;
-       if (bdev_direct_access(bdev, &dax) < 0)
-               return false;
-
-       dax.sector = bdev->bd_part->nr_sects - (PAGE_SIZE / 512);
-       if (bdev_direct_access(bdev, &dax) < 0)
-               return false;
-
-       return true;
-}
-
 /*
  * pseudo-fs
  */