Hi,
On 10-07-17 12:08, Hans de Goede wrote:
Hi all,
During my vboxguest Linux cleanup work I made a small
detour to the vboxsf driver.
I noticed that although it depends on vboxguest to make
hgcm calls, it still comes with its own copy of
GenericRequest, Physheap, Init and VMMDev.c
It seems the only reason it uses this is to get
g_vbgldata.hostVersion so that it can check for
page-list support.
IMHO it would be better if the vboxguest driver were
to store the hostVersion in an exported global
variable, say vbg_host_version. And then
vboxfs would use that. Combine that with moving:
RTSEMFASTMUTEX mutexHGCMHandle;
struct VBGLHGCMHANDLEDATA aHGCMHandleData[64];
From g_vbgldata to static globals in HGCM.c
and then g_vbgldata can be dropped from
VBGLInternal.h together with dropping
GenericRequest, Physheap, Init and VMMDev.c
completely.
I've attached a patch which does this from my
own local vboxsf version.
Ok, that version was no good, I did not notice that
some of the removed code was responsible for
calling vbglR0HGCMInit(), here is a new version
replacing the VbglR0SfInit call with vbglR0HGCMInit.
Regards,
Hans
>From 1e96540dcad6d49594230e1092d118b84cda36f7 Mon Sep 17 00:00:00 2001
From: Hans de Goede <[email protected]>
Date: Mon, 10 Jul 2017 12:01:55 +0200
Subject: [PATCH 1/2] Stop calling VbglGRPerform ourselves just to get the
host-version
Stop calling VbglGRPerform ourselves just to get the host-version,
vboxguest already does this and doing this ourselves requires
a whole bunch of extra code we really don't need in vboxsf.
Signed-off-by: Hans de Goede <[email protected]>
---
HGCM.c | 27 +++++++++++++++++++--------
Makefile | 16 ++++++++++------
VBGLInternal.h | 11 -----------
VBoxGuestR0LibSharedFolders.c | 12 ------------
regops.c | 6 ++++--
vfsmod.c | 9 +++++----
6 files changed, 38 insertions(+), 43 deletions(-)
diff --git a/HGCM.c b/HGCM.c
index 8fcc59a..74c3bb7 100644
--- a/HGCM.c
+++ b/HGCM.c
@@ -39,13 +39,24 @@
#define VBGL_HGCM_ASSERT_MSG AssertReleaseMsg
/**
+ * Fast heap for HGCM handles data.
+ * @{
+ */
+
+static RTSEMFASTMUTEX mutexHGCMHandle;
+
+static struct VBGLHGCMHANDLEDATA aHGCMHandleData[64];
+
+/** @} */
+
+/**
* Initializes the HGCM VBGL bits.
*
* @return VBox status code.
*/
int vbglR0HGCMInit(void)
{
- return RTSemFastMutexCreate(&g_vbgldata.mutexHGCMHandle);
+ return RTSemFastMutexCreate(&mutexHGCMHandle);
}
/**
@@ -55,15 +66,15 @@ int vbglR0HGCMInit(void)
*/
int vbglR0HGCMTerminate(void)
{
- RTSemFastMutexDestroy(g_vbgldata.mutexHGCMHandle);
- g_vbgldata.mutexHGCMHandle = NIL_RTSEMFASTMUTEX;
+ RTSemFastMutexDestroy(mutexHGCMHandle);
+ mutexHGCMHandle = NIL_RTSEMFASTMUTEX;
return VINF_SUCCESS;
}
DECLINLINE(int) vbglHandleHeapEnter(void)
{
- int rc = RTSemFastMutexRequest(g_vbgldata.mutexHGCMHandle);
+ int rc = RTSemFastMutexRequest(mutexHGCMHandle);
VBGL_HGCM_ASSERT_MSG(RT_SUCCESS(rc), ("Failed to request handle heap mutex, rc = %Rrc\n", rc));
@@ -72,7 +83,7 @@ DECLINLINE(int) vbglHandleHeapEnter(void)
DECLINLINE(void) vbglHandleHeapLeave(void)
{
- RTSemFastMutexRelease(g_vbgldata.mutexHGCMHandle);
+ RTSemFastMutexRelease(mutexHGCMHandle);
}
struct VBGLHGCMHANDLEDATA *vbglHGCMHandleAlloc(void)
@@ -85,11 +96,11 @@ struct VBGLHGCMHANDLEDATA *vbglHGCMHandleAlloc(void)
/* Simple linear search in array. This will be called not so often, only connect/disconnect. */
/** @todo bitmap for faster search and other obvious optimizations. */
- for (i = 0; i < RT_ELEMENTS(g_vbgldata.aHGCMHandleData); i++)
+ for (i = 0; i < RT_ELEMENTS(aHGCMHandleData); i++)
{
- if (!g_vbgldata.aHGCMHandleData[i].fAllocated)
+ if (!aHGCMHandleData[i].fAllocated)
{
- p = &g_vbgldata.aHGCMHandleData[i];
+ p = &aHGCMHandleData[i];
p->fAllocated = 1;
break;
}
diff --git a/Makefile b/Makefile
index fddff28..95b866f 100644
--- a/Makefile
+++ b/Makefile
@@ -19,20 +19,24 @@ obj ?= $(CURDIR)
include $(obj)/Makefile.include.header
MOD_NAME = vboxsf
+
+UNUSED_OBJS = \
+ GenericRequest.o \
+ PhysHeap.o \
+ Init.o \
+ VMMDev.o \
+ VbglR0CanUsePhysPageList.o \
+
+
MOD_OBJS = \
vfsmod.o \
dirops.o \
lnkops.o \
regops.o \
utils.o \
- GenericRequest.o \
SysHlp.o \
- PhysHeap.o \
- Init.o \
- VMMDev.o \
HGCM.o \
- VBoxGuestR0LibSharedFolders.o \
- VbglR0CanUsePhysPageList.o
+ VBoxGuestR0LibSharedFolders.o
ifeq ($(BUILD_TARGET_ARCH),x86)
MOD_OBJS += \
divdi3.o \
diff --git a/VBGLInternal.h b/VBGLInternal.h
index 8ea223e..ec2e99c 100644
--- a/VBGLInternal.h
+++ b/VBGLInternal.h
@@ -107,17 +107,6 @@ typedef struct VBGLDATA
VBGLDRIVER driver;
/** @} */
-
- /**
- * Fast heap for HGCM handles data.
- * @{
- */
-
- RTSEMFASTMUTEX mutexHGCMHandle;
-
- struct VBGLHGCMHANDLEDATA aHGCMHandleData[64];
-
- /** @} */
#endif
} VBGLDATA;
diff --git a/VBoxGuestR0LibSharedFolders.c b/VBoxGuestR0LibSharedFolders.c
index 1199b77..34714c7 100644
--- a/VBoxGuestR0LibSharedFolders.c
+++ b/VBoxGuestR0LibSharedFolders.c
@@ -53,18 +53,6 @@
(a)->u32Function = SHFL_FN_##b; \
(a)->cParms = SHFL_CPARMS_##b
-
-
-DECLVBGL(int) VbglR0SfInit(void)
-{
- return VbglInitClient();
-}
-
-DECLVBGL(void) VbglR0SfTerm(void)
-{
- VbglTerminate();
-}
-
DECLVBGL(int) VbglR0SfConnect(PVBGLSFCLIENT pClient)
{
int rc;
diff --git a/regops.c b/regops.c
index d4457dc..bad1d65 100644
--- a/regops.c
+++ b/regops.c
@@ -21,6 +21,9 @@
#include "vfsmod.h"
+/* From vboxguest.ko */
+extern VMMDevReqHostVersion vbg_host_version;
+
static void *alloc_bounce_buffer(size_t *tmp_sizep, PRTCCPHYS physp, size_t
xfer_size, const char *caller)
{
@@ -233,8 +236,7 @@ static ssize_t sf_reg_write(struct file *file, const char *buf, size_t size, lof
}
#if 1
- if (VbglR0CanUsePhysPageList())
- {
+ if (vbg_host_version.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) {
err = VbglR0SfWritePhysCont(&client_handle, &sf_g->map, sf_r->handle,
pos, &nwritten, tmp_phys);
err = RT_FAILURE(err) ? -EPROTO : 0;
diff --git a/vfsmod.c b/vfsmod.c
index 612984c..91eb95d 100644
--- a/vfsmod.c
+++ b/vfsmod.c
@@ -32,6 +32,7 @@
#include "version-generated.h"
#include "revision-generated.h"
#include "product-generated.h"
+#include "VBGLInternal.h"
MODULE_DESCRIPTION(VBOX_PRODUCT " VFS Module for Host File System Access");
MODULE_AUTHOR(VBOX_VENDOR);
@@ -600,10 +601,10 @@ static int __init init(void)
return err;
}
- rcVBox = VbglR0SfInit();
+ rcVBox = vbglR0HGCMInit();
if (RT_FAILURE(rcVBox))
{
- LogRelFunc(("VbglR0SfInit failed, rc=%d\n", rcVBox));
+ LogRelFunc(("vbglR0HGCMInit failed, rc=%d\n", rcVBox));
rcRet = -EPROTO;
goto fail0;
}
@@ -647,7 +648,7 @@ fail2:
VbglR0SfDisconnect(&client_handle);
fail1:
- VbglR0SfTerm();
+ vbglR0HGCMTerminate();
fail0:
unregister_filesystem(&vboxsf_fs_type);
@@ -659,7 +660,7 @@ static void __exit fini(void)
TRACE();
VbglR0SfDisconnect(&client_handle);
- VbglR0SfTerm();
+ vbglR0HGCMTerminate();
unregister_filesystem(&vboxsf_fs_type);
}
--
2.13.0
_______________________________________________
vbox-dev mailing list
[email protected]
https://www.virtualbox.org/mailman/listinfo/vbox-dev