1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
|
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/fs.h>
#include <linux/iobuf.h>
#include <linux/kdb.h>
#include <linux/kdbprivate.h>
#include <linux/blkdev.h>
#include <linux/ctype.h>
MODULE_AUTHOR("SGI");
MODULE_DESCRIPTION("Debug page information");
MODULE_LICENSE("GPL");
/* Standard Linux page stuff */
static char *pg_flag_vals[] = {
"PG_locked", "PG_error", "PG_referenced", "PG_uptodate",
"PG_dirty", "PG_unused_5", "PG_lru", "PG_active",
"PG_slab", "PG_unused_9", "PG_skip", "PG_highmem",
"PG_checked", "PG_arch_1", "PG_reserved", "PG_launder",
NULL };
static char *bh_state_vals[] = {
"Uptodate", "Dirty", "Lock", "Req",
"Mapped", "New", "Async", "Wait_IO",
"Launder", "JBD",
/*XFS*/ "Delay",
NULL };
static char *inode_flag_vals[] = {
"I_DIRTY_SYNC", "I_DIRTY_DATASYNC", "I_DIRTY_PAGES", "I_LOCK",
"I_FREEING", "I_CLEAR",
/*XFS*/ "I_NEW",
NULL };
static char *map_flags(unsigned long flags, char *mapping[])
{
static char buffer[256];
int index;
int offset = 12;
buffer[0] = '\0';
for (index = 0; flags && mapping[index]; flags >>= 1, index++) {
if (flags & 1) {
if ((offset + strlen(mapping[index]) + 1) >= 80) {
strcat(buffer, "\n ");
offset = 12;
} else if (offset > 12) {
strcat(buffer, " ");
offset++;
}
strcat(buffer, mapping[index]);
offset += strlen(mapping[index]);
}
}
return (buffer);
}
static char *page_flags(unsigned long flags)
{
return(map_flags(flags, pg_flag_vals));
}
static int
kdbm_buffers(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct buffer_head bh;
unsigned long addr;
long offset=0;
int nextarg;
int diag;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
(diag = kdb_getarea(bh, addr)))
return(diag);
kdb_printf("buffer_head at 0x%lx\n", addr);
kdb_printf(" next 0x%p bno %ld rsec %ld size %d dev 0x%x rdev 0x%x\n",
bh.b_next, bh.b_blocknr, bh.b_rsector,
bh.b_size, bh.b_dev, bh.b_rdev);
kdb_printf(" count %d state 0x%lx [%s] ftime 0x%lx b_list %d b_reqnext 0x%p b_data 0x%p\n",
bh.b_count.counter, bh.b_state, map_flags(bh.b_state, bh_state_vals),
bh.b_flushtime, bh.b_list, bh.b_reqnext, bh.b_data);
kdb_printf(" b_page 0x%p b_this_page 0x%p b_private 0x%p\n",
bh.b_page, bh.b_this_page, bh.b_private);
return 0;
}
static int
kdbm_page(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct page page;
unsigned long addr;
long offset=0;
int nextarg;
int diag;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
if (diag)
return diag;
if (addr < PAGE_OFFSET) {
printk("Treating 0x%lx as page index, page at 0x%p\n",
addr, &mem_map[addr]);
addr = (unsigned long) &mem_map[addr];
}
if ((diag = kdb_getarea(page, addr)))
return(diag);
kdb_printf("struct page at 0x%lx\n", addr);
kdb_printf(" next 0x%p prev 0x%p addr space 0x%p index %lu (offset 0x%x)\n",
page.list.next, page.list.prev, page.mapping, page.index,
(int)(page.index << PAGE_CACHE_SHIFT));
kdb_printf(" count %d flags %s virtual 0x%p\n",
page.count.counter, page_flags(page.flags),
page.virtual);
kdb_printf(" buffers 0x%p\n", page.buffers);
return 0;
}
unsigned long
print_request(unsigned long addr)
{
struct request rq;
if (kdb_getarea(rq, addr))
return(0);
kdb_printf("struct request at 0x%lx\n", addr);
kdb_printf(" rq_dev 0x%x cmd %d errors %d sector %ld nr_sectors %ld\n",
rq.rq_dev, rq.cmd, rq.errors, rq.sector,
rq.nr_sectors);
kdb_printf(" hsect %ld hnrsect %ld nrseg %d nrhwseg %d currnrsect %ld seq %d\n",
rq.hard_sector, rq.hard_nr_sectors,
rq.nr_segments, rq.nr_hw_segments,
rq.current_nr_sectors, rq.elevator_sequence);
kdb_printf(" ");
kdb_printf("bh 0x%p bhtail 0x%p req_q 0x%p\n\n",
rq.bh, rq.bhtail, rq.q);
return (unsigned long) rq.queue.next;
}
static int
kdbm_request(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
long offset=0;
unsigned long addr;
int nextarg;
int diag;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
if (diag)
return diag;
print_request(addr);
return 0;
}
static int
kdbm_rqueue(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct request_queue rq;
unsigned long addr, head_addr, next;
long offset=0;
int nextarg;
int i, diag;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
(diag = kdb_getarea(rq, addr)))
return(diag);
kdb_printf("struct request_queue at 0x%lx [%s]\n", addr,
rq.plugged ? "plugged" : "running");
kdb_printf(" read free_list [0x%p, 0x%p]\n",
rq.rq[READ].free.prev,
rq.rq[READ].free.next);
kdb_printf(" write free_list [0x%p, 0x%p]\n",
rq.rq[WRITE].free.prev,
rq.rq[WRITE].free.next);
i = 0;
next = (unsigned long)rq.queue_head.next;
head_addr = addr + offsetof(struct request_queue, queue_head);
kdb_printf(" request queue: %s\n", next == head_addr ?
"empty" : "");
while (next != head_addr) {
i++;
next = print_request(next);
}
if (i)
kdb_printf("%d requests found\n", i);
return 0;
}
static void
do_buffer(unsigned long addr)
{
struct buffer_head bh;
if (kdb_getarea(bh, addr))
return;
kdb_printf("bh 0x%lx bno %8ld [%s]\n", addr, bh.b_blocknr,
map_flags(bh.b_state, bh_state_vals));
}
static int
kdbm_inode_pages(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct inode inode;
struct address_space ap;
unsigned long addr, addr1 = 0;
long offset=0;
int nextarg;
int diag;
int which=0;
struct list_head *head, *curr;
if (argc < 1)
return KDB_ARGCOUNT;
nextarg = 1;
diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
if (diag)
return diag;
if (argc == 2) {
nextarg = 2;
diag = kdbgetaddrarg(argc, argv, &nextarg, &addr1,
&offset, NULL, regs);
if (diag)
return diag;
kdb_printf("Looking for page index 0x%lx ... \n", addr1);
}
if ((diag = kdb_getarea(inode, addr)) ||
(diag = kdb_getarea(ap, (unsigned long) inode.i_mapping)))
return(diag);
if (!&inode.i_mapping) goto out;
again:
if (which == 0){
which=1;
head = &inode.i_mapping->clean_pages;
kdb_printf("CLEAN page_struct index cnt flags\n");
} else if (which == 1) {
which=2;
head = &inode.i_mapping->dirty_pages;
kdb_printf("DIRTY page_struct index cnt flags\n");
} else if (which == 2) {
which=3;
head = &inode.i_mapping->locked_pages;
kdb_printf("LOCKED page_struct index cnt flags\n");
} else {
goto out;
}
if(!head) goto again;
curr = head->next;
while (curr != head) {
struct page page;
struct list_head curr_struct;
if ((diag = kdb_getarea(page, (unsigned long) list_entry(curr, struct page, list))))
return(diag);
if (!addr1 || page.index == addr1 ||
(addr1 == -1 && (page.flags & ( 1 << PG_locked))))
{
kdb_printf(" 0x%lx %6lu %5d 0x%lx ",
addr, page.index, page.count.counter,
page.flags);
if (page.buffers)
do_buffer((unsigned long) page.buffers);
}
if ((diag = kdb_getarea(curr_struct, (unsigned long) curr)))
return(diag);
curr = curr_struct.next;
}
goto again;
out:
return 0;
}
static int
kdbm_inode(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct inode inode;
unsigned long addr;
unsigned char *iaddr;
long offset=0;
int nextarg;
int diag;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
(diag = kdb_getarea(inode, addr)))
return(diag);
kdb_printf("struct inode at 0x%lx\n", addr);
kdb_printf(" i_ino = %lu i_count = %u i_dev = 0x%x i_size %Ld\n",
inode.i_ino, atomic_read(&inode.i_count),
inode.i_dev, inode.i_size);
kdb_printf(" i_mode = 0x%x i_nlink = %d i_rdev = 0x%x\n",
inode.i_mode, inode.i_nlink,
inode.i_rdev);
kdb_printf(" i_hash.nxt = 0x%p i_hash.prv = 0x%p\n",
inode.i_hash.next, inode.i_hash.prev);
kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n",
inode.i_list.next, inode.i_list.prev);
kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n",
inode.i_dentry.next,
inode.i_dentry.prev);
kdb_printf(" i_dirty_buffers.nxt = 0x%p i_dirty_buffers.prv = 0x%p\n",
inode.i_dirty_buffers.next,
inode.i_dirty_buffers.prev);
kdb_printf(" i_sb = 0x%p i_op = 0x%p i_data = 0x%lx nrpages = %lu\n",
inode.i_sb, inode.i_op,
addr + offsetof(struct inode, i_data),
inode.i_data.nrpages);
kdb_printf(" i_mapping = 0x%p\n i_flags 0x%x i_state 0x%lx [%s]",
inode.i_mapping, inode.i_flags,
inode.i_state,
map_flags(inode.i_state, inode_flag_vals));
iaddr = (char *)addr;
iaddr += offsetof(struct inode, u);
kdb_printf(" fs specific info @ 0x%p\n", iaddr);
return (0);
}
static int
kdbm_kiobuf(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct kiobuf kiobuf;
struct page page;
struct page *page_array[64];
unsigned long addr;
long offset=0;
int nextarg;
int diag;
int i;
if (argc != 1)
return KDB_ARGCOUNT;
nextarg = 1;
if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
(diag = kdb_getarea(kiobuf, addr)))
return(diag);
kdb_printf("kiobuf at 0x%lx\n", addr);
kdb_printf(" nr_pages %d array_len %d offset 0x%x length 0x%x\n",
kiobuf.nr_pages, kiobuf.array_len,
kiobuf.offset, kiobuf.length);
if (kiobuf.maplist != (((struct kiobuf *)addr)->map_array)) {
if ((diag = kdb_getarea_size(page_array, (unsigned long)kiobuf.maplist, kiobuf.nr_pages * sizeof(page_array[0]))))
return(diag);
kiobuf.maplist = page_array;
}
kdb_printf(" errno %d\n", kiobuf.errno);
kdb_printf(" page_struct page_addr cnt flags\n");
for (i = 0; i < kiobuf.nr_pages; i++) {
if ((diag = kdb_getarea(page, (unsigned long) kiobuf.maplist[i])))
return(diag);
kdb_printf(" 0x%p 0x%p %d 0x%lx\n",
kiobuf.maplist[i], page.virtual,
page.count.counter, page.flags);
}
return (0);
}
#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
#define HAVE_DELALLOCPAGE
#endif
static int
kdbm_memmap(int argc, const char **argv, const char **envp,
struct pt_regs *regs)
{
struct page page;
int i, page_count;
int slab_count = 0;
#ifdef HAVE_DELALLOCPAGE
int delalloc_count = 0;
#endif /* HAVE_DELALLOCPAGE */
int dirty_count = 0;
int locked_count = 0;
int page_counts[9];
int buffered_count = 0;
int diag;
unsigned long addr;
addr = (unsigned long)mem_map;
page_count = max_mapnr;
memset(page_counts, 0, sizeof(page_counts));
for (i = 0; i < page_count; i++) {
if ((diag = kdb_getarea(page, addr)))
return(diag);
addr += sizeof(page);
if (PageSlab(&page))
slab_count++;
#ifdef HAVE_DELALLOCPAGE
if (DelallocPage(&page))
delalloc_count++;
#endif /* HAVE_DELALLOCPAGE */
if (PageDirty(&page))
dirty_count++;
if (PageLocked(&page))
locked_count++;
if (page.count.counter < 8)
page_counts[page.count.counter]++;
else
page_counts[8]++;
if (page.buffers)
buffered_count++;
}
kdb_printf(" Total pages: %6d\n", page_count);
kdb_printf(" Slab pages: %6d\n", slab_count);
#ifdef HAVE_DELALLOCPAGE
kdb_printf(" Delalloc pages: %6d\n", delalloc_count);
#endif /* HAVE_DELALLOCPAGE */
kdb_printf(" Dirty pages: %6d\n", dirty_count);
kdb_printf(" Locked pages: %6d\n", locked_count);
kdb_printf(" Buffer pages: %6d\n", buffered_count);
for (i = 0; i < 8; i++) {
kdb_printf(" %d page count: %6d\n",
i, page_counts[i]);
}
kdb_printf(" high page count: %6d\n", page_counts[8]);
return 0;
}
static int __init kdbm_pg_init(void)
{
kdb_register("kiobuf", kdbm_kiobuf, "<vaddr>", "Display kiobuf", 0);
kdb_register("page", kdbm_page, "<vaddr>", "Display page", 0);
kdb_register("inode", kdbm_inode, "<vaddr>", "Display inode", 0);
kdb_register("bh", kdbm_buffers, "<buffer head address>", "Display buffer", 0);
kdb_register("inode_pages", kdbm_inode_pages, "<inode *>", "Display pages in an inode", 0);
kdb_register("req", kdbm_request, "<vaddr>", "dump request struct", 0);
kdb_register("rqueue", kdbm_rqueue, "<vaddr>", "dump request queue", 0);
kdb_register("memmap", kdbm_memmap, "", "page table summary", 0);
return 0;
}
static void __exit kdbm_pg_exit(void)
{
kdb_unregister("kiobuf");
kdb_unregister("page");
kdb_unregister("inode");
kdb_unregister("bh");
kdb_unregister("inode_pages");
kdb_unregister("req");
kdb_unregister("rqueue");
kdb_unregister("memmap");
}
module_init(kdbm_pg_init)
module_exit(kdbm_pg_exit)
|