super.c (d5178578bcd461cc79118c7a139882350fe505aa) super.c (4f080f571192b0347f45b5709a291af473824484)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
4 */
5
6#include <linux/blkdev.h>
7#include <linux/module.h>
8#include <linux/fs.h>

--- 1890 unchanged lines hidden (view full) ---

1899 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
1900 struct btrfs_device *device;
1901 u64 skip_space;
1902 u64 type;
1903 u64 avail_space;
1904 u64 min_stripe_size;
1905 int min_stripes = 1, num_stripes = 1;
1906 int i = 0, nr_devices;
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
4 */
5
6#include <linux/blkdev.h>
7#include <linux/module.h>
8#include <linux/fs.h>

--- 1890 unchanged lines hidden (view full) ---

1899 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
1900 struct btrfs_device *device;
1901 u64 skip_space;
1902 u64 type;
1903 u64 avail_space;
1904 u64 min_stripe_size;
1905 int min_stripes = 1, num_stripes = 1;
1906 int i = 0, nr_devices;
1907 const struct btrfs_raid_attr *rattr;
1907
1908 /*
1909 * We aren't under the device list lock, so this is racy-ish, but good
1910 * enough for our purposes.
1911 */
1912 nr_devices = fs_info->fs_devices->open_devices;
1913 if (!nr_devices) {
1914 smp_mb();

--- 7 unchanged lines hidden (view full) ---

1922
1923 devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
1924 GFP_KERNEL);
1925 if (!devices_info)
1926 return -ENOMEM;
1927
1928 /* calc min stripe number for data space allocation */
1929 type = btrfs_data_alloc_profile(fs_info);
1908
1909 /*
1910 * We aren't under the device list lock, so this is racy-ish, but good
1911 * enough for our purposes.
1912 */
1913 nr_devices = fs_info->fs_devices->open_devices;
1914 if (!nr_devices) {
1915 smp_mb();

--- 7 unchanged lines hidden (view full) ---

1923
1924 devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
1925 GFP_KERNEL);
1926 if (!devices_info)
1927 return -ENOMEM;
1928
1929 /* calc min stripe number for data space allocation */
1930 type = btrfs_data_alloc_profile(fs_info);
1931 rattr = &btrfs_raid_array[btrfs_bg_flags_to_raid_index(type)];
1932
1930 if (type & BTRFS_BLOCK_GROUP_RAID0) {
1931 min_stripes = 2;
1932 num_stripes = nr_devices;
1933 } else if (type & BTRFS_BLOCK_GROUP_RAID1) {
1934 min_stripes = 2;
1935 num_stripes = 2;
1936 } else if (type & BTRFS_BLOCK_GROUP_RAID10) {
1937 min_stripes = 4;
1938 num_stripes = 4;
1939 }
1940
1933 if (type & BTRFS_BLOCK_GROUP_RAID0) {
1934 min_stripes = 2;
1935 num_stripes = nr_devices;
1936 } else if (type & BTRFS_BLOCK_GROUP_RAID1) {
1937 min_stripes = 2;
1938 num_stripes = 2;
1939 } else if (type & BTRFS_BLOCK_GROUP_RAID10) {
1940 min_stripes = 4;
1941 num_stripes = 4;
1942 }
1943
1941 if (type & BTRFS_BLOCK_GROUP_DUP)
1942 min_stripe_size = 2 * BTRFS_STRIPE_LEN;
1943 else
1944 min_stripe_size = BTRFS_STRIPE_LEN;
1944 /* Adjust for more than 1 stripe per device */
1945 min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN;
1945
1946 rcu_read_lock();
1947 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
1948 if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
1949 &device->dev_state) ||
1950 !device->bdev ||
1951 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
1952 continue;

--- 515 unchanged lines hidden ---
1946
1947 rcu_read_lock();
1948 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
1949 if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
1950 &device->dev_state) ||
1951 !device->bdev ||
1952 test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
1953 continue;

--- 515 unchanged lines hidden ---