[PATCH] remove the old bd_mutex lockdep annotation
[safe/jmp/linux-2.6] / fs / block_dev.c
index c0cbd1b..36c38f4 100644 (file)
@@ -5,25 +5,25 @@
  *  Copyright (C) 2001  Andrea Arcangeli <andrea@suse.de> SuSE
  */
 
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/fcntl.h>
 #include <linux/slab.h>
 #include <linux/kmod.h>
 #include <linux/major.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/smp_lock.h>
 #include <linux/highmem.h>
 #include <linux/blkdev.h>
 #include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/buffer_head.h>
+#include <linux/writeback.h>
 #include <linux/mpage.h>
 #include <linux/mount.h>
 #include <linux/uio.h>
 #include <linux/namei.h>
 #include <asm/uaccess.h>
+#include "internal.h"
 
 struct bdev_inode {
        struct block_device bdev;
@@ -86,16 +86,12 @@ EXPORT_SYMBOL(set_blocksize);
 
 int sb_set_blocksize(struct super_block *sb, int size)
 {
-       int bits = 9; /* 2^9 = 512 */
-
        if (set_blocksize(sb->s_bdev, size))
                return 0;
        /* If we get here, we know size is power of two
         * and it's value is between 512 and PAGE_SIZE */
        sb->s_blocksize = size;
-       for (size >>= 10; size; size >>= 1)
-               ++bits;
-       sb->s_blocksize_bits = bits;
+       sb->s_blocksize_bits = blksize_bits(size);
        return sb->s_blocksize;
 }
 
@@ -135,9 +131,10 @@ blkdev_get_block(struct inode *inode, sector_t iblock,
 
 static int
 blkdev_get_blocks(struct inode *inode, sector_t iblock,
-               unsigned long max_blocks, struct buffer_head *bh, int create)
+               struct buffer_head *bh, int create)
 {
        sector_t end_block = max_block(I_BDEV(inode));
+       unsigned long max_blocks = bh->b_size >> inode->i_blkbits;
 
        if ((iblock + max_blocks) > end_block) {
                max_blocks = end_block - iblock;
@@ -202,7 +199,7 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin)
        loff_t size;
        loff_t retval;
 
-       down(&bd_inode->i_sem);
+       mutex_lock(&bd_inode->i_mutex);
        size = i_size_read(bd_inode);
 
        switch (origin) {
@@ -219,7 +216,7 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin)
                }
                retval = offset;
        }
-       up(&bd_inode->i_sem);
+       mutex_unlock(&bd_inode->i_mutex);
        return retval;
 }
        
@@ -238,11 +235,11 @@ static int block_fsync(struct file *filp, struct dentry *dentry, int datasync)
  */
 
 static  __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock);
-static kmem_cache_t * bdev_cachep;
+static struct kmem_cache * bdev_cachep __read_mostly;
 
 static struct inode *bdev_alloc_inode(struct super_block *sb)
 {
-       struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, SLAB_KERNEL);
+       struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
        if (!ei)
                return NULL;
        return &ei->vfs_inode;
@@ -256,7 +253,7 @@ static void bdev_destroy_inode(struct inode *inode)
        kmem_cache_free(bdev_cachep, bdi);
 }
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
 {
        struct bdev_inode *ei = (struct bdev_inode *) foo;
        struct block_device *bdev = &ei->bdev;
@@ -265,10 +262,13 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
            SLAB_CTOR_CONSTRUCTOR)
        {
                memset(bdev, 0, sizeof(*bdev));
-               sema_init(&bdev->bd_sem, 1);
-               sema_init(&bdev->bd_mount_sem, 1);
+               mutex_init(&bdev->bd_mutex);
+               mutex_init(&bdev->bd_mount_mutex);
                INIT_LIST_HEAD(&bdev->bd_inodes);
                INIT_LIST_HEAD(&bdev->bd_list);
+#ifdef CONFIG_SYSFS
+               INIT_LIST_HEAD(&bdev->bd_holder_list);
+#endif
                inode_init_once(&ei->vfs_inode);
        }
 }
@@ -300,10 +300,10 @@ static struct super_operations bdev_sops = {
        .clear_inode = bdev_clear_inode,
 };
 
-static struct super_block *bd_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int bd_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576);
+       return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576, mnt);
 }
 
 static struct file_system_type bd_type = {
@@ -312,14 +312,15 @@ static struct file_system_type bd_type = {
        .kill_sb        = kill_anon_super,
 };
 
-static struct vfsmount *bd_mnt;
+static struct vfsmount *bd_mnt __read_mostly;
 struct super_block *blockdev_superblock;
 
 void __init bdev_cache_init(void)
 {
        int err;
        bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
-                       0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_PANIC,
+                       0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
+                               SLAB_MEM_SPREAD|SLAB_PANIC),
                        init_once, NULL);
        err = register_filesystem(&bd_type);
        if (err)
@@ -413,21 +414,31 @@ EXPORT_SYMBOL(bdput);
 static struct block_device *bd_acquire(struct inode *inode)
 {
        struct block_device *bdev;
+
        spin_lock(&bdev_lock);
        bdev = inode->i_bdev;
-       if (bdev && igrab(bdev->bd_inode)) {
+       if (bdev) {
+               atomic_inc(&bdev->bd_inode->i_count);
                spin_unlock(&bdev_lock);
                return bdev;
        }
        spin_unlock(&bdev_lock);
+
        bdev = bdget(inode->i_rdev);
        if (bdev) {
                spin_lock(&bdev_lock);
-               if (inode->i_bdev)
-                       __bd_forget(inode);
-               inode->i_bdev = bdev;
-               inode->i_mapping = bdev->bd_inode->i_mapping;
-               list_add(&inode->i_devices, &bdev->bd_inodes);
+               if (!inode->i_bdev) {
+                       /*
+                        * We take an additional bd_inode->i_count for inode,
+                        * and it's released in clear_inode() of inode.
+                        * So, we can access it via ->i_mapping always
+                        * without igrab().
+                        */
+                       atomic_inc(&bdev->bd_inode->i_count);
+                       inode->i_bdev = bdev;
+                       inode->i_mapping = bdev->bd_inode->i_mapping;
+                       list_add(&inode->i_devices, &bdev->bd_inodes);
+               }
                spin_unlock(&bdev_lock);
        }
        return bdev;
@@ -437,10 +448,18 @@ static struct block_device *bd_acquire(struct inode *inode)
 
 void bd_forget(struct inode *inode)
 {
+       struct block_device *bdev = NULL;
+
        spin_lock(&bdev_lock);
-       if (inode->i_bdev)
+       if (inode->i_bdev) {
+               if (inode->i_sb != blockdev_superblock)
+                       bdev = inode->i_bdev;
                __bd_forget(inode);
+       }
        spin_unlock(&bdev_lock);
+
+       if (bdev)
+               iput(bdev->bd_inode);
 }
 
 int bd_claim(struct block_device *bdev, void *holder)
@@ -492,6 +511,330 @@ void bd_release(struct block_device *bdev)
 
 EXPORT_SYMBOL(bd_release);
 
+#ifdef CONFIG_SYSFS
+/*
+ * Functions for bd_claim_by_kobject / bd_release_from_kobject
+ *
+ *     If a kobject is passed to bd_claim_by_kobject()
+ *     and the kobject has a parent directory,
+ *     following symlinks are created:
+ *        o from the kobject to the claimed bdev
+ *        o from "holders" directory of the bdev to the parent of the kobject
+ *     bd_release_from_kobject() removes these symlinks.
+ *
+ *     Example:
+ *        If /dev/dm-0 maps to /dev/sda, kobject corresponding to
+ *        /sys/block/dm-0/slaves is passed to bd_claim_by_kobject(), then:
+ *           /sys/block/dm-0/slaves/sda --> /sys/block/sda
+ *           /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
+ */
+
+static struct kobject *bdev_get_kobj(struct block_device *bdev)
+{
+       if (bdev->bd_contains != bdev)
+               return kobject_get(&bdev->bd_part->kobj);
+       else
+               return kobject_get(&bdev->bd_disk->kobj);
+}
+
+static struct kobject *bdev_get_holder(struct block_device *bdev)
+{
+       if (bdev->bd_contains != bdev)
+               return kobject_get(bdev->bd_part->holder_dir);
+       else
+               return kobject_get(bdev->bd_disk->holder_dir);
+}
+
+static int add_symlink(struct kobject *from, struct kobject *to)
+{
+       if (!from || !to)
+               return 0;
+       return sysfs_create_link(from, to, kobject_name(to));
+}
+
+static void del_symlink(struct kobject *from, struct kobject *to)
+{
+       if (!from || !to)
+               return;
+       sysfs_remove_link(from, kobject_name(to));
+}
+
+/*
+ * 'struct bd_holder' contains pointers to kobjects symlinked by
+ * bd_claim_by_kobject.
+ * It's connected to bd_holder_list which is protected by bdev->bd_sem.
+ */
+struct bd_holder {
+       struct list_head list;  /* chain of holders of the bdev */
+       int count;              /* references from the holder */
+       struct kobject *sdir;   /* holder object, e.g. "/block/dm-0/slaves" */
+       struct kobject *hdev;   /* e.g. "/block/dm-0" */
+       struct kobject *hdir;   /* e.g. "/block/sda/holders" */
+       struct kobject *sdev;   /* e.g. "/block/sda" */
+};
+
+/*
+ * Get references of related kobjects at once.
+ * Returns 1 on success. 0 on failure.
+ *
+ * Should call bd_holder_release_dirs() after successful use.
+ */
+static int bd_holder_grab_dirs(struct block_device *bdev,
+                       struct bd_holder *bo)
+{
+       if (!bdev || !bo)
+               return 0;
+
+       bo->sdir = kobject_get(bo->sdir);
+       if (!bo->sdir)
+               return 0;
+
+       bo->hdev = kobject_get(bo->sdir->parent);
+       if (!bo->hdev)
+               goto fail_put_sdir;
+
+       bo->sdev = bdev_get_kobj(bdev);
+       if (!bo->sdev)
+               goto fail_put_hdev;
+
+       bo->hdir = bdev_get_holder(bdev);
+       if (!bo->hdir)
+               goto fail_put_sdev;
+
+       return 1;
+
+fail_put_sdev:
+       kobject_put(bo->sdev);
+fail_put_hdev:
+       kobject_put(bo->hdev);
+fail_put_sdir:
+       kobject_put(bo->sdir);
+
+       return 0;
+}
+
+/* Put references of related kobjects at once. */
+static void bd_holder_release_dirs(struct bd_holder *bo)
+{
+       kobject_put(bo->hdir);
+       kobject_put(bo->sdev);
+       kobject_put(bo->hdev);
+       kobject_put(bo->sdir);
+}
+
+static struct bd_holder *alloc_bd_holder(struct kobject *kobj)
+{
+       struct bd_holder *bo;
+
+       bo = kzalloc(sizeof(*bo), GFP_KERNEL);
+       if (!bo)
+               return NULL;
+
+       bo->count = 1;
+       bo->sdir = kobj;
+
+       return bo;
+}
+
+static void free_bd_holder(struct bd_holder *bo)
+{
+       kfree(bo);
+}
+
+/**
+ * find_bd_holder - find matching struct bd_holder from the block device
+ *
+ * @bdev:      struct block device to be searched
+ * @bo:                target struct bd_holder
+ *
+ * Returns matching entry with @bo in @bdev->bd_holder_list.
+ * If found, increment the reference count and return the pointer.
+ * If not found, returns NULL.
+ */
+static struct bd_holder *find_bd_holder(struct block_device *bdev,
+                                       struct bd_holder *bo)
+{
+       struct bd_holder *tmp;
+
+       list_for_each_entry(tmp, &bdev->bd_holder_list, list)
+               if (tmp->sdir == bo->sdir) {
+                       tmp->count++;
+                       return tmp;
+               }
+
+       return NULL;
+}
+
+/**
+ * add_bd_holder - create sysfs symlinks for bd_claim() relationship
+ *
+ * @bdev:      block device to be bd_claimed
+ * @bo:                preallocated and initialized by alloc_bd_holder()
+ *
+ * Add @bo to @bdev->bd_holder_list, create symlinks.
+ *
+ * Returns 0 if symlinks are created.
+ * Returns -ve if something fails.
+ */
+static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
+{
+       int ret;
+
+       if (!bo)
+               return -EINVAL;
+
+       if (!bd_holder_grab_dirs(bdev, bo))
+               return -EBUSY;
+
+       ret = add_symlink(bo->sdir, bo->sdev);
+       if (ret == 0) {
+               ret = add_symlink(bo->hdir, bo->hdev);
+               if (ret)
+                       del_symlink(bo->sdir, bo->sdev);
+       }
+       if (ret == 0)
+               list_add_tail(&bo->list, &bdev->bd_holder_list);
+       return ret;
+}
+
+/**
+ * del_bd_holder - delete sysfs symlinks for bd_claim() relationship
+ *
+ * @bdev:      block device to be bd_claimed
+ * @kobj:      holder's kobject
+ *
+ * If there is matching entry with @kobj in @bdev->bd_holder_list
+ * and no other bd_claim() from the same kobject,
+ * remove the struct bd_holder from the list, delete symlinks for it.
+ *
+ * Returns a pointer to the struct bd_holder when it's removed from the list
+ * and ready to be freed.
+ * Returns NULL if matching claim isn't found or there is other bd_claim()
+ * by the same kobject.
+ */
+static struct bd_holder *del_bd_holder(struct block_device *bdev,
+                                       struct kobject *kobj)
+{
+       struct bd_holder *bo;
+
+       list_for_each_entry(bo, &bdev->bd_holder_list, list) {
+               if (bo->sdir == kobj) {
+                       bo->count--;
+                       BUG_ON(bo->count < 0);
+                       if (!bo->count) {
+                               list_del(&bo->list);
+                               del_symlink(bo->sdir, bo->sdev);
+                               del_symlink(bo->hdir, bo->hdev);
+                               bd_holder_release_dirs(bo);
+                               return bo;
+                       }
+                       break;
+               }
+       }
+
+       return NULL;
+}
+
+/**
+ * bd_claim_by_kobject - bd_claim() with additional kobject signature
+ *
+ * @bdev:      block device to be claimed
+ * @holder:    holder's signature
+ * @kobj:      holder's kobject
+ *
+ * Do bd_claim() and if it succeeds, create sysfs symlinks between
+ * the bdev and the holder's kobject.
+ * Use bd_release_from_kobject() when relesing the claimed bdev.
+ *
+ * Returns 0 on success. (same as bd_claim())
+ * Returns errno on failure.
+ */
+static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
+                               struct kobject *kobj)
+{
+       int res;
+       struct bd_holder *bo, *found;
+
+       if (!kobj)
+               return -EINVAL;
+
+       bo = alloc_bd_holder(kobj);
+       if (!bo)
+               return -ENOMEM;
+
+       mutex_lock(&bdev->bd_mutex);
+       res = bd_claim(bdev, holder);
+       if (res == 0) {
+               found = find_bd_holder(bdev, bo);
+               if (found == NULL) {
+                       res = add_bd_holder(bdev, bo);
+                       if (res)
+                               bd_release(bdev);
+               }
+       }
+
+       if (res || found)
+               free_bd_holder(bo);
+       mutex_unlock(&bdev->bd_mutex);
+
+       return res;
+}
+
+/**
+ * bd_release_from_kobject - bd_release() with additional kobject signature
+ *
+ * @bdev:      block device to be released
+ * @kobj:      holder's kobject
+ *
+ * Do bd_release() and remove sysfs symlinks created by bd_claim_by_kobject().
+ */
+static void bd_release_from_kobject(struct block_device *bdev,
+                                       struct kobject *kobj)
+{
+       struct bd_holder *bo;
+
+       if (!kobj)
+               return;
+
+       mutex_lock(&bdev->bd_mutex);
+       bd_release(bdev);
+       if ((bo = del_bd_holder(bdev, kobj)))
+               free_bd_holder(bo);
+       mutex_unlock(&bdev->bd_mutex);
+}
+
+/**
+ * bd_claim_by_disk - wrapper function for bd_claim_by_kobject()
+ *
+ * @bdev:      block device to be claimed
+ * @holder:    holder's signature
+ * @disk:      holder's gendisk
+ *
+ * Call bd_claim_by_kobject() with getting @disk->slave_dir.
+ */
+int bd_claim_by_disk(struct block_device *bdev, void *holder,
+                       struct gendisk *disk)
+{
+       return bd_claim_by_kobject(bdev, holder, kobject_get(disk->slave_dir));
+}
+EXPORT_SYMBOL_GPL(bd_claim_by_disk);
+
+/**
+ * bd_release_from_disk - wrapper function for bd_release_from_kobject()
+ *
+ * @bdev:      block device to be claimed
+ * @disk:      holder's gendisk
+ *
+ * Call bd_release_from_kobject() and put @disk->slave_dir.
+ */
+void bd_release_from_disk(struct block_device *bdev, struct gendisk *disk)
+{
+       bd_release_from_kobject(bdev, disk->slave_dir);
+       kobject_put(disk->slave_dir);
+}
+EXPORT_SYMBOL_GPL(bd_release_from_disk);
+#endif
+
 /*
  * Tries to open block device by device number.  Use it ONLY if you
  * really do not have anything better - i.e. when you are behind a
@@ -574,7 +917,7 @@ static int do_open(struct block_device *bdev, struct file *file)
        }
        owner = disk->fops->owner;
 
-       down(&bdev->bd_sem);
+       mutex_lock(&bdev->bd_mutex);
        if (!bdev->bd_openers) {
                bdev->bd_disk = disk;
                bdev->bd_contains = bdev;
@@ -605,21 +948,21 @@ static int do_open(struct block_device *bdev, struct file *file)
                        if (ret)
                                goto out_first;
                        bdev->bd_contains = whole;
-                       down(&whole->bd_sem);
+                       mutex_lock(&whole->bd_mutex);
                        whole->bd_part_count++;
                        p = disk->part[part - 1];
                        bdev->bd_inode->i_data.backing_dev_info =
                           whole->bd_inode->i_data.backing_dev_info;
                        if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) {
                                whole->bd_part_count--;
-                               up(&whole->bd_sem);
+                               mutex_unlock(&whole->bd_mutex);
                                ret = -ENXIO;
                                goto out_first;
                        }
                        kobject_get(&p->kobj);
                        bdev->bd_part = p;
                        bd_set_size(bdev, (loff_t) p->nr_sects << 9);
-                       up(&whole->bd_sem);
+                       mutex_unlock(&whole->bd_mutex);
                }
        } else {
                put_disk(disk);
@@ -633,13 +976,13 @@ static int do_open(struct block_device *bdev, struct file *file)
                        if (bdev->bd_invalidated)
                                rescan_partitions(bdev->bd_disk, bdev);
                } else {
-                       down(&bdev->bd_contains->bd_sem);
+                       mutex_lock(&bdev->bd_contains->bd_mutex);
                        bdev->bd_contains->bd_part_count++;
-                       up(&bdev->bd_contains->bd_sem);
+                       mutex_unlock(&bdev->bd_contains->bd_mutex);
                }
        }
        bdev->bd_openers++;
-       up(&bdev->bd_sem);
+       mutex_unlock(&bdev->bd_mutex);
        unlock_kernel();
        return 0;
 
@@ -652,7 +995,7 @@ out_first:
        put_disk(disk);
        module_put(owner);
 out:
-       up(&bdev->bd_sem);
+       mutex_unlock(&bdev->bd_mutex);
        unlock_kernel();
        if (ret)
                bdput(bdev);
@@ -693,6 +1036,8 @@ static int blkdev_open(struct inode * inode, struct file * filp)
        filp->f_flags |= O_LARGEFILE;
 
        bdev = bd_acquire(inode);
+       if (bdev == NULL)
+               return -ENOMEM;
 
        res = do_open(bdev, filp);
        if (res)
@@ -714,7 +1059,7 @@ int blkdev_put(struct block_device *bdev)
        struct inode *bd_inode = bdev->bd_inode;
        struct gendisk *disk = bdev->bd_disk;
 
-       down(&bdev->bd_sem);
+       mutex_lock(&bdev->bd_mutex);
        lock_kernel();
        if (!--bdev->bd_openers) {
                sync_blockdev(bdev);
@@ -724,9 +1069,9 @@ int blkdev_put(struct block_device *bdev)
                if (disk->fops->release)
                        ret = disk->fops->release(bd_inode, NULL);
        } else {
-               down(&bdev->bd_contains->bd_sem);
+               mutex_lock(&bdev->bd_contains->bd_mutex);
                bdev->bd_contains->bd_part_count--;
-               up(&bdev->bd_contains->bd_sem);
+               mutex_unlock(&bdev->bd_contains->bd_mutex);
        }
        if (!bdev->bd_openers) {
                struct module *owner = disk->fops->owner;
@@ -746,7 +1091,7 @@ int blkdev_put(struct block_device *bdev)
                bdev->bd_contains = NULL;
        }
        unlock_kernel();
-       up(&bdev->bd_sem);
+       mutex_unlock(&bdev->bd_mutex);
        bdput(bdev);
        return ret;
 }
@@ -761,29 +1106,12 @@ static int blkdev_close(struct inode * inode, struct file * filp)
        return blkdev_put(bdev);
 }
 
-static ssize_t blkdev_file_write(struct file *file, const char __user *buf,
-                                  size_t count, loff_t *ppos)
-{
-       struct iovec local_iov = { .iov_base = (void __user *)buf, .iov_len = count };
-
-       return generic_file_write_nolock(file, &local_iov, 1, ppos);
-}
-
-static ssize_t blkdev_file_aio_write(struct kiocb *iocb, const char __user *buf,
-                                  size_t count, loff_t pos)
-{
-       struct iovec local_iov = { .iov_base = (void __user *)buf, .iov_len = count };
-
-       return generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos);
-}
-
-static int block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
-                       unsigned long arg)
+static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
        return blkdev_ioctl(file->f_mapping->host, file, cmd, arg);
 }
 
-struct address_space_operations def_blk_aops = {
+const struct address_space_operations def_blk_aops = {
        .readpage       = blkdev_readpage,
        .writepage      = blkdev_writepage,
        .sync_page      = block_sync_page,
@@ -793,23 +1121,23 @@ struct address_space_operations def_blk_aops = {
        .direct_IO      = blkdev_direct_IO,
 };
 
-struct file_operations def_blk_fops = {
+const struct file_operations def_blk_fops = {
        .open           = blkdev_open,
        .release        = blkdev_close,
        .llseek         = block_llseek,
-       .read           = generic_file_read,
-       .write          = blkdev_file_write,
+       .read           = do_sync_read,
+       .write          = do_sync_write,
        .aio_read       = generic_file_aio_read,
-       .aio_write      = blkdev_file_aio_write, 
+       .aio_write      = generic_file_aio_write_nolock,
        .mmap           = generic_file_mmap,
        .fsync          = block_fsync,
-       .ioctl          = block_ioctl,
+       .unlocked_ioctl = block_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = compat_blkdev_ioctl,
 #endif
-       .readv          = generic_file_readv,
-       .writev         = generic_file_write_nolock,
        .sendfile       = generic_file_sendfile,
+       .splice_read    = generic_file_splice_read,
+       .splice_write   = generic_file_splice_write,
 };
 
 int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
@@ -921,3 +1249,24 @@ void close_bdev_excl(struct block_device *bdev)
 }
 
 EXPORT_SYMBOL(close_bdev_excl);
+
+int __invalidate_device(struct block_device *bdev)
+{
+       struct super_block *sb = get_super(bdev);
+       int res = 0;
+
+       if (sb) {
+               /*
+                * no need to lock the super, get_super holds the
+                * read mutex so the filesystem cannot go away
+                * under us (->put_super runs with the write lock
+                * hold).
+                */
+               shrink_dcache_sb(sb);
+               res = invalidate_inodes(sb);
+               drop_super(sb);
+       }
+       invalidate_bdev(bdev, 0);
+       return res;
+}
+EXPORT_SYMBOL(__invalidate_device);