diff options
| author | Matthew Ahrens <mahrens@delphix.com> | 2014-06-06 12:14:51 -0800 | 
|---|---|---|
| committer | Christopher Siden <chris@delphix.com> | 2014-06-06 13:14:51 -0700 | 
| commit | df15e419cb7359ba56ddddab9045e438d89e7cbc (patch) | |
| tree | 2e272714e5ab0e03910f4dd65f2d6dce634f0129 /usr/src/lib/libzpool | |
| parent | 05d57413471eaaa425913a06edc2ab33ad9b05bc (diff) | |
| download | illumos-joyent-df15e419cb7359ba56ddddab9045e438d89e7cbc.tar.gz | |
4891 want zdb option to dump all metadata
Reviewed by: Sonu Pillai <sonu.pillai@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Garrett D'Amore <garrett@damore.org>
Diffstat (limited to 'usr/src/lib/libzpool')
| -rw-r--r-- | usr/src/lib/libzpool/common/kernel.c | 24 | ||||
| -rw-r--r-- | usr/src/lib/libzpool/common/sys/zfs_context.h | 2 | 
2 files changed, 26 insertions, 0 deletions
| diff --git a/usr/src/lib/libzpool/common/kernel.c b/usr/src/lib/libzpool/common/kernel.c index d030700415..418ef435b0 100644 --- a/usr/src/lib/libzpool/common/kernel.c +++ b/usr/src/lib/libzpool/common/kernel.c @@ -31,6 +31,7 @@  #include <stdlib.h>  #include <string.h>  #include <zlib.h> +#include <libgen.h>  #include <sys/spa.h>  #include <sys/stat.h>  #include <sys/processor.h> @@ -51,6 +52,9 @@ char hw_serial[HW_HOSTID_LEN];  kmutex_t cpu_lock;  vmem_t *zio_arena = NULL; +/* If set, all blocks read will be copied to the specified directory. */ +char *vn_dumpdir = NULL; +  struct utsname utsname = {  	"userland", "libzpool", "1", "1", "na"  }; @@ -394,6 +398,7 @@ int  vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)  {  	int fd; +	int dump_fd;  	vnode_t *vp;  	int old_umask;  	char realpath[MAXPATHLEN]; @@ -442,6 +447,17 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)  	if (flags & FCREAT)  		(void) umask(old_umask); +	if (vn_dumpdir != NULL) { +		char dumppath[MAXPATHLEN]; +		(void) snprintf(dumppath, sizeof (dumppath), +		    "%s/%s", vn_dumpdir, basename(realpath)); +		dump_fd = open64(dumppath, O_CREAT | O_WRONLY, 0666); +		if (dump_fd == -1) +			return (errno); +	} else { +		dump_fd = -1; +	} +  	if (fd == -1)  		return (errno); @@ -457,6 +473,7 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)  	vp->v_fd = fd;  	vp->v_size = st.st_size;  	vp->v_path = spa_strdup(path); +	vp->v_dump_fd = dump_fd;  	return (0);  } @@ -489,6 +506,11 @@ vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset,  	if (uio == UIO_READ) {  		iolen = pread64(vp->v_fd, addr, len, offset); +		if (vp->v_dump_fd != -1) { +			int status = +			    pwrite64(vp->v_dump_fd, addr, iolen, offset); +			ASSERT(status != -1); +		}  	} else {  		/*  		 * To simulate partial disk writes, we split writes into two @@ -515,6 +537,8 @@ void  vn_close(vnode_t *vp)  {  	close(vp->v_fd); +	if (vp->v_dump_fd != -1) +		close(vp->v_dump_fd);  	spa_strfree(vp->v_path);  	umem_free(vp, sizeof (vnode_t));  } diff --git a/usr/src/lib/libzpool/common/sys/zfs_context.h b/usr/src/lib/libzpool/common/sys/zfs_context.h index 5be4df6f0f..5a19542b8f 100644 --- a/usr/src/lib/libzpool/common/sys/zfs_context.h +++ b/usr/src/lib/libzpool/common/sys/zfs_context.h @@ -389,8 +389,10 @@ typedef struct vnode {  	uint64_t	v_size;  	int		v_fd;  	char		*v_path; +	int		v_dump_fd;  } vnode_t; +extern char *vn_dumpdir;  #define	AV_SCANSTAMP_SZ	32		/* length of anti-virus scanstamp */  typedef struct xoptattr { | 
