Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp865469rdb; Fri, 9 Feb 2024 03:45:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUDRkeYbbHcIdrInhyS2j8K9HdQrNbbBEQOL5G38kAC7VWC9mbtCZHvVqlVQcJXFbgrkER X-Received: by 2002:a05:6870:8186:b0:218:c9c6:6cf9 with SMTP id k6-20020a056870818600b00218c9c66cf9mr1191957oae.28.1707479145674; Fri, 09 Feb 2024 03:45:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707479145; cv=pass; d=google.com; s=arc-20160816; b=ybXg2LipyonUCzmAsLHAhdCEWNVvbxaqzmfMSYGSZK52TVXMpf+NR4/apRKTz/ftXJ Cxyw48RokqYOcJBmM9STp7ehRA4Rk91ZYxK1bwiL+rnrIATfzWfp0zZZFiv8cKK4juiM 6fKPO6lZD11TElPTOIb6QcsWvSwsd2MxzCEQBO6a39SdC1G+nzQN4PZ+WMl1HZptFXGE bZiENrW6ZAwegdJsMfMyUfum5pQ+iQZ2oVslEhe+dImg7FvZFmO8jrLEYH9XiIHjonMh Bw3aGcsMhS7Pp333x+4kWh4N8pGekGySQBIxou8JFdHZ+Qso66u8t5+hod2b6+BLnqQn rAxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature; bh=gNrqiNAaZMWCvNANNKTPlOJbjUtw7A2fXJ/3W2rPMWw=; fh=d7TuOaiUsAKED1W8KtHP6pNYO8ZqT2cig7PY2Tmag/8=; b=UCLaNeTaync3oArza2rtYKsmRxKLQcg0wR57ZzZgx8tJijB+hszZu1lnoWKoa4HdQW VltKNrX32GLWu6OUm6W9aAVcFLtOt+zNR5lIZ52LcimCa2HnOx3KaTlT4GO1WoILi65k pOFLAn7OY2xuVrZKMvoSnX0vmo5QrQVzGc30cfm53/RToGtL5LGadmemjLMWzHfhqQlN LkJfae7rN8DgnhDJvOJUCKnSo2eW0+BqnjWy6mj4mi0tiL6D28nppFZQBPNiV47SXq9S q87f196xvcqZXgAOitzKRRzLIWNPAD8iRj6WnohOipRSbPuoLbvw/CeAn/yrRet6kV4I a1qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=S5rqwisB; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="w8PUnKa/"; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-1183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1183-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXkJJlDweYYmOgoD9kWO7MWbdp1ntRA5HhnXdOIHbGsWJXPrJY25djRNKrjWLzQ2EfEH1DFxUxqL0Nh6syTwywzUttCFwVxP5brtD4sJA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p17-20020a637411000000b005ced19e2d21si1587789pgc.676.2024.02.09.03.45.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 03:45:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=S5rqwisB; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="w8PUnKa/"; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-1183-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1183-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8829BB2A402 for ; Fri, 9 Feb 2024 11:23:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0C382E858; Fri, 9 Feb 2024 11:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="S5rqwisB"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="w8PUnKa/" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 B84B82D04F for ; Fri, 9 Feb 2024 11:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707477673; cv=none; b=DZqXYBEjU1YtA1rj6t+HIdfX44JTQ+q4py4QeuGnkhlN3W6iFjEFFLKDWyvUuMFnLueEQJbmWnZm8685Ckh9S95+3TOHqXHSvpY2dXpN/JHvqAD1YNzTxGzasO3pnw51aNKd+x2t0jfaFUE1O6aMnTAsB9xNA6u3F39GcjhWgrI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707477673; c=relaxed/simple; bh=QKsz8+4nVeQbBno3VOSz24JxTTH1VtojewFqvVVQ7ek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AG9HUEW3uAAki3/0amxsXZtZ4y4vUfT6PylO7CQKjYZhYKkRmQUC7QxA/AsEw6WLGyoM0H42Ccyz//CrPLTTTXOQ6kFZHLlUDGUvTRWYlua+UUqVFWz353VtCXjbarP7Ac5onAToNrswqKUs9bNM/7Ffj+/yOtUgjFSqmmWqqiI= 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=S5rqwisB; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=w8PUnKa/; arc=none smtp.client-ip=195.135.223.131 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-out2.suse.de (Postfix) with ESMTPS id D33EB1F7F9; Fri, 9 Feb 2024 11:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707477667; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gNrqiNAaZMWCvNANNKTPlOJbjUtw7A2fXJ/3W2rPMWw=; b=S5rqwisBgsFtNHcwRMP5Zg5GRJ/gyBWREuK7jNRGspjU6JE6lL69bwCZ/c+6xQ0wOeNE4s izJcyVVlWJ6qwQvBPECHh33s7Ze/FlGX5msZP6tPMslaJcSO5OzyjjlLeX2IrRWtDfRkSW Rr27mJY4Tc7fpdg8dI/xHXjGOAHbW74= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707477667; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gNrqiNAaZMWCvNANNKTPlOJbjUtw7A2fXJ/3W2rPMWw=; b=w8PUnKa/I2ae5M1MxrY5pJGatJBTncwpd2YTNosXHy9iJ70jI/OicdxG0a3X0KWxgVRlaB FnT5P9BeXbZ82iAA== 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 BB699139E7; Fri, 9 Feb 2024 11:21:07 +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 EDi7LaMKxmWcNQAAD6G6ig (envelope-from ); Fri, 09 Feb 2024 11:21:07 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 6F973A05C4; Fri, 9 Feb 2024 12:21:07 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 1/3] ext4: Fold quota accounting into ext4_xattr_inode_lookup_create() Date: Fri, 9 Feb 2024 12:20:59 +0100 Message-Id: <20240209112107.10585-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240209111418.22308-1-jack@suse.cz> References: <20240209111418.22308-1-jack@suse.cz> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3247; i=jack@suse.cz; h=from:subject; bh=QKsz8+4nVeQbBno3VOSz24JxTTH1VtojewFqvVVQ7ek=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBlxgqac55kL12p7NCMxxSulcKzF7ADQLTzretxdZOC nfs+IEKJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZcYKmgAKCRCcnaoHP2RA2b9TCA C/AAYpEJqDNOP0I1OxWVmRhy0cfNVHJI9RPWty8FKADxAyd+35YqwAB24fOmRr9uarLwsOjaRuzV4j aBDMynb3esRzDIWCFnFRtusKNQnqAAwFXo+EJH7as7C5QyBbtQ2Be08uEW1WTgF8ejr8zoIo9nh0gc Lz96AaIvvZ1f7H/DeqZV82QY3a5F40X6d43OsTC6Me8coiZs1DQTcYwgmABoPpwK0X/xfYWf/G7qzN LZxb2K/czv7NEoD+GkCCk/u3uAM9WDSO+0wgRimQYoG2a0MHLeb8IyLNuI+Vv66ck/Um73MGARVtp3 qQOtI+6f8dv17M87Ja+uoxq0wQDzBA X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: D33EB1F7F9 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO When allocating EA inode, quota accounting is done just before ext4_xattr_inode_lookup_create(). Logically these two operations belong together so just fold quota accounting into ext4_xattr_inode_lookup_create(). We also make ext4_xattr_inode_lookup_create() return the looked up / created inode to convert the function to a more standard calling convention. Signed-off-by: Jan Kara --- fs/ext4/xattr.c | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 82dc5e673d5c..146690c10c73 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1565,46 +1565,49 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value, /* * Add value of the EA in an inode. */ -static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode, - const void *value, size_t value_len, - struct inode **ret_inode) +static struct inode *ext4_xattr_inode_lookup_create(handle_t *handle, + struct inode *inode, const void *value, size_t value_len) { struct inode *ea_inode; u32 hash; int err; + /* Account inode & space to quota even if sharing... */ + err = ext4_xattr_inode_alloc_quota(inode, value_len); + if (err) + return ERR_PTR(err); + hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len); ea_inode = ext4_xattr_inode_cache_find(inode, value, value_len, hash); if (ea_inode) { err = ext4_xattr_inode_inc_ref(handle, ea_inode); - if (err) { - iput(ea_inode); - return err; - } - - *ret_inode = ea_inode; - return 0; + if (err) + goto out_err; + return ea_inode; } /* Create an inode for the EA value */ ea_inode = ext4_xattr_inode_create(handle, inode, hash); - if (IS_ERR(ea_inode)) - return PTR_ERR(ea_inode); + if (IS_ERR(ea_inode)) { + ext4_xattr_inode_free_quota(inode, NULL, value_len); + return ea_inode; + } err = ext4_xattr_inode_write(handle, ea_inode, value, value_len); if (err) { if (ext4_xattr_inode_dec_ref(handle, ea_inode)) ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err); - iput(ea_inode); - return err; + goto out_err; } if (EA_INODE_CACHE(inode)) mb_cache_entry_create(EA_INODE_CACHE(inode), GFP_NOFS, hash, ea_inode->i_ino, true /* reusable */); - - *ret_inode = ea_inode; - return 0; + return ea_inode; +out_err: + iput(ea_inode); + ext4_xattr_inode_free_quota(inode, NULL, value_len); + return ERR_PTR(err); } /* @@ -1712,16 +1715,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, if (i->value && in_inode) { WARN_ON_ONCE(!i->value_len); - ret = ext4_xattr_inode_alloc_quota(inode, i->value_len); - if (ret) - goto out; - - ret = ext4_xattr_inode_lookup_create(handle, inode, i->value, - i->value_len, - &new_ea_inode); - if (ret) { + new_ea_inode = ext4_xattr_inode_lookup_create(handle, inode, + i->value, i->value_len); + if (IS_ERR(new_ea_inode)) { + ret = PTR_ERR(new_ea_inode); new_ea_inode = NULL; - ext4_xattr_inode_free_quota(inode, NULL, i->value_len); goto out; } } -- 2.35.3