Skip to contentSkip to conversation

fs: Add VirtualBox guest shared folder (vboxsf) support

PATCH Superseded Hans de Goede 2 participants 2 messages Mar 29, 2018 – Apr 3, 2018

Subsystems (2)

v7 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 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.

---
Changes in v7:
-Do not propagate sgid / suid bits between guest-host, note hosts with
VirtualBox version 5.2.6 or newer will filter these out regardless of what we do
-Better error messages when we cannot connect to the VirtualBox guest PCI
device, which may e.g. happen when trying to use vboxsf outside a vbox vm

Changes in v6:
-Address: https://www.virtualbox.org/ticket/819 which really is multiple bugs:
1) Fix MAP_SHARED not being supported
2) Fix changes done through regular read/write on the guest side not being seen by guest apps using mmap() access
3) Fix any changes done on the host side not being seen by guest apps using mmap() access

Changes in v5:
-Honor CONFIG_NLS_DEFAULT (reported-by [email protected])

Changes in v4:
-Drop "name=..." mount option, instead use the dev_name argument to the
mount syscall, to keep compatibility with existing fstab entries
-Fix "nls=%" match_table_t entry to "nls=%s"

Changes in v3:
-Use text only mount options, instead of a custom data struct -Stop caching full path in inode data, if parents gets renamed it will change -Fixed negative dentries handling
-Dropped the force_reread flag for dirs, not sure what it was actually for
but it is no good, doing a re-read on unlink of a file will lead to another file being skipped if the caller has already iterated over the entry for the unlinked file.
-Use file_inode(), file_dentry() and d_inode() helpers
-Prefix any non object-private symbols with vboxsf_ so as to not pollute
the global namespace when builtin
-Add MAINTAINERS entry
-Misc. cleanups

Changes in v2:
-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
-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

---
 MAINTAINERS                 |   6 +
 fs/Kconfig                  |   1 +
 fs/Makefile                 |   1 +
 fs/vboxsf/Kconfig           |  10 +
 fs/vboxsf/Makefile          |   3 +
 fs/vboxsf/dir.c             | 574 ++++++++++++++++++++++
 fs/vboxsf/file.c            | 367 ++++++++++++++
 fs/vboxsf/shfl_hostintf.h   | 919 ++++++++++++++++++++++++++++++++++++
 fs/vboxsf/super.c           | 442 +++++++++++++++++
 fs/vboxsf/utils.c           | 520 ++++++++++++++++++++
 fs/vboxsf/vboxsf_wrappers.c | 370 +++++++++++++++
 fs/vboxsf/vfsmod.h          | 133 ++++++
 12 files changed, 3346 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/vfsmod.h
MAINTAINERS +6 -0
index 8a1dbb9260a4..587997bd6bd5 100644
@@ -14856,6 +14856,12 @@ F:	include/linux/vbox_utils.h
 F:	include/uapi/linux/vbox*.h
 F:	drivers/virt/vboxguest/
 
+VIRTUAL BOX SHARED FOLDER VFS DRIVER:
+M:	Hans de Goede <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	fs/vboxsf/*
+
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
 S:	Maintained
fs/Kconfig +1 -0
index bc821a86d965..ec7baaf9cf8f 100644
@@ -251,6 +251,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
index add789ea270a..bf230c9d305b 100644
@@ -128,3 +128,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 +10 -0
new file mode 100644
index 000000000000..b034698121ea
@@ -0,0 +1,10 @@
+config VBOXSF_FS
+	tristate "VirtualBox guest shared folder (vboxsf) support"
+	depends on VBOXGUEST
+	select NLS
+	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
new file mode 100644
index 000000000000..fcbd488f9eec
@@ -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 +574 -0

574 lines not on this page · raw message

fs/vboxsf/file.c new file +367 -0

367 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 +442 -0

442 lines not on this page · raw message

fs/vboxsf/utils.c new file +520 -0

520 lines not on this page · raw message

fs/vboxsf/vboxsf_wrappers.c new file +370 -0

142 lines not on this page · raw message

fs/vboxsf/vfsmod.h new file +133 -0

133 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.17.0.rc1

Part of the diff is not shown here. View the raw message.

#1 lore raw
I love your patch! Yet something to improve:

Hi Hans,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16 next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/fs-Add-VirtualBox-guest-shared-folder-vboxsf-support/20180331-001843
config: x86_64-randconfig-g0-04030108 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

fs//vboxsf/file.c: In function 'sf_readpage':

>> fs//vboxsf/file.c:236:2: error: implicit declaration of function 'page_offset' [-Werror=implicit-function-declaration]
     loff_t off = page_offset(page);
     ^
>> fs//vboxsf/file.c:241:2: error: implicit declaration of function 'kmap' [-Werror=implicit-function-declaration]
     buf = kmap(page);
     ^
>> fs//vboxsf/file.c:241:6: warning: assignment makes pointer from integer without a cast
     buf = kmap(page);
         ^
>> fs//vboxsf/file.c:246:3: error: implicit declaration of function 'flush_dcache_page' [-Werror=implicit-function-declaration]
      flush_dcache_page(page);
      ^
>> fs//vboxsf/file.c:247:3: error: implicit declaration of function 'SetPageUptodate' [-Werror=implicit-function-declaration]
      SetPageUptodate(page);
      ^
>> fs//vboxsf/file.c:249:3: error: implicit declaration of function 'SetPageError' [-Werror=implicit-function-declaration]
      SetPageError(page);
      ^
>> fs//vboxsf/file.c:252:2: error: implicit declaration of function 'kunmap' [-Werror=implicit-function-declaration]
     kunmap(page);
     ^
>> fs//vboxsf/file.c:253:2: error: implicit declaration of function 'unlock_page' [-Werror=implicit-function-declaration]
     unlock_page(page);
     ^
   fs//vboxsf/file.c: In function 'sf_writepage':
   fs//vboxsf/file.c:272:6: warning: assignment makes pointer from integer without a cast
     buf = kmap(page);
         ^
>> fs//vboxsf/file.c:277:3: error: implicit declaration of function 'ClearPageError' [-Werror=implicit-function-declaration]
      ClearPageError(page);
      ^
>> fs//vboxsf/file.c:281:3: error: implicit declaration of function 'ClearPageUptodate' [-Werror=implicit-function-declaration]
      ClearPageUptodate(page);
      ^
   fs//vboxsf/file.c: In function 'sf_write_end':
   fs//vboxsf/file.c:300:6: warning: assignment makes pointer from integer without a cast
     buf = kmap(page);
         ^
>> fs//vboxsf/file.c:311:2: error: implicit declaration of function 'PageUptodate' [-Werror=implicit-function-declaration]
     if (!PageUptodate(page) && nwritten == PAGE_SIZE)
     ^
>> fs//vboxsf/file.c:320:2: error: implicit declaration of function 'put_page' [-Werror=implicit-function-declaration]
     put_page(page);
     ^
   fs//vboxsf/file.c: At top level:
>> fs//vboxsf/file.c:328:20: error: '__set_page_dirty_nobuffers' undeclared here (not in a function)

.set_page_dirty = __set_page_dirty_nobuffers,
^
cc1: some warnings being treated as errors

vim +/page_offset +236 fs//vboxsf/file.c

231
232 static int sf_readpage(struct file *file, struct page *page)
233 {
234 struct sf_glob_info *sf_g = GET_GLOB_INFO(file_inode(file)->i_sb);
235 struct sf_reg_info *sf_r = file->private_data;

 > 236		loff_t off = page_offset(page);
   237		u32 nread = PAGE_SIZE;
   238		u8 *buf;
   239		int err;
   240	
 > 241		buf = kmap(page);
   242	
   243		err = vboxsf_read(sf_g->root, sf_r->handle, off, &nread, buf, false);
   244		if (err == 0) {
   245			memset(&buf[nread], 0, PAGE_SIZE - nread);
 > 246			flush_dcache_page(page);
 > 247			SetPageUptodate(page);
   248		} else {
 > 249			SetPageError(page);
   250		}
   251	
 > 252		kunmap(page);
 > 253		unlock_page(page);
   254		return err;
   255	}
   256	
   257	static int sf_writepage(struct page *page, struct writeback_control *wbc)
   258	{
   259		struct inode *inode = page->mapping->host;
   260		struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
   261		struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
   262		struct sf_reg_info *sf_r = sf_i->file->private_data;
   263		loff_t off = page_offset(page);
   264		loff_t size = i_size_read(inode);
   265		u32 nwrite = PAGE_SIZE;
   266		u8 *buf;
   267		int err;
   268	
   269		if (off + PAGE_SIZE > size)
   270			nwrite = size & ~PAGE_MASK;
   271	
 > 272		buf = kmap(page);
   273		err = vboxsf_write(sf_g->root, sf_r->handle, off, &nwrite, buf, false);
   274		kunmap(page);
   275	
   276		if (err == 0) {
 > 277			ClearPageError(page);
   278			/* mtime changed */
   279			sf_i->force_restat = 1;
   280		} else {
 > 281			ClearPageUptodate(page);
   282		}
   283	
   284		unlock_page(page);
   285		return err;
   286	}
   287	
   288	int sf_write_end(struct file *file, struct address_space *mapping, loff_t pos,
   289			 unsigned int len, unsigned int copied, struct page *page,
   290			 void *fsdata)
   291	{
   292		struct inode *inode = mapping->host;
   293		struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
   294		struct sf_reg_info *sf_r = file->private_data;
   295		unsigned int from = pos & ~PAGE_MASK;
   296		u32 nwritten = len;
   297		u8 *buf;
   298		int err;
   299	
 > 300		buf = kmap(page);
   301		err = vboxsf_write(sf_g->root, sf_r->handle, pos, &nwritten,
   302				   buf + from, false);
   303		kunmap(page);
   304	
   305		if (err)
   306			goto out;
   307	
   308		/* mtime changed */
   309		GET_INODE_INFO(inode)->force_restat = 1;
   310	
 > 311		if (!PageUptodate(page) && nwritten == PAGE_SIZE)
   312			SetPageUptodate(page);
   313	
   314		pos += nwritten;
   315		if (pos > inode->i_size)
   316			i_size_write(inode, pos);
   317	
   318	out:
   319		unlock_page(page);
 > 320		put_page(page);
   321	
   322		return err;
   323	}
   324	
   325	const struct address_space_operations vboxsf_reg_aops = {
   326		.readpage = sf_readpage,
   327		.writepage = sf_writepage,
 > 328		.set_page_dirty = __set_page_dirty_nobuffers,

329 .write_begin = simple_write_begin,
330 .write_end = sf_write_end,
331 };
332

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation