Skip to content

Commit

Permalink
CA-393578: Fix vbd cleanup in metadata scripts
Browse files Browse the repository at this point in the history
The xe-[backup,restore]-metadata scripts have cleanup logic designed to ensure
we do not leave any vbd objects etc behind.

This logic calls `vbd-unplug` with a 20s timeout, and then (regardless of the
result) allows up to 10s for any device specified in the VBD to disappear - if
it does not, it does not trigger a `vbd-destroy`.

This logic fails in the case where a VDI is attached to a VM running on the same
host, as the `device` field in the new VBD will be populated with the backend
device for the running VM. In this case, the `vbd-unplug` fails immediately (as
the vbd is not plugged because the original `vbd-plug` attempt fails as the VDI
is in use), but then we sit waiting for 10s for the device to disappear (which
is obviously does not), and then fail to trigger a `vbd-destroy`, leaving the
VBD behind.

Fix this by simply removing the wait for the device to disappear and always
attempting a `vbd-destroy`, as I am not aware of any situation where this
additional 10s wait will give any benefit given current behaviours.

Signed-off-by: Alex Brett <[email protected]>
  • Loading branch information
alexbrett authored and lindig committed Jul 17, 2024
1 parent d7bc18d commit bb29f94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
21 changes: 2 additions & 19 deletions scripts/xe-backup-metadata
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,8 @@ function cleanup {
if [ ! -z "${vbd_uuid}" ]; then
${debug} echo -n "Unplugging VBD: "
${XE} vbd-unplug uuid="${vbd_uuid}" timeout=20
# poll for the device to go away if we know its name
if [ "${device}" != "" ]; then
device_gone=0
for ((i=0; i<10; i++)); do
${debug} echo -n "."
if [ ! -b "${device}" ]; then
${debug} echo " done"
device_gone=1
break
fi
sleep 1
done
if [ ${device_gone} -eq 0 ]; then
${debug} echo " failed"
echo "Please destroy VBD ${vbd_uuid} manually."
else
${XE} vbd-destroy uuid="${vbd_uuid}"
fi
fi
${debug} echo -n "Destroying VBD: "
${XE} vbd-destroy uuid="${vbd_uuid}"
fi
if [ ${fs_uninitialised} -eq 1 -a -n "${vdi_uuid}" ] ; then
${XE} vdi-destroy uuid="${vdi_uuid}"
Expand Down
23 changes: 3 additions & 20 deletions scripts/xe-restore-metadata
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,9 @@ function cleanup {
if [ ! -z "${vbd_uuid}" ]; then
${debug} echo -n "Unplugging VBD: " >&2
${XE} vbd-unplug uuid="${vbd_uuid}" timeout=20
# poll for the device to go away if we know its name
if [ "${device}" != "" ]; then
device_gone=0
for ((i=0; i<10; i++)); do
${debug} echo -n "." >&2
if [ ! -b "${device}" ]; then
${debug} echo " done" >&2
device_gone=1
break
fi
sleep 1
done
if [ ${device_gone} -eq 0 ]; then
${debug} echo " failed" >&2
${debug} echo "Please destroy VBD ${vbd_uuid} manually." >&2
else
${XE} vbd-destroy uuid="${vbd_uuid}"
vbd_uuid=""
fi
fi
${debug} echo -n "Destroying VBD: " >&2
${XE} vbd-destroy uuid="${vbd_uuid}"
vbd_uuid=""
device=""
fi
}
Expand Down

0 comments on commit bb29f94

Please sign in to comment.