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 2003 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 <mdb/mdb_modapi.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/buf.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/var.h> 32*7c478bd9Sstevel@tonic-gate #include <vm/page.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include "bio.h" 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate typedef struct buf_walk { 37*7c478bd9Sstevel@tonic-gate uintptr_t bw_hbufbase; /* Base address of hbuf buckets */ 38*7c478bd9Sstevel@tonic-gate struct hbuf *bw_hbufs; /* Snapshot of hbuf buckets */ 39*7c478bd9Sstevel@tonic-gate size_t bw_nhbufs; /* Number of hbuf buckets */ 40*7c478bd9Sstevel@tonic-gate size_t bw_hbufi; /* Current hbuf index */ 41*7c478bd9Sstevel@tonic-gate buf_t *bw_bufp; /* Current buffer */ 42*7c478bd9Sstevel@tonic-gate } buf_walk_t; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate int 45*7c478bd9Sstevel@tonic-gate buf_walk_init(mdb_walk_state_t *wsp) 46*7c478bd9Sstevel@tonic-gate { 47*7c478bd9Sstevel@tonic-gate struct hbuf *hbufs; 48*7c478bd9Sstevel@tonic-gate struct var v; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate uintptr_t hbuf_addr; 51*7c478bd9Sstevel@tonic-gate size_t nbytes; 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate buf_walk_t *bwp; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 56*7c478bd9Sstevel@tonic-gate mdb_warn("only global buf walk supported\n"); 57*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 58*7c478bd9Sstevel@tonic-gate } 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&v, "v") == -1) { 61*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read var struct"); 62*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&hbuf_addr, "hbuf") == -1) { 66*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read hbuf pointer"); 67*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate nbytes = sizeof (struct hbuf) * v.v_hbuf; 71*7c478bd9Sstevel@tonic-gate hbufs = mdb_alloc(nbytes, UM_SLEEP); 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate if (mdb_vread(hbufs, nbytes, hbuf_addr) != nbytes) { 74*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read hbufs"); 75*7c478bd9Sstevel@tonic-gate mdb_free(hbufs, nbytes); 76*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate bwp = mdb_alloc(sizeof (buf_walk_t), UM_SLEEP); 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate bwp->bw_hbufbase = hbuf_addr; 82*7c478bd9Sstevel@tonic-gate bwp->bw_hbufs = hbufs; 83*7c478bd9Sstevel@tonic-gate bwp->bw_nhbufs = v.v_hbuf; 84*7c478bd9Sstevel@tonic-gate bwp->bw_hbufi = 0; 85*7c478bd9Sstevel@tonic-gate bwp->bw_bufp = mdb_alloc(sizeof (buf_t), UM_SLEEP); 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)hbufs[0].b_forw; 88*7c478bd9Sstevel@tonic-gate wsp->walk_data = bwp; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate int 94*7c478bd9Sstevel@tonic-gate buf_walk_step(mdb_walk_state_t *wsp) 95*7c478bd9Sstevel@tonic-gate { 96*7c478bd9Sstevel@tonic-gate buf_walk_t *bwp = wsp->walk_data; 97*7c478bd9Sstevel@tonic-gate uintptr_t addr; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * If the next buf_t address we want is NULL or points back at the 101*7c478bd9Sstevel@tonic-gate * hbuf itself, advance to the next hash bucket. When we reach 102*7c478bd9Sstevel@tonic-gate * bw_nhbufs, we're done. 103*7c478bd9Sstevel@tonic-gate */ 104*7c478bd9Sstevel@tonic-gate while (wsp->walk_addr == NULL || wsp->walk_addr == (bwp->bw_hbufbase + 105*7c478bd9Sstevel@tonic-gate bwp->bw_hbufi * sizeof (struct hbuf))) { 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate if (++bwp->bw_hbufi == bwp->bw_nhbufs) 108*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t) 111*7c478bd9Sstevel@tonic-gate bwp->bw_hbufs[bwp->bw_hbufi].b_forw; 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* 115*7c478bd9Sstevel@tonic-gate * When we have a buf_t address, read the buffer and invoke our 116*7c478bd9Sstevel@tonic-gate * walk callback. We keep the next buf_t address in wsp->walk_addr. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate addr = wsp->walk_addr; 119*7c478bd9Sstevel@tonic-gate (void) mdb_vread(bwp->bw_bufp, sizeof (buf_t), addr); 120*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)bwp->bw_bufp->b_forw; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, bwp->bw_bufp, wsp->walk_cbdata)); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate void 126*7c478bd9Sstevel@tonic-gate buf_walk_fini(mdb_walk_state_t *wsp) 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate buf_walk_t *bwp = wsp->walk_data; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate mdb_free(bwp->bw_hbufs, sizeof (struct hbuf) * bwp->bw_nhbufs); 131*7c478bd9Sstevel@tonic-gate mdb_free(bwp->bw_bufp, sizeof (buf_t)); 132*7c478bd9Sstevel@tonic-gate mdb_free(bwp, sizeof (buf_walk_t)); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 136*7c478bd9Sstevel@tonic-gate int 137*7c478bd9Sstevel@tonic-gate bufpagefind(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 138*7c478bd9Sstevel@tonic-gate { 139*7c478bd9Sstevel@tonic-gate uintptr_t b_addr = addr; 140*7c478bd9Sstevel@tonic-gate uintptr_t arg; 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate page_t p; 143*7c478bd9Sstevel@tonic-gate buf_t b; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate if (argc != 1) 146*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate if (argv->a_type == MDB_TYPE_IMMEDIATE) 149*7c478bd9Sstevel@tonic-gate arg = (uintptr_t)argv->a_un.a_val; 150*7c478bd9Sstevel@tonic-gate else 151*7c478bd9Sstevel@tonic-gate arg = (uintptr_t)mdb_strtoull(argv->a_un.a_str); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate if (mdb_vread(&b, sizeof (buf_t), b_addr) == -1) 154*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate for (addr = (uintptr_t)b.b_pages; addr != NULL; 157*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)p.p_next) { 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate if (addr == arg) { 160*7c478bd9Sstevel@tonic-gate mdb_printf("buf %p has page %p on b_pages list\n", 161*7c478bd9Sstevel@tonic-gate b_addr, addr); 162*7c478bd9Sstevel@tonic-gate break; 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (page_t), addr) == -1) 166*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 170*7c478bd9Sstevel@tonic-gate } 171