f2fs: add nat/sit entries into status
[linux-2.6-block.git] / fs / f2fs / trace.c
CommitLineData
63f92ddc
JK
1/*
2 * f2fs IO tracer
3 *
4 * Copyright (c) 2014 Motorola Mobility
5 * Copyright (c) 2014 Jaegeuk Kim <jaegeuk@kernel.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/fs.h>
12#include <linux/f2fs_fs.h>
13#include <linux/sched.h>
14
15#include "f2fs.h"
16#include "trace.h"
17
0e689d03
JK
18RADIX_TREE(pids, GFP_NOIO);
19struct last_io_info last_io;
20
21static inline void __print_last_io(void)
22{
23 if (!last_io.len)
24 return;
25
26 trace_printk("%3x:%3x %4x %-16s %2x %5x %12x %4x\n",
27 last_io.major, last_io.minor,
28 last_io.pid, "----------------",
29 last_io.type,
30 last_io.fio.rw, last_io.fio.blk_addr,
31 last_io.len);
32 memset(&last_io, 0, sizeof(last_io));
33}
34
35static int __file_type(struct inode *inode, pid_t pid)
36{
37 if (f2fs_is_atomic_file(inode))
38 return __ATOMIC_FILE;
39 else if (f2fs_is_volatile_file(inode))
40 return __VOLATILE_FILE;
41 else if (S_ISDIR(inode->i_mode))
42 return __DIR_FILE;
43 else if (inode->i_ino == F2FS_NODE_INO(F2FS_I_SB(inode)))
44 return __NODE_FILE;
45 else if (inode->i_ino == F2FS_META_INO(F2FS_I_SB(inode)))
46 return __META_FILE;
47 else if (pid)
48 return __NORMAL_FILE;
49 else
50 return __MISC_FILE;
51}
52
63f92ddc
JK
53void f2fs_trace_pid(struct page *page)
54{
0e689d03
JK
55 struct inode *inode = page->mapping->host;
56 pid_t pid = task_pid_nr(current);
57 void *p;
58
59 page->private = pid;
60
61 p = radix_tree_lookup(&pids, pid);
62 if (p == current)
63 return;
64 if (p)
65 radix_tree_delete(&pids, pid);
66
67 f2fs_radix_tree_insert(&pids, pid, current);
68
69 trace_printk("%3x:%3x %4x %-16s\n",
70 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
71 pid, current->comm);
72
63f92ddc
JK
73}
74
75void f2fs_trace_ios(struct page *page, struct f2fs_io_info *fio, int flush)
76{
0e689d03
JK
77 struct inode *inode;
78 pid_t pid;
79 int major, minor;
80
81 if (flush) {
82 __print_last_io();
83 return;
84 }
85
86 inode = page->mapping->host;
87 pid = page_private(page);
88
89 major = MAJOR(inode->i_sb->s_dev);
90 minor = MINOR(inode->i_sb->s_dev);
91
92 if (last_io.major == major && last_io.minor == minor &&
93 last_io.pid == pid &&
94 last_io.type == __file_type(inode, pid) &&
95 last_io.fio.rw == fio->rw &&
96 last_io.fio.blk_addr + last_io.len == fio->blk_addr) {
97 last_io.len++;
98 return;
99 }
100
101 __print_last_io();
102
103 last_io.major = major;
104 last_io.minor = minor;
105 last_io.pid = pid;
106 last_io.type = __file_type(inode, pid);
107 last_io.fio = *fio;
108 last_io.len = 1;
109 return;
63f92ddc 110}