Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2311386ybz; Thu, 30 Apr 2020 14:55:50 -0700 (PDT) X-Google-Smtp-Source: APiQypL+Zw5IYHLqvPI5updqxgnkXFp2PqtO0NDapWbXU9RoXU/nRzvhiwkSPH7teqNYFacZB6G1 X-Received: by 2002:aa7:c609:: with SMTP id h9mr1021026edq.250.1588283749983; Thu, 30 Apr 2020 14:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588283749; cv=none; d=google.com; s=arc-20160816; b=fHjRx6bV5EDxpMPUueb84rjlppVn876NI3ST1y2vhiaUFEjzWfcMk3om1rVRKH4b20 QqJgYIgzSvZilo0le7DsmVThIgqlyPmOXklVijB1ITPN4GWyws+2GgUkttlbenyz2p59 9q3YwTpS7ayz/OUtFpoPzFwj/wPtT9h6Val1K2SA6Xe0Am419dwajcFddSJAj9pNr4EO 4MxUC/BleHGa+TFOa3WADjXPLDAe0cERveGc6QyYOy27xW+eCiho9XjvQ+Nn7XjPUJOy l2qofzcsfNuYfnjnboPjN2AiVBd6+LMv0tOJVDlEF+x7R5HHjzqKbz80XdD5zEUBP7N/ 4Cmw== 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=A09pnxCtmHNFxtu5/7SWNRBZ57kuvjkQtubB+do4qv0=; b=ij75XUpOyUJUtzIbkzhBfzMSYX5IFvMiqmsXc4VH6c9QkMd7RnzxuBNfeUcZ1DatW9 JXuPpesWapvHul0JBWV+EDoLo+GS/JiO3U/2revZnsI+g82bDTY39/6c72HcHoEUmCwU 9dtuWdsmNQCftJj9hyHc7VtczWGLwtzFbs9OSnbkjvRIRqLKGPfvsh6ggN/GlQYLeU/8 S4b8pzeAqWj19nK80oSr+nGxgjgtyCYkPoV1IdzeNv5vAaf7jsw/7mtUHwghPYM+4zyD qfCMqlViIf18DltOvCxviGCXJILeQiHAtOgtI7jBsyRIqO6C75SbFzier68wfPiEiFUw fhkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=coBxNrXx; 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 cb14si536856edb.529.2020.04.30.14.55.26; Thu, 30 Apr 2020 14:55:49 -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=coBxNrXx; 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 S1727997AbgD3VxL (ORCPT + 99 others); Thu, 30 Apr 2020 17:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgD3Vwl (ORCPT ); Thu, 30 Apr 2020 17:52:41 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE692C035494 for ; Thu, 30 Apr 2020 14:52:40 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id q8so5986397eja.2 for ; Thu, 30 Apr 2020 14:52:40 -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=A09pnxCtmHNFxtu5/7SWNRBZ57kuvjkQtubB+do4qv0=; b=coBxNrXxFKfsgd7ezmeRSMXArxrt4d5nG71g2m2wa3tS/g6U6HEWU9BoF6/hkAXZoG 577qwNithCoeR1JzQnF6A6JRGXpAqNL/fRuja5anAhDdJq+TkHUONmaDVzJlSNgkhc2I dk1pmVRAlGg9aVQ8aELP8PYAzHz0JrF3DN9gQryz1pVoAsJMJVIRe1Pd1N3gCghHC9yL yqSQiDQ4el0qSc//QT9+h3Ogegpsh3a/5yhPvrkMTmpnw7OE+Mow6HAZhgv8VOKOTUyE IIQVwnF5yomS1DIMau0s9YDJqLuIR0w15xpkZXu6XOffLWkGdQhWNRbqXSNiibl6KsAh vDjg== 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=A09pnxCtmHNFxtu5/7SWNRBZ57kuvjkQtubB+do4qv0=; b=sU8TcBv2AIEyWozFNdqeub0v9rgn77i7FCyDxDLSPvuY8kALrUmVKbsGlEdqZQbN8K NSY0olAomvDNv4b7Q4mS0H125e4eqzMVOA/wb2KPYkdcmDf9uXSAniUt/IOIKYGFXeEZ 4OgIcJpgCUqhONR/lRuYBJ3WyFWNp1v+kXC6qndRvx4YacC4XCgEssfDaVOSPCkxh9TD 48UbNwv5pYgx8TYTe2rw1W2KXVpX2A5AXazE/nf/VYU9ZTAGCJfMjmZHUK9IQ9087D9g O8vnBYlAdey6qqENditIXbfykqU/53r3k8OJ55YRJlbsYfERashdMFvlhYmdU5GR1pUw hXHQ== X-Gm-Message-State: AGi0Pub8/sg3heggRJTfnU1sSs7CTg0wpjSZbzgb1dzd5u23ArMUnXNO Nv4e/zO+s/b6dOeserZq7SwOPAjGf028Iw== X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr504911ejw.211.1588283559260; Thu, 30 Apr 2020 14:52:39 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:b82f:dfc:5e2a:e7cc]) by smtp.gmail.com with ESMTPSA id f13sm92022ejd.2.2020.04.30.14.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 14:52:38 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: hch@infradead.org, david@fromorbit.com, willy@infradead.org, Guoqing Jiang , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [RFC PATCH V2 3/9] btrfs: use attach/clear_page_private Date: Thu, 30 Apr 2020 23:44:44 +0200 Message-Id: <20200430214450.10662-4-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> References: <20200430214450.10662-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 -> 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 a6cb5cbbdb9f..fe4acf821110 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); + clear_page_private(page); } } diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 39e45b8a5031..095a5e83e660 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); + clear_page_private(page); } if (mapped) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 320d1062068d..34b09ab2c32a 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) + clear_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, clear_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); - } + clear_page_private(page); } /* -- 2.17.1