@@ -6090,7 +6090,8 @@ static int btrfs_cmp_devid(const void *a, const void *b)
6090
6090
* The calculated stripe index is then used to select the corresponding device
6091
6091
* from the list of devices, which is ordered by devid.
6092
6092
*/
6093
- static int btrfs_read_rr (struct btrfs_chunk_map * map , int first , int num_stripe )
6093
+ static int btrfs_read_rr (struct btrfs_chunk_map * map , int first , int num_stripes ,
6094
+ u64 min_latency )
6094
6095
{
6095
6096
struct stripe_mirror stripes [BTRFS_RAID1_MAX_MIRRORS ] = {0 };
6096
6097
struct btrfs_device * device = map -> stripes [first ].dev ;
@@ -6106,11 +6107,34 @@ static int btrfs_read_rr(struct btrfs_chunk_map *map, int first, int num_stripe)
6106
6107
fs_info -> sectorsize_bits ;
6107
6108
6108
6109
index = 0 ;
6109
- for (int i = first ; i < first + num_stripe ; i ++ ) {
6110
+ for (int i = first ; i < first + num_stripes ; i ++ ) {
6111
+ if (min_latency > 0 ) {
6112
+ u64 read_wait ;
6113
+ u64 avg_wait = 0 ;
6114
+ unsigned long read_ios ;
6115
+ struct btrfs_device * device = map -> stripes [index ].dev ;
6116
+
6117
+ read_wait = part_stat_read (device -> bdev , nsecs [READ ]);
6118
+ read_ios = part_stat_read (device -> bdev , ios [READ ]);
6119
+
6120
+ if (read_wait && read_ios && read_wait >= read_ios )
6121
+ avg_wait = div_u64 (read_wait , read_ios );
6122
+
6123
+ if (min_latency < avg_wait )
6124
+ continue ;
6125
+ }
6126
+
6110
6127
stripes [index ].devid = map -> stripes [i ].dev -> devid ;
6111
6128
stripes [index ].num = i ;
6112
6129
index ++ ;
6113
6130
}
6131
+
6132
+ /* if the caller passed a minimum latency and we filtered for no
6133
+ * stripes, return -1 to indicate that no stripe qualified.
6134
+ */
6135
+ if (min_latency && !index )
6136
+ return -1 ;
6137
+
6114
6138
sort (stripes , index , sizeof (struct stripe_mirror ),
6115
6139
btrfs_cmp_devid , NULL );
6116
6140
@@ -6152,7 +6176,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
6152
6176
break ;
6153
6177
#ifdef CONFIG_BTRFS_EXPERIMENTAL
6154
6178
case BTRFS_READ_POLICY_RR :
6155
- preferred_mirror = btrfs_read_rr (map , first , num_stripes );
6179
+ preferred_mirror = btrfs_read_rr (map , first , num_stripes , 0 );
6156
6180
break ;
6157
6181
case BTRFS_READ_POLICY_DEVID :
6158
6182
preferred_mirror = btrfs_read_preferred (map , first , num_stripes );
0 commit comments