On Fri, Feb 12, 2021 at 06:26:41PM +0000, Michal Rostecki wrote: > On Wed, Feb 10, 2021 at 05:08:05AM +0100, Michał Mirosław wrote: > > On Tue, Feb 09, 2021 at 09:30:38PM +0100, Michal Rostecki wrote: > > > From: Michal Rostecki <mroste...@suse.com> > > > > > > Add the btrfs_check_mixed() function which checks if the filesystem has > > > the mixed type of devices (non-rotational and rotational). This > > > information is going to be used in roundrobin raid1 read policy.a > > [...] > > > @@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct > > > btrfs_fs_devices *fs_devices, > > > } > > > > > > q = bdev_get_queue(bdev); > > > - if (!blk_queue_nonrot(q)) > > > + rotating = !blk_queue_nonrot(q); > > > + device->rotating = rotating; > > > + if (rotating) > > > fs_devices->rotating = true; > > > + if (!fs_devices->mixed) > > > + fs_devices->mixed = btrfs_check_mixed(fs_devices, rotating); > > [...] > > > > Since this is adding to a set, a faster way is: > > > > if (fs_devices->rotating != rotating) > > fs_devices->mixed = true; > > > > The scan might be necessary on device removal, though. > Actually, that's not going to work in case of appenging a rotational > device when all previous devices are non-rotational. [...] > Inverting the order of those `if` checks would break the other > permuitations which start with rotational disks.
But not if you would add: if (adding first device) fs_devices->rotating = rotating; before the checks. But them, there is a simpler way: count how many rotating vs non-rotating devices there are while adding them. Like: rotating ? ++n_rotating : ++n_fixed; And then on remove you'd have it covered. Best Regards Michał Mirosław