Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4986450pxb; Mon, 15 Feb 2021 06:42:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0xyw5GzUdml0kB3ScIkNzt+nBsLRI6d0noCg1m2LvZXE9zQK6EawrMGOZfQ/n0UchOWoE X-Received: by 2002:a17:906:d922:: with SMTP id rn2mr16275709ejb.414.1613400158811; Mon, 15 Feb 2021 06:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613400158; cv=none; d=google.com; s=arc-20160816; b=Aw6R2SxnVGelaKFTklHfvhMeqzWLjfTW7+CGu97IFFLZwG80/M5hqkiK9tyxK56i/N vmqlw5HvFw5LGOZMWUc9XTAfcFhIc2autc8qf4fq02rvHDJ1FqSv1Rcp1dmO2gezXXjl R8MsISOLVRNpYZpxBCRWICRSTURIgn6N2lWecDH4RfVhp+AqtTXJuxCDeBZeIJv5J7N9 R2K+s29NoA4aID1KSJrDInnGKpFFXB7bDUe3qli94+/y0DAsdC6NIEBURUizdHWSCaPW l87bPm4jElEvJYbEJBJsFQSFAr1snG3o3Fl49zxskY5IhMYNc4vvw/j4BPxWOTvGmBSr DmJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lnRexESqKOilvs5cscT6HZjmxSpQOehw1JGywODJI68=; b=C7YqHVHJWtEQ8FSz7gPxcWZM1ytQgUiaFLQ4neBMVagHCU3WGyMzR908kZGa/Jzrr5 v0CcLdXE69oHkvfNui0rrZCv5GFbH/IRUP/Clkp98NwOfnaFwvVGRTHXFUirt6KWJLks ajTlTDncncf9bdgtmulZc1T9c3lQK7YCuT91tfBmyIbq/6nwa773wZVUX8J3RFVyxy4H q1gk8Fxai9AlB258JOon3b8CyppT+QSX3RFmqx5gqD7Kqyp6UjPHhamvHxAUywEtyTQs 6H/p+l6ksAQPI2Ds4dN12hf3V56d8hEo62uzJ6jVl2w2zbHjEK0u2kwZAwqnHz65rNo5 wKZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p24si12696798edw.248.2021.02.15.06.42.15; Mon, 15 Feb 2021 06:42:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbhBOOli (ORCPT + 99 others); Mon, 15 Feb 2021 09:41:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:49828 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbhBOOlJ (ORCPT ); Mon, 15 Feb 2021 09:41:09 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 785F1AC69; Mon, 15 Feb 2021 14:40:27 +0000 (UTC) Date: Mon, 15 Feb 2021 14:40:26 +0000 From: Michal Rostecki To: =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Chris Mason , Josef Bacik , David Sterba , "open list:BTRFS FILE SYSTEM" , open list , Michal Rostecki Subject: Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices Message-ID: <20210215144026.GB21872@wotan.suse.de> References: <20210209203041.21493-1-mrostecki@suse.de> <20210209203041.21493-5-mrostecki@suse.de> <20210210040805.GB12086@qmqm.qmqm.pl> <20210212182641.GB20817@wotan.suse.de> <20210212233602.GA30441@qmqm.qmqm.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210212233602.GA30441@qmqm.qmqm.pl> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 13, 2021 at 12:36:02AM +0100, Michał Mirosław wrote: > 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 > > > > > > > > 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. I like the idea of storing numbers and simply checking them. I use it in v2 - though probably in a different form, and I will most likely move the whole logic around checking device types to separate functions, to not bloat btrfs_open_one_device() and the others too much.