Merge tag 'md/4.2-fixes' of git://neil.brown.name/md
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Jul 2015 18:24:58 +0000 (11:24 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Jul 2015 18:24:58 +0000 (11:24 -0700)
Pull md fixes from Neil Brown:
 "Some md fixes for 4.2

  Several are tagged for -stable.
  A few aren't because they are not very, serious or because they are in
  the 'experimental' cluster code"

* tag 'md/4.2-fixes' of git://neil.brown.name/md:
  md/raid5: clear R5_NeedReplace when no longer needed.
  Fix read-balancing during node failure
  md-cluster: fix bitmap sub-offset in bitmap_read_sb
  md: Return error if request_module fails and returns positive value
  md: Skip cluster setup in case of error while reading bitmap
  md/raid1: fix test for 'was read error from last working device'.
  md: Skip cluster setup for dm-raid
  md: flush ->event_work before stopping array.
  md/raid10: always set reshape_safe when initializing reshape_position.
  md/raid5: avoid races when changing cache size.

1  2 
drivers/md/bitmap.c
drivers/md/md.c

diff --combined drivers/md/bitmap.c
index ed2346ddf4c9fb54dafeb92ae9c795a0584444e8,1b9c2df718c6d80ad3e27145dbce4a0af1edc636..e51de52eeb94f71c9d6712a61d31e49f8e6f2f60
@@@ -494,7 -494,7 +494,7 @@@ static int bitmap_new_disk_sb(struct bi
        bitmap_super_t *sb;
        unsigned long chunksize, daemon_sleep, write_behind;
  
-       bitmap->storage.sb_page = alloc_page(GFP_KERNEL);
+       bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
        if (bitmap->storage.sb_page == NULL)
                return -ENOMEM;
        bitmap->storage.sb_page->index = 0;
        sb->state = cpu_to_le32(bitmap->flags);
        bitmap->events_cleared = bitmap->mddev->events;
        sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
+       bitmap->mddev->bitmap_info.nodes = 0;
  
        kunmap_atomic(sb);
  
@@@ -558,6 -559,7 +559,7 @@@ static int bitmap_read_sb(struct bitma
        unsigned long sectors_reserved = 0;
        int err = -EINVAL;
        struct page *sb_page;
+       loff_t offset = bitmap->mddev->bitmap_info.offset;
  
        if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) {
                chunksize = 128 * 1024 * 1024;
@@@ -584,9 -586,9 +586,9 @@@ re_read
                bm_blocks = ((bm_blocks+7) >> 3) + sizeof(bitmap_super_t);
                /* to 4k blocks */
                bm_blocks = DIV_ROUND_UP_SECTOR_T(bm_blocks, 4096);
-               bitmap->mddev->bitmap_info.offset += bitmap->cluster_slot * (bm_blocks << 3);
+               offset = bitmap->mddev->bitmap_info.offset + (bitmap->cluster_slot * (bm_blocks << 3));
                pr_info("%s:%d bm slot: %d offset: %llu\n", __func__, __LINE__,
-                       bitmap->cluster_slot, (unsigned long long)bitmap->mddev->bitmap_info.offset);
+                       bitmap->cluster_slot, offset);
        }
  
        if (bitmap->storage.file) {
                                bitmap, bytes, sb_page);
        } else {
                err = read_sb_page(bitmap->mddev,
-                                  bitmap->mddev->bitmap_info.offset,
+                                  offset,
                                   sb_page,
                                   0, sizeof(bitmap_super_t));
        }
        daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ;
        write_behind = le32_to_cpu(sb->write_behind);
        sectors_reserved = le32_to_cpu(sb->sectors_reserved);
-       nodes = le32_to_cpu(sb->nodes);
-       strlcpy(bitmap->mddev->bitmap_info.cluster_name, sb->cluster_name, 64);
+       /* XXX: This is a hack to ensure that we don't use clustering
+        *  in case:
+        *      - dm-raid is in use and
+        *      - the nodes written in bitmap_sb is erroneous.
+        */
+       if (!bitmap->mddev->sync_super) {
+               nodes = le32_to_cpu(sb->nodes);
+               strlcpy(bitmap->mddev->bitmap_info.cluster_name,
+                               sb->cluster_name, 64);
+       }
  
        /* verify that the bitmap-specific fields are valid */
        if (sb->magic != cpu_to_le32(BITMAP_MAGIC))
@@@ -671,7 -681,7 +681,7 @@@ out
        kunmap_atomic(sb);
        /* Assiging chunksize is required for "re_read" */
        bitmap->mddev->bitmap_info.chunksize = chunksize;
-       if (nodes && (bitmap->cluster_slot < 0)) {
+       if (err == 0 && nodes && (bitmap->cluster_slot < 0)) {
                err = md_setup_cluster(bitmap->mddev, nodes);
                if (err) {
                        pr_err("%s: Could not setup cluster service (%d)\n",
@@@ -839,7 -849,7 +849,7 @@@ static void bitmap_file_kick(struct bit
                if (bitmap->storage.file) {
                        path = kmalloc(PAGE_SIZE, GFP_KERNEL);
                        if (path)
 -                              ptr = d_path(&bitmap->storage.file->f_path,
 +                              ptr = file_path(bitmap->storage.file,
                                             path, PAGE_SIZE);
  
                        printk(KERN_ALERT
@@@ -1866,10 -1876,6 +1876,6 @@@ int bitmap_copy_from_slot(struct mddev 
        if (IS_ERR(bitmap))
                return PTR_ERR(bitmap);
  
-       rv = bitmap_read_sb(bitmap);
-       if (rv)
-               goto err;
        rv = bitmap_init_from_disk(bitmap, 0);
        if (rv)
                goto err;
@@@ -1927,7 -1933,7 +1933,7 @@@ void bitmap_status(struct seq_file *seq
                   chunk_kb ? "KB" : "B");
        if (bitmap->storage.file) {
                seq_printf(seq, ", file: ");
 -              seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
 +              seq_file_path(seq, bitmap->storage.file, " \t\n");
        }
  
        seq_printf(seq, "\n");
diff --combined drivers/md/md.c
index d429c30cd51471c26cb1c07cb3e6a413106133d4,0fcf6de2415ad1a2e510049c82955ba171228d91..0c2a4e8b873c659dbc260b2aa5484c7a5e87b176
@@@ -5382,6 -5382,8 +5382,8 @@@ static void __md_stop(struct mddev *mdd
  {
        struct md_personality *pers = mddev->pers;
        mddev_detach(mddev);
+       /* Ensure ->event_work is done */
+       flush_workqueue(md_misc_wq);
        spin_lock(&mddev->lock);
        mddev->ready = 0;
        mddev->pers = NULL;
@@@ -5766,7 -5768,7 +5768,7 @@@ static int get_bitmap_file(struct mdde
        /* bitmap disabled, zero the first byte and copy out */
        if (!mddev->bitmap_info.file)
                file->pathname[0] = '\0';
 -      else if ((ptr = d_path(&mddev->bitmap_info.file->f_path,
 +      else if ((ptr = file_path(mddev->bitmap_info.file,
                               file->pathname, sizeof(file->pathname))),
                 IS_ERR(ptr))
                err = PTR_ERR(ptr);
@@@ -7437,7 -7439,7 +7439,7 @@@ int md_setup_cluster(struct mddev *mdde
        err = request_module("md-cluster");
        if (err) {
                pr_err("md-cluster module not found.\n");
-               return err;
+               return -ENOENT;
        }
  
        spin_lock(&pers_lock);