[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <163584180781.4023316.5037526301198034310.stgit@warthog.procyon.org.uk>
Date: Tue, 02 Nov 2021 08:30:07 +0000
From: David Howells <dhowells@...hat.com>
To: "Matthew Wilcox (Oracle)" <willy@...radead.org>
Cc: dhowells@...hat.com, Jeff Layton <jlayton@...nel.org>,
Ilya Dryomov <idryomov@...il.com>,
Dominique Martinet <asmadeus@...ewreck.org>,
linux-fsdevel@...r.kernel.org, linux-cachefs@...hat.com,
v9fs-developer@...ts.sourceforge.net,
linux-afs@...ts.infradead.org, linux-nfs@...r.kernel.org,
linux-cifs@...r.kernel.org, ceph-devel@...r.kernel.org,
v9fs-developer@...ts.sourceforge.net, devel@...ts.orangefs.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH v3 3/6] folio: Add a function to change the private data
attached to a folio
Add a function, folio_change_private(), that will change the private data
attached to a folio, without the need to twiddle the private bit or the
refcount. It assumes that folio_add_private() has already been called on
the page.
Signed-off-by: David Howells <dhowells@...hat.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@...radead.org>
Link: https://lore.kernel.org/r/162981149911.1901565.17776700811659843340.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/163005743485.2472992.5100702469503007023.stgit@warthog.procyon.org.uk/ # v2
---
include/linux/pagemap.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 013cdc90f5fd..569302e4defe 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -229,6 +229,25 @@ static inline void folio_attach_private(struct folio *folio, void *data)
folio_set_private(folio);
}
+/**
+ * folio_change_private - Change private data on a folio.
+ * @folio: Folio to change the data on.
+ * @data: Data to set on the folio.
+ *
+ * Change the private data attached to a folio and return the old
+ * data. The page must previously have had data attached and the data
+ * must be detached before the folio will be freed.
+ *
+ * Return: Data that was previously attached to the folio.
+ */
+static inline void *folio_change_private(struct folio *folio, void *data)
+{
+ void *old = folio_get_private(folio);
+
+ folio->private = data;
+ return old;
+}
+
/**
* folio_detach_private - Detach private data from a folio.
* @folio: Folio to detach data from.
Powered by blists - more mailing lists