static int _init_by_name_integrity(struct crypt_device *cd, const char *name)
{
	struct crypt_dm_active_device dmd;
	struct dm_target *tgt = &dmd.segment;
	int r;

	r = dm_query_device(cd, name, DM_ACTIVE_DEVICE |
				      DM_ACTIVE_CRYPT_KEY |
				      DM_ACTIVE_CRYPT_KEYSIZE |
				      DM_ACTIVE_INTEGRITY_PARAMS, &dmd);
	if (r < 0)
		return r;
	if (!single_segment(&dmd) || tgt->type != DM_INTEGRITY) {
		log_dbg(cd, "Unsupported device table detected in %s.", name);
		r = -EINVAL;
		goto out;
	}
	if (r > 0)
		r = 0;

	if (isINTEGRITY(cd->type)) {
		cd->u.integrity.params.tag_size = tgt->u.integrity.tag_size;
		cd->u.integrity.params.sector_size = tgt->u.integrity.sector_size;
		cd->u.integrity.params.journal_size = tgt->u.integrity.journal_size;
		cd->u.integrity.params.journal_watermark = tgt->u.integrity.journal_watermark;
		cd->u.integrity.params.journal_commit_time = tgt->u.integrity.journal_commit_time;
		cd->u.integrity.params.interleave_sectors = tgt->u.integrity.interleave_sectors;
		cd->u.integrity.params.buffer_sectors = tgt->u.integrity.buffer_sectors;
		MOVE_REF(cd->u.integrity.params.integrity, tgt->u.integrity.integrity);
		MOVE_REF(cd->u.integrity.params.journal_integrity, tgt->u.integrity.journal_integrity);
		MOVE_REF(cd->u.integrity.params.journal_crypt, tgt->u.integrity.journal_crypt);

		if (tgt->u.integrity.vk)
			cd->u.integrity.params.integrity_key_size = tgt->u.integrity.vk->keylength;
		if (tgt->u.integrity.journal_integrity_key)
			cd->u.integrity.params.journal_integrity_key_size = tgt->u.integrity.journal_integrity_key->keylength;
		if (tgt->u.integrity.journal_crypt_key)
			cd->u.integrity.params.integrity_key_size = tgt->u.integrity.journal_crypt_key->keylength;
		MOVE_REF(cd->metadata_device, tgt->u.integrity.meta_device);
	}
out:
	dm_targets_free(cd, &dmd);
	return r;
}
static int _init_by_name_integrity(struct crypt_device *cd, const char *name)
{
	struct crypt_dm_active_device dmd;
	struct dm_target *tgt = &dmd.segment;
	int r;

	r = dm_query_device(cd, name, DM_ACTIVE_DEVICE |
				      DM_ACTIVE_CRYPT_KEY |
				      DM_ACTIVE_CRYPT_KEYSIZE |
				      DM_ACTIVE_INTEGRITY_PARAMS, &dmd);
	if (r < 0)
		return r;
	if (!single_segment(&dmd) || tgt->type != DM_INTEGRITY) {
		log_dbg(cd, "Unsupported device table detected in %s.", name);
		r = -EINVAL;
		goto out;
	}
	if (r > 0)
		r = 0;

	if (isINTEGRITY(cd->type)) {
		cd->u.integrity.params.tag_size = tgt->u.integrity.tag_size;
		cd->u.integrity.params.sector_size = tgt->u.integrity.sector_size;
		cd->u.integrity.params.journal_size = tgt->u.integrity.journal_size;
		cd->u.integrity.params.journal_watermark = tgt->u.integrity.journal_watermark;
		cd->u.integrity.params.journal_commit_time = tgt->u.integrity.journal_commit_time;
		cd->u.integrity.params.interleave_sectors = tgt->u.integrity.interleave_sectors;
		cd->u.integrity.params.buffer_sectors = tgt->u.integrity.buffer_sectors;
		MOVE_REF(cd->u.integrity.params.integrity, tgt->u.integrity.integrity);
		MOVE_REF(cd->u.integrity.params.journal_integrity, tgt->u.integrity.journal_integrity);
		MOVE_REF(cd->u.integrity.params.journal_crypt, tgt->u.integrity.journal_crypt);

		if (tgt->u.integrity.vk)
			cd->u.integrity.params.integrity_key_size = tgt->u.integrity.vk->keylength;
		if (tgt->u.integrity.journal_integrity_key)
			cd->u.integrity.params.journal_integrity_key_size = tgt->u.integrity.journal_integrity_key->keylength;
		if (tgt->u.integrity.journal_crypt_key)
			cd->u.integrity.params.integrity_key_size = tgt->u.integrity.journal_crypt_key->keylength;
		MOVE_REF(cd->metadata_device, tgt->u.integrity.meta_device);
	}
out:
	dm_targets_free(cd, &dmd);
	return r;
}