# Volume Shows Attached After Detach Operation Fails With Error " Unable to detach from guest transient domain

## Problem

* Volume unavailable inside the instance after failure to detach the volume from the instance with error as follows.

{% tabs %}
{% tab title="None" %}

```none
DeviceDetachFailed: Device detach failed for vd[x]: Unable to detach from guest transient domain
```

{% endtab %}
{% endtabs %}

* Volume status is "attached" and "in-use" in Cinder DB.

{% tabs %}
{% tab title="None" %}

```none
# openstack volume show volume_uuid --fit-width -c properties -c status+--------------------------------+--------------------------------------------------| Field | Value |+--------------------------------+--------------------------------------------------+| properties | attached_mode='rw' || status | in-use |+--------------------------------+---------------------------------------------------
```

{% endtab %}
{% endtabs %}

## Environment

* Platform9 Managed OpenStack - All Versions
* Cinder
* Nova
* Libvirt

## Cause

* The volume detach at the Libvirt driver level happens in two steps:
  * Detach from the persistent domain (affect instance upon next reboot).
  * Detach from the live domain (affect running instance) - Transient Domain.
* A detach from a live domain is a request from the host to the guest, which the guest can choose to ignore. If the guest has a file open on the volume by some process, it might ignore the request to detach that volume because the file is in use and logs below error in *ostackhost.log.*

{% tabs %}
{% tab title="None" %}

```none
TRACE oslo.service.loopingcall DeviceDetachFailed: Device detach failed for vd[x]: Unable to detach from guest transient domain.
```

{% endtab %}
{% endtabs %}

* If this scenario occurs, when a user retries to detach the volume, the volume is already detached from the persistent domain. Thus, it will fail the second attempt of detach operation with error:

{% tabs %}
{% tab title="None" %}

```none
ERROR nova.compute.manager [req-id  user-id] [instance: instance-id] Failed to detach volume volume_id from /dev/vd[x]
```

{% endtab %}
{% endtabs %}

* This is the expected behavior if the volume is detached from the persistent domain and unavailable inside the instance.

## Resolution

1. Restart of the instance is required to complete the detach operation.

## Additional Information

A patch to log the error observed while detaching the volume from a persistent domain was added in the upstream [OpenStack bugs launchpad #1633236](https://bugs.launchpad.net/nova/+bug/1633236).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform9.com/kb/pmo/how-to/volume-shows-attached-after-detach-operation-fails-with-error-u.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
