VirtualBox

Changeset 77854 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 22, 2019 10:23:36 PM (6 years ago)
Author:
vboxsync
Message:

linux/vboxsf: Cleaned up init(), moving the file system registration to the end of everything to avoid races. Also coverted the UTF-8 and symlinks setting to fast HGCM requests. bugref:9172

Location:
trunk/src/VBox/Additions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibSharedFolders.c

    r77304 r77854  
    5151*   Defined Constants And Macros                                                                                                 *
    5252*********************************************************************************************************************************/
    53 #define SHFL_CPARMS_SET_UTF8 0
    54 #define SHFL_CPARMS_SET_SYMLINKS 0
    55 
    5653#define VBOX_INIT_CALL(a, b, c) \
    5754    LogFunc(("%s, idClient=%d\n", "SHFL_FN_" # b, (c)->idClient)); \
     
    10198}
    10299
     100#if !defined(RT_OS_LINUX)
     101
    103102DECLVBGL(int) VbglR0SfSetUtf8(PVBGLSFCLIENT pClient)
    104103{
     
    111110    return rc;
    112111}
    113 
    114 #if !defined(RT_OS_LINUX)
    115112
    116113/** @name       Deprecated VBGL shared folder helpers.
     
    393390}
    394391
    395 #endif /* !RT_OS_LINUX */
    396 
    397392DECLVBGL(int) VbglR0SfWrite(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile,
    398393                            uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer, bool fLocked)
     
    425420    return rc;
    426421}
    427 
    428 #ifndef RT_OS_LINUX
    429422
    430423DECLVBGL(int) VbglR0SfWritePhysCont(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile, uint64_t offset,
     
    697690}
    698691
     692#if !defined(RT_OS_LINUX)
     693
    699694DECLVBGL(int) VbglR0SfSetSymlinks(PVBGLSFCLIENT pClient)
    700695{
     
    708703}
    709704
     705#endif /* !RT_OS_LINUX */
    710706
    711707/** @} */
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c

    r77853 r77854  
    5353#include <linux/seq_file.h>
    5454#include <linux/vfs.h>
    55 #include <iprt/err.h>
     55#include <VBox/err.h>
    5656#include <iprt/path.h>
    5757
     
    7575
    7676/* forward declaration */
    77 static struct super_operations sf_super_ops;
     77static struct super_operations g_vbsf_super_ops;
    7878
    7979
     
    503503# endif
    504504#endif
    505         sb->s_op = &sf_super_ops;
     505        sb->s_op = &g_vbsf_super_ops;
    506506#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
    507507        sb->s_d_op = &vbsf_dentry_ops;
     
    723723 * Super block operations.
    724724 */
    725 static struct super_operations sf_super_ops = {
     725static struct super_operations g_vbsf_super_ops = {
    726726#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
    727     .clear_inode = vbsf_clear_inode,
     727    .clear_inode  = vbsf_clear_inode,
    728728#else
    729     .evict_inode = vbsf_evict_inode,
     729    .evict_inode  = vbsf_evict_inode,
    730730#endif
    731731#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
    732     .read_inode = vbsf_read_inode,
    733 #endif
    734     .put_super = vbsf_put_super,
    735     .statfs = vbsf_statfs,
    736     .remount_fs = vbsf_remount_fs,
     732    .read_inode   = vbsf_read_inode,
     733#endif
     734    .put_super    = vbsf_put_super,
     735    .statfs       = vbsf_statfs,
     736    .remount_fs   = vbsf_remount_fs,
    737737    .show_options = vbsf_show_options
    738738};
    739739
    740740
    741 /*
    742  * File system type related stuff.
    743  */
     741
     742/*********************************************************************************************************************************
     743*   File system type related stuff.                                                                                              *
     744*********************************************************************************************************************************/
    744745
    745746#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 4)
     
    777778# endif /* LINUX_VERSION_CODE >= 2.6.39 */
    778779
    779 static struct file_system_type vboxsf_fs_type = {
     780/**
     781 * File system registration structure.
     782 */
     783static struct file_system_type g_vboxsf_fs_type = {
    780784    .owner = THIS_MODULE,
    781785    .name = "vboxsf",
     
    804808}
    805809
    806 static DECLARE_FSTYPE(vboxsf_fs_type, "vboxsf", vbsf_read_super_24, 0);
     810static DECLARE_FSTYPE(g_vboxsf_fs_type, "vboxsf", vbsf_read_super_24, 0);
    807811
    808812#endif /* LINUX_VERSION_CODE < 2.5.4 */
    809813
    810814
    811 /* Module initialization/finalization handlers */
     815
     816/*********************************************************************************************************************************
     817*   Module stuff                                                                                                                 *
     818*********************************************************************************************************************************/
     819
     820/**
     821 * Called on module initialization.
     822 */
    812823static int __init init(void)
    813824{
    814     int rcRet = 0;
    815     int vrc;
    816     int err;
    817 
    818     TRACE();
    819 
     825    int rc;
     826    SFLOGFLOW(("vboxsf: init\n"));
     827
     828    /*
     829     * Must be paranoid about the vbsf_mount_info_new size.
     830     */
    820831    AssertCompile(sizeof(struct vbsf_mount_info_new) <= PAGE_SIZE);
    821832    if (sizeof(struct vbsf_mount_info_new) > PAGE_SIZE) {
    822833        printk(KERN_ERR
    823                "Mount information structure is too large %lu\n"
    824                "Must be less than or equal to %lu\n",
     834               "vboxsf: Mount information structure is too large %lu\n"
     835               "vboxsf: Must be less than or equal to %lu\n",
    825836               (unsigned long)sizeof(struct vbsf_mount_info_new),
    826837               (unsigned long)PAGE_SIZE);
     
    828839    }
    829840
    830     /** @todo Init order is wrong, file system reigstration is the very last
    831      *        thing we should do. */
     841    /*
     842     * Initialize stuff.
     843     */
    832844    spin_lock_init(&g_SfHandleLock);
    833     err = register_filesystem(&vboxsf_fs_type);
    834     if (err) {
    835         LogFunc(("register_filesystem err=%d\n", err));
    836         return err;
    837     }
    838 
    839     vrc = VbglR0SfInit();
    840     if (RT_FAILURE(vrc)) {
    841         LogRelFunc(("VbglR0SfInit failed, vrc=%Rrc\n", vrc));
    842         rcRet = -EPROTO;
    843         goto fail0;
    844     }
    845 
    846     vrc = VbglR0SfConnect(&g_SfClient);
    847     if (RT_FAILURE(vrc)) {
    848         LogRelFunc(("VbglR0SfConnect failed, vrc=%Rrc\n", vrc));
    849         rcRet = -EPROTO;
    850         goto fail1;
    851     }
    852 
    853     vrc = VbglR0QueryHostFeatures(&g_fHostFeatures);
    854     if (RT_FAILURE(vrc))
    855     {
    856         LogRelFunc(("VbglR0QueryHostFeatures failed: vrc=%Rrc (ignored)\n", vrc));
    857         g_fHostFeatures = 0;
    858     }
    859 
    860     VbglR0SfHostReqQueryFeaturesSimple(&g_fSfFeatures, &g_uSfLastFunction);
    861     LogRelFunc(("g_fHostFeatures=%#x g_fSfFeatures=%#RX64 g_uSfLastFunction=%u\n",
    862                 g_fHostFeatures, g_fSfFeatures, g_uSfLastFunction));
    863 
    864     vrc = VbglR0SfSetUtf8(&g_SfClient);
    865     if (RT_FAILURE(vrc)) {
    866         LogRelFunc(("VbglR0SfSetUtf8 failed, vrc=%Rrc\n", vrc));
    867         rcRet = -EPROTO;
    868         goto fail2;
    869     }
     845    rc = VbglR0SfInit();
     846    if (RT_SUCCESS(rc)) {
     847        /*
     848         * Try connect to the shared folder HGCM service.
     849         * It is possible it is not there.
     850         */
     851        rc = VbglR0SfConnect(&g_SfClient);
     852        if (RT_SUCCESS(rc)) {
     853            /*
     854             * Query host HGCM features and afterwards (must be last) shared folder features.
     855             */
     856            rc = VbglR0QueryHostFeatures(&g_fHostFeatures);
     857            if (RT_FAILURE(rc))
     858            {
     859                LogRel(("vboxsf: VbglR0QueryHostFeatures failed: rc=%Rrc (ignored)\n", rc));
     860                g_fHostFeatures = 0;
     861            }
     862            VbglR0SfHostReqQueryFeaturesSimple(&g_fSfFeatures, &g_uSfLastFunction);
     863            LogRel(("vboxsf: g_fHostFeatures=%#x g_fSfFeatures=%#RX64 g_uSfLastFunction=%u\n",
     864                    g_fHostFeatures, g_fSfFeatures, g_uSfLastFunction));
     865
     866            /*
     867             * Tell the shared folder service about our expectations:
     868             *      - UTF-8 strings (rather than UTF-16)
     869             *      - Wheter to return or follow (default) symbolic links.
     870             */
     871            rc = VbglR0SfHostReqSetUtf8Simple();
     872            if (RT_SUCCESS(rc)) {
    870873#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    871     if (!g_fFollowSymlinks) {
    872         vrc = VbglR0SfSetSymlinks(&g_SfClient);
    873         if (RT_FAILURE(vrc)) {
    874             printk(KERN_WARNING
    875                    "vboxsf: Host unable to show symlinks, vrc=%d\n",
    876                    vrc);
     874                if (!g_fFollowSymlinks) {
     875                    rc = VbglR0SfHostReqSetSymlinksSimple();
     876                    if (RT_FAILURE(rc))
     877                        printk(KERN_WARNING "vboxsf: Host unable to show symlinks, rc=%d\n", rc);
     878                }
     879#endif
     880                /*
     881                 * Now that we're ready for action, try register the
     882                 * file system with the kernel.
     883                 */
     884                rc = register_filesystem(&g_vboxsf_fs_type);
     885                if (rc == 0) {
     886                    printk(KERN_INFO "vboxsf: Successfully loaded version " VBOX_VERSION_STRING "\n");
     887                    return 0;
     888                }
     889
     890                /*
     891                 * Failed. Bail out.
     892                 */
     893                LogRel(("vboxsf: register_filesystem failed: rc=%d\n", rc));
     894            } else  {
     895                LogRel(("vboxsf: VbglR0SfSetUtf8 failed, rc=%Rrc\n", rc));
     896                rc = -EPROTO;
     897            }
     898            VbglR0SfDisconnect(&g_SfClient);
     899        } else {
     900            LogRel(("vboxsf: VbglR0SfConnect failed, rc=%Rrc\n", rc));
     901            rc = rc == VERR_HGCM_SERVICE_NOT_FOUND ? -EHOSTDOWN : -ECONNREFUSED;
    877902        }
    878     }
    879 #endif
    880 
    881     printk(KERN_DEBUG
    882            "vboxsf: Successfully loaded version " VBOX_VERSION_STRING
    883            " (interface " RT_XSTR(VMMDEV_VERSION) ")\n");
    884 
    885     return 0;
    886 
    887  fail2:
    888     VbglR0SfDisconnect(&g_SfClient);
    889 
    890  fail1:
    891     VbglR0SfTerm();
    892 
    893  fail0:
    894     unregister_filesystem(&vboxsf_fs_type);
    895     return rcRet;
    896 }
    897 
     903        VbglR0SfTerm();
     904    } else {
     905        LogRel(("vboxsf: VbglR0SfInit failed, rc=%Rrc\n", rc));
     906        rc = -EPROTO;
     907    }
     908    return rc;
     909}
     910
     911
     912/**
     913 * Called on module finalization.
     914 */
    898915static void __exit fini(void)
    899916{
    900     TRACE();
    901 
     917    SFLOGFLOW(("vboxsf: fini\n"));
     918
     919    unregister_filesystem(&g_vboxsf_fs_type);
    902920    VbglR0SfDisconnect(&g_SfClient);
    903921    VbglR0SfTerm();
    904     unregister_filesystem(&vboxsf_fs_type);
    905922}
    906923
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette