summaryrefslogtreecommitdiffstats
path: root/sys/cddl/compat
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2009-09-15 11:13:40 +0000
committerpjd <pjd@FreeBSD.org>2009-09-15 11:13:40 +0000
commit12d546b4f4e82a3ea4a177af05014cf22488327f (patch)
treeb227ca009c662518ca0f3e89ec74d1c9015ed356 /sys/cddl/compat
parentabfab3edcca5dcf4e1885c3c71058cdfb23ccd95 (diff)
downloadFreeBSD-src-12d546b4f4e82a3ea4a177af05014cf22488327f.zip
FreeBSD-src-12d546b4f4e82a3ea4a177af05014cf22488327f.tar.gz
MFC r196456,r196457,r196458,r196662,r196702,r196703,r196919,r196927,r196928,
r196943,r196944,r196947,r196950,r196953,r196954,r196965,r196978,r196979, r196980,r196982,r196985,r196992,r197131,r197133,r197150,r197151,r197152, r197153,r197167,r197172,r197177,r197200,r197201: r196456: - Give minclsyspri and maxclsyspri real values (consulted with kmacy). - Honour 'pri' argument for thread_create(). r196457: Set priority of vdev_geom threads and zvol threads to PRIBIO. r196458: - Hide ZFS kernel threads under zfskern process. - Use better (shorter) threads names: 'zvol:worker zvol/tank/vol00' -> 'zvol tank/vol00' 'vdev:worker da0' -> 'vdev da0' r196662: Add missing mountpoint vnode locking. This fixes panic on assertion with DEBUG_VFS_LOCKS and vfs.usermount=1 when regular user tries to mount dataset owned by him. r196702: Remove empty directory. r196703: Backport the 'dirtying dbuf' panic fix from newer ZFS version. Reported by: Thomas Backman <serenity@exscape.org> r196919: bzero() on-stack argument, so mutex_init() won't misinterpret that the lock is already initialized if we have some garbage on the stack. PR: kern/135480 Reported by: Emil Mikulic <emikulic@gmail.com> r196927: Changing provider size is not really supported by GEOM, but doing so when provider is closed should be ok. When administrator requests to change ZVOL size do it immediately if ZVOL is closed or do it on last ZVOL close. PR: kern/136942 Requested by: Bernard Buri <bsd@ask-us.at> r196928: Teach zdb(8) how to obtain GEOM provider size. PR: kern/133134 Reported by: Philipp Wuensche <cryx-freebsd@h3q.com> r196943: - Avoid holding mutex around M_WAITOK allocations. - Add locking for mnt_opt field. r196944: Don't recheck ownership on update mount. This will eliminate LOR between vfs_busy() and mount mutex. We check ownership in vfs_domount() anyway. Noticed by: kib Reviewed by: kib r196947: Defer thread start until we set priority. Reviewed by: kib r196950: Fix detection of file system being shared. Now zfs unshare/destroy/rename command will properly remove exported file systems. r196953: When snapshot mount point is busy (for example we are still in it) we will fail to unmount it, but it won't be removed from the tree, so in that case there is no need to reinsert it. Reported by: trasz r196954: If we have to use avl_find(), optimize a bit and use avl_insert() instead of avl_add() (the latter is actually a wrapper around avl_find() + avl_insert()). Fix similar case in the code that is currently commented out. r196965: Fix reference count leak for a case where snapshot's mount point is updated. r196978: Call ZFS_EXIT() after locking the vnode. r196979: On FreeBSD we don't have to look for snapshot's mount point, because fhtovp method is already called with proper mount point. r196980: When we automatically mount snapshot we want to return vnode of the mount point from the lookup and not covered vnode. This is one of the fixes for using .zfs/ over NFS. r196982: We don't export individual snapshots, so mnt_export field in snapshot's mount point is NULL. That's why when we try to access snapshots over NFS use mnt_export field from the parent file system. r196985: Only log successful commands! Without this fix we log even unsuccessful commands executed by unprivileged users. Action is not really taken, but it is logged to pool history, which might be confusing. Reported by: Denis Ahrens <denis@h3q.com> r196992: Implement __assert() for Solaris-specific code. Until now Solaris code was using Solaris prototype for __assert(), but FreeBSD's implementation. Both take different arguments, so we were either core-dumping in assert() or printing garbage. Reported by: avg r197131: Tighten up the check for race in zfs_zget() - ZTOV(zp) can not only contain NULL, but also can point to dead vnode, take that into account. PR: kern/132068 Reported by: Edward Fisk <7ogcg7g02@sneakemail.com>, kris Fix based on patch from: Jaakko Heinonen <jh@saunalahti.fi> r197133: - Protect reclaim with z_teardown_inactive_lock. - Be prepared for dbuf to disappear in zfs_reclaim_complete() and check if z_dbuf field is NULL - this might happen in case of rollback or forced unmount between zfs_freebsd_reclaim() and zfs_reclaim_complete(). - On forced unmount wait for all znodes to be destroyed - destruction can be done asynchronously via zfs_reclaim_complete(). r197150: There is a bug where mze_insert() can trigger an assert() of inserting the same entry twice. This bug is not fixed yet, but leads to situation where when try to access corrupted directory the kernel will panic. Until the bug is properly fixed, try to recover from it and log that it happened. Reported by: marck OpenSolaris bug: 6709336 r197151: Be sure not to overflow struct fid. r197152: Extend scope of the z_teardown_lock lock for consistency and "just in case". r197153: When zfs.ko is compiled with debug, make sure that znode and vnode point at each other. r197167: Work-around READDIRPLUS problem with .zfs/ and .zfs/snapshot/ directories by just returning EOPNOTSUPP. This will allow NFS server to fall back to regular READDIR. Note that converting inode number to snapshot's vnode is expensive operation. Snapshots are stored in AVL tree, but based on their names, not inode numbers, so to convert inode to snapshot vnode we have to interate over all snalshots. This is not a problem in OpenSolaris, because in their READDIRPLUS implementation they use VOP_LOOKUP() on d_name, instead of VFS_VGET() on d_fileno as we do. PR: kern/125149 Reported by: Weldon Godfrey <wgodfrey@ena.com> Analysis by: Jaakko Heinonen <jh@saunalahti.fi> r197172: Add missing \n. Reported by: marck r197177: Support both case: when snapshot is already mounted and when it is not yet mounted. r197200: Modify mount(8) to skip MNT_IGNORE file systems by default, just like df(1) does. This is not POLA violation, because there is no single file system in the base that use MNT_IGNORE currently, although ZFS snapshots will be mounted with MNT_IGNORE after next commit. Reviewed by: kib r197201: - Mount ZFS snapshots with MNT_IGNORE flag, so they are not visible in regular df(1) and mount(8) output. This is a bit smilar to OpenSolaris and follows ZFS route of not listing snapshots by default with 'zfs list' command. - Add UPDATING entry to note that ZFS snapshots are no longer visible in mount(8) and df(1) output by default. Reviewed by: kib Approved by: re (bz)
Diffstat (limited to 'sys/cddl/compat')
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c99
-rw-r--r--sys/cddl/compat/opensolaris/sys/mutex.h2
-rw-r--r--sys/cddl/compat/opensolaris/sys/proc.h27
-rw-r--r--sys/cddl/compat/opensolaris/sys/vfs.h4
4 files changed, 82 insertions, 50 deletions
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
index a716b63..8538b54 100644
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
+++ b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
@@ -45,20 +45,33 @@ vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
{
struct vfsopt *opt;
size_t namesize;
+ int locked;
+
+ if (!(locked = mtx_owned(MNT_MTX(vfsp))))
+ MNT_ILOCK(vfsp);
if (vfsp->mnt_opt == NULL) {
- vfsp->mnt_opt = malloc(sizeof(*vfsp->mnt_opt), M_MOUNT, M_WAITOK);
- TAILQ_INIT(vfsp->mnt_opt);
+ void *opts;
+
+ MNT_IUNLOCK(vfsp);
+ opts = malloc(sizeof(*vfsp->mnt_opt), M_MOUNT, M_WAITOK);
+ MNT_ILOCK(vfsp);
+ if (vfsp->mnt_opt == NULL) {
+ vfsp->mnt_opt = opts;
+ TAILQ_INIT(vfsp->mnt_opt);
+ } else {
+ free(opts, M_MOUNT);
+ }
}
- opt = malloc(sizeof(*opt), M_MOUNT, M_WAITOK);
+ MNT_IUNLOCK(vfsp);
+ opt = malloc(sizeof(*opt), M_MOUNT, M_WAITOK);
namesize = strlen(name) + 1;
opt->name = malloc(namesize, M_MOUNT, M_WAITOK);
strlcpy(opt->name, name, namesize);
opt->pos = -1;
opt->seen = 1;
-
if (arg == NULL) {
opt->value = NULL;
opt->len = 0;
@@ -67,16 +80,23 @@ vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
opt->value = malloc(opt->len, M_MOUNT, M_WAITOK);
bcopy(arg, opt->value, opt->len);
}
- /* TODO: Locking. */
+
+ MNT_ILOCK(vfsp);
TAILQ_INSERT_TAIL(vfsp->mnt_opt, opt, link);
+ if (!locked)
+ MNT_IUNLOCK(vfsp);
}
void
vfs_clearmntopt(vfs_t *vfsp, const char *name)
{
+ int locked;
- /* TODO: Locking. */
+ if (!(locked = mtx_owned(MNT_MTX(vfsp))))
+ MNT_ILOCK(vfsp);
vfs_deleteopt(vfsp->mnt_opt, name);
+ if (!locked)
+ MNT_IUNLOCK(vfsp);
}
int
@@ -92,12 +112,13 @@ vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp)
}
int
-domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
+mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
char *fspec, int fsflags)
{
struct mount *mp;
struct vfsconf *vfsp;
struct ucred *cr;
+ vnode_t *vp;
int error;
/*
@@ -112,23 +133,28 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
if (vfsp == NULL)
return (ENODEV);
+ vp = *vpp;
if (vp->v_type != VDIR)
return (ENOTDIR);
+ /*
+ * We need vnode lock to protect v_mountedhere and vnode interlock
+ * to protect v_iflag.
+ */
+ vn_lock(vp, LK_SHARED | LK_RETRY);
VI_LOCK(vp);
- if ((vp->v_iflag & VI_MOUNT) != 0 ||
- vp->v_mountedhere != NULL) {
+ if ((vp->v_iflag & VI_MOUNT) != 0 || vp->v_mountedhere != NULL) {
VI_UNLOCK(vp);
+ VOP_UNLOCK(vp, 0);
return (EBUSY);
}
vp->v_iflag |= VI_MOUNT;
VI_UNLOCK(vp);
+ VOP_UNLOCK(vp, 0);
/*
* Allocate and initialize the filesystem.
*/
- vn_lock(vp, LK_SHARED | LK_RETRY);
mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred);
- VOP_UNLOCK(vp, 0);
mp->mnt_optnew = NULL;
vfs_setmntopt(mp, "from", fspec, 0);
@@ -138,11 +164,18 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
/*
* Set the mount level flags.
*/
- if (fsflags & MNT_RDONLY)
- mp->mnt_flag |= MNT_RDONLY;
- mp->mnt_flag &=~ MNT_UPDATEMASK;
+ mp->mnt_flag &= ~MNT_UPDATEMASK;
mp->mnt_flag |= fsflags & (MNT_UPDATEMASK | MNT_FORCE | MNT_ROOTFS);
/*
+ * Snapshots are always read-only.
+ */
+ mp->mnt_flag |= MNT_RDONLY;
+ /*
+ * We don't want snapshots to be visible in regular
+ * mount(8) and df(1) output.
+ */
+ mp->mnt_flag |= MNT_IGNORE;
+ /*
* Unprivileged user can trigger mounting a snapshot, but we don't want
* him to unmount it, so we switch to privileged of original mount.
*/
@@ -150,11 +183,6 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
mp->mnt_cred = crdup(vp->v_mount->mnt_cred);
mp->mnt_stat.f_owner = mp->mnt_cred->cr_uid;
/*
- * Mount the filesystem.
- * XXX The final recipients of VFS_MOUNT just overwrite the ndp they
- * get. No freeing of cn_pnbuf.
- */
- /*
* XXX: This is evil, but we can't mount a snapshot as a regular user.
* XXX: Is is safe when snapshot is mounted from within a jail?
*/
@@ -163,7 +191,7 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
error = VFS_MOUNT(mp);
td->td_ucred = cr;
- if (!error) {
+ if (error == 0) {
if (mp->mnt_opt != NULL)
vfs_freeopts(mp->mnt_opt);
mp->mnt_opt = mp->mnt_optnew;
@@ -175,42 +203,33 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
*/
mp->mnt_optnew = NULL;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
- /*
- * Put the new filesystem on the mount list after root.
- */
#ifdef FREEBSD_NAMECACHE
cache_purge(vp);
#endif
- if (!error) {
+ VI_LOCK(vp);
+ vp->v_iflag &= ~VI_MOUNT;
+ VI_UNLOCK(vp);
+ if (error == 0) {
vnode_t *mvp;
- VI_LOCK(vp);
- vp->v_iflag &= ~VI_MOUNT;
- VI_UNLOCK(vp);
vp->v_mountedhere = mp;
+ /*
+ * Put the new filesystem on 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);
if (VFS_ROOT(mp, LK_EXCLUSIVE, &mvp))
panic("mount: lost mount");
- mountcheckdirs(vp, mvp);
- vput(mvp);
- VOP_UNLOCK(vp, 0);
- if ((mp->mnt_flag & MNT_RDONLY) == 0)
- error = vfs_allocate_syncvnode(mp);
+ vput(vp);
vfs_unbusy(mp);
- if (error)
- vrele(vp);
- else
- vfs_mountedfrom(mp, fspec);
+ *vpp = mvp;
} else {
- VI_LOCK(vp);
- vp->v_iflag &= ~VI_MOUNT;
- VI_UNLOCK(vp);
- VOP_UNLOCK(vp, 0);
+ vput(vp);
vfs_unbusy(mp);
vfs_mount_destroy(mp);
+ *vpp = NULL;
}
return (error);
}
diff --git a/sys/cddl/compat/opensolaris/sys/mutex.h b/sys/cddl/compat/opensolaris/sys/mutex.h
index 8756cd0..f6858a7 100644
--- a/sys/cddl/compat/opensolaris/sys/mutex.h
+++ b/sys/cddl/compat/opensolaris/sys/mutex.h
@@ -32,9 +32,9 @@
#ifdef _KERNEL
#include <sys/param.h>
-#include <sys/proc.h>
#include <sys/lock.h>
#include_next <sys/mutex.h>
+#include <sys/proc.h>
#include <sys/sx.h>
typedef enum {
diff --git a/sys/cddl/compat/opensolaris/sys/proc.h b/sys/cddl/compat/opensolaris/sys/proc.h
index 73fbcda..e0b7bc5 100644
--- a/sys/cddl/compat/opensolaris/sys/proc.h
+++ b/sys/cddl/compat/opensolaris/sys/proc.h
@@ -34,13 +34,17 @@
#include_next <sys/proc.h>
#include <sys/stdint.h>
#include <sys/smp.h>
+#include <sys/sched.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/unistd.h>
#include <sys/debug.h>
#ifdef _KERNEL
#define CPU curcpu
-#define minclsyspri 0
-#define maxclsyspri 0
+#define minclsyspri PRIBIO
+#define maxclsyspri PVM
#define max_ncpus mp_ncpus
#define boot_max_ncpus mp_ncpus
@@ -54,11 +58,13 @@ typedef struct thread kthread_t;
typedef struct thread *kthread_id_t;
typedef struct proc proc_t;
+extern struct proc *zfsproc;
+
static __inline kthread_t *
thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
size_t len, proc_t *pp, int state, pri_t pri)
{
- proc_t *p;
+ kthread_t *td = NULL;
int error;
/*
@@ -67,13 +73,20 @@ thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
ASSERT(stk == NULL);
ASSERT(len == 0);
ASSERT(state == TS_RUN);
+ ASSERT(pp == &p0);
- error = kproc_create(proc, arg, &p, 0, stksize / PAGE_SIZE,
- "solthread %p", proc);
- return (error == 0 ? FIRST_THREAD_IN_PROC(p) : NULL);
+ error = kproc_kthread_add(proc, arg, &zfsproc, &td, RFSTOPPED,
+ stksize / PAGE_SIZE, "zfskern", "solthread %p", proc);
+ if (error == 0) {
+ thread_lock(td);
+ sched_prio(td, pri);
+ sched_add(td, SRQ_BORING);
+ thread_unlock(td);
+ }
+ return (td);
}
-#define thread_exit() kproc_exit(0)
+#define thread_exit() kthread_exit()
#endif /* _KERNEL */
diff --git a/sys/cddl/compat/opensolaris/sys/vfs.h b/sys/cddl/compat/opensolaris/sys/vfs.h
index be3e3cf..d3a7e38 100644
--- a/sys/cddl/compat/opensolaris/sys/vfs.h
+++ b/sys/cddl/compat/opensolaris/sys/vfs.h
@@ -110,8 +110,8 @@ void vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
int flags __unused);
void vfs_clearmntopt(vfs_t *vfsp, const char *name);
int vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp);
-int domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
- char *fspec, int fsflags);
+int mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype,
+ char *fspath, char *fspec, int fsflags);
typedef uint64_t vfs_feature_t;
OpenPOWER on IntegriCloud