diff options
author | pjd <pjd@FreeBSD.org> | 2008-11-17 20:49:29 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2008-11-17 20:49:29 +0000 |
commit | bbe899b96e388a8b82439f81ed3707e0d9c6070d (patch) | |
tree | 81b89fa4ac6467771d5aa291a97f4665981a6108 /cddl/contrib/opensolaris/lib/libzpool | |
parent | d2f579595c362ce27b4d87e2c40e1c4e09b929e3 (diff) | |
download | FreeBSD-src-bbe899b96e388a8b82439f81ed3707e0d9c6070d.zip FreeBSD-src-bbe899b96e388a8b82439f81ed3707e0d9c6070d.tar.gz |
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libzpool')
4 files changed, 295 insertions, 93 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzpool/common/kernel.c b/cddl/contrib/opensolaris/lib/libzpool/common/kernel.c index 30c5a0c..467cf5c 100644 --- a/cddl/contrib/opensolaris/lib/libzpool/common/kernel.c +++ b/cddl/contrib/opensolaris/lib/libzpool/common/kernel.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -101,20 +101,24 @@ void zmutex_init(kmutex_t *mp) { mp->m_owner = NULL; + mp->initialized = B_TRUE; (void) _mutex_init(&mp->m_lock, USYNC_THREAD, NULL); } void zmutex_destroy(kmutex_t *mp) { + ASSERT(mp->initialized == B_TRUE); ASSERT(mp->m_owner == NULL); (void) _mutex_destroy(&(mp)->m_lock); mp->m_owner = (void *)-1UL; + mp->initialized = B_FALSE; } void mutex_enter(kmutex_t *mp) { + ASSERT(mp->initialized == B_TRUE); ASSERT(mp->m_owner != (void *)-1UL); ASSERT(mp->m_owner != curthread); VERIFY(mutex_lock(&mp->m_lock) == 0); @@ -125,6 +129,7 @@ mutex_enter(kmutex_t *mp) int mutex_tryenter(kmutex_t *mp) { + ASSERT(mp->initialized == B_TRUE); ASSERT(mp->m_owner != (void *)-1UL); if (mutex_trylock(&mp->m_lock) == 0) { ASSERT(mp->m_owner == NULL); @@ -138,6 +143,7 @@ mutex_tryenter(kmutex_t *mp) void mutex_exit(kmutex_t *mp) { + ASSERT(mp->initialized == B_TRUE); ASSERT(mp->m_owner == curthread); mp->m_owner = NULL; VERIFY(mutex_unlock(&mp->m_lock) == 0); @@ -146,6 +152,7 @@ mutex_exit(kmutex_t *mp) void * mutex_owner(kmutex_t *mp) { + ASSERT(mp->initialized == B_TRUE); return (mp->m_owner); } @@ -160,7 +167,7 @@ rw_init(krwlock_t *rwlp, char *name, int type, void *arg) { rwlock_init(&rwlp->rw_lock, USYNC_THREAD, NULL); rwlp->rw_owner = NULL; - rwlp->rw_count = 0; + rwlp->initialized = B_TRUE; } void @@ -168,22 +175,23 @@ rw_destroy(krwlock_t *rwlp) { rwlock_destroy(&rwlp->rw_lock); rwlp->rw_owner = (void *)-1UL; - rwlp->rw_count = -2; + rwlp->initialized = B_FALSE; } void rw_enter(krwlock_t *rwlp, krw_t rw) { //ASSERT(!RW_LOCK_HELD(rwlp)); + ASSERT(rwlp->initialized == B_TRUE); ASSERT(rwlp->rw_owner != (void *)-1UL); ASSERT(rwlp->rw_owner != curthread); if (rw == RW_READER) { - (void) rw_rdlock(&rwlp->rw_lock); + VERIFY(rw_rdlock(&rwlp->rw_lock) == 0); ASSERT(rwlp->rw_count >= 0); atomic_add_int(&rwlp->rw_count, 1); } else { - (void) rw_wrlock(&rwlp->rw_lock); + VERIFY(rw_wrlock(&rwlp->rw_lock) == 0); ASSERT(rwlp->rw_count == 0); rwlp->rw_count = -1; rwlp->rw_owner = curthread; @@ -193,6 +201,7 @@ rw_enter(krwlock_t *rwlp, krw_t rw) void rw_exit(krwlock_t *rwlp) { + ASSERT(rwlp->initialized == B_TRUE); ASSERT(rwlp->rw_owner != (void *)-1UL); if (rwlp->rw_owner == curthread) { @@ -205,7 +214,7 @@ rw_exit(krwlock_t *rwlp) ASSERT(rwlp->rw_count > 0); atomic_add_int(&rwlp->rw_count, -1); } - (void) rw_unlock(&rwlp->rw_lock); + VERIFY(rw_unlock(&rwlp->rw_lock) == 0); } int @@ -213,6 +222,7 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw) { int rv; + ASSERT(rwlp->initialized == B_TRUE); ASSERT(rwlp->rw_owner != (void *)-1UL); ASSERT(rwlp->rw_owner != curthread); @@ -241,6 +251,7 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw) int rw_tryupgrade(krwlock_t *rwlp) { + ASSERT(rwlp->initialized == B_TRUE); ASSERT(rwlp->rw_owner != (void *)-1UL); return (0); @@ -422,9 +433,10 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3) return (0); } +/*ARGSUSED*/ int vn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, - int x3, vnode_t *startvp) + int x3, vnode_t *startvp, int fd) { char *realpath = umem_alloc(strlen(path) + 2, UMEM_NOFAIL); int ret; @@ -432,6 +444,7 @@ vn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, ASSERT(startvp == rootdir); (void) sprintf(realpath, "/%s", path); + /* fd ignored for now, need if want to simulate nbmand support */ ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3); umem_free(realpath, strlen(path) + 2); @@ -469,7 +482,7 @@ vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset, } void -vn_close(vnode_t *vp) +vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td) { close(vp->v_fd); spa_strfree(vp->v_path); @@ -657,7 +670,8 @@ kobj_open_file(char *name) vnode_t *vp; /* set vp as the _fd field of the file */ - if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir) != 0) + if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir, + -1) != 0) return ((void *)-1UL); file = umem_zalloc(sizeof (struct _buf), UMEM_NOFAIL); @@ -679,7 +693,7 @@ kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off) void kobj_close_file(struct _buf *file) { - vn_close((vnode_t *)file->_fd); + vn_close((vnode_t *)file->_fd, 0, NULL, NULL); umem_free(file, sizeof (struct _buf)); } @@ -690,7 +704,7 @@ kobj_get_filesize(struct _buf *file, uint64_t *size) vnode_t *vp = (vnode_t *)file->_fd; if (fstat64(vp->v_fd, &st) == -1) { - vn_close(vp); + vn_close(vp, 0, NULL, NULL); return (errno); } *size = st.st_size; @@ -746,10 +760,11 @@ highbit(ulong_t i) } #endif +static int random_fd = -1, urandom_fd = -1; + static int -random_get_bytes_common(uint8_t *ptr, size_t len, char *devname) +random_get_bytes_common(uint8_t *ptr, size_t len, int fd) { - int fd = open(devname, O_RDONLY); size_t resid = len; ssize_t bytes; @@ -757,26 +772,24 @@ random_get_bytes_common(uint8_t *ptr, size_t len, char *devname) while (resid != 0) { bytes = read(fd, ptr, resid); - ASSERT(bytes >= 0); + ASSERT3S(bytes, >=, 0); ptr += bytes; resid -= bytes; } - close(fd); - return (0); } int random_get_bytes(uint8_t *ptr, size_t len) { - return (random_get_bytes_common(ptr, len, "/dev/random")); + return (random_get_bytes_common(ptr, len, random_fd)); } int random_get_pseudo_bytes(uint8_t *ptr, size_t len) { - return (random_get_bytes_common(ptr, len, "/dev/urandom")); + return (random_get_bytes_common(ptr, len, urandom_fd)); } int @@ -815,7 +828,11 @@ kernel_init(int mode) dprintf("physmem = %llu pages (%.2f GB)\n", physmem, (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30)); - snprintf(hw_serial, sizeof (hw_serial), "%ld", gethostid()); + snprintf(hw_serial, sizeof (hw_serial), "%lu", + (unsigned long)gethostid()); + + VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1); + VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1); spa_init(mode); } @@ -824,6 +841,12 @@ void kernel_fini(void) { spa_fini(); + + close(random_fd); + close(urandom_fd); + + random_fd = -1; + urandom_fd = -1; } int @@ -850,3 +873,62 @@ z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen, return (ret); } + +uid_t +crgetuid(cred_t *cr) +{ + return (0); +} + +gid_t +crgetgid(cred_t *cr) +{ + return (0); +} + +int +crgetngroups(cred_t *cr) +{ + return (0); +} + +gid_t * +crgetgroups(cred_t *cr) +{ + return (NULL); +} + +int +zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr) +{ + return (0); +} + +int +zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr) +{ + return (0); +} + +int +zfs_secpolicy_destroy_perms(const char *name, cred_t *cr) +{ + return (0); +} + +ksiddomain_t * +ksid_lookupdomain(const char *dom) +{ + ksiddomain_t *kd; + + kd = umem_zalloc(sizeof (ksiddomain_t), UMEM_NOFAIL); + kd->kd_name = spa_strdup(dom); + return (kd); +} + +void +ksiddomain_rele(ksiddomain_t *ksid) +{ + spa_strfree(ksid->kd_name); + umem_free(ksid, sizeof (ksiddomain_t)); +} diff --git a/cddl/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h b/cddl/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h index 24572c9..971584d 100644 --- a/cddl/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h +++ b/cddl/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h @@ -19,15 +19,13 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _SYS_ZFS_CONTEXT_H #define _SYS_ZFS_CONTEXT_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -64,6 +62,7 @@ extern "C" { #include <fsshare.h> #include <sys/note.h> #include <sys/types.h> +#include <sys/cred.h> #include <sys/atomic.h> #include <sys/sysmacros.h> #include <sys/bitmap.h> @@ -78,8 +77,10 @@ extern "C" { #include <sys/debug.h> #include <sys/sdt.h> #include <sys/kstat.h> +#include <sys/u8_textprep.h> #include <sys/kernel.h> #include <sys/disk.h> +#include <sys/sysevent/eventdefs.h> #include <machine/atomic.h> #define ZFS_EXPORTS_PATH "/etc/zfs/exports" @@ -116,11 +117,12 @@ extern void vcmn_err(int, const char *, __va_list); extern void panic(const char *, ...); extern void vpanic(const char *, __va_list); +#define fm_panic panic + /* This definition is copied from assert.h. */ #if defined(__STDC__) #if __STDC_VERSION__ - 0 >= 199901L -#define verify(EX) (void)((EX) || \ - (__assert_c99(#EX, __FILE__, __LINE__, __func__), 0)) +#define verify(EX) (void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0)) #else #define verify(EX) (void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0)) #endif /* __STDC_VERSION__ - 0 >= 199901L */ @@ -167,11 +169,16 @@ _NOTE(CONSTCOND) } while (0) #endif /* - * Dtrace SDT probes have different signatures in userland than they do in + * DTrace SDT probes have different signatures in userland than they do in * kernel. If they're being used in kernel code, re-define them out of * existence for their counterparts in libzpool. */ +#ifdef DTRACE_PROBE +#undef DTRACE_PROBE +#define DTRACE_PROBE(a) ((void)0) +#endif /* DTRACE_PROBE */ + #ifdef DTRACE_PROBE1 #undef DTRACE_PROBE1 #define DTRACE_PROBE1(a, b, c) ((void)0) @@ -212,8 +219,9 @@ extern kthread_t *zk_thread_create(void (*func)(), void *arg); * Mutexes */ typedef struct kmutex { - void *m_owner; - mutex_t m_lock; + void *m_owner; + boolean_t initialized; + mutex_t m_lock; } kmutex_t; #define MUTEX_DEFAULT USYNC_THREAD @@ -243,6 +251,7 @@ extern void *mutex_owner(kmutex_t *mp); typedef struct krwlock { int rw_count; void *rw_owner; + boolean_t initialized; rwlock_t rw_lock; } krwlock_t; @@ -253,6 +262,7 @@ typedef int krw_t; #define RW_DEFAULT USYNC_THREAD #undef RW_READ_HELD +#define RW_READ_HELD(x) ((x)->rw_owner == NULL && (x)->rw_count > 0) #undef RW_WRITE_HELD #define RW_WRITE_HELD(x) ((x)->rw_owner == curthread) @@ -267,6 +277,11 @@ extern void rw_exit(krwlock_t *rwlp); extern int rw_lock_held(krwlock_t *rwlp); #define rw_downgrade(rwlp) do { } while (0) +extern uid_t crgetuid(cred_t *cr); +extern gid_t crgetgid(cred_t *cr); +extern int crgetngroups(cred_t *cr); +extern gid_t *crgetgroups(cred_t *cr); + /* * Condition variables */ @@ -285,6 +300,7 @@ extern void cv_broadcast(kcondvar_t *cv); * Kernel memory */ #define KM_SLEEP UMEM_NOFAIL +#define KM_PUSHPAGE KM_SLEEP #define KM_NOSLEEP UMEM_DEFAULT #define KMC_NODEBUG UMC_NODEBUG #define kmem_alloc(_s, _f) umem_alloc(_s, _f) @@ -322,6 +338,9 @@ extern void taskq_destroy(taskq_t *); extern void taskq_wait(taskq_t *); extern int taskq_member(taskq_t *, void *); +#define XVA_MAPSIZE 3 +#define XVA_MAGIC 0x78766174 + /* * vnodes */ @@ -331,44 +350,93 @@ typedef struct vnode { char *v_path; } vnode_t; + +typedef struct xoptattr { + timestruc_t xoa_createtime; /* Create time of file */ + uint8_t xoa_archive; + uint8_t xoa_system; + uint8_t xoa_readonly; + uint8_t xoa_hidden; + uint8_t xoa_nounlink; + uint8_t xoa_immutable; + uint8_t xoa_appendonly; + uint8_t xoa_nodump; + uint8_t xoa_settable; + uint8_t xoa_opaque; + uint8_t xoa_av_quarantined; + uint8_t xoa_av_modified; +} xoptattr_t; + typedef struct vattr { uint_t va_mask; /* bit-mask of attributes */ u_offset_t va_size; /* file size in bytes */ } vattr_t; -#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 0x8000 + +typedef struct xvattr { + vattr_t xva_vattr; /* Embedded vattr structure */ + uint32_t xva_magic; /* Magic Number */ + uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ + uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ + uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ + uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ + xoptattr_t xva_xoptattrs; /* Optional attributes */ +} xvattr_t; + +typedef struct vsecattr { + uint_t vsa_mask; /* See below */ + int vsa_aclcnt; /* ACL entry count */ + void *vsa_aclentp; /* pointer to ACL entries */ + int vsa_dfaclcnt; /* default ACL entry count */ + void *vsa_dfaclentp; /* pointer to default ACL entries */ + size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ +} vsecattr_t; + +#define AT_TYPE 0x00001 +#define AT_MODE 0x00002 +#define AT_UID 0x00004 +#define AT_GID 0x00008 +#define AT_FSID 0x00010 +#define AT_NODEID 0x00020 +#define AT_NLINK 0x00040 +#define AT_SIZE 0x00080 +#define AT_ATIME 0x00100 +#define AT_MTIME 0x00200 +#define AT_CTIME 0x00400 +#define AT_RDEV 0x00800 +#define AT_BLKSIZE 0x01000 +#define AT_NBLOCKS 0x02000 +#define AT_SEQ 0x08000 +#define AT_XVATTR 0x10000 #define CRCREAT 0 -#define VOP_CLOSE(vp, f, c, o, cr) 0 -#define VOP_PUTPAGE(vp, of, sz, fl, cr) 0 -#define VOP_GETATTR(vp, vap, fl) ((vap)->va_size = (vp)->v_size, 0) +#define VOP_CLOSE(vp, f, c, o, cr, ct) 0 +#define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 +#define VOP_GETATTR(vp, vap, cr) ((vap)->va_size = (vp)->v_size, 0) -#define VOP_FSYNC(vp, f, cr) fsync((vp)->v_fd) +#define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) -#define VN_RELE(vp) vn_close(vp) +#define VN_RELE(vp) vn_close(vp, 0, NULL, NULL) + +#define vn_lock(vp, type) +#define VOP_UNLOCK(vp, type) +#ifdef VFS_LOCK_GIANT +#undef VFS_LOCK_GIANT +#endif +#define VFS_LOCK_GIANT(mp) 0 +#ifdef VFS_UNLOCK_GIANT +#undef VFS_UNLOCK_GIANT +#endif +#define VFS_UNLOCK_GIANT(vfslocked) extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, int x2, int x3); extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, - int x2, int x3, vnode_t *vp); + int x2, int x3, vnode_t *vp, int fd); extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); -extern void vn_close(vnode_t *vp); +extern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td); #define vn_remove(path, x1, x2) remove(path) #define vn_rename(from, to, seg) rename((from), (to)) @@ -397,8 +465,9 @@ extern void delay(clock_t ticks); #define CPU_SEQID (thr_self() & (max_ncpus - 1)) -#define kcred NULL -#define CRED() NULL +#ifndef ptob +#define ptob(x) ((x) * PAGESIZE) +#endif extern uint64_t physmem; @@ -455,11 +524,31 @@ struct bootstat { uint64_t st_size; }; +typedef struct ace_object { + uid_t a_who; + uint32_t a_access_mask; + uint16_t a_flags; + uint16_t a_type; + uint8_t a_obj_type[16]; + uint8_t a_inherit_obj_type[16]; +} ace_object_t; + + +#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 +#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 +#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 +#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 + extern struct _buf *kobj_open_file(char *name); extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off); extern void kobj_close_file(struct _buf *file); extern int kobj_get_filesize(struct _buf *file, uint64_t *size); +extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); +extern int zfs_secpolicy_rename_perms(const char *from, const char *to, + cred_t *cr); +extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); +extern zoneid_t getzoneid(void); /* Random compatibility stuff. */ #define lbolt (gethrtime() >> 23) #define lbolt64 (gethrtime() >> 23) @@ -482,18 +571,32 @@ struct file { #define FCREAT O_CREAT #define FOFFMAX 0x0 +/* SID stuff */ +typedef struct ksiddomain { + uint_t kd_ref; + uint_t kd_len; + char *kd_name; +} ksiddomain_t; + +ksiddomain_t *ksid_lookupdomain(const char *); +void ksiddomain_rele(ksiddomain_t *); + #define SX_SYSINIT(name, lock, desc) #define SYSCTL_DECL(...) #define SYSCTL_NODE(...) #define SYSCTL_INT(...) +#define SYSCTL_UINT(...) #define SYSCTL_ULONG(...) +#define SYSCTL_QUAD(...) #ifdef TUNABLE_INT #undef TUNABLE_INT #undef TUNABLE_ULONG +#undef TUNABLE_QUAD #endif #define TUNABLE_INT(...) #define TUNABLE_ULONG(...) +#define TUNABLE_QUAD(...) /* Errors */ diff --git a/cddl/contrib/opensolaris/lib/libzpool/common/taskq.c b/cddl/contrib/opensolaris/lib/libzpool/common/taskq.c index f7b6571..ccf5b4d 100644 --- a/cddl/contrib/opensolaris/lib/libzpool/common/taskq.c +++ b/cddl/contrib/opensolaris/lib/libzpool/common/taskq.c @@ -2,9 +2,8 @@ * 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. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -177,6 +176,9 @@ taskq_create(const char *name, int nthreads, pri_t pri, int t; rw_init(&tq->tq_threadlock, NULL, RW_DEFAULT, NULL); + mutex_init(&tq->tq_lock, NULL, MUTEX_DEFAULT, NULL); + cv_init(&tq->tq_dispatch_cv, NULL, CV_DEFAULT, NULL); + cv_init(&tq->tq_wait_cv, NULL, CV_DEFAULT, NULL); tq->tq_flags = flags | TASKQ_ACTIVE; tq->tq_active = nthreads; tq->tq_nthreads = nthreads; @@ -230,6 +232,9 @@ taskq_destroy(taskq_t *tq) kmem_free(tq->tq_threadlist, nthreads * sizeof (thread_t)); rw_destroy(&tq->tq_threadlock); + mutex_destroy(&tq->tq_lock); + cv_destroy(&tq->tq_dispatch_cv); + cv_destroy(&tq->tq_wait_cv); kmem_free(tq, sizeof (taskq_t)); } diff --git a/cddl/contrib/opensolaris/lib/libzpool/common/util.c b/cddl/contrib/opensolaris/lib/libzpool/common/util.c index df49adb..781edb6 100644 --- a/cddl/contrib/opensolaris/lib/libzpool/common/util.c +++ b/cddl/contrib/opensolaris/lib/libzpool/common/util.c @@ -19,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <assert.h> #include <sys/zfs_context.h> #include <sys/avl.h> @@ -67,46 +65,58 @@ nicenum(uint64_t num, char *buf) } static void -show_vdev_stats(const char *desc, nvlist_t *nv, int indent) +show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent) { - nvlist_t **child; - uint_t c, children; vdev_stat_t *vs; + vdev_stat_t v0 = { 0 }; uint64_t sec; + uint64_t is_log = 0; + nvlist_t **child; + uint_t c, children; char used[6], avail[6]; char rops[6], wops[6], rbytes[6], wbytes[6], rerr[6], werr[6], cerr[6]; + char *prefix = ""; - if (indent == 0) { - (void) printf(" " + if (indent == 0 && desc != NULL) { + (void) printf(" " " capacity operations bandwidth ---- errors ----\n"); - (void) printf("description " + (void) printf("description " "used avail read write read write read write cksum\n"); } - VERIFY(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS, - (uint64_t **)&vs, &c) == 0); - - sec = MAX(1, vs->vs_timestamp / NANOSEC); - - nicenum(vs->vs_alloc, used); - nicenum(vs->vs_space - vs->vs_alloc, avail); - nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops); - nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops); - nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes); - nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes); - nicenum(vs->vs_read_errors, rerr); - nicenum(vs->vs_write_errors, werr); - nicenum(vs->vs_checksum_errors, cerr); - - (void) printf("%*s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n", - indent, "", - indent - 19 - (vs->vs_space ? 0 : 12), desc, - vs->vs_space ? 6 : 0, vs->vs_space ? used : "", - vs->vs_space ? 6 : 0, vs->vs_space ? avail : "", - rops, wops, rbytes, wbytes, rerr, werr, cerr); - - if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, - &child, &children) != 0) + if (desc != NULL) { + (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log); + + if (is_log) + prefix = "log "; + + if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS, + (uint64_t **)&vs, &c) != 0) + vs = &v0; + + sec = MAX(1, vs->vs_timestamp / NANOSEC); + + nicenum(vs->vs_alloc, used); + nicenum(vs->vs_space - vs->vs_alloc, avail); + nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops); + nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops); + nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes); + nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes); + nicenum(vs->vs_read_errors, rerr); + nicenum(vs->vs_write_errors, werr); + nicenum(vs->vs_checksum_errors, cerr); + + (void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n", + indent, "", + prefix, + indent + strlen(prefix) - 25 - (vs->vs_space ? 0 : 12), + desc, + vs->vs_space ? 6 : 0, vs->vs_space ? used : "", + vs->vs_space ? 6 : 0, vs->vs_space ? avail : "", + rops, wops, rbytes, wbytes, rerr, werr, cerr); + } + + if (nvlist_lookup_nvlist_array(nv, ctype, &child, &children) != 0) return; for (c = 0; c < children; c++) { @@ -120,7 +130,7 @@ show_vdev_stats(const char *desc, nvlist_t *nv, int indent) (void) strcpy(tname, cname); if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0) tname[strlen(tname)] = '0' + np; - show_vdev_stats(tname, cnv, indent + 2); + show_vdev_stats(tname, ctype, cnv, indent + 2); free(tname); } } @@ -131,14 +141,16 @@ show_pool_stats(spa_t *spa) nvlist_t *config, *nvroot; char *name; - spa_config_enter(spa, RW_READER, FTAG); - config = spa_config_generate(spa, NULL, -1ULL, B_TRUE); - spa_config_exit(spa, FTAG); + VERIFY(spa_get_stats(spa_name(spa), &config, NULL, 0) == 0); VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); VERIFY(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, &name) == 0); - show_vdev_stats(name, nvroot, 0); + show_vdev_stats(name, ZPOOL_CONFIG_CHILDREN, nvroot, 0); + show_vdev_stats(NULL, ZPOOL_CONFIG_L2CACHE, nvroot, 0); + show_vdev_stats(NULL, ZPOOL_CONFIG_SPARES, nvroot, 0); + + nvlist_free(config); } |