Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / drivers / md / bitmap.c
index 5432d07c074dd08b959cb3ffe9de5a910b084fda..5554adaa58f9be01d37bc5623f63384c084e69de 100644 (file)
@@ -479,9 +479,12 @@ static int bitmap_read_sb(struct bitmap *bitmap)
        int err = -EINVAL;
 
        /* page 0 is the superblock, read it... */
-       if (bitmap->file)
-               bitmap->sb_page = read_page(bitmap->file, 0, bitmap, PAGE_SIZE);
-       else {
+       if (bitmap->file) {
+               loff_t isize = i_size_read(bitmap->file->f_mapping->host);
+               int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
+
+               bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes);
+       } else {
                bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 0);
        }
        if (IS_ERR(bitmap->sb_page)) {
@@ -663,7 +666,7 @@ static void bitmap_file_put(struct bitmap *bitmap)
 
        if (file) {
                struct inode *inode = file->f_path.dentry->d_inode;
-               invalidate_inode_pages(inode->i_mapping);
+               invalidate_mapping_pages(inode->i_mapping, 0, -1);
                fput(file);
        }
 }
@@ -877,7 +880,8 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
                        int count;
                        /* unmap the old page, we're done with it */
                        if (index == num_pages-1)
-                               count = bytes - index * PAGE_SIZE;
+                               count = bytes + sizeof(bitmap_super_t)
+                                       - index * PAGE_SIZE;
                        else
                                count = PAGE_SIZE;
                        if (index == 0) {
@@ -1156,6 +1160,22 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
                        return 0;
                }
 
+               if (unlikely((*bmc & COUNTER_MAX) == COUNTER_MAX)) {
+                       DEFINE_WAIT(__wait);
+                       /* note that it is safe to do the prepare_to_wait
+                        * after the test as long as we do it before dropping
+                        * the spinlock.
+                        */
+                       prepare_to_wait(&bitmap->overflow_wait, &__wait,
+                                       TASK_UNINTERRUPTIBLE);
+                       spin_unlock_irq(&bitmap->lock);
+                       bitmap->mddev->queue
+                               ->unplug_fn(bitmap->mddev->queue);
+                       schedule();
+                       finish_wait(&bitmap->overflow_wait, &__wait);
+                       continue;
+               }
+
                switch(*bmc) {
                case 0:
                        bitmap_file_set_bit(bitmap, offset);
@@ -1165,7 +1185,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
                case 1:
                        *bmc = 2;
                }
-               BUG_ON((*bmc & COUNTER_MAX) == COUNTER_MAX);
+
                (*bmc)++;
 
                spin_unlock_irq(&bitmap->lock);
@@ -1203,6 +1223,9 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
                if (!success && ! (*bmc & NEEDED_MASK))
                        *bmc |= NEEDED_MASK;
 
+               if ((*bmc & COUNTER_MAX) == COUNTER_MAX)
+                       wake_up(&bitmap->overflow_wait);
+
                (*bmc)--;
                if (*bmc <= 2) {
                        set_page_attr(bitmap,
@@ -1427,6 +1450,7 @@ int bitmap_create(mddev_t *mddev)
        spin_lock_init(&bitmap->lock);
        atomic_set(&bitmap->pending_writes, 0);
        init_waitqueue_head(&bitmap->write_wait);
+       init_waitqueue_head(&bitmap->overflow_wait);
 
        bitmap->mddev = mddev;