Skip to content

Commit a19672f

Browse files
committed
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 <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Tested-by: Jeff Layton <[email protected]> Tested-by: Dominique Martinet <[email protected]> Tested-by: [email protected] 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 Link: https://lore.kernel.org/r/163584180781.4023316.5037526301198034310.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/163649324326.309189.17817587229450840783.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/163657848531.834781.14269656212269187893.stgit@warthog.procyon.org.uk/ # v5
1 parent f89ce84 commit a19672f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/linux/pagemap.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,25 @@ static inline void folio_attach_private(struct folio *folio, void *data)
279279
folio_set_private(folio);
280280
}
281281

282+
/**
283+
* folio_change_private - Change private data on a folio.
284+
* @folio: Folio to change the data on.
285+
* @data: Data to set on the folio.
286+
*
287+
* Change the private data attached to a folio and return the old
288+
* data. The page must previously have had data attached and the data
289+
* must be detached before the folio will be freed.
290+
*
291+
* Return: Data that was previously attached to the folio.
292+
*/
293+
static inline void *folio_change_private(struct folio *folio, void *data)
294+
{
295+
void *old = folio_get_private(folio);
296+
297+
folio->private = data;
298+
return old;
299+
}
300+
282301
/**
283302
* folio_detach_private - Detach private data from a folio.
284303
* @folio: Folio to detach data from.

0 commit comments

Comments
 (0)