int crypt_suspend(struct crypt_device *cd,
		  const char *name)
{
	char *key_desc;
	crypt_status_info ci;
	int r;
	uint32_t dmflags = DM_SUSPEND_WIPE_KEY;

	/* FIXME: check context uuid matches the dm-crypt device uuid (onlyLUKS branching) */

	if (!cd || !name)
		return -EINVAL;

	log_dbg(cd, "Suspending volume %s.", name);

	if (cd->type)
		r = onlyLUKS(cd);
	else {
		r = crypt_uuid_type_cmp(cd, CRYPT_LUKS1);
		if (r < 0)
			r = crypt_uuid_type_cmp(cd, CRYPT_LUKS2);
		if (r < 0)
			log_err(cd, _("This operation is supported only for LUKS device."));
	}

	if (r < 0)
		return r;

	ci = crypt_status(NULL, name);
	if (ci < CRYPT_ACTIVE) {
		log_err(cd, _("Volume %s is not active."), name);
		return -EINVAL;
	}

	dm_backend_init(cd);

	r = dm_status_suspended(cd, name);
	if (r < 0)
		goto out;

	if (r) {
		log_err(cd, _("Volume %s is already suspended."), name);
		r = -EINVAL;
		goto out;
	}

	key_desc = crypt_get_device_key_description(cd, name);

	/* we can't simply wipe wrapped keys */
	if (crypt_cipher_wrapped_key(crypt_get_cipher(cd), crypt_get_cipher_mode(cd)))
		dmflags &= ~DM_SUSPEND_WIPE_KEY;

	r = dm_suspend_device(cd, name, dmflags);
	if (r == -ENOTSUP)
		log_err(cd, _("Suspend is not supported for device %s."), name);
	else if (r)
		log_err(cd, _("Error during suspending device %s."), name);
	else
		crypt_drop_keyring_key_by_description(cd, key_desc, LOGON_KEY);
	free(key_desc);
out:
	dm_backend_exit(cd);
	return r;
}
int crypt_suspend(struct crypt_device *cd,
		  const char *name)
{
	char *key_desc;
	crypt_status_info ci;
	int r;
	uint32_t dmflags = DM_SUSPEND_WIPE_KEY;

	 

	if (!cd || !name)
		return -EINVAL;

	log_dbg(cd, "Suspending volume %s.", name);

	if (cd->type)
		r = onlyLUKS(cd);
	else {
		r = crypt_uuid_type_cmp(cd, CRYPT_LUKS1);
		if (r < 0)
			r = crypt_uuid_type_cmp(cd, CRYPT_LUKS2);
		if (r < 0)
			log_err(cd, _("This operation is supported only for LUKS device."));
	}

	if (r < 0)
		return r;

	ci = crypt_status(NULL, name);
	if (ci < CRYPT_ACTIVE) {
		log_err(cd, _("Volume %s is not active."), name);
		return -EINVAL;
	}

	dm_backend_init(cd);

	r = dm_status_suspended(cd, name);
	if (r < 0)
		goto out;

	if (r) {
		log_err(cd, _("Volume %s is already suspended."), name);
		r = -EINVAL;
		goto out;
	}

	key_desc = crypt_get_device_key_description(cd, name);

	 
	if (crypt_cipher_wrapped_key(crypt_get_cipher(cd), crypt_get_cipher_mode(cd)))
		dmflags &= ~DM_SUSPEND_WIPE_KEY;

	r = dm_suspend_device(cd, name, dmflags);
	if (r == -ENOTSUP)
		log_err(cd, _("Suspend is not supported for device %s."), name);
	else if (r)
		log_err(cd, _("Error during suspending device %s."), name);
	else
		crypt_drop_keyring_key_by_description(cd, key_desc, LOGON_KEY);
	free(key_desc);
out:
	dm_backend_exit(cd);
	return r;
}