Bug 245865 - emulators/virtualbox-ose-additions: doesn't let go of files placed on a Windows host shared folder
Summary: emulators/virtualbox-ose-additions: doesn't let go of files placed on a Windo...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Vladimir Druzenko
URL: https://www.freshports.org/emulators/...
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2020-04-24 03:52 UTC by Ian Laurie
Modified: 2025-01-07 19:56 UTC (History)
5 users (show)

See Also:
vvd: maintainer-feedback+
vvd: merge-quarterly+


Attachments
Patch for ports tree (17.24 KB, patch)
2023-08-25 10:43 UTC, takahiro.kurosawa
no flags Details | Diff
Patch for the vboxvfs module source (VirtualBox-6.1.46/src/VBox/Additions/freebsd/vboxvfs) (10.96 KB, patch)
2023-08-25 10:50 UTC, takahiro.kurosawa
no flags Details | Diff
Patch for ports tree (updated) (17.34 KB, patch)
2025-01-05 10:22 UTC, takahiro.kurosawa
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Laurie 2020-04-24 03:52:56 UTC
virtualbox-ose-additions doesn't seem to want to let go of files placed on a Windows host shared folder.  

My host is Win8.1, VirtualBox is 6.1.6, my FreeBSD is 12.1-RELEASE-p3 and my GUI in FreeBSD is Xfce 4.14.

Not sure if this is an issue with FreeBSD or Linux hosts.

Minimal steps to highlight issue:

1. Mount Windows shared folder, for example: sudo mount -t vboxvfs -w Development ~/host
2. Go there in the file manager.
3. Right click "Create Document" -> "Empty File".
4. Then try to delete it.  It cannot be deleted.

If you try to delete the file from the command line:

$ rm dog
rm: dog: Text file busy

In fact it cannot be deleted even on the Windows host until the VM shuts down, it's as if the file is still open for writing or something.

This issue came to light running some code that creates lock files, but when done the code was unable to delete the lock files, leaving things in a locked state.  Needless to say this is rather annoying.

Derived distros like FuryBSD exhibit the same problem.
Comment 1 Graham Perrin freebsd_committer freebsd_triage 2021-07-22 04:24:02 UTC
(In reply to nixuser from comment #0)

> … as if the file is still open …

You can use fstat(1) in the guest to tell. 


fstat /path/to/file


man 1 fstat

From the EXAMPLES section of the manual page: 

>    Requesting information about a file that is not opened results in just a
>    header line instead of an error:
Comment 2 groenveld 2021-07-23 20:23:13 UTC
A work around:
# mount -t vboxvfs guestshare /mnt
# cp /etc/os-release /mnt
# umount /mnt
# kldunload vboxvfs

Once the FreeBSD VirtualBox guest unload the vboxvfs driver, the host releases its lock on the file in the VBox guest folder.
John
groenveld@acm.org
Comment 3 martin 2021-09-13 19:30:49 UTC
I think this is a problem on a vboxvfs side. I was able to reproduce it on handful of hosts hosting the test VM (FreeBSD 13 release with 6.1.26 r145957 additions).

/shared is a directory shared from guest to host.

The simple test:

guest:/shared# mkdir d && ls -lad d
drwxrwxr-x  1 root  wheel  4096 Sep 13 21:24 d

host:/shared# rmdir d && echo test > d

; has no problem going in

guest:/shared# cd d && ls -la && cd -
-rw-rw-r--  1 root  wheel  5 Sep 13 21:25 .

guest:/shared# cat d
cat: d: Is a directory
guest:/shared#ls -lad d
-rw-rw-r--  1 root  wheel  5 Sep 13 21:25 d

It seems the cache vboxvfs module keeps can get out of sync with the reality pretty fast.

Going through the larger shared directory or even doing ls -la on a shared directory within guest repeatedly renders FS unusable on a guest. Umount/module unload and load back is required to get the functionality back.
Comment 4 martin 2021-09-13 19:32:20 UTC
>> /shared is a directory shared from guest to host.
I didn't catch this even though I did read after myself. Of course share is coming from host to guest.
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2021-09-14 06:41:44 UTC
Is effectiveness, of things such as vboxvfs, limited by what's possible with FreeBSD?

Bug 258010 comes to mind: 

> kqueue shortcoming for desktop usage
Comment 6 martin 2021-09-14 12:10:59 UTC
My opinion probably doesn't matter due to lack of experience but I don't think that's it. 
Few days ago I fixed one bug of random crashes with this module and I was curious to see if I can do more -- understand what is happening and possibly make it better (this module, as many other parts of virtualbox, leaves memory leaks behind).
There seems to be lack of documentation about this or I didn't look well enough.

FreeBSD additions code seems to be inspired by Solaris additions. But in FreeBSD code I see handful of code segments commented out with #if 0 segments. Also the naming seems to be confusing as Solaris is using AVL tree for cache, here simple link list is used.

From what I understand VirtualBox provides API guest can communicate with host. This API is used to get the FS information (vboxvfs_prov.c). The vboxvfs_vnops.c is the glue code. Again, at least how I understood it. 

Now I want to find out what happens when there's a change on FS done by host -- how is guest notified and what has to be done. 

I'm on my own without any docs, just reading the code. It slow but I'm trying.
Comment 7 Graham Perrin freebsd_committer freebsd_triage 2023-08-18 20:21:57 UTC
Reproducible with 6.1.46 additions and 13.2-RELEASE-p2 as a guest?
Comment 8 takahiro.kurosawa 2023-08-25 10:43:08 UTC
Created attachment 244334 [details]
Patch for ports tree

I've run into this problem while playing with shared folders on 14-CURRENT w/ virtualbox-ose-additions-6.1.46.
The patch is tested on 14-CURRENT and 13.2-RELEASE.  Not tested on 12.
Also fixes a bug around directory listing.
Comment 9 takahiro.kurosawa 2023-08-25 10:50:19 UTC
Created attachment 244335 [details]
Patch for the vboxvfs module source (VirtualBox-6.1.46/src/VBox/Additions/freebsd/vboxvfs)

The patch for ports tree tends to conflict due to mismatched contexts.  I'll attach a patch for the vboxvfs module source too.
Comment 10 Vladimir Druzenko freebsd_committer freebsd_triage 2025-01-04 22:23:05 UTC
(In reply to takahiro.kurosawa from comment #9)
1. Is the previous patch obsolete?
2. Is the patch applicable to VirtualBox 6.1.50?
Comment 11 takahiro.kurosawa 2025-01-05 08:14:01 UTC
(In reply to Vladimir Druzenko from comment #10)
The patch is obsolete. I've set the obsolete flag to the patch.
I have kept updating the patch to fix build failures, but just realized
that the updated patch doesn't work correctly (I didn't use vbox
shared folders recently).
I will fix the problem and upload the patch.
Comment 12 takahiro.kurosawa 2025-01-05 10:22:48 UTC
Created attachment 256435 [details]
Patch for ports tree (updated)

I just updated the patch. Tested for emulators/virtualbox-ose-additions
version 6.1.50 on FreeBSD kernel version 1500029.
Please let me know if you find any problems.
Comment 13 Vladimir Druzenko freebsd_committer freebsd_triage 2025-01-06 12:21:45 UTC
(In reply to takahiro.kurosawa from comment #12)
I don't use this function.
I can check if emulators/virtualbox-ose-additions build and run after this patch.
Comment 14 commit-hook freebsd_committer freebsd_triage 2025-01-06 14:04:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1a2220ab88eed87566727fef85f4cb7fb0d95965

commit 1a2220ab88eed87566727fef85f4cb7fb0d95965
Author:     takahiro.kurosawa <takahiro.kurosawa@gmail.com>
AuthorDate: 2025-01-06 14:02:21 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2025-01-06 14:02:21 +0000

    emulators/virtualbox-ose-additions{,-nox11}: Fix vboxvfs bugs

    This commit fixes vboxvfs (shared foler) kernel module bugs:
    * fix open file leaks on creating files that causes file descriptor
      leaks on host;
    * fix halfway lookups.

    PR:     245865
    MFH:    2025Q1

 emulators/virtualbox-ose-additions-nox11/Makefile  |   2 +-
 emulators/virtualbox-ose-additions/Makefile        |   2 +-
 ...ch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h |   9 +-
 ..._VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c |  19 +-
 ...VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c | 228 +++++++++++++--------
 5 files changed, 152 insertions(+), 108 deletions(-)
Comment 15 commit-hook freebsd_committer freebsd_triage 2025-01-06 14:05:44 UTC
A commit in branch 2025Q1 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c1013a1ce3bbfa2b29e97ee946140d40b0d40b12

commit c1013a1ce3bbfa2b29e97ee946140d40b0d40b12
Author:     takahiro.kurosawa <takahiro.kurosawa@gmail.com>
AuthorDate: 2025-01-06 14:02:21 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2025-01-06 14:05:28 +0000

    emulators/virtualbox-ose-additions{,-nox11}: Fix vboxvfs bugs

    This commit fixes vboxvfs (shared foler) kernel module bugs:
    * fix open file leaks on creating files that causes file descriptor
      leaks on host;
    * fix halfway lookups.

    PR:     245865
    MFH:    2025Q1
    (cherry picked from commit 1a2220ab88eed87566727fef85f4cb7fb0d95965)

 emulators/virtualbox-ose-additions-nox11/Makefile  |   2 +-
 emulators/virtualbox-ose-additions/Makefile        |   2 +-
 ...ch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h |   9 +-
 ..._VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c |  19 +-
 ...VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c | 228 +++++++++++++--------
 5 files changed, 152 insertions(+), 108 deletions(-)
Comment 16 Vladimir Druzenko freebsd_committer freebsd_triage 2025-01-06 14:11:57 UTC
I'll try to apply this patch to emulators/virtualbox-ose-additions-legacy.
Comment 17 commit-hook freebsd_committer freebsd_triage 2025-01-07 19:39:13 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=abe3df235ee4885d7937f2626f566ea48715e02c

commit abe3df235ee4885d7937f2626f566ea48715e02c
Author:     takahiro.kurosawa <takahiro.kurosawa@gmail.com>
AuthorDate: 2025-01-07 19:37:49 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2025-01-07 19:37:49 +0000

    emulators/virtualbox-ose{,-additions}{,-nox11}-legacy: Fix vboxvfs bugs

    This commit fixes vboxvfs (shared foler) kernel module bugs:
    * fix open file leaks on creating files that causes file descriptor
      leaks on host;
    * fix halfway lookups.

    PR:     245865
    MFH:    2025Q1

 emulators/virtualbox-ose-additions-legacy/Makefile |   2 +-
 .../virtualbox-ose-additions-nox11-legacy/Makefile |   2 +-
 emulators/virtualbox-ose-legacy/Makefile           |   2 +-
 ...ch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h |   9 +-
 ..._VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c |  19 +-
 ...VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c | 226 +++++++++++++--------
 emulators/virtualbox-ose-nox11-legacy/Makefile     |   2 +-
 7 files changed, 153 insertions(+), 109 deletions(-)
Comment 18 commit-hook freebsd_committer freebsd_triage 2025-01-07 19:50:21 UTC
A commit in branch 2025Q1 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=aed3690309b69bd8c7d2fe4e91f447e1d49ba935

commit aed3690309b69bd8c7d2fe4e91f447e1d49ba935
Author:     takahiro.kurosawa <takahiro.kurosawa@gmail.com>
AuthorDate: 2025-01-07 19:37:49 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2025-01-07 19:47:56 +0000

    emulators/virtualbox-ose{,-additions}{,-nox11}-legacy: Fix vboxvfs bugs

    This commit fixes vboxvfs (shared foler) kernel module bugs:
    * fix open file leaks on creating files that causes file descriptor
      leaks on host;
    * fix halfway lookups.

    PR:     245865
    MFH:    2025Q1
    (cherry picked from commit abe3df235ee4885d7937f2626f566ea48715e02c)

 emulators/virtualbox-ose-additions-legacy/Makefile |   2 +-
 .../virtualbox-ose-additions-nox11-legacy/Makefile |   2 +-
 emulators/virtualbox-ose-legacy/Makefile           |   2 +-
 ...ch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h |   9 +-
 ..._VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c |  19 +-
 ...VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c | 226 +++++++++++++--------
 emulators/virtualbox-ose-nox11-legacy/Makefile     |   2 +-
 7 files changed, 153 insertions(+), 109 deletions(-)
Comment 19 Vladimir Druzenko freebsd_committer freebsd_triage 2025-01-07 19:56:46 UTC
Thanks!