Hi, I noticed that every time an NFS backup remote is disabled and re-enabled in Xen Orchestra, a new empty .nfs file is created while the previous files remain on the storage.
Xen Orchestra built from source, commit 54051163e0, mount options: hard,proto=tcp,timeo=600,retrans=2
The NAS remains available at all times. No network interruption is required to reproduce the issue. I monitored the open file descriptors. Here is an example of consecutive disable/enable cycles:
Remote enabled (3 open descriptors):
l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048
l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbff0000004a
l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049
Remote disabled (2 open descriptors):
l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048
l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049
Remote enabled (4 open descriptors):
l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048
l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b
l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049
l-wx------ 1 root root 64 Nov 28 17:16 37 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc020000004c
Remote disabled (3 open descriptors):
l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048
l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b
l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049
Remote enabled (5 open descriptors):
l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048
l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b
l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049
l-wx------ 1 root root 64 Nov 28 17:16 37 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc040000004d
l-wx------ 1 root root 64 Nov 28 17:16 38 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc050000004e
During an earlier test, I reached 37 open file descriptors. Disabling the remote closed only one of them, leaving 36 still open.
Even though the remote is disabled in XO, the NFS filesystem remains mounted at OS level:
$ findmnt -t nfs,nfs4
TARGET SOURCE FSTYPE OPTIONS
/run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699
192.168.10.30:/volume1/backup_xcp
nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=
Trying to unmount it manually results in the following error:
$ sudo umount /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699
umount.nfs4: /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699: device is busy
After stopping the xo-server service, the same unmount command completes successfully.
This also appears to explain the failed unmount message during the shutdown of the VM running Xen Orchestra:
[FAILED] Failed unmounting /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699
I asked AI to review the source code in @xen-orchestra/fs/src/_mount.js (https://github.com/vatesfr/xen-orchestra/blob/54051163e0/@xen-orchestra/fs/src/_mount.js) and found the following:
const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`
this.#keeper = await fs.open(keeperPath, 'w')
ignoreErrors.call(fs.unlink(keeperPath))
The creation of .nfs files is expected NFS behaviour because XO intentionally deletes keeper files while keeping their file descriptors open. However, the increasing number of open descriptors is not expected. The observed behaviour suggests that two keeper descriptors are opened during remote activation, but only one is properly closed during deactivation.
It may be worth checking whether _sync() is called twice during remote activation, whether the #keeper reference is overwritten without closing the previous descriptor, or whether multiple handler instances are created for the same remote.
Another possible cause is the asynchronous handler clean-up in packages/xo-server/src/xo-mixins/remotes.mjs.
A possible solution would be to ensure that existing keeper descriptors are properly closed before opening new ones, wait for handler clean-up to complete before replacing a handler, and prevent overlapping operations for the same remote. Logging failed close and unmount operations instead of silently ignoring them could also help identify the cause.
The number of open file descriptors should remain stable across repeated disable/enable cycles. Disabling an unused remote should release all associated file descriptors, remove the temporary .nfs files and allow the NFS filesystem to be unmounted.
A simple regression test covering repeated disable/enable cycles could help verify this behaviour.
The issue is consistently reproducible, although the exact cause in the source code remains unconfirmed and the proposed changes have not been tested.
Possibly related to #10741, although no NFS server outage or network interruption is required to reproduce this issue.