diff options
Diffstat (limited to 'sys/cddl/compat/opensolaris')
35 files changed, 1004 insertions, 373 deletions
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c b/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c index 72d1557..4aba9ea 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c @@ -83,8 +83,7 @@ atomic_add_64_nv(volatile uint64_t *target, int64_t delta) return (newval); } -#if defined(__sparc64__) || defined(__powerpc__) || defined(__arm__) || \ - defined(__mips__) +#if defined(__powerpc__) || defined(__arm__) || defined(__mips__) void atomic_or_8(volatile uint8_t *target, uint8_t value) { @@ -105,27 +104,23 @@ atomic_or_8_nv(volatile uint8_t *target, uint8_t value) return (newval); } -#ifndef __LP64__ -void * -atomic_cas_ptr(volatile void *target, void *cmp, void *newval) +uint64_t +atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval) { - void *oldval, **trg; + uint64_t oldval; mtx_lock(&atomic_mtx); - trg = __DEVOLATILE(void **, target); - oldval = *trg; + oldval = *target; if (oldval == cmp) - *trg = newval; + *target = newval; mtx_unlock(&atomic_mtx); return (oldval); } -#endif -#ifndef __sparc64__ -uint64_t -atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval) +uint32_t +atomic_cas_32(volatile uint32_t *target, uint32_t cmp, uint32_t newval) { - uint64_t oldval; + uint32_t oldval; mtx_lock(&atomic_mtx); oldval = *target; @@ -134,7 +129,6 @@ atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval) mtx_unlock(&atomic_mtx); return (oldval); } -#endif void membar_producer(void) diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c index 5d4ba06..3bcbc0b 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$"); #endif #ifdef _KERNEL -static MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris"); +MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris"); #else #define malloc(size, type, flags) malloc(size) #define free(addr, type) free(addr) diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c b/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c index 4ac666d..595f3c0 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c @@ -33,40 +33,22 @@ __FBSDID("$FreeBSD$"); #include <sys/libkern.h> #include <sys/limits.h> #include <sys/misc.h> -#include <sys/sunddi.h> +#include <sys/sysctl.h> char hw_serial[11] = "0"; struct opensolaris_utsname utsname = { - .nodename = "unset", - .sysname = "SunOS" + .machine = MACHINE }; -int -ddi_strtol(const char *str, char **nptr, int base, long *result) +static void +opensolaris_utsname_init(void *arg) { - *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) -{ - - if (str == hw_serial) { - *result = prison0.pr_hostid; - return (0); - } - - *result = strtoul(str, nptr, base); - if (*result == 0) - return (EINVAL); - else if (*result == ULONG_MAX) - return (ERANGE); - return (0); + utsname.sysname = ostype; + utsname.nodename = prison0.pr_hostname; + utsname.release = osrelease; + snprintf(utsname.version, sizeof(utsname.version), "%d", osreldate); } +SYSINIT(opensolaris_utsname_init, SI_SUB_TUNABLES, SI_ORDER_ANY, + opensolaris_utsname_init, NULL); diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c b/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c index 3b22c44..019f29f 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c @@ -38,47 +38,47 @@ __FBSDID("$FreeBSD$"); #include <sys/zfs_vfsops.h> int -secpolicy_nfs(struct ucred *cred) +secpolicy_nfs(cred_t *cr) { - return (priv_check_cred(cred, PRIV_NFS_DAEMON, 0)); + return (priv_check_cred(cr, PRIV_NFS_DAEMON, 0)); } int -secpolicy_zfs(struct ucred *cred) +secpolicy_zfs(cred_t *cr) { - return (priv_check_cred(cred, PRIV_VFS_MOUNT, 0)); + return (priv_check_cred(cr, PRIV_VFS_MOUNT, 0)); } int -secpolicy_sys_config(struct ucred *cred, int checkonly __unused) +secpolicy_sys_config(cred_t *cr, int checkonly __unused) { - return (priv_check_cred(cred, PRIV_ZFS_POOL_CONFIG, 0)); + return (priv_check_cred(cr, PRIV_ZFS_POOL_CONFIG, 0)); } int -secpolicy_zinject(struct ucred *cred) +secpolicy_zinject(cred_t *cr) { - return (priv_check_cred(cred, PRIV_ZFS_INJECT, 0)); + return (priv_check_cred(cr, PRIV_ZFS_INJECT, 0)); } int -secpolicy_fs_unmount(struct ucred *cred, struct mount *vfsp __unused) +secpolicy_fs_unmount(cred_t *cr, struct mount *vfsp __unused) { - return (priv_check_cred(cred, PRIV_VFS_UNMOUNT, 0)); + return (priv_check_cred(cr, PRIV_VFS_UNMOUNT, 0)); } int -secpolicy_fs_owner(struct mount *mp, struct ucred *cred) +secpolicy_fs_owner(struct mount *mp, cred_t *cr) { if (zfs_super_owner) { - if (cred->cr_uid == mp->mnt_cred->cr_uid && - cred->cr_prison == mp->mnt_cred->cr_prison) { + if (cr->cr_uid == mp->mnt_cred->cr_uid && + cr->cr_prison == mp->mnt_cred->cr_prison) { return (0); } } @@ -90,75 +90,129 @@ secpolicy_fs_owner(struct mount *mp, struct ucred *cred) */ extern int hardlink_check_uid; int -secpolicy_basic_link(struct vnode *vp, struct ucred *cred) +secpolicy_basic_link(vnode_t *vp, cred_t *cr) { if (!hardlink_check_uid) return (0); - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_LINK, 0)); + return (priv_check_cred(cr, PRIV_VFS_LINK, 0)); } int -secpolicy_vnode_stky_modify(struct ucred *cred) +secpolicy_vnode_stky_modify(cred_t *cr) { return (EPERM); } int -secpolicy_vnode_remove(struct vnode *vp, struct ucred *cred) +secpolicy_vnode_remove(vnode_t *vp, cred_t *cr) { - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0)); + return (priv_check_cred(cr, PRIV_VFS_ADMIN, 0)); } int -secpolicy_vnode_access(struct ucred *cred, struct vnode *vp, uint64_t owner, - accmode_t accmode) +secpolicy_vnode_access(cred_t *cr, vnode_t *vp, uid_t owner, accmode_t accmode) { - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - if ((accmode & VREAD) && priv_check_cred(cred, PRIV_VFS_READ, 0) != 0) + if ((accmode & VREAD) && priv_check_cred(cr, PRIV_VFS_READ, 0) != 0) return (EACCES); if ((accmode & VWRITE) && - priv_check_cred(cred, PRIV_VFS_WRITE, 0) != 0) { + priv_check_cred(cr, PRIV_VFS_WRITE, 0) != 0) { return (EACCES); } if (accmode & VEXEC) { if (vp->v_type == VDIR) { - if (priv_check_cred(cred, PRIV_VFS_LOOKUP, 0) != 0) { + if (priv_check_cred(cr, PRIV_VFS_LOOKUP, 0) != 0) return (EACCES); - } } else { - if (priv_check_cred(cred, PRIV_VFS_EXEC, 0) != 0) { + if (priv_check_cred(cr, PRIV_VFS_EXEC, 0) != 0) return (EACCES); - } } } return (0); } +/* + * Like secpolicy_vnode_access() but we get the actual wanted mode and the + * current mode of the file, not the missing bits. + */ +int +secpolicy_vnode_access2(cred_t *cr, vnode_t *vp, uid_t owner, + accmode_t curmode, accmode_t wantmode) +{ + accmode_t mode; + + mode = ~curmode & wantmode; + + if (mode == 0) + return (0); + + return (secpolicy_vnode_access(cr, vp, owner, mode)); +} + +int +secpolicy_vnode_any_access(cred_t *cr, vnode_t *vp, uid_t owner) +{ + static int privs[] = { + PRIV_VFS_ADMIN, + PRIV_VFS_READ, + PRIV_VFS_WRITE, + PRIV_VFS_EXEC, + PRIV_VFS_LOOKUP + }; + int i; + + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) + return (0); + + /* Same as secpolicy_vnode_setdac */ + if (owner == cr->cr_uid) + return (0); + + for (i = 0; i < sizeof (privs)/sizeof (int); i++) { + boolean_t allzone = B_FALSE; + int priv; + + switch (priv = privs[i]) { + case PRIV_VFS_EXEC: + if (vp->v_type == VDIR) + continue; + break; + case PRIV_VFS_LOOKUP: + if (vp->v_type != VDIR) + continue; + break; + } + if (priv_check_cred(cr, priv, 0) == 0) + return (0); + } + return (EPERM); +} + int -secpolicy_vnode_setdac(struct vnode *vp, struct ucred *cred, uid_t owner) +secpolicy_vnode_setdac(vnode_t *vp, cred_t *cr, uid_t owner) { - if (owner == cred->cr_uid) + if (owner == cr->cr_uid) return (0); - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0)); + return (priv_check_cred(cr, PRIV_VFS_ADMIN, 0)); } int -secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, +secpolicy_vnode_setattr(cred_t *cr, vnode_t *vp, struct vattr *vap, const struct vattr *ovap, int flags, - int unlocked_access(void *, int, struct ucred *), void *node) + int unlocked_access(void *, int, cred_t *), void *node) { int mask = vap->va_mask; int error; @@ -166,7 +220,7 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, if (mask & AT_SIZE) { if (vp->v_type == VDIR) return (EISDIR); - error = unlocked_access(node, VWRITE, cred); + error = unlocked_access(node, VWRITE, cr); if (error) return (error); } @@ -179,17 +233,17 @@ 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(vp, cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid); if (error) return (error); - error = secpolicy_setid_setsticky_clear(vp, vap, ovap, cred); + error = secpolicy_setid_setsticky_clear(vp, vap, ovap, cr); if (error) return (error); } else { vap->va_mode = ovap->va_mode; } if (mask & (AT_UID | AT_GID)) { - error = secpolicy_vnode_setdac(vp, cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid); if (error) return (error); @@ -200,9 +254,9 @@ 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))) { - if (secpolicy_fs_owner(vp->v_mount, cred) != 0) { - error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0); + !groupmember(vap->va_gid, cr))) { + if (secpolicy_fs_owner(vp->v_mount, cr) != 0) { + error = priv_check_cred(cr, PRIV_VFS_CHOWN, 0); if (error) return (error); } @@ -210,7 +264,7 @@ 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)) { - secpolicy_setid_clear(vap, vp, cred); + secpolicy_setid_clear(vap, vp, cr); } } if (mask & (AT_ATIME | AT_MTIME)) { @@ -222,9 +276,9 @@ 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(vp, cred, ovap->va_uid); + error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid); if (error && (vap->va_vaflags & VA_UTIMES_NULL)) - error = unlocked_access(node, VWRITE, cred); + error = unlocked_access(node, VWRITE, cr); if (error) return (error); } @@ -232,41 +286,42 @@ secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap, } int -secpolicy_vnode_create_gid(struct ucred *cred) +secpolicy_vnode_create_gid(cred_t *cr) { return (EPERM); } int -secpolicy_vnode_setids_setgids(vnode_t *vp, struct ucred *cred, gid_t gid) +secpolicy_vnode_setids_setgids(vnode_t *vp, cred_t *cr, gid_t gid) { - if (groupmember(gid, cred)) + + if (groupmember(gid, cr)) return (0); - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_SETGID, 0)); + return (priv_check_cred(cr, PRIV_VFS_SETGID, 0)); } int -secpolicy_vnode_setid_retain(struct vnode *vp, struct ucred *cred, +secpolicy_vnode_setid_retain(vnode_t *vp, cred_t *cr, boolean_t issuidroot __unused) { - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)); + return (priv_check_cred(cr, PRIV_VFS_RETAINSUGID, 0)); } void -secpolicy_setid_clear(struct vattr *vap, struct vnode *vp, struct ucred *cred) +secpolicy_setid_clear(struct vattr *vap, vnode_t *vp, cred_t *cr) { - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return; if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0) { - if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) { + if (priv_check_cred(cr, PRIV_VFS_RETAINSUGID, 0)) { vap->va_mask |= AT_MODE; vap->va_mode &= ~(S_ISUID|S_ISGID); } @@ -274,12 +329,12 @@ 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) +secpolicy_setid_setsticky_clear(vnode_t *vp, struct vattr *vap, + const struct vattr *ovap, cred_t *cr) { int error; - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); /* @@ -288,7 +343,7 @@ secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap, * is not a member of. Both of these are allowed in jail(8). */ if (vp->v_type != VDIR && (vap->va_mode & S_ISTXT)) { - if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0)) + if (priv_check_cred(cr, PRIV_VFS_STICKYFILE, 0)) return (EFTYPE); } /* @@ -296,15 +351,15 @@ 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(vp, cred, ovap->va_gid); + error = secpolicy_vnode_setids_setgids(vp, cr, ovap->va_gid); if (error) return (error); } /* * Deny setting setuid if we are not the file owner. */ - if ((vap->va_mode & S_ISUID) && ovap->va_uid != cred->cr_uid) { - error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0); + if ((vap->va_mode & S_ISUID) && ovap->va_uid != cr->cr_uid) { + error = priv_check_cred(cr, PRIV_VFS_ADMIN, 0); if (error) return (error); } @@ -319,25 +374,25 @@ secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct mount *vfsp) } int -secpolicy_vnode_owner(struct vnode *vp, cred_t *cred, uid_t owner) +secpolicy_vnode_owner(vnode_t *vp, cred_t *cr, uid_t owner) { - if (owner == cred->cr_uid) + if (owner == cr->cr_uid) return (0); - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); /* XXX: vfs_suser()? */ - return (priv_check_cred(cred, PRIV_VFS_MOUNT_OWNER, 0)); + return (priv_check_cred(cr, PRIV_VFS_MOUNT_OWNER, 0)); } int -secpolicy_vnode_chown(struct vnode *vp, cred_t *cred, uid_t owner) +secpolicy_vnode_chown(vnode_t *vp, cred_t *cr, uid_t owner) { - if (secpolicy_fs_owner(vp->v_mount, cred) == 0) + if (secpolicy_fs_owner(vp->v_mount, cr) == 0) return (0); - return (priv_check_cred(cred, PRIV_VFS_CHOWN, 0)); + return (priv_check_cred(cr, PRIV_VFS_CHOWN, 0)); } void @@ -357,7 +412,7 @@ secpolicy_fs_mount_clearopts(cred_t *cr, struct mount *vfsp) * Check privileges for setting xvattr attributes */ int -secpolicy_xvattr(struct vnode *vp, xvattr_t *xvap, uid_t owner, cred_t *cr, +secpolicy_xvattr(vnode_t *vp, xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) { diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_string.c b/sys/cddl/compat/opensolaris/kern/opensolaris_string.c index de9169e..2150608 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_string.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_string.c @@ -27,6 +27,8 @@ #include <sys/param.h> #include <sys/string.h> +#include <sys/kmem.h> +#include <machine/stdarg.h> #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') @@ -71,3 +73,34 @@ strident_canon(char *s, size_t n) } *s = 0; } + +/* + * Do not change the length of the returned string; it must be freed + * with strfree(). + */ +char * +kmem_asprintf(const char *fmt, ...) +{ + int size; + va_list adx; + char *buf; + + va_start(adx, fmt); + size = vsnprintf(NULL, 0, fmt, adx) + 1; + va_end(adx); + + buf = kmem_alloc(size, KM_SLEEP); + + va_start(adx, fmt); + (void) vsnprintf(buf, size, fmt, adx); + va_end(adx); + + return (buf); +} + +void +strfree(char *str) +{ + ASSERT(str != NULL); + kmem_free(str, strlen(str) + 1); +} diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c b/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c new file mode 100644 index 0000000..bb56909 --- /dev/null +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c @@ -0,0 +1,198 @@ +/*- + * Copyright (c) 2010 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/jail.h> +#include <sys/kernel.h> +#include <sys/libkern.h> +#include <sys/limits.h> +#include <sys/misc.h> +#include <sys/sunddi.h> +#include <sys/sysctl.h> + +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) +{ + + if (str == hw_serial) { + *result = prison0.pr_hostid; + return (0); + } + + *result = strtoul(str, nptr, base); + if (*result == 0) + return (EINVAL); + else if (*result == ULONG_MAX) + return (ERANGE); + return (0); +} + +int +ddi_strtoull(const char *str, char **nptr, int base, unsigned long long *result) +{ + + *result = (unsigned long long)strtouq(str, nptr, base); + if (*result == 0) + return (EINVAL); + else if (*result == ULLONG_MAX) + return (ERANGE); + return (0); +} + +struct ddi_soft_state_item { + int ssi_item; + void *ssi_data; + LIST_ENTRY(ddi_soft_state_item) ssi_next; +}; + +struct ddi_soft_state { + size_t ss_size; + kmutex_t ss_lock; + LIST_HEAD(, ddi_soft_state_item) ss_list; +}; + +static void * +ddi_get_soft_state_locked(struct ddi_soft_state *ss, int item) +{ + struct ddi_soft_state_item *itemp; + + ASSERT(MUTEX_HELD(&zfsdev_state_lock)); + + LIST_FOREACH(itemp, &ss->ss_list, ssi_next) { + if (itemp->ssi_item == item) + return (itemp->ssi_data); + } + return (NULL); +} + +void * +ddi_get_soft_state(void *state, int item) +{ + struct ddi_soft_state *ss = state; + void *data; + + mutex_enter(&ss->ss_lock); + data = ddi_get_soft_state_locked(ss, item); + mutex_exit(&ss->ss_lock); + return (data); +} + +int +ddi_soft_state_zalloc(void *state, int item) +{ + struct ddi_soft_state *ss = state; + struct ddi_soft_state_item *itemp; + + itemp = kmem_alloc(sizeof(*itemp), KM_SLEEP); + itemp->ssi_item = item; + itemp->ssi_data = kmem_zalloc(ss->ss_size, KM_SLEEP); + + mutex_enter(&ss->ss_lock); + if (ddi_get_soft_state_locked(ss, item) != NULL) { + mutex_exit(&ss->ss_lock); + kmem_free(itemp->ssi_data, ss->ss_size); + kmem_free(itemp, sizeof(*itemp)); + return (DDI_FAILURE); + } + LIST_INSERT_HEAD(&ss->ss_list, itemp, ssi_next); + mutex_exit(&ss->ss_lock); + return (DDI_SUCCESS); +} + +static void +ddi_soft_state_free_locked(struct ddi_soft_state *ss, int item) +{ + struct ddi_soft_state_item *itemp; + + ASSERT(MUTEX_HELD(&zfsdev_state_lock)); + + LIST_FOREACH(itemp, &ss->ss_list, ssi_next) { + if (itemp->ssi_item == item) + break; + } + if (itemp != NULL) { + LIST_REMOVE(itemp, ssi_next); + kmem_free(itemp->ssi_data, ss->ss_size); + kmem_free(itemp, sizeof(*itemp)); + } +} + +void +ddi_soft_state_free(void *state, int item) +{ + struct ddi_soft_state *ss = state; + + mutex_enter(&ss->ss_lock); + ddi_soft_state_free_locked(ss, item); + mutex_exit(&ss->ss_lock); +} + +int +ddi_soft_state_init(void **statep, size_t size, size_t nitems __unused) +{ + struct ddi_soft_state *ss; + + ss = kmem_alloc(sizeof(*ss), KM_SLEEP); + mutex_init(&ss->ss_lock, NULL, MUTEX_DEFAULT, NULL); + ss->ss_size = size; + LIST_INIT(&ss->ss_list); + *statep = ss; + return (0); +} + +void +ddi_soft_state_fini(void **statep) +{ + struct ddi_soft_state *ss = *statep; + struct ddi_soft_state_item *itemp; + int item; + + mutex_enter(&ss->ss_lock); + while ((itemp = LIST_FIRST(&ss->ss_list)) != NULL) { + item = itemp->ssi_item; + ddi_soft_state_free_locked(ss, item); + } + mutex_exit(&ss->ss_lock); + mutex_destroy(&ss->ss_lock); + kmem_free(ss, sizeof(*ss)); + + *statep = NULL; +} diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c b/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c new file mode 100644 index 0000000..dea618c --- /dev/null +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c @@ -0,0 +1,334 @@ +/*- + * Copyright (c) 2010 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/malloc.h> +#include <sys/kmem.h> +#include <sys/sbuf.h> +#include <sys/bus.h> +#include <sys/nvpair.h> +#include <sys/sunddi.h> +#include <sys/sysevent.h> +#include <sys/fm/protocol.h> + +struct sysevent { + nvlist_t *se_nvl; + char se_class[128]; + char se_subclass[128]; + char se_pub[128]; +}; + +sysevent_t * +sysevent_alloc(char *class, char *subclass, char *pub, int flag) +{ + struct sysevent *ev; + + ASSERT(class != NULL); + ASSERT(subclass != NULL); + ASSERT(pub != NULL); + ASSERT(flag == SE_SLEEP); + + ev = kmem_alloc(sizeof(*ev), KM_SLEEP); + ev->se_nvl = NULL; + strlcpy(ev->se_class, class, sizeof(ev->se_class)); + strlcpy(ev->se_subclass, subclass, sizeof(ev->se_subclass)); + strlcpy(ev->se_pub, pub, sizeof(ev->se_pub)); + + return ((sysevent_t *)ev); +} + +void +sysevent_free(sysevent_t *evp) +{ + struct sysevent *ev = (struct sysevent *)evp; + + ASSERT(evp != NULL); + + if (ev->se_nvl != NULL) + sysevent_free_attr(ev->se_nvl); + kmem_free(ev, sizeof(*ev)); +} + +int +sysevent_add_attr(sysevent_attr_list_t **ev_attr_list, char *name, + sysevent_value_t *se_value, int flag) +{ + nvlist_t *nvl; + int error; + + ASSERT(ev_attr_list != NULL); + ASSERT(name != NULL); + ASSERT(se_value != NULL); + ASSERT(flag == SE_SLEEP); + + if (strlen(name) >= MAX_ATTR_NAME) + return (SE_EINVAL); + + nvl = *ev_attr_list; + if (nvl == NULL) { + if (nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, KM_SLEEP) != 0) + return (SE_ENOMEM); + } + + error = 0; + + switch (se_value->value_type) { + case SE_DATA_TYPE_UINT64: + error = nvlist_add_uint64(nvl, name, se_value->value.sv_uint64); + break; + case SE_DATA_TYPE_STRING: + if (strlen(se_value->value.sv_string) >= MAX_STRING_SZ) + error = SE_EINVAL; + if (error == 0) { + error = nvlist_add_string(nvl, name, + se_value->value.sv_string); + } + break; + default: + printf("%s: type %d is not implemented\n", __func__, + se_value->value_type); + break; + } + + if (error != 0) { + nvlist_free(nvl); + return (error); + } + + *ev_attr_list = nvl; + + return (0); +} + +void +sysevent_free_attr(sysevent_attr_list_t *ev_attr_list) +{ + + nvlist_free(ev_attr_list); +} + +int +sysevent_attach_attributes(sysevent_t *evp, sysevent_attr_list_t *ev_attr_list) +{ + struct sysevent *ev = (struct sysevent *)evp; + + ASSERT(ev->se_nvl == NULL); + + ev->se_nvl = ev_attr_list; + + return (0); +} + +void +sysevent_detach_attributes(sysevent_t *evp) +{ + struct sysevent *ev = (struct sysevent *)evp; + + ASSERT(ev->se_nvl != NULL); + + ev->se_nvl = NULL; +} + +int +log_sysevent(sysevent_t *evp, int flag, sysevent_id_t *eid) +{ + struct sysevent *ev = (struct sysevent *)evp; + struct sbuf *sb; + const char *type; + char typestr[128]; + nvpair_t *elem = NULL; + + ASSERT(evp != NULL); + ASSERT(ev->se_nvl != NULL); + ASSERT(flag == SE_SLEEP); + ASSERT(eid != NULL); + + sb = sbuf_new_auto(); + if (sb == NULL) + return (SE_ENOMEM); + type = NULL; + + while ((elem = nvlist_next_nvpair(ev->se_nvl, elem)) != NULL) { + switch (nvpair_type(elem)) { + case DATA_TYPE_BOOLEAN: + { + boolean_t value; + + (void) nvpair_value_boolean_value(elem, &value); + sbuf_printf(sb, " %s=%s", nvpair_name(elem), + value ? "true" : "false"); + break; + } + case DATA_TYPE_UINT8: + { + uint8_t value; + + (void) nvpair_value_uint8(elem, &value); + sbuf_printf(sb, " %s=%hhu", nvpair_name(elem), value); + break; + } + case DATA_TYPE_INT32: + { + int32_t value; + + (void) nvpair_value_int32(elem, &value); + sbuf_printf(sb, " %s=%jd", nvpair_name(elem), + (intmax_t)value); + break; + } + case DATA_TYPE_UINT32: + { + uint32_t value; + + (void) nvpair_value_uint32(elem, &value); + sbuf_printf(sb, " %s=%ju", nvpair_name(elem), + (uintmax_t)value); + break; + } + case DATA_TYPE_INT64: + { + int64_t value; + + (void) nvpair_value_int64(elem, &value); + sbuf_printf(sb, " %s=%jd", nvpair_name(elem), + (intmax_t)value); + break; + } + case DATA_TYPE_UINT64: + { + uint64_t value; + + (void) nvpair_value_uint64(elem, &value); + sbuf_printf(sb, " %s=%ju", nvpair_name(elem), + (uintmax_t)value); + break; + } + case DATA_TYPE_STRING: + { + char *value; + + (void) nvpair_value_string(elem, &value); + sbuf_printf(sb, " %s=%s", nvpair_name(elem), value); + if (strcmp(FM_CLASS, nvpair_name(elem)) == 0) + type = value; + break; + } + case DATA_TYPE_UINT8_ARRAY: + { + uint8_t *value; + uint_t ii, nelem; + + (void) nvpair_value_uint8_array(elem, &value, &nelem); + sbuf_printf(sb, " %s=", nvpair_name(elem)); + for (ii = 0; ii < nelem; ii++) + sbuf_printf(sb, "%02hhx", value[ii]); + break; + } + case DATA_TYPE_UINT16_ARRAY: + { + uint16_t *value; + uint_t ii, nelem; + + (void) nvpair_value_uint16_array(elem, &value, &nelem); + sbuf_printf(sb, " %s=", nvpair_name(elem)); + for (ii = 0; ii < nelem; ii++) + sbuf_printf(sb, "%04hx", value[ii]); + break; + } + case DATA_TYPE_UINT32_ARRAY: + { + uint32_t *value; + uint_t ii, nelem; + + (void) nvpair_value_uint32_array(elem, &value, &nelem); + sbuf_printf(sb, " %s=", nvpair_name(elem)); + for (ii = 0; ii < nelem; ii++) + sbuf_printf(sb, "%08jx", (uintmax_t)value[ii]); + break; + } + case DATA_TYPE_UINT64_ARRAY: + { + uint64_t *value; + uint_t ii, nelem; + + (void) nvpair_value_uint64_array(elem, &value, &nelem); + sbuf_printf(sb, " %s=", nvpair_name(elem)); + for (ii = 0; ii < nelem; ii++) + sbuf_printf(sb, "%016jx", (uintmax_t)value[ii]); + break; + } + default: + printf("%s: type %d is not implemented\n", __func__, + nvpair_type(elem)); + break; + } + } + + if (sbuf_finish(sb) != 0) { + sbuf_delete(sb); + return (SE_ENOMEM); + } + + if (type == NULL) + type = ev->se_subclass; + if (strncmp(type, "ESC_ZFS_", 8) == 0) { + snprintf(typestr, sizeof(typestr), "misc.fs.zfs.%s", type + 8); + type = typestr; + } + devctl_notify("ZFS", "ZFS", type, sbuf_data(sb)); + sbuf_delete(sb); + + return (0); +} + +int +_ddi_log_sysevent(char *vendor, char *class, char *subclass, + nvlist_t *attr_list, sysevent_id_t *eidp, int flag) +{ + sysevent_t *ev; + int ret; + + ASSERT(vendor != NULL); + ASSERT(class != NULL); + ASSERT(subclass != NULL); + ASSERT(attr_list != NULL); + ASSERT(eidp != NULL); + ASSERT(flag == DDI_SLEEP); + + ev = sysevent_alloc(class, subclass, vendor, SE_SLEEP); + ASSERT(ev != NULL); + (void)sysevent_attach_attributes(ev, attr_list); + ret = log_sysevent(ev, SE_SLEEP, eidp); + sysevent_detach_attributes(ev); + sysevent_free(ev); + + return (ret); +} diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c b/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c index f7b31db..5a20488 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c @@ -115,12 +115,17 @@ taskqid_t taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags) { struct ostask *task; - int mflag; + int mflag, prio; if ((flags & (TQ_SLEEP | TQ_NOQUEUE)) == TQ_SLEEP) mflag = M_WAITOK; else mflag = M_NOWAIT; + /* + * If TQ_FRONT is given, we want higher priority for this task, so it + * can go at the front of the queue. + */ + prio = !!(flags & TQ_FRONT); task = uma_zalloc(taskq_zone, mflag); if (task == NULL) @@ -129,7 +134,7 @@ taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags) task->ost_func = func; task->ost_arg = arg; - TASK_INIT(&task->ost_task, 0, taskq_run, task); + TASK_INIT(&task->ost_task, prio, taskq_run, task); taskqueue_enqueue(tq->tq_queue, &task->ost_task); return ((taskqid_t)(void *)task); @@ -148,17 +153,24 @@ taskq_run_safe(void *arg, int pending __unused) } taskqid_t -taskq_dispatch_safe(taskq_t *tq, task_func_t func, void *arg, +taskq_dispatch_safe(taskq_t *tq, task_func_t func, void *arg, u_int flags, struct ostask *task) { + int prio; ASSERT(task->ost_magic != TASKQ_MAGIC); + /* + * If TQ_FRONT is given, we want higher priority for this task, so it + * can go at the front of the queue. + */ + prio = !!(flags & TQ_FRONT); + task->ost_magic = TASKQ_MAGIC; task->ost_func = func; task->ost_arg = arg; - TASK_INIT(&task->ost_task, 0, taskq_run_safe, task); + TASK_INIT(&task->ost_task, prio, taskq_run_safe, task); taskqueue_enqueue(tq->tq_queue, &task->ost_task); return ((taskqid_t)(void *)task); diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c index 8538b54..be9f4ec 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c @@ -115,10 +115,10 @@ int mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, char *fspec, int fsflags) { - struct mount *mp; struct vfsconf *vfsp; + struct mount *mp; + vnode_t *vp, *mvp; struct ucred *cr; - vnode_t *vp; int error; /* @@ -153,8 +153,10 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, /* * Allocate and initialize the filesystem. + * We don't want regular user that triggered snapshot mount to be able + * to unmount it, so pass credentials of the parent mount. */ - mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred); + mp = vfs_mount_alloc(vp, vfsp, fspath, vp->v_mount->mnt_cred); mp->mnt_optnew = NULL; vfs_setmntopt(mp, "from", fspec, 0); @@ -164,8 +166,7 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, /* * Set the mount level flags. */ - mp->mnt_flag &= ~MNT_UPDATEMASK; - mp->mnt_flag |= fsflags & (MNT_UPDATEMASK | MNT_FORCE | MNT_ROOTFS); + mp->mnt_flag = fsflags & MNT_UPDATEMASK; /* * Snapshots are always read-only. */ @@ -176,13 +177,6 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, */ 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. - */ - crfree(mp->mnt_cred); - mp->mnt_cred = crdup(vp->v_mount->mnt_cred); - mp->mnt_stat.f_owner = mp->mnt_cred->cr_uid; - /* * 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? */ @@ -191,17 +185,25 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, error = VFS_MOUNT(mp); td->td_ucred = cr; - if (error == 0) { - if (mp->mnt_opt != NULL) - vfs_freeopts(mp->mnt_opt); - mp->mnt_opt = mp->mnt_optnew; - (void)VFS_STATFS(mp, &mp->mnt_stat); + if (error != 0) { + vrele(vp); + vfs_unbusy(mp); + vfs_mount_destroy(mp); + *vpp = NULL; + return (error); } + + if (mp->mnt_opt != NULL) + vfs_freeopts(mp->mnt_opt); + mp->mnt_opt = mp->mnt_optnew; + (void)VFS_STATFS(mp, &mp->mnt_stat); + /* * Prevent external consumers of mount options from reading * mnt_optnew. */ mp->mnt_optnew = NULL; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); #ifdef FREEBSD_NAMECACHE cache_purge(vp); @@ -209,27 +211,17 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath, VI_LOCK(vp); vp->v_iflag &= ~VI_MOUNT; VI_UNLOCK(vp); - if (error == 0) { - vnode_t *mvp; - - 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"); - vput(vp); - vfs_unbusy(mp); - *vpp = mvp; - } else { - vput(vp); - vfs_unbusy(mp); - vfs_mount_destroy(mp); - *vpp = NULL; - } - return (error); + + 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"); + vput(vp); + vfs_unbusy(mp); + *vpp = mvp; + return (0); } diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c b/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c index f25a67c..55b1906 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c @@ -229,6 +229,15 @@ zone_destroy(void *arg) free(head, M_ZONES); } +uint32_t +zone_get_hostid(void *ptr) +{ + + KASSERT(ptr == NULL, ("only NULL pointer supported in %s", __func__)); + + return ((uint32_t)curthread->td_ucred->cr_prison->pr_hostid); +} + static void zone_sysinit(void *arg __unused) { diff --git a/sys/cddl/compat/opensolaris/sys/atomic.h b/sys/cddl/compat/opensolaris/sys/atomic.h index ddfb325..af9cc5d 100644 --- a/sys/cddl/compat/opensolaris/sys/atomic.h +++ b/sys/cddl/compat/opensolaris/sys/atomic.h @@ -41,9 +41,10 @@ extern void atomic_add_64(volatile uint64_t *target, int64_t delta); extern void atomic_dec_64(volatile uint64_t *target); #endif #ifndef __LP64__ -extern void *atomic_cas_ptr(volatile void *target, void *cmp, void *newval); #endif #ifndef __sparc64__ +extern uint32_t atomic_cas_32(volatile uint32_t *target, uint32_t cmp, + uint32_t newval); extern uint64_t atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval); #endif @@ -118,13 +119,20 @@ atomic_inc_64_nv(volatile uint64_t *target) return (atomic_add_64_nv(target, 1)); } -#ifdef __LP64__ +#if !defined(COMPAT_32BIT) && defined(__LP64__) static __inline void * atomic_cas_ptr(volatile void *target, void *cmp, void *newval) { - return ((void *)atomic_cas_64((volatile uint64_t *)target, (uint64_t)cmp, - (uint64_t)newval)); + return ((void *)atomic_cas_64((volatile uint64_t *)target, + (uint64_t)cmp, (uint64_t)newval)); } -#endif +#else +static __inline void * +atomic_cas_ptr(volatile void *target, void *cmp, void *newval) +{ + return ((void *)atomic_cas_32((volatile uint32_t *)target, + (uint32_t)cmp, (uint32_t)newval)); +} +#endif /* !defined(COMPAT_32BIT) && defined(__LP64__) */ #endif /* !_OPENSOLARIS_SYS_ATOMIC_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/byteorder.h b/sys/cddl/compat/opensolaris/sys/byteorder.h index a8f8bc2..72ae45b 100644 --- a/sys/cddl/compat/opensolaris/sys/byteorder.h +++ b/sys/cddl/compat/opensolaris/sys/byteorder.h @@ -59,9 +59,31 @@ * Macros to convert from a specific byte order to/from native byte order */ #if _BYTE_ORDER == _BIG_ENDIAN +#define BE_8(x) BMASK_8(x) +#define BE_16(x) BMASK_16(x) +#define BE_32(x) BMASK_32(x) +#define BE_64(x) BMASK_64(x) +#define LE_8(x) BSWAP_8(x) +#define LE_16(x) BSWAP_16(x) +#define LE_32(x) BSWAP_32(x) #define LE_64(x) BSWAP_64(x) #else +#define LE_8(x) BMASK_8(x) +#define LE_16(x) BMASK_16(x) +#define LE_32(x) BMASK_32(x) #define LE_64(x) BMASK_64(x) +#define BE_8(x) BSWAP_8(x) +#define BE_16(x) BSWAP_16(x) +#define BE_32(x) BSWAP_32(x) +#define BE_64(x) BSWAP_64(x) +#endif + +#if _BYTE_ORDER == _BIG_ENDIAN +#define htonll(x) BMASK_64(x) +#define ntohll(x) BMASK_64(x) +#else +#define htonll(x) BSWAP_64(x) +#define ntohll(x) BSWAP_64(x) #endif #endif /* _OPENSOLARIS_SYS_BYTEORDER_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/dirent.h b/sys/cddl/compat/opensolaris/sys/dirent.h index c369b04..d273f8a 100644 --- a/sys/cddl/compat/opensolaris/sys/dirent.h +++ b/sys/cddl/compat/opensolaris/sys/dirent.h @@ -29,11 +29,14 @@ #ifndef _OPENSOLARIS_SYS_DIRENT_H_ #define _OPENSOLARIS_SYS_DIRENT_H_ +#include <sys/types.h> + #include_next <sys/dirent.h> typedef struct dirent dirent64_t; +typedef ino_t ino64_t; + #define dirent64 dirent -#define ino64_t ino_t #define d_ino d_fileno diff --git a/sys/cddl/compat/opensolaris/sys/file.h b/sys/cddl/compat/opensolaris/sys/file.h index afd1050..811b78c 100644 --- a/sys/cddl/compat/opensolaris/sys/file.h +++ b/sys/cddl/compat/opensolaris/sys/file.h @@ -31,26 +31,30 @@ #include_next <sys/file.h> +#define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */ + #ifdef _KERNEL typedef struct file file_t; static __inline file_t * -getf(int fd, int write) +getf(int fd) { struct file *fp; - if (write && fget_write(curthread, fd, &fp) == 0) - return (fp); - else if (!write && fget_read(curthread, fd, &fp) == 0) + if (fget(curthread, fd, &fp) == 0) return (fp); return (NULL); } static __inline void -releasef(file_t *fp) +releasef(int fd) { + struct file *fp; - fdrop(fp, curthread); + if (fget(curthread, fd, &fp) == 0) { + fdrop(fp, curthread); + fdrop(fp, curthread); + } } #endif /* _KERNEL */ diff --git a/sys/cddl/compat/opensolaris/sys/kmem.h b/sys/cddl/compat/opensolaris/sys/kmem.h index c103d18..6be2735 100644 --- a/sys/cddl/compat/opensolaris/sys/kmem.h +++ b/sys/cddl/compat/opensolaris/sys/kmem.h @@ -37,10 +37,16 @@ #include <vm/vm.h> #include <vm/vm_extern.h> +MALLOC_DECLARE(M_SOLARIS); + +#define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3)) +#define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1)) + #define KM_SLEEP M_WAITOK #define KM_PUSHPAGE M_WAITOK #define KM_NOSLEEP M_NOWAIT #define KMC_NODEBUG 0 +#define KMC_NOTOUCH 0 typedef struct kmem_cache { char kc_name[32]; @@ -75,4 +81,6 @@ void *calloc(size_t n, size_t s); #define kmem_zalloc(size, kmflags) zfs_kmem_alloc((size), (kmflags) | M_ZERO) #define kmem_free(buf, size) zfs_kmem_free((buf), (size)) +#define kmem_cache_set_move(cache, movefunc) do { } while (0) + #endif /* _OPENSOLARIS_SYS_KMEM_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/misc.h b/sys/cddl/compat/opensolaris/sys/misc.h index 20d335b..e128ce0 100644 --- a/sys/cddl/compat/opensolaris/sys/misc.h +++ b/sys/cddl/compat/opensolaris/sys/misc.h @@ -29,7 +29,9 @@ #ifndef _OPENSOLARIS_SYS_MISC_H_ #define _OPENSOLARIS_SYS_MISC_H_ -#define MAXUID 2147483647 +#include <sys/limits.h> + +#define MAXUID UID_MAX #define SPEC_MAXOFFSET_T OFF_MAX @@ -45,8 +47,11 @@ #ifdef _KERNEL struct opensolaris_utsname { - char *nodename; - char *sysname; + char *sysname; + char *nodename; + char *release; + char version[32]; + char *machine; }; extern char hw_serial[11]; diff --git a/sys/cddl/compat/opensolaris/sys/mount.h b/sys/cddl/compat/opensolaris/sys/mount.h index d4c4039..e012597 100644 --- a/sys/cddl/compat/opensolaris/sys/mount.h +++ b/sys/cddl/compat/opensolaris/sys/mount.h @@ -29,6 +29,8 @@ #ifndef _OPENSOLARIS_SYS_MOUNT_H_ #define _OPENSOLARIS_SYS_MOUNT_H_ +#include <sys/param.h> + #include_next <sys/mount.h> #define MS_FORCE MNT_FORCE diff --git a/sys/cddl/compat/opensolaris/sys/mutex.h b/sys/cddl/compat/opensolaris/sys/mutex.h index f6858a7..ef05891 100644 --- a/sys/cddl/compat/opensolaris/sys/mutex.h +++ b/sys/cddl/compat/opensolaris/sys/mutex.h @@ -54,7 +54,7 @@ typedef struct sx kmutex_t; #define mutex_init(lock, desc, type, arg) do { \ const char *_name; \ - ASSERT((type) == MUTEX_DEFAULT); \ + ASSERT((type) == 0 || (type) == MUTEX_DEFAULT); \ KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) != \ LO_EXPECTED, ("lock %s already initialized", #lock)); \ bzero((lock), sizeof(struct sx)); \ diff --git a/sys/cddl/compat/opensolaris/sys/policy.h b/sys/cddl/compat/opensolaris/sys/policy.h index f61859b..0b968ae 100644 --- a/sys/cddl/compat/opensolaris/sys/policy.h +++ b/sys/cddl/compat/opensolaris/sys/policy.h @@ -36,41 +36,39 @@ #include <sys/vnode.h> struct mount; -struct ucred; struct vattr; -struct vnode; -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, uid_t owner); -int secpolicy_vnode_stky_modify(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 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 vnode *vp, struct ucred *cred, - gid_t gid); -int secpolicy_vnode_setid_retain(struct vnode *vp, struct ucred *cred, +int secpolicy_nfs(cred_t *cr); +int secpolicy_zfs(cred_t *crd); +int secpolicy_sys_config(cred_t *cr, int checkonly); +int secpolicy_zinject(cred_t *cr); +int secpolicy_fs_unmount(cred_t *cr, struct mount *vfsp); +int secpolicy_basic_link(vnode_t *vp, cred_t *cr); +int secpolicy_vnode_owner(vnode_t *vp, cred_t *cr, uid_t owner); +int secpolicy_vnode_chown(vnode_t *vp, cred_t *cr, uid_t owner); +int secpolicy_vnode_stky_modify(cred_t *cr); +int secpolicy_vnode_remove(vnode_t *vp, cred_t *cr); +int secpolicy_vnode_access(cred_t *cr, vnode_t *vp, uid_t owner, + accmode_t accmode); +int secpolicy_vnode_access2(cred_t *cr, vnode_t *vp, uid_t owner, + accmode_t curmode, accmode_t wantmode); +int secpolicy_vnode_any_access(cred_t *cr, vnode_t *vp, uid_t owner); +int secpolicy_vnode_setdac(vnode_t *vp, cred_t *cr, uid_t owner); +int secpolicy_vnode_setattr(cred_t *cr, vnode_t *vp, struct vattr *vap, + const struct vattr *ovap, int flags, + int unlocked_access(void *, int, cred_t *), void *node); +int secpolicy_vnode_create_gid(cred_t *cr); +int secpolicy_vnode_setids_setgids(vnode_t *vp, cred_t *cr, gid_t gid); +int secpolicy_vnode_setid_retain(vnode_t *vp, cred_t *cr, 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); +void secpolicy_setid_clear(struct vattr *vap, vnode_t *vp, cred_t *cr); +int secpolicy_setid_setsticky_clear(vnode_t *vp, struct vattr *vap, + const struct vattr *ovap, cred_t *cr); +int secpolicy_fs_owner(struct mount *vfsp, cred_t *cr); 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(struct vnode *vp, xvattr_t *xvap, uid_t owner, - cred_t *cr, vtype_t vtype); +int secpolicy_xvattr(vnode_t *vp, xvattr_t *xvap, uid_t owner, cred_t *cr, + vtype_t vtype); int secpolicy_smb(cred_t *cr); #endif /* _KERNEL */ diff --git a/sys/cddl/compat/opensolaris/sys/proc.h b/sys/cddl/compat/opensolaris/sys/proc.h index e0b7bc5..9f26f61 100644 --- a/sys/cddl/compat/opensolaris/sys/proc.h +++ b/sys/cddl/compat/opensolaris/sys/proc.h @@ -52,6 +52,8 @@ #define p0 proc0 +#define t_tid td_tid + typedef short pri_t; typedef struct thread _kthread; typedef struct thread kthread_t; diff --git a/sys/cddl/compat/opensolaris/sys/rwlock.h b/sys/cddl/compat/opensolaris/sys/rwlock.h index a3e5515..996a426 100644 --- a/sys/cddl/compat/opensolaris/sys/rwlock.h +++ b/sys/cddl/compat/opensolaris/sys/rwlock.h @@ -37,7 +37,6 @@ #ifdef _KERNEL typedef enum { - RW_DRIVER = 2, /* driver (DDI) rwlock */ RW_DEFAULT = 4 /* kernel default rwlock */ } krw_type_t; @@ -61,6 +60,7 @@ typedef struct sx krwlock_t; #define rw_init(lock, desc, type, arg) do { \ const char *_name; \ + ASSERT((type) == 0 || (type) == RW_DEFAULT); \ KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) != \ LO_EXPECTED, ("lock %s already initialized", #lock)); \ bzero((lock), sizeof(struct sx)); \ diff --git a/sys/cddl/compat/opensolaris/sys/sid.h b/sys/cddl/compat/opensolaris/sys/sid.h index d48b1df..d6c1b0c 100644 --- a/sys/cddl/compat/opensolaris/sys/sid.h +++ b/sys/cddl/compat/opensolaris/sys/sid.h @@ -51,11 +51,28 @@ ksiddomain_rele(ksiddomain_t *kd) kmem_free(kd, sizeof(*kd)); } -static __inline int -ksid_getid(void *ksid) +static __inline uint_t +ksid_getid(ksid_t *ks) { panic("%s has been unexpectedly called", __func__); } +static __inline const char * +ksid_getdomain(ksid_t *ks) +{ + + panic("%s has been unexpectedly called", __func__); +} + +static __inline uint_t +ksid_getrid(ksid_t *ks) +{ + + panic("%s has been unexpectedly called", __func__); +} + +#define kidmap_getsidbyuid(zone, uid, sid_prefix, rid) (1) +#define kidmap_getsidbygid(zone, gid, sid_prefix, rid) (1) + #endif /* _OPENSOLARIS_SYS_SID_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/stat.h b/sys/cddl/compat/opensolaris/sys/stat.h index 5f45ebe..d730184 100644 --- a/sys/cddl/compat/opensolaris/sys/stat.h +++ b/sys/cddl/compat/opensolaris/sys/stat.h @@ -33,6 +33,24 @@ #include_next <sys/stat.h> #define stat64 stat -#define fstat64 fstat +#define MAXOFFSET_T OFF_MAX + +#ifndef _KERNEL +#include <sys/disk.h> + +static __inline int +fstat64(int fd, struct stat *sb) +{ + int ret; + + ret = fstat(fd, sb); + if (ret == 0) { + if (S_ISCHR(sb->st_mode)) + (void)ioctl(fd, DIOCGMEDIASIZE, &sb->st_size); + } + return (ret); +} #endif + +#endif /* !_COMPAT_OPENSOLARIS_SYS_STAT_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/string.h b/sys/cddl/compat/opensolaris/sys/string.h index aeec929..0d7fb4f 100644 --- a/sys/cddl/compat/opensolaris/sys/string.h +++ b/sys/cddl/compat/opensolaris/sys/string.h @@ -32,6 +32,8 @@ #include <sys/libkern.h> char *strpbrk(const char *, const char *); -void strident_canon(char *s, size_t n); +void strident_canon(char *, size_t); +char *kmem_asprintf(const char *, ...); +void strfree(char *); #endif /* _OPENSOLARIS_SYS_STRING_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sunddi.h b/sys/cddl/compat/opensolaris/sys/sunddi.h index 1ca2bf0..1997017 100644 --- a/sys/cddl/compat/opensolaris/sys/sunddi.h +++ b/sys/cddl/compat/opensolaris/sys/sunddi.h @@ -29,10 +29,39 @@ #ifndef _OPENSOLARIS_SYS_SUNDDI_H_ #define _OPENSOLARIS_SYS_SUNDDI_H_ +#ifdef _KERNEL + +#include <sys/kmem.h> +#include <sys/libkern.h> +#include <sys/sysevent.h> + +#define strdup(ptr) strdup((ptr), M_SOLARIS) #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); +int ddi_strtoull(const char *str, char **nptr, int base, + unsigned long long *result); + +#define DDI_SUCCESS (0) +#define DDI_FAILURE (-1) +#define DDI_SLEEP 0x666 + +int ddi_soft_state_init(void **statep, size_t size, size_t nitems); +void ddi_soft_state_fini(void **statep); + +void *ddi_get_soft_state(void *state, int item); +int ddi_soft_state_zalloc(void *state, int item); +void ddi_soft_state_free(void *state, int item); + +int _ddi_log_sysevent(char *vendor, char *class_name, char *subclass_name, + nvlist_t *attr_list, sysevent_id_t *eidp, int flag); +#define ddi_log_sysevent(dip, vendor, class_name, subclass_name, \ + attr_list, eidp, flag) \ + _ddi_log_sysevent((vendor), (class_name), (subclass_name), \ + (attr_list), (eidp), (flag)) + +#endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_SUNDDI_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/sysmacros.h b/sys/cddl/compat/opensolaris/sys/sysmacros.h deleted file mode 100644 index 0afc9ca..0000000 --- a/sys/cddl/compat/opensolaris/sys/sysmacros.h +++ /dev/null @@ -1,143 +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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _OPENSOLARIS_SYS_SYSMACROS_H_ -#define _OPENSOLARIS_SYS_SYSMACROS_H_ - -#include <sys/param.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef ABS -#define ABS(a) ((a) < 0 ? -(a) : (a)) -#endif - -#ifndef SIGNOF -#define SIGNOF(a) ((a) < 0 ? -1 : (a) > 0) -#endif - -/* - * Macro for checking power of 2 address alignment. - */ -#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) - -/* - * Macro to determine if value is a power of 2 - */ -#define ISP2(x) (((x) & ((x) - 1)) == 0) - -/* - * Macros for various sorts of alignment and rounding when the alignment - * is known to be a power of 2. - */ -#define P2ALIGN(x, align) ((x) & -(align)) -#define P2PHASE(x, align) ((x) & ((align) - 1)) -#define P2NPHASE(x, align) (-(x) & ((align) - 1)) -#define P2ROUNDUP(x, align) (-(-(x) & -(align))) -#define P2END(x, align) (-(~(x) & -(align))) -#define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) -#define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1) -/* - * Determine whether two numbers have the same high-order bit. - */ -#define P2SAMEHIGHBIT(x, y) (((x) ^ (y)) < ((x) & (y))) - -/* - * Typed version of the P2* macros. These macros should be used to ensure - * that the result is correctly calculated based on the data type of (x), - * which is passed in as the last argument, regardless of the data - * type of the alignment. For example, if (x) is of type uint64_t, - * and we want to round it up to a page boundary using "PAGESIZE" as - * the alignment, we can do either - * P2ROUNDUP(x, (uint64_t)PAGESIZE) - * or - * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) - */ -#define P2ALIGN_TYPED(x, align, type) \ - ((type)(x) & -(type)(align)) -#define P2PHASE_TYPED(x, align, type) \ - ((type)(x) & ((type)(align) - 1)) -#define P2NPHASE_TYPED(x, align, type) \ - (-(type)(x) & ((type)(align) - 1)) -#define P2ROUNDUP_TYPED(x, align, type) \ - (-(-(type)(x) & -(type)(align))) -#define P2END_TYPED(x, align, type) \ - (-(~(type)(x) & -(type)(align))) -#define P2PHASEUP_TYPED(x, align, phase, type) \ - ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) -#define P2CROSS_TYPED(x, y, align, type) \ - (((type)(x) ^ (type)(y)) > (type)(align) - 1) -#define P2SAMEHIGHBIT_TYPED(x, y, type) \ - (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) - -/* - * Find highest one bit set. - * Returns bit number + 1 of highest bit that is set, otherwise returns 0. - * High order bit is 31 (or 63 in _LP64 kernel). - */ -static __inline int -highbit(ulong_t i) -{ - register int h = 1; - - if (i == 0) - return (0); -#ifdef _LP64 - if (i & 0xffffffff00000000ul) { - h += 32; i >>= 32; - } -#endif - if (i & 0xffff0000) { - h += 16; i >>= 16; - } - if (i & 0xff00) { - h += 8; i >>= 8; - } - if (i & 0xf0) { - h += 4; i >>= 4; - } - if (i & 0xc) { - h += 2; i >>= 2; - } - if (i & 0x2) { - h += 1; - } - return (h); -} - -#ifdef __cplusplus -} -#endif - -#endif /* _OPENSOLARIS_SYS_SYSMACROS_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/systeminfo.h b/sys/cddl/compat/opensolaris/sys/systeminfo.h new file mode 100644 index 0000000..df08f45 --- /dev/null +++ b/sys/cddl/compat/opensolaris/sys/systeminfo.h @@ -0,0 +1,6 @@ +#ifndef _SYS_SYSTEMINFO_H_ +#define _SYS_SYSTEMINFO_H_ + +#define HW_HOSTID_LEN 11 + +#endif /* !_SYS_SYSTEMINFO_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/systm.h b/sys/cddl/compat/opensolaris/sys/systm.h index d4ef17c..136960e 100644 --- a/sys/cddl/compat/opensolaris/sys/systm.h +++ b/sys/cddl/compat/opensolaris/sys/systm.h @@ -29,10 +29,11 @@ #ifndef _OPENSOLARIS_SYS_SYSTM_H_ #define _OPENSOLARIS_SYS_SYSTM_H_ +#ifdef _KERNEL + #include <sys/param.h> #include_next <sys/systm.h> -#ifdef _KERNEL #include <sys/string.h> #define PAGESIZE PAGE_SIZE diff --git a/sys/cddl/compat/opensolaris/sys/taskq.h b/sys/cddl/compat/opensolaris/sys/taskq.h index 9083e6a..eedc4da 100644 --- a/sys/cddl/compat/opensolaris/sys/taskq.h +++ b/sys/cddl/compat/opensolaris/sys/taskq.h @@ -39,6 +39,6 @@ struct ostask { }; taskqid_t taskq_dispatch_safe(taskq_t *tq, task_func_t func, void *arg, - struct ostask *task); + u_int flags, struct ostask *task); #endif /* _OPENSOLARIS_SYS_TASKQ_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/time.h b/sys/cddl/compat/opensolaris/sys/time.h index 4275790..05db50e 100644 --- a/sys/cddl/compat/opensolaris/sys/time.h +++ b/sys/cddl/compat/opensolaris/sys/time.h @@ -38,8 +38,6 @@ typedef longlong_t hrtime_t; -#define LBOLT ((gethrtime() * hz) / NANOSEC) - #if defined(__i386__) || defined(__powerpc__) #define TIMESPEC_OVERFLOW(ts) \ ((ts)->tv_sec < INT32_MIN || (ts)->tv_sec > INT32_MAX) @@ -49,25 +47,23 @@ typedef longlong_t hrtime_t; #endif #ifdef _KERNEL -#define lbolt64 (int64_t)(LBOLT) - static __inline hrtime_t gethrtime(void) { struct timespec ts; hrtime_t nsec; -#if 1 getnanouptime(&ts); -#else - nanouptime(&ts); -#endif nsec = (hrtime_t)ts.tv_sec * NANOSEC + ts.tv_nsec; return (nsec); } #define gethrestime_sec() (time_second) #define gethrestime(ts) getnanotime(ts) +#define gethrtime_waitfree() gethrtime() + +#define ddi_get_lbolt() ((gethrtime() * hz) / NANOSEC) +#define ddi_get_lbolt64() (int64_t)((gethrtime() * hz) / NANOSEC) #else @@ -77,7 +73,6 @@ static __inline hrtime_t gethrtime(void) { return (((u_int64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } - #endif /* _KERNEL */ #endif /* !_OPENSOLARIS_SYS_TIME_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/types.h b/sys/cddl/compat/opensolaris/sys/types.h index aeec27a..4d79b5e 100644 --- a/sys/cddl/compat/opensolaris/sys/types.h +++ b/sys/cddl/compat/opensolaris/sys/types.h @@ -45,6 +45,7 @@ typedef int64_t clock_t; #define MAXNAMELEN 256 typedef struct timespec timestruc_t; +typedef struct timespec timespec_t; typedef u_int uint_t; typedef u_char uchar_t; typedef u_short ushort_t; @@ -59,6 +60,7 @@ typedef id_t zoneid_t; typedef id_t ctid_t; typedef mode_t o_mode_t; typedef uint64_t pgcnt_t; +typedef u_int minor_t; #ifdef _KERNEL @@ -83,7 +85,6 @@ typedef enum { B_FALSE, B_TRUE } boolean_t; typedef longlong_t offset_t; typedef u_longlong_t u_offset_t; typedef uint64_t upad64_t; -typedef struct timespec timespec_t; typedef short pri_t; typedef int32_t daddr32_t; typedef int32_t time32_t; diff --git a/sys/cddl/compat/opensolaris/sys/uio.h b/sys/cddl/compat/opensolaris/sys/uio.h index c3fa0bc..f0edfb1 100644 --- a/sys/cddl/compat/opensolaris/sys/uio.h +++ b/sys/cddl/compat/opensolaris/sys/uio.h @@ -46,10 +46,31 @@ struct uio { }; #endif +#define uio_loffset uio_offset + typedef struct uio uio_t; typedef struct iovec iovec_t; -#define uio_loffset uio_offset +typedef enum xuio_type { + UIOTYPE_ASYNCIO, + UIOTYPE_ZEROCOPY +} xuio_type_t; + +typedef struct xuio { + uio_t xu_uio; + + /* Extended uio fields */ + enum xuio_type xu_type; /* What kind of uio structure? */ + union { + struct { + int xu_zc_rw; + void *xu_zc_priv; + } xu_zc; + } xu_ext; +} xuio_t; + +#define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv +#define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw #ifdef BUILDING_ZFS static __inline int diff --git a/sys/cddl/compat/opensolaris/sys/vfs.h b/sys/cddl/compat/opensolaris/sys/vfs.h index d3a7e38..e1e49ed 100644 --- a/sys/cddl/compat/opensolaris/sys/vfs.h +++ b/sys/cddl/compat/opensolaris/sys/vfs.h @@ -121,9 +121,15 @@ typedef uint64_t vfs_feature_t; #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) +#define VFSFT_SYSATTR_VIEWS 0x100000040 /* Supports sysattr view i/f */ +#define VFSFT_ACCESS_FILTER 0x100000080 /* dirents filtered by access */ +#define VFSFT_REPARSE 0x100000100 /* Supports reparse point */ +#define VFSFT_ZEROCOPY_SUPPORTED 0x100000200 + /* Support loaning /returning cache buffer */ + +#define vfs_set_feature(vfsp, feature) do { } while (0) +#define vfs_clear_feature(vfsp, feature) do { } while (0) +#define vfs_has_feature(vfsp, feature) (0) #endif /* _KERNEL */ diff --git a/sys/cddl/compat/opensolaris/sys/vnode.h b/sys/cddl/compat/opensolaris/sys/vnode.h index 926d034..d653db2 100644 --- a/sys/cddl/compat/opensolaris/sys/vnode.h +++ b/sys/cddl/compat/opensolaris/sys/vnode.h @@ -29,6 +29,8 @@ #ifndef _OPENSOLARIS_SYS_VNODE_H_ #define _OPENSOLARIS_SYS_VNODE_H_ +#ifdef _KERNEL + struct vnode; struct vattr; @@ -60,6 +62,8 @@ typedef struct vop_vector vnodeops_t; #define V_APPEND VAPPEND +#define rootvfs (rootvnode == NULL ? NULL : rootvnode->v_mount) + static __inline int vn_is_readonly(vnode_t *vp) { @@ -70,8 +74,9 @@ 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 \ - || (vp)->v_object->cache != NULL)) + ((vp)->v_object != NULL && \ + ((vp)->v_object->resident_page_count > 0 || \ + (vp)->v_object->cache != NULL)) #define vn_exists(vp) do { } while (0) #define vn_invalid(vp) do { } while (0) #define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0) @@ -93,7 +98,8 @@ vn_is_readonly(vnode_t *vp) #define vnevent_rename_dest_dir(vp, ct) do { } while (0) #define specvp(vp, rdev, type, cr) (VN_HOLD(vp), (vp)) -#define MANDMODE(mode) (0) +#define MANDMODE(mode) (0) +#define MANDLOCK(vp, mode) (0) #define chklock(vp, op, offset, size, mode, ct) (0) #define cleanlocks(vp, pid, foo) do { } while (0) #define cleanshares(vp, pid) do { } while (0) @@ -143,6 +149,7 @@ vattr_init_mask(vattr_t *vap) #define FCREAT O_CREAT #define FTRUNC O_TRUNC +#define FEXCL O_EXCL #define FDSYNC FFSYNC #define FRSYNC FFSYNC #define FSYNC FFSYNC @@ -165,7 +172,8 @@ vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode, ASSERT(crwhy == CRCREAT); operation = CREATE; } else { - ASSERT(filemode == (FREAD | FWRITE | FOFFMAX)); + ASSERT(filemode == (FREAD | FOFFMAX) || + filemode == (FREAD | FWRITE | FOFFMAX)); ASSERT(crwhy == 0); operation = LOOKUP; } @@ -292,4 +300,6 @@ vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag) return (kern_unlink(curthread, fnamep, seg)); } +#endif /* _KERNEL */ + #endif /* _OPENSOLARIS_SYS_VNODE_H_ */ diff --git a/sys/cddl/compat/opensolaris/sys/zone.h b/sys/cddl/compat/opensolaris/sys/zone.h index d761310..e8eb2c6 100644 --- a/sys/cddl/compat/opensolaris/sys/zone.h +++ b/sys/cddl/compat/opensolaris/sys/zone.h @@ -57,6 +57,13 @@ extern int zone_dataset_detach(struct ucred *, const char *, int); */ extern int zone_dataset_visible(const char *, int *); +/* + * Safely get the hostid of the specified zone (defaults to machine's hostid + * if the specified zone doesn't emulate a hostid). Passing NULL retrieves + * the global zone's (i.e., physical system's) hostid. + */ +extern uint32_t zone_get_hostid(void *); + #else /* !_KERNEL */ #define GLOBAL_ZONEID 0 |