File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed
scripts/vm/hypervisor/kvm Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -154,8 +154,7 @@ backup_running_vm() {
154154 virsh -c qemu:///system domjobinfo $VM --completed
155155 du -sb $dest | cut -f1
156156
157- umount $mount_point
158- rmdir $mount_point
157+ umount_operation
159158}
160159
161160backup_stopped_vm () {
@@ -184,6 +183,8 @@ backup_stopped_vm() {
184183 sync
185184
186185 ls -l --numeric-uid-gid $dest | awk ' {print $5}'
186+
187+ umount_operation
187188}
188189
189190delete_backup () {
@@ -219,6 +220,34 @@ mount_operation() {
219220 fi
220221}
221222
223+ umount_operation () {
224+ elapsed=0
225+ while fuser -m " $mount_point " > /dev/null 2>&1 && (( elapsed < 10 )) ; do
226+ sleep 1
227+ elapsed=$(( elapsed + 1 ))
228+ done
229+
230+ # Check if timeout was reached
231+ if (( elapsed >= 10 )) ; then
232+ echo " Timeout for unmounting reached: still busy"
233+ fi
234+
235+ # Attempt to unmount safely and capture output
236+ set +e
237+ umount_output=$( umount " $mount_point " 2>&1 )
238+ umount_exit=$?
239+ set -e
240+
241+ if [ " $umount_exit " -eq 0 ]; then
242+ # Only remove directory if unmount succeeded
243+ rmdir " $mount_point "
244+ else
245+ echo " Warning: failed to unmount $mount_point , skipping rmdir"
246+ echo " umount error message: $umount_output "
247+ log -ne " Warning: failed to unmount $mount_point , error: $umount_output "
248+ fi
249+ }
250+
222251cleanup () {
223252 local status=0
224253
You can’t perform that action at this time.
0 commit comments