2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2004-12-03 22:38:06 +00:00
|
|
|
* Copyright (c) 1999-2004 Poul-Henning Kamp
|
2004-12-06 12:44:30 +00:00
|
|
|
* Copyright (c) 1999 Michael Smith
|
2002-07-02 17:09:22 +00:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2016-09-15 13:16:20 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2002-07-02 17:09:22 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
2002-07-02 18:33:32 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-24 10:09:53 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2002-07-02 18:33:32 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-24 10:09:53 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
2019-09-16 21:31:02 +00:00
|
|
|
#include <sys/smp.h>
|
2020-08-21 00:03:24 +00:00
|
|
|
#include <sys/devctl.h>
|
2018-01-07 18:07:22 +00:00
|
|
|
#include <sys/eventhandler.h>
|
2008-03-31 12:01:21 +00:00
|
|
|
#include <sys/fcntl.h>
|
2004-02-02 19:02:05 +00:00
|
|
|
#include <sys/jail.h>
|
2002-07-02 17:09:22 +00:00
|
|
|
#include <sys/kernel.h>
|
2019-05-21 20:38:48 +00:00
|
|
|
#include <sys/ktr.h>
|
2005-02-03 15:10:58 +00:00
|
|
|
#include <sys/libkern.h>
|
2021-05-17 22:47:27 +00:00
|
|
|
#include <sys/limits.h>
|
2002-08-01 17:47:56 +00:00
|
|
|
#include <sys/malloc.h>
|
2002-07-02 17:09:22 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/filedesc.h>
|
2002-07-02 17:09:22 +00:00
|
|
|
#include <sys/reboot.h>
|
2011-07-11 05:17:46 +00:00
|
|
|
#include <sys/sbuf.h>
|
2004-12-07 08:15:41 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2002-07-02 17:09:22 +00:00
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/systm.h>
|
2021-06-12 19:42:12 +00:00
|
|
|
#include <sys/taskqueue.h>
|
2002-07-05 05:15:30 +00:00
|
|
|
#include <sys/vnode.h>
|
2006-03-31 03:49:51 +00:00
|
|
|
#include <vm/uma.h>
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2002-10-25 18:44:42 +00:00
|
|
|
#include <geom/geom.h>
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
#include <machine/stdarg.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2006-06-05 15:32:07 +00:00
|
|
|
#include <security/audit/audit.h>
|
2006-10-22 11:52:19 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
2006-06-05 15:32:07 +00:00
|
|
|
|
2003-11-14 05:27:41 +00:00
|
|
|
#define VFS_MOUNTARG_SIZE_MAX (1024 * 64)
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2012-01-17 01:08:01 +00:00
|
|
|
static int vfs_domount(struct thread *td, const char *fstype, char *fspath,
|
|
|
|
uint64_t fsflags, struct vfsoptlist **optlist);
|
2005-02-10 12:25:38 +00:00
|
|
|
static void free_mntarg(struct mntarg *ma);
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2004-03-27 08:39:28 +00:00
|
|
|
static int usermount = 0;
|
|
|
|
SYSCTL_INT(_vfs, OID_AUTO, usermount, CTLFLAG_RW, &usermount, 0,
|
|
|
|
"Unprivileged users may mount and unmount file systems");
|
2001-05-01 08:13:21 +00:00
|
|
|
|
2018-03-27 14:31:42 +00:00
|
|
|
static bool default_autoro = false;
|
|
|
|
SYSCTL_BOOL(_vfs, OID_AUTO, default_autoro, CTLFLAG_RW, &default_autoro, 0,
|
|
|
|
"Retry failed r/w mount as r/o if no explicit ro/rw option is specified");
|
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
static bool recursive_forced_unmount = false;
|
|
|
|
SYSCTL_BOOL(_vfs, OID_AUTO, recursive_forced_unmount, CTLFLAG_RW,
|
|
|
|
&recursive_forced_unmount, 0, "Recursively unmount stacked upper mounts"
|
|
|
|
" when a file system is forcibly unmounted");
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure");
|
2017-01-05 17:19:26 +00:00
|
|
|
MALLOC_DEFINE(M_STATFS, "statfs", "statfs structure");
|
2006-03-31 03:49:51 +00:00
|
|
|
static uma_zone_t mount_zone;
|
1997-02-10 02:22:35 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/* List of mounted filesystems. */
|
|
|
|
struct mntlist mountlist = TAILQ_HEAD_INITIALIZER(mountlist);
|
|
|
|
|
|
|
|
/* For any iteration/modification of mountlist */
|
2020-10-17 08:47:08 +00:00
|
|
|
struct mtx_padalign __exclusive_cache_line mountlist_mtx;
|
2005-04-18 21:11:47 +00:00
|
|
|
MTX_SYSINIT(mountlist, &mountlist_mtx, "mountlist", MTX_DEF);
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2018-01-07 18:07:22 +00:00
|
|
|
EVENTHANDLER_LIST_DEFINE(vfs_mounted);
|
|
|
|
EVENTHANDLER_LIST_DEFINE(vfs_unmounted);
|
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
static void vfs_deferred_unmount(void *arg, int pending);
|
|
|
|
static struct task deferred_unmount_task =
|
|
|
|
TASK_INITIALIZER(0, vfs_deferred_unmount, NULL);;
|
|
|
|
static struct mtx deferred_unmount_lock;
|
|
|
|
MTX_SYSINIT(deferred_unmount, &deferred_unmount_lock, "deferred_unmount",
|
|
|
|
MTX_DEF);
|
|
|
|
static STAILQ_HEAD(, mount) deferred_unmount_list =
|
|
|
|
STAILQ_HEAD_INITIALIZER(deferred_unmount_list);
|
|
|
|
TASKQUEUE_DEFINE_THREAD(deferred_unmount);
|
|
|
|
|
2020-08-20 16:52:48 +00:00
|
|
|
static void mount_devctl_event(const char *type, struct mount *mp, bool donew);
|
2020-08-19 17:10:04 +00:00
|
|
|
|
2004-12-06 18:18:35 +00:00
|
|
|
/*
|
|
|
|
* Global opts, taken by all filesystems
|
|
|
|
*/
|
|
|
|
static const char *global_opts[] = {
|
2005-12-08 04:09:29 +00:00
|
|
|
"errmsg",
|
2004-12-06 18:18:35 +00:00
|
|
|
"fstype",
|
|
|
|
"fspath",
|
|
|
|
"ro",
|
2005-12-03 01:26:27 +00:00
|
|
|
"rw",
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
"nosuid",
|
|
|
|
"noexec",
|
2004-12-06 18:18:35 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-10-02 19:44:13 +00:00
|
|
|
static int
|
|
|
|
mount_init(void *mem, int size, int flags)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
1999-11-04 01:40:18 +00:00
|
|
|
|
2010-10-02 19:44:13 +00:00
|
|
|
mp = (struct mount *)mem;
|
|
|
|
mtx_init(&mp->mnt_mtx, "struct mount mtx", NULL, MTX_DEF);
|
2016-09-30 17:27:17 +00:00
|
|
|
mtx_init(&mp->mnt_listmtx, "struct mount vlist mtx", NULL, MTX_DEF);
|
2010-10-02 19:44:13 +00:00
|
|
|
lockinit(&mp->mnt_explock, PVFS, "explock", 0, 0);
|
2020-11-09 23:02:13 +00:00
|
|
|
mp->mnt_pcpu = uma_zalloc_pcpu(pcpu_zone_16, M_WAITOK | M_ZERO);
|
2019-09-16 21:31:02 +00:00
|
|
|
mp->mnt_ref = 0;
|
|
|
|
mp->mnt_vfs_ops = 1;
|
2019-10-06 22:14:32 +00:00
|
|
|
mp->mnt_rootvnode = NULL;
|
2010-10-02 19:44:13 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mount_fini(void *mem, int size)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
|
|
|
|
mp = (struct mount *)mem;
|
2020-11-09 23:02:13 +00:00
|
|
|
uma_zfree_pcpu(pcpu_zone_16, mp->mnt_pcpu);
|
2010-10-02 19:44:13 +00:00
|
|
|
lockdestroy(&mp->mnt_explock);
|
2016-09-30 17:27:17 +00:00
|
|
|
mtx_destroy(&mp->mnt_listmtx);
|
2010-10-02 19:44:13 +00:00
|
|
|
mtx_destroy(&mp->mnt_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vfs_mount_init(void *dummy __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
mount_zone = uma_zcreate("Mountpoints", sizeof(struct mount), NULL,
|
2019-09-19 21:23:14 +00:00
|
|
|
NULL, mount_init, mount_fini, UMA_ALIGN_CACHE, UMA_ZONE_NOFREE);
|
2010-10-02 19:44:13 +00:00
|
|
|
}
|
|
|
|
SYSINIT(vfs_mount, SI_SUB_VFS, SI_ORDER_ANY, vfs_mount_init, NULL);
|
2004-12-07 08:15:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
* Functions for building and sanitizing the mount options
|
|
|
|
*/
|
1995-08-28 09:19:25 +00:00
|
|
|
|
2002-07-19 16:05:31 +00:00
|
|
|
/* Remove one mount option. */
|
|
|
|
static void
|
|
|
|
vfs_freeopt(struct vfsoptlist *opts, struct vfsopt *opt)
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_REMOVE(opts, opt, link);
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
if (opt->value != NULL)
|
|
|
|
free(opt->value, M_MOUNT);
|
|
|
|
free(opt, M_MOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release all resources related to the mount options. */
|
2007-03-31 22:44:45 +00:00
|
|
|
void
|
2002-07-02 17:09:22 +00:00
|
|
|
vfs_freeopts(struct vfsoptlist *opts)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(opts)) {
|
|
|
|
opt = TAILQ_FIRST(opts);
|
2002-07-19 16:05:31 +00:00
|
|
|
vfs_freeopt(opts, opt);
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
free(opts, M_MOUNT);
|
|
|
|
}
|
|
|
|
|
2006-12-16 15:44:03 +00:00
|
|
|
void
|
|
|
|
vfs_deleteopt(struct vfsoptlist *opts, const char *name)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt, *temp;
|
2007-03-14 12:54:10 +00:00
|
|
|
|
2008-08-10 12:15:36 +00:00
|
|
|
if (opts == NULL)
|
|
|
|
return;
|
2006-12-16 15:44:03 +00:00
|
|
|
TAILQ_FOREACH_SAFE(opt, opts, link, temp) {
|
|
|
|
if (strcmp(opt->name, name) == 0)
|
|
|
|
vfs_freeopt(opts, opt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:56:38 +00:00
|
|
|
static int
|
|
|
|
vfs_isopt_ro(const char *opt)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(opt, "ro") == 0 || strcmp(opt, "rdonly") == 0 ||
|
|
|
|
strcmp(opt, "norw") == 0)
|
|
|
|
return (1);
|
2011-03-26 17:17:24 +00:00
|
|
|
return (0);
|
2011-03-23 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vfs_isopt_rw(const char *opt)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(opt, "rw") == 0 || strcmp(opt, "noro") == 0)
|
|
|
|
return (1);
|
2011-03-26 17:17:24 +00:00
|
|
|
return (0);
|
2011-03-23 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2004-03-27 08:39:28 +00:00
|
|
|
/*
|
|
|
|
* Check if options are equal (with or without the "no" prefix).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_equalopts(const char *opt1, const char *opt2)
|
|
|
|
{
|
2009-03-02 23:26:30 +00:00
|
|
|
char *p;
|
2004-03-27 08:39:28 +00:00
|
|
|
|
|
|
|
/* "opt" vs. "opt" or "noopt" vs. "noopt" */
|
|
|
|
if (strcmp(opt1, opt2) == 0)
|
|
|
|
return (1);
|
|
|
|
/* "noopt" vs. "opt" */
|
|
|
|
if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0)
|
|
|
|
return (1);
|
|
|
|
/* "opt" vs. "noopt" */
|
|
|
|
if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0)
|
|
|
|
return (1);
|
2009-03-02 23:26:30 +00:00
|
|
|
while ((p = strchr(opt1, '.')) != NULL &&
|
|
|
|
!strncmp(opt1, opt2, ++p - opt1)) {
|
|
|
|
opt2 += p - opt1;
|
|
|
|
opt1 = p;
|
|
|
|
/* "foo.noopt" vs. "foo.opt" */
|
|
|
|
if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0)
|
|
|
|
return (1);
|
|
|
|
/* "foo.opt" vs. "foo.noopt" */
|
|
|
|
if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0)
|
|
|
|
return (1);
|
|
|
|
}
|
2011-03-23 17:56:38 +00:00
|
|
|
/* "ro" / "rdonly" / "norw" / "rw" / "noro" */
|
|
|
|
if ((vfs_isopt_ro(opt1) || vfs_isopt_rw(opt1)) &&
|
|
|
|
(vfs_isopt_ro(opt2) || vfs_isopt_rw(opt2)))
|
|
|
|
return (1);
|
2004-03-27 08:39:28 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-07-19 16:05:31 +00:00
|
|
|
/*
|
|
|
|
* If a mount option is specified several times,
|
|
|
|
* (with or without the "no" prefix) only keep
|
2013-04-17 11:40:10 +00:00
|
|
|
* the last occurrence of it.
|
2002-07-19 16:05:31 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vfs_sanitizeopts(struct vfsoptlist *opts)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt, *opt2, *tmp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_REVERSE(opt, opts, vfsoptlist, link) {
|
|
|
|
opt2 = TAILQ_PREV(opt, vfsoptlist, link);
|
|
|
|
while (opt2 != NULL) {
|
2004-03-27 08:39:28 +00:00
|
|
|
if (vfs_equalopts(opt->name, opt2->name)) {
|
2002-07-19 16:05:31 +00:00
|
|
|
tmp = TAILQ_PREV(opt2, vfsoptlist, link);
|
|
|
|
vfs_freeopt(opts, opt2);
|
|
|
|
opt2 = tmp;
|
|
|
|
} else {
|
|
|
|
opt2 = TAILQ_PREV(opt2, vfsoptlist, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Build a linked list of mount options from a struct uio.
|
|
|
|
*/
|
2009-03-02 23:26:30 +00:00
|
|
|
int
|
2002-07-02 17:09:22 +00:00
|
|
|
vfs_buildopts(struct uio *auio, struct vfsoptlist **options)
|
|
|
|
{
|
|
|
|
struct vfsoptlist *opts;
|
|
|
|
struct vfsopt *opt;
|
2009-03-02 23:26:30 +00:00
|
|
|
size_t memused, namelen, optlen;
|
2002-07-02 17:09:22 +00:00
|
|
|
unsigned int i, iovcnt;
|
2009-03-02 23:26:30 +00:00
|
|
|
int error;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK);
|
2002-07-02 17:09:22 +00:00
|
|
|
TAILQ_INIT(opts);
|
2003-11-14 05:27:41 +00:00
|
|
|
memused = 0;
|
|
|
|
iovcnt = auio->uio_iovcnt;
|
2002-07-02 17:09:22 +00:00
|
|
|
for (i = 0; i < iovcnt; i += 2) {
|
|
|
|
namelen = auio->uio_iov[i].iov_len;
|
|
|
|
optlen = auio->uio_iov[i + 1].iov_len;
|
2003-11-14 05:27:41 +00:00
|
|
|
memused += sizeof(struct vfsopt) + optlen + namelen;
|
2003-11-12 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* Avoid consuming too much memory, and attempts to overflow
|
2003-11-14 05:27:41 +00:00
|
|
|
* memused.
|
2003-11-12 02:54:47 +00:00
|
|
|
*/
|
|
|
|
if (memused > VFS_MOUNTARG_SIZE_MAX ||
|
|
|
|
optlen > VFS_MOUNTARG_SIZE_MAX ||
|
|
|
|
namelen > VFS_MOUNTARG_SIZE_MAX) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2009-03-02 23:26:30 +00:00
|
|
|
opt = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK);
|
|
|
|
opt->name = malloc(namelen, M_MOUNT, M_WAITOK);
|
|
|
|
opt->value = NULL;
|
|
|
|
opt->len = 0;
|
|
|
|
opt->pos = i / 2;
|
|
|
|
opt->seen = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do this early, so jumps to "bad" will free the current
|
|
|
|
* option.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(opts, opt, link);
|
|
|
|
|
2002-07-24 19:50:00 +00:00
|
|
|
if (auio->uio_segflg == UIO_SYSSPACE) {
|
|
|
|
bcopy(auio->uio_iov[i].iov_base, opt->name, namelen);
|
2002-07-02 17:09:22 +00:00
|
|
|
} else {
|
2002-07-24 19:50:00 +00:00
|
|
|
error = copyin(auio->uio_iov[i].iov_base, opt->name,
|
|
|
|
namelen);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
2003-11-14 05:27:41 +00:00
|
|
|
/* Ensure names are null-terminated strings. */
|
2009-03-02 23:26:30 +00:00
|
|
|
if (namelen == 0 || opt->name[namelen - 1] != '\0') {
|
2003-11-14 05:27:41 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
2003-11-12 02:54:47 +00:00
|
|
|
}
|
2002-07-24 19:50:00 +00:00
|
|
|
if (optlen != 0) {
|
2004-09-05 22:24:28 +00:00
|
|
|
opt->len = optlen;
|
2003-02-19 05:47:46 +00:00
|
|
|
opt->value = malloc(optlen, M_MOUNT, M_WAITOK);
|
2002-07-19 16:05:31 +00:00
|
|
|
if (auio->uio_segflg == UIO_SYSSPACE) {
|
|
|
|
bcopy(auio->uio_iov[i + 1].iov_base, opt->value,
|
|
|
|
optlen);
|
|
|
|
} else {
|
2002-07-02 17:09:22 +00:00
|
|
|
error = copyin(auio->uio_iov[i + 1].iov_base,
|
|
|
|
opt->value, optlen);
|
2002-07-19 16:05:31 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-19 16:05:31 +00:00
|
|
|
vfs_sanitizeopts(opts);
|
2002-07-02 17:09:22 +00:00
|
|
|
*options = opts;
|
|
|
|
return (0);
|
|
|
|
bad:
|
|
|
|
vfs_freeopts(opts);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-07-19 16:05:31 +00:00
|
|
|
/*
|
|
|
|
* Merge the old mount options with the new ones passed
|
|
|
|
* in the MNT_UPDATE case.
|
2008-02-18 10:10:42 +00:00
|
|
|
*
|
2011-04-22 07:26:09 +00:00
|
|
|
* XXX: This function will keep a "nofoo" option in the new
|
|
|
|
* options. E.g, if the option's canonical name is "foo",
|
|
|
|
* "nofoo" ends up in the mount point's active options.
|
2002-07-19 16:05:31 +00:00
|
|
|
*/
|
|
|
|
static void
|
2011-04-22 07:26:09 +00:00
|
|
|
vfs_mergeopts(struct vfsoptlist *toopts, struct vfsoptlist *oldopts)
|
2002-07-19 16:05:31 +00:00
|
|
|
{
|
2011-04-22 07:26:09 +00:00
|
|
|
struct vfsopt *opt, *new;
|
2002-07-19 16:05:31 +00:00
|
|
|
|
2011-04-22 07:26:09 +00:00
|
|
|
TAILQ_FOREACH(opt, oldopts, link) {
|
2003-02-19 05:47:46 +00:00
|
|
|
new = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK);
|
2011-04-22 07:26:09 +00:00
|
|
|
new->name = strdup(opt->name, M_MOUNT);
|
2002-07-19 16:05:31 +00:00
|
|
|
if (opt->len != 0) {
|
2003-02-19 05:47:46 +00:00
|
|
|
new->value = malloc(opt->len, M_MOUNT, M_WAITOK);
|
2002-07-19 16:05:31 +00:00
|
|
|
bcopy(opt->value, new->value, opt->len);
|
2011-04-22 07:26:09 +00:00
|
|
|
} else
|
2002-07-19 16:05:31 +00:00
|
|
|
new->value = NULL;
|
|
|
|
new->len = opt->len;
|
2009-03-02 23:26:30 +00:00
|
|
|
new->seen = opt->seen;
|
2011-04-22 07:26:09 +00:00
|
|
|
TAILQ_INSERT_HEAD(toopts, new, link);
|
2002-07-19 16:05:31 +00:00
|
|
|
}
|
2011-04-22 07:26:09 +00:00
|
|
|
vfs_sanitizeopts(toopts);
|
2002-07-19 16:05:31 +00:00
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
2007-03-05 13:10:58 +00:00
|
|
|
* Mount a filesystem.
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
2017-05-17 00:34:34 +00:00
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct nmount_args {
|
|
|
|
struct iovec *iovp;
|
|
|
|
unsigned int iovcnt;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
#endif
|
2002-07-02 17:09:22 +00:00
|
|
|
int
|
2017-05-17 00:34:34 +00:00
|
|
|
sys_nmount(struct thread *td, struct nmount_args *uap)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
2004-07-10 15:42:16 +00:00
|
|
|
struct uio *auio;
|
2002-07-02 17:09:22 +00:00
|
|
|
int error;
|
2004-07-10 15:42:16 +00:00
|
|
|
u_int iovcnt;
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t flags;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2012-01-17 01:08:01 +00:00
|
|
|
/*
|
|
|
|
* Mount flags are now 64-bits. On 32-bit archtectures only
|
|
|
|
* 32-bits are passed in, but from here on everything handles
|
|
|
|
* 64-bit flags correctly.
|
|
|
|
*/
|
|
|
|
flags = uap->flags;
|
|
|
|
|
|
|
|
AUDIT_ARG_FFLAGS(flags);
|
2009-02-05 15:03:35 +00:00
|
|
|
CTR4(KTR_VFS, "%s: iovp %p with iovcnt %d and flags %d", __func__,
|
2012-01-17 01:08:01 +00:00
|
|
|
uap->iovp, uap->iovcnt, flags);
|
2006-06-05 15:32:07 +00:00
|
|
|
|
2007-10-27 15:59:18 +00:00
|
|
|
/*
|
|
|
|
* Filter out MNT_ROOTFS. We do not want clients of nmount() in
|
|
|
|
* userspace to set this flag, but we must filter it out if we want
|
|
|
|
* MNT_UPDATE on the root file system to work.
|
2010-11-23 13:49:15 +00:00
|
|
|
* MNT_ROOTFS should only be set by the kernel when mounting its
|
|
|
|
* root file system.
|
2007-10-27 15:59:18 +00:00
|
|
|
*/
|
2012-01-17 01:08:01 +00:00
|
|
|
flags &= ~MNT_ROOTFS;
|
2004-12-03 19:25:44 +00:00
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
iovcnt = uap->iovcnt;
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Check that we have an even number of iovec's
|
|
|
|
* and that we have at least two options.
|
|
|
|
*/
|
2009-02-05 15:03:35 +00:00
|
|
|
if ((iovcnt & 1) || (iovcnt < 4)) {
|
|
|
|
CTR2(KTR_VFS, "%s: failed for invalid iovcnt %d", __func__,
|
|
|
|
uap->iovcnt);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (EINVAL);
|
2009-02-05 15:03:35 +00:00
|
|
|
}
|
2004-12-03 19:25:44 +00:00
|
|
|
|
2004-07-10 15:42:16 +00:00
|
|
|
error = copyinuio(uap->iovp, iovcnt, &auio);
|
2009-02-05 15:03:35 +00:00
|
|
|
if (error) {
|
|
|
|
CTR2(KTR_VFS, "%s: failed for invalid uio op with %d errno",
|
|
|
|
__func__, error);
|
2004-07-10 15:42:16 +00:00
|
|
|
return (error);
|
2009-02-05 15:03:35 +00:00
|
|
|
}
|
2012-01-17 01:08:01 +00:00
|
|
|
error = vfs_donmount(td, flags, auio);
|
2005-11-09 02:26:38 +00:00
|
|
|
|
2004-07-10 15:42:16 +00:00
|
|
|
free(auio, M_IOV);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-12-07 08:15:41 +00:00
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
* Various utility functions
|
|
|
|
*/
|
|
|
|
|
2021-02-15 22:08:40 +00:00
|
|
|
/*
|
|
|
|
* Get a reference on a mount point from a vnode.
|
|
|
|
*
|
|
|
|
* The vnode is allowed to be passed unlocked and race against dooming. Note in
|
|
|
|
* such case there are no guarantees the referenced mount point will still be
|
|
|
|
* associated with it after the function returns.
|
|
|
|
*/
|
|
|
|
struct mount *
|
|
|
|
vfs_ref_from_vp(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
struct mount_pcpu *mpcpu;
|
|
|
|
|
|
|
|
mp = atomic_load_ptr(&vp->v_mount);
|
|
|
|
if (__predict_false(mp == NULL)) {
|
|
|
|
return (mp);
|
|
|
|
}
|
|
|
|
if (vfs_op_thread_enter(mp, mpcpu)) {
|
|
|
|
if (__predict_true(mp == vp->v_mount)) {
|
|
|
|
vfs_mp_count_add_pcpu(mpcpu, ref, 1);
|
|
|
|
vfs_op_thread_exit(mp, mpcpu);
|
|
|
|
} else {
|
|
|
|
vfs_op_thread_exit(mp, mpcpu);
|
|
|
|
mp = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
if (mp == vp->v_mount) {
|
|
|
|
MNT_REF(mp);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
} else {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
mp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (mp);
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:19:50 +00:00
|
|
|
void
|
|
|
|
vfs_ref(struct mount *mp)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2006-02-06 10:19:50 +00:00
|
|
|
|
2009-02-05 15:03:35 +00:00
|
|
|
CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
|
2020-11-09 23:02:13 +00:00
|
|
|
if (vfs_op_thread_enter(mp, mpcpu)) {
|
|
|
|
vfs_mp_count_add_pcpu(mpcpu, ref, 1);
|
|
|
|
vfs_op_thread_exit(mp, mpcpu);
|
2019-09-16 21:31:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:19:50 +00:00
|
|
|
MNT_ILOCK(mp);
|
|
|
|
MNT_REF(mp);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
/*
|
|
|
|
* Register ump as an upper mount of the mount associated with
|
|
|
|
* vnode vp. This registration will be tracked through
|
|
|
|
* mount_upper_node upper, which should be allocated by the
|
|
|
|
* caller and stored in per-mount data associated with mp.
|
|
|
|
*
|
|
|
|
* If successful, this function will return the mount associated
|
|
|
|
* with vp, and will ensure that it cannot be unmounted until
|
|
|
|
* ump has been unregistered as one of its upper mounts.
|
|
|
|
*
|
|
|
|
* Upon failure this function will return NULL.
|
|
|
|
*/
|
2021-05-17 22:47:27 +00:00
|
|
|
struct mount *
|
2021-06-12 19:42:12 +00:00
|
|
|
vfs_register_upper_from_vp(struct vnode *vp, struct mount *ump,
|
|
|
|
struct mount_upper_node *upper)
|
2021-05-17 22:47:27 +00:00
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
|
|
|
|
mp = atomic_load_ptr(&vp->v_mount);
|
|
|
|
if (mp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
MNT_ILOCK(mp);
|
2021-06-12 19:42:12 +00:00
|
|
|
if (mp != vp->v_mount ||
|
|
|
|
((mp->mnt_kern_flag & (MNTK_UNMOUNT | MNTK_RECURSE)) != 0)) {
|
2021-05-17 22:47:27 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2021-06-12 19:42:12 +00:00
|
|
|
KASSERT(ump != mp, ("upper and lower mounts are identical"));
|
|
|
|
upper->mp = ump;
|
2021-05-17 22:47:27 +00:00
|
|
|
MNT_REF(mp);
|
2021-06-12 19:42:12 +00:00
|
|
|
TAILQ_INSERT_TAIL(&mp->mnt_uppers, upper, mnt_upper_link);
|
2021-05-17 22:47:27 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
return (mp);
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
/*
|
|
|
|
* Register upper mount ump to receive vnode unlink/reclaim
|
|
|
|
* notifications from lower mount mp. This registration will
|
|
|
|
* be tracked through mount_upper_node upper, which should be
|
|
|
|
* allocated by the caller and stored in per-mount data
|
|
|
|
* associated with mp.
|
|
|
|
*
|
|
|
|
* ump must already be registered as an upper mount of mp
|
|
|
|
* through a call to vfs_register_upper_from_vp().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vfs_register_for_notification(struct mount *mp, struct mount *ump,
|
|
|
|
struct mount_upper_node *upper)
|
|
|
|
{
|
|
|
|
upper->mp = ump;
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
TAILQ_INSERT_TAIL(&mp->mnt_notify, upper, mnt_upper_link);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vfs_drain_upper_locked(struct mount *mp)
|
|
|
|
{
|
|
|
|
mtx_assert(MNT_MTX(mp), MA_OWNED);
|
|
|
|
while (mp->mnt_upper_pending != 0) {
|
|
|
|
mp->mnt_kern_flag |= MNTK_UPPER_WAITER;
|
|
|
|
msleep(&mp->mnt_uppers, MNT_MTX(mp), 0, "mntupw", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo a previous call to vfs_register_for_notification().
|
|
|
|
* The mount represented by upper must be currently registered
|
|
|
|
* as an upper mount for mp.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vfs_unregister_for_notification(struct mount *mp,
|
|
|
|
struct mount_upper_node *upper)
|
|
|
|
{
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
vfs_drain_upper_locked(mp);
|
|
|
|
TAILQ_REMOVE(&mp->mnt_notify, upper, mnt_upper_link);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo a previous call to vfs_register_upper_from_vp().
|
|
|
|
* This must be done before mp can be unmounted.
|
|
|
|
*/
|
2021-05-17 22:47:27 +00:00
|
|
|
void
|
2021-06-12 19:42:12 +00:00
|
|
|
vfs_unregister_upper(struct mount *mp, struct mount_upper_node *upper)
|
2021-05-17 22:47:27 +00:00
|
|
|
{
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
KASSERT((mp->mnt_kern_flag & MNTK_UNMOUNT) == 0,
|
2021-06-12 19:42:12 +00:00
|
|
|
("registered upper with pending unmount"));
|
|
|
|
vfs_drain_upper_locked(mp);
|
|
|
|
TAILQ_REMOVE(&mp->mnt_uppers, upper, mnt_upper_link);
|
|
|
|
if ((mp->mnt_kern_flag & MNTK_TASKQUEUE_WAITER) != 0 &&
|
|
|
|
TAILQ_EMPTY(&mp->mnt_uppers)) {
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_TASKQUEUE_WAITER;
|
|
|
|
wakeup(&mp->mnt_taskqueue_link);
|
|
|
|
}
|
2021-05-17 22:47:27 +00:00
|
|
|
MNT_REL(mp);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:19:50 +00:00
|
|
|
void
|
|
|
|
vfs_rel(struct mount *mp)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2006-02-06 10:19:50 +00:00
|
|
|
|
2009-02-05 15:03:35 +00:00
|
|
|
CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
|
2020-11-09 23:02:13 +00:00
|
|
|
if (vfs_op_thread_enter(mp, mpcpu)) {
|
|
|
|
vfs_mp_count_sub_pcpu(mpcpu, ref, 1);
|
|
|
|
vfs_op_thread_exit(mp, mpcpu);
|
2019-09-16 21:31:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:19:50 +00:00
|
|
|
MNT_ILOCK(mp);
|
|
|
|
MNT_REL(mp);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
2003-11-12 02:54:47 +00:00
|
|
|
* Allocate and initialize the mount point struct.
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
2007-04-17 21:14:06 +00:00
|
|
|
struct mount *
|
2008-08-31 14:26:08 +00:00
|
|
|
vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp, const char *fspath,
|
|
|
|
struct ucred *cred)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
|
|
|
struct mount *mp;
|
2003-11-12 02:54:47 +00:00
|
|
|
|
2006-03-31 03:49:51 +00:00
|
|
|
mp = uma_zalloc(mount_zone, M_WAITOK);
|
|
|
|
bzero(&mp->mnt_startzero,
|
|
|
|
__rangeof(struct mount, mnt_startzero, mnt_endzero));
|
2020-11-09 23:02:13 +00:00
|
|
|
mp->mnt_kern_flag = 0;
|
|
|
|
mp->mnt_flag = 0;
|
|
|
|
mp->mnt_rootvnode = NULL;
|
|
|
|
mp->mnt_vnodecovered = NULL;
|
|
|
|
mp->mnt_op = NULL;
|
|
|
|
mp->mnt_vfc = NULL;
|
2003-11-12 02:54:47 +00:00
|
|
|
TAILQ_INIT(&mp->mnt_nvnodelist);
|
|
|
|
mp->mnt_nvnodelistsize = 0;
|
2020-01-13 02:34:02 +00:00
|
|
|
TAILQ_INIT(&mp->mnt_lazyvnodelist);
|
|
|
|
mp->mnt_lazyvnodelistsize = 0;
|
2019-09-16 21:31:02 +00:00
|
|
|
if (mp->mnt_ref != 0 || mp->mnt_lockref != 0 ||
|
|
|
|
mp->mnt_writeopcount != 0)
|
|
|
|
panic("%s: non-zero counters on new mp %p\n", __func__, mp);
|
|
|
|
if (mp->mnt_vfs_ops != 1)
|
|
|
|
panic("%s: vfs_ops should be 1 but %d found\n", __func__,
|
|
|
|
mp->mnt_vfs_ops);
|
2008-11-02 10:15:42 +00:00
|
|
|
(void) vfs_busy(mp, MBF_NOWAIT);
|
2014-08-03 03:27:54 +00:00
|
|
|
atomic_add_acq_int(&vfsp->vfc_refcount, 1);
|
2003-11-12 02:54:47 +00:00
|
|
|
mp->mnt_op = vfsp->vfc_vfsops;
|
|
|
|
mp->mnt_vfc = vfsp;
|
|
|
|
mp->mnt_stat.f_type = vfsp->vfc_typenum;
|
2006-10-03 10:47:04 +00:00
|
|
|
mp->mnt_gen++;
|
2003-11-12 02:54:47 +00:00
|
|
|
strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
|
|
|
|
mp->mnt_vnodecovered = vp;
|
2008-08-31 14:26:08 +00:00
|
|
|
mp->mnt_cred = crdup(cred);
|
|
|
|
mp->mnt_stat.f_owner = cred->cr_uid;
|
2003-11-12 02:54:47 +00:00
|
|
|
strlcpy(mp->mnt_stat.f_mntonname, fspath, MNAMELEN);
|
|
|
|
mp->mnt_iosize_max = DFLTPHYS;
|
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
mac_mount_init(mp);
|
2008-08-31 14:26:08 +00:00
|
|
|
mac_mount_create(cred, mp);
|
2003-11-12 02:54:47 +00:00
|
|
|
#endif
|
2005-03-16 07:35:06 +00:00
|
|
|
arc4rand(&mp->mnt_hashseed, sizeof mp->mnt_hashseed, 0);
|
2021-06-12 19:42:12 +00:00
|
|
|
mp->mnt_upper_pending = 0;
|
2012-09-09 19:17:15 +00:00
|
|
|
TAILQ_INIT(&mp->mnt_uppers);
|
2021-06-12 19:42:12 +00:00
|
|
|
TAILQ_INIT(&mp->mnt_notify);
|
|
|
|
mp->mnt_taskqueue_flags = 0;
|
2005-12-20 00:43:51 +00:00
|
|
|
return (mp);
|
2003-11-12 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 05:27:41 +00:00
|
|
|
/*
|
|
|
|
* Destroy the mount struct previously allocated by vfs_mount_alloc().
|
|
|
|
*/
|
2007-03-31 22:44:45 +00:00
|
|
|
void
|
2006-06-02 20:29:02 +00:00
|
|
|
vfs_mount_destroy(struct mount *mp)
|
2003-11-12 02:54:47 +00:00
|
|
|
{
|
|
|
|
|
2019-09-16 21:31:02 +00:00
|
|
|
if (mp->mnt_vfs_ops == 0)
|
|
|
|
panic("%s: entered with zero vfs_ops\n", __func__);
|
|
|
|
|
2019-09-16 21:37:47 +00:00
|
|
|
vfs_assert_mount_counters(mp);
|
|
|
|
|
2006-01-09 20:42:19 +00:00
|
|
|
MNT_ILOCK(mp);
|
1) Fix a deadlock in the VFS:
- threadA runs vfs_rel(mp1)
- threadB does unmount the mp1 fs, sets MNTK_UNMOUNT and drop MNT_ILOCK()
- threadA runs vfs_busy(mp1) and, as long as, MNTK_UNMOUNT is set, sleeps
waiting for threadB to complete the unmount
- threadB, in vfs_mount_destroy(), finds mnt_lock > 0 and sleeps waiting
for the refcount to expire.
Fix the deadlock by adding a flag called MNTK_REFEXPIRE which signals the
unmounter is waiting for mnt_ref to expire.
The vfs_busy contenders got awake, fails, and if they retry the
MNTK_REFEXPIRE won't allow them to sleep again.
2) Simplify significantly the code of vfs_mount_destroy() trimming
unnecessary codes:
- as long as any reference exited, it is no-more possible to have
write-op (primarty and secondary) in progress.
- it is no needed to drop and reacquire the mount lock.
- filling the structures with dummy values is unuseful as long as
it is going to be freed.
Tested by: pho, Andrea Barberio <insomniac at slackware dot it>
Discussed with: kib
2008-12-16 23:16:10 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_REFEXPIRE;
|
|
|
|
if (mp->mnt_kern_flag & MNTK_MWAIT) {
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_MWAIT;
|
|
|
|
wakeup(mp);
|
|
|
|
}
|
2008-11-02 10:15:42 +00:00
|
|
|
while (mp->mnt_ref)
|
|
|
|
msleep(mp, MNT_MTX(mp), PVFS, "mntref", 0);
|
1) Fix a deadlock in the VFS:
- threadA runs vfs_rel(mp1)
- threadB does unmount the mp1 fs, sets MNTK_UNMOUNT and drop MNT_ILOCK()
- threadA runs vfs_busy(mp1) and, as long as, MNTK_UNMOUNT is set, sleeps
waiting for threadB to complete the unmount
- threadB, in vfs_mount_destroy(), finds mnt_lock > 0 and sleeps waiting
for the refcount to expire.
Fix the deadlock by adding a flag called MNTK_REFEXPIRE which signals the
unmounter is waiting for mnt_ref to expire.
The vfs_busy contenders got awake, fails, and if they retry the
MNTK_REFEXPIRE won't allow them to sleep again.
2) Simplify significantly the code of vfs_mount_destroy() trimming
unnecessary codes:
- as long as any reference exited, it is no-more possible to have
write-op (primarty and secondary) in progress.
- it is no needed to drop and reacquire the mount lock.
- filling the structures with dummy values is unuseful as long as
it is going to be freed.
Tested by: pho, Andrea Barberio <insomniac at slackware dot it>
Discussed with: kib
2008-12-16 23:16:10 +00:00
|
|
|
KASSERT(mp->mnt_ref == 0,
|
|
|
|
("%s: invalid refcount in the drain path @ %s:%d", __func__,
|
|
|
|
__FILE__, __LINE__));
|
|
|
|
if (mp->mnt_writeopcount != 0)
|
|
|
|
panic("vfs_mount_destroy: nonzero writeopcount");
|
|
|
|
if (mp->mnt_secondary_writes != 0)
|
|
|
|
panic("vfs_mount_destroy: nonzero secondary_writes");
|
2014-08-03 03:27:54 +00:00
|
|
|
atomic_subtract_rel_int(&mp->mnt_vfc->vfc_refcount, 1);
|
2006-03-31 23:38:15 +00:00
|
|
|
if (!TAILQ_EMPTY(&mp->mnt_nvnodelist)) {
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes)
|
2016-08-10 16:12:31 +00:00
|
|
|
vn_printf(vp, "dangling vnode ");
|
2003-11-12 02:54:47 +00:00
|
|
|
panic("unmount: dangling vnode");
|
2006-03-31 23:38:15 +00:00
|
|
|
}
|
2021-06-12 19:42:12 +00:00
|
|
|
KASSERT(mp->mnt_upper_pending == 0, ("mnt_upper_pending"));
|
2012-09-09 19:17:15 +00:00
|
|
|
KASSERT(TAILQ_EMPTY(&mp->mnt_uppers), ("mnt_uppers"));
|
2021-06-12 19:42:12 +00:00
|
|
|
KASSERT(TAILQ_EMPTY(&mp->mnt_notify), ("mnt_notify"));
|
2006-01-09 20:42:19 +00:00
|
|
|
if (mp->mnt_nvnodelistsize != 0)
|
|
|
|
panic("vfs_mount_destroy: nonzero nvnodelistsize");
|
2020-01-13 02:34:02 +00:00
|
|
|
if (mp->mnt_lazyvnodelistsize != 0)
|
|
|
|
panic("vfs_mount_destroy: nonzero lazyvnodelistsize");
|
1) Fix a deadlock in the VFS:
- threadA runs vfs_rel(mp1)
- threadB does unmount the mp1 fs, sets MNTK_UNMOUNT and drop MNT_ILOCK()
- threadA runs vfs_busy(mp1) and, as long as, MNTK_UNMOUNT is set, sleeps
waiting for threadB to complete the unmount
- threadB, in vfs_mount_destroy(), finds mnt_lock > 0 and sleeps waiting
for the refcount to expire.
Fix the deadlock by adding a flag called MNTK_REFEXPIRE which signals the
unmounter is waiting for mnt_ref to expire.
The vfs_busy contenders got awake, fails, and if they retry the
MNTK_REFEXPIRE won't allow them to sleep again.
2) Simplify significantly the code of vfs_mount_destroy() trimming
unnecessary codes:
- as long as any reference exited, it is no-more possible to have
write-op (primarty and secondary) in progress.
- it is no needed to drop and reacquire the mount lock.
- filling the structures with dummy values is unuseful as long as
it is going to be freed.
Tested by: pho, Andrea Barberio <insomniac at slackware dot it>
Discussed with: kib
2008-12-16 23:16:10 +00:00
|
|
|
if (mp->mnt_lockref != 0)
|
|
|
|
panic("vfs_mount_destroy: nonzero lock refcount");
|
2005-01-24 10:28:41 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2019-09-16 21:31:02 +00:00
|
|
|
|
|
|
|
if (mp->mnt_vfs_ops != 1)
|
|
|
|
panic("%s: vfs_ops should be 1 but %d found\n", __func__,
|
|
|
|
mp->mnt_vfs_ops);
|
|
|
|
|
2019-10-06 22:14:32 +00:00
|
|
|
if (mp->mnt_rootvnode != NULL)
|
|
|
|
panic("%s: mount point still has a root vnode %p\n", __func__,
|
|
|
|
mp->mnt_rootvnode);
|
|
|
|
|
2017-09-19 16:49:45 +00:00
|
|
|
if (mp->mnt_vnodecovered != NULL)
|
|
|
|
vrele(mp->mnt_vnodecovered);
|
2003-11-12 02:54:47 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
mac_mount_destroy(mp);
|
2003-11-12 02:54:47 +00:00
|
|
|
#endif
|
2003-11-23 17:13:48 +00:00
|
|
|
if (mp->mnt_opt != NULL)
|
2003-11-12 02:54:47 +00:00
|
|
|
vfs_freeopts(mp->mnt_opt);
|
|
|
|
crfree(mp->mnt_cred);
|
2006-03-31 03:49:51 +00:00
|
|
|
uma_zfree(mount_zone, mp);
|
2003-11-12 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 14:31:42 +00:00
|
|
|
static bool
|
|
|
|
vfs_should_downgrade_to_ro_mount(uint64_t fsflags, int error)
|
|
|
|
{
|
|
|
|
/* This is an upgrade of an exisiting mount. */
|
|
|
|
if ((fsflags & MNT_UPDATE) != 0)
|
|
|
|
return (false);
|
|
|
|
/* This is already an R/O mount. */
|
|
|
|
if ((fsflags & MNT_RDONLY) != 0)
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
case ENODEV: /* generic, geom, ... */
|
|
|
|
case EACCES: /* cam/scsi, ... */
|
|
|
|
case EROFS: /* md, mmcsd, ... */
|
|
|
|
/*
|
|
|
|
* These errors can be returned by the storage layer to signal
|
|
|
|
* that the media is read-only. No harm in the R/O mount
|
|
|
|
* attempt if the error was returned for some other reason.
|
|
|
|
*/
|
|
|
|
return (true);
|
|
|
|
default:
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-19 15:17:32 +00:00
|
|
|
int
|
2012-01-17 01:08:01 +00:00
|
|
|
vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions)
|
2003-11-12 02:54:47 +00:00
|
|
|
{
|
2002-07-02 17:09:22 +00:00
|
|
|
struct vfsoptlist *optlist;
|
2011-04-22 07:26:09 +00:00
|
|
|
struct vfsopt *opt, *tmp_opt;
|
2005-11-23 20:51:15 +00:00
|
|
|
char *fstype, *fspath, *errmsg;
|
|
|
|
int error, fstypelen, fspathlen, errmsg_len, errmsg_pos;
|
2018-03-27 14:31:42 +00:00
|
|
|
bool autoro;
|
2005-11-12 14:41:44 +00:00
|
|
|
|
2008-09-19 15:17:32 +00:00
|
|
|
errmsg = fspath = NULL;
|
2011-04-22 07:26:09 +00:00
|
|
|
errmsg_len = fspathlen = 0;
|
2005-11-23 20:51:15 +00:00
|
|
|
errmsg_pos = -1;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = default_autoro;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
|
|
|
error = vfs_buildopts(fsoptions, &optlist);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2007-03-14 12:54:10 +00:00
|
|
|
if (vfs_getopt(optlist, "errmsg", (void **)&errmsg, &errmsg_len) == 0)
|
2005-11-23 20:51:15 +00:00
|
|
|
errmsg_pos = vfs_getopt_pos(optlist, "errmsg");
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* We need these two options before the others,
|
|
|
|
* and they are mandatory for any filesystem.
|
|
|
|
* Ensure they are NUL terminated as well.
|
|
|
|
*/
|
|
|
|
fstypelen = 0;
|
|
|
|
error = vfs_getopt(optlist, "fstype", (void **)&fstype, &fstypelen);
|
2019-09-27 16:22:28 +00:00
|
|
|
if (error || fstypelen <= 0 || fstype[fstypelen - 1] != '\0') {
|
2002-07-02 17:09:22 +00:00
|
|
|
error = EINVAL;
|
2005-11-23 20:51:15 +00:00
|
|
|
if (errmsg != NULL)
|
2013-01-04 11:11:12 +00:00
|
|
|
strncpy(errmsg, "Invalid fstype", errmsg_len);
|
2003-11-12 02:54:47 +00:00
|
|
|
goto bail;
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
fspathlen = 0;
|
|
|
|
error = vfs_getopt(optlist, "fspath", (void **)&fspath, &fspathlen);
|
2019-09-27 16:22:28 +00:00
|
|
|
if (error || fspathlen <= 0 || fspath[fspathlen - 1] != '\0') {
|
2002-07-02 17:09:22 +00:00
|
|
|
error = EINVAL;
|
2005-11-23 20:51:15 +00:00
|
|
|
if (errmsg != NULL)
|
2013-01-04 11:11:12 +00:00
|
|
|
strncpy(errmsg, "Invalid fspath", errmsg_len);
|
2003-11-12 02:54:47 +00:00
|
|
|
goto bail;
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
|
2005-11-18 01:31:10 +00:00
|
|
|
/*
|
|
|
|
* We need to see if we have the "update" option
|
|
|
|
* before we call vfs_domount(), since vfs_domount() has special
|
|
|
|
* logic based on MNT_UPDATE. This is very important
|
|
|
|
* when we want to update the root filesystem.
|
2007-03-14 12:54:10 +00:00
|
|
|
*/
|
2008-07-12 20:12:40 +00:00
|
|
|
TAILQ_FOREACH_SAFE(opt, optlist, link, tmp_opt) {
|
2019-09-23 04:28:07 +00:00
|
|
|
int do_freeopt = 0;
|
|
|
|
|
2008-07-12 20:12:40 +00:00
|
|
|
if (strcmp(opt->name, "update") == 0) {
|
2006-03-13 14:58:37 +00:00
|
|
|
fsflags |= MNT_UPDATE;
|
2019-09-23 04:28:07 +00:00
|
|
|
do_freeopt = 1;
|
2008-07-12 20:12:40 +00:00
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "async") == 0)
|
|
|
|
fsflags |= MNT_ASYNC;
|
2008-08-23 01:16:09 +00:00
|
|
|
else if (strcmp(opt->name, "force") == 0) {
|
2006-03-13 14:58:37 +00:00
|
|
|
fsflags |= MNT_FORCE;
|
2019-09-23 04:28:07 +00:00
|
|
|
do_freeopt = 1;
|
2008-08-23 01:16:09 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(opt->name, "reload") == 0) {
|
|
|
|
fsflags |= MNT_RELOAD;
|
2019-09-23 04:28:07 +00:00
|
|
|
do_freeopt = 1;
|
2008-08-23 01:16:09 +00:00
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "multilabel") == 0)
|
|
|
|
fsflags |= MNT_MULTILABEL;
|
|
|
|
else if (strcmp(opt->name, "noasync") == 0)
|
|
|
|
fsflags &= ~MNT_ASYNC;
|
|
|
|
else if (strcmp(opt->name, "noatime") == 0)
|
|
|
|
fsflags |= MNT_NOATIME;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "atime") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonoatime", M_MOUNT);
|
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "noclusterr") == 0)
|
|
|
|
fsflags |= MNT_NOCLUSTERR;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "clusterr") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonoclusterr", M_MOUNT);
|
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "noclusterw") == 0)
|
|
|
|
fsflags |= MNT_NOCLUSTERW;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "clusterw") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonoclusterw", M_MOUNT);
|
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "noexec") == 0)
|
|
|
|
fsflags |= MNT_NOEXEC;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "exec") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonoexec", M_MOUNT);
|
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "nosuid") == 0)
|
|
|
|
fsflags |= MNT_NOSUID;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "suid") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonosuid", M_MOUNT);
|
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "nosymfollow") == 0)
|
|
|
|
fsflags |= MNT_NOSYMFOLLOW;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
else if (strcmp(opt->name, "symfollow") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("nonosymfollow", M_MOUNT);
|
|
|
|
}
|
2018-03-27 14:31:42 +00:00
|
|
|
else if (strcmp(opt->name, "noro") == 0) {
|
2006-05-14 01:51:38 +00:00
|
|
|
fsflags &= ~MNT_RDONLY;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = false;
|
|
|
|
}
|
|
|
|
else if (strcmp(opt->name, "rw") == 0) {
|
2006-03-13 14:58:37 +00:00
|
|
|
fsflags &= ~MNT_RDONLY;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = false;
|
|
|
|
}
|
|
|
|
else if (strcmp(opt->name, "ro") == 0) {
|
2006-03-13 14:58:37 +00:00
|
|
|
fsflags |= MNT_RDONLY;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = false;
|
|
|
|
}
|
2007-12-05 03:26:14 +00:00
|
|
|
else if (strcmp(opt->name, "rdonly") == 0) {
|
|
|
|
free(opt->name, M_MOUNT);
|
|
|
|
opt->name = strdup("ro", M_MOUNT);
|
|
|
|
fsflags |= MNT_RDONLY;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = false;
|
|
|
|
}
|
|
|
|
else if (strcmp(opt->name, "autoro") == 0) {
|
2019-09-23 04:28:07 +00:00
|
|
|
do_freeopt = 1;
|
2018-03-27 14:31:42 +00:00
|
|
|
autoro = true;
|
2007-12-05 03:26:14 +00:00
|
|
|
}
|
2006-03-13 14:58:37 +00:00
|
|
|
else if (strcmp(opt->name, "suiddir") == 0)
|
|
|
|
fsflags |= MNT_SUIDDIR;
|
|
|
|
else if (strcmp(opt->name, "sync") == 0)
|
|
|
|
fsflags |= MNT_SYNCHRONOUS;
|
|
|
|
else if (strcmp(opt->name, "union") == 0)
|
|
|
|
fsflags |= MNT_UNION;
|
2014-08-17 09:44:42 +00:00
|
|
|
else if (strcmp(opt->name, "automounted") == 0) {
|
|
|
|
fsflags |= MNT_AUTOMOUNTED;
|
2019-09-23 04:28:07 +00:00
|
|
|
do_freeopt = 1;
|
|
|
|
} else if (strcmp(opt->name, "nocover") == 0) {
|
|
|
|
fsflags |= MNT_NOCOVER;
|
|
|
|
do_freeopt = 1;
|
|
|
|
} else if (strcmp(opt->name, "cover") == 0) {
|
|
|
|
fsflags &= ~MNT_NOCOVER;
|
|
|
|
do_freeopt = 1;
|
|
|
|
} else if (strcmp(opt->name, "emptydir") == 0) {
|
|
|
|
fsflags |= MNT_EMPTYDIR;
|
|
|
|
do_freeopt = 1;
|
|
|
|
} else if (strcmp(opt->name, "noemptydir") == 0) {
|
|
|
|
fsflags &= ~MNT_EMPTYDIR;
|
|
|
|
do_freeopt = 1;
|
2014-08-17 09:44:42 +00:00
|
|
|
}
|
2019-09-23 04:28:07 +00:00
|
|
|
if (do_freeopt)
|
|
|
|
vfs_freeopt(optlist, opt);
|
2006-03-13 14:58:37 +00:00
|
|
|
}
|
Parse more mount options in vfs_donmount(), before vfs_domount()
is called. It looks like there are lots of different mount flags checked
in vfs_domount(), so we need to do the parsing for these particular
mount flags earlier on. The new flags parsed are:
async, force, multilabel, noasync, noatime, noclusterr, noclusterw,
noexec, nosuid, nosymfollow, snapshot, suiddir, sync, union.
Existing code which uses mount() to mount UFS filesystems is not
affected, but new code which uses nmount() to mount UFS filesystems
should behave better.
2005-11-19 21:22:21 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Be ultra-paranoid about making sure the type and fspath
|
|
|
|
* variables will fit in our mp buffers, including the
|
|
|
|
* terminating NUL.
|
|
|
|
*/
|
2013-10-03 22:52:03 +00:00
|
|
|
if (fstypelen > MFSNAMELEN || fspathlen > MNAMELEN) {
|
2002-07-02 17:09:22 +00:00
|
|
|
error = ENAMETOOLONG;
|
2003-11-12 02:54:47 +00:00
|
|
|
goto bail;
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 14:27:14 +00:00
|
|
|
error = vfs_domount(td, fstype, fspath, fsflags, &optlist);
|
2018-03-27 14:31:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See if we can mount in the read-only mode if the error code suggests
|
|
|
|
* that it could be possible and the mount options allow for that.
|
|
|
|
* Never try it if "[no]{ro|rw}" has been explicitly requested and not
|
|
|
|
* overridden by "autoro".
|
|
|
|
*/
|
|
|
|
if (autoro && vfs_should_downgrade_to_ro_mount(fsflags, error)) {
|
|
|
|
printf("%s: R/W mount failed, possibly R/O media,"
|
|
|
|
" trying R/O mount\n", __func__);
|
|
|
|
fsflags |= MNT_RDONLY;
|
|
|
|
error = vfs_domount(td, fstype, fspath, fsflags, &optlist);
|
|
|
|
}
|
2003-11-12 02:54:47 +00:00
|
|
|
bail:
|
2005-11-23 20:51:15 +00:00
|
|
|
/* copyout the errmsg */
|
|
|
|
if (errmsg_pos != -1 && ((2 * errmsg_pos + 1) < fsoptions->uio_iovcnt)
|
|
|
|
&& errmsg_len > 0 && errmsg != NULL) {
|
|
|
|
if (fsoptions->uio_segflg == UIO_SYSSPACE) {
|
2006-08-24 18:52:28 +00:00
|
|
|
bcopy(errmsg,
|
|
|
|
fsoptions->uio_iov[2 * errmsg_pos + 1].iov_base,
|
2005-11-23 20:51:15 +00:00
|
|
|
fsoptions->uio_iov[2 * errmsg_pos + 1].iov_len);
|
|
|
|
} else {
|
2006-08-24 18:52:28 +00:00
|
|
|
copyout(errmsg,
|
2005-11-23 20:51:15 +00:00
|
|
|
fsoptions->uio_iov[2 * errmsg_pos + 1].iov_base,
|
2006-08-24 18:52:28 +00:00
|
|
|
fsoptions->uio_iov[2 * errmsg_pos + 1].iov_len);
|
2007-03-14 12:54:10 +00:00
|
|
|
}
|
2005-11-09 02:26:38 +00:00
|
|
|
}
|
2005-11-23 20:51:15 +00:00
|
|
|
|
2011-02-19 14:27:14 +00:00
|
|
|
if (optlist != NULL)
|
2003-11-12 02:54:47 +00:00
|
|
|
vfs_freeopts(optlist);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Old mount API.
|
|
|
|
*/
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct mount_args {
|
|
|
|
char *type;
|
|
|
|
char *path;
|
|
|
|
int flags;
|
|
|
|
caddr_t data;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2017-05-17 00:34:34 +00:00
|
|
|
sys_mount(struct thread *td, struct mount_args *uap)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
|
|
|
char *fstype;
|
2004-12-07 08:15:41 +00:00
|
|
|
struct vfsconf *vfsp = NULL;
|
2004-12-06 16:39:05 +00:00
|
|
|
struct mntarg *ma = NULL;
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t flags;
|
2002-07-02 17:09:22 +00:00
|
|
|
int error;
|
|
|
|
|
2012-01-17 01:08:01 +00:00
|
|
|
/*
|
2012-12-09 20:26:51 +00:00
|
|
|
* Mount flags are now 64-bits. On 32-bit architectures only
|
2012-01-17 01:08:01 +00:00
|
|
|
* 32-bits are passed in, but from here on everything handles
|
|
|
|
* 64-bit flags correctly.
|
|
|
|
*/
|
|
|
|
flags = uap->flags;
|
|
|
|
|
|
|
|
AUDIT_ARG_FFLAGS(flags);
|
2006-06-05 15:32:07 +00:00
|
|
|
|
2007-10-27 15:59:18 +00:00
|
|
|
/*
|
|
|
|
* Filter out MNT_ROOTFS. We do not want clients of mount() in
|
|
|
|
* userspace to set this flag, but we must filter it out if we want
|
|
|
|
* MNT_UPDATE on the root file system to work.
|
2010-11-23 13:49:15 +00:00
|
|
|
* MNT_ROOTFS should only be set by the kernel when mounting its
|
|
|
|
* root file system.
|
2007-10-27 15:59:18 +00:00
|
|
|
*/
|
2012-01-17 01:08:01 +00:00
|
|
|
flags &= ~MNT_ROOTFS;
|
2004-12-03 19:25:44 +00:00
|
|
|
|
2004-12-07 08:15:41 +00:00
|
|
|
fstype = malloc(MFSNAMELEN, M_TEMP, M_WAITOK);
|
2002-12-14 01:56:26 +00:00
|
|
|
error = copyinstr(uap->type, fstype, MFSNAMELEN, NULL);
|
2006-06-27 14:46:31 +00:00
|
|
|
if (error) {
|
|
|
|
free(fstype, M_TEMP);
|
|
|
|
return (error);
|
2004-11-25 12:06:43 +00:00
|
|
|
}
|
2006-06-27 14:46:31 +00:00
|
|
|
|
2009-06-27 13:58:44 +00:00
|
|
|
AUDIT_ARG_TEXT(fstype);
|
2006-06-27 14:46:31 +00:00
|
|
|
vfsp = vfs_byname_kld(fstype, td, &error);
|
2002-07-02 17:09:22 +00:00
|
|
|
free(fstype, M_TEMP);
|
2014-08-03 03:27:54 +00:00
|
|
|
if (vfsp == NULL)
|
2004-12-07 08:15:41 +00:00
|
|
|
return (ENOENT);
|
2018-10-24 19:40:09 +00:00
|
|
|
if (((vfsp->vfc_flags & VFCF_SBDRY) != 0 &&
|
|
|
|
vfsp->vfc_vfsops_sd->vfs_cmount == NULL) ||
|
|
|
|
((vfsp->vfc_flags & VFCF_SBDRY) == 0 &&
|
|
|
|
vfsp->vfc_vfsops->vfs_cmount == NULL))
|
2004-12-07 08:15:41 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
2014-04-12 21:39:17 +00:00
|
|
|
ma = mount_argsu(ma, "fstype", uap->type, MFSNAMELEN);
|
2004-12-07 08:15:41 +00:00
|
|
|
ma = mount_argsu(ma, "fspath", uap->path, MNAMELEN);
|
2012-01-17 01:08:01 +00:00
|
|
|
ma = mount_argb(ma, flags & MNT_RDONLY, "noro");
|
|
|
|
ma = mount_argb(ma, !(flags & MNT_NOSUID), "nosuid");
|
|
|
|
ma = mount_argb(ma, !(flags & MNT_NOEXEC), "noexec");
|
2004-12-07 08:15:41 +00:00
|
|
|
|
2018-10-23 21:43:41 +00:00
|
|
|
if ((vfsp->vfc_flags & VFCF_SBDRY) != 0)
|
|
|
|
return (vfsp->vfc_vfsops_sd->vfs_cmount(ma, uap->data, flags));
|
|
|
|
return (vfsp->vfc_vfsops->vfs_cmount(ma, uap->data, flags));
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 21:00:53 +00:00
|
|
|
/*
|
|
|
|
* vfs_domount_first(): first file system mount (not update)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_domount_first(
|
2011-02-19 14:27:14 +00:00
|
|
|
struct thread *td, /* Calling thread. */
|
|
|
|
struct vfsconf *vfsp, /* File system type. */
|
2011-08-05 11:12:50 +00:00
|
|
|
char *fspath, /* Mount path. */
|
2011-02-19 14:27:14 +00:00
|
|
|
struct vnode *vp, /* Vnode to be covered. */
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t fsflags, /* Flags common to all filesystems. */
|
2011-02-19 14:27:14 +00:00
|
|
|
struct vfsoptlist **optlist /* Options local to the filesystem. */
|
2010-09-08 21:00:53 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct vattr va;
|
|
|
|
struct mount *mp;
|
2020-03-22 18:18:30 +00:00
|
|
|
struct vnode *newdp, *rootvp;
|
2018-12-15 19:04:50 +00:00
|
|
|
int error, error1;
|
2020-11-26 18:08:42 +00:00
|
|
|
bool unmounted;
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(vp, __func__);
|
|
|
|
KASSERT((fsflags & MNT_UPDATE) == 0, ("MNT_UPDATE shouldn't be here"));
|
|
|
|
|
2019-09-23 04:28:07 +00:00
|
|
|
if ((fsflags & MNT_EMPTYDIR) != 0) {
|
|
|
|
error = vfs_emptydir(vp);
|
|
|
|
if (error != 0) {
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 20:54:27 +00:00
|
|
|
/*
|
|
|
|
* If the jail of the calling thread lacks permission for this type of
|
2021-04-05 21:19:15 +00:00
|
|
|
* file system, or is trying to cover its own root, deny immediately.
|
2018-05-04 20:54:27 +00:00
|
|
|
*/
|
2021-04-05 21:19:15 +00:00
|
|
|
if (jailed(td->td_ucred) && (!prison_allow(td->td_ucred,
|
|
|
|
vfsp->vfc_prison_flag) || vp == td->td_ucred->cr_prison->pr_root)) {
|
2018-05-04 20:54:27 +00:00
|
|
|
vput(vp);
|
|
|
|
return (EPERM);
|
|
|
|
}
|
|
|
|
|
2010-09-08 21:00:53 +00:00
|
|
|
/*
|
|
|
|
* If the user is not root, ensure that they own the directory
|
|
|
|
* onto which we are attempting to mount.
|
|
|
|
*/
|
|
|
|
error = VOP_GETATTR(vp, &va, td->td_ucred);
|
|
|
|
if (error == 0 && va.va_uid != td->td_ucred->cr_uid)
|
2018-12-11 19:32:16 +00:00
|
|
|
error = priv_check_cred(td->td_ucred, PRIV_VFS_ADMIN);
|
2010-09-08 21:00:53 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = vinvalbuf(vp, V_SAVE, 0, 0);
|
|
|
|
if (error == 0 && vp->v_type != VDIR)
|
|
|
|
error = ENOTDIR;
|
|
|
|
if (error == 0) {
|
|
|
|
VI_LOCK(vp);
|
|
|
|
if ((vp->v_iflag & VI_MOUNT) == 0 && vp->v_mountedhere == NULL)
|
|
|
|
vp->v_iflag |= VI_MOUNT;
|
|
|
|
else
|
|
|
|
error = EBUSY;
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
}
|
|
|
|
if (error != 0) {
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_begin(vp);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(vp);
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
/* Allocate and initialize the filesystem. */
|
|
|
|
mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred);
|
|
|
|
/* XXXMAC: pass to vfs_mount_alloc? */
|
2011-02-19 14:27:14 +00:00
|
|
|
mp->mnt_optnew = *optlist;
|
2010-09-08 21:00:53 +00:00
|
|
|
/* Set the mount level flags. */
|
|
|
|
mp->mnt_flag = (fsflags & (MNT_UPDATEMASK | MNT_ROOTFS | MNT_RDONLY));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mount the filesystem.
|
|
|
|
* XXX The final recipients of VFS_MOUNT just overwrite the ndp they
|
|
|
|
* get. No freeing of cn_pnbuf.
|
|
|
|
*/
|
2018-12-15 19:04:50 +00:00
|
|
|
error1 = 0;
|
2020-11-26 18:08:42 +00:00
|
|
|
unmounted = true;
|
2018-12-15 19:04:50 +00:00
|
|
|
if ((error = VFS_MOUNT(mp)) != 0 ||
|
2018-12-21 01:09:25 +00:00
|
|
|
(error1 = VFS_STATFS(mp, &mp->mnt_stat)) != 0 ||
|
2018-12-15 19:04:50 +00:00
|
|
|
(error1 = VFS_ROOT(mp, LK_EXCLUSIVE, &newdp)) != 0) {
|
2020-08-26 21:49:43 +00:00
|
|
|
rootvp = NULL;
|
2018-12-15 19:04:50 +00:00
|
|
|
if (error1 != 0) {
|
2020-11-26 18:08:42 +00:00
|
|
|
MPASS(error == 0);
|
2020-03-22 18:18:30 +00:00
|
|
|
rootvp = vfs_cache_root_clear(mp);
|
2020-08-26 21:49:43 +00:00
|
|
|
if (rootvp != NULL) {
|
|
|
|
vhold(rootvp);
|
2020-03-22 18:18:30 +00:00
|
|
|
vrele(rootvp);
|
2020-08-26 21:49:43 +00:00
|
|
|
}
|
2020-11-26 18:08:42 +00:00
|
|
|
(void)vn_start_write(NULL, &mp, V_WAIT);
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
mp->mnt_kern_flag |= MNTK_UNMOUNT | MNTK_UNMOUNTF;
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
VFS_PURGE(mp);
|
|
|
|
error = VFS_UNMOUNT(mp, 0);
|
|
|
|
vn_finished_write(mp);
|
|
|
|
if (error != 0) {
|
|
|
|
printf(
|
|
|
|
"failed post-mount (%d): rollback unmount returned %d\n",
|
|
|
|
error1, error);
|
|
|
|
unmounted = false;
|
|
|
|
}
|
|
|
|
error = error1;
|
2018-12-15 19:04:50 +00:00
|
|
|
}
|
2010-09-08 21:00:53 +00:00
|
|
|
vfs_unbusy(mp);
|
2017-09-14 08:47:06 +00:00
|
|
|
mp->mnt_vnodecovered = NULL;
|
2020-11-26 18:08:42 +00:00
|
|
|
if (unmounted) {
|
|
|
|
/* XXXKIB wait for mnt_lockref drain? */
|
|
|
|
vfs_mount_destroy(mp);
|
|
|
|
}
|
2010-09-09 07:55:13 +00:00
|
|
|
VI_LOCK(vp);
|
|
|
|
vp->v_iflag &= ~VI_MOUNT;
|
|
|
|
VI_UNLOCK(vp);
|
2020-08-26 21:49:43 +00:00
|
|
|
if (rootvp != NULL) {
|
|
|
|
vn_seqc_write_end(rootvp);
|
|
|
|
vdrop(rootvp);
|
|
|
|
}
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_end(vp);
|
2010-09-08 21:00:53 +00:00
|
|
|
vrele(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_begin(newdp);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(newdp);
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
if (mp->mnt_opt != NULL)
|
|
|
|
vfs_freeopts(mp->mnt_opt);
|
|
|
|
mp->mnt_opt = mp->mnt_optnew;
|
2011-02-19 14:27:14 +00:00
|
|
|
*optlist = NULL;
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent external consumers of mount options from reading mnt_optnew.
|
|
|
|
*/
|
|
|
|
mp->mnt_optnew = NULL;
|
|
|
|
|
|
|
|
MNT_ILOCK(mp);
|
2012-03-09 00:12:05 +00:00
|
|
|
if ((mp->mnt_flag & MNT_ASYNC) != 0 &&
|
|
|
|
(mp->mnt_kern_flag & MNTK_NOASYNC) == 0)
|
2010-09-08 21:00:53 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_ASYNC;
|
|
|
|
else
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_ASYNC;
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
|
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
cache_purge(vp);
|
|
|
|
VI_LOCK(vp);
|
|
|
|
vp->v_iflag &= ~VI_MOUNT;
|
2021-01-01 03:10:12 +00:00
|
|
|
vn_irflag_set_locked(vp, VIRF_MOUNTPOINT);
|
2010-09-08 21:00:53 +00:00
|
|
|
vp->v_mountedhere = mp;
|
2021-01-01 03:10:12 +00:00
|
|
|
VI_UNLOCK(vp);
|
2010-09-08 21:00:53 +00:00
|
|
|
/* Place the new filesystem at the end of the mount list. */
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
vfs_event_signal(NULL, VQ_MOUNT, 0);
|
2018-12-15 19:04:50 +00:00
|
|
|
vn_lock(newdp, LK_EXCLUSIVE | LK_RETRY);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(vp);
|
2018-01-07 18:07:22 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(vfs_mounted, mp, newdp, td);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(newdp);
|
2020-08-20 16:52:48 +00:00
|
|
|
mount_devctl_event("MOUNT", mp, false);
|
2010-09-08 21:00:53 +00:00
|
|
|
mountcheckdirs(vp, newdp);
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_end(vp);
|
|
|
|
vn_seqc_write_end(newdp);
|
2010-09-08 21:00:53 +00:00
|
|
|
vrele(newdp);
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
vfs_allocate_syncvnode(mp);
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_exit(mp);
|
2010-09-08 21:00:53 +00:00
|
|
|
vfs_unbusy(mp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vfs_domount_update(): update of mounted file system
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_domount_update(
|
2011-02-19 14:27:14 +00:00
|
|
|
struct thread *td, /* Calling thread. */
|
|
|
|
struct vnode *vp, /* Mount point vnode. */
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t fsflags, /* Flags common to all filesystems. */
|
2011-02-19 14:27:14 +00:00
|
|
|
struct vfsoptlist **optlist /* Options local to the filesystem. */
|
2010-09-08 21:00:53 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct export_args export;
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
struct o2export_args o2export;
|
2019-10-06 22:14:32 +00:00
|
|
|
struct vnode *rootvp;
|
2016-02-04 16:32:21 +00:00
|
|
|
void *bufp;
|
2010-09-08 21:00:53 +00:00
|
|
|
struct mount *mp;
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
int error, export_error, i, len;
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t flag;
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
gid_t *grps;
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(vp, __func__);
|
|
|
|
KASSERT((fsflags & MNT_UPDATE) != 0, ("MNT_UPDATE should be here"));
|
2015-02-10 18:00:32 +00:00
|
|
|
mp = vp->v_mount;
|
2010-09-08 21:00:53 +00:00
|
|
|
|
|
|
|
if ((vp->v_vflag & VV_ROOT) == 0) {
|
2015-02-10 18:00:32 +00:00
|
|
|
if (vfs_copyopt(*optlist, "export", &export, sizeof(export))
|
|
|
|
== 0)
|
|
|
|
error = EXDEV;
|
|
|
|
else
|
|
|
|
error = EINVAL;
|
2010-09-08 21:00:53 +00:00
|
|
|
vput(vp);
|
2015-02-10 18:00:32 +00:00
|
|
|
return (error);
|
2010-09-08 21:00:53 +00:00
|
|
|
}
|
2015-02-10 18:00:32 +00:00
|
|
|
|
2010-09-08 21:00:53 +00:00
|
|
|
/*
|
|
|
|
* We only allow the filesystem to be reloaded if it
|
|
|
|
* is currently mounted read-only.
|
|
|
|
*/
|
|
|
|
flag = mp->mnt_flag;
|
|
|
|
if ((fsflags & MNT_RELOAD) != 0 && (flag & MNT_RDONLY) == 0) {
|
|
|
|
vput(vp);
|
|
|
|
return (EOPNOTSUPP); /* Needs translation */
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Only privileged root, or (if MNT_USER is set) the user that
|
|
|
|
* did the original mount is permitted to update it.
|
|
|
|
*/
|
|
|
|
error = vfs_suser(mp, td);
|
|
|
|
if (error != 0) {
|
|
|
|
vput(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (vfs_busy(mp, MBF_NOWAIT)) {
|
|
|
|
vput(vp);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
VI_LOCK(vp);
|
|
|
|
if ((vp->v_iflag & VI_MOUNT) != 0 || vp->v_mountedhere != NULL) {
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
vput(vp);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
vp->v_iflag |= VI_MOUNT;
|
|
|
|
VI_UNLOCK(vp);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(vp);
|
2010-09-08 21:00:53 +00:00
|
|
|
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_enter(mp);
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_begin(vp);
|
2019-09-16 21:31:02 +00:00
|
|
|
|
2020-07-25 10:31:52 +00:00
|
|
|
rootvp = NULL;
|
2010-09-08 21:00:53 +00:00
|
|
|
MNT_ILOCK(mp);
|
2016-11-13 21:49:51 +00:00
|
|
|
if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0) {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
error = EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
2010-09-08 21:00:53 +00:00
|
|
|
mp->mnt_flag &= ~MNT_UPDATEMASK;
|
|
|
|
mp->mnt_flag |= fsflags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE |
|
|
|
|
MNT_SNAPSHOT | MNT_ROOTFS | MNT_UPDATEMASK | MNT_RDONLY);
|
|
|
|
if ((mp->mnt_flag & MNT_ASYNC) == 0)
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_ASYNC;
|
2019-10-06 22:14:32 +00:00
|
|
|
rootvp = vfs_cache_root_clear(mp);
|
2010-09-08 21:00:53 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2011-02-19 14:27:14 +00:00
|
|
|
mp->mnt_optnew = *optlist;
|
2010-09-08 21:00:53 +00:00
|
|
|
vfs_mergeopts(mp->mnt_optnew, mp->mnt_opt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mount the filesystem.
|
|
|
|
* XXX The final recipients of VFS_MOUNT just overwrite the ndp they
|
|
|
|
* get. No freeing of cn_pnbuf.
|
|
|
|
*/
|
2011-01-24 17:08:26 +00:00
|
|
|
error = VFS_MOUNT(mp);
|
2010-09-08 21:00:53 +00:00
|
|
|
|
2011-02-19 14:27:14 +00:00
|
|
|
export_error = 0;
|
2016-02-04 16:32:21 +00:00
|
|
|
/* Process the export option. */
|
|
|
|
if (error == 0 && vfs_getopt(mp->mnt_optnew, "export", &bufp,
|
|
|
|
&len) == 0) {
|
|
|
|
/* Assume that there is only 1 ABI for each length. */
|
|
|
|
switch (len) {
|
|
|
|
case (sizeof(struct oexport_args)):
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
bzero(&o2export, sizeof(o2export));
|
2016-02-04 16:32:21 +00:00
|
|
|
/* FALLTHROUGH */
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
case (sizeof(o2export)):
|
|
|
|
bcopy(bufp, &o2export, len);
|
|
|
|
export.ex_flags = (uint64_t)o2export.ex_flags;
|
|
|
|
export.ex_root = o2export.ex_root;
|
|
|
|
export.ex_uid = o2export.ex_anon.cr_uid;
|
|
|
|
export.ex_groups = NULL;
|
|
|
|
export.ex_ngroups = o2export.ex_anon.cr_ngroups;
|
|
|
|
if (export.ex_ngroups > 0) {
|
|
|
|
if (export.ex_ngroups <= XU_NGROUPS) {
|
|
|
|
export.ex_groups = malloc(
|
|
|
|
export.ex_ngroups * sizeof(gid_t),
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
for (i = 0; i < export.ex_ngroups; i++)
|
|
|
|
export.ex_groups[i] =
|
|
|
|
o2export.ex_anon.cr_groups[i];
|
|
|
|
} else
|
|
|
|
export_error = EINVAL;
|
|
|
|
} else if (export.ex_ngroups < 0)
|
|
|
|
export_error = EINVAL;
|
|
|
|
export.ex_addr = o2export.ex_addr;
|
|
|
|
export.ex_addrlen = o2export.ex_addrlen;
|
|
|
|
export.ex_mask = o2export.ex_mask;
|
|
|
|
export.ex_masklen = o2export.ex_masklen;
|
|
|
|
export.ex_indexfile = o2export.ex_indexfile;
|
|
|
|
export.ex_numsecflavors = o2export.ex_numsecflavors;
|
|
|
|
if (export.ex_numsecflavors < MAXSECFLAVORS) {
|
|
|
|
for (i = 0; i < export.ex_numsecflavors; i++)
|
|
|
|
export.ex_secflavors[i] =
|
|
|
|
o2export.ex_secflavors[i];
|
|
|
|
} else
|
|
|
|
export_error = EINVAL;
|
|
|
|
if (export_error == 0)
|
|
|
|
export_error = vfs_export(mp, &export);
|
|
|
|
free(export.ex_groups, M_TEMP);
|
|
|
|
break;
|
2016-02-04 16:32:21 +00:00
|
|
|
case (sizeof(export)):
|
|
|
|
bcopy(bufp, &export, len);
|
Fix export_args ex_flags field so that is 64bits, the same as mnt_flags.
Since mnt_flags was upgraded to 64bits there has been a quirk in
"struct export_args", since it hold a copy of mnt_flags
in ex_flags, which is an "int" (32bits).
This happens to currently work, since all the flag bits used in ex_flags are
defined in the low order 32bits. However, new export flags cannot be defined.
Also, ex_anon is a "struct xucred", which limits it to 16 additional groups.
This patch revises "struct export_args" to make ex_flags 64bits and replaces
ex_anon with ex_uid, ex_ngroups and ex_groups (which points to a
groups list, so it can be malloc'd up to NGROUPS in size.
This requires that the VFS_CHECKEXP() arguments change, so I also modified the
last "secflavors" argument to be an array pointer, so that the
secflavors could be copied in VFS_CHECKEXP() while the export entry is locked.
(Without this patch VFS_CHECKEXP() returns a pointer to the secflavors
array and then it is used after being unlocked, which is potentially
a problem if the exports entry is changed.
In practice this does not occur when mountd is run with "-S",
but I think it is worth fixing.)
This patch also deleted the vfs_oexport_conv() function, since
do_mount_update() does the conversion, as required by the old vfs_cmount()
calls.
Reviewed by: kib, freqlabs
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D25088
2020-06-14 00:10:18 +00:00
|
|
|
grps = NULL;
|
|
|
|
if (export.ex_ngroups > 0) {
|
|
|
|
if (export.ex_ngroups <= NGROUPS_MAX) {
|
|
|
|
grps = malloc(export.ex_ngroups *
|
|
|
|
sizeof(gid_t), M_TEMP, M_WAITOK);
|
|
|
|
export_error = copyin(export.ex_groups,
|
|
|
|
grps, export.ex_ngroups *
|
|
|
|
sizeof(gid_t));
|
|
|
|
if (export_error == 0)
|
|
|
|
export.ex_groups = grps;
|
|
|
|
} else
|
|
|
|
export_error = EINVAL;
|
|
|
|
} else if (export.ex_ngroups == 0)
|
|
|
|
export.ex_groups = NULL;
|
|
|
|
else
|
|
|
|
export_error = EINVAL;
|
|
|
|
if (export_error == 0)
|
|
|
|
export_error = vfs_export(mp, &export);
|
|
|
|
free(grps, M_TEMP);
|
2016-02-04 16:32:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
export_error = EINVAL;
|
|
|
|
break;
|
2010-09-08 21:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
if (error == 0) {
|
|
|
|
mp->mnt_flag &= ~(MNT_UPDATE | MNT_RELOAD | MNT_FORCE |
|
|
|
|
MNT_SNAPSHOT);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we fail, restore old mount flags. MNT_QUOTA is special,
|
|
|
|
* because it is not part of MNT_UPDATEMASK, but it could have
|
|
|
|
* changed in the meantime if quotactl(2) was called.
|
|
|
|
* All in all we want current value of MNT_QUOTA, not the old
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
mp->mnt_flag = (mp->mnt_flag & MNT_QUOTA) | (flag & ~MNT_QUOTA);
|
|
|
|
}
|
2012-03-09 00:12:05 +00:00
|
|
|
if ((mp->mnt_flag & MNT_ASYNC) != 0 &&
|
|
|
|
(mp->mnt_kern_flag & MNTK_NOASYNC) == 0)
|
2010-09-08 21:00:53 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_ASYNC;
|
|
|
|
else
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_ASYNC;
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
goto end;
|
|
|
|
|
2020-08-20 16:52:48 +00:00
|
|
|
mount_devctl_event("REMOUNT", mp, true);
|
2010-09-08 21:00:53 +00:00
|
|
|
if (mp->mnt_opt != NULL)
|
|
|
|
vfs_freeopts(mp->mnt_opt);
|
|
|
|
mp->mnt_opt = mp->mnt_optnew;
|
2011-02-19 14:27:14 +00:00
|
|
|
*optlist = NULL;
|
2010-09-08 21:00:53 +00:00
|
|
|
(void)VFS_STATFS(mp, &mp->mnt_stat);
|
|
|
|
/*
|
|
|
|
* Prevent external consumers of mount options from reading
|
|
|
|
* mnt_optnew.
|
|
|
|
*/
|
|
|
|
mp->mnt_optnew = NULL;
|
|
|
|
|
2010-09-11 13:06:06 +00:00
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
vfs_allocate_syncvnode(mp);
|
|
|
|
else
|
|
|
|
vfs_deallocate_syncvnode(mp);
|
2010-09-08 21:00:53 +00:00
|
|
|
end:
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_exit(mp);
|
2020-07-25 10:31:52 +00:00
|
|
|
if (rootvp != NULL) {
|
|
|
|
vn_seqc_write_end(rootvp);
|
|
|
|
vrele(rootvp);
|
|
|
|
}
|
|
|
|
vn_seqc_write_end(vp);
|
2010-09-08 21:00:53 +00:00
|
|
|
vfs_unbusy(mp);
|
|
|
|
VI_LOCK(vp);
|
|
|
|
vp->v_iflag &= ~VI_MOUNT;
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
vrele(vp);
|
2011-02-19 14:27:14 +00:00
|
|
|
return (error != 0 ? error : export_error);
|
2010-09-08 21:00:53 +00:00
|
|
|
}
|
2004-12-07 08:15:41 +00:00
|
|
|
|
2003-11-12 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* vfs_domount(): actually attempt a filesystem mount.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_domount(
|
2011-02-19 14:27:14 +00:00
|
|
|
struct thread *td, /* Calling thread. */
|
|
|
|
const char *fstype, /* Filesystem type. */
|
|
|
|
char *fspath, /* Mount path. */
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t fsflags, /* Flags common to all filesystems. */
|
2011-02-19 14:27:14 +00:00
|
|
|
struct vfsoptlist **optlist /* Options local to the filesystem. */
|
2003-11-14 05:27:41 +00:00
|
|
|
)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
|
|
|
struct vfsconf *vfsp;
|
|
|
|
struct nameidata nd;
|
2010-09-08 21:00:53 +00:00
|
|
|
struct vnode *vp;
|
2012-02-05 10:59:50 +00:00
|
|
|
char *pathbuf;
|
2010-09-08 21:00:53 +00:00
|
|
|
int error;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Be ultra-paranoid about making sure the type and fspath
|
|
|
|
* variables will fit in our mp buffers, including the
|
|
|
|
* terminating NUL.
|
|
|
|
*/
|
|
|
|
if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN)
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
|
2007-03-14 13:09:59 +00:00
|
|
|
if (jailed(td->td_ucred) || usermount == 0) {
|
2006-11-06 13:42:10 +00:00
|
|
|
if ((error = priv_check(td, PRIV_VFS_MOUNT)) != 0)
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2004-03-27 08:09:00 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
2004-03-27 08:09:00 +00:00
|
|
|
* Do not allow NFS export or MNT_SUIDDIR by unprivileged users.
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
2006-11-06 13:42:10 +00:00
|
|
|
if (fsflags & MNT_EXPORTED) {
|
|
|
|
error = priv_check(td, PRIV_VFS_MOUNT_EXPORTED);
|
|
|
|
if (error)
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2006-11-06 13:42:10 +00:00
|
|
|
if (fsflags & MNT_SUIDDIR) {
|
|
|
|
error = priv_check(td, PRIV_VFS_MOUNT_SUIDDIR);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
2006-11-06 13:42:10 +00:00
|
|
|
* Silently enforce MNT_NOSUID and MNT_USER for unprivileged users.
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
2006-11-06 13:42:10 +00:00
|
|
|
if ((fsflags & (MNT_NOSUID | MNT_USER)) != (MNT_NOSUID | MNT_USER)) {
|
|
|
|
if (priv_check(td, PRIV_VFS_MOUNT_NONUSER) != 0)
|
|
|
|
fsflags |= MNT_NOSUID | MNT_USER;
|
|
|
|
}
|
2006-02-22 06:29:55 +00:00
|
|
|
|
|
|
|
/* Load KLDs before we lock the covered vnode to avoid reversals. */
|
|
|
|
vfsp = NULL;
|
|
|
|
if ((fsflags & MNT_UPDATE) == 0) {
|
|
|
|
/* Don't try to load KLDs if we're mounting the root. */
|
|
|
|
if (fsflags & MNT_ROOTFS)
|
|
|
|
vfsp = vfs_byname(fstype);
|
|
|
|
else
|
|
|
|
vfsp = vfs_byname_kld(fstype, td, &error);
|
|
|
|
if (vfsp == NULL)
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
2010-09-08 21:00:53 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
2010-09-08 21:00:53 +00:00
|
|
|
* Get vnode to be covered or mount point's vnode in case of MNT_UPDATE.
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1,
|
2010-09-08 21:00:53 +00:00
|
|
|
UIO_SYSSPACE, fspath, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error != 0)
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
vp = nd.ni_vp;
|
2011-08-05 11:12:50 +00:00
|
|
|
if ((fsflags & MNT_UPDATE) == 0) {
|
2019-09-23 04:28:07 +00:00
|
|
|
if ((vp->v_vflag & VV_ROOT) != 0 &&
|
|
|
|
(fsflags & MNT_NOCOVER) != 0) {
|
|
|
|
vput(vp);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
2012-02-05 10:59:50 +00:00
|
|
|
pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
|
|
|
strcpy(pathbuf, fspath);
|
|
|
|
error = vn_path_to_global_path(td, vp, pathbuf, MNAMELEN);
|
2020-02-08 15:51:08 +00:00
|
|
|
if (error == 0) {
|
2012-02-05 10:59:50 +00:00
|
|
|
error = vfs_domount_first(td, vfsp, pathbuf, vp,
|
2012-01-15 12:08:20 +00:00
|
|
|
fsflags, optlist);
|
|
|
|
}
|
2012-02-05 10:59:50 +00:00
|
|
|
free(pathbuf, M_TEMP);
|
2012-01-15 12:08:20 +00:00
|
|
|
} else
|
2011-02-19 14:27:14 +00:00
|
|
|
error = vfs_domount_update(td, vp, fsflags, optlist);
|
2002-07-02 17:09:22 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmount a filesystem.
|
|
|
|
*
|
2007-03-05 13:10:58 +00:00
|
|
|
* Note: unmount takes a path to the vnode mounted on as argument, not
|
|
|
|
* special file (as before).
|
2002-07-02 17:09:22 +00:00
|
|
|
*/
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct unmount_args {
|
|
|
|
char *path;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2015-05-27 09:22:50 +00:00
|
|
|
sys_unmount(struct thread *td, struct unmount_args *uap)
|
2020-01-24 11:57:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (kern_unmount(td, uap->path, uap->flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
kern_unmount(struct thread *td, const char *path, int flags)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
2012-01-15 12:08:20 +00:00
|
|
|
struct nameidata nd;
|
2002-07-02 17:09:22 +00:00
|
|
|
struct mount *mp;
|
2011-08-05 11:12:50 +00:00
|
|
|
char *pathbuf;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error, id0, id1;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2020-01-24 11:57:55 +00:00
|
|
|
AUDIT_ARG_VALUE(flags);
|
2007-03-18 02:39:19 +00:00
|
|
|
if (jailed(td->td_ucred) || usermount == 0) {
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_VFS_UNMOUNT);
|
|
|
|
if (error)
|
2004-02-02 19:02:05 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2003-07-01 17:40:23 +00:00
|
|
|
pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
2020-01-24 11:57:55 +00:00
|
|
|
error = copyinstr(path, pathbuf, MNAMELEN, NULL);
|
2003-07-01 17:40:23 +00:00
|
|
|
if (error) {
|
|
|
|
free(pathbuf, M_TEMP);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
2003-07-01 17:40:23 +00:00
|
|
|
}
|
2020-01-24 11:57:55 +00:00
|
|
|
if (flags & MNT_BYFSID) {
|
2009-07-01 16:56:56 +00:00
|
|
|
AUDIT_ARG_TEXT(pathbuf);
|
2003-07-01 17:40:23 +00:00
|
|
|
/* Decode the filesystem ID. */
|
|
|
|
if (sscanf(pathbuf, "FSID:%d:%d", &id0, &id1) != 2) {
|
|
|
|
free(pathbuf, M_TEMP);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
mtx_lock(&mountlist_mtx);
|
2004-03-27 08:39:28 +00:00
|
|
|
TAILQ_FOREACH_REVERSE(mp, &mountlist, mntlist, mnt_list) {
|
2003-07-01 17:40:23 +00:00
|
|
|
if (mp->mnt_stat.f_fsid.val[0] == id0 &&
|
2015-05-27 09:22:50 +00:00
|
|
|
mp->mnt_stat.f_fsid.val[1] == id1) {
|
|
|
|
vfs_ref(mp);
|
2003-07-01 17:40:23 +00:00
|
|
|
break;
|
2015-05-27 09:22:50 +00:00
|
|
|
}
|
2004-03-27 08:39:28 +00:00
|
|
|
}
|
2003-07-01 17:40:23 +00:00
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
} else {
|
2012-01-15 12:08:20 +00:00
|
|
|
/*
|
|
|
|
* Try to find global path for path argument.
|
|
|
|
*/
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1,
|
2012-01-15 12:08:20 +00:00
|
|
|
UIO_SYSSPACE, pathbuf, td);
|
|
|
|
if (namei(&nd) == 0) {
|
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
error = vn_path_to_global_path(td, nd.ni_vp, pathbuf,
|
|
|
|
MNAMELEN);
|
2020-02-08 15:51:08 +00:00
|
|
|
if (error == 0)
|
2012-01-15 12:08:20 +00:00
|
|
|
vput(nd.ni_vp);
|
|
|
|
}
|
2003-07-01 17:40:23 +00:00
|
|
|
mtx_lock(&mountlist_mtx);
|
2004-03-27 08:39:28 +00:00
|
|
|
TAILQ_FOREACH_REVERSE(mp, &mountlist, mntlist, mnt_list) {
|
2015-05-27 09:22:50 +00:00
|
|
|
if (strcmp(mp->mnt_stat.f_mntonname, pathbuf) == 0) {
|
|
|
|
vfs_ref(mp);
|
2003-07-01 17:40:23 +00:00
|
|
|
break;
|
2015-05-27 09:22:50 +00:00
|
|
|
}
|
2004-03-27 08:39:28 +00:00
|
|
|
}
|
2003-07-01 17:40:23 +00:00
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
}
|
|
|
|
free(pathbuf, M_TEMP);
|
2003-09-08 16:23:21 +00:00
|
|
|
if (mp == NULL) {
|
|
|
|
/*
|
|
|
|
* Previously we returned ENOENT for a nonexistent path and
|
|
|
|
* EINVAL for a non-mountpoint. We cannot tell these apart
|
|
|
|
* now, so in the !MNT_BYFSID case return the more likely
|
|
|
|
* EINVAL for compatibility.
|
|
|
|
*/
|
2020-01-24 11:57:55 +00:00
|
|
|
return ((flags & MNT_BYFSID) ? ENOENT : EINVAL);
|
2003-09-08 16:23:21 +00:00
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't allow unmounting the root filesystem.
|
|
|
|
*/
|
2015-05-27 09:22:50 +00:00
|
|
|
if (mp->mnt_flag & MNT_ROOTFS) {
|
|
|
|
vfs_rel(mp);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (EINVAL);
|
2015-05-27 09:22:50 +00:00
|
|
|
}
|
2020-01-24 11:57:55 +00:00
|
|
|
error = dounmount(mp, flags, td);
|
2004-11-25 12:06:43 +00:00
|
|
|
return (error);
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 09:03:57 +00:00
|
|
|
/*
|
|
|
|
* Return error if any of the vnodes, ignoring the root vnode
|
|
|
|
* and the syncer vnode, have non-zero usecount.
|
2016-09-21 05:44:13 +00:00
|
|
|
*
|
|
|
|
* This function is purely advisory - it can return false positives
|
|
|
|
* and negatives.
|
2016-07-07 09:03:57 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_check_usecounts(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct vnode *vp, *mvp;
|
|
|
|
|
|
|
|
MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
|
|
|
|
if ((vp->v_vflag & VV_ROOT) == 0 && vp->v_type != VNON &&
|
|
|
|
vp->v_usecount != 0) {
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
static void
|
|
|
|
dounmount_cleanup(struct mount *mp, struct vnode *coveredvp, int mntkflags)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx_assert(MNT_MTX(mp), MA_OWNED);
|
|
|
|
mp->mnt_kern_flag &= ~mntkflags;
|
|
|
|
if ((mp->mnt_kern_flag & MNTK_MWAIT) != 0) {
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_MWAIT;
|
|
|
|
wakeup(mp);
|
|
|
|
}
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_exit_locked(mp);
|
2016-11-13 21:39:55 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
if (coveredvp != NULL) {
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(coveredvp);
|
2016-11-13 21:39:55 +00:00
|
|
|
vdrop(coveredvp);
|
|
|
|
}
|
|
|
|
vn_finished_write(mp);
|
|
|
|
}
|
|
|
|
|
2019-09-16 21:31:02 +00:00
|
|
|
/*
|
|
|
|
* There are various reference counters associated with the mount point.
|
|
|
|
* Normally it is permitted to modify them without taking the mnt ilock,
|
|
|
|
* but this behavior can be temporarily disabled if stable value is needed
|
|
|
|
* or callers are expected to block (e.g. to not allow new users during
|
|
|
|
* forced unmount).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vfs_op_enter(struct mount *mp)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2019-09-16 21:37:47 +00:00
|
|
|
int cpu;
|
2019-09-16 21:31:02 +00:00
|
|
|
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
mp->mnt_vfs_ops++;
|
|
|
|
if (mp->mnt_vfs_ops > 1) {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vfs_op_barrier_wait(mp);
|
2019-09-16 21:37:47 +00:00
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
|
|
|
|
mp->mnt_ref += mpcpu->mntp_ref;
|
|
|
|
mpcpu->mntp_ref = 0;
|
|
|
|
|
|
|
|
mp->mnt_lockref += mpcpu->mntp_lockref;
|
|
|
|
mpcpu->mntp_lockref = 0;
|
|
|
|
|
|
|
|
mp->mnt_writeopcount += mpcpu->mntp_writeopcount;
|
|
|
|
mpcpu->mntp_writeopcount = 0;
|
2019-09-16 21:37:47 +00:00
|
|
|
}
|
2020-08-19 02:50:09 +00:00
|
|
|
if (mp->mnt_ref <= 0 || mp->mnt_lockref < 0 || mp->mnt_writeopcount < 0)
|
|
|
|
panic("%s: invalid count(s) on mp %p: ref %d lockref %d writeopcount %d\n",
|
|
|
|
__func__, mp, mp->mnt_ref, mp->mnt_lockref, mp->mnt_writeopcount);
|
2019-09-16 21:31:02 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2019-09-16 21:37:47 +00:00
|
|
|
vfs_assert_mount_counters(mp);
|
2019-09-16 21:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_op_exit_locked(struct mount *mp)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx_assert(MNT_MTX(mp), MA_OWNED);
|
|
|
|
|
|
|
|
if (mp->mnt_vfs_ops <= 0)
|
|
|
|
panic("%s: invalid vfs_ops count %d for mp %p\n",
|
|
|
|
__func__, mp->mnt_vfs_ops, mp);
|
|
|
|
mp->mnt_vfs_ops--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_op_exit(struct mount *mp)
|
|
|
|
{
|
|
|
|
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
vfs_op_exit_locked(mp);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
}
|
|
|
|
|
2020-02-12 11:17:45 +00:00
|
|
|
struct vfs_op_barrier_ipi {
|
|
|
|
struct mount *mp;
|
|
|
|
struct smp_rendezvous_cpus_retry_arg srcra;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
vfs_op_action_func(void *arg)
|
|
|
|
{
|
|
|
|
struct vfs_op_barrier_ipi *vfsopipi;
|
|
|
|
struct mount *mp;
|
|
|
|
|
|
|
|
vfsopipi = __containerof(arg, struct vfs_op_barrier_ipi, srcra);
|
|
|
|
mp = vfsopipi->mp;
|
|
|
|
|
|
|
|
if (!vfs_op_thread_entered(mp))
|
|
|
|
smp_rendezvous_cpus_done(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vfs_op_wait_func(void *arg, int cpu)
|
|
|
|
{
|
|
|
|
struct vfs_op_barrier_ipi *vfsopipi;
|
|
|
|
struct mount *mp;
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2020-02-12 11:17:45 +00:00
|
|
|
|
|
|
|
vfsopipi = __containerof(arg, struct vfs_op_barrier_ipi, srcra);
|
|
|
|
mp = vfsopipi->mp;
|
|
|
|
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
while (atomic_load_int(&mpcpu->mntp_thread_in_ops))
|
2020-02-12 11:17:45 +00:00
|
|
|
cpu_spinwait();
|
|
|
|
}
|
|
|
|
|
2019-09-16 21:31:02 +00:00
|
|
|
void
|
|
|
|
vfs_op_barrier_wait(struct mount *mp)
|
|
|
|
{
|
2020-02-12 11:17:45 +00:00
|
|
|
struct vfs_op_barrier_ipi vfsopipi;
|
2019-09-16 21:31:02 +00:00
|
|
|
|
2020-02-12 11:17:45 +00:00
|
|
|
vfsopipi.mp = mp;
|
|
|
|
|
|
|
|
smp_rendezvous_cpus_retry(all_cpus,
|
|
|
|
smp_no_rendezvous_barrier,
|
|
|
|
vfs_op_action_func,
|
|
|
|
smp_no_rendezvous_barrier,
|
|
|
|
vfs_op_wait_func,
|
|
|
|
&vfsopipi.srcra);
|
2019-09-16 21:31:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 21:37:47 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
void
|
|
|
|
vfs_assert_mount_counters(struct mount *mp)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2019-09-16 21:37:47 +00:00
|
|
|
int cpu;
|
|
|
|
|
|
|
|
if (mp->mnt_vfs_ops == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
if (mpcpu->mntp_ref != 0 ||
|
|
|
|
mpcpu->mntp_lockref != 0 ||
|
|
|
|
mpcpu->mntp_writeopcount != 0)
|
2019-09-16 21:37:47 +00:00
|
|
|
vfs_dump_mount_counters(mp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_dump_mount_counters(struct mount *mp)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2019-09-16 21:37:47 +00:00
|
|
|
int ref, lockref, writeopcount;
|
2020-11-09 23:02:13 +00:00
|
|
|
int cpu;
|
2019-09-16 21:37:47 +00:00
|
|
|
|
|
|
|
printf("%s: mp %p vfs_ops %d\n", __func__, mp, mp->mnt_vfs_ops);
|
|
|
|
|
|
|
|
printf(" ref : ");
|
|
|
|
ref = mp->mnt_ref;
|
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
printf("%d ", mpcpu->mntp_ref);
|
|
|
|
ref += mpcpu->mntp_ref;
|
2019-09-16 21:37:47 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
printf(" lockref : ");
|
|
|
|
lockref = mp->mnt_lockref;
|
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
printf("%d ", mpcpu->mntp_lockref);
|
|
|
|
lockref += mpcpu->mntp_lockref;
|
2019-09-16 21:37:47 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
printf("writeopcount: ");
|
|
|
|
writeopcount = mp->mnt_writeopcount;
|
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
printf("%d ", mpcpu->mntp_writeopcount);
|
|
|
|
writeopcount += mpcpu->mntp_writeopcount;
|
2019-09-16 21:37:47 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("counter struct total\n");
|
|
|
|
printf("ref %-5d %-5d\n", mp->mnt_ref, ref);
|
|
|
|
printf("lockref %-5d %-5d\n", mp->mnt_lockref, lockref);
|
|
|
|
printf("writeopcount %-5d %-5d\n", mp->mnt_writeopcount, writeopcount);
|
|
|
|
|
|
|
|
panic("invalid counts on struct mount");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_mount_fetch_counter(struct mount *mp, enum mount_counter which)
|
|
|
|
{
|
2020-11-09 23:02:13 +00:00
|
|
|
struct mount_pcpu *mpcpu;
|
2019-09-16 21:37:47 +00:00
|
|
|
int cpu, sum;
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case MNT_COUNT_REF:
|
2020-11-09 23:02:13 +00:00
|
|
|
sum = mp->mnt_ref;
|
2019-09-16 21:37:47 +00:00
|
|
|
break;
|
|
|
|
case MNT_COUNT_LOCKREF:
|
2020-11-09 23:02:13 +00:00
|
|
|
sum = mp->mnt_lockref;
|
2019-09-16 21:37:47 +00:00
|
|
|
break;
|
|
|
|
case MNT_COUNT_WRITEOPCOUNT:
|
2020-11-09 23:02:13 +00:00
|
|
|
sum = mp->mnt_writeopcount;
|
2019-09-16 21:37:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPU_FOREACH(cpu) {
|
2020-11-09 23:02:13 +00:00
|
|
|
mpcpu = vfs_mount_pcpu_remote(mp, cpu);
|
|
|
|
switch (which) {
|
|
|
|
case MNT_COUNT_REF:
|
|
|
|
sum += mpcpu->mntp_ref;
|
|
|
|
break;
|
|
|
|
case MNT_COUNT_LOCKREF:
|
|
|
|
sum += mpcpu->mntp_lockref;
|
|
|
|
break;
|
|
|
|
case MNT_COUNT_WRITEOPCOUNT:
|
|
|
|
sum += mpcpu->mntp_writeopcount;
|
|
|
|
break;
|
|
|
|
}
|
2019-09-16 21:37:47 +00:00
|
|
|
}
|
|
|
|
return (sum);
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
static bool
|
|
|
|
deferred_unmount_enqueue(struct mount *mp, uint64_t flags, bool requeue)
|
|
|
|
{
|
|
|
|
bool enqueued;
|
|
|
|
|
|
|
|
enqueued = false;
|
|
|
|
mtx_lock(&deferred_unmount_lock);
|
|
|
|
if ((mp->mnt_taskqueue_flags & MNT_DEFERRED) == 0 || requeue) {
|
|
|
|
mp->mnt_taskqueue_flags = flags | MNT_DEFERRED;
|
|
|
|
STAILQ_INSERT_TAIL(&deferred_unmount_list, mp,
|
|
|
|
mnt_taskqueue_link);
|
|
|
|
enqueued = true;
|
|
|
|
}
|
|
|
|
mtx_unlock(&deferred_unmount_lock);
|
|
|
|
|
|
|
|
if (enqueued) {
|
|
|
|
taskqueue_enqueue(taskqueue_deferred_unmount,
|
|
|
|
&deferred_unmount_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (enqueued);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Taskqueue handler for processing async/recursive unmounts
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vfs_deferred_unmount(void *argi __unused, int pending __unused)
|
|
|
|
{
|
|
|
|
STAILQ_HEAD(, mount) local_unmounts;
|
|
|
|
uint64_t flags;
|
|
|
|
struct mount *mp, *tmp;
|
|
|
|
bool unmounted;
|
|
|
|
|
|
|
|
STAILQ_INIT(&local_unmounts);
|
|
|
|
mtx_lock(&deferred_unmount_lock);
|
|
|
|
STAILQ_CONCAT(&local_unmounts, &deferred_unmount_list);
|
|
|
|
mtx_unlock(&deferred_unmount_lock);
|
|
|
|
|
|
|
|
STAILQ_FOREACH_SAFE(mp, &local_unmounts, mnt_taskqueue_link, tmp) {
|
|
|
|
flags = mp->mnt_taskqueue_flags;
|
|
|
|
KASSERT((flags & MNT_DEFERRED) != 0,
|
|
|
|
("taskqueue unmount without MNT_DEFERRED"));
|
|
|
|
if (dounmount(mp, flags, curthread) != 0) {
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
unmounted = ((mp->mnt_kern_flag & MNTK_REFEXPIRE) != 0);
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
if (!unmounted)
|
|
|
|
deferred_unmount_enqueue(mp, flags, true);
|
|
|
|
else
|
|
|
|
vfs_rel(mp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Do the actual filesystem unmount.
|
|
|
|
*/
|
|
|
|
int
|
2021-06-12 19:42:12 +00:00
|
|
|
dounmount(struct mount *mp, uint64_t flags, struct thread *td)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
2021-06-12 19:42:12 +00:00
|
|
|
struct mount_upper_node *upper;
|
2019-10-06 22:14:32 +00:00
|
|
|
struct vnode *coveredvp, *rootvp;
|
2002-07-02 17:09:22 +00:00
|
|
|
int error;
|
2012-01-17 01:08:01 +00:00
|
|
|
uint64_t async_flag;
|
2006-10-03 10:47:04 +00:00
|
|
|
int mnt_gen_r;
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2021-06-12 19:42:12 +00:00
|
|
|
KASSERT((flags & MNT_DEFERRED) == 0 ||
|
|
|
|
(flags & (MNT_RECURSE | MNT_FORCE)) == (MNT_RECURSE | MNT_FORCE),
|
|
|
|
("MNT_DEFERRED requires MNT_RECURSE | MNT_FORCE"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the caller has explicitly requested the unmount to be handled by
|
|
|
|
* the taskqueue and we're not already in taskqueue context, queue
|
|
|
|
* up the unmount request and exit. This is done prior to any
|
|
|
|
* credential checks; MNT_DEFERRED should be used only for kernel-
|
|
|
|
* initiated unmounts and will therefore be processed with the
|
|
|
|
* (kernel) credentials of the taskqueue thread. Still, callers
|
|
|
|
* should be sure this is the behavior they want.
|
|
|
|
*/
|
|
|
|
if ((flags & MNT_DEFERRED) != 0 &&
|
|
|
|
taskqueue_member(taskqueue_deferred_unmount, curthread) == 0) {
|
|
|
|
if (!deferred_unmount_enqueue(mp, flags, false))
|
|
|
|
vfs_rel(mp);
|
|
|
|
return (EINPROGRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only privileged root, or (if MNT_USER is set) the user that did the
|
|
|
|
* original mount is permitted to unmount this filesystem.
|
|
|
|
* This check should be made prior to queueing up any recursive
|
|
|
|
* unmounts of upper filesystems. Those unmounts will be executed
|
|
|
|
* with kernel thread credentials and are expected to succeed, so
|
|
|
|
* we must at least ensure the originating context has sufficient
|
|
|
|
* privilege to unmount the base filesystem before proceeding with
|
|
|
|
* the uppers.
|
|
|
|
*/
|
|
|
|
error = vfs_suser(mp, td);
|
|
|
|
if (error != 0) {
|
|
|
|
KASSERT((flags & MNT_DEFERRED) == 0,
|
|
|
|
("taskqueue unmount with insufficient privilege"));
|
|
|
|
vfs_rel(mp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recursive_forced_unmount && ((flags & MNT_FORCE) != 0))
|
|
|
|
flags |= MNT_RECURSE;
|
|
|
|
|
|
|
|
if ((flags & MNT_RECURSE) != 0) {
|
|
|
|
KASSERT((flags & MNT_FORCE) != 0,
|
|
|
|
("MNT_RECURSE requires MNT_FORCE"));
|
|
|
|
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
/*
|
|
|
|
* Set MNTK_RECURSE to prevent new upper mounts from being
|
|
|
|
* added, and note that an operation on the uppers list is in
|
|
|
|
* progress. This will ensure that unregistration from the
|
|
|
|
* uppers list, and therefore any pending unmount of the upper
|
|
|
|
* FS, can't complete until after we finish walking the list.
|
|
|
|
*/
|
|
|
|
mp->mnt_kern_flag |= MNTK_RECURSE;
|
|
|
|
mp->mnt_upper_pending++;
|
|
|
|
TAILQ_FOREACH(upper, &mp->mnt_uppers, mnt_upper_link) {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
vfs_ref(upper->mp);
|
|
|
|
if (!deferred_unmount_enqueue(upper->mp, flags, false))
|
|
|
|
vfs_rel(upper->mp);
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
}
|
|
|
|
mp->mnt_upper_pending--;
|
|
|
|
if ((mp->mnt_kern_flag & MNTK_UPPER_WAITER) != 0 &&
|
|
|
|
mp->mnt_upper_pending == 0) {
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_UPPER_WAITER;
|
|
|
|
wakeup(&mp->mnt_uppers);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we're not on the taskqueue, wait until the uppers list
|
|
|
|
* is drained before proceeding with unmount. Otherwise, if
|
|
|
|
* we are on the taskqueue and there are still pending uppers,
|
|
|
|
* just re-enqueue on the end of the taskqueue.
|
|
|
|
*/
|
|
|
|
if ((flags & MNT_DEFERRED) == 0) {
|
|
|
|
while (!TAILQ_EMPTY(&mp->mnt_uppers)) {
|
|
|
|
mp->mnt_kern_flag |= MNTK_TASKQUEUE_WAITER;
|
|
|
|
msleep(&mp->mnt_taskqueue_link, MNT_MTX(mp), 0,
|
|
|
|
"umntqw", 0);
|
|
|
|
}
|
|
|
|
} else if (!TAILQ_EMPTY(&mp->mnt_uppers)) {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
deferred_unmount_enqueue(mp, flags, true);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
KASSERT(TAILQ_EMPTY(&mp->mnt_uppers), ("mnt_uppers not empty"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow the taskqueue to safely re-enqueue on failure */
|
|
|
|
if ((flags & MNT_DEFERRED) != 0)
|
|
|
|
vfs_ref(mp);
|
|
|
|
|
2006-09-18 15:35:22 +00:00
|
|
|
if ((coveredvp = mp->mnt_vnodecovered) != NULL) {
|
2006-10-03 10:47:04 +00:00
|
|
|
mnt_gen_r = mp->mnt_gen;
|
2006-09-18 15:35:22 +00:00
|
|
|
VI_LOCK(coveredvp);
|
|
|
|
vholdl(coveredvp);
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(coveredvp, LK_EXCLUSIVE | LK_INTERLOCK | LK_RETRY);
|
2006-09-18 15:35:22 +00:00
|
|
|
/*
|
|
|
|
* Check for mp being unmounted while waiting for the
|
|
|
|
* covered vnode lock.
|
|
|
|
*/
|
2006-10-03 10:47:04 +00:00
|
|
|
if (coveredvp->v_mountedhere != mp ||
|
|
|
|
coveredvp->v_mountedhere->mnt_gen != mnt_gen_r) {
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(coveredvp);
|
2016-06-15 15:56:03 +00:00
|
|
|
vdrop(coveredvp);
|
2015-05-27 09:22:50 +00:00
|
|
|
vfs_rel(mp);
|
2006-09-18 15:35:22 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 15:56:03 +00:00
|
|
|
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_enter(mp);
|
|
|
|
|
2015-05-27 09:22:50 +00:00
|
|
|
vn_start_write(NULL, &mp, V_WAIT | V_MNTREF);
|
2005-01-24 10:28:41 +00:00
|
|
|
MNT_ILOCK(mp);
|
2012-09-09 19:17:15 +00:00
|
|
|
if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0 ||
|
2016-11-13 21:49:51 +00:00
|
|
|
(mp->mnt_flag & MNT_UPDATE) != 0 ||
|
2021-06-12 19:42:12 +00:00
|
|
|
!TAILQ_EMPTY(&mp->mnt_uppers)) {
|
2016-11-13 21:39:55 +00:00
|
|
|
dounmount_cleanup(mp, coveredvp, 0);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2019-08-23 19:40:10 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_UNMOUNT;
|
2019-10-06 22:14:32 +00:00
|
|
|
rootvp = vfs_cache_root_clear(mp);
|
2020-07-25 10:31:52 +00:00
|
|
|
if (coveredvp != NULL)
|
|
|
|
vn_seqc_write_begin(coveredvp);
|
2016-07-07 09:03:57 +00:00
|
|
|
if (flags & MNT_NONBUSY) {
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
error = vfs_check_usecounts(mp);
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
if (error != 0) {
|
2020-07-25 10:31:52 +00:00
|
|
|
vn_seqc_write_end(coveredvp);
|
2019-08-23 19:40:10 +00:00
|
|
|
dounmount_cleanup(mp, coveredvp, MNTK_UNMOUNT);
|
2020-07-25 10:31:52 +00:00
|
|
|
if (rootvp != NULL) {
|
|
|
|
vn_seqc_write_end(rootvp);
|
2019-10-06 22:14:32 +00:00
|
|
|
vrele(rootvp);
|
2020-07-25 10:31:52 +00:00
|
|
|
}
|
2016-07-07 09:03:57 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
/* Allow filesystems to detect that a forced unmount is in progress. */
|
2013-09-01 23:02:59 +00:00
|
|
|
if (flags & MNT_FORCE) {
|
2002-07-02 17:09:22 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_UNMOUNTF;
|
2013-09-01 23:02:59 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
/*
|
|
|
|
* Must be done after setting MNTK_UNMOUNTF and before
|
|
|
|
* waiting for mnt_lockref to become 0.
|
|
|
|
*/
|
|
|
|
VFS_PURGE(mp);
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
}
|
2008-11-02 10:15:42 +00:00
|
|
|
error = 0;
|
|
|
|
if (mp->mnt_lockref) {
|
|
|
|
mp->mnt_kern_flag |= MNTK_DRAINING;
|
|
|
|
error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
|
|
|
|
"mount drain", 0);
|
2002-07-02 17:09:22 +00:00
|
|
|
}
|
2008-11-02 10:15:42 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
KASSERT(mp->mnt_lockref == 0,
|
|
|
|
("%s: invalid lock refcount in the drain path @ %s:%d",
|
|
|
|
__func__, __FILE__, __LINE__));
|
|
|
|
KASSERT(error == 0,
|
|
|
|
("%s: invalid return value for msleep in the drain path @ %s:%d",
|
|
|
|
__func__, __FILE__, __LINE__));
|
2002-07-02 17:09:22 +00:00
|
|
|
|
2020-07-25 10:31:52 +00:00
|
|
|
/*
|
|
|
|
* We want to keep the vnode around so that we can vn_seqc_write_end
|
|
|
|
* after we are done with unmount. Downgrade our reference to a mere
|
|
|
|
* hold count so that we don't interefere with anything.
|
|
|
|
*/
|
|
|
|
if (rootvp != NULL) {
|
|
|
|
vhold(rootvp);
|
2019-10-06 22:14:32 +00:00
|
|
|
vrele(rootvp);
|
2020-07-25 10:31:52 +00:00
|
|
|
}
|
2019-10-06 22:14:32 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
if (mp->mnt_flag & MNT_EXPUBLIC)
|
|
|
|
vfs_setpublicfs(NULL, NULL, NULL);
|
|
|
|
|
2020-01-07 15:56:24 +00:00
|
|
|
vfs_periodic(mp, MNT_WAIT);
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_ILOCK(mp);
|
2002-07-02 17:09:22 +00:00
|
|
|
async_flag = mp->mnt_flag & MNT_ASYNC;
|
2004-03-27 08:39:28 +00:00
|
|
|
mp->mnt_flag &= ~MNT_ASYNC;
|
2006-09-26 04:15:59 +00:00
|
|
|
mp->mnt_kern_flag &= ~MNTK_ASYNC;
|
2006-09-26 04:12:49 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2010-09-11 13:06:06 +00:00
|
|
|
vfs_deallocate_syncvnode(mp);
|
2020-01-15 18:53:32 +00:00
|
|
|
error = VFS_UNMOUNT(mp, flags);
|
2002-07-02 17:09:22 +00:00
|
|
|
vn_finished_write(mp);
|
2007-12-27 16:38:28 +00:00
|
|
|
/*
|
|
|
|
* If we failed to flush the dirty blocks for this mount point,
|
|
|
|
* undo all the cdir/rdir and rootvnode changes we made above.
|
|
|
|
* Unless we failed to do so because the device is reporting that
|
|
|
|
* it doesn't exist anymore.
|
|
|
|
*/
|
|
|
|
if (error && error != ENXIO) {
|
2005-01-24 10:28:41 +00:00
|
|
|
MNT_ILOCK(mp);
|
2010-09-11 13:06:06 +00:00
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0) {
|
2007-09-12 16:31:32 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2010-08-28 08:57:15 +00:00
|
|
|
vfs_allocate_syncvnode(mp);
|
2007-09-12 16:31:32 +00:00
|
|
|
MNT_ILOCK(mp);
|
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_UNMOUNTF);
|
|
|
|
mp->mnt_flag |= async_flag;
|
2012-03-09 00:12:05 +00:00
|
|
|
if ((mp->mnt_flag & MNT_ASYNC) != 0 &&
|
|
|
|
(mp->mnt_kern_flag & MNTK_NOASYNC) == 0)
|
2006-09-26 04:15:59 +00:00
|
|
|
mp->mnt_kern_flag |= MNTK_ASYNC;
|
2008-11-02 10:15:42 +00:00
|
|
|
if (mp->mnt_kern_flag & MNTK_MWAIT) {
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_MWAIT;
|
2002-07-02 17:09:22 +00:00
|
|
|
wakeup(mp);
|
2008-11-02 10:15:42 +00:00
|
|
|
}
|
2019-09-16 21:31:02 +00:00
|
|
|
vfs_op_exit_locked(mp);
|
2005-01-24 10:28:41 +00:00
|
|
|
MNT_IUNLOCK(mp);
|
2020-07-25 10:31:52 +00:00
|
|
|
if (coveredvp) {
|
|
|
|
vn_seqc_write_end(coveredvp);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(coveredvp);
|
2020-07-25 10:31:52 +00:00
|
|
|
vdrop(coveredvp);
|
|
|
|
}
|
|
|
|
if (rootvp != NULL) {
|
|
|
|
vn_seqc_write_end(rootvp);
|
|
|
|
vdrop(rootvp);
|
|
|
|
}
|
2002-07-02 17:09:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2021-06-12 19:42:12 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
TAILQ_REMOVE(&mountlist, mp, mnt_list);
|
2003-11-12 02:54:47 +00:00
|
|
|
mtx_unlock(&mountlist_mtx);
|
2018-01-07 18:07:22 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(vfs_unmounted, mp, td);
|
2006-02-22 06:29:55 +00:00
|
|
|
if (coveredvp != NULL) {
|
2021-01-01 03:10:12 +00:00
|
|
|
VI_LOCK(coveredvp);
|
|
|
|
vn_irflag_unset_locked(coveredvp, VIRF_MOUNTPOINT);
|
2006-02-22 06:29:55 +00:00
|
|
|
coveredvp->v_mountedhere = NULL;
|
2021-01-01 03:10:12 +00:00
|
|
|
vn_seqc_write_end_locked(coveredvp);
|
|
|
|
VI_UNLOCK(coveredvp);
|
2020-01-03 22:29:58 +00:00
|
|
|
VOP_UNLOCK(coveredvp);
|
2020-07-25 10:31:52 +00:00
|
|
|
vdrop(coveredvp);
|
|
|
|
}
|
2020-08-20 16:52:48 +00:00
|
|
|
mount_devctl_event("UNMOUNT", mp, false);
|
2020-07-25 10:31:52 +00:00
|
|
|
if (rootvp != NULL) {
|
|
|
|
vn_seqc_write_end(rootvp);
|
|
|
|
vdrop(rootvp);
|
2006-02-22 06:29:55 +00:00
|
|
|
}
|
2004-07-06 09:12:03 +00:00
|
|
|
vfs_event_signal(NULL, VQ_UNMOUNT, 0);
|
2017-10-13 09:42:05 +00:00
|
|
|
if (rootvnode != NULL && mp == rootvnode->v_mount) {
|
|
|
|
vrele(rootvnode);
|
|
|
|
rootvnode = NULL;
|
|
|
|
}
|
2015-08-24 13:18:13 +00:00
|
|
|
if (mp == rootdevmp)
|
|
|
|
rootdevmp = NULL;
|
2021-06-12 19:42:12 +00:00
|
|
|
if ((flags & MNT_DEFERRED) != 0)
|
|
|
|
vfs_rel(mp);
|
2006-06-02 20:29:02 +00:00
|
|
|
vfs_mount_destroy(mp);
|
2002-07-02 17:09:22 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-11-08 04:13:39 +00:00
|
|
|
/*
|
2007-03-14 12:54:10 +00:00
|
|
|
* Report errors during filesystem mounting.
|
2005-11-08 04:13:39 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
vfs_mount_error(struct mount *mp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct vfsoptlist *moptlist = mp->mnt_optnew;
|
|
|
|
va_list ap;
|
|
|
|
int error, len;
|
|
|
|
char *errmsg;
|
|
|
|
|
|
|
|
error = vfs_getopt(moptlist, "errmsg", (void **)&errmsg, &len);
|
2005-11-09 02:26:38 +00:00
|
|
|
if (error || errmsg == NULL || len <= 0)
|
2005-11-08 04:13:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(errmsg, (size_t)len, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2009-03-02 23:26:30 +00:00
|
|
|
void
|
|
|
|
vfs_opterror(struct vfsoptlist *opts, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int error, len;
|
|
|
|
char *errmsg;
|
|
|
|
|
|
|
|
error = vfs_getopt(opts, "errmsg", (void **)&errmsg, &len);
|
|
|
|
if (error || errmsg == NULL || len <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(errmsg, (size_t)len, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2004-12-06 18:18:35 +00:00
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
* Functions for querying mount options/arguments from filesystems.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that no unknown options are given
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vfs_filteropt(struct vfsoptlist *opts, const char **legal)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
char errmsg[255];
|
|
|
|
const char **t, *p, *q;
|
|
|
|
int ret = 0;
|
2004-12-06 18:18:35 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
p = opt->name;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
q = NULL;
|
2004-12-06 18:18:35 +00:00
|
|
|
if (p[0] == 'n' && p[1] == 'o')
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
q = p + 2;
|
|
|
|
for(t = global_opts; *t != NULL; t++) {
|
|
|
|
if (strcmp(*t, p) == 0)
|
2004-12-06 18:18:35 +00:00
|
|
|
break;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
if (q != NULL) {
|
|
|
|
if (strcmp(*t, q) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-06 18:18:35 +00:00
|
|
|
if (*t != NULL)
|
|
|
|
continue;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
for(t = legal; *t != NULL; t++) {
|
|
|
|
if (strcmp(*t, p) == 0)
|
2004-12-06 18:18:35 +00:00
|
|
|
break;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
if (q != NULL) {
|
|
|
|
if (strcmp(*t, q) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-06 18:18:35 +00:00
|
|
|
if (*t != NULL)
|
|
|
|
continue;
|
2008-09-03 19:09:47 +00:00
|
|
|
snprintf(errmsg, sizeof(errmsg),
|
|
|
|
"mount option <%s> is unknown", p);
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
ret = EINVAL;
|
2004-12-06 18:18:35 +00:00
|
|
|
}
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(opt->name, "errmsg") == 0) {
|
2013-01-04 11:11:12 +00:00
|
|
|
strncpy((char *)opt->value, errmsg, opt->len);
|
2010-10-18 04:34:42 +00:00
|
|
|
break;
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-18 04:34:42 +00:00
|
|
|
if (opt == NULL)
|
|
|
|
printf("%s\n", errmsg);
|
On 6.x this works:
% mount | grep home
/dev/ad4s1e on /home (ufs, local, noatime, soft-updates)
% mount -u -o atime /home
% mount | grep home
/dev/ad4s1e on /home (ufs, local, soft-updates)
Restore this behavior for on 7.x for the following mount options:
noatime, noclusterr, noclusterw, noexec, nosuid, nosymfollow
In addition, on 7.x, the following are equivalent:
mount -u -o atime /home
mount -u -o nonoatime /home
Ideally, when we introduce new mount options, we should avoid
options starting with "no". :)
Requested by: jhb
Reported by: Karol Kwiat <karol.kwiat gmail com>, Scott Hetzel <swhetzel gmail com>
Approved by: re (bmah)
Proxy commit for: rodrigc
2007-08-15 17:40:09 +00:00
|
|
|
}
|
|
|
|
return (ret);
|
2004-12-06 18:18:35 +00:00
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Get a mount option by its name.
|
|
|
|
*
|
|
|
|
* Return 0 if the option was found, ENOENT otherwise.
|
|
|
|
* If len is non-NULL it will be filled with the length
|
|
|
|
* of the option. If buf is non-NULL, it will be filled
|
|
|
|
* with the address of the option.
|
|
|
|
*/
|
|
|
|
int
|
2017-05-17 00:34:34 +00:00
|
|
|
vfs_getopt(struct vfsoptlist *opts, const char *name, void **buf, int *len)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
2003-02-14 13:30:25 +00:00
|
|
|
KASSERT(opts != NULL, ("vfs_getopt: caller passed 'opts' as NULL"));
|
2003-02-14 13:18:51 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) == 0) {
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->seen = 1;
|
2002-07-02 17:09:22 +00:00
|
|
|
if (len != NULL)
|
|
|
|
*len = opt->len;
|
|
|
|
if (buf != NULL)
|
|
|
|
*buf = opt->value;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
2009-03-02 23:26:30 +00:00
|
|
|
int
|
2005-11-23 20:51:15 +00:00
|
|
|
vfs_getopt_pos(struct vfsoptlist *opts, const char *name)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
if (opts == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
2009-03-02 23:26:30 +00:00
|
|
|
if (strcmp(name, opt->name) == 0) {
|
|
|
|
opt->seen = 1;
|
|
|
|
return (opt->pos);
|
|
|
|
}
|
2005-11-23 20:51:15 +00:00
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2012-04-07 15:27:34 +00:00
|
|
|
int
|
|
|
|
vfs_getopt_size(struct vfsoptlist *opts, const char *name, off_t *value)
|
|
|
|
{
|
|
|
|
char *opt_value, *vtp;
|
|
|
|
quad_t iv;
|
|
|
|
int error, opt_len;
|
|
|
|
|
|
|
|
error = vfs_getopt(opts, name, (void **)&opt_value, &opt_len);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (opt_len == 0 || opt_value == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (opt_value[0] == '\0' || opt_value[opt_len - 1] != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
iv = strtoq(opt_value, &vtp, 0);
|
|
|
|
if (vtp == opt_value || (vtp[0] != '\0' && vtp[1] != '\0'))
|
|
|
|
return (EINVAL);
|
|
|
|
if (iv < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
switch (vtp[0]) {
|
2018-10-25 15:43:21 +00:00
|
|
|
case 't': case 'T':
|
2012-04-07 15:27:34 +00:00
|
|
|
iv *= 1024;
|
2018-10-25 15:43:21 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'g': case 'G':
|
2012-04-07 15:27:34 +00:00
|
|
|
iv *= 1024;
|
2018-10-25 15:43:21 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'm': case 'M':
|
2012-04-07 15:27:34 +00:00
|
|
|
iv *= 1024;
|
2018-10-25 15:43:21 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'k': case 'K':
|
2012-04-07 15:27:34 +00:00
|
|
|
iv *= 1024;
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
*value = iv;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-12-06 18:18:35 +00:00
|
|
|
char *
|
|
|
|
vfs_getopts(struct vfsoptlist *opts, const char *name, int *error)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
*error = 0;
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) != 0)
|
|
|
|
continue;
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->seen = 1;
|
|
|
|
if (opt->len == 0 ||
|
|
|
|
((char *)opt->value)[opt->len - 1] != '\0') {
|
2004-12-06 18:18:35 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (opt->value);
|
|
|
|
}
|
2007-02-13 01:28:48 +00:00
|
|
|
*error = ENOENT;
|
2004-12-06 18:18:35 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-24 17:43:09 +00:00
|
|
|
vfs_flagopt(struct vfsoptlist *opts, const char *name, uint64_t *w,
|
|
|
|
uint64_t val)
|
2004-12-06 18:18:35 +00:00
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) == 0) {
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->seen = 1;
|
2004-12-06 18:18:35 +00:00
|
|
|
if (w != NULL)
|
|
|
|
*w |= val;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (w != NULL)
|
|
|
|
*w &= ~val;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_scanopt(struct vfsoptlist *opts, const char *name, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct vfsopt *opt;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
KASSERT(opts != NULL, ("vfs_getopt: caller passed 'opts' as NULL"));
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) != 0)
|
|
|
|
continue;
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->seen = 1;
|
2007-12-31 23:44:53 +00:00
|
|
|
if (opt->len == 0 || opt->value == NULL)
|
|
|
|
return (0);
|
2004-12-06 18:18:35 +00:00
|
|
|
if (((char *)opt->value)[opt->len - 1] != '\0')
|
|
|
|
return (0);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = vsscanf(opt->value, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2004-12-07 08:15:41 +00:00
|
|
|
|
2009-03-02 23:26:30 +00:00
|
|
|
int
|
|
|
|
vfs_setopt(struct vfsoptlist *opts, const char *name, void *value, int len)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) != 0)
|
|
|
|
continue;
|
|
|
|
opt->seen = 1;
|
|
|
|
if (opt->value == NULL)
|
|
|
|
opt->len = len;
|
|
|
|
else {
|
|
|
|
if (opt->len != len)
|
|
|
|
return (EINVAL);
|
|
|
|
bcopy(value, opt->value, len);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_setopt_part(struct vfsoptlist *opts, const char *name, void *value, int len)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) != 0)
|
|
|
|
continue;
|
|
|
|
opt->seen = 1;
|
|
|
|
if (opt->value == NULL)
|
|
|
|
opt->len = len;
|
|
|
|
else {
|
|
|
|
if (opt->len < len)
|
|
|
|
return (EINVAL);
|
|
|
|
opt->len = len;
|
|
|
|
bcopy(value, opt->value, len);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_setopts(struct vfsoptlist *opts, const char *name, const char *value)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) != 0)
|
|
|
|
continue;
|
|
|
|
opt->seen = 1;
|
|
|
|
if (opt->value == NULL)
|
|
|
|
opt->len = strlen(value) + 1;
|
|
|
|
else if (strlcpy(opt->value, value, opt->len) >= opt->len)
|
|
|
|
return (EINVAL);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
/*
|
|
|
|
* Find and copy a mount option.
|
|
|
|
*
|
|
|
|
* The size of the buffer has to be specified
|
|
|
|
* in len, if it is not the same length as the
|
|
|
|
* mount option, EINVAL is returned.
|
|
|
|
* Returns ENOENT if the option is not found.
|
|
|
|
*/
|
|
|
|
int
|
2017-05-17 00:34:34 +00:00
|
|
|
vfs_copyopt(struct vfsoptlist *opts, const char *name, void *dest, int len)
|
2002-07-02 17:09:22 +00:00
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
|
2003-02-14 13:30:25 +00:00
|
|
|
KASSERT(opts != NULL, ("vfs_copyopt: caller passed 'opts' as NULL"));
|
2003-02-14 13:18:51 +00:00
|
|
|
|
2002-07-02 17:09:22 +00:00
|
|
|
TAILQ_FOREACH(opt, opts, link) {
|
|
|
|
if (strcmp(name, opt->name) == 0) {
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->seen = 1;
|
2002-07-02 17:09:22 +00:00
|
|
|
if (len != opt->len)
|
|
|
|
return (EINVAL);
|
|
|
|
bcopy(opt->value, dest, opt->len);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
2004-07-04 08:52:35 +00:00
|
|
|
|
2004-12-05 22:41:02 +00:00
|
|
|
int
|
2009-05-11 15:33:26 +00:00
|
|
|
__vfs_statfs(struct mount *mp, struct statfs *sbp)
|
2004-12-05 22:41:02 +00:00
|
|
|
{
|
|
|
|
|
2019-08-19 14:11:54 +00:00
|
|
|
/*
|
|
|
|
* Filesystems only fill in part of the structure for updates, we
|
|
|
|
* have to read the entirety first to get all content.
|
|
|
|
*/
|
2020-07-10 06:46:42 +00:00
|
|
|
if (sbp != &mp->mnt_stat)
|
|
|
|
memcpy(sbp, &mp->mnt_stat, sizeof(*sbp));
|
2019-08-19 14:11:54 +00:00
|
|
|
|
2019-08-18 18:40:12 +00:00
|
|
|
/*
|
|
|
|
* Set these in case the underlying filesystem fails to do so.
|
|
|
|
*/
|
|
|
|
sbp->f_version = STATFS_VERSION;
|
|
|
|
sbp->f_namemax = NAME_MAX;
|
|
|
|
sbp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
|
|
|
|
|
|
|
|
return (mp->mnt_op->vfs_statfs(mp, sbp));
|
2004-12-05 22:41:02 +00:00
|
|
|
}
|
2004-12-06 13:01:41 +00:00
|
|
|
|
2004-12-06 18:18:35 +00:00
|
|
|
void
|
|
|
|
vfs_mountedfrom(struct mount *mp, const char *from)
|
|
|
|
{
|
|
|
|
|
|
|
|
bzero(mp->mnt_stat.f_mntfromname, sizeof mp->mnt_stat.f_mntfromname);
|
|
|
|
strlcpy(mp->mnt_stat.f_mntfromname, from,
|
|
|
|
sizeof mp->mnt_stat.f_mntfromname);
|
|
|
|
}
|
|
|
|
|
2004-12-06 13:01:41 +00:00
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
* This is the api for building mount args and mounting filesystems from
|
|
|
|
* inside the kernel.
|
|
|
|
*
|
|
|
|
* The API works by accumulation of individual args. First error is
|
|
|
|
* latched.
|
|
|
|
*
|
|
|
|
* XXX: should be documented in new manpage kernel_mount(9)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* A memory allocation which must be freed when we are done */
|
|
|
|
struct mntaarg {
|
|
|
|
SLIST_ENTRY(mntaarg) next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The header for the mount arguments */
|
|
|
|
struct mntarg {
|
|
|
|
struct iovec *v;
|
|
|
|
int len;
|
|
|
|
int error;
|
|
|
|
SLIST_HEAD(, mntaarg) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a boolean argument.
|
|
|
|
*
|
|
|
|
* flag is the boolean value.
|
|
|
|
* name must start with "no".
|
|
|
|
*/
|
|
|
|
struct mntarg *
|
|
|
|
mount_argb(struct mntarg *ma, int flag, const char *name)
|
|
|
|
{
|
|
|
|
|
|
|
|
KASSERT(name[0] == 'n' && name[1] == 'o',
|
|
|
|
("mount_argb(...,%s): name must start with 'no'", name));
|
|
|
|
|
|
|
|
return (mount_arg(ma, name + (flag ? 2 : 0), NULL, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an argument printf style
|
|
|
|
*/
|
|
|
|
struct mntarg *
|
|
|
|
mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct mntaarg *maa;
|
|
|
|
struct sbuf *sb;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (ma == NULL) {
|
|
|
|
ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO);
|
|
|
|
SLIST_INIT(&ma->list);
|
|
|
|
}
|
|
|
|
if (ma->error)
|
|
|
|
return (ma);
|
|
|
|
|
|
|
|
ma->v = realloc(ma->v, sizeof *ma->v * (ma->len + 2),
|
|
|
|
M_MOUNT, M_WAITOK);
|
|
|
|
ma->v[ma->len].iov_base = (void *)(uintptr_t)name;
|
|
|
|
ma->v[ma->len].iov_len = strlen(name) + 1;
|
|
|
|
ma->len++;
|
|
|
|
|
2008-08-09 11:14:05 +00:00
|
|
|
sb = sbuf_new_auto();
|
2004-12-06 13:01:41 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
sbuf_vprintf(sb, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
sbuf_finish(sb);
|
|
|
|
len = sbuf_len(sb) + 1;
|
|
|
|
maa = malloc(sizeof *maa + len, M_MOUNT, M_WAITOK | M_ZERO);
|
|
|
|
SLIST_INSERT_HEAD(&ma->list, maa, next);
|
|
|
|
bcopy(sbuf_data(sb), maa + 1, len);
|
|
|
|
sbuf_delete(sb);
|
|
|
|
|
|
|
|
ma->v[ma->len].iov_base = maa + 1;
|
|
|
|
ma->v[ma->len].iov_len = len;
|
|
|
|
ma->len++;
|
|
|
|
|
|
|
|
return (ma);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an argument which is a userland string.
|
|
|
|
*/
|
|
|
|
struct mntarg *
|
|
|
|
mount_argsu(struct mntarg *ma, const char *name, const void *val, int len)
|
|
|
|
{
|
|
|
|
struct mntaarg *maa;
|
|
|
|
char *tbuf;
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
return (ma);
|
|
|
|
if (ma == NULL) {
|
|
|
|
ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO);
|
|
|
|
SLIST_INIT(&ma->list);
|
|
|
|
}
|
|
|
|
if (ma->error)
|
|
|
|
return (ma);
|
|
|
|
maa = malloc(sizeof *maa + len, M_MOUNT, M_WAITOK | M_ZERO);
|
|
|
|
SLIST_INSERT_HEAD(&ma->list, maa, next);
|
|
|
|
tbuf = (void *)(maa + 1);
|
|
|
|
ma->error = copyinstr(val, tbuf, len, NULL);
|
|
|
|
return (mount_arg(ma, name, tbuf, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Plain argument.
|
|
|
|
*
|
2008-02-14 17:04:31 +00:00
|
|
|
* If length is -1, treat value as a C string.
|
2004-12-06 13:01:41 +00:00
|
|
|
*/
|
|
|
|
struct mntarg *
|
|
|
|
mount_arg(struct mntarg *ma, const char *name, const void *val, int len)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ma == NULL) {
|
|
|
|
ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO);
|
|
|
|
SLIST_INIT(&ma->list);
|
|
|
|
}
|
|
|
|
if (ma->error)
|
|
|
|
return (ma);
|
|
|
|
|
|
|
|
ma->v = realloc(ma->v, sizeof *ma->v * (ma->len + 2),
|
|
|
|
M_MOUNT, M_WAITOK);
|
|
|
|
ma->v[ma->len].iov_base = (void *)(uintptr_t)name;
|
|
|
|
ma->v[ma->len].iov_len = strlen(name) + 1;
|
|
|
|
ma->len++;
|
|
|
|
|
|
|
|
ma->v[ma->len].iov_base = (void *)(uintptr_t)val;
|
|
|
|
if (len < 0)
|
|
|
|
ma->v[ma->len].iov_len = strlen(val) + 1;
|
|
|
|
else
|
|
|
|
ma->v[ma->len].iov_len = len;
|
|
|
|
ma->len++;
|
|
|
|
return (ma);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a mntarg structure
|
|
|
|
*/
|
2005-02-10 12:25:38 +00:00
|
|
|
static void
|
2004-12-06 13:01:41 +00:00
|
|
|
free_mntarg(struct mntarg *ma)
|
|
|
|
{
|
|
|
|
struct mntaarg *maa;
|
|
|
|
|
|
|
|
while (!SLIST_EMPTY(&ma->list)) {
|
|
|
|
maa = SLIST_FIRST(&ma->list);
|
|
|
|
SLIST_REMOVE_HEAD(&ma->list, next);
|
|
|
|
free(maa, M_MOUNT);
|
|
|
|
}
|
|
|
|
free(ma->v, M_MOUNT);
|
|
|
|
free(ma, M_MOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mount a filesystem
|
|
|
|
*/
|
|
|
|
int
|
2012-01-17 01:08:01 +00:00
|
|
|
kernel_mount(struct mntarg *ma, uint64_t flags)
|
2004-12-06 13:01:41 +00:00
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
KASSERT(ma != NULL, ("kernel_mount NULL ma"));
|
|
|
|
KASSERT(ma->v != NULL, ("kernel_mount NULL ma->v"));
|
|
|
|
KASSERT(!(ma->len & 1), ("kernel_mount odd ma->len (%d)", ma->len));
|
|
|
|
|
|
|
|
auio.uio_iov = ma->v;
|
|
|
|
auio.uio_iovcnt = ma->len;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
|
|
|
|
error = ma->error;
|
|
|
|
if (!error)
|
|
|
|
error = vfs_donmount(curthread, flags, &auio);
|
|
|
|
free_mntarg(ma);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A printflike function to mount a filesystem.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kernel_vmount(int flags, ...)
|
|
|
|
{
|
|
|
|
struct mntarg *ma = NULL;
|
|
|
|
va_list ap;
|
|
|
|
const char *cp;
|
|
|
|
const void *vp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
va_start(ap, flags);
|
|
|
|
for (;;) {
|
|
|
|
cp = va_arg(ap, const char *);
|
|
|
|
if (cp == NULL)
|
|
|
|
break;
|
|
|
|
vp = va_arg(ap, const void *);
|
2008-02-14 17:04:31 +00:00
|
|
|
ma = mount_arg(ma, cp, vp, (vp != NULL ? -1 : 0));
|
2004-12-06 13:01:41 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
error = kernel_mount(ma, flags);
|
|
|
|
return (error);
|
|
|
|
}
|
2020-08-19 17:10:04 +00:00
|
|
|
|
|
|
|
/* Map from mount options to printable formats. */
|
|
|
|
static struct mntoptnames optnames[] = {
|
|
|
|
MNTOPT_NAMES
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEVCTL_LEN 1024
|
|
|
|
static void
|
2020-08-20 16:52:48 +00:00
|
|
|
mount_devctl_event(const char *type, struct mount *mp, bool donew)
|
2020-08-19 17:10:04 +00:00
|
|
|
{
|
|
|
|
const uint8_t *cp;
|
|
|
|
struct mntoptnames *fp;
|
|
|
|
struct sbuf sb;
|
|
|
|
struct statfs *sfp = &mp->mnt_stat;
|
|
|
|
char *buf;
|
|
|
|
|
2020-08-20 16:52:48 +00:00
|
|
|
buf = malloc(DEVCTL_LEN, M_MOUNT, M_NOWAIT);
|
2020-08-19 17:10:04 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
sbuf_new(&sb, buf, DEVCTL_LEN, SBUF_FIXEDLEN);
|
|
|
|
sbuf_cpy(&sb, "mount-point=\"");
|
|
|
|
devctl_safe_quote_sb(&sb, sfp->f_mntonname);
|
|
|
|
sbuf_cat(&sb, "\" mount-dev=\"");
|
|
|
|
devctl_safe_quote_sb(&sb, sfp->f_mntfromname);
|
|
|
|
sbuf_cat(&sb, "\" mount-type=\"");
|
|
|
|
devctl_safe_quote_sb(&sb, sfp->f_fstypename);
|
|
|
|
sbuf_cat(&sb, "\" fsid=0x");
|
|
|
|
cp = (const uint8_t *)&sfp->f_fsid.val[0];
|
|
|
|
for (int i = 0; i < sizeof(sfp->f_fsid); i++)
|
|
|
|
sbuf_printf(&sb, "%02x", cp[i]);
|
|
|
|
sbuf_printf(&sb, " owner=%u flags=\"", sfp->f_owner);
|
|
|
|
for (fp = optnames; fp->o_opt != 0; fp++) {
|
|
|
|
if ((mp->mnt_flag & fp->o_opt) != 0) {
|
|
|
|
sbuf_cat(&sb, fp->o_name);
|
|
|
|
sbuf_putc(&sb, ';');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sbuf_putc(&sb, '"');
|
|
|
|
sbuf_finish(&sb);
|
|
|
|
|
2021-07-24 15:03:53 +00:00
|
|
|
/*
|
|
|
|
* Options are not published because the form of the options depends on
|
|
|
|
* the file system and may include binary data. In addition, they don't
|
|
|
|
* necessarily provide enough useful information to be actionable when
|
|
|
|
* devd processes them.
|
|
|
|
*/
|
|
|
|
|
2020-08-20 16:52:48 +00:00
|
|
|
if (sbuf_error(&sb) == 0)
|
|
|
|
devctl_notify("VFS", "FS", type, sbuf_data(&sb));
|
2020-08-19 17:10:04 +00:00
|
|
|
sbuf_delete(&sb);
|
|
|
|
free(buf, M_MOUNT);
|
|
|
|
}
|
2020-11-05 20:52:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend write operations on all local writeable filesystems. Does
|
|
|
|
* full sync of them in the process.
|
|
|
|
*
|
|
|
|
* Iterate over the mount points in reverse order, suspending most
|
|
|
|
* recently mounted filesystems first. It handles a case where a
|
|
|
|
* filesystem mounted from a md(4) vnode-backed device should be
|
|
|
|
* suspended before the filesystem that owns the vnode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
suspend_all_fs(void)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
TAILQ_FOREACH_REVERSE(mp, &mountlist, mntlist, mnt_list) {
|
|
|
|
error = vfs_busy(mp, MBF_MNTLSTLOCK | MBF_NOWAIT);
|
|
|
|
if (error != 0)
|
|
|
|
continue;
|
|
|
|
if ((mp->mnt_flag & (MNT_RDONLY | MNT_LOCAL)) != MNT_LOCAL ||
|
|
|
|
(mp->mnt_kern_flag & MNTK_SUSPEND) != 0) {
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = vfs_write_suspend(mp, 0);
|
|
|
|
if (error == 0) {
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
MPASS((mp->mnt_kern_flag & MNTK_SUSPEND_ALL) == 0);
|
|
|
|
mp->mnt_kern_flag |= MNTK_SUSPEND_ALL;
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
} else {
|
|
|
|
printf("suspend of %s failed, error %d\n",
|
|
|
|
mp->mnt_stat.f_mntonname, error);
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
resume_all_fs(void)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
|
|
|
|
if ((mp->mnt_kern_flag & MNTK_SUSPEND_ALL) == 0)
|
|
|
|
continue;
|
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
MNT_ILOCK(mp);
|
|
|
|
MPASS((mp->mnt_kern_flag & MNTK_SUSPEND) != 0);
|
|
|
|
mp->mnt_kern_flag &= ~MNTK_SUSPEND_ALL;
|
|
|
|
MNT_IUNLOCK(mp);
|
|
|
|
vfs_write_resume(mp, 0);
|
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
}
|
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
}
|