/* Description: Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller to ask for a number of bytes to be allocated in front of the bio. Front pad allocation is useful for embedding the bio inside another structure, to avoid allocating extra data to go with the bio. Note that the bio must be embedded at the END of that structure always, or things will break badly.  */
struct bio_set* bioset_create(unsigned int pool_size, unsigned int front_pad)
/* Description: Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller to ask for a number of bytes to be allocated in front of the bio. Front pad allocation is useful for embedding the bio inside another structure, to avoid allocating extra data to go with the bio. Note that the bio must be embedded at the END of that structure always, or things will break badly.  */
struct bio_set* bioset_create(unsigned int pool_size, unsigned int front_pad)
{
	unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
	struct bio_set *bs;
	bs = kzalloc(sizeof(*bs), GFP_KERNEL);
	if (!bs)
		return NULL;
	bs->front_pad = front_pad;
	bs->bio_slab = bio_find_or_create_slab(front_pad + back_pad);
	if (!bs->bio_slab) {
		kfree(bs);
		return NULL;
	}
	bs->bio_pool = mempool_create_slab_pool(pool_size, bs->bio_slab);
	if (!bs->bio_pool)
		goto bad;
	if (bioset_integrity_create(bs, pool_size))
		goto bad;
	if (!biovec_create_pools(bs, pool_size))
		return bs;
bad:
	bioset_free(bs);
	return NULL;
}