1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/fs/lofs_node.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/fs/lofs_info.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate typedef struct lnode_walk { 37*7c478bd9Sstevel@tonic-gate struct lobucket *lw_table; /* Snapshot of hash table */ 38*7c478bd9Sstevel@tonic-gate uint_t lw_tabsz; /* Size of hash table */ 39*7c478bd9Sstevel@tonic-gate uint_t lw_tabi; /* Current table index */ 40*7c478bd9Sstevel@tonic-gate lnode_t *lw_lnode; /* Current buffer */ 41*7c478bd9Sstevel@tonic-gate } lnode_walk_t; 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate int 44*7c478bd9Sstevel@tonic-gate lnode_walk_init(mdb_walk_state_t *wsp) 45*7c478bd9Sstevel@tonic-gate { 46*7c478bd9Sstevel@tonic-gate lnode_walk_t *lwp; 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate int lofsfstype; 49*7c478bd9Sstevel@tonic-gate struct vfs vfs; 50*7c478bd9Sstevel@tonic-gate struct loinfo loinfo; 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&lofsfstype, "lofsfstype") == -1) { 53*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'lofsfstype' symbol\n"); 54*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 55*7c478bd9Sstevel@tonic-gate } 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 58*7c478bd9Sstevel@tonic-gate uintptr_t rootvfsp, vfsp; 59*7c478bd9Sstevel@tonic-gate uint_t htsize; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate lwp = mdb_alloc(sizeof (lnode_walk_t), UM_SLEEP); 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate retry: 64*7c478bd9Sstevel@tonic-gate lwp->lw_tabsz = 0; 65*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&rootvfsp, "rootvfs") == -1) { 66*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'rootvfs' symbol\n"); 67*7c478bd9Sstevel@tonic-gate mdb_free(lwp, sizeof (lnode_walk_t)); 68*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate vfsp = rootvfsp; 72*7c478bd9Sstevel@tonic-gate do { 73*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&vfs, sizeof (vfs), vfsp); 74*7c478bd9Sstevel@tonic-gate if (lofsfstype != vfs.vfs_fstype) { 75*7c478bd9Sstevel@tonic-gate vfsp = (uintptr_t)vfs.vfs_next; 76*7c478bd9Sstevel@tonic-gate continue; 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&loinfo, sizeof (struct loinfo), 79*7c478bd9Sstevel@tonic-gate (uintptr_t)vfs.vfs_data); 80*7c478bd9Sstevel@tonic-gate lwp->lw_tabsz += loinfo.li_htsize; 81*7c478bd9Sstevel@tonic-gate vfsp = (uintptr_t)vfs.vfs_next; 82*7c478bd9Sstevel@tonic-gate } while (vfsp != rootvfsp); 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate if (lwp->lw_tabsz == 0) { 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * No lofs filesystems mounted. 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate mdb_free(lwp, sizeof (lnode_walk_t)); 89*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 90*7c478bd9Sstevel@tonic-gate } 91*7c478bd9Sstevel@tonic-gate lwp->lw_table = mdb_alloc(lwp->lw_tabsz * 92*7c478bd9Sstevel@tonic-gate sizeof (struct lobucket), UM_SLEEP); 93*7c478bd9Sstevel@tonic-gate htsize = 0; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate vfsp = rootvfsp; 96*7c478bd9Sstevel@tonic-gate do { 97*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&vfs, sizeof (vfs), vfsp); 98*7c478bd9Sstevel@tonic-gate if (lofsfstype != vfs.vfs_fstype) { 99*7c478bd9Sstevel@tonic-gate vfsp = (uintptr_t)vfs.vfs_next; 100*7c478bd9Sstevel@tonic-gate continue; 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&loinfo, sizeof (struct loinfo), 103*7c478bd9Sstevel@tonic-gate (uintptr_t)vfs.vfs_data); 104*7c478bd9Sstevel@tonic-gate if (htsize + loinfo.li_htsize > lwp->lw_tabsz) { 105*7c478bd9Sstevel@tonic-gate /* 106*7c478bd9Sstevel@tonic-gate * Something must have resized. 107*7c478bd9Sstevel@tonic-gate */ 108*7c478bd9Sstevel@tonic-gate mdb_free(lwp->lw_table, 109*7c478bd9Sstevel@tonic-gate lwp->lw_tabsz * sizeof (struct lobucket)); 110*7c478bd9Sstevel@tonic-gate goto retry; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate (void) mdb_vread(lwp->lw_table + htsize, 113*7c478bd9Sstevel@tonic-gate loinfo.li_htsize * sizeof (struct lobucket), 114*7c478bd9Sstevel@tonic-gate (uintptr_t)loinfo.li_hashtable); 115*7c478bd9Sstevel@tonic-gate htsize += loinfo.li_htsize; 116*7c478bd9Sstevel@tonic-gate vfsp = (uintptr_t)vfs.vfs_next; 117*7c478bd9Sstevel@tonic-gate } while (vfsp != rootvfsp); 118*7c478bd9Sstevel@tonic-gate } else { 119*7c478bd9Sstevel@tonic-gate if (mdb_vread(&vfs, sizeof (vfs_t), wsp->walk_addr) == -1) { 120*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read from '%p'\n", wsp->walk_addr); 121*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate if (lofsfstype != vfs.vfs_fstype) { 124*7c478bd9Sstevel@tonic-gate mdb_warn("%p does not point to a lofs mount vfs\n", 125*7c478bd9Sstevel@tonic-gate wsp->walk_addr); 126*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate if (mdb_vread(&loinfo, sizeof (loinfo), 129*7c478bd9Sstevel@tonic-gate (uintptr_t)vfs.vfs_data) == -1) { 130*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read struct loinfo from '%p'\n", 131*7c478bd9Sstevel@tonic-gate vfs.vfs_data); 132*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate lwp = mdb_alloc(sizeof (lnode_walk_t), UM_SLEEP); 136*7c478bd9Sstevel@tonic-gate lwp->lw_tabsz = loinfo.li_htsize; 137*7c478bd9Sstevel@tonic-gate lwp->lw_table = mdb_alloc(lwp->lw_tabsz * 138*7c478bd9Sstevel@tonic-gate sizeof (struct lobucket), UM_SLEEP); 139*7c478bd9Sstevel@tonic-gate (void) mdb_vread(lwp->lw_table, 140*7c478bd9Sstevel@tonic-gate lwp->lw_tabsz * sizeof (struct lobucket), 141*7c478bd9Sstevel@tonic-gate (uintptr_t)loinfo.li_hashtable); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate lwp->lw_tabi = 0; 144*7c478bd9Sstevel@tonic-gate lwp->lw_lnode = mdb_alloc(sizeof (lnode_t), UM_SLEEP); 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)lwp->lw_table[0].lh_chain; 147*7c478bd9Sstevel@tonic-gate wsp->walk_data = lwp; 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate int 153*7c478bd9Sstevel@tonic-gate lnode_walk_step(mdb_walk_state_t *wsp) 154*7c478bd9Sstevel@tonic-gate { 155*7c478bd9Sstevel@tonic-gate lnode_walk_t *lwp = wsp->walk_data; 156*7c478bd9Sstevel@tonic-gate uintptr_t addr; 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate /* 159*7c478bd9Sstevel@tonic-gate * If the next lnode_t address we want is NULL, advance to the next 160*7c478bd9Sstevel@tonic-gate * hash bucket. When we reach lw_tabsz, we're done. 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate while (wsp->walk_addr == NULL) { 163*7c478bd9Sstevel@tonic-gate if (++lwp->lw_tabi < lwp->lw_tabsz) 164*7c478bd9Sstevel@tonic-gate wsp->walk_addr = 165*7c478bd9Sstevel@tonic-gate (uintptr_t)lwp->lw_table[lwp->lw_tabi].lh_chain; 166*7c478bd9Sstevel@tonic-gate else 167*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * When we have an lnode_t address, read the lnode and invoke the 172*7c478bd9Sstevel@tonic-gate * walk callback. Keep the next lnode_t address in wsp->walk_addr. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate addr = wsp->walk_addr; 175*7c478bd9Sstevel@tonic-gate (void) mdb_vread(lwp->lw_lnode, sizeof (lnode_t), addr); 176*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)lwp->lw_lnode->lo_next; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, lwp->lw_lnode, wsp->walk_cbdata)); 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate void 182*7c478bd9Sstevel@tonic-gate lnode_walk_fini(mdb_walk_state_t *wsp) 183*7c478bd9Sstevel@tonic-gate { 184*7c478bd9Sstevel@tonic-gate lnode_walk_t *lwp = wsp->walk_data; 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate mdb_free(lwp->lw_table, lwp->lw_tabsz * sizeof (struct lobucket)); 187*7c478bd9Sstevel@tonic-gate mdb_free(lwp->lw_lnode, sizeof (lnode_t)); 188*7c478bd9Sstevel@tonic-gate mdb_free(lwp, sizeof (lnode_walk_t)); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 192*7c478bd9Sstevel@tonic-gate static int 193*7c478bd9Sstevel@tonic-gate lnode_format(uintptr_t addr, const void *data, void *private) 194*7c478bd9Sstevel@tonic-gate { 195*7c478bd9Sstevel@tonic-gate const lnode_t *lop = data; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate mdb_printf("%?p %?p %?p\n", 198*7c478bd9Sstevel@tonic-gate addr, lop->lo_vnode, lop->lo_vp); 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 204*7c478bd9Sstevel@tonic-gate int 205*7c478bd9Sstevel@tonic-gate lnode(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 206*7c478bd9Sstevel@tonic-gate { 207*7c478bd9Sstevel@tonic-gate if (argc != 0) 208*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 211*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %?s %?s%</u>\n", 212*7c478bd9Sstevel@tonic-gate "LNODE", "VNODE", "REALVP"); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) { 216*7c478bd9Sstevel@tonic-gate lnode_t lo; 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&lo, sizeof (lo), addr); 219*7c478bd9Sstevel@tonic-gate return (lnode_format(addr, &lo, NULL)); 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate if (mdb_walk("lnode", lnode_format, NULL) == -1) 223*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 229*7c478bd9Sstevel@tonic-gate int 230*7c478bd9Sstevel@tonic-gate lnode2dev(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 231*7c478bd9Sstevel@tonic-gate { 232*7c478bd9Sstevel@tonic-gate lnode_t lo; 233*7c478bd9Sstevel@tonic-gate vnode_t vno; 234*7c478bd9Sstevel@tonic-gate vfs_t vfs; 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate if (argc != 0) 237*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&lo, sizeof (lo), addr); 240*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&vno, sizeof (vno), (uintptr_t)lo.lo_vnode); 241*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&vfs, sizeof (vfs), (uintptr_t)vno.v_vfsp); 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate mdb_printf("lnode %p vfs_dev %0?lx\n", addr, vfs.vfs_dev); 244*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 245*7c478bd9Sstevel@tonic-gate } 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 248*7c478bd9Sstevel@tonic-gate { "lnode", NULL, "print lnode structure(s)", lnode }, 249*7c478bd9Sstevel@tonic-gate { "lnode2dev", ":", "print vfs_dev given lnode", lnode2dev }, 250*7c478bd9Sstevel@tonic-gate { NULL } 251*7c478bd9Sstevel@tonic-gate }; 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 254*7c478bd9Sstevel@tonic-gate { "lnode", "hash of lnode structures", 255*7c478bd9Sstevel@tonic-gate lnode_walk_init, lnode_walk_step, lnode_walk_fini }, 256*7c478bd9Sstevel@tonic-gate { NULL } 257*7c478bd9Sstevel@tonic-gate }; 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { 260*7c478bd9Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers 261*7c478bd9Sstevel@tonic-gate }; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate const mdb_modinfo_t * 264*7c478bd9Sstevel@tonic-gate _mdb_init(void) 265*7c478bd9Sstevel@tonic-gate { 266*7c478bd9Sstevel@tonic-gate return (&modinfo); 267*7c478bd9Sstevel@tonic-gate } 268