/* Return Value: On success, a pointer to the allocated page is returned. On error, NULL is returned.  */
struct page* nilfs_alloc_private_page(struct block_device *bdev, int size, unsigned long state)
/* Return Value: On success, a pointer to the allocated page is returned. On error, NULL is returned.  */
struct page* nilfs_alloc_private_page(struct block_device *bdev, int size, unsigned long state)
{
	struct buffer_head *bh, *head, *tail;
	struct page *page;
	page = alloc_page(GFP_NOFS);
	if (unlikely(!page))
		return NULL;
	lock_page(page);
	head = alloc_page_buffers(page, size, 0);
	if (unlikely(!head)) {
		unlock_page(page);
		__free_page(page);
		return NULL;
	}
	bh = head;
	do {
		bh->b_state = (1UL << BH_NILFS_Allocated) | state;
		tail = bh;
		bh->b_bdev = bdev;
		bh = bh->b_this_page;
	} while (bh);
	tail->b_this_page = head;
	attach_page_buffers(page, head);
	return page;
}