fs: Add VirtualBox guest shared folder (vboxsf) support
Subsystems (2)
v2 cover fs: Add VirtualBox guest shared folder (vboxsf) support
Hi All,
Now that the vboxguest driver which the vboxsf (guest shared folder) fs driver depends on is queued for merging into 4.16 in char-misc-next, all the dependencies for the vboxsf are in place.
So here is a v2 of my initial vboxsf, addressing all of the remark from Christoph Hellwig about v1:
-Removed various unused wrapper functions
-Don't use i_private, instead defined alloc_inode and destroy_inode
methods and use container_of.
-Drop obsolete comment referencing people to
http://www.atnf.csiro.au/people/rgooch/linux/vfs.txt
-move the single symlink op of from lnkops.c to file.c
As well as bunch of other cleanups:
-Use SPDX license headers
-Replace SHFLROOT / SHFLHANDLE defines with normal types -Removed unnecessary S_ISREG checks
-Got rid of bounce_buffer in regops, instead add a "user" flag to
vboxsf_read / vboxsf_write, re-using the existing __user address support in the vboxguest module
-Make vboxsf_wrappers return regular linux errno values
-Use i_size_write to update size on writing
-Convert doxygen style comments to kerneldoc style comments
Please review.
Regards,
Hans
PATCH v2 1/1 fs: Add VirtualBox guest shared folder (vboxsf) support
VirtualBox hosts can share folders with guests, this commit adds a VFS driver implementing the Linux-guest side of this, allowing folders exported by the host to be mounted under Linux.
This driver depends on the guest <-> host IPC functions exported by the vboxguest driver.
--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/vboxsf/Kconfig | 9 + fs/vboxsf/Makefile | 3 + fs/vboxsf/dir.c | 648 +++++++++++++++++++++++++++++ fs/vboxsf/file.c | 416 +++++++++++++++++++ fs/vboxsf/shfl_hostintf.h | 919 +++++++++++++++++++++++++++++++++++++++++ fs/vboxsf/super.c | 430 +++++++++++++++++++ fs/vboxsf/utils.c | 589 ++++++++++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.c | 365 ++++++++++++++++ fs/vboxsf/vboxsf_wrappers.h | 46 +++ fs/vboxsf/vfsmod.h | 104 +++++ include/uapi/linux/vbsfmount.h | 62 +++ 13 files changed, 3593 insertions(+) create mode 100644 fs/vboxsf/Kconfig create mode 100644 fs/vboxsf/Makefile create mode 100644 fs/vboxsf/dir.c create mode 100644 fs/vboxsf/file.c create mode 100644 fs/vboxsf/shfl_hostintf.h create mode 100644 fs/vboxsf/super.c create mode 100644 fs/vboxsf/utils.c create mode 100644 fs/vboxsf/vboxsf_wrappers.c create mode 100644 fs/vboxsf/vboxsf_wrappers.h create mode 100644 fs/vboxsf/vfsmod.h create mode 100644 include/uapi/linux/vbsfmount.h
fs/Kconfig +1 -0
@@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vboxsf/Kconfig" endif # MISC_FILESYSTEMS
fs/Makefile +1 -0
@@ -129,3 +129,4 @@ obj-y += exofs/ # Multiple modules obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_VBOXSF_FS) += vboxsf/
fs/vboxsf/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config VBOXSF_FS + tristate "VirtualBox guest shared folder (vboxsf) support" + depends on VBOXGUEST + help + VirtualBox hosts can share folders with guests, this driver + implements the Linux-guest side of this allowing folders exported + by the host to be mounted under Linux. + + If you want to use shared folders in VirtualBox guests, answer Y or M.
fs/vboxsf/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_VBOXSF_FS) += vboxsf.o + +vboxsf-objs := dir.o file.o utils.o vboxsf_wrappers.o super.o
fs/vboxsf/dir.c new file +648 -0
648 lines not on this page · raw message
fs/vboxsf/file.c new file +416 -0
416 lines not on this page · raw message
fs/vboxsf/shfl_hostintf.h new file +919 -0
919 lines not on this page · raw message
fs/vboxsf/super.c new file +430 -0
430 lines not on this page · raw message
fs/vboxsf/utils.c new file +589 -0
564 lines not on this page · raw message
fs/vboxsf/vboxsf_wrappers.c new file +365 -0
365 lines not on this page · raw message
fs/vboxsf/vboxsf_wrappers.h new file +46 -0
46 lines not on this page · raw message
fs/vboxsf/vfsmod.h new file +104 -0
104 lines not on this page · raw message
include/uapi/linux/vbsfmount.h new file +62 -0
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.14.3
Part of the diff is not shown here. View the raw message.
The mount uabi stuff is a red flag - all filesystems should use text options only these days. From a 20 second view it seems like this one does that, and the header can just be removed, but if not a lot more work will be needed.
Hi,
Quoted 4 lines · Christoph Hellwig
The mount uabi stuff is a red flag - all filesystems should use text options only these days. From a 20 second view it seems like this one does that, and the header can just be removed, but if not a lot more work will be needed.
Thank you for the quick feedback. I already expected this would be a problem, but I kept it around for 100% compatibility with the out of tree version of the vboxsf driver. I will fix this for v3 and coordinate with vbox upstream what to do about the compatibility issue.
Regards,
Hans
Quoted 26 lines · Hans de Goede
VirtualBox hosts can share folders with guests, this commit adds a VFS driver implementing the Linux-guest side of this, allowing folders exported by the host to be mounted under Linux.
This driver depends on the guest <-> host IPC functions exported by the vboxguest driver.
Signed-off-by Hans de Goede <[email protected]>--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/vboxsf/Kconfig | 9 + fs/vboxsf/Makefile | 3 + fs/vboxsf/dir.c | 648 +++++++++++++++++++++++++++++ fs/vboxsf/file.c | 416 +++++++++++++++++++ fs/vboxsf/shfl_hostintf.h | 919 +++++++++++++++++++++++++++++++++++++++++ fs/vboxsf/super.c | 430 +++++++++++++++++++ fs/vboxsf/utils.c | 589 ++++++++++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.c | 365 ++++++++++++++++ fs/vboxsf/vboxsf_wrappers.h | 46 +++ fs/vboxsf/vfsmod.h | 104 +++++ include/uapi/linux/vbsfmount.h | 62 +++ 13 files changed, 3593 insertions(+) create mode 100644 fs/vboxsf/Kconfig create mode 100644 fs/vboxsf/Makefile create mode 100644 fs/vboxsf/dir.c
Quoted 8 lines
create mode 100644 fs/vboxsf/file.c create mode 100644 fs/vboxsf/shfl_hostintf.h create mode 100644 fs/vboxsf/super.c create mode 100644 fs/vboxsf/utils.c create mode 100644 fs/vboxsf/vboxsf_wrappers.c create mode 100644 fs/vboxsf/vboxsf_wrappers.h create mode 100644 fs/vboxsf/vfsmod.h create mode 100644 include/uapi/linux/vbsfmount.h
A MAINTAINERS entry seems in order.
Quoted 28 lines
fs/Kconfig +1
-0@@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vboxsf/Kconfig" endif # MISC_FILESYSTEMSfs/Makefile +1
-0@@ -129,3 +129,4 @@ obj-y += exofs/ # Multiple modules obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_VBOXSF_FS) += vboxsf/fs/vboxsf/Kconfig new file +0
-0
fs/vboxsf/Kconfig line 2
Quoted 2 lines
fs/vboxsf/Kconfig new file +2
-0@@ -0,0 +1,9 @@ +config VBOXSF_FS + tristate "VirtualBox guest shared folder (vboxsf) support"
Don't know if you noticed, but calling your filesystem vboxsf is quite odd name among other XXXfs beasts.
Will it be an option to re-brand this as vboxfs?
Even if it is too late or too much of a hustle to change the user visible file_system_type name, I think changing the internal name is worth it.
The other thing is if you can help it to avoid the short 'sf_' prefix and use a longer prefix even for static functions, something like vbsf_ or vbfs_ that would be better.
Cheers,
Amir.
Hi,
Quoted 36 lines · Amir Goldstein
Quoted 23 lines · Hans de Goede
VirtualBox hosts can share folders with guests, this commit adds a VFS driver implementing the Linux-guest side of this, allowing folders exported by the host to be mounted under Linux.
This driver depends on the guest <-> host IPC functions exported by the vboxguest driver.
Signed-off-by Hans de Goede <[email protected]>--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/vboxsf/Kconfig | 9 + fs/vboxsf/Makefile | 3 + fs/vboxsf/dir.c | 648 +++++++++++++++++++++++++++++ fs/vboxsf/file.c | 416 +++++++++++++++++++ fs/vboxsf/shfl_hostintf.h | 919 +++++++++++++++++++++++++++++++++++++++++ fs/vboxsf/super.c | 430 +++++++++++++++++++ fs/vboxsf/utils.c | 589 ++++++++++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.c | 365 ++++++++++++++++ fs/vboxsf/vboxsf_wrappers.h | 46 +++ fs/vboxsf/vfsmod.h | 104 +++++ include/uapi/linux/vbsfmount.h | 62 +++ 13 files changed, 3593 insertions(+)Quoted 11 lines
create mode 100644
fs/vboxsf/Kconfigcreate mode 100644fs/vboxsf/Makefilecreate mode 100644fs/vboxsf/dir.c
create mode 100644fs/vboxsf/file.ccreate mode 100644fs/vboxsf/shfl_hostintf.hcreate mode 100644fs/vboxsf/super.ccreate mode 100644fs/vboxsf/utils.ccreate mode 100644fs/vboxsf/vboxsf_wrappers.ccreate mode 100644fs/vboxsf/vboxsf_wrappers.hcreate mode 100644fs/vboxsf/vfsmod.hcreate mode 100644include/uapi/linux/vbsfmount.h
Quoted 1 line
A
MAINTAINERSentry seems in order.
Ack and thank you for the feedback.
Quoted 25 lines
Quoted 25 lines
fs/Kconfig +1
-0@@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vboxsf/Kconfig" endif # MISC_FILESYSTEMSfs/Makefile +1
-0@@ -129,3 +129,4 @@ obj-y += exofs/ # Multiple modules obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_VBOXSF_FS) += vboxsf/fs/vboxsf/Kconfig new file +0
-1--- /dev/null
Quoted 8 lines
fs/vboxsf/Kconfig line 2
Quoted 4 lines
+++ b/fs/vboxsf/Kconfig
fs/vboxsf/Kconfig new file +2
-0@@ -0,0 +1,9 @@ +config VBOXSF_FS + tristate "VirtualBox guest shared folder (vboxsf) support"Don't know if you noticed, but calling your filesystem vboxsf is quite odd name among other XXXfs beasts.
Yes I noticed, note I'm only the guy pushing this upstream this code has a long out-of-tree history. FWIW the sf stand for "shared folder"
Quoted 3 lines
Will it be an option to re-brand this as vboxfs?
Even if it is too late or too much of a hustle to change the user visiblefile_system_typename, I think changing the internal name is worth it.
We can quite definitely not change the user-visible name, the mount arg changes Christoph Hellwig has requested are tricky enough wrt compatibility with the out-of-tree version most users use atm.
The users will need updated userspace tools to deal with the mount arg changes, but that is as easy as checking for -EINVAL and trying again with the new style string args. But figuring out the right fstype name is rather more tricky and the mount binary name has been mount.vboxsf for ages... So I would really like to keep the file_system_type name as vboxsf, at which point it seems counter-productive to me to rename the files / kernel-mode to vboxfs.
Quoted 3 lines
The other thing is if you can help it to avoid the short '
sf_' prefix and use a longer prefix even for static functions, something likevbsf_orvbfs_that would be better.
Agreed, I did not take the buildin use-case where everything gets linked into a single binary into account, will fix for v3.
Regards,
Hans
Quoted 45 lines · Hans de Goede
Hi,
Quoted 41 lines · Amir Goldstein
Quoted 36 lines · Hans de Goede
VirtualBox hosts can share folders with guests, this commit adds a VFS driver implementing the Linux-guest side of this, allowing folders exported by the host to be mounted under Linux.
This driver depends on the guest <-> host IPC functions exported by the vboxguest driver.
Signed-off-by Hans de Goede <[email protected]>--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/vboxsf/Kconfig | 9 + fs/vboxsf/Makefile | 3 + fs/vboxsf/dir.c | 648 +++++++++++++++++++++++++++++ fs/vboxsf/file.c | 416 +++++++++++++++++++ fs/vboxsf/shfl_hostintf.h | 919 +++++++++++++++++++++++++++++++++++++++++ fs/vboxsf/super.c | 430 +++++++++++++++++++ fs/vboxsf/utils.c | 589 ++++++++++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.c | 365 ++++++++++++++++ fs/vboxsf/vboxsf_wrappers.h | 46 +++ fs/vboxsf/vfsmod.h | 104 +++++ include/uapi/linux/vbsfmount.h | 62 +++ 13 files changed, 3593 insertions(+)create mode 100644
fs/vboxsf/Kconfigcreate mode 100644fs/vboxsf/Makefilecreate mode 100644fs/vboxsf/dir.c
create mode 100644fs/vboxsf/file.ccreate mode 100644fs/vboxsf/shfl_hostintf.hcreate mode 100644fs/vboxsf/super.ccreate mode 100644fs/vboxsf/utils.ccreate mode 100644fs/vboxsf/vboxsf_wrappers.ccreate mode 100644fs/vboxsf/vboxsf_wrappers.hcreate mode 100644fs/vboxsf/vfsmod.hcreate mode 100644include/uapi/linux/vbsfmount.h
[...]
Quoted 23 lines
Quoted 9 lines
fs/vboxsf/Kconfig line 2
Quoted 4 lines
+++ b/fs/vboxsf/Kconfig
fs/vboxsf/Kconfig new file +2
-0@@ -0,0 +1,9 @@ +config VBOXSF_FS + tristate "VirtualBox guest shared folder (vboxsf) support"Don't know if you noticed, but calling your filesystem vboxsf is quite odd name among other XXXfs beasts.
Yes I noticed, note I'm only the guy pushing this upstream this code has a long out-of-tree history. FWIW the sf stand for "shared folder"
Quoted 3 lines
Will it be an option to re-brand this as vboxfs?
Even if it is too late or too much of a hustle to change the user visiblefile_system_typename, I think changing the internal name is worth it.We can quite definitely not change the user-visible name, the mount arg changes Christoph Hellwig has requested are tricky enough wrt compatibility with the out-of-tree version most users use atm.
Quoted 8 lines
The users will need updated userspace tools to deal with the mount arg changes, but that is as easy as checking for
-EINVALand trying again with the new style string args. But figuring out the right fstype name is rather more tricky and the mount binary name has been mount.vboxsf for ages... So I would really like to keep thefile_system_typename as vboxsf, at which point it seems counter-productive to me to rename the files / kernel-mode to vboxfs.
Well, its up to you and whoever merges this code, but I don't find this rename counter-productive at all. Isn't the idea behind becoming an in-tree fs, conforming to the way we do things in-the-tree?
Someone at Oracle once made a decision sometime in the past when that code was out of tree and not among other fs without conforming to in-tree standards. That decision affects the user visible fs name and I wasn't suggesting to change that. That is what MODULE_ALIAS_FS is for. But there is not really a good reason to carry the baggage of this decision into the tree.
I don't know, maybe it's just me...
Cheers,
Amir.
Al Viro
maintainer* what hch said about mount options. Get rid of that before the thing goes into mainline.
* all "inode = GET_F_DENTRY(f)->d_inode;" are complete BS; it's called file_inode(f). Kill GET_F_DENTRY() off and be done with that.
* your ->rename() can race with ->get_link(). Look at the place where the former reassigns ->path and frees the old value and think what happens if the latter is called just prior to that kfree().
* the same goes for sf_inode_revalidate() vs. rename().
* just what happens to ->path of inode when e.g. its grandparent directory is renamed?
* AFAICS, you consider all negative dentries invalid. Why do you even hash them, then?
Hi Al,
Thank you for the quick review.
Quoted 2 lines · Al Viro
* what hch said about mount options. Get rid of that before the thing goes into mainline.
Ack.
Quoted 2 lines
* all "inode = GET_F_DENTRY(f)->d_inode;" are complete BS; it's called
file_inode(f). KillGET_F_DENTRY()off and be done with that.
Ok, will fix.
Quoted 8 lines
* your ->rename() can race with ->get_link(). Look at the place where the former reassigns ->path and frees the old value and think what happens if the latter is called just prior to that
kfree().* the same goes for
sf_inode_revalidate()vs.rename().* just what happens to ->path of inode when e.g. its grandparent directory is renamed?
Can I summarize all 3 above with: Caching the path is a bad idea and instead the code should always look up the name from e.g. file->f_path.dentry ?
Quoted 2 lines
* AFAICS, you consider all negative dentries invalid. Why do you even hash them, then?
I'm afraid I'm not entirely following you. Note I've no experience with fs code prior to this. Also I'm not the original author of this code, this code started as part of the out-of-tree kernel modules used by the VirtualBox guest-additions. I've been working on cleaning these modules up and then mainlinging them (there are 3 of them, this is the last).
Note I believe that this code is based on the fs/hostfs code.
Can you reword your question keeping my lack of experience wrt fs code in mind ?
Regards,
Hans
Al Viro
maintainerQuoted 11 lines · Hans de Goede
Quoted 8 lines
* your ->rename() can race with ->get_link(). Look at the place where the former reassigns ->path and frees the old value and think what happens if the latter is called just prior to that
kfree().* the same goes for
sf_inode_revalidate()vs.rename().* just what happens to ->path of inode when e.g. its grandparent directory is renamed?
Can I summarize all 3 above with: Caching the path is a bad idea and instead the code should always look up the name from e.g.
file->f_path.dentry?
Caching the path is very likely to be a bad idea. OTOH, caching conversions of individual components, which appear to be completely independent of any inodes, might be useful, especially if you attach the results to dentries instead of inodes. That way you only do nls shite on lookups. Concatenation of pieces into the pathname is probably best done later and in each case we really want to decide what to do with racing renames of ancestors *DURING* vboxsf_...() primitives. We can be clever and careful while building the pathname, but what's to prevent it going stale just as we'd formed the damn string and started to do whatever it was we'd formed it for and what happens in case of such races?
Quoted 9 lines
Quoted 2 lines
* AFAICS, you consider all negative dentries invalid. Why do you even hash them, then?
I'm afraid I'm not entirely following you. Note I've no experience with fs code prior to this. Also I'm not the original author of this code, this code started as part of the out-of-tree kernel modules used by the VirtualBox guest-additions. I've been working on cleaning these modules up and then mainlinging them (there are 3 of them, this is the last).
Quoted 4 lines
Note I believe that this code is based on the fs/hostfs code.
Can you reword your question keeping my lack of experience wrt fs code in mind ?
Your ->d_revalidate() flat-out returns 0 on negative dentries. Which means "consider them invalid when found by dcache lookup". So what's the point of hashing them at all? Note that the right answer might very well be "build a pathname anyway, stat the sucker and consider ENOENT as it's still valid"...
Hi,
Quoted 13 lines · Al Viro
Quoted 11 lines · Hans de Goede
Quoted 8 lines
* your ->rename() can race with ->get_link(). Look at the place where the former reassigns ->path and frees the old value and think what happens if the latter is called just prior to that
kfree().* the same goes for
sf_inode_revalidate()vs.rename().* just what happens to ->path of inode when e.g. its grandparent directory is renamed?
Can I summarize all 3 above with: Caching the path is a bad idea and instead the code should always look up the name from e.g.
file->f_path.dentry?
Quoted 10 lines
Caching the path is very likely to be a bad idea. OTOH, caching conversions of individual components, which appear to be completely independent of any inodes, might be useful, especially if you attach the results to dentries instead of inodes. That way you only do nls shite on lookups. Concatenation of pieces into the pathname is probably best done later and in each case we really want to decide what to do with racing renames of ancestors *DURING* vboxsf_...() primitives. We can be clever and careful while building the pathname, but what's to prevent it going stale just as we'd formed the damn string and started to do whatever it was we'd formed it for and what happens in case of such races?
vboxsf really works like a networkfs wrt this, for any calls to the hypervisor taking a path (rather then a handle) if we race and we loose then the hypervisor will simply return to use which a file-does-not-exist (at the now no longer valid path) error.
There are 2 types of races here:
1) Racing with accesses to the shared-folder outside of the guest, there is really nothing we can do here and in this case just reporting the error to the higher layers is the right thing to do IMHO
2) Racing with other accesses inside the guest, so we do something which requires a path and some of the parents may e.g. be renamed from inside the guest while we do this. I'm tempted to just also report the error returned by the host here. Since 1. is unavoidable anyways treating them both the same seems easiest.
Ideally 2 should never happen at all and all calls which fall under 2 would work with a handle, but at least re-reading a dir, which we do when a file inside it gets renamed, requires closing and opening the handle.
The call to get entries of the dir has an index argument, but the implementation in the hypervisor has:
Assert(*pIndex == 0);
And uses hypervisor private data attached to the handle to actually track where we are in the listing :|
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
* AFAICS, you consider all negative dentries invalid. Why do you even hash them, then?
I'm afraid I'm not entirely following you. Note I've no experience with fs code prior to this. Also I'm not the original author of this code, this code started as part of the out-of-tree kernel modules used by the VirtualBox guest-additions. I've been working on cleaning these modules up and then mainlinging them (there are 3 of them, this is the last).
Note I believe that this code is based on the fs/hostfs code.
Quoted 8 lines
Quoted 2 lines
Can you reword your question keeping my lack of experience wrt fs code in mind ?
Your ->d_revalidate() flat-out returns 0 on negative dentries. Which means "consider them invalid when found by dcache lookup". So what's the point of hashing them at all? Note that the right answer might very well be "build a pathname anyway, stat the sucker and consider ENOENT as it's still valid"...
Ah ok, so reading up a bit on this I see now that a "negative" dentry is a dentry for an unlinked filename, so without an inode linked to it (dentry->inode is NULL).
As you suggest building the path and check if it has not been recreated underneath us with a stat seems like the best solution here.
Regards,
Hans