From patchwork Wed Feb 19 11:43:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13981996 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4EBB1DFE10 for ; Wed, 19 Feb 2025 11:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965411; cv=none; b=rdLkBgoJvcxp/YAXyJxD+aIjxa0ts9zzmR+SlMmrmYYecTcCcjd9F5/ylJkTki0l79PpeLrf5YtpfswKfulye2wyMgq1mOC1VQCNO6K9jzEv1FVtNTKvZWJVm+RcYNnbhAuUkU9VlbBvruJOQo9iVZyfycwZoKk1pToye9Y5ud0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965411; c=relaxed/simple; bh=SFoXfHCjtGJFKLXsvz0msUIJ3NMfNEF9czHWurNCZcY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Epi67D60yxwPblUiox+GXuG8IO1jmbGUgiaL8JiZ/qSsbQo6uRlEBvaWL0VAB3tHi54JMDoAqqbvx6UcYjfAZWC0PP0/uyFuhQGtR0/njbHd4xUaOQdV1AWp73nnXLUEMbxavbZQvVt9+0S/daMnXoHs1Dam/qfyiEfgnu8FmSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k7OaDpYC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k7OaDpYC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C550FC4CEE7 for ; Wed, 19 Feb 2025 11:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965411; bh=SFoXfHCjtGJFKLXsvz0msUIJ3NMfNEF9czHWurNCZcY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=k7OaDpYCQ77/i7ElalthN9hf8yKbQEwM7PNP0FugpxLROtz0G26MZoDk22jit6R8H F5Y161/LT2XVm+FjGKYB39lVGQ6FpTpjFiXr9u60csRG+VVsDyOLTokwn8ad6SHzKc +LeKIaH6emwCrp5zv0+6lKf8lEZx6pCJ8VUeI8F3XAyHPmxYUkjpJ00H4GFBZMFrXh OgLHqIwZyz0ef2l4OPWr+ennDXqtlJ10KKKOuGp4kMjtYCQmI9pe7UCt4SAs76L/a/ hV80cG7FTudNSZ+/10phNB9eKsKo9l9OOjObNt4kCYrlmMPkC9s+7qXpvC+37bGYUy atZ8DmkVfLz9g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/26] btrfs: send: remove duplicated logic from fs_path_reset() Date: Wed, 19 Feb 2025 11:43:01 +0000 Message-Id: <47d18790786cbf47aa764a45222e3a92e2c4da81.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There's duplicated logic in both branches of the if statement, so move it outside the branches. This also reduces the object code size. Before this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1746279 163600 16920 1926799 1d668f fs/btrfs/btrfs.ko After this change: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 1746047 163592 16920 1926559 1d659f fs/btrfs/btrfs.ko Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index d513f7fd5fe8..8de561fb1390 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -424,15 +424,13 @@ static int need_send_hole(struct send_ctx *sctx) static void fs_path_reset(struct fs_path *p) { - if (p->reversed) { + if (p->reversed) p->start = p->buf + p->buf_len - 1; - p->end = p->start; - *p->start = 0; - } else { + else p->start = p->buf; - p->end = p->start; - *p->start = 0; - } + + p->end = p->start; + *p->start = 0; } static struct fs_path *fs_path_alloc(void) From patchwork Wed Feb 19 11:43:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13981997 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEB721DFE32 for ; Wed, 19 Feb 2025 11:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965412; cv=none; b=F85a3n7wYifCKBwrcY9a/4hy/bdV4Htj9W/CNE6H7r4br6UeBh1hjoQC4cfZasQ1OBUG6W9cy7xCsSXXF50F3XQ+qZkL6mqcMDPkLBrs0KnUp8DufHPB+qxZraQSColvcLpjYzYERq4iV4HuxJgPR2tn3eR86vdRIwtvgo3pRh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965412; c=relaxed/simple; bh=VElW5lz5SNietu+keLp8sG3SfJrkP00ZTihTb1ozIFI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E3jjwOfnFRNC0QiXXJMEprKIKqPM7AZfaY8BnuPEP8jfbqvGZKUxVONKSd0Hte3uSTZQNiQ28hkmpXXq7rM9Ip8P8dAhFvedpynX1EDuX4caE/ClwzLYqY3pUDL2xmJS27UmkiUMry++p26MGWzHjTOleyoARSBHkcskOC4GIcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pgBknuyF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pgBknuyF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB027C4CED1 for ; Wed, 19 Feb 2025 11:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965412; bh=VElW5lz5SNietu+keLp8sG3SfJrkP00ZTihTb1ozIFI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pgBknuyF9yV9DokWlrUcHrXHGCS02ZCt2cJv9U1cI4Mx2ueW+7EgXEn578QW/h5y5 JjK1jvHXECI3lU3xKAV7BrgwnJ2ug9VTZzUnJHQJIA8wmUpECapi8Gu73pbapNChGV OaY04y/pU/iVBIZ6OEdk1hDfXGZJhYB0sGlIqK+UpZU7ZtiDhPMM1FqEU96ABJ2Por rJxlHIWiDPAyfAUUa9MHE6slJv5VDxb8WVWjWLed7jAXkw441yQgCornL4lyOv/wMd 1QW0aXNcUGym8CP3YMYCqSaZSFB+23ePBecEpe3vmrRQDKrYjcM8X5HQjW9HbzZEEZ seLKjJ+fKuoHA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/26] btrfs: send: make fs_path_len() inline and constify its argument Date: Wed, 19 Feb 2025 11:43:02 +0000 Message-Id: <8f82f33481d50f8381a6c29ae0966982d3a7bc1d.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The helper function fs_path_len() is trivial and doesn't need to change its path argument, so make it inline and constify the argument. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 8de561fb1390..4e998bf8d379 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -468,7 +468,7 @@ static void fs_path_free(struct fs_path *p) kfree(p); } -static int fs_path_len(struct fs_path *p) +static inline int fs_path_len(const struct fs_path *p) { return p->end - p->start; } From patchwork Wed Feb 19 11:43:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13981998 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A861E0084 for ; Wed, 19 Feb 2025 11:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965413; cv=none; b=l2FCLZe4EzHlrMH7WBRW1PgE1N6yKuInKt+ME4p8tRU4AmN1xwVZzU8fI8v6tVA6vEYcTv88PdH3BU42XvzAW1XBaCgP8pRpYJuGaisFgGoWGv3LlHZgmxjVKKdIj3TzJWERwgGvu55ch6RExSB0XeVkgkk/pilI2vbj6AR0Zw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965413; c=relaxed/simple; bh=qw0g4x9hg7TAw+pEdZ+odymNejfMhtMSkua0gV5gkeQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AHcfbOo1AAp3+oN/yzb2KXGZh0oUVUVEmK/Ad/kvsDI/cWb7gs633ac6pVPdZ3r2iJXOo/I6gCWgtRPliAntNZC1kquss6nd+Hsep/JZzr0p8cyN+7ELdomqhEL3IOJw16LuSr3VcxC2lZi475qK23bjp/zzooQRD2Q4tL99E8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pAgTj/3i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pAgTj/3i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D94F5C4CEE6 for ; Wed, 19 Feb 2025 11:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965413; bh=qw0g4x9hg7TAw+pEdZ+odymNejfMhtMSkua0gV5gkeQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pAgTj/3ibamuvdFVRl1JKA507gLVv6hK/YGx/gzN1CD3ac+GAq9iuUAEvFbcHoZRg ymUFX5CMX4Lcra6L6jVFRrGOtyGagJ+kPWxiGtpSiTkklN0JpOQJ6Mgl6U9f3XnE38 WeoiyViv8HMFopk+mmNczrds16soCtTrIr+/3ZM9eAH3S0SBA523SK5q42laMWTZSd +iPhaP0jz/6JXJqxZHytgqV2Gz+0aKQGFL+VY74dvC2cdAEkB9hi63sp7yp5A0Gk3Z lYlK7mbgty7vDqEQnGsUpcAkNc6uLgWjazEMTYX4G7xAEVz97PU0oc1BUdt/E/aBjQ lnMH+loZmuIbg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/26] btrfs: send: always use fs_path_len() to determine a path's length Date: Wed, 19 Feb 2025 11:43:03 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Several places are hardcoding the path length calculation instead of using the helper fs_path_len() for that. Update all those places to instead use fs_path_len(). Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 4e998bf8d379..9f9885dc1e10 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -489,7 +489,7 @@ static int fs_path_ensure_buf(struct fs_path *p, int len) return -ENOMEM; } - path_len = p->end - p->start; + path_len = fs_path_len(p); old_buf_len = p->buf_len; /* @@ -530,7 +530,7 @@ static int fs_path_prepare_for_add(struct fs_path *p, int name_len, int ret; int new_len; - new_len = p->end - p->start + name_len; + new_len = fs_path_len(p) + name_len; if (p->start != p->end) new_len++; ret = fs_path_ensure_buf(p, new_len); @@ -571,12 +571,13 @@ static int fs_path_add(struct fs_path *p, const char *name, int name_len) static int fs_path_add_path(struct fs_path *p, struct fs_path *p2) { int ret; + const int p2_len = fs_path_len(p2); char *prepared; - ret = fs_path_prepare_for_add(p, p2->end - p2->start, &prepared); + ret = fs_path_prepare_for_add(p, p2_len, &prepared); if (ret < 0) goto out; - memcpy(prepared, p2->start, p2->end - p2->start); + memcpy(prepared, p2->start, p2_len); out: return ret; @@ -616,7 +617,7 @@ static void fs_path_unreverse(struct fs_path *p) return; tmp = p->start; - len = p->end - p->start; + len = fs_path_len(p); p->start = p->buf; p->end = p->start + len; memmove(p->start, tmp, len + 1); @@ -737,7 +738,7 @@ static int tlv_put_btrfs_timespec(struct send_ctx *sctx, u16 attr, #define TLV_PUT_PATH(sctx, attrtype, p) \ do { \ ret = tlv_put_string(sctx, attrtype, p->start, \ - p->end - p->start); \ + fs_path_len((p))); \ if (ret < 0) \ goto tlv_put_failure; \ } while(0) @@ -2364,7 +2365,7 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, * earlier. If yes, treat as orphan and return 1. */ ret = did_overwrite_ref(sctx, *parent_ino, *parent_gen, ino, gen, - dest->start, dest->end - dest->start); + dest->start, fs_path_len(dest)); if (ret < 0) goto out; if (ret) { From patchwork Wed Feb 19 11:43:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13981999 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1AC21E5B7E for ; Wed, 19 Feb 2025 11:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965416; cv=none; b=m3BgXLhBaKgBWynY0ue11HJaS8KTPdgGRVi/++b7RYJXW+byynpPFk4SbsRN4CewWdPPBAW9azNGSQihCZyinCqmXkQAH17K/wmQhONgXcosh8EVdTso6JA7uSrYLEcry1Jz/ahLXnN29m6hNyH1iNR2PF0dDb6igG7fOKn8gCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965416; c=relaxed/simple; bh=rdrI5QR7o7YSMAs7It4zSI9Pc91EI1TQvoSr4/qmDNk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fj7udIpS6iiaPFSGV59aHKOPhmBfqEO/zwIJnjfKwOZt19xD4h31xZ+RrPY0M/ZGes/rfCRsJPc71/Pos9dZjv3vT1mt+4FKU9CFDWkSGC+7MzMdzeKAb9Xs/oDkqTD7T2UImuxo98+Pi4SFctkx4ztI6aBeGGb2ICx7to1v7V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QHnP0COl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QHnP0COl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE104C4CEE6 for ; Wed, 19 Feb 2025 11:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965414; bh=rdrI5QR7o7YSMAs7It4zSI9Pc91EI1TQvoSr4/qmDNk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QHnP0COlmt/j/Fk+xZ8vB7RhNfE/QMF2M3KVH6SdGsvE9jrQ1Cs4N6J+2a9IMOXGl uyCtT82itNWHzvTHwR2O40RjUj03GCEbcP6sKIBZ84q3QQMV1qq7OL1oItaSBxVPGD 2kxOd+QhszeoVnA7prZC1qm9uVwu3OJ4bz/Xpka2lYbFajvaA7ht56STYYPQp48ANk WaD8zZkeiITHXihauztXmJO2gGLjDFGK65XgrCR7j5xKQL2qSw1owon75Ur2K8chmF hmj8058WGT1v4a2BVH+t8BW9FwRspDDryFI7dzzr5gG4LIs3XUBYG9urr1GoIgygjW VHxYyEcMwxwug== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/26] btrfs: send: simplify return logic from fs_path_prepare_for_add() Date: Wed, 19 Feb 2025 11:43:04 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 9f9885dc1e10..535384028cb8 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -535,7 +535,7 @@ static int fs_path_prepare_for_add(struct fs_path *p, int name_len, new_len++; ret = fs_path_ensure_buf(p, new_len); if (ret < 0) - goto out; + return ret; if (p->reversed) { if (p->start != p->end) @@ -550,8 +550,7 @@ static int fs_path_prepare_for_add(struct fs_path *p, int name_len, *p->end = 0; } -out: - return ret; + return 0; } static int fs_path_add(struct fs_path *p, const char *name, int name_len) From patchwork Wed Feb 19 11:43:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982000 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1A5A1E5B65 for ; Wed, 19 Feb 2025 11:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965416; cv=none; b=S/kbaPsdnVsf5msrgkiNxU3Nh5sjrVhw7EWxDZxqDHwHhVD/48vjiyVhJjoqYH5sig3bzcRG0K16V4hYDMv5bLkgVGAfEL4ntlfSxgeHgz8wUMHcOZaTxJjngzgUV33Q5dGOfiYlvV2x2RSTT3fYpHpkECQDpH4/lc+tlSs/hDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965416; c=relaxed/simple; bh=nLZMehNoN9F5I0XHcpAhnK5JTMMzu8dFugV0exoQdf0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UQt+5sHhBr4l/lTYvcqr65NrKm9zyFKvSR9Qe6pSA7qXR/HvyDaL3RbOBcIUuTBwqM/u6UnRzEwu7vRtbw2amEZryFgHFOOGYg/TR4+AMw+TTEf8dyMq5rpjYCQNltMrJPPKVFpxjDcn4YPCDQZFkJk70Wyl+gEhOPwX4XJu/dE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zo597lbs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zo597lbs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E30D1C4CED1 for ; Wed, 19 Feb 2025 11:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965415; bh=nLZMehNoN9F5I0XHcpAhnK5JTMMzu8dFugV0exoQdf0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Zo597lbsIBmki4JFDf02QoNNd0WwCgc6mkpbD5ql+FLDbxk7YR3p0+/4EoiVR1dRp nuA9iDDHHCgY9L3yiDOib7icwPL/N1JeIUQ2a7wunoTie0239QVAIsh38wFZdpHn9H 5c6CRx2EuhaurG/1VQbKOlvaFCWPp8mhUEu8ZAdnHzXQhgy0rPMA12+vMn48avYGvb NN6k95nsETlnRy9SqX7Ec7/suGjezOhJKoS9xQYYXCo2IqmzdATAvsjAEFhQbv2Wp6 juhQ37TviwT1UwM/4hYVHBoMimuHV49+q8symCxBhnGD6psWZ/2peVVX0NHgio6G8U NSWYJsPotJKvg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/26] btrfs: send: simplify return logic from fs_path_add() Date: Wed, 19 Feb 2025 11:43:05 +0000 Message-Id: <3cabcc617f04d2182749e9a22c1fed64b4d63041.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 535384028cb8..2203745569e0 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -560,11 +560,10 @@ static int fs_path_add(struct fs_path *p, const char *name, int name_len) ret = fs_path_prepare_for_add(p, name_len, &prepared); if (ret < 0) - goto out; + return ret; memcpy(prepared, name, name_len); -out: - return ret; + return 0; } static int fs_path_add_path(struct fs_path *p, struct fs_path *p2) From patchwork Wed Feb 19 11:43:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982001 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 035CB1E8323 for ; Wed, 19 Feb 2025 11:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965417; cv=none; b=P8jhjs16XEodewVNBZPnSFjNo0shLGCqVbgayRRU/1qLwGGAF4k8PrXBk+XtHNkyD28UdpiJ/VAiHVkXeVDnKJHPNLHLSCBXcFTh/2dbibEDqils8ypJH95A9bWl742ziCXCf3zqs19bWp/00g5fWIrmXiuDp+SR9Zi5Tbjt0kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965417; c=relaxed/simple; bh=XxZo2AnDSw5lV1zznAhDaeSUgPufzogr8jT0/2qq8Mo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kt84agZQDMGw9r2ATxiEu6Cd0qElY78SmWXLd19u3BO9THq23KM3/X0V5/MxnJsPz0gTNo8CdLnkdGx1U3Xtl26oHS+JA7Cji6lcYJtepgWlTCl4SQlV+nQmHMQTkoF0D3QtT12D94R5biNOw17kqbcVlPqlwJ2/W75ud9/cGic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgiQ2W4f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XgiQ2W4f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8129C4CEE8 for ; Wed, 19 Feb 2025 11:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965416; bh=XxZo2AnDSw5lV1zznAhDaeSUgPufzogr8jT0/2qq8Mo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XgiQ2W4fYXJuhN3dJ1yX/3meI1M0S/M0fmWFLFqzUYEabd4JyWr5T53tvXvU9aXYr CVBl+oLlHI0y8BTpOLDd7Yqd/CbBS3Ri9WbtVlYFDEV+HBCAcL9Fp9Z9o+Dx3S99GJ DIC8ADPRQysbMfDnZADWQfn4a1/+B+YjOnoqN5MSzV1NzEcMsv3AzNgVBwpRZOo6Cb neppYwVmedsMLaMZkWgq18CnhlKD4lWD66rhRgiErwXLy7z20i/h+oBxcteNeqHK3/ zZAZWBWqP0kHq5Sg6K70RKOOsW420vz1/I1kS7D6D/RCiOWXHega41Ng9dEGpvPLgt HWY3HIZ+flEwg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/26] btrfs: send: implement fs_path_add_path() using fs_path_add() Date: Wed, 19 Feb 2025 11:43:06 +0000 Message-Id: <984cf0ba391d6e7de70b7c8057cdaaecffd961a1.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The helper fs_path_add_path() is basically a copy of fs_path_add() and it can be made a wrapper around fs_path_add(). So do that and also make it inline and constify its second argument. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 2203745569e0..7a75f1d963f9 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -566,19 +566,9 @@ static int fs_path_add(struct fs_path *p, const char *name, int name_len) return 0; } -static int fs_path_add_path(struct fs_path *p, struct fs_path *p2) +static inline int fs_path_add_path(struct fs_path *p, const struct fs_path *p2) { - int ret; - const int p2_len = fs_path_len(p2); - char *prepared; - - ret = fs_path_prepare_for_add(p, p2_len, &prepared); - if (ret < 0) - goto out; - memcpy(prepared, p2->start, p2_len); - -out: - return ret; + return fs_path_add(p, p2->start, fs_path_len(p2)); } static int fs_path_add_from_extent_buffer(struct fs_path *p, From patchwork Wed Feb 19 11:43:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982002 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC75B1E8331 for ; Wed, 19 Feb 2025 11:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965418; cv=none; b=lmSDYoOh+nPkNv8aYcj5U9Qlv27YNfBvjTYTRGnD86RtnlzPccix2NgsKoBWWELB87iNKjcWzf7kYizmZmzNj8sG7LELeIcXAxvKDer8YDD/JzPJTT9EOjDjLUFblHjmWOOhviCZnUG3pnjXf12fHpprQpuPCEFhxSahsPRUTdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965418; c=relaxed/simple; bh=TU4XK2ZNfLY7/Ncb2aX2uSF786rE++vnCm1jmieZQ44=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V760nuc/djciNNdbkvyOYkiR3UDp6kA7jX/NHLhCyIevke7A/eoqBp2ki/h+8cIbb07cL/mBnIEtRCtGbNoBl9Fc67jU/QDwaflkF59hF92cVFDl62/vuKftGrHUsYhvvg+QBnfFcZhtZqxVFdSQiQA2K5eCR9fInCwJJMlSbTo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AlbZO9KN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AlbZO9KN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDF6DC4CEE7 for ; Wed, 19 Feb 2025 11:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965417; bh=TU4XK2ZNfLY7/Ncb2aX2uSF786rE++vnCm1jmieZQ44=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AlbZO9KNJK4p/IGZb/05rZ3di5wkIyd4MaxziSxYa2oWyfCA2/HvWwguI5lo5SbLT nX29Fitp6CteVdVFySuq6J8Yqd6NTOCsPfs2CBzOL+AISmjRN6DhsRuCm7s5coHFcv +0TAH+D8EdaEMx/rv/lvfMsRPULsnMIAXXe/mJIB7K8XbnpL8ouwU1veLRla4tgNFF Zub61DAF9+ZHYFVC4atam+gBZUIBaPrsRBYtDrdI/OJHWSjvfsdV2kJBUP3qoyuC0o gowcG+y2vyN2kE7huM+euIdFLK3VIiooStUokTWCprpkHpXUPRiL8D+bylxCgJnNAs wyB08x8ZNNNLQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/26] btrfs: send: simplify return logic from fs_path_add_from_extent_buffer() Date: Wed, 19 Feb 2025 11:43:07 +0000 Message-Id: <3b345a8f4e091bc5a3e2cd8a55180d54d48b3dec.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 7a75f1d963f9..b9de1ab94367 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -580,12 +580,11 @@ static int fs_path_add_from_extent_buffer(struct fs_path *p, ret = fs_path_prepare_for_add(p, len, &prepared); if (ret < 0) - goto out; + return ret; read_extent_buffer(eb, prepared, off, len); -out: - return ret; + return 0; } static int fs_path_copy(struct fs_path *p, struct fs_path *from) From patchwork Wed Feb 19 11:43:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982003 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 134C71E8346 for ; Wed, 19 Feb 2025 11:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965419; cv=none; b=poqvF0YWSJH88zOiVrs/DoxNlS8bIh+vrnT4F1P1WzpUm+JACms/uKgT67txsAD/oK3AKfKJCOpidF9po4aibR7cAfpuF+qOiUgBFX/JBwa6X9UhBkJGo58IJiKbBw6ExAoTWfDfaLtn4uUcWf/gJAPxxkDJn+Hzqso4SIhAr6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965419; c=relaxed/simple; bh=jyxzL+aBLpb/hFzx7tyDyKjp6IkA5CQDpEEkFLuAiaw=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eww/PmdSto6yEPKOnhz9RHLyQvRyYay8mTdcDfzoUJe2w12tSoZ8jwqLHSobM7wiNUATiOKPIvkCe6nXO6wpY7W1wQFCehenTzEZx8cJXMPGowZB8ns90P6KDtzu/EDd78DvzDpiZ302f8/iy3ZILZPmLczSzw3GBGimvLeTdoU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dC7rlCGR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dC7rlCGR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F32C2C4CEE6 for ; Wed, 19 Feb 2025 11:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965418; bh=jyxzL+aBLpb/hFzx7tyDyKjp6IkA5CQDpEEkFLuAiaw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dC7rlCGRv8qu0KsbLYHYdahfWdWTZJH+SR3XDFf8q3nJRIeFh1rILwzAXjaB37MnH osiBDyStE64DoSo+B3OkyNkFdMkkowIz/CvY8GLpddTFy1bEJg2WgRv2oiX/vEGg8e 1i08EBGHaKx+b8nFEseFlPHeKOYE9KzMWhU6EOKC6dZfKxaYQbwBbsIPxtqEl0WaQ5 DlsoQ5rDSaPluVfRSiSeoSbeWCq8xH+GQHt6thVgwChYc19Cv5hT2d5xKS85WGEQyr NSqrVb6EeAqutCl9EVO5li+v8ib0ZoNh32rbjEfyglvrGI4MSpHUYsmU9mpA81gc9W nfBv2cB+8Qc1A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/26] btrfs: send: return -ENAMETOOLONG when attempting a path that is too long Date: Wed, 19 Feb 2025 11:43:08 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana When attempting to build a too long path we are currently returning -ENOMEM, which is very odd and misleading. So update fs_path_ensure_buf() to return -ENAMETOOLONG instead. Also, while at it, move the WARN_ON() into the if statement's expression, as it makes it clear what is being tested and also has the effect of adding 'unlikely' to the statement, which allows the compiler to generate better code as this condition is never expected to happen. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index b9de1ab94367..dcc1cf7d1dbd 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -484,10 +484,8 @@ static int fs_path_ensure_buf(struct fs_path *p, int len) if (p->buf_len >= len) return 0; - if (len > PATH_MAX) { - WARN_ON(1); - return -ENOMEM; - } + if (WARN_ON(len > PATH_MAX)) + return -ENAMETOOLONG; path_len = fs_path_len(p); old_buf_len = p->buf_len; From patchwork Wed Feb 19 11:43:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982004 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D85D1E8351 for ; Wed, 19 Feb 2025 11:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965420; cv=none; b=eh+pny2gZbpY/J4/En7Nyv3fjCjGaW7ICUbolHpPmL7vt8Nr+WfPslWLyhejQW3VSfpfWixCdRemy6oKeOKMBoGBgBSi8L3Djf7CXC9bqoUzsM4iNaJJHO7o4kJJETMO3KHQDhdA4WL2bilqdWOEgVE8sNa8g8kwCoFKWMfxhPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965420; c=relaxed/simple; bh=ChBKnQAulfXbutwRNaXkCCJf8hYyc7teGSzKCz2J0jg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NczY3C2EoW8e+LCzDPJ5teK0vy0NGWT/aYXY0UIchb0EV+0IQVGL2gvfWzMVNtRTUXo2rQqRJGndSR2OiJHpW1uRzuCsk12R34pbVv9IJ+7zjk7k4iX+RCMSAbtpvKBmN4f/GrliCkZGT+itsbmtGZTblMrotw0KH22zIuK+Ym8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HYxz0Mwx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HYxz0Mwx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 039EEC4CED1 for ; Wed, 19 Feb 2025 11:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965419; bh=ChBKnQAulfXbutwRNaXkCCJf8hYyc7teGSzKCz2J0jg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HYxz0Mwx966aZurJEVXxqz3jS04S4EWB2J9pKF9CWBfAlBr5wG+v7rT5cxQmM5XM+ JJrDCKW8UKnBaIx++zDNBQZCEdxt2R5bgrj7UIZlzVYRzn8uLhKNipl9z3k/Ji+Moq 1hiTq6Z3eFJhjS6nVzY1KS5yhv5yfysNeLSETcBII2XMPULRnlM6e13IA0qrG6b1q/ cHFrq+RfKdSLHUgqpCKdpAHFf7FI/VcZz8//ya5T4nji3pKRFuH8Wpx2mIY29ZtaHA HUSbZX9tw2Al9oRLeQ+jiAxOkUGq+8xjREAxP6F1S2M622R06Pss6/9Ub21No+McAr xOoYfJdm2JGLA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/26] btrfs: send: simplify return logic from __get_cur_name_and_parent() Date: Wed, 19 Feb 2025 11:43:09 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index dcc1cf7d1dbd..393c9ca5de90 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2309,9 +2309,8 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, *parent_gen = nce->parent_gen; ret = fs_path_add(dest, nce->name, nce->name_len); if (ret < 0) - goto out; - ret = nce->ret; - goto out; + return ret; + return nce->ret; } } @@ -2322,12 +2321,12 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, */ ret = is_inode_existent(sctx, ino, gen, NULL, NULL); if (ret < 0) - goto out; + return ret; if (!ret) { ret = gen_unique_name(sctx, ino, gen, dest); if (ret < 0) - goto out; + return ret; ret = 1; goto out_cache; } @@ -2343,7 +2342,7 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, ret = get_first_ref(sctx->parent_root, ino, parent_ino, parent_gen, dest); if (ret < 0) - goto out; + return ret; /* * Check if the ref was overwritten by an inode's ref that was processed @@ -2352,12 +2351,12 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, ret = did_overwrite_ref(sctx, *parent_ino, *parent_gen, ino, gen, dest->start, fs_path_len(dest)); if (ret < 0) - goto out; + return ret; if (ret) { fs_path_reset(dest); ret = gen_unique_name(sctx, ino, gen, dest); if (ret < 0) - goto out; + return ret; ret = 1; } @@ -2366,10 +2365,8 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, * Store the result of the lookup in the name cache. */ nce = kmalloc(sizeof(*nce) + fs_path_len(dest), GFP_KERNEL); - if (!nce) { - ret = -ENOMEM; - goto out; - } + if (!nce) + return -ENOMEM; nce->entry.key = ino; nce->entry.gen = gen; @@ -2387,10 +2384,9 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, nce_ret = btrfs_lru_cache_store(&sctx->name_cache, &nce->entry, GFP_KERNEL); if (nce_ret < 0) { kfree(nce); - ret = nce_ret; + return nce_ret; } -out: return ret; } From patchwork Wed Feb 19 11:43:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982005 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05DB81E98ED for ; Wed, 19 Feb 2025 11:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965421; cv=none; b=evYB8wMjqsqFpldOYoZpSXGZ8qAt7nhXJWtH1tUAy+GiwwflKi2/wOQwjkCsnNrk9YZZvXequFGLuT6dLwiQJ6TVlTu352EQW4wX558F1F1kIQ9S3YZYt9RMOhDrmV4gNhTIF1lwPBJTtoalcwe0qcjvKODsew9yhdshZ4BooT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965421; c=relaxed/simple; bh=wU+8lAGav3ycWmUOUtxDG0zPsFe5lhgvAzLDXJIHe+M=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k02QSaN43PxjTOW3SFA/yoA+r6q6JtSn6tFxfSkLDPFhjvRgjsW3enjyx6VqmxnDNPQnhwVIL6Y1TQ1Y1PufxTzr8veAn979DS78hWn9OifoVqMVvT8L9BHbQ7tuZXZvLnn8vu28F+Tpz4QKUxPJrdWtfJOUGB2maquV7kWEF2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QPc6s+SO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QPc6s+SO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0762DC4CEE6 for ; Wed, 19 Feb 2025 11:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965420; bh=wU+8lAGav3ycWmUOUtxDG0zPsFe5lhgvAzLDXJIHe+M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QPc6s+SO16sZDrnB/Br79f+Q9kWBIwDnTYObbTVcaSJW5nl2HxwUf+feVEodrArA/ /0VtULesTqIWPsR8zF37psPqb9tyN0bNU3/pEUKeXdC6Ip+elkBhY02BQBT1EbkM+G eTRTPh+9Ze36ysnfLBePr4N97+K9DsGBG1Zy64fGp1Y/6hjyqLkB/U2TJpdYFoQkJ9 S+lPgNW2K8pU6OB4H7hpKmUIsH7tjnv8X+qZAtT8OY1qwI1oYKEdfE7XxahyaLwP8V Fva6JwmlO5Opjqd8dTIdisCjv8OrsVImfCPHJRI2RowqBIRCPSPmIF2vsll1/GgDOB AGYQtOWg5uNTg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/26] btrfs: send: simplify return logic from is_inode_existent() Date: Wed, 19 Feb 2025 11:43:10 +0000 Message-Id: <1dcd7cdbe1e547af8ae5e673346ded6cbf79e213.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 393c9ca5de90..0a908e1066a6 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1950,17 +1950,14 @@ static int is_inode_existent(struct send_ctx *sctx, u64 ino, u64 gen, ret = get_cur_inode_state(sctx, ino, gen, send_gen, parent_gen); if (ret < 0) - goto out; + return ret; if (ret == inode_state_no_change || ret == inode_state_did_create || ret == inode_state_will_delete) - ret = 1; - else - ret = 0; + return 1; -out: - return ret; + return 0; } /* From patchwork Wed Feb 19 11:43:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982006 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B27031E0DCC for ; Wed, 19 Feb 2025 11:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965421; cv=none; b=U4R16SUnURWZ214sYtopE3BurMW+IY+N8uj/k7mWwvJ5JyNa44jRw7MhWHs+LERKDjaqbvN6unnhb16hjs1o36E/xtVfcmeUg8R3f+ikNj6iGJhXyR+mszk7joHFBwCNy+BKgnSP35eLh2/v2sh/PJUd9o0OJB7WqEXxY32L2j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965421; c=relaxed/simple; bh=yGG6Cy9K8ygG2fE8rIJTVP2uEfYv8gX0Yf3gDRp25FY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tt0K5cZ+b0l46DEWUz6EvSARhr8dgXGJK8qRyuwK412CNJaLNo2USTELTUhqFAa1Pw3rX7BhdDRERpYh4AZ1wCHcX50MTCZoEj4OeR6KWXgrxrH9jF1Ksu+s1n9JATNT+VMI57Ts+NSbX/PjOVoEwkiFiGrRLd0kF9ToVBjMD4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kyVcf5+J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kyVcf5+J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C51FC4CEE8 for ; Wed, 19 Feb 2025 11:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965421; bh=yGG6Cy9K8ygG2fE8rIJTVP2uEfYv8gX0Yf3gDRp25FY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kyVcf5+JVEuOYDTH+VrQfx/rLrzHmAfnQ6VKCGLlL355Jz/P5GqYfvQHxBl0MLdxV kyi5Kb2QYyzJN+u3iOGqDpszYN+OXq/Ie9YBZcYBIS7PB0utN5RyVaVttVdIU83cEV Xo6WtWKZ0MWbeWRU4J0cbJeiPN3cLD6rKdChjI7sb0AmNSh2j2OeYDSXylt+6oFbrB jQ3zJx78CdSVKd4YqhgeI8gwItNjNLBAkBXPUfa3xmByxVLnjlbcaGW2Q5BfHMKQfA Bht+F9qh3jJOdljBK1fZ2HXnhVivIlYI09r1VtANtntvOq1UBpk5J9mQLwrMuqovDa +yIAMo9c7edvw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/26] btrfs: send: simplify return logic from get_cur_inode_state() Date: Wed, 19 Feb 2025 11:43:11 +0000 Message-Id: <7a0324782e68e96229c2bc37943dc398aa14d4b5.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 0a908e1066a6..e0e24ac94aac 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1880,7 +1880,7 @@ static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen, ret = get_inode_info(sctx->send_root, ino, &info); if (ret < 0 && ret != -ENOENT) - goto out; + return ret; left_ret = (info.nlink == 0) ? -ENOENT : ret; left_gen = info.gen; if (send_gen) @@ -1891,7 +1891,7 @@ static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen, } else { ret = get_inode_info(sctx->parent_root, ino, &info); if (ret < 0 && ret != -ENOENT) - goto out; + return ret; right_ret = (info.nlink == 0) ? -ENOENT : ret; right_gen = info.gen; if (parent_gen) @@ -1936,7 +1936,6 @@ static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen, ret = -ENOENT; } -out: return ret; } From patchwork Wed Feb 19 11:43:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982007 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EED01DED70 for ; Wed, 19 Feb 2025 11:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965423; cv=none; b=dxMwB9Y4Y1mgTScsYveHpZv7FLfbSGnG6Xn8+Gd+LhRbK2H5KtPafI5Vcis8G2T1CocZ6WmlPcre8r4FuL5IBGthM3GFI1QFmmSKM23SEKqL3kS85U1fGJ75dDbGujIrU52OCyh34tsrGzziXTzsyDtG0IA+LvorTBLTIr0rJMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965423; c=relaxed/simple; bh=GSRyDQepQ8nNM+59vyTKZf4Kiuw+8c2fQg4jvtw63aI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qJwByqbwp0Cj9O9QosuQOQVayr6/o5Iy8eAkJ7THyaLbLxeu1DLCzvryZUASx2SNagl+ceP+EkydR8mMupSyiJwU+NG5XA/dquevV1cY25NXitsB0U55BZ3/PFVaaNedsQ/DcjpZjhYcByBsVVGf+GtT2hksemdIr9sHFDWJAts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xi2MoZQB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xi2MoZQB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12680C4CEE6 for ; Wed, 19 Feb 2025 11:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965422; bh=GSRyDQepQ8nNM+59vyTKZf4Kiuw+8c2fQg4jvtw63aI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Xi2MoZQBT20UWDBRxfM6S5BzBkPxeCfwLjZSFtJRA0e1kOeA2QCPdQirAvxiVyhgb ifOZHxXt3l1HWR1JQ+AOSMTntNv9jSHunqi6hgqtbrI2121+UYmV2LQV2R5PhS46tc px2DejLB4MlUck0ab520AM7GSZROem14AnRHMOElrHBdhVnOARbPfIgxVYirmrUate oVN+s5NNO8yF0OJI5KTvJPV1tUeCo4DoRjNklRQI407YWJllNFmOtevVpCftLgQlxR Zw6pc73pr8hx8QuxswadpLx0svhpcH6jvvwZaaqGzqrwWsXV3Wrglz+UwEmpYuZ3kS V/bprNwEXu4/A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 12/26] btrfs: send: factor out common logic when sending xattrs Date: Wed, 19 Feb 2025 11:43:12 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We always send xattrs for the current inode only and both callers of send_set_xattr() pass a path for the current inode. So move the path allocation and computation to send_set_xattr(), reducing duplicated code. This also facilitates an upcoming patch. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index e0e24ac94aac..3aa2877f8c80 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4844,11 +4844,19 @@ static int process_all_refs(struct send_ctx *sctx, } static int send_set_xattr(struct send_ctx *sctx, - struct fs_path *path, const char *name, int name_len, const char *data, int data_len) { - int ret = 0; + struct fs_path *path; + int ret; + + path = fs_path_alloc(); + if (!path) + return -ENOMEM; + + ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, path); + if (ret < 0) + goto out; ret = begin_cmd(sctx, BTRFS_SEND_C_SET_XATTR); if (ret < 0) @@ -4862,6 +4870,8 @@ static int send_set_xattr(struct send_ctx *sctx, tlv_put_failure: out: + fs_path_free(path); + return ret; } @@ -4889,19 +4899,13 @@ static int __process_new_xattr(int num, struct btrfs_key *di_key, const char *name, int name_len, const char *data, int data_len, void *ctx) { - int ret; struct send_ctx *sctx = ctx; - struct fs_path *p; struct posix_acl_xattr_header dummy_acl; /* Capabilities are emitted by finish_inode_if_needed */ if (!strncmp(name, XATTR_NAME_CAPS, name_len)) return 0; - p = fs_path_alloc(); - if (!p) - return -ENOMEM; - /* * This hack is needed because empty acls are stored as zero byte * data in xattrs. Problem with that is, that receiving these zero byte @@ -4918,15 +4922,7 @@ static int __process_new_xattr(int num, struct btrfs_key *di_key, } } - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto out; - - ret = send_set_xattr(sctx, p, name, name_len, data, data_len); - -out: - fs_path_free(p); - return ret; + return send_set_xattr(sctx, name, name_len, data, data_len); } static int __process_deleted_xattr(int num, struct btrfs_key *di_key, @@ -5803,7 +5799,6 @@ static int send_extent_data(struct send_ctx *sctx, struct btrfs_path *path, */ static int send_capabilities(struct send_ctx *sctx) { - struct fs_path *fspath = NULL; struct btrfs_path *path; struct btrfs_dir_item *di; struct extent_buffer *leaf; @@ -5829,25 +5824,19 @@ static int send_capabilities(struct send_ctx *sctx) leaf = path->nodes[0]; buf_len = btrfs_dir_data_len(leaf, di); - fspath = fs_path_alloc(); buf = kmalloc(buf_len, GFP_KERNEL); - if (!fspath || !buf) { + if (!buf) { ret = -ENOMEM; goto out; } - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); - if (ret < 0) - goto out; - data_ptr = (unsigned long)(di + 1) + btrfs_dir_name_len(leaf, di); read_extent_buffer(leaf, buf, data_ptr, buf_len); - ret = send_set_xattr(sctx, fspath, XATTR_NAME_CAPS, + ret = send_set_xattr(sctx, XATTR_NAME_CAPS, strlen(XATTR_NAME_CAPS), buf, buf_len); out: kfree(buf); - fs_path_free(fspath); btrfs_free_path(path); return ret; } From patchwork Wed Feb 19 11:43:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982008 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C238D1E9B0B for ; Wed, 19 Feb 2025 11:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965423; cv=none; b=c3n4byCtqMEXcAOpyHgV7OLlXaFmvuC5qk+hw//n6HpIFQ7Ru66xQO+hd1aMQp7AHbU9HUbpUfDanwfcHwK7qmcwqcYOFHm4YjGTECPQV9vIAmIfcKOL9VycjFRmxv4vXNk5l3Np/aCnL/7hBYk3odr7P36vz0Ivl3ZV5OAOldg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965423; c=relaxed/simple; bh=9hxk+7ErPnp6CkqDnLiQhSsA+nXDmhR3kp3A7y4ud6c=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mausvHOxqQQo8JN4KMF4iMn3d7cSv8yOPAVuBR16jleQhO21HITgrKJ8k9gkbeuu+MHF1jyTknyUKJbDH3ChMfd5S/LUwijVbzymTSj936JetB31U61R5ytf9aD/LyH2PEAoVN4ulqQwOvFuB9DrHJWG8N0MZGItKXa6xNOcFTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DcoCYo73; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DcoCYo73" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1731BC4CEE7 for ; Wed, 19 Feb 2025 11:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965423; bh=9hxk+7ErPnp6CkqDnLiQhSsA+nXDmhR3kp3A7y4ud6c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DcoCYo73a3gOaoSgo19b216VcPlT7/YvK8QcNvdOZ9QbHbTLpKsx5Y4BRGT//Y78z yJtrSmmCInr68Rdx5airjahUXA0bud2LXiQOMcQhRj26SSXvl/2ekNNP/OV3ESRptD IedzLgaG7prIjYXDhLQF4XmqG6Njwd2xV87SB+9k84S6C3++DnyEaioNNTnb55QqCq xqG1tllnzvz4+rqe3WXGZNyv36kajXl1JPHd6+8z42keyZDYVvuvrPrTQQVGQawHVb /ZS8M2mVepO5mbCvJHprINkuMIqqNOSiIIrESomw+TX1/R844+GuruJ18P+TlAJwoz dRPI/EfEuOKXg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/26] btrfs: send: only use booleans variables at process_recorded_refs() Date: Wed, 19 Feb 2025 11:43:13 +0000 Message-Id: <9569f7e861f4f3fcb793a0752aaddfaaadb6a03a.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We have several local variables at process_recorded_refs() that are used as booleans, with some of them having a 'bool' type while two of them having an 'int' type. Change this to make them all use the 'bool' type which is more clear and to make everything more consistent. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 3aa2877f8c80..6e27a7d77b25 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4147,9 +4147,9 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) u64 ow_inode = 0; u64 ow_gen; u64 ow_mode; - int did_overwrite = 0; - int is_orphan = 0; u64 last_dir_ino_rm = 0; + bool did_overwrite = false; + bool is_orphan = false; bool can_rename = true; bool orphanized_dir = false; bool orphanized_ancestor = false; @@ -4191,14 +4191,14 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) if (ret < 0) goto out; if (ret) - did_overwrite = 1; + did_overwrite = true; } if (sctx->cur_inode_new || did_overwrite) { ret = gen_unique_name(sctx, sctx->cur_ino, sctx->cur_inode_gen, valid_path); if (ret < 0) goto out; - is_orphan = 1; + is_orphan = true; } else { ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, valid_path); @@ -4421,7 +4421,7 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) ret = send_rename(sctx, valid_path, cur->full_path); if (ret < 0) goto out; - is_orphan = 0; + is_orphan = false; ret = fs_path_copy(valid_path, cur->full_path); if (ret < 0) goto out; @@ -4482,7 +4482,7 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) sctx->cur_inode_gen, valid_path); if (ret < 0) goto out; - is_orphan = 1; + is_orphan = true; } list_for_each_entry(cur, &sctx->deleted_refs, list) { From patchwork Wed Feb 19 11:43:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982009 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEC9A1E8855 for ; Wed, 19 Feb 2025 11:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965424; cv=none; b=ZthsENenj0fQZlbJVq6uB+LfokiVW7JoKvybqVgPyhtvqtPr6y+OCC54ZXC3A4q7O+468L7E56wTvqaEgS/LCvOcEAqF7eymIAZy/AGmhPj6paCVMrRVuuJsuB/INez5DurMAIRgK5/Bib0l6//60hZGWHHwX8hN14m/M78IONQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965424; c=relaxed/simple; bh=rKG84Dm+qgA2a8K8nJHKowtWopfIOurS1J8H/BWnAXQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LgO6chwSHJqUS1JCHr6PFkYOT+vyVPZzE1Sq+5PyWPQJVHTVj3Te82XK/futd4/mHEbo36ibxZoYBxgalE2uQTYZaGCEpgwG7RLb/fzPguB1zFhelsAl7tMMJknPfXpVlMyEbZIXPDAs6RGzj1Q0e4Hz0xEWaB3pVhm/7XTZvbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WVfcY/2Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WVfcY/2Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CAABC4CED1 for ; Wed, 19 Feb 2025 11:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965424; bh=rKG84Dm+qgA2a8K8nJHKowtWopfIOurS1J8H/BWnAXQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WVfcY/2QSNEWysFEy/7itgg09B0+fxSxIlaqGfwUoO1VRqYtbEwXmbLK0RJwcoJPF 59hY+uMi8jFGeFg1u5Ri0W1z8GQibkD5IpHUq1+lOv3YhCVSzwyfcvk26aLa6JZJDY 7yvDQH6Z1dj/eduHFLXETXGdoFYhiC2RZAia8O2iSogt37P06DfSN7vZB94WCGwrnP ZJVvJ68rt3stwlqgmH9w4VY6b1jtTc62mSMb70cX6f40dGD8kdY96MM+KEP9eWBoIC 7uH8I4nu/Nvpnvxa/0eXLzW1PWgu0j5j9Cu+ZFiLqx2wQcheL1P5buzJGT7s22pJJH sDQvxC8am6Ttw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 14/26] btrfs: send: add and use helper to rename current inode when processing refs Date: Wed, 19 Feb 2025 11:43:14 +0000 Message-Id: <474e6f7bf43469d83f91f5c455d0a0454a8e5c36.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Extract the logic to rename the current inode at process_recorded_refs() into a helper function and use it, therefore removing duplicated logic and making it easier for an upcoming patch by avoiding yet more duplicated logic. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 6e27a7d77b25..653e0b9a94ca 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4133,6 +4133,19 @@ static int refresh_ref_path(struct send_ctx *sctx, struct recorded_ref *ref) return ret; } +static int rename_current_inode(struct send_ctx *sctx, + struct fs_path *current_path, + struct fs_path *new_path) +{ + int ret; + + ret = send_rename(sctx, current_path, new_path); + if (ret < 0) + return ret; + + return fs_path_copy(current_path, new_path); +} + /* * This does all the move/link/unlink/rmdir magic. */ @@ -4418,13 +4431,10 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) * it depending on the inode mode. */ if (is_orphan && can_rename) { - ret = send_rename(sctx, valid_path, cur->full_path); + ret = rename_current_inode(sctx, valid_path, cur->full_path); if (ret < 0) goto out; is_orphan = false; - ret = fs_path_copy(valid_path, cur->full_path); - if (ret < 0) - goto out; } else if (can_rename) { if (S_ISDIR(sctx->cur_inode_mode)) { /* @@ -4432,10 +4442,7 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) * dirs, we always have one new and one deleted * ref. The deleted ref is ignored later. */ - ret = send_rename(sctx, valid_path, - cur->full_path); - if (!ret) - ret = fs_path_copy(valid_path, + ret = rename_current_inode(sctx, valid_path, cur->full_path); if (ret < 0) goto out; From patchwork Wed Feb 19 11:43:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982010 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C79031E0DDC for ; Wed, 19 Feb 2025 11:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965425; cv=none; b=nvBChfOv1hRjg0fbRb5hH2WKK2WDLNnn4wXmzl+6FdHDPi4Rs1PnU+L3AlV0+w+Qf9NtGqHmLkeuOCI9p6iau31uZBrm2dyQ8X3sqvxGZqFJK+fk1jZ8tIH2qoFdtq4e5+w4yZkI0j+yeoBZE9dp0HQPr76c2zivzELNQUogJ6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965425; c=relaxed/simple; bh=8ihYbfEmW/bqLw/MsLra7UmB8oJ2hM1pKiPbv9n1Dqo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HeTz1P8YeBgXA8DJqJMyrmPwto0yqujc+JP3S9usA1lfoMnu7IQiw37ct6FhjUIVeFBUDdZWvapA9Sow2dXU7worPCBAhl1JKvMQAPkzMeG5wKGSrLWNYK3zMao20wVrAUPW+4bAFCTcJwUtDpElTGqJucTG9fW100ENnVjz1YE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nzN+JUwn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nzN+JUwn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 220D3C4CED1 for ; Wed, 19 Feb 2025 11:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965425; bh=8ihYbfEmW/bqLw/MsLra7UmB8oJ2hM1pKiPbv9n1Dqo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nzN+JUwnjcjIUTBr8PkOmzdJEPkAjdowkUsCPvNe5D4DdSGoQ8YLG+Z4wfnecL1cE C1eTDfB2evurK88gCH6JOpgmebkIv5wI2CKVmWaWbbjOPuiBsGNrz8hL1fZ3IqyTz0 qvJnvIrKH7v4eBA7zB70CRPi/FxDMcofYnFh+a+uTwmB7G6XrU9pza1efVB5cINIQA /udGIsk85VikguOdo6si8dJMkme9xoe+8JiUSiKxCS1Z3J/6N5gRe77d+sdEs2xtOj pK9GY5EkhVkJkNfp0IS0jaA3hspBTtFxiwg+XNaeD9UnjTSZJ2eozd9r9jWDMYVHya feAWUMCh/ePYA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 15/26] btrfs: send: simplify return logic from send_remove_xattr() Date: Wed, 19 Feb 2025 11:43:15 +0000 Message-Id: <89a2e7cee7204f953742097d60dbf1fa61fdc038.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There's no need for the 'out' label as there are no resources to cleanup in case of an error and we can directly return if begin_cmd() fails. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 653e0b9a94ca..5fd3deaf14d6 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4886,11 +4886,11 @@ static int send_remove_xattr(struct send_ctx *sctx, struct fs_path *path, const char *name, int name_len) { - int ret = 0; + int ret; ret = begin_cmd(sctx, BTRFS_SEND_C_REMOVE_XATTR); if (ret < 0) - goto out; + return ret; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); TLV_PUT_STRING(sctx, BTRFS_SEND_A_XATTR_NAME, name, name_len); @@ -4898,7 +4898,6 @@ static int send_remove_xattr(struct send_ctx *sctx, ret = send_cmd(sctx); tlv_put_failure: -out: return ret; } From patchwork Wed Feb 19 11:43:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982011 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31C41EB19D for ; Wed, 19 Feb 2025 11:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965426; cv=none; b=L8Ndy25EhNP5+TkwAgrJRaEqh4yOcE8BA2+5Dzd8yaM4zBv7/WN0MndrSGUiDt3Arb1OUM5TuiHqkuwNm1q4nR0GQ6XoJfJAWoq0eH5M+Vp1CRDHIHWGnr2XTSiGv2jiM+ORLTmLo9klUuMrCH+0Sw0wRCShfpbave6vV3XKOLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965426; c=relaxed/simple; bh=THpErzxIZlA7QdlBQjpr5bQsJcE1FHd68W0QxJlpsYI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LEDmKoxZYAzUOupvntQhdngkxKUwx/hdgWuc7eisS7yn270l3o2NPgINVEGsjJzkfRSLZGBBzHlPKOrtxsNZQjDx/3Lg2dnn7mrBD4AVo9M9yPDETAHWrRPoW10gB7AT4/vv+rTopABfYBUACLntfjPKR3AS6wm2c3Hpg/YaZsI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MKpkjDRd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MKpkjDRd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2826BC4CED1 for ; Wed, 19 Feb 2025 11:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965426; bh=THpErzxIZlA7QdlBQjpr5bQsJcE1FHd68W0QxJlpsYI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MKpkjDRdatSlOMcxFHnCQ6+KSFxFGLnsOXVhgguHw2czUiV5glYmqXUT/xp4qUqYV Z6uKWwJPvmOYDFFT1tSBxMNeWPmF6Ky+fs7QvSJe3iumBb06C6aMns8PtrxK8B1ZCX Rn8ux+Z7Ctg8w5p3Z1K51RL7k/ZakOVvrYHQZnK4COY4eHK2dozCqhPNSJzTpCjziO Jwn2nGYmtgr7sqxClWWvI5SCBsp1z7b42i567pEvWTtBqPksuaLWOgKRXmjyX1gG7I aH0Oi+M/Py3XRBEyRlY5V7bgdrO9WYMRnfPBH/A16m50edBJUmf1bkNQgpfDtf4Let 7Qqyzs5YLuyEQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 16/26] btrfs: send: simplify return logic from record_new_ref_if_needed() Date: Wed, 19 Feb 2025 11:43:16 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 5fd3deaf14d6..96aa519e791a 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4683,7 +4683,7 @@ static int record_ref_in_tree(struct rb_root *root, struct list_head *refs, static int record_new_ref_if_needed(u64 dir, struct fs_path *name, void *ctx) { - int ret = 0; + int ret; struct send_ctx *sctx = ctx; struct rb_node *node = NULL; struct recorded_ref data; @@ -4692,7 +4692,7 @@ static int record_new_ref_if_needed(u64 dir, struct fs_path *name, void *ctx) ret = get_inode_gen(sctx->send_root, dir, &dir_gen); if (ret < 0) - goto out; + return ret; data.dir = dir; data.dir_gen = dir_gen; @@ -4706,7 +4706,7 @@ static int record_new_ref_if_needed(u64 dir, struct fs_path *name, void *ctx) &sctx->new_refs, name, dir, dir_gen, sctx); } -out: + return ret; } From patchwork Wed Feb 19 11:43:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982012 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3493A1DF27F for ; Wed, 19 Feb 2025 11:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965428; cv=none; b=bsOz0J0WhYA+XTMuG9aO51luys86M4lFDvPkVdJpzMP29WfAmT1BPHaCWiKrhuCJc4nj0oefjst84gr66AX26W/0MpkJ4X6J8yY7FPsfdv0anMm/MwNJvm8AMTPm1P7lq8/0hFOkTRfMKfJ5PQ4n4NxZMqWP1fln6DScCUJoqu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965428; c=relaxed/simple; bh=1JCUCDDhbrBpj9klUlZfnrC0vS8NJuYV+O9hY/74lBc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HKVOojgfLuTc3yHB+t0NOZC8peacXW2CHO88qIJ3Xg+rTTdyztFIMmeIN/pl+BQcHfUH748A3JqhOaNJ1w0JyV4C6YGdyKEcEGXjZjTf7/KOdqbP1WYERwdMJQhI39JOsX3kM+A94stZ0QtrezF4eNGURfR4MUCEGJgqMALmRHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=foURemAt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="foURemAt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CA7FC4CEE6 for ; Wed, 19 Feb 2025 11:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965427; bh=1JCUCDDhbrBpj9klUlZfnrC0vS8NJuYV+O9hY/74lBc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=foURemAtUaXjtHZSudH4wdFVsljLGca+BZsiRI5UTyQa8jw/LJqM4hBt5h341yTY+ FAivAuPW7Opkwmo8m5UIit6pJ/argrWe29l79284BMtcQ4Qpf+mOBMG/quPiqaS5xG Rz/IdcO8UgCKC7fJujj2tFM1PN9KPPR9/a0ZZppksD8z2EMDLI1ngrqeojO/pgSlwK S8NxSJQ4ux78f8ON08tQlMXnTlam/pL2eiwDfMZ7zs/cZbDEcfrKQOa0UievAZU3F3 L790LJichsC1cdx61GO5mLj2BHWve+0uEsAPlbrSzBATX4s1uy1bGLRRs/FUfCiWeZ 9jDxsuhx4yOuQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 17/26] btrfs: send: simplify return logic from record_deleted_ref_if_needed() Date: Wed, 19 Feb 2025 11:43:17 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 96aa519e791a..b715557ec720 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4712,7 +4712,7 @@ static int record_new_ref_if_needed(u64 dir, struct fs_path *name, void *ctx) static int record_deleted_ref_if_needed(u64 dir, struct fs_path *name, void *ctx) { - int ret = 0; + int ret; struct send_ctx *sctx = ctx; struct rb_node *node = NULL; struct recorded_ref data; @@ -4721,7 +4721,7 @@ static int record_deleted_ref_if_needed(u64 dir, struct fs_path *name, void *ctx ret = get_inode_gen(sctx->parent_root, dir, &dir_gen); if (ret < 0) - goto out; + return ret; data.dir = dir; data.dir_gen = dir_gen; @@ -4735,7 +4735,7 @@ static int record_deleted_ref_if_needed(u64 dir, struct fs_path *name, void *ctx &sctx->deleted_refs, name, dir, dir_gen, sctx); } -out: + return ret; } From patchwork Wed Feb 19 11:43:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982013 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3851EB1B2 for ; Wed, 19 Feb 2025 11:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965429; cv=none; b=ddsplmmwgxEA4O7ulL1mgiZaU3tzOG9M8kqwTAbsiZUGTr0bJHuNX8ChfkgddWADjmxfJjiOkez19qvMyZN0s25GgvgxErj3/p7Mnoa1+dbDBW3r3NiVTUArQCS+T+gI7wZnG9PCekHqcz2kRLvRRFhWKMrrak7M6BwQhDRJ7CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965429; c=relaxed/simple; bh=Wyd5Wd89gnJUPIDlPqkGSgkK7n/wp64eKpdAMR3Jnzs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q7c6jE0pBKnaPdKD6+GzyK/4r5gs/EcGA4MNBWnYVYpqU9LwfrSPZhobMXsmewDPwCfhpZWTyHsA1sSsNgcx7hadrs4uubBL6e0XOTBixGRsEJEnCaYeAtXuufYYBGxhKqwCxLkeh/qlNyy8Grll2flBKHCBDDozkO8M2RgP7bM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cKwVKqB1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cKwVKqB1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 319D0C4CED1 for ; Wed, 19 Feb 2025 11:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965428; bh=Wyd5Wd89gnJUPIDlPqkGSgkK7n/wp64eKpdAMR3Jnzs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cKwVKqB16hcistaQYHW1acEd+hOyx7rv7cIIRn6tup1YE7HjQfU4MafD5bsHCnRCm 5KhjBqDeKcTJzJUKQBvOPIVlwa8abEmzAkSq/BnvsiR/nt9OJC8r3WN8qloqPH110o PdCncs7Pew/weFJXlmIj3tVO/G0psx9Xnd2L8AAG5VdHwgr9jEYEfz1ebtRS6NyUzO Fm5rtrxh1QWnuLRKZJQrnc8rFMr4Gw3xqJKonOlbBLK6lAIq+DsH3u67IV/aF2G8bn giY9BEkbYE/Yc0WIxQigMwu0oqjCmNNN+rrCdSzGUdvTRSlVIBuhdvabP4fi548FI4 FIWmdURN/1ZTQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 18/26] btrfs: send: simplify return logic from record_new_ref() Date: Wed, 19 Feb 2025 11:43:18 +0000 Message-Id: <7cacb1e6e74eaaafa92656b35d6ea00fd0fcebbc.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index b715557ec720..181a234e3a5e 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4746,11 +4746,9 @@ static int record_new_ref(struct send_ctx *sctx) ret = iterate_inode_ref(sctx->send_root, sctx->left_path, sctx->cmp_key, 0, record_new_ref_if_needed, sctx); if (ret < 0) - goto out; - ret = 0; + return ret; -out: - return ret; + return 0; } static int record_deleted_ref(struct send_ctx *sctx) From patchwork Wed Feb 19 11:43:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982014 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D52E71EB1B9 for ; Wed, 19 Feb 2025 11:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965429; cv=none; b=bmDliS2EjEBfzQvnuxnYk/JDpMb/nm5lWNOSsOyaNg9TsNIuHPNRTq6wOsvS0AMgUDYlY3GKqPUzvaNDGFqKFG5+lcIgkgeNNjpi0+I7pLkEAJFboj5bhZo3dTs48rzfdFz0dQ5IlHGPlHsIx/9j/eEK+A+fA5WFDj4XBc1ztc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965429; c=relaxed/simple; bh=bo65LBflfD+3mpw0tdqCeliFgx2TqnU6QVvpvc7mI6U=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kSo9WLZLuRw26TQWFdrmEolmEVtfzxo1u4YFnnrUwCLvu0kLLaotlhYki45O1i/NFEHeJ6dj+8WF6cfaEMVwPfkfN9SDRWM+4WfNxoEUht+7gVI5ClIxSYse08xOg7BMKkyOCLwd0NV61UHua9eHSmZChSTSS7/dk0t6Glp53zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PhKxwEML; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PhKxwEML" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3665AC4CEE7 for ; Wed, 19 Feb 2025 11:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965429; bh=bo65LBflfD+3mpw0tdqCeliFgx2TqnU6QVvpvc7mI6U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PhKxwEMLyhukAW2kXno4cuiXMMgT47L/e8ocPJDA2t0/3nFukTPytMOJK36eCYOrW q8cXTvD3e6rcW58x0y0ikdUucPNp1gAE+fRn5PBHvy0Wm01b/3O6xAdr7wGg6sC648 1y4HEICgeReG827WcI8T1Zrbhaqa5KVokKe3HV69wS5LDIvecvfRaj/gkl5KPyyo6x 2bDeFkVbDCsLEKtnPS8JcKW/uDbV88vJJugE4dJXd6M+Mdox4pgYqDjTdZ/EoNVCyf YoRuSuvSKRdJ8VxkWHR2X0l6kT7KLoYIo08P35rumiTmdfu8rir7arcXYBK2DQbHXH +5RAa8Mpt8CcQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 19/26] btrfs: send: simplify return logic from record_deleted_ref() Date: Wed, 19 Feb 2025 11:43:19 +0000 Message-Id: <1cc622c733eb7cc5dc54e640cc685a2998c596a9.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 181a234e3a5e..6e171b504415 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4759,11 +4759,9 @@ static int record_deleted_ref(struct send_ctx *sctx) sctx->cmp_key, 0, record_deleted_ref_if_needed, sctx); if (ret < 0) - goto out; - ret = 0; + return ret; -out: - return ret; + return 0; } static int record_changed_ref(struct send_ctx *sctx) From patchwork Wed Feb 19 11:43:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982015 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 460631E0E01 for ; Wed, 19 Feb 2025 11:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965431; cv=none; b=aqWlU8goGmlf1yOhuLVzzwYbioR5HiRR/ggW/XxKbrk+O9TXWngYbiBSdEcrPTtwTwAP8njCuJcW4R4+HCzWw2gdxUL7v16xjQFlVrJZ0z2d2qcVB9b2DnLP832QnK9TCJwrIabeIWRuZFb1flXY9LPa6WxMS4o6z9rPVlBtbWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965431; c=relaxed/simple; bh=wXsAxsgamsNQG+m9lr5ppecgeBVTHoTlfPbVpx8Orsc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A9Yl2KxtJMuvwp5yo5XSi5LtBKqpGcIu1sYxsW7l89DwqOxNfH7Evj1VAAQAAWhpttCM7ALBpkOF2qS0AAg+uSnQt5PurABRL6Wm6rH6RdOPHw6EAA5FdZfctvRE1CkuywWwehkoTwgt7q0lSwbGxB2g6jvWOpio3R2hVsEqUdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCrdRj+x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCrdRj+x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B041C4CEE7 for ; Wed, 19 Feb 2025 11:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965430; bh=wXsAxsgamsNQG+m9lr5ppecgeBVTHoTlfPbVpx8Orsc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TCrdRj+xBa9F5QXpJHgcJie+J7r4D/5aio8qCY4j+UPY1KEZVc559/lC3gBjfL2uU nteWf+rHadbfdIahjL1nh5T8qBPvhLGLeYcaAme0nqYr1siwPo2I/hfHRTKqQooLjc all5thIZTG+6wVEifx52be/pupWlFWQ0qks8KQB/8jUDFZJqYZumW/yOtxJnaig5vq Nf4f/5GeHq9L30e74J0eAadT04gIZhWOSVMxRBMO+XR6OeXpl3h0JMWOVME3JJTWmS ivKWQ//UlVV52TefmLbtYI936B1rL1MMGkOfO2nD5Si5DapblRO9XDoWiGrqdeFZaI dW2x6mpWsTudg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 20/26] btrfs: send: simplify return logic from record_changed_ref() Date: Wed, 19 Feb 2025 11:43:20 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 6e171b504415..01b8b570d6ed 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4766,20 +4766,18 @@ static int record_deleted_ref(struct send_ctx *sctx) static int record_changed_ref(struct send_ctx *sctx) { - int ret = 0; + int ret; ret = iterate_inode_ref(sctx->send_root, sctx->left_path, sctx->cmp_key, 0, record_new_ref_if_needed, sctx); if (ret < 0) - goto out; + return ret; ret = iterate_inode_ref(sctx->parent_root, sctx->right_path, sctx->cmp_key, 0, record_deleted_ref_if_needed, sctx); if (ret < 0) - goto out; - ret = 0; + return ret; -out: - return ret; + return 0; } /* From patchwork Wed Feb 19 11:43:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982016 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4B781EB5D5 for ; Wed, 19 Feb 2025 11:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965432; cv=none; b=UHcEcS2F9p2Av8IpqV/77rauuZR0juFthguiAFZRojlqRgZrNE+1bqV3qZ99pBOprxmijX7AMuBmcF8TfxfzsG7K+RlaOzI8rlk4DZXULp00x52SNp9bQSkmLpJltB1b0I22CsEVnMg6nODcAoAgdAv3JP5F4GVjW81xo8naXS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965432; c=relaxed/simple; bh=RzCBeOeEYPp3KthUnzogTIy1HdaiyHqUReO3IYXsSj4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nqGjyn05I0xJe/wRgofTmJvLvPwh2g5C3SSIo6pbZDBIa6vz8p+mY+mud0VqQO6AWz9CuUaT8I5tGU+dq6YUz58148h3drrLX1pV+f4bcse7MzbspKmhfTZqDI1mIMPJFHtGOu9fQlMYwzP+PYQmnKTzC+qDAbQj6gcM5HmKuUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VykFhWZA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VykFhWZA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4098EC4CEE6 for ; Wed, 19 Feb 2025 11:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965431; bh=RzCBeOeEYPp3KthUnzogTIy1HdaiyHqUReO3IYXsSj4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VykFhWZAWMdAUJ/hhh0Rx4TaLSpYVOV8rGdkbrUWR8ajfdZ4uin4CdVRBeVxwpEkW Oh065aP75Rs3S3GTtq2wLetcROapmilFan8BlbPP660QUFxMUsocb84+Rw7oCaJqDh Co5Sj9KltL684KdE/g7rRwu+vhetAQOkqtF95jzU4c1EAL3+mjXvj3/5NSxQAYO5X/ ld+f1DWUgwQy0iygWADuNSYxzyIrzN3+K4bxi5shiI0zqP8WQka9OLNmo4tWhNenAc 2wE6JlrmXjIPID6vNU3O4aqxfllhtzO0a3ho0tHoWOHsCxfee5rUPjkrrU47rPkX++ zel0mlEBou08g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 21/26] btrfs: send: remove unnecessary return variable from process_new_xattr() Date: Wed, 19 Feb 2025 11:43:21 +0000 Message-Id: <509d20faf13eaa4b44ec44c9402c56cbc54c3338.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There's no need for the 'ret' variable, we can just return directly the result of the call to iterate_dir_item(). Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 01b8b570d6ed..e29b5a5ccdd6 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4950,12 +4950,8 @@ static int __process_deleted_xattr(int num, struct btrfs_key *di_key, static int process_new_xattr(struct send_ctx *sctx) { - int ret = 0; - - ret = iterate_dir_item(sctx->send_root, sctx->left_path, - __process_new_xattr, sctx); - - return ret; + return iterate_dir_item(sctx->send_root, sctx->left_path, + __process_new_xattr, sctx); } static int process_deleted_xattr(struct send_ctx *sctx) From patchwork Wed Feb 19 11:43:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982017 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBED81EB9EF for ; Wed, 19 Feb 2025 11:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965433; cv=none; b=gvA724B0rVgqXyPhOnOFhlkRV/3XooisUoPtkwI3XHB3iWo7+A94fPK0LnQTjCBDux1lg3dlZe7cqC5hFTw66api+XaCUcZmRW9I9/ypwfIQCEsXlIX319iilve2KFR4OEO7BehDRFwSUAD8ch5rr6ZFwzxPuJdKjUPc+6gR758= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965433; c=relaxed/simple; bh=NJ2JgutmmQTjMHYytZ3fYMdgpi7FupvrNgUYg/RUnPg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ldOjUCsjGvWCgeASMTASeToPUSzO3MQXq4518F5XrDxEOX+WtQFUr3NSb9N8X9CCcEpVSgx5fFFgU0fdzuTcKjpAKR/rTJgu89TBccVM4rEuhtLazhhJHQCoASQhmPHIyXgBfoh2m999tYcv9BVIklH3e5hkPhCdl9hXbv4RJg0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eCi8TOdt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eCi8TOdt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46F74C4CEE6 for ; Wed, 19 Feb 2025 11:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965432; bh=NJ2JgutmmQTjMHYytZ3fYMdgpi7FupvrNgUYg/RUnPg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eCi8TOdtyqjaO2Sgs2Jm1KbymkSje09Wj62EWpvHpp4OL1o9ZR2Om73E2yoYjL1xx p/5VEhbvGStKHqPtCHWNaXasXg3j5YFdTmLSWV5L6Y5Jt0OXwSpwCkvPpaN4DH5E2C 2eJEKKhbY9oO/TT8tC5j9/yE4w3TmFSxApulL+LxqwEm6zpQzicqGNN0gM/JN5M3Qd VE8usr3lrkkw2C9WxKZbsrzA/WfdeKDczjEXzh/scvIoHM/Xi6iueK8jjMXGD+Bv4x eNmrYXisp9tHEn2lpVzPx2LajmHtnrghxX1UF/MnMQNhlDinIcFEwtBm92wGIKldHP 1pV5lBJwMORXw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 22/26] btrfs: send: simplify return logic from process_changed_xattr() Date: Wed, 19 Feb 2025 11:43:22 +0000 Message-Id: <4f86d440ff6e3975d86df4e119259d2bc4f3301d.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There is no need to have an 'out' label and jump into it since there are no resource cleanups to perform (release locks, free memory, etc), so make this simpler by removing the label and goto and instead return directly. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index e29b5a5ccdd6..0cbc8b5b6fab 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5067,17 +5067,15 @@ static int __process_changed_deleted_xattr(int num, struct btrfs_key *di_key, static int process_changed_xattr(struct send_ctx *sctx) { - int ret = 0; + int ret; ret = iterate_dir_item(sctx->send_root, sctx->left_path, __process_changed_new_xattr, sctx); if (ret < 0) - goto out; - ret = iterate_dir_item(sctx->parent_root, sctx->right_path, - __process_changed_deleted_xattr, sctx); + return ret; -out: - return ret; + return iterate_dir_item(sctx->parent_root, sctx->right_path, + __process_changed_deleted_xattr, sctx); } static int process_all_new_xattrs(struct send_ctx *sctx) From patchwork Wed Feb 19 11:43:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982018 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FB9C1E0E0A for ; Wed, 19 Feb 2025 11:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965434; cv=none; b=oHc4AvxudOfFJ6mTdXSRadVZGTczN7dcvzkrSCN8dJcLp2vkvIJCL7vGIZZf88MaqZsdjBalxni4gNX7ht6dMpAq4ZBN20XIBpG6d6eT1kCpAB9Q1s8kmct8S++dUO6p3qY85pDRA7uAHtKRO3gEQKvdpmAK3V5EOsGos/0kD74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965434; c=relaxed/simple; bh=Z0gnj+j7I6tesK3fs5Y4sZ2G4+laz1ers4iiF43Kdgs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cBaxfpE/ZBoNeNHOyigwnox21Q2WWFZi4YEUn0p+K7OstWBwLXLvEV6jrh+T26GKiaCOTD79RJPxKVcxcjVvhABM5PH2IiEAjlwB+E5Yg6kF9knt1S/YH86crGzWu6NOKh7d3B9jws+NrZUgS2kkHPYogRO5NL+b0ZDMpmnpUtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m2yTnNZT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m2yTnNZT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AE82C4CED1 for ; Wed, 19 Feb 2025 11:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965433; bh=Z0gnj+j7I6tesK3fs5Y4sZ2G4+laz1ers4iiF43Kdgs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m2yTnNZTJFfqb1Dt0oplMg8xMU2A0qeir++lEfN2Z8NKp4xCubfOyZPAvQr3gbzqy KNmCnbaiRUA6L+8Wmzofuy+E3BaTht79gqZCg5nyHIwA/9MXHe+4xthBBLAyvujrtj 8XcvtcfiyD4eGt3eiFlu7u1+hURmItA3pPBGDZ5XcLfFgMMCxZk0WMkzzGRUEa9byr gom/gAFy9YOzE73zTdc06DzNNpuIJcN1aDoLdnuf78lODkHA805gRh8tSiuAa2IyDG isft0r1Fflg1nKc44G/qVaWlhMn9e1CAvrWvCoUt4IXF7oWIcI3MI46kKho12YVfS9 fRIyWt/quE4dg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 23/26] btrfs: send: simplify return logic from send_verity() Date: Wed, 19 Feb 2025 11:43:23 +0000 Message-Id: <231e2cd5b7ff30e91c66cc72efd4d4564ed0deff.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There's no need for the 'out' label as there are no resources to cleanup in case of an error and we can directly return if begin_cmd() fails. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 0cbc8b5b6fab..f161e6a695bd 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -5122,7 +5122,7 @@ static int send_verity(struct send_ctx *sctx, struct fs_path *path, ret = begin_cmd(sctx, BTRFS_SEND_C_ENABLE_VERITY); if (ret < 0) - goto out; + return ret; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); TLV_PUT_U8(sctx, BTRFS_SEND_A_VERITY_ALGORITHM, @@ -5137,7 +5137,6 @@ static int send_verity(struct send_ctx *sctx, struct fs_path *path, ret = send_cmd(sctx); tlv_put_failure: -out: return ret; } From patchwork Wed Feb 19 11:43:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982019 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 070431EDA2C for ; Wed, 19 Feb 2025 11:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965435; cv=none; b=OsdCqibuD2DspBuA4l/SSCYv1NZ8wtDYZ6PNm1cJvXhZzZkiaxfjfThCgptVIMp5BaNnASW549pQJHBqPWDFpfUuOyQI90JpTeKnXbUyfxV/Ra81orU9OtZyZEgeCUmyhYSWrg2Tbjmg2nBiPbwCh3MSvjVq0EGjRW+263RL/6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965435; c=relaxed/simple; bh=hJI7VMR/Lc2dLgc0ARCoL3PyWcBx6mTHUMDxGS/UJ1k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U0cWABpQwR0DTBD7pwzI/9RXh5aNxzRjq4jbzVnjWJAc5qLWkxtV9/ji0kUC/lYYoJP1/wBlt9PogPzerdd7D7jV0RDvulrng9Hux59yzMpZbPKjjNNcztPJQzMqPBiHTE2j5CnFNj3/+7iCfKIptO5IXnmJeaxXdyPiY9fd2rs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FtypfmHo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FtypfmHo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50C73C4CEE6 for ; Wed, 19 Feb 2025 11:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965434; bh=hJI7VMR/Lc2dLgc0ARCoL3PyWcBx6mTHUMDxGS/UJ1k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FtypfmHop7TTR/eIQaf6wGPwpV/iPBv9Ib3/Yqi8gonj+edyYRHATRFvY32aS9WR5 X/wuO3mB3M0yaAIYowc5orpJDWfA2l5sll3Qdr+stBnkUkCh5jN0hxHPLWN6qdtAUC 4Kl9VHDXT5XhSvmIAshb/Lp6/CI4WgrjyyTyKXoD3+zcXMJQdtH1mQdEWfZJcKP8Wd yQ0YlLg27uGyiiy3mLXf42pRh78ERmepNPc81LMahiEcQ8uReoCW6FPkN5mOHih22V G5RE4E01oK1SRMP0lVfP3NhjQm8MEQSOu97WRaf4tolrxfuoMf8CxVA/FaGre1WLUP NoA5CCCAWVHIQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 24/26] btrfs: send: keep the current inode's path cached Date: Wed, 19 Feb 2025 11:43:24 +0000 Message-Id: <6dbeb0b889a40c60b985d5c07ee1e62901ce47aa.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Whenever we need to send a command for the current inode, like sending writes, xattr updates, truncates, utimes, etc, we compute the inode's path each time, which implies doing some memory allocations and traversing the inode hierarchy to extract the name of the inode and each ancestor directory, and that implies doing lookups in the subvolume tree amongst other operations. Most of the time, by far, the current inode's path doesn't change while we are processing it (like if we need to issue 100 write commands, the path remains the same and it's pointless to compute it 100 times). To avoid this keep the current inode's path cached in the send context and invalidate it or update it whenever it's needed (after unlinks or renames). A performance test, and its results, is mentioned in the next patch in the series (subject: "btrfs: send: avoid path allocation for the current inode when issuing commands"). Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 53 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index f161e6a695bd..0d0f073a9945 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -177,6 +177,7 @@ struct send_ctx { u64 cur_inode_rdev; u64 cur_inode_last_extent; u64 cur_inode_next_write_offset; + struct fs_path cur_inode_path; bool cur_inode_new; bool cur_inode_new_gen; bool cur_inode_deleted; @@ -433,6 +434,14 @@ static void fs_path_reset(struct fs_path *p) *p->start = 0; } +static void init_path(struct fs_path *p) +{ + p->reversed = 0; + p->buf = p->inline_buf; + p->buf_len = FS_PATH_INLINE_SIZE; + fs_path_reset(p); +} + static struct fs_path *fs_path_alloc(void) { struct fs_path *p; @@ -440,10 +449,7 @@ static struct fs_path *fs_path_alloc(void) p = kmalloc(sizeof(*p), GFP_KERNEL); if (!p) return NULL; - p->reversed = 0; - p->buf = p->inline_buf; - p->buf_len = FS_PATH_INLINE_SIZE; - fs_path_reset(p); + init_path(p); return p; } @@ -609,6 +615,14 @@ static void fs_path_unreverse(struct fs_path *p) p->reversed = 0; } +static inline bool is_current_inode_path(const struct send_ctx *sctx, + const struct fs_path *path) +{ + const struct fs_path *cur = &sctx->cur_inode_path; + + return (strncmp(path->start, cur->start, fs_path_len(cur)) == 0); +} + static struct btrfs_path *alloc_path_for_send(void) { struct btrfs_path *path; @@ -2419,6 +2433,14 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, u64 parent_inode = 0; u64 parent_gen = 0; int stop = 0; + const bool is_cur_inode = (ino == sctx->cur_ino && gen == sctx->cur_inode_gen); + + if (is_cur_inode && fs_path_len(&sctx->cur_inode_path) > 0) { + if (dest != &sctx->cur_inode_path) + return fs_path_copy(dest, &sctx->cur_inode_path); + + return 0; + } name = fs_path_alloc(); if (!name) { @@ -2470,8 +2492,12 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, out: fs_path_free(name); - if (!ret) + if (!ret) { fs_path_unreverse(dest); + if (is_cur_inode && dest != &sctx->cur_inode_path) + ret = fs_path_copy(&sctx->cur_inode_path, dest); + } + return ret; } @@ -3081,6 +3107,11 @@ static int orphanize_inode(struct send_ctx *sctx, u64 ino, u64 gen, goto out; ret = send_rename(sctx, path, orphan); + if (ret < 0) + goto out; + + if (ino == sctx->cur_ino && gen == sctx->cur_inode_gen) + ret = fs_path_copy(&sctx->cur_inode_path, orphan); out: fs_path_free(orphan); @@ -4143,6 +4174,10 @@ static int rename_current_inode(struct send_ctx *sctx, if (ret < 0) return ret; + ret = fs_path_copy(&sctx->cur_inode_path, new_path); + if (ret < 0) + return ret; + return fs_path_copy(current_path, new_path); } @@ -4336,6 +4371,7 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) if (ret > 0) { orphanized_ancestor = true; fs_path_reset(valid_path); + fs_path_reset(&sctx->cur_inode_path); ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, valid_path); @@ -4535,6 +4571,8 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) ret = send_unlink(sctx, cur->full_path); if (ret < 0) goto out; + if (is_current_inode_path(sctx, cur->full_path)) + fs_path_reset(&sctx->cur_inode_path); } ret = dup_ref(cur, &check_dirs); if (ret < 0) @@ -6855,6 +6893,7 @@ static int changed_inode(struct send_ctx *sctx, sctx->cur_inode_last_extent = (u64)-1; sctx->cur_inode_next_write_offset = 0; sctx->ignore_cur_inode = false; + fs_path_reset(&sctx->cur_inode_path); /* * Set send_progress to current inode. This will tell all get_cur_xxx @@ -8130,6 +8169,7 @@ long btrfs_ioctl_send(struct btrfs_inode *inode, const struct btrfs_ioctl_send_a goto out; } + init_path(&sctx->cur_inode_path); INIT_LIST_HEAD(&sctx->new_refs); INIT_LIST_HEAD(&sctx->deleted_refs); @@ -8406,6 +8446,9 @@ long btrfs_ioctl_send(struct btrfs_inode *inode, const struct btrfs_ioctl_send_a btrfs_lru_cache_clear(&sctx->dir_created_cache); btrfs_lru_cache_clear(&sctx->dir_utimes_cache); + if (sctx->cur_inode_path.buf != sctx->cur_inode_path.inline_buf) + kfree(sctx->cur_inode_path.buf); + kfree(sctx); } From patchwork Wed Feb 19 11:43:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982020 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5603E1E0E14 for ; Wed, 19 Feb 2025 11:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965436; cv=none; b=Wrn5AHitptICjpishCy0D8YqigoeTAeAULbJX8ifcrcOE3a4i/qVl3XlCe6ZRJ24Wqhp/4EuZ7PFUpoXXpYSqPB5mO3YPbN/lQRbnPfFHov6685h3OBFPvX/YDPKbVfDOoAYfhS5iqUtivm6zDgqUpG8LcGrMo/SjbOJEm57moQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965436; c=relaxed/simple; bh=qZLXRMol7cKJAATfbXYqjE89kDD+9HX1zG+TvSu0SSA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L/eZCqpm1gZ4LUW7hRRBej1auWqtQw2E6T0fCzOwTznVBHPVo8r27EFdYy2aH0eRbV6Tx2DmD2iiy8LwWRlTBkYFGUVRhVc+2z3zM4ELZaZ7pZjYukHREDkOtLkIcv4h+Sy4CFmDJEqPA8oQmlk0r9mFbI3dASbCWEIiWRxvb5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jWW9fytB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jWW9fytB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55F30C4CEE7 for ; Wed, 19 Feb 2025 11:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965435; bh=qZLXRMol7cKJAATfbXYqjE89kDD+9HX1zG+TvSu0SSA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jWW9fytB3Z5SQZn94Q8MqNiTU9DImevH+yOn0Q+QYJpnjHzFtAli5fAunbkiYdaM5 8DBHP4/snaTN7RcdpumjimsfOwU41TKHklB4HbLAiocBqM7ERwTEh81G8SFZfFuqHr h0lLuLBaP0EaRY+ZhOLBCHNUqZ8xRqs1LlCFo4G/aVHww6GID3eXlDAnihVKP//hRN KKx5KaNmaFsxRfFP+d7MZCs9UN0d5H3Bp76HMe/MP6IBtoJHJ1GJOLDGS7BJFlMnnh 7z5++IuvsmdVUWsZRHRirRxLUqX2aAStD2Qr61mrcXdSnOPPQoMhZEjSEpFfLB6GeL GbXd4zuwoFUFg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 25/26] btrfs: send: avoid path allocation for the current inode when issuing commands Date: Wed, 19 Feb 2025 11:43:25 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Whenever we issue a command we allocate a path and then compute it. For the current inode this is not necessary since we have one preallocated and computed in the send context structure, so we can use it instead and avoid allocating and freeing a path. For example if we have 100 extents to send (100 write commands) for a file, we are allocating and freeing paths 100 times. So improve on this by avoiding path allocation and freeing whenever a command is for the current inode by using the current inode's path stored in the send context structure. A test was run before applying this patch and the previous one in the series: "btrfs: send: keep the current inode's path cached" The test script is the following: $ cat test.sh #!/bin/bash DEV=/dev/nullb0 MNT=/mnt/nullb0 mkfs.btrfs -f $DEV > /dev/null mount $DEV $MNT DIR="$MNT/one/two/three/four" FILE="$DIR/foobar" mkdir -p $DIR # Create some empty files to get a deeper btree and therefore make # path computations slower. for ((i = 1; i <= 30000; i++)); do echo -n > "$DIR/filler_$i" done for ((i = 0; i < 10000; i += 2)); do offset=$(( i * 4096 )) xfs_io -f -c "pwrite -S 0xab $offset 4K" $FILE > /dev/null done btrfs subvolume snapshot -r $MNT $MNT/snap start=$(date +%s%N) btrfs send -f /dev/null $MNT/snap end=$(date +%s%N) echo -e "\nsend took $(( (end - start) / 1000000 )) milliseconds" umount $MNT Result before applying the 2 patches: 1121 milliseconds Result after applying the 2 patches: 815 milliseconds (-31.6%) Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 215 ++++++++++++++++++++++-------------------------- 1 file changed, 97 insertions(+), 118 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 0d0f073a9945..77cedde3b57b 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2592,6 +2592,47 @@ static int send_subvol_begin(struct send_ctx *sctx) return ret; } +static struct fs_path *get_cur_inode_path(struct send_ctx *sctx) +{ + if (fs_path_len(&sctx->cur_inode_path) == 0) { + int ret; + + ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, + &sctx->cur_inode_path); + if (ret < 0) + return ERR_PTR(ret); + } + + return &sctx->cur_inode_path; +} + +static struct fs_path *get_path_for_command(struct send_ctx *sctx, u64 ino, u64 gen) +{ + struct fs_path *path; + int ret; + + if (ino == sctx->cur_ino && gen == sctx->cur_inode_gen) + return get_cur_inode_path(sctx); + + path = fs_path_alloc(); + if (!path) + return ERR_PTR(-ENOMEM); + + ret = get_cur_path(sctx, ino, gen, path); + if (ret < 0) { + fs_path_free(path); + return ERR_PTR(ret); + } + + return path; +} + +static void free_path_for_command(const struct send_ctx *sctx, struct fs_path *path) +{ + if (path != &sctx->cur_inode_path) + fs_path_free(path); +} + static int send_truncate(struct send_ctx *sctx, u64 ino, u64 gen, u64 size) { struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; @@ -2600,17 +2641,14 @@ static int send_truncate(struct send_ctx *sctx, u64 ino, u64 gen, u64 size) btrfs_debug(fs_info, "send_truncate %llu size=%llu", ino, size); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_path_for_command(sctx, ino, gen); + if (IS_ERR(p)) + return PTR_ERR(p); ret = begin_cmd(sctx, BTRFS_SEND_C_TRUNCATE); if (ret < 0) goto out; - ret = get_cur_path(sctx, ino, gen, p); - if (ret < 0) - goto out; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_SIZE, size); @@ -2618,7 +2656,7 @@ static int send_truncate(struct send_ctx *sctx, u64 ino, u64 gen, u64 size) tlv_put_failure: out: - fs_path_free(p); + free_path_for_command(sctx, p); return ret; } @@ -2630,17 +2668,14 @@ static int send_chmod(struct send_ctx *sctx, u64 ino, u64 gen, u64 mode) btrfs_debug(fs_info, "send_chmod %llu mode=%llu", ino, mode); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_path_for_command(sctx, ino, gen); + if (IS_ERR(p)) + return PTR_ERR(p); ret = begin_cmd(sctx, BTRFS_SEND_C_CHMOD); if (ret < 0) goto out; - ret = get_cur_path(sctx, ino, gen, p); - if (ret < 0) - goto out; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_MODE, mode & 07777); @@ -2648,7 +2683,7 @@ static int send_chmod(struct send_ctx *sctx, u64 ino, u64 gen, u64 mode) tlv_put_failure: out: - fs_path_free(p); + free_path_for_command(sctx, p); return ret; } @@ -2663,17 +2698,14 @@ static int send_fileattr(struct send_ctx *sctx, u64 ino, u64 gen, u64 fileattr) btrfs_debug(fs_info, "send_fileattr %llu fileattr=%llu", ino, fileattr); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_path_for_command(sctx, ino, gen); + if (IS_ERR(p)) + return PTR_ERR(p); ret = begin_cmd(sctx, BTRFS_SEND_C_FILEATTR); if (ret < 0) goto out; - ret = get_cur_path(sctx, ino, gen, p); - if (ret < 0) - goto out; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_FILEATTR, fileattr); @@ -2681,7 +2713,7 @@ static int send_fileattr(struct send_ctx *sctx, u64 ino, u64 gen, u64 fileattr) tlv_put_failure: out: - fs_path_free(p); + free_path_for_command(sctx, p); return ret; } @@ -2694,17 +2726,14 @@ static int send_chown(struct send_ctx *sctx, u64 ino, u64 gen, u64 uid, u64 gid) btrfs_debug(fs_info, "send_chown %llu uid=%llu, gid=%llu", ino, uid, gid); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_path_for_command(sctx, ino, gen); + if (IS_ERR(p)) + return PTR_ERR(p); ret = begin_cmd(sctx, BTRFS_SEND_C_CHOWN); if (ret < 0) goto out; - ret = get_cur_path(sctx, ino, gen, p); - if (ret < 0) - goto out; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_UID, uid); TLV_PUT_U64(sctx, BTRFS_SEND_A_GID, gid); @@ -2713,7 +2742,7 @@ static int send_chown(struct send_ctx *sctx, u64 ino, u64 gen, u64 uid, u64 gid) tlv_put_failure: out: - fs_path_free(p); + free_path_for_command(sctx, p); return ret; } @@ -2730,9 +2759,9 @@ static int send_utimes(struct send_ctx *sctx, u64 ino, u64 gen) btrfs_debug(fs_info, "send_utimes %llu", ino); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_path_for_command(sctx, ino, gen); + if (IS_ERR(p)) + return PTR_ERR(p); path = alloc_path_for_send(); if (!path) { @@ -2757,9 +2786,6 @@ static int send_utimes(struct send_ctx *sctx, u64 ino, u64 gen) if (ret < 0) goto out; - ret = get_cur_path(sctx, ino, gen, p); - if (ret < 0) - goto out; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_ATIME, eb, &ii->atime); TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_MTIME, eb, &ii->mtime); @@ -2771,7 +2797,7 @@ static int send_utimes(struct send_ctx *sctx, u64 ino, u64 gen) tlv_put_failure: out: - fs_path_free(p); + free_path_for_command(sctx, p); btrfs_free_path(path); return ret; } @@ -4889,13 +4915,9 @@ static int send_set_xattr(struct send_ctx *sctx, struct fs_path *path; int ret; - path = fs_path_alloc(); - if (!path) - return -ENOMEM; - - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, path); - if (ret < 0) - goto out; + path = get_cur_inode_path(sctx); + if (IS_ERR(path)) + return PTR_ERR(path); ret = begin_cmd(sctx, BTRFS_SEND_C_SET_XATTR); if (ret < 0) @@ -4909,8 +4931,6 @@ static int send_set_xattr(struct send_ctx *sctx, tlv_put_failure: out: - fs_path_free(path); - return ret; } @@ -4967,23 +4987,14 @@ static int __process_deleted_xattr(int num, struct btrfs_key *di_key, const char *name, int name_len, const char *data, int data_len, void *ctx) { - int ret; struct send_ctx *sctx = ctx; struct fs_path *p; - p = fs_path_alloc(); - if (!p) - return -ENOMEM; - - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto out; - - ret = send_remove_xattr(sctx, p, name, name_len); + p = get_cur_inode_path(sctx); + if (IS_ERR(p)) + return PTR_ERR(p); -out: - fs_path_free(p); - return ret; + return send_remove_xattr(sctx, p, name, name_len); } static int process_new_xattr(struct send_ctx *sctx) @@ -5209,21 +5220,13 @@ static int process_verity(struct send_ctx *sctx) if (ret < 0) goto iput; - p = fs_path_alloc(); - if (!p) { - ret = -ENOMEM; + p = get_cur_inode_path(sctx); + if (IS_ERR(p)) { + ret = PTR_ERR(p); goto iput; } - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto free_path; ret = send_verity(sctx, p, sctx->verity_descriptor); - if (ret < 0) - goto free_path; - -free_path: - fs_path_free(p); iput: iput(inode); return ret; @@ -5345,31 +5348,25 @@ static int send_write(struct send_ctx *sctx, u64 offset, u32 len) int ret = 0; struct fs_path *p; - p = fs_path_alloc(); - if (!p) - return -ENOMEM; - btrfs_debug(fs_info, "send_write offset=%llu, len=%d", offset, len); - ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE); - if (ret < 0) - goto out; + p = get_cur_inode_path(sctx); + if (IS_ERR(p)) + return PTR_ERR(p); - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); + ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE); if (ret < 0) - goto out; + return ret; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); ret = put_file_data(sctx, offset, len); if (ret < 0) - goto out; + return ret; ret = send_cmd(sctx); tlv_put_failure: -out: - fs_path_free(p); return ret; } @@ -5382,6 +5379,7 @@ static int send_clone(struct send_ctx *sctx, { int ret = 0; struct fs_path *p; + struct fs_path *cur_inode_path; u64 gen; btrfs_debug(sctx->send_root->fs_info, @@ -5389,6 +5387,10 @@ static int send_clone(struct send_ctx *sctx, offset, len, btrfs_root_id(clone_root->root), clone_root->ino, clone_root->offset); + cur_inode_path = get_cur_inode_path(sctx); + if (IS_ERR(cur_inode_path)) + return PTR_ERR(cur_inode_path); + p = fs_path_alloc(); if (!p) return -ENOMEM; @@ -5397,13 +5399,9 @@ static int send_clone(struct send_ctx *sctx, if (ret < 0) goto out; - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto out; - TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_LEN, len); - TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); + TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, cur_inode_path); if (clone_root->root == sctx->send_root) { ret = get_inode_gen(sctx->send_root, clone_root->ino, &gen); @@ -5454,17 +5452,13 @@ static int send_update_extent(struct send_ctx *sctx, int ret = 0; struct fs_path *p; - p = fs_path_alloc(); - if (!p) - return -ENOMEM; + p = get_cur_inode_path(sctx); + if (IS_ERR(p)) + return PTR_ERR(p); ret = begin_cmd(sctx, BTRFS_SEND_C_UPDATE_EXTENT); if (ret < 0) - goto out; - - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto out; + return ret; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); @@ -5473,8 +5467,6 @@ static int send_update_extent(struct send_ctx *sctx, ret = send_cmd(sctx); tlv_put_failure: -out: - fs_path_free(p); return ret; } @@ -5503,12 +5495,10 @@ static int send_hole(struct send_ctx *sctx, u64 end) if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) return send_update_extent(sctx, offset, end - offset); - p = fs_path_alloc(); - if (!p) - return -ENOMEM; - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); - if (ret < 0) - goto tlv_put_failure; + p = get_cur_inode_path(sctx); + if (IS_ERR(p)) + return PTR_ERR(p); + while (offset < end) { u64 len = min(end - offset, read_size); @@ -5529,7 +5519,6 @@ static int send_hole(struct send_ctx *sctx, u64 end) } sctx->cur_inode_next_write_offset = offset; tlv_put_failure: - fs_path_free(p); return ret; } @@ -5552,9 +5541,9 @@ static int send_encoded_inline_extent(struct send_ctx *sctx, if (IS_ERR(inode)) return PTR_ERR(inode); - fspath = fs_path_alloc(); - if (!fspath) { - ret = -ENOMEM; + fspath = get_cur_inode_path(sctx); + if (IS_ERR(fspath)) { + ret = PTR_ERR(fspath); goto out; } @@ -5562,10 +5551,6 @@ static int send_encoded_inline_extent(struct send_ctx *sctx, if (ret < 0) goto out; - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); - if (ret < 0) - goto out; - btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); ram_bytes = btrfs_file_extent_ram_bytes(leaf, ei); @@ -5594,7 +5579,6 @@ static int send_encoded_inline_extent(struct send_ctx *sctx, tlv_put_failure: out: - fs_path_free(fspath); iput(inode); return ret; } @@ -5619,9 +5603,9 @@ static int send_encoded_extent(struct send_ctx *sctx, struct btrfs_path *path, if (IS_ERR(inode)) return PTR_ERR(inode); - fspath = fs_path_alloc(); - if (!fspath) { - ret = -ENOMEM; + fspath = get_cur_inode_path(sctx); + if (IS_ERR(fspath)) { + ret = PTR_ERR(fspath); goto out; } @@ -5629,10 +5613,6 @@ static int send_encoded_extent(struct send_ctx *sctx, struct btrfs_path *path, if (ret < 0) goto out; - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); - if (ret < 0) - goto out; - btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, ei); @@ -5700,7 +5680,6 @@ static int send_encoded_extent(struct send_ctx *sctx, struct btrfs_path *path, tlv_put_failure: out: - fs_path_free(fspath); iput(inode); return ret; } From patchwork Wed Feb 19 11:43:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13982021 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66A861E0E14 for ; Wed, 19 Feb 2025 11:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965438; cv=none; b=cAbARD+sM1XH4+oz82t/uDVn6eo6F4QWHpCxdlRj050IdOIV2XdYwSkEdK3m116dQirT4NEuUyfc4xoUYmvkJ3Mv+UtFq4wrFeiG2QIITh//CjvXv2k+jho/75mp1G/AOwB/SmvH+ld/ZkzexsHlldopso28uDslGa37dcVxqFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739965438; c=relaxed/simple; bh=K8Ukr01cAjFbIg5qr8bYihKjLwaKbXAP5/76TP5tZCE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=arlTenW1rW92Xhpso1ZuVwzjeOEEmwN+iUQ2kRjSrTJB9zAjtlt8kWwCd9lcUmJ2eiZxQpuN7jM4t6g/6UG8uXgdN9okrmUMsgkKUdHkp/tbnRI7mERTVtBPniuhgbusE1F7FlHwfhW11/cKmkZwDJaB7XzN8Zz8+YMGIEZ7Bdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OT8w3d5I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OT8w3d5I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BB9CC4CED1 for ; Wed, 19 Feb 2025 11:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739965436; bh=K8Ukr01cAjFbIg5qr8bYihKjLwaKbXAP5/76TP5tZCE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OT8w3d5I6SqtgsWF0uh2vxBrxwqgnQyDxhtgXj3NiYRnryz4T1kx4NdzA5lZdFcuM BhpKDd55GXZ/dH5oE4EWDbrhJ+K0XlZk39zWxNGF/jINx3bTmHA79NK8JNVQqbWdNP UBNXhWlJ/d8CKEUJQU5CblSM9KM1OeYmOZV+qcS7vmwz2QBseM97xqLOUmQYdAmCFg KdcVKpJzCJp3JSYHu0H7qTYi6IDv/WWDq8ziJGbQ3RSqFYdN2s9MibRbkqvC1kHxzP 80sIRibpDKcZsBzFza8nN8DRl6D6wSY+ZcHzJ8KHIXZZia4T8b5frYmtnwUR5w+wgr Ya9aWfXgBL1TA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 26/26] btrfs: send: simplify return logic from send_set_xattr() Date: Wed, 19 Feb 2025 11:43:26 +0000 Message-Id: <4638c8874946aca59742d03715284a3358656b77.1739965104.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana There's no longer any need for the 'out' label as there are no resources to cleanup anymore in case of an error and we can directly return if begin_cmd() fails. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 77cedde3b57b..644172f1cdb0 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4921,7 +4921,7 @@ static int send_set_xattr(struct send_ctx *sctx, ret = begin_cmd(sctx, BTRFS_SEND_C_SET_XATTR); if (ret < 0) - goto out; + return ret; TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); TLV_PUT_STRING(sctx, BTRFS_SEND_A_XATTR_NAME, name, name_len); @@ -4930,7 +4930,6 @@ static int send_set_xattr(struct send_ctx *sctx, ret = send_cmd(sctx); tlv_put_failure: -out: return ret; }