btrfs: alloc_chunk: fix more DUP stripe size handling
[sfrench/cifs-2.6.git] / fs / btrfs / volumes.c
index 8c5ae9943d694ceeff3994a44eb169e348c855e0..252cc2ef98ee36e54a04e8f8f25fc90b19dcb893 100644 (file)
@@ -4794,19 +4794,17 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
        /*
         * Use the number of data stripes to figure out how big this chunk
         * is really going to be in terms of logical address space,
-        * and compare that answer with the max chunk size
+        * and compare that answer with the max chunk size. If it's higher,
+        * we try to reduce stripe_size.
         */
        if (stripe_size * data_stripes > max_chunk_size) {
-               stripe_size = div_u64(max_chunk_size, data_stripes);
-
-               /* bump the answer up to a 16MB boundary */
-               stripe_size = round_up(stripe_size, SZ_16M);
-
                /*
-                * But don't go higher than the limits we found while searching
-                * for free extents
+                * Reduce stripe_size, round it up to a 16MB boundary again and
+                * then use it, unless it ends up being even bigger than the
+                * previous value we had already.
                 */
-               stripe_size = min(devices_info[ndevs - 1].max_avail,
+               stripe_size = min(round_up(div_u64(max_chunk_size,
+                                                  data_stripes), SZ_16M),
                                  stripe_size);
        }