/* Also validate snapshot exception store handovers. On success, returns 1 if this registration is a handover destination, otherwise returns 0.  */
static int register_snapshot(struct dm_snapshot *snap)
/* Also validate snapshot exception store handovers. On success, returns 1 if this registration is a handover destination, otherwise returns 0.  */
static int register_snapshot(struct dm_snapshot *snap)
{
	struct origin *o, *new_o = NULL;
	struct block_device *bdev = snap->origin->bdev;
	int r = 0;
	new_o = kmalloc(sizeof(*new_o), GFP_KERNEL);
	if (!new_o)
		return -ENOMEM;
	down_write(&_origins_lock);
	r = __validate_exception_handover(snap);
	if (r < 0) {
		kfree(new_o);
		goto out;
	}
	o = __lookup_origin(bdev);
	if (o)
		kfree(new_o);
	else {
		o = new_o;
		INIT_LIST_HEAD(&o->snapshots);
		o->bdev = bdev;
		__insert_origin(o);
	}
	__insert_snapshot(o, snap);
out:
	up_write(&_origins_lock);
	return r;
}