1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/slab.h>
7 int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
8 struct page *page, enum btrfs_subpage_type type)
10 struct btrfs_subpage *subpage = NULL;
14 * We have cases like a dummy extent buffer page, which is not mappped
15 * and doesn't need to be locked.
18 ASSERT(PageLocked(page));
19 /* Either not subpage, or the page already has private attached */
20 if (fs_info->sectorsize == PAGE_SIZE || PagePrivate(page))
23 ret = btrfs_alloc_subpage(fs_info, &subpage, type);
26 attach_page_private(page, subpage);
30 void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info,
33 struct btrfs_subpage *subpage;
35 /* Either not subpage, or already detached */
36 if (fs_info->sectorsize == PAGE_SIZE || !PagePrivate(page))
39 subpage = (struct btrfs_subpage *)detach_page_private(page);
41 btrfs_free_subpage(subpage);
44 int btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
45 struct btrfs_subpage **ret,
46 enum btrfs_subpage_type type)
48 if (fs_info->sectorsize == PAGE_SIZE)
51 *ret = kzalloc(sizeof(struct btrfs_subpage), GFP_NOFS);
54 spin_lock_init(&(*ret)->lock);
58 void btrfs_free_subpage(struct btrfs_subpage *subpage)