Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2467275imw; Wed, 6 Jul 2022 06:30:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAsbiWgXvSrIOagYU7ba5fmQoEBTGFbBbpgmIOnHESEs1Iqt8wCkG3m1dcnBAHAkbFRUcC X-Received: by 2002:a17:90b:384f:b0:1ed:32be:7893 with SMTP id nl15-20020a17090b384f00b001ed32be7893mr49644752pjb.211.1657114239229; Wed, 06 Jul 2022 06:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657114239; cv=none; d=google.com; s=arc-20160816; b=S/bZ0wpq7Jj+5PzBuaeJevGvFbRz2EMiYDSRrdikcXSVul2U6/LZzKwgNoidY5ND+E CWV8BFFJIal25gHNLjNBQqyAyQYkpGuogHxuYd0rAgt/H1dpRgmVaNgwtx1dOR7JMdBq ZwgApw2cd2JLj8vCtUken+pgQBYsCOtfTvGuY63UDrBWmjvlMrN+VLquTuQQlKcaGMUd dmxcEMaOOECKnGpQyzNdK/MvvKh4TTfCCZL8MszuKTS/Dkk7zelfSgkvmzodIbih+8Ne qLEUm7990x60ECPPO/ON+slkgLxEVzMfJxwENV7SI2XFi0L/R4teRawyr+NkmfH0k80g 8Ilg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LhkC3vRuNuPmOjUTu0YnSNsOJurAVIvlOtG3Gd0/gPM=; b=QLYg9VIiHY78iwR/2s8Vdu5OLIWII11YZC15kVXPym9Qcho36QM72F33+LkOu+nBEN 2znO5IPt42wDYZ4PlvG0xdMxqX0jn770Z6kuKfInG1/KwdNGPLF28D7b28JiWvtxO0U2 smWoVZ7VeZPBVm3CJthaWOVT1gwj+56PZ15JD4VaGpTicoelgbv1tztU8J8mLrzRR2ex EzsIWlrfVygS0YPmjN0STywJlXUpKLR/UV4Sg15+4RbNX4vkhaBlrNHCzEnkPPAlC58u GjUoALfE27yAmuX02qmJQBB1tcSMoguxPMgyZIchhLHij0iW6qtpLrpYizPKpvW9zviI 5Ubw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=KKUzzIjJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a656c12000000b0040ce4de349csi53322030pgu.291.2022.07.06.06.30.26; Wed, 06 Jul 2022 06:30:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=KKUzzIjJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbiGFNPo (ORCPT + 99 others); Wed, 6 Jul 2022 09:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbiGFNPj (ORCPT ); Wed, 6 Jul 2022 09:15:39 -0400 Received: from synology.com (mail.synology.com [211.23.38.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 134DB5F77; Wed, 6 Jul 2022 06:15:38 -0700 (PDT) Received: from localhost.localdomain (unknown [10.17.41.204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id 7BF261BA23679; Wed, 6 Jul 2022 21:10:14 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1657113014; bh=mrQNKI4KC3vKIi8mGBtl801ZRNnPh+3BDudhW/ttL10=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KKUzzIjJi/bFhFkStKvW7z7PKXookZURXDHR5Cr7D/7LbzkPRt6D2G/NPZCBh8UAM dGHqgR/h3WyuQPl+0Gh+msi0QouLYwmyhbHsT8zQy2mjGsDqIV0E7l/u/MRN5zyp0K nX/lLZQJ28gINnHhE72d2lEcnmF0s1Lg7xMejCnc= From: bingjingc To: josef@toxicpanda.com, dsterba@suse.com, clm@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bingjingc@synology.com, robbieko@synology.com, bxxxjxxg@gmail.com Subject: [PATCH 1/2] btrfs: send: introduce recorded_ref_alloc and recorded_ref_free Date: Wed, 6 Jul 2022 21:09:02 +0800 Message-Id: <20220706130903.1661-2-bingjingc@synology.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220706130903.1661-1-bingjingc@synology.com> References: <20220706130903.1661-1-bingjingc@synology.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: BingJing Chang Introduce wrappers to allocate and free struct recorded_ref*. Reviewed-by: Robbie Ko Signed-off-by: BingJing Chang --- fs/btrfs/send.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index fa56890ff81f..420a86720aa2 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2749,6 +2749,26 @@ struct recorded_ref { int name_len; }; +static struct recorded_ref *recorded_ref_alloc(void) +{ + struct recorded_ref *ref; + + ref = kzalloc(sizeof(*ref), GFP_KERNEL); + if (!ref) + return NULL; + INIT_LIST_HEAD(&ref->list); + return ref; +} + +static void recorded_ref_free(struct recorded_ref *ref) +{ + if (!ref) + return; + list_del(&ref->list); + fs_path_free(ref->full_path); + kfree(ref); +} + static void set_ref_path(struct recorded_ref *ref, struct fs_path *path) { ref->full_path = path; @@ -2766,7 +2786,7 @@ static int __record_ref(struct list_head *head, u64 dir, { struct recorded_ref *ref; - ref = kmalloc(sizeof(*ref), GFP_KERNEL); + ref = recorded_ref_alloc(); if (!ref) return -ENOMEM; @@ -2781,14 +2801,12 @@ static int dup_ref(struct recorded_ref *ref, struct list_head *list) { struct recorded_ref *new; - new = kmalloc(sizeof(*ref), GFP_KERNEL); + new = recorded_ref_alloc(); if (!new) return -ENOMEM; new->dir = ref->dir; new->dir_gen = ref->dir_gen; - new->full_path = NULL; - INIT_LIST_HEAD(&new->list); list_add_tail(&new->list, list); return 0; } @@ -2799,9 +2817,7 @@ static void __free_recorded_refs(struct list_head *head) while (!list_empty(head)) { cur = list_entry(head->next, struct recorded_ref, list); - fs_path_free(cur->full_path); - list_del(&cur->list); - kfree(cur); + recorded_ref_free(cur); } } @@ -6216,9 +6232,7 @@ static int btrfs_unlink_all_paths(struct send_ctx *sctx) ret = send_unlink(sctx, ref->full_path); if (ret < 0) goto out; - fs_path_free(ref->full_path); - list_del(&ref->list); - kfree(ref); + recorded_ref_free(ref); } ret = 0; out: -- 2.37.0