diff options
Diffstat (limited to 'sys/cddl/compat')
32 files changed, 811 insertions, 689 deletions
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c b/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c index 37de21f..bdb8f02 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c @@ -61,6 +61,15 @@ atomic_add_64(volatile uint64_t *target, int64_t delta) *target += delta; mtx_unlock(&atomic_mtx); } + +void +atomic_dec_64(volatile uint64_t *target) +{ + + mtx_lock(&atomic_mtx); + *target -= 1; + mtx_unlock(&atomic_mtx); +} #endif uint64_t diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c index 139d018..a24ca83 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c @@ -94,7 +94,7 @@ zfs_kmem_free(void *buf, size_t size __unused) { #ifdef KMEM_DEBUG if (buf == NULL) { - printf("%s: attempt to free NULL\n",__func__); + printf("%s: attempt to free NULL\n", __func__); return; } struct kmem_item *i; @@ -156,7 +156,7 @@ kmem_cache_create(char *name, size_t bufsize, size_t align, cache->kc_constructor = constructor; cache->kc_destructor = destructor; cache->kc_private = private; -#ifdef _KERNEL +#if defined(_KERNEL) && !defined(KMEM_DEBUG) cache->kc_zone = uma_zcreate(cache->kc_name, bufsize, constructor != NULL ? kmem_std_constructor : NULL, destructor != NULL ? kmem_std_destructor : NULL, @@ -171,23 +171,23 @@ kmem_cache_create(char *name, size_t bufsize, size_t align, void kmem_cache_destroy(kmem_cache_t *cache) { +#if defined(_KERNEL) && !defined(KMEM_DEBUG) uma_zdestroy(cache->kc_zone); +#endif kmem_free(cache, sizeof(*cache)); } void * kmem_cache_alloc(kmem_cache_t *cache, int flags) { -#ifdef _KERNEL +#if defined(_KERNEL) && !defined(KMEM_DEBUG) return (uma_zalloc_arg(cache->kc_zone, cache, flags)); #else void *p; p = kmem_alloc(cache->kc_size, flags); - if (p != NULL) { - kmem_std_constructor(p, cache->kc_size, cache->kc_private, - flags); - } + if (p != NULL && cache->kc_constructor != NULL) + kmem_std_constructor(p, cache->kc_size, cache, flags); return (p); #endif } @@ -195,10 +195,11 @@ kmem_cache_alloc(kmem_cache_t *cache, int flags) void kmem_cache_free(kmem_cache_t *cache, void *buf) { -#ifdef _KERNEL +#if defined(_KERNEL) && !defined(KMEM_DEBUG) uma_zfree_arg(cache->kc_zone, buf, cache); #else - kmem_std_destructor(buf, cache->kc_size, cache->kc_private); + if (cache->kc_destructor != NULL) + kmem_std_destructor(buf, cache->kc_size, cache); kmem_free(buf, cache->kc_size); #endif } @@ -207,7 +208,9 @@ kmem_cache_free(kmem_cache_t *cache, void *buf) void kmem_cache_reap_now(kmem_cache_t *cache) { +#ifndef KMEM_DEBUG zone_drain(cache->kc_zone); +#endif } void @@ -253,6 +256,8 @@ kmem_show(void *dummy __unused) printf("KMEM_DEBUG: Leaked elements:\n\n"); LIST_FOREACH(i, &kmem_items, next) { printf("address=%p\n", i); + stack_print_ddb(&i->stack); + printf("\n"); } } mtx_unlock(&kmem_items_mtx); diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c b/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c new file mode 100644 index 0000000..47df799 --- /dev/null +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c @@ -0,0 +1,112 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/pathname.h> +#include <sys/vfs.h> +#include <sys/vnode.h> + +int +lookupname(char *dirname, enum uio_seg seg, enum symfollow follow, + vnode_t **dirvpp, vnode_t **compvpp) +{ + + return (lookupnameat(dirname, seg, follow, dirvpp, compvpp, NULL)); +} + +int +lookupnameat(char *dirname, enum uio_seg seg, enum symfollow follow, + vnode_t **dirvpp, vnode_t **compvpp, vnode_t *startvp) +{ + struct nameidata nd; + int error, ltype; + + ASSERT(dirvpp == NULL); + + vref(startvp); + ltype = VOP_ISLOCKED(startvp); + VOP_UNLOCK(startvp, 0); + NDINIT_ATVP(&nd, LOOKUP, LOCKLEAF | MPSAFE | follow, seg, dirname, + startvp, curthread); + error = namei(&nd); + *compvpp = nd.ni_vp; + NDFREE(&nd, NDF_ONLY_PNBUF); + vn_lock(startvp, ltype | LK_RETRY); + return (error); +} + +int +traverse(vnode_t **cvpp, int lktype) +{ + kthread_t *td = curthread; + vnode_t *cvp; + vnode_t *tvp; + vfs_t *vfsp; + int error; + + cvp = *cvpp; + tvp = NULL; + + /* + * If this vnode is mounted on, then we transparently indirect + * to the vnode which is the root of the mounted file system. + * Before we do this we must check that an unmount is not in + * progress on this vnode. + */ + + for (;;) { + /* + * Reached the end of the mount chain? + */ + vfsp = vn_mountedvfs(cvp); + if (vfsp == NULL) + break; + /* + * tvp is NULL for *cvpp vnode, which we can't unlock. + */ + if (tvp != NULL) + vput(cvp); + else + vrele(cvp); + + /* + * The read lock must be held across the call to VFS_ROOT() to + * prevent a concurrent unmount from destroying the vfs. + */ + error = VFS_ROOT(vfsp, lktype, &tvp, td); + if (error != 0) + return (error); + cvp = tvp; + } + + *cvpp = cvp; + return (0); +} diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c b/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c index a89d478..279ae4c 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/kernel.h> #include <sys/libkern.h> +#include <sys/limits.h> #include <sys/misc.h> #include <sys/sunddi.h> @@ -40,17 +41,30 @@ struct opensolaris_utsname utsname = { }; int +ddi_strtol(const char *str, char **nptr, int base, long *result) +{ + + *result = strtol(str, nptr, base); + if (*result == 0) + return (EINVAL); + else if (*result == LONG_MIN || *result == LONG_MAX) + return (ERANGE); + return (0); +} + +int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result) { - char *end; if (str == hw_serial) { *result = hostid; return (0); } - *result = strtoul(str, &end, base); + *result = strtoul(str, nptr, base); if (*result == 0) return (EINVAL); + else if (*result == ULONG_MAX) + return (ERANGE); return (0); } diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c b/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c index 272fe59..837d736 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c @@ -30,9 +30,20 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/priv.h> #include <sys/vnode.h> +#include <sys/mntent.h> #include <sys/mount.h> #include <sys/stat.h> +#include <sys/jail.h> #include <sys/policy.h> +#include <sys/zfs_vfsops.h> + +int +secpolicy_nfs(struct ucred *cred) +{ + + /* TODO: Change PRIV_ROOT! */ + return (priv_check_cred(cred, PRIV_ROOT, 0)); +} int secpolicy_zfs(struct ucred *cred) @@ -62,16 +73,32 @@ secpolicy_fs_unmount(struct ucred *cred, struct mount *vfsp __unused) return (priv_check_cred(cred, PRIV_VFS_UNMOUNT, 0)); } +int +secpolicy_fs_owner(struct mount *mp, struct ucred *cred) +{ + + if (zfs_super_owner) { + if (cred->cr_uid == mp->mnt_cred->cr_uid && + (!jailed(cred) || + cred->cr_prison == mp->mnt_cred->cr_prison)) { + return (0); + } + } + return (priv_check_cred(cred, PRIV_VFS_MOUNT_OWNER, 0)); +} + /* * This check is done in kern_link(), so we could just return 0 here. */ extern int hardlink_check_uid; int -secpolicy_basic_link(struct ucred *cred) +secpolicy_basic_link(struct vnode *vp, struct ucred *cred) { if (!hardlink_check_uid) return (0); + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); return (priv_check_cred(cred, PRIV_VFS_LINK, 0)); } @@ -83,9 +110,11 @@ secpolicy_vnode_stky_modify(struct ucred *cred) } int -secpolicy_vnode_remove(struct ucred *cred) +secpolicy_vnode_remove(struct vnode *vp, struct ucred *cred) { + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0)); } @@ -94,9 +123,11 @@ secpolicy_vnode_access(struct ucred *cred, struct vnode *vp, uint64_t owner, accmode_t accmode) { - if ((accmode & VREAD) && priv_check_cred(cred, PRIV_VFS_READ, 0) != 0) { + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); + + if ((accmode & VREAD) && priv_check_cred(cred, PRIV_VFS_READ, 0) != 0) return (EACCES); - } if ((accmode & VWRITE) && priv_check_cred(cred, PRIV_VFS_WRITE, 0) != 0) { return (EACCES); @@ -116,11 +147,13 @@ secpolicy_vnode_access(struct ucred *cred, struct vnode *vp, uint64_t owner, } int -secpolicy_vnode_setdac(struct ucred *cred, uid_t owner) +secpolicy_vnode_setdac(struct vnode *vp, struct ucred *cred, uid_t owner) { if (owner == cred->cr_uid) return (0); + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0)); } @@ -148,7 +181,7 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, * In the specific case of creating a set-uid root * file, we need even more permissions. */ - error = secpolicy_vnode_setdac(cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cred, ovap->va_uid); if (error) return (error); error = secpolicy_setid_setsticky_clear(vp, vap, ovap, cred); @@ -158,7 +191,7 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, vap->va_mode = ovap->va_mode; } if (mask & (AT_UID | AT_GID)) { - error = secpolicy_vnode_setdac(cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cred, ovap->va_uid); if (error) return (error); @@ -170,14 +203,16 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || ((mask & AT_GID) && vap->va_gid != ovap->va_gid && !groupmember(vap->va_gid, cred))) { - error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0); - if (error) - return (error); + if (secpolicy_fs_owner(vp->v_mount, cred) != 0) { + error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0); + if (error) + return (error); + } } if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || ((mask & AT_GID) && vap->va_gid != ovap->va_gid)) { - secpolicy_setid_clear(vap, cred); + secpolicy_setid_clear(vap, vp, cred); } } if (mask & (AT_ATIME | AT_MTIME)) { @@ -189,7 +224,7 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, * If times is non-NULL, ... The caller must be the owner of * the file or be the super-user. */ - error = secpolicy_vnode_setdac(cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cred, ovap->va_uid); if (error && (vap->va_vaflags & VA_UTIMES_NULL)) error = unlocked_access(node, VWRITE, cred); if (error) @@ -206,25 +241,33 @@ secpolicy_vnode_create_gid(struct ucred *cred) } int -secpolicy_vnode_setids_setgids(struct ucred *cred, gid_t gid) +secpolicy_vnode_setids_setgids(struct vnode *vp, struct ucred *cred, gid_t gid) { - if (!groupmember(gid, cred)) - return (priv_check_cred(cred, PRIV_VFS_SETGID, 0)); - return (0); + if (groupmember(gid, cred)) + return (0); + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); + return (priv_check_cred(cred, PRIV_VFS_SETGID, 0)); } int -secpolicy_vnode_setid_retain(struct ucred *cred, boolean_t issuidroot __unused) +secpolicy_vnode_setid_retain(struct vnode *vp, struct ucred *cred, + boolean_t issuidroot __unused) { + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); return (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)); } void -secpolicy_setid_clear(struct vattr *vap, struct ucred *cred) +secpolicy_setid_clear(struct vattr *vap, struct vnode *vp, struct ucred *cred) { + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return; + if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0) { if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) { vap->va_mask |= AT_MODE; @@ -239,6 +282,9 @@ secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap, { int error; + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); + /* * Privileged processes may set the sticky bit on non-directories, * as well as set the setgid bit on a file with a group that the process @@ -253,9 +299,61 @@ secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap, * group-id bit. */ if ((vap->va_mode & S_ISGID) != 0) { - error = secpolicy_vnode_setids_setgids(cred, ovap->va_gid); + error = secpolicy_vnode_setids_setgids(vp, cred, ovap->va_gid); if (error) return (error); } return (0); } + +int +secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct mount *vfsp) +{ + + return (priv_check_cred(cr, PRIV_VFS_MOUNT, 0)); +} + +int +secpolicy_vnode_owner(struct vnode *vp, cred_t *cred, uid_t owner) +{ + + if (owner == cred->cr_uid) + return (0); + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); + + /* XXX: vfs_suser()? */ + return (priv_check_cred(cred, PRIV_VFS_MOUNT_OWNER, 0)); +} + +int +secpolicy_vnode_chown(struct vnode *vp, cred_t *cred, boolean_t check_self) +{ + + if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + return (0); + return (priv_check_cred(cred, PRIV_VFS_CHOWN, 0)); +} + +void +secpolicy_fs_mount_clearopts(cred_t *cr, struct mount *vfsp) +{ + + if (priv_check_cred(cr, PRIV_VFS_MOUNT_NONUSER, 0) != 0) { + MNT_ILOCK(vfsp); + vfsp->vfs_flag |= VFS_NOSETUID | MNT_USER; + vfs_clearmntopt(vfsp, MNTOPT_SETUID); + vfs_setmntopt(vfsp, MNTOPT_NOSETUID, NULL, 0); + MNT_IUNLOCK(vfsp); + } +} + +/* + * Check privileges for setting xvattr attributes + */ +int +secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) +{ + + return (priv_check_cred(cr, PRIV_VFS_SYSFLAGS, 0)); +} diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c index e9120ee..f1bb4e2 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/kernel.h> #include <sys/systm.h> +#include <sys/malloc.h> #include <sys/mount.h> #include <sys/cred.h> #include <sys/vfs.h> @@ -110,60 +111,12 @@ vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp) } int -traverse(vnode_t **cvpp, int lktype) -{ - kthread_t *td = curthread; - vnode_t *cvp; - vnode_t *tvp; - vfs_t *vfsp; - int error; - - cvp = *cvpp; - tvp = NULL; - - /* - * If this vnode is mounted on, then we transparently indirect - * to the vnode which is the root of the mounted file system. - * Before we do this we must check that an unmount is not in - * progress on this vnode. - */ - - for (;;) { - /* - * Reached the end of the mount chain? - */ - vfsp = vn_mountedvfs(cvp); - if (vfsp == NULL) - break; - /* - * tvp is NULL for *cvpp vnode, which we can't unlock. - */ - if (tvp != NULL) - vput(cvp); - else - vrele(cvp); - - /* - * The read lock must be held across the call to VFS_ROOT() to - * prevent a concurrent unmount from destroying the vfs. - */ - error = VFS_ROOT(vfsp, lktype, &tvp, td); - if (error != 0) - return (error); - cvp = tvp; - } - - *cvpp = cvp; - return (0); -} - -int domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath, char *fspec, int fsflags) { struct mount *mp; struct vfsconf *vfsp; - struct ucred *newcr, *oldcr; + struct ucred *cr; int error; /* @@ -203,29 +156,31 @@ domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath, /* * Set the mount level flags. - * crdup() can sleep, so do it before acquiring a mutex. */ - newcr = crdup(kcred); - MNT_ILOCK(mp); if (fsflags & MNT_RDONLY) mp->mnt_flag |= MNT_RDONLY; mp->mnt_flag &=~ MNT_UPDATEMASK; mp->mnt_flag |= fsflags & (MNT_UPDATEMASK | MNT_FORCE | MNT_ROOTFS); /* * Unprivileged user can trigger mounting a snapshot, but we don't want - * him to unmount it, so we switch to privileged credentials. + * him to unmount it, so we switch to privileged of original mount. */ - oldcr = mp->mnt_cred; - mp->mnt_cred = newcr; + crfree(mp->mnt_cred); + mp->mnt_cred = crdup(vp->v_mount->mnt_cred); mp->mnt_stat.f_owner = mp->mnt_cred->cr_uid; - MNT_IUNLOCK(mp); - crfree(oldcr); /* * 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? + */ + cr = td->td_ucred; + td->td_ucred = kcred; error = VFS_MOUNT(mp, td); + td->td_ucred = cr; if (!error) { if (mp->mnt_opt != NULL) diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c b/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c index 3059a78..8489052 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/queue.h> #include <sys/jail.h> +#include <sys/osd.h> #include <sys/priv.h> #include <sys/zone.h> @@ -52,7 +53,7 @@ typedef struct zone_dataset { LIST_HEAD(zone_dataset_head, zone_dataset); -static struct prison_service *zone_prison_service = NULL; +static int zone_slot; int zone_dataset_attach(struct ucred *cred, const char *dataset, int jailid) @@ -60,7 +61,7 @@ zone_dataset_attach(struct ucred *cred, const char *dataset, int jailid) struct zone_dataset_head *head; zone_dataset_t *zd, *zd2; struct prison *pr; - int error; + int dofree, error; if ((error = priv_check_cred(cred, PRIV_ZFS_JAIL, 0)) != 0) return (error); @@ -76,18 +77,33 @@ zone_dataset_attach(struct ucred *cred, const char *dataset, int jailid) return (ENOENT); } - head = prison_service_data_get(zone_prison_service, pr); - LIST_FOREACH(zd2, head, zd_next) { - if (strcmp(dataset, zd2->zd_dataset) == 0) { - free(zd, M_ZONES); - error = EEXIST; - goto failure; + head = osd_jail_get(pr, zone_slot); + if (head != NULL) { + dofree = 0; + LIST_FOREACH(zd2, head, zd_next) { + if (strcmp(dataset, zd2->zd_dataset) == 0) { + free(zd, M_ZONES); + error = EEXIST; + goto end; + } } + } else { + dofree = 1; + prison_hold_locked(pr); + mtx_unlock(&pr->pr_mtx); + head = malloc(sizeof(*head), M_ZONES, M_WAITOK); + LIST_INIT(head); + mtx_lock(&pr->pr_mtx); + error = osd_jail_set(pr, zone_slot, head); + KASSERT(error == 0, ("osd_jail_set() failed (error=%d)", error)); } strcpy(zd->zd_dataset, dataset); LIST_INSERT_HEAD(head, zd, zd_next); -failure: - mtx_unlock(&pr->pr_mtx); +end: + if (dofree) + prison_free_locked(pr); + else + mtx_unlock(&pr->pr_mtx); return (error); } @@ -107,16 +123,25 @@ zone_dataset_detach(struct ucred *cred, const char *dataset, int jailid) sx_sunlock(&allprison_lock); if (pr == NULL) return (ENOENT); - head = prison_service_data_get(zone_prison_service, pr); + head = osd_jail_get(pr, zone_slot); + if (head == NULL) { + error = ENOENT; + goto end; + } LIST_FOREACH(zd, head, zd_next) { - if (strcmp(dataset, zd->zd_dataset) == 0) { - LIST_REMOVE(zd, zd_next); - free(zd, M_ZONES); - goto success; - } + if (strcmp(dataset, zd->zd_dataset) == 0) + break; } - error = ENOENT; -success: + if (zd == NULL) + error = ENOENT; + else { + LIST_REMOVE(zd, zd_next); + free(zd, M_ZONES); + if (LIST_EMPTY(head)) + osd_jail_del(pr, zone_slot); + error = 0; + } +end: mtx_unlock(&pr->pr_mtx); return (error); } @@ -136,14 +161,16 @@ zone_dataset_visible(const char *dataset, int *write) if (dataset[0] == '\0') return (0); - if (INGLOBALZONE(curproc)) { + if (INGLOBALZONE(curthread)) { if (write != NULL) *write = 1; return (1); } pr = curthread->td_ucred->cr_prison; mtx_lock(&pr->pr_mtx); - head = prison_service_data_get(zone_prison_service, pr); + head = osd_jail_get(pr, zone_slot); + if (head == NULL) + goto end; /* * Walk the list once, looking for datasets which match exactly, or @@ -188,49 +215,32 @@ end: return (ret); } -static int -zone_create(struct prison_service *psrv, struct prison *pr) -{ - struct zone_dataset_head *head; - - head = malloc(sizeof(*head), M_ZONES, M_WAITOK); - LIST_INIT(head); - mtx_lock(&pr->pr_mtx); - prison_service_data_set(psrv, pr, head); - mtx_unlock(&pr->pr_mtx); - return (0); -} - -static int -zone_destroy(struct prison_service *psrv, struct prison *pr) +static void +zone_destroy(void *arg) { struct zone_dataset_head *head; zone_dataset_t *zd; - mtx_lock(&pr->pr_mtx); - head = prison_service_data_del(psrv, pr); - mtx_unlock(&pr->pr_mtx); - while ((zd = LIST_FIRST(head)) != NULL) { - LIST_REMOVE(zd, zd_next); - free(zd, M_ZONES); - } - free(head, M_ZONES); - return (0); + head = arg; + while ((zd = LIST_FIRST(head)) != NULL) { + LIST_REMOVE(zd, zd_next); + free(zd, M_ZONES); + } + free(head, M_ZONES); } static void zone_sysinit(void *arg __unused) { - zone_prison_service = prison_service_register("zfs", zone_create, - zone_destroy); + zone_slot = osd_jail_register(zone_destroy); } static void zone_sysuninit(void *arg __unused) { - prison_service_deregister(zone_prison_service); + osd_jail_deregister(zone_slot); } SYSINIT(zone_sysinit, SI_SUB_DRIVERS, SI_ORDER_ANY, zone_sysinit, NULL); diff --git a/sys/cddl/compat/opensolaris/sys/acl.h b/sys/cddl/compat/opensolaris/sys/acl.h deleted file mode 100644 index a7c9566..0000000 --- a/sys/cddl/compat/opensolaris/sys/acl.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - * - * $FreeBSD$ - */ -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _OPENSOLARIS_SYS_ACL_H_ -#define _OPENSOLARIS_SYS_ACL_H_ - -#include_next <sys/acl.h> - -#define MAX_ACL_ENTRIES (1024) /* max entries of each type */ - -typedef struct acl_entry aclent_t; -#define a_type ae_tag -#define a_id ae_id -#define a_perm ae_perm - -typedef struct ace { - uid_t a_who; /* uid or gid */ - uint32_t a_access_mask; /* read,write,... */ - uint16_t a_flags; /* see below */ - uint16_t a_type; /* allow or deny */ -} ace_t; - -#if 0 -/* - * The following are Defined types for an aclent_t. - */ -#define USER_OBJ (0x01) /* object owner */ -#define USER (0x02) /* additional users */ -#define GROUP_OBJ (0x04) /* owning group of the object */ -#define GROUP (0x08) /* additional groups */ -#define CLASS_OBJ (0x10) /* file group class and mask entry */ -#define OTHER_OBJ (0x20) /* other entry for the object */ -#define ACL_DEFAULT (0x1000) /* default flag */ -/* default object owner */ -#define DEF_USER_OBJ (ACL_DEFAULT | USER_OBJ) -/* defalut additional users */ -#define DEF_USER (ACL_DEFAULT | USER) -/* default owning group */ -#define DEF_GROUP_OBJ (ACL_DEFAULT | GROUP_OBJ) -/* default additional groups */ -#define DEF_GROUP (ACL_DEFAULT | GROUP) -/* default mask entry */ -#define DEF_CLASS_OBJ (ACL_DEFAULT | CLASS_OBJ) -/* default other entry */ -#define DEF_OTHER_OBJ (ACL_DEFAULT | OTHER_OBJ) -#endif - -/* - * The following are defined for ace_t. - */ -#define ACE_READ_DATA 0x00000001 -#define ACE_LIST_DIRECTORY 0x00000001 -#define ACE_WRITE_DATA 0x00000002 -#define ACE_ADD_FILE 0x00000002 -#define ACE_APPEND_DATA 0x00000004 -#define ACE_ADD_SUBDIRECTORY 0x00000004 -#define ACE_READ_NAMED_ATTRS 0x00000008 -#define ACE_WRITE_NAMED_ATTRS 0x00000010 -#define ACE_EXECUTE 0x00000020 -#define ACE_DELETE_CHILD 0x00000040 -#define ACE_READ_ATTRIBUTES 0x00000080 -#define ACE_WRITE_ATTRIBUTES 0x00000100 -#define ACE_DELETE 0x00010000 -#define ACE_READ_ACL 0x00020000 -#define ACE_WRITE_ACL 0x00040000 -#define ACE_WRITE_OWNER 0x00080000 -#define ACE_SYNCHRONIZE 0x00100000 - -#define ACE_FILE_INHERIT_ACE 0x0001 -#define ACE_DIRECTORY_INHERIT_ACE 0x0002 -#define ACE_NO_PROPAGATE_INHERIT_ACE 0x0004 -#define ACE_INHERIT_ONLY_ACE 0x0008 -#define ACE_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010 -#define ACE_FAILED_ACCESS_ACE_FLAG 0x0020 -#define ACE_IDENTIFIER_GROUP 0x0040 -#define ACE_OWNER 0x1000 -#define ACE_GROUP 0x2000 -#define ACE_EVERYONE 0x4000 - -#define ACE_ACCESS_ALLOWED_ACE_TYPE 0x0000 -#define ACE_ACCESS_DENIED_ACE_TYPE 0x0001 -#define ACE_SYSTEM_AUDIT_ACE_TYPE 0x0002 -#define ACE_SYSTEM_ALARM_ACE_TYPE 0x0003 - -#define ACE_ALL_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \ - ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \ - ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \ - ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \ - ACE_WRITE_OWNER|ACE_SYNCHRONIZE) - -/* - * The following flags are supported by both NFSv4 ACLs and ace_t. - */ -#define ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \ - ACE_DIRECTORY_INHERIT_ACE | \ - ACE_NO_PROPAGATE_INHERIT_ACE | \ - ACE_INHERIT_ONLY_ACE | \ - ACE_IDENTIFIER_GROUP) - -#define ACE_TYPE_FLAGS (ACE_OWNER|ACE_GROUP|ACE_EVERYONE|ACE_IDENTIFIER_GROUP) - -#if 0 -/* cmd args to acl(2) for aclent_t */ -#define GETACL 1 -#define SETACL 2 -#define GETACLCNT 3 -#endif - -/* cmd's to manipulate ace acls. */ -#define ACE_GETACL 4 -#define ACE_SETACL 5 -#define ACE_GETACLCNT 6 - -#if 0 -/* minimal acl entries from GETACLCNT */ -#define MIN_ACL_ENTRIES 4 - -#if !defined(_KERNEL) - -/* acl check errors */ -#define GRP_ERROR 1 -#define USER_ERROR 2 -#define OTHER_ERROR 3 -#define CLASS_ERROR 4 -#define DUPLICATE_ERROR 5 -#define MISS_ERROR 6 -#define MEM_ERROR 7 -#define ENTRY_ERROR 8 - - -/* - * similar to ufs_acl.h: changed to char type for user commands (tar, cpio) - * Attribute types - */ -#define UFSD_FREE ('0') /* Free entry */ -#define UFSD_ACL ('1') /* Access Control Lists */ -#define UFSD_DFACL ('2') /* reserved for future use */ -#define ACE_ACL ('3') /* ace_t style acls */ - -/* - * flag to [f]acl_get() - * controls whether a trivial acl should be returned. - */ -#define ACL_NO_TRIVIAL 0x2 - - -/* - * Flags to control acl_totext() - */ - -#define ACL_APPEND_ID 0x1 /* append uid/gid to user/group entries */ -#define ACL_COMPACT_FMT 0x2 /* build ACL in ls -V format */ -#define ACL_NORESOLVE 0x4 /* don't do name service lookups */ - -/* - * Legacy aclcheck errors for aclent_t ACLs - */ -#define EACL_GRP_ERROR GRP_ERROR -#define EACL_USER_ERROR USER_ERROR -#define EACL_OTHER_ERROR OTHER_ERROR -#define EACL_CLASS_ERROR CLASS_ERROR -#define EACL_DUPLICATE_ERROR DUPLICATE_ERROR -#define EACL_MISS_ERROR MISS_ERROR -#define EACL_MEM_ERROR MEM_ERROR -#define EACL_ENTRY_ERROR ENTRY_ERROR - -#define EACL_INHERIT_ERROR 9 /* invalid inherit flags */ -#define EACL_FLAGS_ERROR 10 /* unknown flag value */ -#define EACL_PERM_MASK_ERROR 11 /* unknown permission */ -#define EACL_COUNT_ERROR 12 /* invalid acl count */ - -#define EACL_INVALID_SLOT 13 /* invalid acl slot */ -#define EACL_NO_ACL_ENTRY 14 /* Entry doesn't exist */ -#define EACL_DIFF_TYPE 15 /* acls aren't same type */ - -#define EACL_INVALID_USER_GROUP 16 /* need user/group name */ -#define EACL_INVALID_STR 17 /* invalid acl string */ -#define EACL_FIELD_NOT_BLANK 18 /* can't have blank field */ -#define EACL_INVALID_ACCESS_TYPE 19 /* invalid access type */ -#define EACL_UNKNOWN_DATA 20 /* Unrecognized data in ACL */ -#define EACL_MISSING_FIELDS 21 /* missing fields in acl */ - -#define EACL_INHERIT_NOTDIR 22 /* Need dir for inheritance */ - -extern int aclcheck(aclent_t *, int, int *); -extern int acltomode(aclent_t *, int, mode_t *); -extern int aclfrommode(aclent_t *, int, mode_t *); -extern int aclsort(int, int, aclent_t *); -extern char *acltotext(aclent_t *, int); -extern aclent_t *aclfromtext(char *, int *); -extern void acl_free(acl_t *); -extern int acl_get(const char *, int, acl_t **); -extern int facl_get(int, int, acl_t **); -extern int acl_set(const char *, acl_t *acl); -extern int facl_set(int, acl_t *acl); -extern int acl_strip(const char *, uid_t, gid_t, mode_t); -extern int acl_trivial(const char *); -extern char *acl_totext(acl_t *, int); -extern int acl_fromtext(const char *, acl_t **); -extern int acl_check(acl_t *, int); - -#else /* !defined(_KERNEL) */ - -extern void ksort(caddr_t, int, int, int (*)(void *, void *)); -extern int cmp2acls(void *, void *); - -#endif /* !defined(_KERNEL) */ - -#if defined(__STDC__) -extern int acl(const char *path, int cmd, int cnt, void *buf); -extern int facl(int fd, int cmd, int cnt, void *buf); -#else /* !__STDC__ */ -extern int acl(); -extern int facl(); -#endif /* defined(__STDC__) */ - -#endif - -#endif /* _OPENSOLARIS_SYS_ACL_H */ diff --git a/sys/cddl/compat/opensolaris/sys/atomic.h b/sys/cddl/compat/opensolaris/sys/atomic.h index 46752a5..1a8bd45 100644 --- a/sys/cddl/compat/opensolaris/sys/atomic.h +++ b/sys/cddl/compat/opensolaris/sys/atomic.h @@ -38,6 +38,7 @@ #ifndef __LP64__ extern void atomic_add_64(volatile uint64_t *target, int64_t delta); +extern void atomic_dec_64(volatile uint64_t *target); extern void *atomic_cas_ptr(volatile void *target, void *cmp, void *newval); #endif #ifndef __sparc64__ @@ -83,6 +84,14 @@ atomic_dec_32_nv(volatile uint32_t *target) return (atomic_fetchadd_32(target, -1) - 1); } +#ifdef __LP64__ +static __inline void +atomic_dec_64(volatile uint64_t *target) +{ + atomic_subtract_64(target, 1); +} +#endif + static __inline void atomic_inc_32(volatile uint32_t *target) { diff --git a/sys/cddl/compat/opensolaris/sys/callb.h b/sys/cddl/compat/opensolaris/sys/callb.h deleted file mode 100644 index 070d0f9..0000000 --- a/sys/cddl/compat/opensolaris/sys/callb.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - * - * $FreeBSD$ - */ -/* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _SYS_CALLB_H -#define _SYS_CALLB_H - -#pragma ident "@(#)callb.h 1.29 05/06/23 SMI" - -#include <sys/kcondvar.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * definitions of callback classes (c_class) - * - * Callbacks belong in the same class if (1) their callback routines - * do the same kind of processing (ideally, using the same callback function) - * and (2) they can/should be executed at the same time in a cpr - * suspend/resume operation. - * - * Note: The DAEMON class, in particular, is for stopping kernel threads - * and nothing else. The CALLB_* macros below should be used to deal - * with kernel threads, and the callback function should be callb_generic_cpr. - * Another idiosyncrasy of the DAEMON class is that if a suspend operation - * fails, some of the callback functions may be called with the RESUME - * code which were never called with SUSPEND. Not a problem currently, - * but see bug 4201851. - */ -#define CB_CL_CPR_DAEMON 0 -#define CB_CL_CPR_VM 1 -#define CB_CL_CPR_CALLOUT 2 -#define CB_CL_CPR_OBP 3 -#define CB_CL_CPR_FB 4 -#define CB_CL_PANIC 5 -#define CB_CL_CPR_RPC 6 -#define CB_CL_CPR_PROMPRINTF 7 -#define CB_CL_UADMIN 8 -#define CB_CL_CPR_PM 9 -#define CB_CL_HALT 10 -#define CB_CL_CPR_DMA 11 -#define CB_CL_CPR_POST_USER 12 -#define CB_CL_UADMIN_PRE_VFS 13 -#define CB_CL_MDBOOT CB_CL_UADMIN -#define CB_CL_ENTER_DEBUGGER 14 -#define CB_CL_CPR_POST_KERNEL 15 -#define NCBCLASS 16 /* CHANGE ME if classes are added/removed */ - -/* - * CB_CL_CPR_DAEMON class specific definitions are given below: - */ - -/* - * code for CPR callb_execute_class - */ -#define CB_CODE_CPR_CHKPT 0 -#define CB_CODE_CPR_RESUME 1 - -typedef void * callb_id_t; -/* - * Per kernel thread structure for CPR daemon callbacks. - * Must be protected by either a existing lock in the daemon or - * a new lock created for such a purpose. - */ -typedef struct callb_cpr { - kmutex_t *cc_lockp; /* lock to protect this struct */ - char cc_events; /* various events for CPR */ - callb_id_t cc_id; /* callb id address */ - kcondvar_t cc_callb_cv; /* cv for callback waiting */ - kcondvar_t cc_stop_cv; /* cv to checkpoint block */ -} callb_cpr_t; - -/* - * cc_events definitions - */ -#define CALLB_CPR_START 1 /* a checkpoint request's started */ -#define CALLB_CPR_SAFE 2 /* thread is safe for CPR */ -#define CALLB_CPR_ALWAYS_SAFE 4 /* thread is ALWAYS safe for CPR */ - -/* - * Used when checking that all kernel threads are stopped. - */ -#define CALLB_MAX_RETRY 3 /* when waiting for kthread to sleep */ -#define CALLB_THREAD_DELAY 10 /* ticks allowed to reach sleep */ -#define CPR_KTHREAD_TIMEOUT_SEC 90 /* secs before callback times out -- */ - /* due to pwr mgmt of disks, make -- */ - /* big enough for worst spinup time */ - -#ifdef _KERNEL -/* - * - * CALLB_CPR_INIT macro is used by kernel threads to add their entry to - * the callback table and perform other initialization. It automatically - * adds the thread as being in the callback class CB_CL_CPR_DAEMON. - * - * cp - ptr to the callb_cpr_t structure for this kernel thread - * - * lockp - pointer to mutex protecting the callb_cpr_t stuct - * - * func - pointer to the callback function for this kernel thread. - * It has the prototype boolean_t <func>(void *arg, int code) - * where: arg - ptr to the callb_cpr_t structure - * code - not used for this type of callback - * returns: B_TRUE if successful; B_FALSE if unsuccessful. - * - * name - a string giving the name of the kernel thread - * - * Note: lockp is the lock to protect the callb_cpr_t (cp) structure - * later on. No lock held is needed for this initialization. - */ -#define CALLB_CPR_INIT(cp, lockp, func, name) { \ - strlcpy(curthread->td_name, (name), \ - sizeof(curthread->td_name)); \ - strlcpy(curthread->td_proc->p_comm, (name), \ - sizeof(curthread->td_proc->p_comm)); \ - bzero((caddr_t)(cp), sizeof (callb_cpr_t)); \ - (cp)->cc_lockp = lockp; \ - (cp)->cc_id = callb_add(func, (void *)(cp), \ - CB_CL_CPR_DAEMON, name); \ - } - -#ifndef __lock_lint -#define CALLB_CPR_ASSERT(cp) ASSERT(MUTEX_HELD((cp)->cc_lockp)); -#else -#define CALLB_CPR_ASSERT(cp) -#endif -/* - * Some threads (like the idle threads) do not adhere to the callback - * protocol and are always considered safe. Such threads must never exit. - * They register their presence by calling this macro during their - * initialization. - * - * Args: - * t - thread pointer of the client kernel thread - * name - a string giving the name of the kernel thread - */ -#define CALLB_CPR_INIT_SAFE(t, name) { \ - (void) callb_add_thread(callb_generic_cpr_safe, \ - (void *) &callb_cprinfo_safe, CB_CL_CPR_DAEMON, \ - name, t); \ - } -/* - * The lock to protect cp's content must be held before - * calling the following two macros. - * - * Any code region between CALLB_CPR_SAFE_BEGIN and CALLB_CPR_SAFE_END - * is safe for checkpoint/resume. - */ -#define CALLB_CPR_SAFE_BEGIN(cp) { \ - CALLB_CPR_ASSERT(cp) \ - (cp)->cc_events |= CALLB_CPR_SAFE; \ - if ((cp)->cc_events & CALLB_CPR_START) \ - cv_signal(&(cp)->cc_callb_cv); \ - } -#define CALLB_CPR_SAFE_END(cp, lockp) { \ - CALLB_CPR_ASSERT(cp) \ - while ((cp)->cc_events & CALLB_CPR_START) \ - cv_wait(&(cp)->cc_stop_cv, lockp); \ - (cp)->cc_events &= ~CALLB_CPR_SAFE; \ - } -/* - * cv_destroy is nop right now but may be needed in the future. - */ -#define CALLB_CPR_EXIT(cp) { \ - CALLB_CPR_ASSERT(cp) \ - (cp)->cc_events |= CALLB_CPR_SAFE; \ - if ((cp)->cc_events & CALLB_CPR_START) \ - cv_signal(&(cp)->cc_callb_cv); \ - mutex_exit((cp)->cc_lockp); \ - (void) callb_delete((cp)->cc_id); \ - cv_destroy(&(cp)->cc_callb_cv); \ - cv_destroy(&(cp)->cc_stop_cv); \ - } - -extern callb_cpr_t callb_cprinfo_safe; -extern callb_id_t callb_add(boolean_t (*)(void *, int), void *, int, char *); -extern callb_id_t callb_add_thread(boolean_t (*)(void *, int), - void *, int, char *, kthread_id_t); -extern int callb_delete(callb_id_t); -extern void callb_execute(callb_id_t, int); -extern void *callb_execute_class(int, int); -extern boolean_t callb_generic_cpr(void *, int); -extern boolean_t callb_generic_cpr_safe(void *, int); -extern boolean_t callb_is_stopped(kthread_id_t, caddr_t *); -extern void callb_lock_table(void); -extern void callb_unlock_table(void); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_CALLB_H */ diff --git a/sys/cddl/compat/opensolaris/sys/cred.h b/sys/cddl/compat/opensolaris/sys/cred.h index 85e79db..b13ef6c 100644 --- a/sys/cddl/compat/opensolaris/sys/cred.h +++ b/sys/cddl/compat/opensolaris/sys/cred.h @@ -30,12 +30,14 @@ #define _OPENSOLARIS_SYS_CRED_H_ #include <sys/param.h> -#include_next <sys/ucred.h> - -#ifdef _KERNEL +#define _WANT_UCRED +#include <sys/ucred.h> +#undef _WANT_UCRED typedef struct ucred cred_t; +typedef struct ucred ucred_t; +#ifdef _KERNEL #define CRED() (curthread->td_ucred) /* @@ -43,9 +45,14 @@ typedef struct ucred cred_t; */ #define kcred (thread0.td_ucred) -#define crgetuid(cred) ((cred)->cr_uid) -#define crgetgid(cred) ((cred)->cr_gid) - -#endif /* _KERNEL */ +#define crgetuid(cred) ((cred)->cr_uid) +#define crgetgid(cred) ((cred)->cr_gid) +#define crgetgroups(cred) ((cred)->cr_groups) +#define crgetngroups(cred) ((cred)->cr_ngroups) +#define crgetsid(cred, i) (NULL) +#else /* !_KERNEL */ +#define kcred NULL +#define CRED() NULL +#endif /* !_KERNEL */ #endif /* _OPENSOLARIS_SYS_CRED_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/dnlc.h b/sys/cddl/compat/opensolaris/sys/dnlc.h index a2d4f01..e978e975 100644 --- a/sys/cddl/compat/opensolaris/sys/dnlc.h +++ b/sys/cddl/compat/opensolaris/sys/dnlc.h @@ -35,6 +35,6 @@ #define dnlc_update(dvp, name, vp) do { } while (0) #define dnlc_remove(dvp, name) do { } while (0) #define dnlc_purge_vfsp(vfsp, count) (0) -#define dnlc_reduce_cache(percent) do { } while (0) +#define dnlc_reduce_cache(percent) EVENTHANDLER_INVOKE(vfs_lowvnodes, (int)(intptr_t)(percent)) #endif /* !_OPENSOLARIS_SYS_DNLC_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/file.h b/sys/cddl/compat/opensolaris/sys/file.h new file mode 100644 index 0000000..afd1050 --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/file.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_FILE_H_ +#define _OPENSOLARIS_SYS_FILE_H_ + +#include_next <sys/file.h> + +#ifdef _KERNEL +typedef struct file file_t; + +static __inline file_t * +getf(int fd, int write) +{ + struct file *fp; + + if (write && fget_write(curthread, fd, &fp) == 0) + return (fp); + else if (!write && fget_read(curthread, fd, &fp) == 0) + return (fp); + return (NULL); +} + +static __inline void +releasef(file_t *fp) +{ + + fdrop(fp, curthread); +} +#endif /* _KERNEL */ + +#endif /* !_OPENSOLARIS_SYS_FILE_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/kidmap.h b/sys/cddl/compat/opensolaris/sys/kidmap.h new file mode 100644 index 0000000..c2a33d2 --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/kidmap.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_KIDMAP_H_ +#define _OPENSOLARIS_SYS_KIDMAP_H_ + +#include <sys/idmap.h> + +typedef int32_t idmap_stat; +typedef void idmap_get_handle_t; + +#define kidmap_get_create() (NULL) +#define kidmap_get_destroy(hdl) do { } while (0) +#define kidmap_get_mappings(hdl) (NULL) + +#endif /* _OPENSOLARIS_SYS_KIDMAP_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/kmem.h b/sys/cddl/compat/opensolaris/sys/kmem.h index 5258cff..c103d18 100644 --- a/sys/cddl/compat/opensolaris/sys/kmem.h +++ b/sys/cddl/compat/opensolaris/sys/kmem.h @@ -38,15 +38,16 @@ #include <vm/vm_extern.h> #define KM_SLEEP M_WAITOK +#define KM_PUSHPAGE M_WAITOK #define KM_NOSLEEP M_NOWAIT #define KMC_NODEBUG 0 typedef struct kmem_cache { char kc_name[32]; -#ifdef _KERNEL +#if defined(_KERNEL) && !defined(KMEM_DEBUG) uma_zone_t kc_zone; #else - size_t size; + size_t kc_size; #endif int (*kc_constructor)(void *, void *, int); void (*kc_destructor)(void *, void *); diff --git a/sys/cddl/compat/opensolaris/sys/misc.h b/sys/cddl/compat/opensolaris/sys/misc.h index a5a52b7..8e1a637 100644 --- a/sys/cddl/compat/opensolaris/sys/misc.h +++ b/sys/cddl/compat/opensolaris/sys/misc.h @@ -29,6 +29,13 @@ #ifndef _OPENSOLARIS_SYS_MISC_H_ #define _OPENSOLARIS_SYS_MISC_H_ +#define MAXUID 2147483647 + +#define SPEC_MAXOFFSET_T OFF_MAX + +#define _ACL_ACLENT_ENABLED 0x1 +#define _ACL_ACE_ENABLED 0x2 + #define _FIOFFS (INT_MIN) #define _FIOGDIO (INT_MIN+1) #define _FIOSDIO (INT_MIN+2) diff --git a/sys/cddl/compat/opensolaris/sys/mntent.h b/sys/cddl/compat/opensolaris/sys/mntent.h index e4bbc9d..3faea6b 100644 --- a/sys/cddl/compat/opensolaris/sys/mntent.h +++ b/sys/cddl/compat/opensolaris/sys/mntent.h @@ -54,5 +54,7 @@ #define MNTOPT_EXEC "exec" /* enable executables */ #define MNTOPT_NOEXEC "noexec" /* disable executables */ #define MNTOPT_RESTRICT "restrict" /* restricted autofs mount */ +#define MNTOPT_NBMAND "nbmand" /* allow non-blocking mandatory locks */ +#define MNTOPT_NONBMAND "nonbmand" /* deny non-blocking mandatory locks */ #endif /* !_OPENSOLARIS_MNTENT_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/param.h b/sys/cddl/compat/opensolaris/sys/param.h index 8d36a9d..609d22a 100644 --- a/sys/cddl/compat/opensolaris/sys/param.h +++ b/sys/cddl/compat/opensolaris/sys/param.h @@ -34,4 +34,8 @@ #define PAGESIZE PAGE_SIZE +#ifdef _KERNEL +#define ptob(x) ((uint64_t)(x) << PAGE_SHIFT) +#endif + #endif diff --git a/sys/cddl/compat/opensolaris/sys/pathname.h b/sys/cddl/compat/opensolaris/sys/pathname.h new file mode 100644 index 0000000..0d39623 --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/pathname.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_PATHNAME_H_ +#define _OPENSOLARIS_SYS_PATHNAME_H_ + +#ifdef _KERNEL + +#include <sys/param.h> +#include <sys/vnode.h> + +typedef struct pathname { + char *pn_buf; /* underlying storage */ + char *pn_path; /* remaining pathname */ + size_t pn_pathlen; /* remaining length */ + size_t pn_bufsize; /* total size of pn_buf */ +} pathname_t; + +#define pn_alloc(pnp) panic("pn_alloc() called") +#define pn_free(pnp) panic("pn_free() called") + +int lookupname(char *, enum uio_seg, enum symfollow, vnode_t **, vnode_t **); +int lookupnameat(char *, enum uio_seg, enum symfollow, vnode_t **, vnode_t **, + vnode_t *); +int traverse(vnode_t **, int); + +#endif /* _KERNEL */ + +#endif /* _OPENSOLARIS_SYS_PATHNAME_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/policy.h b/sys/cddl/compat/opensolaris/sys/policy.h index 2c764ef..08db5ca 100644 --- a/sys/cddl/compat/opensolaris/sys/policy.h +++ b/sys/cddl/compat/opensolaris/sys/policy.h @@ -33,30 +33,44 @@ #ifdef _KERNEL +#include <sys/vnode.h> + struct mount; struct ucred; struct vattr; struct vnode; -int secpolicy_zfs(struct ucred *cred); -int secpolicy_sys_config(struct ucred *cred, int checkonly); -int secpolicy_zinject(struct ucred *cred); -int secpolicy_fs_unmount(struct ucred *cred, struct mount *vfsp); -int secpolicy_basic_link(struct ucred *cred); +int secpolicy_nfs(struct ucred *cred); +int secpolicy_zfs(struct ucred *cred); +int secpolicy_sys_config(struct ucred *cred, int checkonly); +int secpolicy_zinject(struct ucred *cred); +int secpolicy_fs_unmount(struct ucred *cred, struct mount *vfsp); +int secpolicy_basic_link(struct vnode *vp, struct ucred *cred); +int secpolicy_vnode_owner(struct vnode *vp, cred_t *cred, uid_t owner); +int secpolicy_vnode_chown(struct vnode *vp, cred_t *cred, + boolean_t check_self); int secpolicy_vnode_stky_modify(struct ucred *cred); -int secpolicy_vnode_remove(struct ucred *cred); +int secpolicy_vnode_remove(struct vnode *vp, struct ucred *cred); int secpolicy_vnode_access(struct ucred *cred, struct vnode *vp, uint64_t owner, accmode_t accmode); -int secpolicy_vnode_setdac(struct ucred *cred, uid_t owner); +int secpolicy_vnode_setdac(struct vnode *vp, struct ucred *cred, + uid_t owner); int secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, const struct vattr *ovap, int flags, int unlocked_access(void *, int, struct ucred *), void *node); int secpolicy_vnode_create_gid(struct ucred *cred); -int secpolicy_vnode_setids_setgids(struct ucred *cred, gid_t gid); -int secpolicy_vnode_setid_retain(struct ucred *cred, boolean_t issuidroot); -void secpolicy_setid_clear(struct vattr *vap, struct ucred *cred); +int secpolicy_vnode_setids_setgids(struct vnode *vp, struct ucred *cred, + gid_t gid); +int secpolicy_vnode_setid_retain(struct vnode *vp, struct ucred *cred, + boolean_t issuidroot); +void secpolicy_setid_clear(struct vattr *vap, struct vnode *vp, + struct ucred *cred); int secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap, const struct vattr *ovap, struct ucred *cred); +int secpolicy_fs_owner(struct mount *vfsp, struct ucred *cred); +int secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct mount *vfsp); +void secpolicy_fs_mount_clearopts(cred_t *cr, struct mount *vfsp); +int secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype); #endif /* _KERNEL */ diff --git a/sys/cddl/compat/opensolaris/sys/proc.h b/sys/cddl/compat/opensolaris/sys/proc.h index 2410396..73fbcda 100644 --- a/sys/cddl/compat/opensolaris/sys/proc.h +++ b/sys/cddl/compat/opensolaris/sys/proc.h @@ -54,12 +54,6 @@ typedef struct thread kthread_t; typedef struct thread *kthread_id_t; typedef struct proc proc_t; -#if (KSTACK_PAGES * PAGE_SIZE) < 16384 -#define ZFS_KSTACK_PAGES (16384 / PAGE_SIZE) -#else -#define ZFS_KSTACK_PAGES 0 -#endif - 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) @@ -71,11 +65,10 @@ thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg, * Be sure there are no surprises. */ ASSERT(stk == NULL); - ASSERT(stksize == 0); ASSERT(len == 0); ASSERT(state == TS_RUN); - error = kproc_create(proc, arg, &p, 0, ZFS_KSTACK_PAGES, + error = kproc_create(proc, arg, &p, 0, stksize / PAGE_SIZE, "solthread %p", proc); return (error == 0 ? FIRST_THREAD_IN_PROC(p) : NULL); } diff --git a/sys/cddl/compat/opensolaris/sys/refstr.h b/sys/cddl/compat/opensolaris/sys/refstr.h new file mode 100644 index 0000000..e4e177b --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/refstr.h @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + $ $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_REFSTR_H_ +#define _OPENSOLARIS_SYS_REFSTR_H_ + +#define refstr_value(str) (str) + +#endif /* _OPENSOLARIS_SYS_REFSTR_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sid.h b/sys/cddl/compat/opensolaris/sys/sid.h new file mode 100644 index 0000000..eb8d0be --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/sid.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_SID_H_ +#define _OPENSOLARIS_SYS_SID_H_ + +typedef struct ksiddomain { + char kd_name[16]; /* Domain part of SID */ +} ksiddomain_t; +typedef void ksid_t; + +static __inline ksiddomain_t * +ksid_lookupdomain(const char *domain) +{ + ksiddomain_t *kd; + + kd = kmem_alloc(sizeof(*kd), KM_SLEEP); + strlcpy(kd->kd_name, "FreeBSD", sizeof(kd->kd_name)); + return (kd); +} + +static __inline void +ksiddomain_rele(ksiddomain_t *kd) +{ + + kmem_free(kd, sizeof(*kd)); +} + +#endif /* _OPENSOLARIS_SYS_SID_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sig.h b/sys/cddl/compat/opensolaris/sys/sig.h new file mode 100644 index 0000000..985896e --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/sig.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2008 Pawel Jakub Dawidek <pjd@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + +#ifndef _OPENSOLARIS_SYS_SIG_H_ +#define _OPENSOLARIS_SYS_SIG_H_ + +#ifdef _KERNEL + +#include <sys/param.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/proc.h> +#include <sys/signalvar.h> +#include <sys/debug.h> + +#define FORREAL 0 +#define JUSTLOOKING 1 + +static __inline int +issig(int why) +{ + struct thread *td = curthread; + struct proc *p; + int sig; + + ASSERT(why == FORREAL || why == JUSTLOOKING); + if (SIGPENDING(td)) { + if (why == JUSTLOOKING) + return (1); + p = td->td_proc; + PROC_LOCK(p); + mtx_lock(&p->p_sigacts->ps_mtx); + sig = cursig(td); + mtx_unlock(&p->p_sigacts->ps_mtx); + PROC_UNLOCK(p); + if (sig != 0) + return (1); + } + return (0); +} + +#endif /* _KERNEL */ + +#endif /* _OPENSOLARIS_SYS_SIG_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sunddi.h b/sys/cddl/compat/opensolaris/sys/sunddi.h index 192d5a9..1ca2bf0 100644 --- a/sys/cddl/compat/opensolaris/sys/sunddi.h +++ b/sys/cddl/compat/opensolaris/sys/sunddi.h @@ -29,8 +29,10 @@ #ifndef _OPENSOLARIS_SYS_SUNDDI_H_ #define _OPENSOLARIS_SYS_SUNDDI_H_ +#define ddi_driver_major(zfs_dip) (0) #define ddi_copyin(from, to, size, flag) (bcopy((from), (to), (size)), 0) #define ddi_copyout(from, to, size, flag) (bcopy((from), (to), (size)), 0) +int ddi_strtol(const char *str, char **nptr, int base, long *result); int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result); #endif /* _OPENSOLARIS_SYS_SUNDDI_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sysmacros.h b/sys/cddl/compat/opensolaris/sys/sysmacros.h index a179c5f..7f4885b 100644 --- a/sys/cddl/compat/opensolaris/sys/sysmacros.h +++ b/sys/cddl/compat/opensolaris/sys/sysmacros.h @@ -39,6 +39,10 @@ extern "C" { #endif +#ifndef ABS +#define ABS(a) ((a) < 0 ? -(a) : (a)) +#endif + /* * Macro for checking power of 2 address alignment. */ diff --git a/sys/cddl/compat/opensolaris/sys/time.h b/sys/cddl/compat/opensolaris/sys/time.h index 770b251..0bf1e9b 100644 --- a/sys/cddl/compat/opensolaris/sys/time.h +++ b/sys/cddl/compat/opensolaris/sys/time.h @@ -40,6 +40,9 @@ typedef longlong_t hrtime_t; #define LBOLT ((gethrtime() * hz) / NANOSEC) +#define TIMESPEC_OVERFLOW(ts) \ + ((ts)->tv_sec < INT32_MIN || (ts)->tv_sec > INT32_MAX) + #ifdef _KERNEL #define lbolt64 (int64_t)(LBOLT) diff --git a/sys/cddl/compat/opensolaris/sys/types.h b/sys/cddl/compat/opensolaris/sys/types.h index 7d5d9e4..069ad45 100644 --- a/sys/cddl/compat/opensolaris/sys/types.h +++ b/sys/cddl/compat/opensolaris/sys/types.h @@ -44,13 +44,15 @@ typedef u_char uchar_t; typedef u_short ushort_t; typedef u_long ulong_t; typedef long long longlong_t; -typedef unsigned long long u_longlong_t; +typedef unsigned long long u_longlong_t; typedef off_t off64_t; typedef id_t taskid_t; typedef id_t projid_t; typedef id_t poolid_t; typedef id_t zoneid_t; typedef id_t ctid_t; +typedef mode_t o_mode_t; +typedef uint64_t pgcnt_t; #ifdef _KERNEL @@ -60,8 +62,8 @@ typedef id_t ctid_t; typedef short index_t; typedef off_t offset_t; typedef long ptrdiff_t; /* pointer difference */ -typedef void pathname_t; typedef int64_t rlim64_t; +typedef int major_t; #else #ifdef NEED_SOLARIS_BOOLEAN @@ -80,7 +82,6 @@ typedef short pri_t; typedef int32_t daddr32_t; typedef int32_t time32_t; typedef u_longlong_t diskaddr_t; -typedef ushort_t o_mode_t; /* old file attribute type */ #endif /* !_KERNEL */ diff --git a/sys/cddl/compat/opensolaris/sys/uio.h b/sys/cddl/compat/opensolaris/sys/uio.h index d219ff0..9e53457 100644 --- a/sys/cddl/compat/opensolaris/sys/uio.h +++ b/sys/cddl/compat/opensolaris/sys/uio.h @@ -60,6 +60,6 @@ zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio) return (uiomove(cp, (int)n, uio)); } #define uiomove(cp, n, dir, uio) zfs_uiomove((cp), (n), (dir), (uio)) -#endif +#endif /* BUILDING_ZFS */ #endif /* !_OPENSOLARIS_SYS_UIO_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/vfs.h b/sys/cddl/compat/opensolaris/sys/vfs.h index c2d8a6b..be3e3cf 100644 --- a/sys/cddl/compat/opensolaris/sys/vfs.h +++ b/sys/cddl/compat/opensolaris/sys/vfs.h @@ -45,6 +45,7 @@ typedef struct mount vfs_t; #define vfs_count mnt_ref #define vfs_fsid mnt_stat.f_fsid #define vfs_bsize mnt_stat.f_bsize +#define vfs_resource mnt_stat.f_mntfromname #define v_flag v_vflag #define v_vfsp v_mount @@ -64,6 +65,8 @@ typedef struct mount vfs_t; MNT_IUNLOCK(vfsp); \ } while (0) +#define fs_vscan(vp, cr, async) (0) + #define VROOT VV_ROOT /* @@ -107,10 +110,21 @@ 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 traverse(vnode_t **cvpp, int lktype); int domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath, char *fspec, int fsflags); +typedef uint64_t vfs_feature_t; + +#define VFSFT_XVATTR 0x100000001 /* Supports xvattr for attrs */ +#define VFSFT_CASEINSENSITIVE 0x100000002 /* Supports case-insensitive */ +#define VFSFT_NOCASESENSITIVE 0x100000004 /* NOT case-sensitive */ +#define VFSFT_DIRENTFLAGS 0x100000008 /* Supports dirent flags */ +#define VFSFT_ACLONCREATE 0x100000010 /* Supports ACL on create */ +#define VFSFT_ACEMASKONACCESS 0x100000020 /* Can use ACEMASK for access */ + +#define vfs_set_feature(vfsp, feature) do { } while (0) +#define vfs_has_feature(vfsp, feature) (0) + #endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_VFS_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/vnode.h b/sys/cddl/compat/opensolaris/sys/vnode.h index a8a261c..b490d33 100644 --- a/sys/cddl/compat/opensolaris/sys/vnode.h +++ b/sys/cddl/compat/opensolaris/sys/vnode.h @@ -29,24 +29,32 @@ #ifndef _OPENSOLARIS_SYS_VNODE_H_ #define _OPENSOLARIS_SYS_VNODE_H_ +struct vnode; +struct vattr; + +typedef struct vnode vnode_t; +typedef struct vattr vattr_t; +typedef enum vtype vtype_t; + +#include <sys/namei.h> +enum symfollow { NO_FOLLOW = NOFOLLOW }; + +#include <sys/proc.h> #include_next <sys/vnode.h> #include <sys/mount.h> #include <sys/cred.h> #include <sys/fcntl.h> -#include <sys/namei.h> -#include <sys/proc.h> +#include <sys/file.h> #include <sys/filedesc.h> #include <sys/syscallsubr.h> -typedef struct vnode vnode_t; -typedef struct vattr vattr_t; -typedef void caller_context_t; - typedef struct vop_vector vnodeops_t; #define vop_fid vop_vptofh #define vop_fid_args vop_vptofh_args #define a_fid a_fhp +#define IS_XATTRDIR(dvp) (0) + #define v_count v_usecount static __inline int @@ -59,23 +67,24 @@ vn_is_readonly(vnode_t *vp) #define vn_ismntpt(vp) ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL) #define vn_mountedvfs(vp) ((vp)->v_mountedhere) #define vn_has_cached_data(vp) ((vp)->v_object != NULL && (vp)->v_object->resident_page_count > 0) +#define vn_exists(vp) do { } while (0) +#define vn_invalid(vp) do { } while (0) +#define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0) +#define vn_free(vp) do { } while (0) #define VN_HOLD(v) vref(v) #define VN_RELE(v) vrele(v) #define VN_URELE(v) vput(v) -#define VOP_REALVP(vp, vpp) (*(vpp) = (vp), 0) - -#define vnevent_remove(vp) do { } while (0) -#define vnevent_rmdir(vp) do { } while (0) -#define vnevent_rename_src(vp) do { } while (0) -#define vnevent_rename_dest(vp) do { } while (0) - +#define VOP_REALVP(vp, vpp, ct) (*(vpp) = (vp), 0) -#define IS_DEVVP(vp) \ - ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO) - -#define MODEMASK ALLPERMS +#define vnevent_create(vp, ct) do { } while (0) +#define vnevent_link(vp, ct) do { } while (0) +#define vnevent_remove(vp, dvp, name, ct) do { } while (0) +#define vnevent_rmdir(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_src(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_dest(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_dest_dir(vp, ct) do { } while (0) #define specvp(vp, rdev, type, cr) (VN_HOLD(vp), (vp)) #define MANDMODE(mode) (0) @@ -98,24 +107,6 @@ vn_is_readonly(vnode_t *vp) #define MAXOFFSET_T OFF_MAX #define EXCL 0 -#define AT_TYPE 0x0001 -#define AT_MODE 0x0002 -#define AT_UID 0x0004 -#define AT_GID 0x0008 -#define AT_FSID 0x0010 -#define AT_NODEID 0x0020 -#define AT_NLINK 0x0040 -#define AT_SIZE 0x0080 -#define AT_ATIME 0x0100 -#define AT_MTIME 0x0200 -#define AT_CTIME 0x0400 -#define AT_RDEV 0x0800 -#define AT_BLKSIZE 0x1000 -#define AT_NBLOCKS 0x2000 -#define AT_SEQ 0x4000 -#define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\ - AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) - #define ACCESSED (AT_ATIME) #define STATE_CHANGED (AT_CTIME) #define CONTENT_MODIFIED (AT_MTIME | AT_CTIME) @@ -140,28 +131,37 @@ vattr_init_mask(vattr_t *vap) vap->va_mask |= AT_MTIME; if (vap->va_mode != (u_short)VNOVAL) vap->va_mask |= AT_MODE; + if (vap->va_flags != VNOVAL) + vap->va_mask |= AT_XVATTR; } -#define FCREAT O_CREAT -#define FTRUNC O_TRUNC -#define FDSYNC FFSYNC -#define FRSYNC FFSYNC -#define FSYNC FFSYNC -#define FOFFMAX 0x00 - -enum create { CRCREAT }; +#define FCREAT O_CREAT +#define FTRUNC O_TRUNC +#define FDSYNC FFSYNC +#define FRSYNC FFSYNC +#define FSYNC FFSYNC +#define FOFFMAX 0x00 +#define FIGNORECASE 0x00 static __inline int -zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, - vnode_t **vpp, enum create crwhy, mode_t umask) +vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode, + vnode_t **vpp, enum create crwhy, mode_t umask, struct vnode *startvp, + int fd) { struct thread *td = curthread; struct nameidata nd; - int error; + int error, operation; ASSERT(seg == UIO_SYSSPACE); - ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX)); - ASSERT(crwhy == CRCREAT); + if ((filemode & FCREAT) != 0) { + ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX)); + ASSERT(crwhy == CRCREAT); + operation = CREATE; + } else { + ASSERT(filemode == (FREAD | FWRITE | FOFFMAX)); + ASSERT(crwhy == 0); + operation = LOOKUP; + } ASSERT(umask == 0); if (td->td_proc->p_fd->fd_rdir == NULL) @@ -169,7 +169,10 @@ zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, if (td->td_proc->p_fd->fd_cdir == NULL) td->td_proc->p_fd->fd_cdir = rootvnode; - NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pnamep, td); + if (startvp != NULL) + vref(startvp); + NDINIT_ATVP(&nd, operation, NOFOLLOW | MPSAFE, UIO_SYSSPACE, pnamep, + startvp, td); error = vn_open_cred(&nd, &filemode, createmode, td->td_ucred, NULL); NDFREE(&nd, NDF_ONLY_PNBUF); if (error == 0) { @@ -180,6 +183,15 @@ zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, } return (error); } + +static __inline int +zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, + vnode_t **vpp, enum create crwhy, mode_t umask) +{ + + return (vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, + umask, NULL, -1)); +} #define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask) \ zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask)) @@ -192,14 +204,16 @@ zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len, struct thread *td = curthread; int error, vfslocked, resid; - ASSERT(rw == UIO_WRITE); ASSERT(ioflag == 0); ASSERT(ulimit == RLIM64_INFINITY); - ioflag = IO_APPEND | IO_UNIT; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); - VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE); + if (rw == UIO_WRITE) { + ioflag = IO_SYNC; + VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE); + } else { + ioflag = IO_DIRECT; + } error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED, &resid, td); VFS_UNLOCK_GIANT(vfslocked); @@ -229,7 +243,7 @@ drop: VFS_UNLOCK_GIANT(vfslocked); return (error); } -#define VOP_FSYNC(vp, flag, cr) zfs_vop_fsync((vp), (flag), (cr)) +#define VOP_FSYNC(vp, flag, cr, ct) zfs_vop_fsync((vp), (flag), (cr)) static __inline int zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr) @@ -241,7 +255,7 @@ zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr) return (vn_close(vp, flag, cr, curthread)); } -#define VOP_CLOSE(vp, oflags, count, offset, cr) \ +#define VOP_CLOSE(vp, oflags, count, offset, cr, ct) \ zfs_vop_close((vp), (oflags), (count), (offset), (cr)) static __inline int @@ -253,7 +267,6 @@ vn_rename(char *from, char *to, enum uio_seg seg) return (kern_rename(curthread, from, to, seg)); } -enum rm { RMFILE }; static __inline int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag) { diff --git a/sys/cddl/compat/opensolaris/sys/zone.h b/sys/cddl/compat/opensolaris/sys/zone.h index 2e47eb1..d761310 100644 --- a/sys/cddl/compat/opensolaris/sys/zone.h +++ b/sys/cddl/compat/opensolaris/sys/zone.h @@ -38,9 +38,9 @@ */ /* - * Is process in the global zone? + * Is thread in the global zone? */ -#define INGLOBALZONE(p) (!jailed((p)->p_ucred)) +#define INGLOBALZONE(thread) (!jailed((thread)->td_ucred)) /* * Attach the given dataset to the given jail. @@ -61,8 +61,6 @@ extern int zone_dataset_visible(const char *, int *); #define GLOBAL_ZONEID 0 -extern int getzoneid(void); - #endif /* _KERNEL */ #endif /* !_OPENSOLARIS_SYS_ZONE_H_ */ |