sata.c revision 2ac302890e472bf0c11db192dd18f12ded6043f6
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/mdb_modapi.h>
#include <note.h>
#include <sys/ddi_impldefs.h>
#include <sys/ddidmareq.h>
#include <time.h>
/*
*/
/*
* Initialize the sata_trace_dmsg_t walker by either using the given starting
* address, or reading the value of the kernel's sata_debug_rbuf pointer.
* We also allocate a sata_trace_dmsg_t for storage, and save this using the
* walk_data pointer.
*/
static int
{
mdb_warn("failed to read 'sata_debug_rbuf'");
return (WALK_ERR);
}
== -1) {
mdb_warn("failed to read sata_trace_rbuf_t at %p",
return (WALK_ERR);
}
}
/*
* Save ptr to head of ring buffer to prevent looping.
*/
return (WALK_NEXT);
}
/*
* At each step, read a sata_trace_dmsg_t into our private storage, and then
* invoke the callback function. We terminate when we reach a NULL next
* pointer.
*/
static int
{
int status;
return (WALK_DONE);
mdb_warn("failed to read sata_trace_dmsg_t at %p",
return (WALK_ERR);
}
wsp->walk_cbdata);
/*
* If we've looped then we're done.
*/
return (status);
}
/*
* The walker's fini function is invoked at the end of each walk. Since we
* dynamically allocated a sata_trace_dmsg_t in sata_dmsg_walk_i, we must
* free it now.
*/
static void
{
}
/*
* This routine is used by the sata_dmsg_dump dcmd to dump content of
* SATA trace ring buffer.
*/
int
{
char drivername[MODMAXNAMELEN];
char pathname[MAXPATHLEN];
char merge[1024];
sizeof (dmsg)) {
mdb_warn("failed to read message pointer in kernel");
return (DCMD_ERR);
}
"[%Y:%03d:%03d:%03d] : %s",
} else {
drivername, sizeof (drivername));
"[%Y:%03d:%03d:%03d] %s%d: %s",
if (print_pathname == TRUE) {
(void) mdb_ddi_pathname(
sizeof (pathname));
}
}
} else {
"[%Y:%03d:%03d:%03d] : %s",
}
(*printed)++;
}
break;
}
}
return (DCMD_OK);
}
/*
* 1. Process flag passed to sata_dmsg_dump dcmd.
* 2. Obtain SATA trace ring buffer pointer.
* 3. Pass SATA trace ring buffer pointer to sata_dmsg_dump()
* to dump content of SATA trace ring buffer.
*/
int
{
int print_pathname = FALSE;
if (argc > 1) {
return (DCMD_USAGE);
}
return (DCMD_USAGE);
}
/*
* If ring buffer address not provided try to obtain
* it using sata_debug_rbuf global.
*/
mdb_warn("Failed to read 'sata_debug_rbuf'.");
return (DCMD_ERR);
}
}
mdb_warn("Failed to read ring buffer in kernel.");
return (DCMD_ERR);
}
mdb_printf("The sata trace ring buffer is empty.\n");
return (DCMD_OK);
}
return (rval);
}
if (printed == 0) {
mdb_warn("Failed to read sata trace ring buffer.");
return (DCMD_ERR);
}
return (rval);
}
/*
* MDB module linkage information:
*
* We declare a list of structures describing our dcmds, a list of structures
* describing our walkers, and a function named _mdb_init to return a pointer
* to our module information.
*/
static const mdb_dcmd_t dcmds[] = {
{ "sata_dmsg_dump", "[-a]", "Dump sata trace debug messages",
{ NULL }
};
static const mdb_walker_t walkers[] = {
{ "sata_dmsg",
"walk ring buffer containing sata trace debug messages",
{ NULL }
};
static const mdb_modinfo_t modinfo = {
};
const mdb_modinfo_t *
_mdb_init(void)
{
return (&modinfo);
}