/* copy_to_brd_setup must be called before copy_to_brd. It may sleep.  */
static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)
/* copy_to_brd_setup must be called before copy_to_brd. It may sleep.  */
static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)
{
	unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
	size_t copy;
	copy = min_t(size_t, n, PAGE_SIZE - offset);
	if (!brd_insert_page(brd, sector))
		return -ENOMEM;
	if (copy < n) {
		sector += copy >> SECTOR_SHIFT;
		if (!brd_insert_page(brd, sector))
			return -ENOMEM;
	}
	return 0;
}