zdb_il.c revision 200724
1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22200724Sdelphij * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23168404Spjd * Use is subject to license terms. 24168404Spjd */ 25168404Spjd 26168404Spjd/* 27168404Spjd * Print intent log header and statistics. 28168404Spjd */ 29168404Spjd 30168404Spjd#include <stdio.h> 31168404Spjd#include <stdlib.h> 32168404Spjd#include <ctype.h> 33168404Spjd#include <sys/zfs_context.h> 34168404Spjd#include <sys/spa.h> 35168404Spjd#include <sys/dmu.h> 36168404Spjd#include <sys/stat.h> 37168404Spjd#include <sys/resource.h> 38168404Spjd#include <sys/zil.h> 39168404Spjd#include <sys/zil_impl.h> 40168404Spjd 41168404Spjdextern uint8_t dump_opt[256]; 42168404Spjd 43168404Spjdstatic void 44168404Spjdprint_log_bp(const blkptr_t *bp, const char *prefix) 45168404Spjd{ 46168404Spjd char blkbuf[BP_SPRINTF_LEN]; 47168404Spjd 48168404Spjd sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp); 49168404Spjd (void) printf("%s%s\n", prefix, blkbuf); 50168404Spjd} 51168404Spjd 52168404Spjd/* ARGSUSED */ 53168404Spjdstatic void 54168404Spjdzil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr) 55168404Spjd{ 56168404Spjd time_t crtime = lr->lr_crtime[0]; 57168404Spjd char *name = (char *)(lr + 1); 58168404Spjd char *link = name + strlen(name) + 1; 59168404Spjd 60168404Spjd if (txtype == TX_SYMLINK) 61168404Spjd (void) printf("\t\t\t%s -> %s\n", name, link); 62168404Spjd else 63168404Spjd (void) printf("\t\t\t%s\n", name); 64168404Spjd 65168404Spjd (void) printf("\t\t\t%s", ctime(&crtime)); 66168404Spjd (void) printf("\t\t\tdoid %llu, foid %llu, mode %llo\n", 67168404Spjd (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid, 68168404Spjd (longlong_t)lr->lr_mode); 69168404Spjd (void) printf("\t\t\tuid %llu, gid %llu, gen %llu, rdev 0x%llx\n", 70168404Spjd (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid, 71168404Spjd (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev); 72168404Spjd} 73168404Spjd 74168404Spjd/* ARGSUSED */ 75168404Spjdstatic void 76168404Spjdzil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr) 77168404Spjd{ 78168404Spjd (void) printf("\t\t\tdoid %llu, name %s\n", 79168404Spjd (u_longlong_t)lr->lr_doid, (char *)(lr + 1)); 80168404Spjd} 81168404Spjd 82168404Spjd/* ARGSUSED */ 83168404Spjdstatic void 84168404Spjdzil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr) 85168404Spjd{ 86168404Spjd (void) printf("\t\t\tdoid %llu, link_obj %llu, name %s\n", 87168404Spjd (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj, 88168404Spjd (char *)(lr + 1)); 89168404Spjd} 90168404Spjd 91168404Spjd/* ARGSUSED */ 92168404Spjdstatic void 93168404Spjdzil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr) 94168404Spjd{ 95168404Spjd char *snm = (char *)(lr + 1); 96168404Spjd char *tnm = snm + strlen(snm) + 1; 97168404Spjd 98168404Spjd (void) printf("\t\t\tsdoid %llu, tdoid %llu\n", 99168404Spjd (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid); 100168404Spjd (void) printf("\t\t\tsrc %s tgt %s\n", snm, tnm); 101168404Spjd} 102168404Spjd 103168404Spjd/* ARGSUSED */ 104168404Spjdstatic void 105168404Spjdzil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr) 106168404Spjd{ 107168404Spjd char *data, *dlimit; 108168404Spjd blkptr_t *bp = &lr->lr_blkptr; 109168404Spjd char buf[SPA_MAXBLOCKSIZE]; 110168404Spjd int verbose = MAX(dump_opt['d'], dump_opt['i']); 111168404Spjd int error; 112168404Spjd 113168404Spjd (void) printf("\t\t\tfoid %llu, offset 0x%llx," 114168404Spjd " length 0x%llx, blkoff 0x%llx\n", 115168404Spjd (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset, 116168404Spjd (u_longlong_t)lr->lr_length, (u_longlong_t)lr->lr_blkoff); 117168404Spjd 118168404Spjd if (verbose < 5) 119168404Spjd return; 120168404Spjd 121168404Spjd if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) { 122168404Spjd (void) printf("\t\t\thas blkptr, %s\n", 123168404Spjd bp->blk_birth >= spa_first_txg(zilog->zl_spa) ? 124168404Spjd "will claim" : "won't claim"); 125168404Spjd print_log_bp(bp, "\t\t\t"); 126168404Spjd if (bp->blk_birth == 0) { 127168404Spjd bzero(buf, sizeof (buf)); 128168404Spjd } else { 129168404Spjd zbookmark_t zb; 130168404Spjd 131168404Spjd ASSERT3U(bp->blk_cksum.zc_word[ZIL_ZC_OBJSET], ==, 132168404Spjd dmu_objset_id(zilog->zl_os)); 133168404Spjd 134168404Spjd zb.zb_objset = bp->blk_cksum.zc_word[ZIL_ZC_OBJSET]; 135168404Spjd zb.zb_object = 0; 136168404Spjd zb.zb_level = -1; 137168404Spjd zb.zb_blkid = bp->blk_cksum.zc_word[ZIL_ZC_SEQ]; 138168404Spjd 139168404Spjd error = zio_wait(zio_read(NULL, zilog->zl_spa, 140168404Spjd bp, buf, BP_GET_LSIZE(bp), NULL, NULL, 141168404Spjd ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb)); 142168404Spjd if (error) 143168404Spjd return; 144168404Spjd } 145168404Spjd data = buf + lr->lr_blkoff; 146168404Spjd } else { 147168404Spjd data = (char *)(lr + 1); 148168404Spjd } 149168404Spjd 150168404Spjd dlimit = data + MIN(lr->lr_length, 151168404Spjd (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE)); 152168404Spjd 153168404Spjd (void) printf("\t\t\t"); 154168404Spjd while (data < dlimit) { 155168404Spjd if (isprint(*data)) 156168404Spjd (void) printf("%c ", *data); 157168404Spjd else 158168404Spjd (void) printf("%2X", *data); 159168404Spjd data++; 160168404Spjd } 161168404Spjd (void) printf("\n"); 162168404Spjd} 163168404Spjd 164168404Spjd/* ARGSUSED */ 165168404Spjdstatic void 166168404Spjdzil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr) 167168404Spjd{ 168168404Spjd (void) printf("\t\t\tfoid %llu, offset 0x%llx, length 0x%llx\n", 169168404Spjd (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset, 170168404Spjd (u_longlong_t)lr->lr_length); 171168404Spjd} 172168404Spjd 173168404Spjd/* ARGSUSED */ 174168404Spjdstatic void 175168404Spjdzil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr) 176168404Spjd{ 177168404Spjd time_t atime = (time_t)lr->lr_atime[0]; 178168404Spjd time_t mtime = (time_t)lr->lr_mtime[0]; 179168404Spjd 180168404Spjd (void) printf("\t\t\tfoid %llu, mask 0x%llx\n", 181168404Spjd (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask); 182168404Spjd 183168404Spjd if (lr->lr_mask & AT_MODE) { 184168404Spjd (void) printf("\t\t\tAT_MODE %llo\n", 185168404Spjd (longlong_t)lr->lr_mode); 186168404Spjd } 187168404Spjd 188168404Spjd if (lr->lr_mask & AT_UID) { 189168404Spjd (void) printf("\t\t\tAT_UID %llu\n", 190168404Spjd (u_longlong_t)lr->lr_uid); 191168404Spjd } 192168404Spjd 193168404Spjd if (lr->lr_mask & AT_GID) { 194168404Spjd (void) printf("\t\t\tAT_GID %llu\n", 195168404Spjd (u_longlong_t)lr->lr_gid); 196168404Spjd } 197168404Spjd 198168404Spjd if (lr->lr_mask & AT_SIZE) { 199168404Spjd (void) printf("\t\t\tAT_SIZE %llu\n", 200168404Spjd (u_longlong_t)lr->lr_size); 201168404Spjd } 202168404Spjd 203168404Spjd if (lr->lr_mask & AT_ATIME) { 204168404Spjd (void) printf("\t\t\tAT_ATIME %llu.%09llu %s", 205168404Spjd (u_longlong_t)lr->lr_atime[0], 206168404Spjd (u_longlong_t)lr->lr_atime[1], 207168404Spjd ctime(&atime)); 208168404Spjd } 209168404Spjd 210168404Spjd if (lr->lr_mask & AT_MTIME) { 211168404Spjd (void) printf("\t\t\tAT_MTIME %llu.%09llu %s", 212168404Spjd (u_longlong_t)lr->lr_mtime[0], 213168404Spjd (u_longlong_t)lr->lr_mtime[1], 214168404Spjd ctime(&mtime)); 215168404Spjd } 216168404Spjd} 217168404Spjd 218168404Spjd/* ARGSUSED */ 219168404Spjdstatic void 220168404Spjdzil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr) 221168404Spjd{ 222168404Spjd (void) printf("\t\t\tfoid %llu, aclcnt %llu\n", 223168404Spjd (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt); 224168404Spjd} 225168404Spjd 226168404Spjdtypedef void (*zil_prt_rec_func_t)(); 227168404Spjdtypedef struct zil_rec_info { 228168404Spjd zil_prt_rec_func_t zri_print; 229168404Spjd char *zri_name; 230168404Spjd uint64_t zri_count; 231168404Spjd} zil_rec_info_t; 232168404Spjd 233168404Spjdstatic zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = { 234185029Spjd { NULL, "Total " }, 235185029Spjd { zil_prt_rec_create, "TX_CREATE " }, 236185029Spjd { zil_prt_rec_create, "TX_MKDIR " }, 237185029Spjd { zil_prt_rec_create, "TX_MKXATTR " }, 238185029Spjd { zil_prt_rec_create, "TX_SYMLINK " }, 239185029Spjd { zil_prt_rec_remove, "TX_REMOVE " }, 240185029Spjd { zil_prt_rec_remove, "TX_RMDIR " }, 241185029Spjd { zil_prt_rec_link, "TX_LINK " }, 242185029Spjd { zil_prt_rec_rename, "TX_RENAME " }, 243185029Spjd { zil_prt_rec_write, "TX_WRITE " }, 244185029Spjd { zil_prt_rec_truncate, "TX_TRUNCATE " }, 245185029Spjd { zil_prt_rec_setattr, "TX_SETATTR " }, 246185029Spjd { zil_prt_rec_acl, "TX_ACL_V0 " }, 247185029Spjd { zil_prt_rec_acl, "TX_ACL_ACL " }, 248185029Spjd { zil_prt_rec_create, "TX_CREATE_ACL " }, 249185029Spjd { zil_prt_rec_create, "TX_CREATE_ATTR " }, 250185029Spjd { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " }, 251185029Spjd { zil_prt_rec_create, "TX_MKDIR_ACL " }, 252185029Spjd { zil_prt_rec_create, "TX_MKDIR_ATTR " }, 253185029Spjd { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " }, 254168404Spjd}; 255168404Spjd 256168404Spjd/* ARGSUSED */ 257168404Spjdstatic void 258168404Spjdprint_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg) 259168404Spjd{ 260168404Spjd int txtype; 261168404Spjd int verbose = MAX(dump_opt['d'], dump_opt['i']); 262168404Spjd 263185029Spjd /* reduce size of txtype to strip off TX_CI bit */ 264168404Spjd txtype = lr->lrc_txtype; 265168404Spjd 266168404Spjd ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE); 267168404Spjd ASSERT(lr->lrc_txg); 268168404Spjd 269185029Spjd (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n", 270185029Spjd (lr->lrc_txtype & TX_CI) ? "CI-" : "", 271168404Spjd zil_rec_info[txtype].zri_name, 272168404Spjd (u_longlong_t)lr->lrc_reclen, 273168404Spjd (u_longlong_t)lr->lrc_txg, 274168404Spjd (u_longlong_t)lr->lrc_seq); 275168404Spjd 276168404Spjd if (txtype && verbose >= 3) 277168404Spjd zil_rec_info[txtype].zri_print(zilog, txtype, lr); 278168404Spjd 279168404Spjd zil_rec_info[txtype].zri_count++; 280168404Spjd zil_rec_info[0].zri_count++; 281168404Spjd} 282168404Spjd 283168404Spjd/* ARGSUSED */ 284168404Spjdstatic void 285168404Spjdprint_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg) 286168404Spjd{ 287168404Spjd char blkbuf[BP_SPRINTF_LEN]; 288168404Spjd int verbose = MAX(dump_opt['d'], dump_opt['i']); 289168404Spjd char *claim; 290168404Spjd 291168404Spjd if (verbose <= 3) 292168404Spjd return; 293168404Spjd 294168404Spjd if (verbose >= 5) { 295168404Spjd (void) strcpy(blkbuf, ", "); 296168404Spjd sprintf_blkptr(blkbuf + strlen(blkbuf), 297168404Spjd BP_SPRINTF_LEN - strlen(blkbuf), bp); 298168404Spjd } else { 299168404Spjd blkbuf[0] = '\0'; 300168404Spjd } 301168404Spjd 302168404Spjd if (claim_txg != 0) 303168404Spjd claim = "already claimed"; 304168404Spjd else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa)) 305168404Spjd claim = "will claim"; 306168404Spjd else 307168404Spjd claim = "won't claim"; 308168404Spjd 309168404Spjd (void) printf("\tBlock seqno %llu, %s%s\n", 310168404Spjd (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf); 311168404Spjd} 312168404Spjd 313168404Spjdstatic void 314168404Spjdprint_log_stats(int verbose) 315168404Spjd{ 316168404Spjd int i, w, p10; 317168404Spjd 318168404Spjd if (verbose > 3) 319168404Spjd (void) printf("\n"); 320168404Spjd 321168404Spjd if (zil_rec_info[0].zri_count == 0) 322168404Spjd return; 323168404Spjd 324168404Spjd for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10) 325168404Spjd w++; 326168404Spjd 327168404Spjd for (i = 0; i < TX_MAX_TYPE; i++) 328168404Spjd if (zil_rec_info[i].zri_count || verbose >= 3) 329168404Spjd (void) printf("\t\t%s %*llu\n", 330168404Spjd zil_rec_info[i].zri_name, w, 331168404Spjd (u_longlong_t)zil_rec_info[i].zri_count); 332168404Spjd (void) printf("\n"); 333168404Spjd} 334168404Spjd 335168404Spjd/* ARGSUSED */ 336168404Spjdvoid 337168404Spjddump_intent_log(zilog_t *zilog) 338168404Spjd{ 339168404Spjd const zil_header_t *zh = zilog->zl_header; 340168404Spjd int verbose = MAX(dump_opt['d'], dump_opt['i']); 341168404Spjd int i; 342168404Spjd 343168404Spjd if (zh->zh_log.blk_birth == 0 || verbose < 2) 344168404Spjd return; 345168404Spjd 346200724Sdelphij (void) printf("\n ZIL header: claim_txg %llu, claim_seq %llu", 347200724Sdelphij (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_claim_seq); 348200724Sdelphij (void) printf(" replay_seq %llu, flags 0x%llx\n", 349200724Sdelphij (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags); 350168404Spjd 351168404Spjd if (verbose >= 4) 352168404Spjd print_log_bp(&zh->zh_log, "\n\tfirst block: "); 353168404Spjd 354168404Spjd for (i = 0; i < TX_MAX_TYPE; i++) 355168404Spjd zil_rec_info[i].zri_count = 0; 356168404Spjd 357168404Spjd if (verbose >= 2) { 358168404Spjd (void) printf("\n"); 359168404Spjd (void) zil_parse(zilog, print_log_block, print_log_record, NULL, 360168404Spjd zh->zh_claim_txg); 361168404Spjd print_log_stats(verbose); 362168404Spjd } 363168404Spjd} 364