Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1093084ybj; Thu, 7 May 2020 14:47:24 -0700 (PDT) X-Google-Smtp-Source: APiQypIW8ffj+MwY08N2PQvsY/dILpGI9lwZj0Hboool1CeAGEww7htxqqtizPN2aD/nO0P6aspM X-Received: by 2002:a05:6402:391:: with SMTP id o17mr14110074edv.71.1588888044389; Thu, 07 May 2020 14:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588888044; cv=none; d=google.com; s=arc-20160816; b=fGrs4ctAYheqTIps7dryqEtXdycRn2kJ7ahsGuJf4lDLUnzGtGpj+ow0aoBPy8KZLf xvHWaFN8L0uJ7lIEj1tC4kiZxgJJrjP0sWu+JKllF1WR6RCmcFuG20+ZroKOKjZV5s71 FmC5Pvey3TlJlYyT/N/nInR9iXg1P1toep2Ihg/pVyLhFWEcV5fcY/2OSbBNdNNgYPLa hBaF+Wsa24bbld9wKQdi8HGPNMdkaY9tnt2No0KpwtyjRbnHYbJGigImn4PyUzxyYGR0 kVpSnIX/Uvg/s7wkCvT90HkaFyoPYWjeurAcP+nXmdLFkFJQIhIPMqb83T1a1ti2RUEm oEng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5bOWsbby9E+qmMGJsuMwgUAgEfU2kO6P0jdaZ6pAtUk=; b=sT3BrpDuwlXg2zJ4DHPuaIOYz2aZx9Vdz9NCcxYeS8YaBmRZpZvkoaWbI3EatFXX7W VkRJ81UgfzBvAUU0W+z3eDck+a3VvKrF2rCtcIU+vDZG24DkKjgIivMRvsXFWFG264zR rn7UyeWqkP7PreW0ofZQmdxoa88YKXeb/GHkOPIoFcU/VkcySWQ2On9UPdn7z2SKEkhY 8UIHFOqL3bj5CGF7roBC4DMd+KUlSyE7TDxvkA412OWLXBzEvwByuamH4t0zgWDuqmbF UVyBibY7Jienl9sG2q8f7M3Gb259YI3c1jVCJA4w7NRtCZy0eBIy4m8Zx/1mwT/WvDRV 4Qhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=byF7VyPn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si3737656ejw.403.2020.05.07.14.47.01; Thu, 07 May 2020 14:47:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=byF7VyPn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgEGVo5 (ORCPT + 99 others); Thu, 7 May 2020 17:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727029AbgEGVoW (ORCPT ); Thu, 7 May 2020 17:44:22 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0598C05BD43 for ; Thu, 7 May 2020 14:44:21 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id pg17so5883660ejb.9 for ; Thu, 07 May 2020 14:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5bOWsbby9E+qmMGJsuMwgUAgEfU2kO6P0jdaZ6pAtUk=; b=byF7VyPnLI+nh2I1eprmmNFINZ+NJ5pkCzxdpNRuekTuNjT51vhh3CkV59wkiwN6XH krwChNxiVaVptfaH/K+bCu0LY0cnQl5xilBXoOas9PauRDAkXOKPqe01yfPQuPx1XduZ A0TAiHE+AOTm+JRQPZP2nACr3Ul4ObfdoQGrxi+Cpr1bPzmZoE1CWkqpf+/r3ex3IIW2 yZD1J7LPkidCeei/H6Hf6xaOAj2urjtMyLqyv0kw8rUdyUIpSq2wMms6dl/9ktOCl4VB 9T6Fo6/2uYHMb6SPeVBuh+nwu7QH+Z1b83muCKIBcRYEGskyNZwNJKFacUigra42hXmQ eB9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5bOWsbby9E+qmMGJsuMwgUAgEfU2kO6P0jdaZ6pAtUk=; b=bwbWHYwv8ayLLU1cA7imRJpsZ7dyEn94AHwr8a6AF5nHlnXvfX/jex6GvAm22+JG84 v6b1SoQRJVxbq9rQERuiHSc2ZEoyqzu2r6WR7VChC8EpdNzU/IFilW//7WE4Va9Qu/15 PoR73jvqCUBTRTRaOZT/BQzZp7kf3GBoIGJd6whZ7zbWXq9ILVm2yH5FKchnyKU6dHMp o1+i5f51ctW4KPiiA80Kv4Pure2PGU223lzC3IqoA6BpCC7IMKUbcKl//W5CBdQt3CfT R2nUe/hoRapoOGz1sdIglo6JAm4S+yBXEfdYBpqfO5vPchXKk4lEZpazS/S5ANv9DwA/ HBgw== X-Gm-Message-State: AGi0PubhtPc5MFWYH1HWwrl7J7Tyx2foimWaESCOGxprDbWUSH35WpbC RwiswQQlO29sEs/rJfkdaFJAyg== X-Received: by 2002:a17:906:3952:: with SMTP id g18mr14340273eje.191.1588887860372; Thu, 07 May 2020 14:44:20 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:a1ee:a39a:b93a:c084]) by smtp.gmail.com with ESMTPSA id k3sm613530edi.60.2020.05.07.14.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 14:44:19 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: david@fromorbit.com, hch@infradead.org, willy@infradead.org, Guoqing Jiang , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [RFC PATCH V3 03/10] btrfs: use attach/detach_page_private Date: Thu, 7 May 2020 23:43:53 +0200 Message-Id: <20200507214400.15785-4-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com> References: <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the new pair function is introduced, we can call them to clean the code in btrfs. Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Signed-off-by: Guoqing Jiang --- RFC V2 -> RFC V3 1. rename clear_page_private to detach_page_private. RFC -> RFC V2 1. change the name of new functions to attach/clear_page_private. 2. call attach_page_private(newpage, clear_page_private(page)) to cleanup code further as suggested by Dave Chinner. fs/btrfs/disk-io.c | 4 +--- fs/btrfs/extent_io.c | 21 ++++++--------------- fs/btrfs/inode.c | 23 +++++------------------ 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d10c7be10f3b..7278789ff8a7 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -980,9 +980,7 @@ static void btree_invalidatepage(struct page *page, unsigned int offset, btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, "page private not zero on page %llu", (unsigned long long)page_offset(page)); - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); + detach_page_private(page); } } diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 39e45b8a5031..bf816387715b 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3076,22 +3076,16 @@ static int submit_extent_page(unsigned int opf, static void attach_extent_buffer_page(struct extent_buffer *eb, struct page *page) { - if (!PagePrivate(page)) { - SetPagePrivate(page); - get_page(page); - set_page_private(page, (unsigned long)eb); - } else { + if (!PagePrivate(page)) + attach_page_private(page, eb); + else WARN_ON(page->private != (unsigned long)eb); - } } void set_page_extent_mapped(struct page *page) { - if (!PagePrivate(page)) { - SetPagePrivate(page); - get_page(page); - set_page_private(page, EXTENT_PAGE_PRIVATE); - } + if (!PagePrivate(page)) + attach_page_private(page, (void *)EXTENT_PAGE_PRIVATE); } static struct extent_map * @@ -4929,10 +4923,7 @@ static void btrfs_release_extent_buffer_pages(struct extent_buffer *eb) * We need to make sure we haven't be attached * to a new eb. */ - ClearPagePrivate(page); - set_page_private(page, 0); - /* One for the page private */ - put_page(page); + detach_page_private(page); } if (mapped) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 320d1062068d..a7f7ff0a8b7c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8303,11 +8303,8 @@ btrfs_readpages(struct file *file, struct address_space *mapping, static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags) { int ret = try_release_extent_mapping(page, gfp_flags); - if (ret == 1) { - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); - } + if (ret == 1) + detach_page_private(page); return ret; } @@ -8329,14 +8326,8 @@ static int btrfs_migratepage(struct address_space *mapping, if (ret != MIGRATEPAGE_SUCCESS) return ret; - if (page_has_private(page)) { - ClearPagePrivate(page); - get_page(newpage); - set_page_private(newpage, page_private(page)); - set_page_private(page, 0); - put_page(page); - SetPagePrivate(newpage); - } + if (page_has_private(page)) + attach_page_private(newpage, detach_page_private(page)); if (PagePrivate2(page)) { ClearPagePrivate2(page); @@ -8458,11 +8449,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, } ClearPageChecked(page); - if (PagePrivate(page)) { - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); - } + detach_page_private(page); } /* -- 2.17.1