Home | History | Annotate | Line # | Download | only in zdb
zdb_il.c revision 1.1.1.2.12.1
      1           1.1  haad /*
      2           1.1  haad  * CDDL HEADER START
      3           1.1  haad  *
      4           1.1  haad  * The contents of this file are subject to the terms of the
      5           1.1  haad  * Common Development and Distribution License (the "License").
      6           1.1  haad  * You may not use this file except in compliance with the License.
      7           1.1  haad  *
      8           1.1  haad  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9           1.1  haad  * or http://www.opensolaris.org/os/licensing.
     10           1.1  haad  * See the License for the specific language governing permissions
     11           1.1  haad  * and limitations under the License.
     12           1.1  haad  *
     13           1.1  haad  * When distributing Covered Code, include this CDDL HEADER in each
     14           1.1  haad  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15           1.1  haad  * If applicable, add the following below this CDDL HEADER, with the
     16           1.1  haad  * fields enclosed by brackets "[]" replaced with your own identifying
     17           1.1  haad  * information: Portions Copyright [yyyy] [name of copyright owner]
     18           1.1  haad  *
     19           1.1  haad  * CDDL HEADER END
     20           1.1  haad  */
     21           1.1  haad /*
     22       1.1.1.2  haad  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23           1.1  haad  * Use is subject to license terms.
     24           1.1  haad  */
     25           1.1  haad 
     26           1.1  haad /*
     27           1.1  haad  * Print intent log header and statistics.
     28           1.1  haad  */
     29           1.1  haad 
     30           1.1  haad #include <stdio.h>
     31           1.1  haad #include <stdlib.h>
     32           1.1  haad #include <ctype.h>
     33           1.1  haad #include <sys/zfs_context.h>
     34           1.1  haad #include <sys/spa.h>
     35           1.1  haad #include <sys/dmu.h>
     36           1.1  haad #include <sys/stat.h>
     37           1.1  haad #include <sys/resource.h>
     38           1.1  haad #include <sys/zil.h>
     39           1.1  haad #include <sys/zil_impl.h>
     40           1.1  haad 
     41           1.1  haad extern uint8_t dump_opt[256];
     42           1.1  haad 
     43       1.1.1.2  haad static char prefix[4] = "\t\t\t";
     44       1.1.1.2  haad 
     45           1.1  haad static void
     46           1.1  haad print_log_bp(const blkptr_t *bp, const char *prefix)
     47           1.1  haad {
     48           1.1  haad 	char blkbuf[BP_SPRINTF_LEN];
     49           1.1  haad 
     50  1.1.1.2.12.1   tls 	snprintf_blkptr(blkbuf, sizeof(blkbuf), bp);
     51           1.1  haad 	(void) printf("%s%s\n", prefix, blkbuf);
     52           1.1  haad }
     53           1.1  haad 
     54           1.1  haad /* ARGSUSED */
     55           1.1  haad static void
     56           1.1  haad zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
     57           1.1  haad {
     58           1.1  haad 	time_t crtime = lr->lr_crtime[0];
     59       1.1.1.2  haad 	char *name, *link;
     60       1.1.1.2  haad 	lr_attr_t *lrattr;
     61           1.1  haad 
     62       1.1.1.2  haad 	name = (char *)(lr + 1);
     63           1.1  haad 
     64       1.1.1.2  haad 	if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
     65       1.1.1.2  haad 	    lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
     66       1.1.1.2  haad 		lrattr = (lr_attr_t *)(lr + 1);
     67       1.1.1.2  haad 		name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
     68       1.1.1.2  haad 	}
     69       1.1.1.2  haad 
     70       1.1.1.2  haad 	if (txtype == TX_SYMLINK) {
     71       1.1.1.2  haad 		link = name + strlen(name) + 1;
     72       1.1.1.2  haad 		(void) printf("%s%s -> %s\n", prefix, name, link);
     73       1.1.1.2  haad 	} else if (txtype != TX_MKXATTR) {
     74       1.1.1.2  haad 		(void) printf("%s%s\n", prefix, name);
     75       1.1.1.2  haad 	}
     76       1.1.1.2  haad 
     77       1.1.1.2  haad 	(void) printf("%s%s", prefix, ctime(&crtime));
     78       1.1.1.2  haad 	(void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
     79           1.1  haad 	    (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
     80           1.1  haad 	    (longlong_t)lr->lr_mode);
     81       1.1.1.2  haad 	(void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
     82           1.1  haad 	    (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
     83           1.1  haad 	    (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
     84           1.1  haad }
     85           1.1  haad 
     86           1.1  haad /* ARGSUSED */
     87           1.1  haad static void
     88           1.1  haad zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
     89           1.1  haad {
     90       1.1.1.2  haad 	(void) printf("%sdoid %llu, name %s\n", prefix,
     91           1.1  haad 	    (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
     92           1.1  haad }
     93           1.1  haad 
     94           1.1  haad /* ARGSUSED */
     95           1.1  haad static void
     96           1.1  haad zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
     97           1.1  haad {
     98       1.1.1.2  haad 	(void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
     99           1.1  haad 	    (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
    100           1.1  haad 	    (char *)(lr + 1));
    101           1.1  haad }
    102           1.1  haad 
    103           1.1  haad /* ARGSUSED */
    104           1.1  haad static void
    105           1.1  haad zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
    106           1.1  haad {
    107           1.1  haad 	char *snm = (char *)(lr + 1);
    108           1.1  haad 	char *tnm = snm + strlen(snm) + 1;
    109           1.1  haad 
    110       1.1.1.2  haad 	(void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
    111           1.1  haad 	    (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
    112       1.1.1.2  haad 	(void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
    113           1.1  haad }
    114           1.1  haad 
    115           1.1  haad /* ARGSUSED */
    116           1.1  haad static void
    117           1.1  haad zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
    118           1.1  haad {
    119           1.1  haad 	char *data, *dlimit;
    120           1.1  haad 	blkptr_t *bp = &lr->lr_blkptr;
    121       1.1.1.2  haad 	zbookmark_t zb;
    122           1.1  haad 	char buf[SPA_MAXBLOCKSIZE];
    123           1.1  haad 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
    124           1.1  haad 	int error;
    125           1.1  haad 
    126       1.1.1.2  haad 	(void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
    127       1.1.1.2  haad 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
    128       1.1.1.2  haad 	    (u_longlong_t)lr->lr_length);
    129           1.1  haad 
    130       1.1.1.2  haad 	if (txtype == TX_WRITE2 || verbose < 5)
    131           1.1  haad 		return;
    132           1.1  haad 
    133           1.1  haad 	if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
    134       1.1.1.2  haad 		(void) printf("%shas blkptr, %s\n", prefix,
    135           1.1  haad 		    bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
    136           1.1  haad 		    "will claim" : "won't claim");
    137       1.1.1.2  haad 		print_log_bp(bp, prefix);
    138       1.1.1.2  haad 
    139       1.1.1.2  haad 		if (BP_IS_HOLE(bp)) {
    140       1.1.1.2  haad 			(void) printf("\t\t\tLSIZE 0x%llx\n",
    141       1.1.1.2  haad 			    (u_longlong_t)BP_GET_LSIZE(bp));
    142       1.1.1.2  haad 		}
    143           1.1  haad 		if (bp->blk_birth == 0) {
    144           1.1  haad 			bzero(buf, sizeof (buf));
    145       1.1.1.2  haad 			(void) printf("%s<hole>\n", prefix);
    146       1.1.1.2  haad 			return;
    147       1.1.1.2  haad 		}
    148       1.1.1.2  haad 		if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
    149       1.1.1.2  haad 			(void) printf("%s<block already committed>\n", prefix);
    150       1.1.1.2  haad 			return;
    151           1.1  haad 		}
    152       1.1.1.2  haad 
    153       1.1.1.2  haad 		SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
    154       1.1.1.2  haad 		    lr->lr_foid, ZB_ZIL_LEVEL,
    155       1.1.1.2  haad 		    lr->lr_offset / BP_GET_LSIZE(bp));
    156       1.1.1.2  haad 
    157       1.1.1.2  haad 		error = zio_wait(zio_read(NULL, zilog->zl_spa,
    158       1.1.1.2  haad 		    bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
    159       1.1.1.2  haad 		    ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
    160       1.1.1.2  haad 		if (error)
    161       1.1.1.2  haad 			return;
    162       1.1.1.2  haad 		data = buf;
    163           1.1  haad 	} else {
    164           1.1  haad 		data = (char *)(lr + 1);
    165           1.1  haad 	}
    166           1.1  haad 
    167           1.1  haad 	dlimit = data + MIN(lr->lr_length,
    168           1.1  haad 	    (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
    169           1.1  haad 
    170       1.1.1.2  haad 	(void) printf("%s", prefix);
    171           1.1  haad 	while (data < dlimit) {
    172           1.1  haad 		if (isprint(*data))
    173           1.1  haad 			(void) printf("%c ", *data);
    174           1.1  haad 		else
    175           1.1  haad 			(void) printf("%2X", *data);
    176           1.1  haad 		data++;
    177           1.1  haad 	}
    178           1.1  haad 	(void) printf("\n");
    179           1.1  haad }
    180           1.1  haad 
    181           1.1  haad /* ARGSUSED */
    182           1.1  haad static void
    183           1.1  haad zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
    184           1.1  haad {
    185       1.1.1.2  haad 	(void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
    186           1.1  haad 	    (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
    187           1.1  haad 	    (u_longlong_t)lr->lr_length);
    188           1.1  haad }
    189           1.1  haad 
    190           1.1  haad /* ARGSUSED */
    191           1.1  haad static void
    192           1.1  haad zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
    193           1.1  haad {
    194           1.1  haad 	time_t atime = (time_t)lr->lr_atime[0];
    195           1.1  haad 	time_t mtime = (time_t)lr->lr_mtime[0];
    196           1.1  haad 
    197       1.1.1.2  haad 	(void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
    198           1.1  haad 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
    199           1.1  haad 
    200           1.1  haad 	if (lr->lr_mask & AT_MODE) {
    201       1.1.1.2  haad 		(void) printf("%sAT_MODE  %llo\n", prefix,
    202           1.1  haad 		    (longlong_t)lr->lr_mode);
    203           1.1  haad 	}
    204           1.1  haad 
    205           1.1  haad 	if (lr->lr_mask & AT_UID) {
    206       1.1.1.2  haad 		(void) printf("%sAT_UID   %llu\n", prefix,
    207           1.1  haad 		    (u_longlong_t)lr->lr_uid);
    208           1.1  haad 	}
    209           1.1  haad 
    210           1.1  haad 	if (lr->lr_mask & AT_GID) {
    211       1.1.1.2  haad 		(void) printf("%sAT_GID   %llu\n", prefix,
    212           1.1  haad 		    (u_longlong_t)lr->lr_gid);
    213           1.1  haad 	}
    214           1.1  haad 
    215           1.1  haad 	if (lr->lr_mask & AT_SIZE) {
    216       1.1.1.2  haad 		(void) printf("%sAT_SIZE  %llu\n", prefix,
    217           1.1  haad 		    (u_longlong_t)lr->lr_size);
    218           1.1  haad 	}
    219           1.1  haad 
    220           1.1  haad 	if (lr->lr_mask & AT_ATIME) {
    221       1.1.1.2  haad 		(void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
    222           1.1  haad 		    (u_longlong_t)lr->lr_atime[0],
    223           1.1  haad 		    (u_longlong_t)lr->lr_atime[1],
    224           1.1  haad 		    ctime(&atime));
    225           1.1  haad 	}
    226           1.1  haad 
    227           1.1  haad 	if (lr->lr_mask & AT_MTIME) {
    228       1.1.1.2  haad 		(void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
    229           1.1  haad 		    (u_longlong_t)lr->lr_mtime[0],
    230           1.1  haad 		    (u_longlong_t)lr->lr_mtime[1],
    231           1.1  haad 		    ctime(&mtime));
    232           1.1  haad 	}
    233           1.1  haad }
    234           1.1  haad 
    235           1.1  haad /* ARGSUSED */
    236           1.1  haad static void
    237           1.1  haad zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
    238           1.1  haad {
    239       1.1.1.2  haad 	(void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
    240           1.1  haad 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
    241           1.1  haad }
    242           1.1  haad 
    243           1.1  haad typedef void (*zil_prt_rec_func_t)();
    244           1.1  haad typedef struct zil_rec_info {
    245           1.1  haad 	zil_prt_rec_func_t	zri_print;
    246           1.1  haad 	char			*zri_name;
    247           1.1  haad 	uint64_t		zri_count;
    248           1.1  haad } zil_rec_info_t;
    249           1.1  haad 
    250           1.1  haad static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
    251           1.1  haad 	{	NULL,			"Total              " },
    252           1.1  haad 	{	zil_prt_rec_create,	"TX_CREATE          " },
    253           1.1  haad 	{	zil_prt_rec_create,	"TX_MKDIR           " },
    254           1.1  haad 	{	zil_prt_rec_create,	"TX_MKXATTR         " },
    255           1.1  haad 	{	zil_prt_rec_create,	"TX_SYMLINK         " },
    256           1.1  haad 	{	zil_prt_rec_remove,	"TX_REMOVE          " },
    257           1.1  haad 	{	zil_prt_rec_remove,	"TX_RMDIR           " },
    258           1.1  haad 	{	zil_prt_rec_link,	"TX_LINK            " },
    259           1.1  haad 	{	zil_prt_rec_rename,	"TX_RENAME          " },
    260           1.1  haad 	{	zil_prt_rec_write,	"TX_WRITE           " },
    261           1.1  haad 	{	zil_prt_rec_truncate,	"TX_TRUNCATE        " },
    262           1.1  haad 	{	zil_prt_rec_setattr,	"TX_SETATTR         " },
    263           1.1  haad 	{	zil_prt_rec_acl,	"TX_ACL_V0          " },
    264           1.1  haad 	{	zil_prt_rec_acl,	"TX_ACL_ACL         " },
    265           1.1  haad 	{	zil_prt_rec_create,	"TX_CREATE_ACL      " },
    266           1.1  haad 	{	zil_prt_rec_create,	"TX_CREATE_ATTR     " },
    267           1.1  haad 	{	zil_prt_rec_create,	"TX_CREATE_ACL_ATTR " },
    268           1.1  haad 	{	zil_prt_rec_create,	"TX_MKDIR_ACL       " },
    269           1.1  haad 	{	zil_prt_rec_create,	"TX_MKDIR_ATTR      " },
    270           1.1  haad 	{	zil_prt_rec_create,	"TX_MKDIR_ACL_ATTR  " },
    271       1.1.1.2  haad 	{	zil_prt_rec_write,	"TX_WRITE2          " },
    272           1.1  haad };
    273           1.1  haad 
    274           1.1  haad /* ARGSUSED */
    275       1.1.1.2  haad static int
    276           1.1  haad print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
    277           1.1  haad {
    278           1.1  haad 	int txtype;
    279           1.1  haad 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
    280           1.1  haad 
    281           1.1  haad 	/* reduce size of txtype to strip off TX_CI bit */
    282           1.1  haad 	txtype = lr->lrc_txtype;
    283           1.1  haad 
    284           1.1  haad 	ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
    285           1.1  haad 	ASSERT(lr->lrc_txg);
    286           1.1  haad 
    287           1.1  haad 	(void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
    288           1.1  haad 	    (lr->lrc_txtype & TX_CI) ? "CI-" : "",
    289           1.1  haad 	    zil_rec_info[txtype].zri_name,
    290           1.1  haad 	    (u_longlong_t)lr->lrc_reclen,
    291           1.1  haad 	    (u_longlong_t)lr->lrc_txg,
    292           1.1  haad 	    (u_longlong_t)lr->lrc_seq);
    293           1.1  haad 
    294           1.1  haad 	if (txtype && verbose >= 3)
    295           1.1  haad 		zil_rec_info[txtype].zri_print(zilog, txtype, lr);
    296           1.1  haad 
    297           1.1  haad 	zil_rec_info[txtype].zri_count++;
    298           1.1  haad 	zil_rec_info[0].zri_count++;
    299       1.1.1.2  haad 
    300       1.1.1.2  haad 	return (0);
    301           1.1  haad }
    302           1.1  haad 
    303           1.1  haad /* ARGSUSED */
    304       1.1.1.2  haad static int
    305           1.1  haad print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
    306           1.1  haad {
    307       1.1.1.2  haad 	char blkbuf[BP_SPRINTF_LEN + 10];
    308           1.1  haad 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
    309           1.1  haad 	char *claim;
    310           1.1  haad 
    311           1.1  haad 	if (verbose <= 3)
    312       1.1.1.2  haad 		return (0);
    313           1.1  haad 
    314           1.1  haad 	if (verbose >= 5) {
    315           1.1  haad 		(void) strcpy(blkbuf, ", ");
    316  1.1.1.2.12.1   tls 		snprintf_blkptr(blkbuf + strlen(blkbuf),
    317  1.1.1.2.12.1   tls 		    sizeof(blkbuf) - strlen(blkbuf), bp);
    318           1.1  haad 	} else {
    319           1.1  haad 		blkbuf[0] = '\0';
    320           1.1  haad 	}
    321           1.1  haad 
    322           1.1  haad 	if (claim_txg != 0)
    323           1.1  haad 		claim = "already claimed";
    324           1.1  haad 	else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
    325           1.1  haad 		claim = "will claim";
    326           1.1  haad 	else
    327           1.1  haad 		claim = "won't claim";
    328           1.1  haad 
    329           1.1  haad 	(void) printf("\tBlock seqno %llu, %s%s\n",
    330           1.1  haad 	    (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
    331       1.1.1.2  haad 
    332       1.1.1.2  haad 	return (0);
    333           1.1  haad }
    334           1.1  haad 
    335           1.1  haad static void
    336           1.1  haad print_log_stats(int verbose)
    337           1.1  haad {
    338           1.1  haad 	int i, w, p10;
    339           1.1  haad 
    340           1.1  haad 	if (verbose > 3)
    341           1.1  haad 		(void) printf("\n");
    342           1.1  haad 
    343           1.1  haad 	if (zil_rec_info[0].zri_count == 0)
    344           1.1  haad 		return;
    345           1.1  haad 
    346           1.1  haad 	for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
    347           1.1  haad 		w++;
    348           1.1  haad 
    349           1.1  haad 	for (i = 0; i < TX_MAX_TYPE; i++)
    350           1.1  haad 		if (zil_rec_info[i].zri_count || verbose >= 3)
    351           1.1  haad 			(void) printf("\t\t%s %*llu\n",
    352           1.1  haad 			    zil_rec_info[i].zri_name, w,
    353           1.1  haad 			    (u_longlong_t)zil_rec_info[i].zri_count);
    354           1.1  haad 	(void) printf("\n");
    355           1.1  haad }
    356           1.1  haad 
    357           1.1  haad /* ARGSUSED */
    358           1.1  haad void
    359           1.1  haad dump_intent_log(zilog_t *zilog)
    360           1.1  haad {
    361           1.1  haad 	const zil_header_t *zh = zilog->zl_header;
    362           1.1  haad 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
    363           1.1  haad 	int i;
    364           1.1  haad 
    365       1.1.1.2  haad 	if (zh->zh_log.blk_birth == 0 || verbose < 1)
    366           1.1  haad 		return;
    367           1.1  haad 
    368       1.1.1.2  haad 	(void) printf("\n    ZIL header: claim_txg %llu, "
    369       1.1.1.2  haad 	    "claim_blk_seq %llu, claim_lr_seq %llu",
    370       1.1.1.2  haad 	    (u_longlong_t)zh->zh_claim_txg,
    371       1.1.1.2  haad 	    (u_longlong_t)zh->zh_claim_blk_seq,
    372       1.1.1.2  haad 	    (u_longlong_t)zh->zh_claim_lr_seq);
    373       1.1.1.2  haad 	(void) printf(" replay_seq %llu, flags 0x%llx\n",
    374       1.1.1.2  haad 	    (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
    375           1.1  haad 
    376           1.1  haad 	for (i = 0; i < TX_MAX_TYPE; i++)
    377           1.1  haad 		zil_rec_info[i].zri_count = 0;
    378           1.1  haad 
    379           1.1  haad 	if (verbose >= 2) {
    380           1.1  haad 		(void) printf("\n");
    381           1.1  haad 		(void) zil_parse(zilog, print_log_block, print_log_record, NULL,
    382           1.1  haad 		    zh->zh_claim_txg);
    383           1.1  haad 		print_log_stats(verbose);
    384           1.1  haad 	}
    385           1.1  haad }
    386