From 6753582e4b1999fdf2fd9ea0f499c0cd0f7cd64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oto=20Pet=C5=99=C3=ADk?= Date: Sun, 22 Oct 2023 17:11:19 +0200 Subject: [PATCH] fix(vm): better check for disk ownership (#633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Storage using .raw or .qcow2 files uses additional element in path, which is not present in ZFS storage. Support both patterns when determining disk ownership. This fixes #632 Signed-off-by: Oto Petřík --- proxmox/nodes/vms/vms_types.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index 96e65abd..f6a725c8 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -224,7 +224,17 @@ func (r CustomStorageDevice) IsOwnedBy(vmID int) bool { return false } - return strings.HasPrefix(*pathInDatastore, fmt.Sprintf("vm-%d-", vmID)) + // ZFS uses "local-zfs:vm-123-disk-0" + if strings.HasPrefix(*pathInDatastore, fmt.Sprintf("vm-%d-", vmID)) { + return true + } + + // directory uses "local:123/vm-123-disk-0" + if strings.HasPrefix(*pathInDatastore, fmt.Sprintf("%d/vm-%d-", vmID, vmID)) { + return true + } + + return false } // CustomStorageDevices handles QEMU SATA device parameters.