Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2052580lqo; Mon, 13 May 2024 06:43:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWpMy8NTazaY0w/I0V3VZ7EjyCAFBBAzjoVCthax34sdcb2qWy8oF2D2Uc9blL9oiCMETcYdooN+oKK3Jgfm9eWfLeO00LFkxHOE0+ZAw== X-Google-Smtp-Source: AGHT+IHHpBNJLVRET/Doh7zj92SEcBa3Mq5RQkN/8nd6fDibP1/x84Q+xjnqRr/BULLBBjIoi6pv X-Received: by 2002:a17:906:3618:b0:a59:9c14:a774 with SMTP id a640c23a62f3a-a5a2d680d90mr636857566b.74.1715607792023; Mon, 13 May 2024 06:43:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715607792; cv=pass; d=google.com; s=arc-20160816; b=Vvg6WgohN2C0j0L8TM3PYfAH1Cpgrs5rOegzs3YMP9b8FuEf3L/UNinkNQjLztOI7F 4eE36MMRV6NGxy2ANRbjTYqbyery2Fq1WfV33mEu5/2dksrMOklkFD09Vqi1OpSrYoyC RtnubyqQpJr8667apM7g83ghik2rKwZjWDWbWSvTHSBvh6wxgO3pu/yxuv0Wgq5IS6Zk V8KhKvXx2RshvSAxbDuAhICmjAHX+ja46GGWxWsXJg4ZyPIuzjlWLRvuHr1hL0w11eZ/ cF8+38sTKP/F4QpvfOHxJUFzCUVyWSjiGmBEE9j7pLZd23SWkDl/L5HRFvtEB62D/ThB KYUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=aJ3/9uVi0I/ZwsAfox/LIaH1RxLHv69gQR1JBA2UvNg=; fh=YLiscq7i7YusbhIbjuQWJXnKgX0guoalbvuKGcFw/tg=; b=bJ5FDDHey7F4CV0qKIYrenp6VfXrlih0L3tr5w/PJdiMqNljYWg2MFwgTHQ92n1wjT 4RdI/NnJvxa9L1w7Q/ZYKbBwDanmq+GY7xJz7p4WfpQRuYIn2ycfRL+DsfFUkr3mR3CV 7Vp3j3XH/0SlVc0QYQt6T0/pWujz1tV77ywsRsEp6OjtgWxmG1bagmsObWI7IIZ1gIKD wP5FbI1tezVgtT6LSRtnMZFFRu0Yf4wgw3zx1xFJKRqSgNtxGIogicbFQGOkP1PD0n8e JNFs4QFGBeaA3tpuVmBQKnvbKVB2n3n92LmGVJHi5nkyqLeLCE3+K2+RaSjiv4vClL0v 9sig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dDMPWsDl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dDMPWsDl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-2485-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2485-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c3d9si510340666b.930.2024.05.13.06.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 06:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2485-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dDMPWsDl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dDMPWsDl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-2485-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2485-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 878E21F217D4 for ; Mon, 13 May 2024 13:43:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E69B15445C; Mon, 13 May 2024 13:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="dDMPWsDl"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="L5j6mNJH"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="dDMPWsDl"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="L5j6mNJH" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A049D15350C; Mon, 13 May 2024 13:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715607699; cv=none; b=SCJPqdinBoXbdyye+lTPaBCBydBzPsfvY39SC4gQYbWhuQFAtByygx5AuJ7fMwpVx/y378WTu5+gATGDiXEoZuaATK0kgYiEbEYTwej1YGJFvO9pQ62wZN7mDB2qfcwFoaa7xycJYhfNvKxp3mZGX+5Wp3kFgW67sc7RRZXCRxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715607699; c=relaxed/simple; bh=Sg+EICwdCUrjnHF/9vdyW64NLfEQouoxeJBc6xIQaaA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YFsnZxqwU1ISA0TfGOWvYVB47zPqhObBOiuA6MT+uh10EZohaD+kwhYajy6fIEoGJWFQplxIkD1gJ7U+zUUcLO2AV1h7/ll+lbn34qJy9IVqdiz2SfvXPBWZXs/P4JElLRV5Gbqft9yzAJJDW48b0kpvclTTdePK8LqBAK1bMGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=dDMPWsDl; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=L5j6mNJH; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=dDMPWsDl; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=L5j6mNJH; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BF83634A08; Mon, 13 May 2024 13:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1715607695; 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=aJ3/9uVi0I/ZwsAfox/LIaH1RxLHv69gQR1JBA2UvNg=; b=dDMPWsDlElO9ruRbKHh389gRH3FNkbMbCAt1FprJUKxFM4lFoZC1oe6QndHpiym6hOF/XM bm4W+YB4b2fRKMgYyK0HgL17cMkyUqzk6oN2Kf7bFOt7BarDZ6UXF7MAopufbWFhpUZV8S dWHgZ58cN5WBLTieRRMAsDWliQXtCkI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1715607695; 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=aJ3/9uVi0I/ZwsAfox/LIaH1RxLHv69gQR1JBA2UvNg=; b=L5j6mNJHaCyNNNNIQhUwTRimALIN2XjLtE+bAYu4JXsbKEI0jnytR/SkhZgEH394yXEvPj qUAEljumSxut1GDg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=dDMPWsDl; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=L5j6mNJH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1715607695; 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=aJ3/9uVi0I/ZwsAfox/LIaH1RxLHv69gQR1JBA2UvNg=; b=dDMPWsDlElO9ruRbKHh389gRH3FNkbMbCAt1FprJUKxFM4lFoZC1oe6QndHpiym6hOF/XM bm4W+YB4b2fRKMgYyK0HgL17cMkyUqzk6oN2Kf7bFOt7BarDZ6UXF7MAopufbWFhpUZV8S dWHgZ58cN5WBLTieRRMAsDWliQXtCkI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1715607695; 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=aJ3/9uVi0I/ZwsAfox/LIaH1RxLHv69gQR1JBA2UvNg=; b=L5j6mNJHaCyNNNNIQhUwTRimALIN2XjLtE+bAYu4JXsbKEI0jnytR/SkhZgEH394yXEvPj qUAEljumSxut1GDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 82F4E1372E; Mon, 13 May 2024 13:41:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id VFPxH48YQmZBDwAAD6G6ig (envelope-from ); Mon, 13 May 2024 13:41:35 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id BF009A090B; Sun, 12 May 2024 17:40:37 +0200 (CEST) Date: Sun, 12 May 2024 17:40:37 +0200 From: Jan Kara To: Zhang Yi Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH v3 08/10] ext4: factor out check for whether a cluster is allocated Message-ID: <20240512154037.x6icodkj2zmzeqtg@quack3> References: <20240508061220.967970-1-yi.zhang@huaweicloud.com> <20240508061220.967970-9-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240508061220.967970-9-yi.zhang@huaweicloud.com> X-Spam-Flag: NO X-Spam-Score: -2.51 X-Rspamd-Action: no action X-Rspamd-Queue-Id: BF83634A08 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-2.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; FREEMAIL_CC(0.00)[vger.kernel.org,mit.edu,dilger.ca,suse.cz,gmail.com,huawei.com]; RCPT_COUNT_SEVEN(0.00)[11]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_TRACE(0.00)[suse.cz:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:email,huawei.com:email,suse.cz:dkim] On Wed 08-05-24 14:12:18, Zhang Yi wrote: > From: Zhang Yi > > Factor out a common helper ext4_da_check_clu_allocated(), check whether > the cluster containing a delalloc block to be added has been delayed or > allocated, no logic changes. > > Signed-off-by: Zhang Yi I have one suggestion for improvement here. > +/* > + * Check whether the cluster containing lblk has been delayed or allocated, > + * if not, it means we should reserve a cluster when add delalloc, return 1, > + * otherwise return 0 or error code. > + */ > +static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, > + bool *allocated) The name of the function does not quite match what it is returning and that is confusing. Essentially we have three states here: a) cluster allocated b) cluster has delalloc reservation c) cluster doesn't have either So maybe we could call the function ext4_clu_alloc_state() and return 0 / 1 / 2 based on the state? Honza > +{ > + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); > + int ret; > + > + *allocated = false; > + if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) > + return 0; > + > + if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk)) > + goto allocated; > + > + ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk)); > + if (ret < 0) > + return ret; > + if (ret == 0) > + return 1; > +allocated: > + *allocated = true; > + return 0; > +} > + > /* > * ext4_insert_delayed_block - adds a delayed block to the extents status > * tree, incrementing the reserved cluster/block > @@ -1682,23 +1710,13 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) > if (ret != 0) /* ENOSPC */ > return ret; > } else { /* bigalloc */ > - if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { > - if (!ext4_es_scan_clu(inode, > - &ext4_es_is_mapped, lblk)) { > - ret = ext4_clu_mapped(inode, > - EXT4_B2C(sbi, lblk)); > - if (ret < 0) > - return ret; > - if (ret == 0) { > - ret = ext4_da_reserve_space(inode, 1); > - if (ret != 0) /* ENOSPC */ > - return ret; > - } else { > - allocated = true; > - } > - } else { > - allocated = true; > - } > + ret = ext4_da_check_clu_allocated(inode, lblk, &allocated); > + if (ret < 0) > + return ret; > + if (ret > 0) { > + ret = ext4_da_reserve_space(inode, 1); > + if (ret != 0) /* ENOSPC */ > + return ret; > } > } > > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR