VirtualBox

Changeset 75433 in vbox


Ignore:
Timestamp:
Nov 13, 2018 10:34:39 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126586
Message:

linux/vboxsf,VBoxService: Added mount tag and implemented show_options so the tag (and more) is visible in /proc/mounts. Made use of the tag in VBoxService, also made it prefer /proc/mounts over /etc/mtab, and made it rmdir mountpoints during umount.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp

    r75415 r75433  
    169169/** The attachment tag we use to identify attchments that belongs to us. */
    170170static char const       g_szTag[] = "VBoxAutomounter";
     171#elif defined(RT_OS_LINUX)
     172/** Tag option value that lets us identify mounts that belongs to us. */
     173static char const       g_szTag[] = "VBoxAutomounter";
    171174#elif defined(RT_OS_SOLARIS)
    172175/** Dummy mount option that lets us identify mounts that belongs to us. */
     
    433436        mntinf.dmask = Opts.dmask;
    434437        mntinf.fmask = Opts.fmask;
     438        mntinf.tag[0] = '\0';
    435439
    436440        strcpy(mntinf.name, pszShareName);
     
    958962     * but later we may use the same approach as on solaris.
    959963     */
    960     char szMountPrefix[RTPATH_MAX];
    961     rc = vbsvcAutomounterQueryMountDirAndPrefix(szMountPrefix, sizeof(szMountPrefix));
    962     AssertRCReturn(rc, rc);
    963     size_t const cchMountPrefix = strlen(szMountPrefix);
    964 
    965     FILE *pFile = setmntent(_PATH_MOUNTED, "r");
     964    FILE *pFile = setmntent("/proc/mounts", "r");
     965    if (!pFile)
     966        pFile = setmntent("/etc/mtab", "r");
    966967    if (pFile)
    967968    {
     
    970971        while ((pEntry = getmntent(pFile)) != NULL)
    971972            if (strcmp(pEntry->mnt_type, "vboxsf") == 0)
    972             {
    973                 /** @todo add mount option for tagging a mount, make kernel show it by
    974                  *        implementing super_operations::show_options. */
    975                 if (strncmp(pEntry->mnt_dir, szMountPrefix, cchMountPrefix) == 0)
     973                if (strstr(pEntry->mnt_opts, g_szTag) != NULL)
    976974                {
    977975                    rc = vbsvcAutomounterAddEntry(pMountTable, pEntry->mnt_fsname, pEntry->mnt_dir);
     
    982980                    }
    983981                }
    984             }
    985982        endmntent(pFile);
    986983    }
     
    988985        VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab '%s' (errno=%d) or '/proc/mounts' (errno=%d)\n",
    989986                   _PATH_MOUNTED, errno);
    990     return rc;
    991987
    992988#elif defined(RT_OS_SOLARIS)
     
    11591155                    if (RTStrICmp(pszMountedName, pszName) == 0)
    11601156                    {
    1161                         VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",
     1157                        VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n",
    11621158                                     pszMountPoint, pszName);
    11631159                        rc = VINF_SUCCESS;
     
    12231219            if (RTStrICmp(pszMountedName, pszName) == 0)
    12241220            {
    1225                 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",
     1221                VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n",
    12261222                             pszMountPoint, pszName);
    12271223                rc = VINF_SUCCESS;
     
    12551251     * match file system and device/share.
    12561252     */
    1257     FILE *pFile = setmntent(_PATH_MOUNTED, "r");
     1253    FILE *pFile = setmntent("/proc/mounts", "r");
    12581254    int rc = errno;
    12591255    if (!pFile)
    1260         pFile = setmntent("/proc/mounts", "r");
     1256        pFile = setmntent(_PATH_MOUNTED, "r");
    12611257    if (pFile)
    12621258    {
     
    12701266                    if (RTStrICmp(pEntry->mnt_fsname, pszName) == 0)
    12711267                    {
    1272                         VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",
     1268                        VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n",
    12731269                                     pszMountPoint, pszName);
    12741270                        rc = VINF_SUCCESS;
     
    12931289    else
    12941290    {
    1295         VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab '%s' (errno=%d) or '/proc/mounts' (errno=%d)\n",
    1296                    _PATH_MOUNTED, rc, errno);
     1291        VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab '/proc/mounts' (errno=%d) or '%s' (errno=%d)\n",
     1292                   rc, _PATH_MOUNTED, errno);
    12971293        rc = VERR_ACCESS_DENIED;
    12981294    }
     
    13161312                    if (RTStrICmp(Entry.mnt_special, pszName) == 0)
    13171313                    {
    1318                         VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",
     1314                        VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n",
    13191315                                     pszMountPoint, pszName);
    13201316                        rc = VINF_SUCCESS;
     
    14781474    MntInfo.dmask        = MntOpts.dmask = 0000;
    14791475    MntInfo.fmask        = MntOpts.fmask = 0000;
     1476    memcpy(MntInfo.tag, g_szTag, sizeof(g_szTag)); AssertCompile(sizeof(MntInfo.tag) >= sizeof(g_szTag));
    14801477    rc = RTStrCopy(MntInfo.name, sizeof(MntInfo.name), pEntry->pszName);
    14811478    if (RT_FAILURE(rc))
     
    14951492        errno = 0;
    14961493        rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, &MntOpts);
    1497         if (rc == 0)
    1498             return VINF_SUCCESS;
    1499 
    1500         VGSvcError("vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n",
    1501                    rc == 1 ? "open_memstream" : rc == 2 ? "setmntent" : rc == 3 ? "addmntent" : "unknown", rc, errno);
     1494        if (rc != 0) /* Ignorable. /etc/mtab is probably a link to /proc/mounts. */
     1495            VGSvcVerbose(1, "vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n",
     1496                         rc == 1 ? "open_memstream" : rc == 2 ? "setmntent" : rc == 3 ? "addmntent" : "unknown", rc, errno);
     1497        return VINF_SUCCESS;
    15021498    }
    15031499    else if (errno == EINVAL)
     
    16301626         * Path based #2: Mount dir + prefix + share.
    16311627         */
    1632         /* Mount base directory: */
    1633         szActualMountPoint[0] = '\0';
    1634         char *pszProp;
    1635         rc = VbglR3SharedFolderGetMountDir(&pszProp);
     1628        rc = vbsvcAutomounterQueryMountDirAndPrefix(szActualMountPoint, sizeof(szActualMountPoint));
    16361629        if (RT_SUCCESS(rc))
    16371630        {
    1638             if (*pszProp == '/')
    1639                 rc = RTPathAbs(pszProp, szActualMountPoint, sizeof(szActualMountPoint));
    1640             else
    1641                 VGSvcError("vbsvcAutomounterMountNewEntry: Invalid mount directory: '%s'\n", pszProp);
    1642             RTStrFree(pszProp);
    1643         }
    1644         if (RT_FAILURE(rc) || szActualMountPoint[0] != '/')
    1645             memcpy(szActualMountPoint, VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR, sizeof(VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR));
    1646 
    1647         /* Add prefix: */
    1648         rc = VbglR3SharedFolderGetMountPrefix(&pszProp);
    1649         if (RT_SUCCESS(rc))
    1650         {
    1651             if (   strchr(pszProp, '/')  == NULL
    1652                 && strchr(pszProp, '\\') == NULL
    1653                 && strcmp(pszProp, "..") != 0)
    1654                 rc = RTPathAppend(szActualMountPoint, sizeof(szActualMountPoint), pszProp);
    1655             else
    1656                 VGSvcError("vbsvcAutomounterMountNewEntry: Invalid mount prefix: '%s'\n", pszProp);
    1657             RTStrFree(pszProp);
    1658         }
    1659         else
    1660             rc = RTPathEnsureTrailingSeparator(szActualMountPoint, sizeof(szActualMountPoint)) != 0
    1661                ? VINF_SUCCESS : VERR_BUFFER_OVERFLOW;
    1662         if (RT_SUCCESS(rc))
    1663         {
    1664             /* Add sanitized share name: */
     1631            /* Append a sanitized share name: */
    16651632            size_t const offShare = strlen(szActualMountPoint);
    16661633            size_t offDst = offShare;
     
    18241791        int rc2 = umount(pszMountPoint);
    18251792        if (rc2 == 0)
     1793        {
     1794            /* Remove the mount directory if not directly under the root dir. */
     1795            RTPATHPARSED Parsed = { 0 };
     1796            RTPathParse(pszMountPoint, &Parsed, sizeof(Parsed), RTPATH_STR_F_STYLE_HOST);
     1797            if (Parsed.cComps >= 3)
     1798                RTDirRemove(pszMountPoint);
     1799
    18261800            return VINF_SUCCESS;
     1801        }
    18271802        rc2 = errno;
    18281803        VGSvcVerbose(2, "vbsvcAutomounterUnmount: umount failed on '%s' ('%s'): %d\n", pszMountPoint, pszName, rc2);
     
    18651840    Assert(iTable < pTable->cEntries);
    18661841    PVBSVCAUTOMOUNTERENTRY pEntry = pTable->papEntries[iTable];
    1867     VGSvcVerbose(3, "vbsvcAutomounterUnmountEntry: #%u: '%s' at '%s' (reason: %s)\n",
    1868                  iTable, pEntry->pszName, pEntry->pszMountPoint, pszReason);
     1842    VGSvcVerbose(2, "vbsvcAutomounterUnmountEntry: #%u: '%s' at '%s' (reason: %s)\n",
     1843                 iTable, pEntry->pszName, pEntry->pszActualMountPoint, pszReason);
    18691844
    18701845    /*
     
    18761851        if (rc == VERR_TRY_AGAIN)
    18771852        {
    1878             VGSvcVerbose(2, "vbsvcAutomounterUnmountEntry: Keeping '%s' -> '%s' (VERR_TRY_AGAIN)\n",
     1853            VGSvcVerbose(1, "vbsvcAutomounterUnmountEntry: Keeping '%s' -> '%s' (VERR_TRY_AGAIN)\n",
    18791854                         pEntry->pszActualMountPoint, pEntry->pszName);
    18801855            return iTable + 1;
  • trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c

    r69500 r75433  
    402402    mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
    403403    mntinf.length       = sizeof(mntinf);
     404    mntinf.tag[0] = '\0';
    404405
    405406    if (getuid())
  • trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h

    r72627 r75433  
    5959        int dmask;              /* umask applied to directories */
    6060        int fmask;              /* umask applied to regular files */
     61        char tag[32];           /**< Mount tag for VBoxService automounter.  @since 6.0 */
    6162};
    6263
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c

    r75407 r75433  
    156156        sf_g->gid = info->gid;
    157157
    158         if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) {
     158        if ((unsigned)info->length >= RT_UOFFSETOF(struct vbsf_mount_info_new, tag)) {
    159159                /* new fields */
    160160                sf_g->dmode = info->dmode;
     
    165165                sf_g->dmode = ~0;
    166166                sf_g->fmode = ~0;
     167        }
     168
     169        if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) {
     170                AssertCompile(sizeof(sf_g->tag) >= sizeof(info->tag));
     171                memcpy(sf_g->tag, info->tag, sizeof(info->tag));
     172                sf_g->tag[sizeof(sf_g->tag) - 1] = '\0';
     173        } else {
     174                sf_g->tag[0] = '\0';
    167175        }
    168176
     
    457465                        sf_g->gid = info->gid;
    458466                        sf_g->ttl = info->ttl;
    459                         sf_g->dmode = info->dmode;
    460                         sf_g->fmode = info->fmode;
    461                         sf_g->dmask = info->dmask;
    462                         sf_g->fmask = info->fmask;
     467                        if ((unsigned)info->length >= RT_UOFFSETOF(struct vbsf_mount_info_new, tag)) {
     468                                sf_g->dmode = info->dmode;
     469                                sf_g->fmode = info->fmode;
     470                                sf_g->dmask = info->dmask;
     471                                sf_g->fmask = info->fmask;
     472                        } else {
     473                                sf_g->dmode = ~0;
     474                                sf_g->fmode = ~0;
     475                        }
     476                        if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) {
     477                                AssertCompile(sizeof(sf_g->tag) >= sizeof(info->tag));
     478                                memcpy(sf_g->tag, info->tag, sizeof(info->tag));
     479                                sf_g->tag[sizeof(sf_g->tag) - 1] = '\0';
     480                        } else {
     481                                sf_g->tag[0] = '\0';
     482                        }
    463483                }
    464484        }
     
    479499}
    480500
     501/** Show mount options. */
     502#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
     503static int sf_show_options(struct seq_file *m, struct vfsmount *mnt)
     504#else
     505static int sf_show_options(struct seq_file *m, struct dentry *root)
     506#endif
     507{
     508#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
     509        struct super_block *sb = mnt->mnt_sb;
     510#else
     511        struct super_block *sb = root->d_sb;
     512#endif
     513        struct sf_glob_info *sf_g = GET_GLOB_INFO(sb);
     514        if (sf_g) {
     515                seq_printf(m, ",uid=%u,gid=%u,ttl=%u,dmode=0%o,fmode=0%o,dmask=0%o,fmask=0%o",
     516                        sf_g->uid, sf_g->gid, sf_g->ttl, sf_g->dmode, sf_g->fmode, sf_g->dmask, sf_g->fmask);
     517                if (sf_g->tag[0] != '\0') {
     518                        seq_puts(m, ",tag=");
     519                        seq_escape(m, sf_g->tag, " \t\n\\");
     520                }
     521        }
     522
     523    return 0;
     524}
     525
    481526/** @todo Implement show_options (forever) or maybe set s_options (2.6.25+).
    482527 *        Necessary for the automounter tagging.  */
     
    492537        .put_super = sf_put_super,
    493538        .statfs = sf_statfs,
    494         .remount_fs = sf_remount_fs
     539        .remount_fs = sf_remount_fs,
     540        .show_options = sf_show_options
    495541};
    496542
  • trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.h

    r72627 r75433  
    5858        struct backing_dev_info bdi;
    5959#endif
     60        char tag[32];           /**< Mount tag for VBoxService automounter.  @since 6.0 */
    6061};
    6162
Note: See TracChangeset for help on using the changeset viewer.

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