Hi there!

I've been trying to get shared folders working on FreeBSD 8.1 and came to a 
couple of problems. The following
patch attempts to remedy some of the issues when compiling with regards to the 
VMHGFS module. It fixes a couple
of compatability issues and also some memory leaks.

With respect to the meomry leaks however, a couple of memory leaks have been 
solved
(but only for the root vnode as allocated in HgfsMount() The problem remains 
however as
all the files allocated as the shared folders are used and several allocations 
are not freed.
For instance, after creating a couple of directories and files, a couple of 
listings and rm's,
a following warning is given upon unloading the vmhgfs module:

    "Warning: memory type vmhgfs leacking memory on destroy (21 allocations, 
14784 bytes leaked)"

These leaks correspond mostly with the file allocations (HgfsFile, in 
HgfsAllocFile()), and their corresponding synch objects ((modeMutex) and 
rwlocks (handleLock/rwFileLock(apple)) in  HgfsInitFile(for the mutexes & 
rwlocks)). 
There appear to have been also a couple of small allocations (two of 32 bytes) 
that have gone missing but these did not occur everytime (I think!) so I seem 
to have lost track of those, I'll have to do some more testing. A good thing to 
do I think, in
my opinion, would be to iterate through all the files allocated and free the 
data structures associated with those files including the file pointers 
themselves. Any thoughts?

The addition in state.c is necessary otherwise HGFS_VP_TO_SIP(vp) would page 
fault since vp->_mnt_data would always be NULL.
There are also a few other issues with random crashes that I haven't been able 
to track down yet such as a freeze on a mkdir on a shared
folder and also in some other seemingly random situations.

I've only tested on FreeBSD 8.1-RELEASE but I will test on 8.2, CURRENT and 
some older releases shortly.

diff -uNr open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/state.c 
open-vm-tools/modules/freebsd/vmhgfs/state.c
--- open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/state.c      
2010-09-20 18:30:55.000000000 +0000
+++ open-vm-tools/modules/freebsd/vmhgfs/state.c        2010-10-05 
00:52:47.000000000 +0000
@@ -761,6 +761,9 @@
       return ret;
    }

+   /* Store pointer to mount point */
+   vp->v_mount = vfsp;
+
    /*
     * Return a locked vnode to the caller.
     */
diff -uNr open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/vfsops.c 
open-vm-tools/modules/freebsd/vmhgfs/vfsops.c
--- open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/vfsops.c     
2010-09-20 18:30:55.000000000 +0000
+++ open-vm-tools/modules/freebsd/vmhgfs/vfsops.c       2010-10-05 
00:52:47.000000000 +0000
@@ -32,6 +32,9 @@
 #if __FreeBSD_version >= 700000
 #include <sys/priv.h>
 #endif
+#include <sys/fcntl.h>
+#include <sys/uio.h>
+#include <sys/types.h>

 #include "hgfs_kernel.h"
 #include "request.h"
@@ -109,8 +112,12 @@
  */

 static int
+#if __FreeBSD_version >= 800011
+HgfsVfsMount(struct mount *mp)  // IN: structure representing the file systems
+#else
 HgfsVfsMount(struct mount *mp,  // IN: structure representing the file system
              struct thread *td) // IN: thread which is mounting the file system
+#endif
 {
    HgfsSuperInfo *sip;
    struct vnode *vp;
@@ -145,7 +152,7 @@
     * Since Hgfs requires the caller to be root, only allow mount attempts made
     * by the superuser.
     */
-   if ((ret = suser(td)) != 0) {
+   if ((ret = compat_priv_check(compat_td, PRIV_DRIVER)) != 0) {
       return ret;
    }

@@ -176,7 +183,7 @@
    sip->rootVnode = vp;

    /* We're finished with the root vnode, so unlock it. */
-   COMPAT_VOP_UNLOCK(vp, 0, td);
+   COMPAT_VOP_UNLOCK(vp, 0, compat_td);

    /*
     * Initialize this file system's Hgfs requests container.
@@ -277,7 +284,11 @@
  */

 static int
+#if __FreeBSD_version >= 800011
+HgfsVfsUnmount(struct mount *mp, int mntflags)
+#else
 HgfsVfsUnmount(struct mount *mp, int mntflags, struct thread *td)
+#endif
 {
    HgfsSuperInfo *sip;
    int ret = 0;
@@ -309,11 +320,14 @@
    /*
     * Vflush will wait until all pending vnode operations are complete.
     */
-   ret = vflush(mp, 1, flags, td);
+   ret = vflush(mp, 1, flags, compat_td);
    if (ret != 0) {
       return ret;
    }

+   /* Release the root file's data structures */
+   HgfsReleaseVnodeContext(sip->rootVnode, &sip->fileHashTable);
+
    HgfsDestroyFileHashTable(&sip->fileHashTable);

    /*
@@ -348,7 +362,11 @@
  */

 static int
+#if __FreeBSD_version >= 800011
+HgfsVfsStatfs(struct mount *mp, struct statfs *sbp)
+#else
 HgfsVfsStatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
+#endif
 {
    int ret = 0;
    struct vnode *vp;
@@ -361,8 +379,11 @@
     * we got from a call to vfs_getnewfsid() in HgfsVfsMount()
     */
    bcopy(&mp->mnt_stat, sbp, sizeof mp->mnt_stat);
-
-   ret = HgfsVfsRoot(mp, LK_SHARED, &vp, td);
+#if __FreeBSD_version >= 800011
+   ret = HgfsVfsRoot(mp, LK_SHARED, &vp);
+#else
+   ret = HgfsVfsRoot(mp, LK_SHARED, &vp, compat_td);
+#endif
    if (ret) {
       DEBUG(VM_DEBUG_FAIL, "HgfsVfsRoot failed\n");
       return ret;
@@ -397,17 +418,23 @@
  */

 static int
-HgfsVfsRoot(struct mount *mp,   // IN: Filesystem structure
-            int flags,          // IN: Flags to vget
+#if __FreeBSD_version >= 800011
+HgfsVfsRoot(struct mount *mp,   // IN:  Filesystem structure
+                int flags,                  // IN:  Flags to vget
+                struct vnode **vpp) // OUT: Address of root vnode
+#else
+HgfsVfsRoot(struct mount *mp,   // IN:  Filesystem structure
+            int flags,          // IN:  Flags to vget
             struct vnode **vpp, // OUT: Address of root vnode
-            struct thread *td)  // IN: Thread structure
+            struct thread *td)  // IN:  Thread structure
+#endif
 {
    HgfsSuperInfo *sip = (HgfsSuperInfo *)mp->mnt_data;
    int ret = 0;

    *vpp = NULL;

-   ret = vget(sip->rootVnode, flags, td);
+   ret = vget(sip->rootVnode, flags, compat_td);
    if (ret == 0) {
       *vpp = sip->rootVnode;
    }
diff -uNr open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/vnops.c 
open-vm-tools/modules/freebsd/vmhgfs/vnops.c
--- open-vm-tools-2010.09.19-301124/modules/freebsd/vmhgfs/vnops.c      
2010-09-20 18:30:55.000000000 +0000
+++ open-vm-tools/modules/freebsd/vmhgfs/vnops.c        2010-10-05 
00:52:47.000000000 +0000
@@ -42,6 +42,7 @@
 #include "debug.h"
 #include "fsutil.h"
 #include "vnopscommon.h"
+#include "compat_vop.h"


 /*
@@ -325,7 +326,7 @@
 */
 {
    struct vnode *vp = ap->a_vp;
-   int mode = ap->a_mode;
+   compat_accmode_t mode = ap->compat_a_accmode;
    HgfsAccessMode accessMode = 0;
    Bool isDir = vp->v_type == VDIR;
    if (mode & VREAD) {

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
open-vm-tools-devel mailing list
open-vm-tools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-vm-tools-devel

Reply via email to