diff options
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r-- | fs/btrfs/super.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 0ac712efcdf2..32fe8b33cc1c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -913,6 +913,32 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) | |||
913 | return 0; | 913 | return 0; |
914 | } | 914 | } |
915 | 915 | ||
916 | /* Used to sort the devices by max_avail(descending sort) */ | ||
917 | static int btrfs_cmp_device_free_bytes(const void *dev_info1, | ||
918 | const void *dev_info2) | ||
919 | { | ||
920 | if (((struct btrfs_device_info *)dev_info1)->max_avail > | ||
921 | ((struct btrfs_device_info *)dev_info2)->max_avail) | ||
922 | return -1; | ||
923 | else if (((struct btrfs_device_info *)dev_info1)->max_avail < | ||
924 | ((struct btrfs_device_info *)dev_info2)->max_avail) | ||
925 | return 1; | ||
926 | else | ||
927 | return 0; | ||
928 | } | ||
929 | |||
930 | /* | ||
931 | * sort the devices by max_avail, in which max free extent size of each device | ||
932 | * is stored.(Descending Sort) | ||
933 | */ | ||
934 | static inline void btrfs_descending_sort_devices( | ||
935 | struct btrfs_device_info *devices, | ||
936 | size_t nr_devices) | ||
937 | { | ||
938 | sort(devices, nr_devices, sizeof(struct btrfs_device_info), | ||
939 | btrfs_cmp_device_free_bytes, NULL); | ||
940 | } | ||
941 | |||
916 | /* | 942 | /* |
917 | * The helper to calc the free space on the devices that can be used to store | 943 | * The helper to calc the free space on the devices that can be used to store |
918 | * file data. | 944 | * file data. |