Skip to content

Commit 4e6ee49

Browse files
committed
Fix NAS backup filename for legacy LINSTOR path
When backing up a running VM, nasbackup.sh derives the backup filename from the disk source path reported by libvirt. VMs started before the switch to /dev/drbd/by-res/ paths still carry the raw DRBD device node (e.g. /dev/drbd1098) in their live domain XML, which fell into the basename fallback and produced root.drbd1098.qcow2 instead of root.<volume-uuid>.qcow2. Restore always expects the UUID-based name, so these backups could not be restored until the VM was stopped and started. Resolve raw /dev/drbdNNNN device nodes back to the volume UUID by asking udev for the device's /dev/drbd/by-res/cs-<uuid> symlink. Apply the same handling in all three backup loops (running-VM XML build, sparsify, and stopped-VM convert). Signed-off-by: Moritz Tanner <moritz.tanner@linbit.com>
1 parent 348ceaf commit 4e6ee49

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ get_linstor_uuid_from_path() {
108108
echo "$volUuid"
109109
}
110110

111+
get_linstor_uuid_from_device() {
112+
local fullpath="$1"
113+
# VMs started before the /dev/drbd/by-res/ change still reference the raw DRBD
114+
# device node (e.g. /dev/drbd1098) in their live libvirt XML. Ask udev for the
115+
# device's symlinks and map it back to the volume UUID via the by-res symlink.
116+
local link
117+
for link in $(udevadm info --query=symlink --name="$fullpath" 2>/dev/null || true); do
118+
if [[ "$link" == drbd/by-res/cs-* ]]; then
119+
get_linstor_uuid_from_path "/dev/$link"
120+
return 0
121+
fi
122+
done
123+
echo "${fullpath##*/}"
124+
}
125+
111126
backup_running_vm() {
112127
mount_operation
113128
mkdir -p "$dest" || { echo "Failed to create backup directory $dest"; exit 1; }
@@ -117,6 +132,8 @@ backup_running_vm() {
117132
while read -r disk fullpath; do
118133
if [[ "$fullpath" == /dev/drbd/by-res/* ]]; then
119134
volUuid=$(get_linstor_uuid_from_path "$fullpath")
135+
elif [[ "$fullpath" == /dev/drbd[0-9]* ]]; then
136+
volUuid=$(get_linstor_uuid_from_device "$fullpath")
120137
else
121138
volUuid="${fullpath##*/}"
122139
fi
@@ -174,10 +191,14 @@ backup_running_vm() {
174191
# Use qemu-img convert to sparsify linstor backups which get bloated due to virsh backup-begin.
175192
name="root"
176193
while read -r disk fullpath; do
177-
if [[ "$fullpath" != /dev/drbd/by-res/* ]]; then
194+
if [[ "$fullpath" == /dev/drbd/by-res/* ]]; then
195+
volUuid=$(get_linstor_uuid_from_path "$fullpath")
196+
elif [[ "$fullpath" == /dev/drbd[0-9]* ]]; then
197+
volUuid=$(get_linstor_uuid_from_device "$fullpath")
198+
else
199+
name="datadisk"
178200
continue
179201
fi
180-
volUuid=$(get_linstor_uuid_from_path "$fullpath")
181202
if ! qemu-img convert -O qcow2 "$dest/$name.$volUuid.qcow2" "$dest/$name.$volUuid.qcow2.tmp" >> "$logFile" 2> >(cat >&2); then
182203
echo "qemu-img convert failed for $dest/$name.$volUuid.qcow2"
183204
cleanup
@@ -213,6 +234,8 @@ backup_stopped_vm() {
213234
volUuid=$(get_ceph_uuid_from_path "$disk")
214235
elif [[ "$disk" == /dev/drbd/by-res/* ]]; then
215236
volUuid=$(get_linstor_uuid_from_path "$disk")
237+
elif [[ "$disk" == /dev/drbd[0-9]* ]]; then
238+
volUuid=$(get_linstor_uuid_from_device "$disk")
216239
else
217240
volUuid="${disk##*/}"
218241
fi

0 commit comments

Comments
 (0)