-
Notifications
You must be signed in to change notification settings - Fork 0
/
io-stat-0002-add-wrapper-functions-for-buffer-layer.patch
139 lines (133 loc) · 3.87 KB
/
io-stat-0002-add-wrapper-functions-for-buffer-layer.patch
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
Subject: [PATCH v4 2/8] ext4: add wrapper functions for buffer layer
From: Zheng Liu <[email protected]>
Wrapper functions are defined to account the result of different IO type.
CC: Jens Axboe <[email protected]>
CC: Steven Whitehouse <[email protected]>
CC: Aditya Kali <[email protected]>
Signed-off-by: Wang Shaoyan <[email protected]>
Signed-off-by: Zheng Liu <[email protected]>
---
fs/ext4/ext4.h | 21 +++++++++++++++
fs/ext4/super.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 7ec0596..688891e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1968,6 +1968,27 @@ static inline void ext4_ios_read(struct super_block *sb, int type,
__ext4_io_stat(sb, READ, type, count);
}
+extern void ext4_submit_bh_read_nowait(int rw, struct buffer_head *bh,
+ struct super_block *sb, int type,
+ unsigned long count);
+extern int ext4_submit_bh_read(int rw, struct buffer_head *bh,
+ struct super_block *sb, int type,
+ unsigned long count);
+extern void ext4_submit_bh_write_nowait(int rw, struct buffer_head *bh,
+ struct super_block *sb, int type,
+ unsigned long count);
+extern struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
+ int type, unsigned long count);
+extern void ext4_sb_breadahead(struct super_block *sb,
+ sector_t block, int type);
+
+static inline int ext4_bh_submit_read(struct buffer_head *bh,
+ struct super_block *sb,
+ int type, unsigned long count)
+{
+ return ext4_submit_bh_read(READ, bh, sb, type, count);
+}
+
extern void *ext4_kvmalloc(size_t size, gfp_t flags);
extern void *ext4_kvzalloc(size_t size, gfp_t flags);
extern void ext4_kvfree(void *ptr);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f3a5cab..305ece7 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4999,6 +4999,84 @@ count:
__ext4_io_stat(sb, WRITE, type, count);
}
+void ext4_submit_bh_read_nowait(int rw, struct buffer_head *bh,
+ struct super_block *sb, int type,
+ unsigned long count)
+{
+ BUG_ON(rw & WRITE);
+ BUG_ON(!buffer_locked(bh));
+
+ /* IO type accouting */
+ ext4_ios_read(sb, type, count);
+
+ get_bh(bh);
+ bh->b_end_io = end_buffer_read_sync;
+ submit_bh(rw, bh);
+}
+
+int ext4_submit_bh_read(int rw, struct buffer_head *bh, struct super_block *sb,
+ int type, unsigned long count)
+{
+ BUG_ON(rw & WRITE);
+ BUG_ON(!buffer_locked(bh));
+
+ if (buffer_uptodate(bh)) {
+ unlock_buffer(bh);
+ return 0;
+ }
+
+ ext4_submit_bh_read_nowait(rw, bh, sb, type, count);
+ wait_on_buffer(bh);
+ if (buffer_uptodate(bh))
+ return 0;
+ return -EIO;
+}
+
+void ext4_submit_bh_write_nowait(int rw, struct buffer_head *bh,
+ struct super_block *sb, int type,
+ unsigned long count)
+{
+ BUG_ON(!(rw & WRITE));
+ BUG_ON(!buffer_locked(bh));
+
+ /* IO type accouting */
+ ext4_ios_write(sb, NULL, NULL, type, count);
+
+ get_bh(bh);
+ bh->b_end_io = end_buffer_write_sync;
+ submit_bh(rw, bh);
+}
+
+struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
+ int type, unsigned long count)
+{
+ struct buffer_head *bh = __getblk(sb->s_bdev, block, sb->s_blocksize);
+
+ if (likely(bh) && !buffer_uptodate(bh)) {
+ lock_buffer(bh);
+ if (ext4_submit_bh_read(READ, bh, sb, type, count)) {
+ brelse(bh);
+ bh = NULL;
+ }
+ }
+ return bh;
+}
+
+void ext4_sb_breadahead(struct super_block *sb, sector_t block, int type)
+{
+ struct buffer_head *bh = __getblk(sb->s_bdev, block, sb->s_blocksize);
+ if (likely(bh)) {
+ if (trylock_buffer(bh)) {
+ if (buffer_uptodate(bh))
+ ext4_submit_bh_read_nowait(READ, bh, sb,
+ type, 1);
+ else
+ unlock_buffer(bh);
+ }
+ brelse(bh);
+ }
+}
+
static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
const char *dev_name, void *data)
{
--
1.7.4.1