/* * This is a simple MDB module that modifies ::lminfo to print the full path to * the vnode instead of truncating it. * * Ray Van Dolson */ #include #include #include #include "mdb_ks.h" #define LM_VNPATHLEN 255 #define LM_OUTLEN 1024 static int lminfo_cb(uintptr_t addr, const void *data, void *priv) { const lock_descriptor_t *ld = data; char buf[LM_VNPATHLEN]; char outbuf[LM_OUTLEN]; char outbuf2[LM_OUTLEN]; char *q, *r; proc_t p; mdb_vnode2path((uintptr_t)ld->l_vnode, buf, sizeof (buf)); mdb_snprintf(outbuf, sizeof(outbuf), "%-?p %2s %04x %6d %-16s %-?p %s", addr, ld->l_type == F_RDLCK ? "RD" : ld->l_type == F_WRLCK ? "WR" : "??", ld->l_state, ld->l_flock.l_pid, ld->l_flock.l_pid == 0 ? "" : mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ? "" : p.p_user.u_comm, ld->l_vnode, buf); /* * mdb_snprintf throws in a random newline because it wants to format * the output for the expected terminal width. Cycle through our output * and copy it into a new output buffer stripping out this extra newline * along the way. */ q = &outbuf[0]; r = &outbuf2[0]; while (*q != '\0') { if (*q != '\n') { *r = *q; r++; } q++; } *r = '\0'; printf("%s\n", outbuf2); return (WALK_NEXT); } int lminfo2(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { if (DCMD_HDRSPEC(flags)) mdb_printf("%%-?s %2s %4s %6s %-16s %-?s %s%\n", "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH"); return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL)); } static const mdb_dcmd_t dcmds[] = { { "lminfo2", NULL, "print lock manager information", lminfo2 }, { NULL } }; static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, NULL }; const mdb_modinfo_t * _mdb_init(void) { return (&modinfo); } /* ex: set sw=8 sts=8 noexpandtab: */