From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guoqing Jiang Subject: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Date: Thu, 30 Apr 2020 23:44:42 +0200 Message-ID: <20200430214450.10662-2-guoqing.jiang@cloud.ionos.com> References: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> Return-path: In-Reply-To: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> Sender: linux-kernel-owner@vger.kernel.org To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: hch@infradead.org, david@fromorbit.com, willy@infradead.org, Guoqing Jiang , Andrew Morton , "Darrick J. Wong" , William Kucharski , "Kirill A. Shutemov" , Andreas Gruenbacher , Yang Shi , Yafang Shao , Song Liu , linux-raid@vger.kernel.org, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, Alexander Viro , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Anton List-Id: linux-raid.ids The logic in attach_page_buffers and __clear_page_buffers are quite paired, but 1. they are located in different files. 2. attach_page_buffers is implemented in buffer_head.h, so it could be used by other files. But __clear_page_buffers is static function in buffer.c and other potential users can't call the function, md-bitmap even copied the function. So, introduce the new attach/clear_page_private to replace them. With the new pair of function, we will remove the usage of attach_page_buffers and __clear_page_buffers in next patches. Thanks for the new names from Christoph Hellwig. Suggested-by: Matthew Wilcox Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: William Kucharski Cc: "Kirill A. Shutemov" Cc: Andreas Gruenbacher Cc: Yang Shi Cc: Yafang Shao Cc: Song Liu Cc: linux-raid@vger.kernel.org Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Alexander Viro Cc: Jaegeuk Kim Cc: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Cc: Christoph Hellwig Cc: linux-xfs@vger.kernel.org Cc: Anton Altaparmakov Cc: linux-ntfs-dev@lists.sourceforge.net Cc: Mike Marshall Cc: Martin Brandenburg Cc: devel@lists.orangefs.org Cc: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: Roman Gushchin Cc: Andreas Dilger Signed-off-by: Guoqing Jiang --- RFC -> RFC V2: Address the comments from Christoph Hellwig 1. change function names to attach/clear_page_private and add comments. 2. change the return type of attach_page_private. include/linux/pagemap.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..2e515f210b18 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count) return __page_cache_add_speculative(page, count); } +/** + * attach_page_private - attach data to page's private field and set PG_private. + * @page: page to be attached and set flag. + * @data: data to attach to page's private field. + * + * Need to take reference as mm.h said "Setting PG_private should also increment + * the refcount". + */ +static inline void attach_page_private(struct page *page, void *data) +{ + get_page(page); + set_page_private(page, (unsigned long)data); + SetPagePrivate(page); +} + +/** + * clear_page_private - clear page's private field and PG_private. + * @page: page to be cleared. + * + * The counterpart function of attach_page_private. + * Return: private data of page or NULL if page doesn't have private data. + */ +static inline void *clear_page_private(struct page *page) +{ + void *data = (void *)page_private(page); + + if (!PagePrivate(page)) + return NULL; + ClearPagePrivate(page); + set_page_private(page, 0); + put_page(page); + + return data; +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2937BC47254 for ; Thu, 30 Apr 2020 21:53:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F139E207DD for ; Thu, 30 Apr 2020 21:53:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="NGAEKGru" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726336AbgD3VxT (ORCPT ); Thu, 30 Apr 2020 17:53:19 -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 S1727053AbgD3Vwj (ORCPT ); Thu, 30 Apr 2020 17:52:39 -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 E02BDC08ED7D for ; Thu, 30 Apr 2020 14:52:38 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id gr25so5963705ejb.10 for ; Thu, 30 Apr 2020 14:52:38 -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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=NGAEKGruhKtx7ZWTrFdEqTmqAVl/YDbNX5SVHiheCt5mgGQXMvPqVsB2mWj4W+6TZx avj1y2aqFM2fM4mYbpeY1mNHjz5L5wFBJHZ7nqGDO/UfrsVe7K3fK+19Qz0xhaRBCJF8 cnG9jsv0Y3cuCHExnrUC59PgGg5ldN6zReZ4l/MkqDih/pWf2Qq5leOqyJa1Ea1uUvqL KSJUgjKhSgiIMTbhcESV0rK/2/wlrqs0rRp/j53oVanG3NSXpHazoglUXFC2CIoq8QGs T0RBK7fYVyj0odwSJ7t5g5PDfIz9c6vhMkT7fz1ruAgadlRAj8EWlz0SjkauUs46ppHW r7PQ== 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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=fvTHjvQ4p6gEpexgT6IsubOfPUuAEVxrYvd3eB0m5Aoj8mGt7eKWEt1siGLK2llPMl D7ta/0g9B5SY+1qSHN6/gcEosgLQN5ywDCBzLD38utW6QcERiSAL0PzD3dJkPsFXFJrE UdoK1lEf49i0kxGP0+R9UZ/sVkfZS8AJtf8BBVblSbfzsyLz9/jP6AYgJHC3L50noEB/ UKLlAGGT7+eiP8mYVrTug8sKOOq4NBt2LeJTjQgtl4gkzlkr8cjU2O/GrYIEEdAOCSEq TrQz3SY30qEXmmA+jEqN/eK9/dp+rtPIRekjOETngbEjgU3IPppCqTrjv0PzuerRhKid vdxg== X-Gm-Message-State: AGi0Pubvfd2g/IUnlrA5r3IG9jKdxUxLQ3WTHymnCMEpMQL8LMyUXsu6 dHFDhDe30qC4TuKb4swvo049GQ== X-Google-Smtp-Source: APiQypIDTj3Uj7biPphTd2Cba892cORi5pdinqFvBm6XPxrzHDikqrxlAy/dZ1nN6NDVa1Eq5TMhqw== X-Received: by 2002:a17:906:b2c4:: with SMTP id cf4mr538626ejb.340.1588283557346; Thu, 30 Apr 2020 14:52:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 14:52:36 -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 , Andrew Morton , "Darrick J. Wong" , William Kucharski , "Kirill A. Shutemov" , Andreas Gruenbacher , Yang Shi , Yafang Shao , Song Liu , linux-raid@vger.kernel.org, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, Alexander Viro , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Anton Altaparmakov , linux-ntfs-dev@lists.sourceforge.net, Mike Marshall , Martin Brandenburg , devel@lists.orangefs.org, Thomas Gleixner , Sebastian Andrzej Siewior , Roman Gushchin , Andreas Dilger Subject: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Date: Thu, 30 Apr 2020 23:44:42 +0200 Message-Id: <20200430214450.10662-2-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-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The logic in attach_page_buffers and __clear_page_buffers are quite paired, but 1. they are located in different files. 2. attach_page_buffers is implemented in buffer_head.h, so it could be used by other files. But __clear_page_buffers is static function in buffer.c and other potential users can't call the function, md-bitmap even copied the function. So, introduce the new attach/clear_page_private to replace them. With the new pair of function, we will remove the usage of attach_page_buffers and __clear_page_buffers in next patches. Thanks for the new names from Christoph Hellwig. Suggested-by: Matthew Wilcox Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: William Kucharski Cc: "Kirill A. Shutemov" Cc: Andreas Gruenbacher Cc: Yang Shi Cc: Yafang Shao Cc: Song Liu Cc: linux-raid@vger.kernel.org Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Alexander Viro Cc: Jaegeuk Kim Cc: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Cc: Christoph Hellwig Cc: linux-xfs@vger.kernel.org Cc: Anton Altaparmakov Cc: linux-ntfs-dev@lists.sourceforge.net Cc: Mike Marshall Cc: Martin Brandenburg Cc: devel@lists.orangefs.org Cc: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: Roman Gushchin Cc: Andreas Dilger Signed-off-by: Guoqing Jiang --- RFC -> RFC V2: Address the comments from Christoph Hellwig 1. change function names to attach/clear_page_private and add comments. 2. change the return type of attach_page_private. include/linux/pagemap.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..2e515f210b18 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count) return __page_cache_add_speculative(page, count); } +/** + * attach_page_private - attach data to page's private field and set PG_private. + * @page: page to be attached and set flag. + * @data: data to attach to page's private field. + * + * Need to take reference as mm.h said "Setting PG_private should also increment + * the refcount". + */ +static inline void attach_page_private(struct page *page, void *data) +{ + get_page(page); + set_page_private(page, (unsigned long)data); + SetPagePrivate(page); +} + +/** + * clear_page_private - clear page's private field and PG_private. + * @page: page to be cleared. + * + * The counterpart function of attach_page_private. + * Return: private data of page or NULL if page doesn't have private data. + */ +static inline void *clear_page_private(struct page *page) +{ + void *data = (void *)page_private(page); + + if (!PagePrivate(page)) + return NULL; + ClearPagePrivate(page); + set_page_private(page, 0); + put_page(page); + + return data; +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A728C47247 for ; Thu, 30 Apr 2020 21:59:39 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 05788206F0 for ; Thu, 30 Apr 2020 21:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="HxLJEhCR"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="hjC1frVB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="NGAEKGru" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05788206F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cloud.ionos.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jUHDW-00044c-Hu; Thu, 30 Apr 2020 21:59:38 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jUHDV-00044V-Lk for linux-f2fs-devel@lists.sourceforge.net; Thu, 30 Apr 2020 21:59:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=HxLJEhCRUDL53rw1J6S9v8FcyC +Uz4x2I2lJExVAA0dQYQXZxd90+t7vE2cI9GdB5nGFZo0mjbf6RuNpKPVUQ67qvzzJjf0F2Fw0ep3 Ab237HanV9rpXSAZ4vtyz5K3vEinYGqvku/LBXGBDZK805HNNE3pXGc58Tkm+VjWT1KU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=hjC1frVBuhS5r7aKlRQSMqa9qD lfVIo0oAl1AmLHK+wJeHFu/2OAkhmYEJu6l/fxAsbgQx0segTIEWkWJ9jpDlQFKtYPC9IVckOXlXS joq8/bTMr2vPc6dWw6+fri69EeJB7hDjcGSKAorWONWoMqmB7MkFwmhdmXoPfy4QEm0Q=; Received: from mail-wr1-f68.google.com ([209.85.221.68]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1jUHDT-0009eH-GL for linux-f2fs-devel@lists.sourceforge.net; Thu, 30 Apr 2020 21:59:37 +0000 Received: by mail-wr1-f68.google.com with SMTP id i10so9199432wrv.10 for ; Thu, 30 Apr 2020 14:59:35 -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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=NGAEKGruhKtx7ZWTrFdEqTmqAVl/YDbNX5SVHiheCt5mgGQXMvPqVsB2mWj4W+6TZx avj1y2aqFM2fM4mYbpeY1mNHjz5L5wFBJHZ7nqGDO/UfrsVe7K3fK+19Qz0xhaRBCJF8 cnG9jsv0Y3cuCHExnrUC59PgGg5ldN6zReZ4l/MkqDih/pWf2Qq5leOqyJa1Ea1uUvqL KSJUgjKhSgiIMTbhcESV0rK/2/wlrqs0rRp/j53oVanG3NSXpHazoglUXFC2CIoq8QGs T0RBK7fYVyj0odwSJ7t5g5PDfIz9c6vhMkT7fz1ruAgadlRAj8EWlz0SjkauUs46ppHW r7PQ== 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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=A3/NF9i8fgzINtlvvaO9uxF98QgZkGEgllhQ1AEbg2MSo4NtPQcS0VqYTPME0Ut68g zMyy7usLcXKHlKk/WqTw7tfzgZJoBn9MnVJoqUVrlmnWunkL+P4wfKHGYWO/hV+tDHv6 B/vMWFlKyEuOkB2mh5lxZpsiHXmSxFDs5nJGK4itposr58EyUC6arAL8Cg1jRbYRLl1q 0CiJR4StjXdazPOmVDQL3OYsQmrdrjppFCh9g4gtJoy00E1UF8FWNxfhB7W0GnSjyK7V ekGWPRXoHDdOn2aAWtxtzOlpFEalqbFOZWliztZZ0h6kZog+DbXwqO8DFdl68a+51yhF UexQ== X-Gm-Message-State: AGi0PuZESg1O/T9dxTY3sqQBahcVEEa4ujpsk1cH87AHLjXBGaTnXDJg 7/h10YwoTuNcBZY9447O25DVWMr1PnpHHQ== X-Google-Smtp-Source: APiQypIDTj3Uj7biPphTd2Cba892cORi5pdinqFvBm6XPxrzHDikqrxlAy/dZ1nN6NDVa1Eq5TMhqw== X-Received: by 2002:a17:906:b2c4:: with SMTP id cf4mr538626ejb.340.1588283557346; Thu, 30 Apr 2020 14:52:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 14:52:36 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 30 Apr 2020 23:44:42 +0200 Message-Id: <20200430214450.10662-2-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> X-Headers-End: 1jUHDT-0009eH-GL Subject: [f2fs-dev] [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Brandenburg , Sebastian Andrzej Siewior , david@fromorbit.com, Song Liu , Yafang Shao , Mike Marshall , Andreas Gruenbacher , "Darrick J. Wong" , Chris Mason , willy@infradead.org, hch@infradead.org, devel@lists.orangefs.org, Josef Bacik , linux-raid@vger.kernel.org, Alexander Viro , David Sterba , Jaegeuk Kim , Thomas Gleixner , Anton Altaparmakov , Andreas Dilger , Guoqing Jiang , Yang Shi , William Kucharski , linux-ntfs-dev@lists.sourceforge.net, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, "Kirill A. Shutemov" , Andrew Morton , Roman Gushchin , linux-btrfs@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net The logic in attach_page_buffers and __clear_page_buffers are quite paired, but 1. they are located in different files. 2. attach_page_buffers is implemented in buffer_head.h, so it could be used by other files. But __clear_page_buffers is static function in buffer.c and other potential users can't call the function, md-bitmap even copied the function. So, introduce the new attach/clear_page_private to replace them. With the new pair of function, we will remove the usage of attach_page_buffers and __clear_page_buffers in next patches. Thanks for the new names from Christoph Hellwig. Suggested-by: Matthew Wilcox Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: William Kucharski Cc: "Kirill A. Shutemov" Cc: Andreas Gruenbacher Cc: Yang Shi Cc: Yafang Shao Cc: Song Liu Cc: linux-raid@vger.kernel.org Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Alexander Viro Cc: Jaegeuk Kim Cc: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Cc: Christoph Hellwig Cc: linux-xfs@vger.kernel.org Cc: Anton Altaparmakov Cc: linux-ntfs-dev@lists.sourceforge.net Cc: Mike Marshall Cc: Martin Brandenburg Cc: devel@lists.orangefs.org Cc: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: Roman Gushchin Cc: Andreas Dilger Signed-off-by: Guoqing Jiang --- RFC -> RFC V2: Address the comments from Christoph Hellwig 1. change function names to attach/clear_page_private and add comments. 2. change the return type of attach_page_private. include/linux/pagemap.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..2e515f210b18 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count) return __page_cache_add_speculative(page, count); } +/** + * attach_page_private - attach data to page's private field and set PG_private. + * @page: page to be attached and set flag. + * @data: data to attach to page's private field. + * + * Need to take reference as mm.h said "Setting PG_private should also increment + * the refcount". + */ +static inline void attach_page_private(struct page *page, void *data) +{ + get_page(page); + set_page_private(page, (unsigned long)data); + SetPagePrivate(page); +} + +/** + * clear_page_private - clear page's private field and PG_private. + * @page: page to be cleared. + * + * The counterpart function of attach_page_private. + * Return: private data of page or NULL if page doesn't have private data. + */ +static inline void *clear_page_private(struct page *page) +{ + void *data = (void *)page_private(page); + + if (!PagePrivate(page)) + return NULL; + ClearPagePrivate(page); + set_page_private(page, 0); + put_page(page); + + return data; +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else -- 2.17.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel