From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E124C77B73 for ; Tue, 30 May 2023 11:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbjE3LmM (ORCPT ); Tue, 30 May 2023 07:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232026AbjE3Llz (ORCPT ); Tue, 30 May 2023 07:41:55 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEDF7180; Tue, 30 May 2023 04:41:50 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7A14E1F8B9; Tue, 30 May 2023 11:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685446909; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oNkvyNSd6Gfbh+iwH/YENF6xAIahzjc7Hs/dYYi9deo=; b=xpd3sC6RR6kU3o+umSclYiwAFJjQx7Xjq15U4MxefiLS1Djr47vdhCFNVBdDm681EvHLV2 9LHRp321nEfc0At1HI7+MfdBtgXNmsm/1moxpg+fKNJ5d611MketQZUDh7REJa5w0gqQ4w dKZZC7r2yorXr78gYtl3LX5pyJEdQYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685446909; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oNkvyNSd6Gfbh+iwH/YENF6xAIahzjc7Hs/dYYi9deo=; b=PKIa1ZJciElQ0VLmcrPRG1c8/ltJcnLgwms06I1FJaHnSa8HnALE5RyxTd9A7RfB6gxikd Fk8Tdw/m+mlQD9AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 58A9213597; Tue, 30 May 2023 11:41:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JMMsFf3gdWT+AgAAMHmgww (envelope-from ); Tue, 30 May 2023 11:41:49 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id DA200A0754; Tue, 30 May 2023 13:41:48 +0200 (CEST) Date: Tue, 30 May 2023 13:41:48 +0200 From: Jan Kara To: Christoph Hellwig Cc: Jens Axboe , Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: [PATCH 02/13] block: refactor bd_may_claim Message-ID: <20230530114148.zobtxdurit24pqev@quack3> References: <20230518042323.663189-1-hch@lst.de> <20230518042323.663189-3-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230518042323.663189-3-hch@lst.de> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu 18-05-23 06:23:11, Christoph Hellwig wrote: > The long if/else chain obsfucates the actual logic. Tidy it up to be > more structured. Also drop the whole argument, as it can be trivially > derived from bdev using bdev_whole, and having the bdev_whole in the > function makes it easier to follow. > > Signed-off-by: Christoph Hellwig Looks good to me. Just one nit below but regardless of how you decided feel free to add: Reviewed-by: Jan Kara > +static bool bd_may_claim(struct block_device *bdev, void *holder) > { > - if (bdev->bd_holder == holder) > - return true; /* already a holder */ > - else if (bdev->bd_holder != NULL) > - return false; /* held by someone else */ > - else if (whole == bdev) > - return true; /* is a whole device which isn't held */ > - > - else if (whole->bd_holder == bd_may_claim) > - return true; /* is a partition of a device that is being partitioned */ > - else if (whole->bd_holder != NULL) > - return false; /* is a partition of a held device */ > - else > - return true; /* is a partition of an un-held device */ > + struct block_device *whole = bdev_whole(bdev); > + > + if (bdev->bd_holder) { > + /* > + * The same holder can always re-claim. > + */ > + if (bdev->bd_holder == holder) > + return true; > + return false; With this simple condition I'd just do: /* The same holder can always re-claim. */ return bdev->bd_holder == holder; Honza -- Jan Kara SUSE Labs, CR