]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
1 | From: Joel Becker <joel.becker@oracle.com> |
2 | Subject: ocfs2: Make cached block reads the common case. | |
3 | Patch-mainline: 2.6.28 | |
4 | ||
5 | ocfs2_read_blocks() currently requires the CACHED flag for cached I/O. | |
6 | However, that's the common case. Let's flip it around and provide an | |
7 | IGNORE_CACHE flag for the special users. This has the added benefit of | |
8 | cleaning up the code some (ignore_cache takes on its special meaning | |
9 | earlier in the loop). | |
10 | ||
11 | Signed-off-by: Joel Becker <joel.becker@oracle.com> | |
12 | Signed-off-by: Mark Fasheh <mfasheh@suse.com> | |
13 | --- | |
14 | fs/ocfs2/buffer_head_io.c | 19 +++++++++++-------- | |
15 | fs/ocfs2/buffer_head_io.h | 4 ++-- | |
16 | fs/ocfs2/dir.c | 2 +- | |
17 | fs/ocfs2/inode.c | 3 ++- | |
18 | fs/ocfs2/journal.c | 3 ++- | |
19 | fs/ocfs2/localalloc.c | 4 ++-- | |
20 | fs/ocfs2/slot_map.c | 6 ++++-- | |
21 | 7 files changed, 24 insertions(+), 17 deletions(-) | |
22 | ||
23 | Index: linux-2.6.27/fs/ocfs2/buffer_head_io.c | |
24 | =================================================================== | |
25 | --- linux-2.6.27.orig/fs/ocfs2/buffer_head_io.c | |
26 | +++ linux-2.6.27/fs/ocfs2/buffer_head_io.c | |
27 | @@ -181,7 +181,8 @@ int ocfs2_read_blocks(struct inode *inod | |
28 | inode, (unsigned long long)block, nr, flags); | |
29 | ||
30 | BUG_ON(!inode); | |
31 | - BUG_ON((flags & OCFS2_BH_READAHEAD) && !(flags & OCFS2_BH_CACHED)); | |
32 | + BUG_ON((flags & OCFS2_BH_READAHEAD) && | |
33 | + (flags & OCFS2_BH_IGNORE_CACHE)); | |
34 | ||
35 | if (bhs == NULL) { | |
36 | status = -EINVAL; | |
37 | @@ -214,7 +215,7 @@ int ocfs2_read_blocks(struct inode *inod | |
38 | } | |
39 | } | |
40 | bh = bhs[i]; | |
41 | - ignore_cache = 0; | |
42 | + ignore_cache = (flags & OCFS2_BH_IGNORE_CACHE); | |
43 | ||
44 | /* There are three read-ahead cases here which we need to | |
45 | * be concerned with. All three assume a buffer has | |
46 | @@ -240,26 +241,27 @@ int ocfs2_read_blocks(struct inode *inod | |
47 | * before our is-it-in-flight check. | |
48 | */ | |
49 | ||
50 | - if (flags & OCFS2_BH_CACHED && | |
51 | - !ocfs2_buffer_uptodate(inode, bh)) { | |
52 | + if (!ignore_cache && !ocfs2_buffer_uptodate(inode, bh)) { | |
53 | mlog(ML_UPTODATE, | |
54 | "bh (%llu), inode %llu not uptodate\n", | |
55 | (unsigned long long)bh->b_blocknr, | |
56 | (unsigned long long)OCFS2_I(inode)->ip_blkno); | |
57 | + /* We're using ignore_cache here to say | |
58 | + * "go to disk" */ | |
59 | ignore_cache = 1; | |
60 | } | |
61 | ||
62 | /* XXX: Can we ever get this and *not* have the cached | |
63 | * flag set? */ | |
64 | if (buffer_jbd(bh)) { | |
65 | - if (!(flags & OCFS2_BH_CACHED) || ignore_cache) | |
66 | + if (ignore_cache) | |
67 | mlog(ML_BH_IO, "trying to sync read a jbd " | |
68 | "managed bh (blocknr = %llu)\n", | |
69 | (unsigned long long)bh->b_blocknr); | |
70 | continue; | |
71 | } | |
72 | ||
73 | - if (!(flags & OCFS2_BH_CACHED) || ignore_cache) { | |
74 | + if (ignore_cache) { | |
75 | if (buffer_dirty(bh)) { | |
76 | /* This should probably be a BUG, or | |
77 | * at least return an error. */ | |
78 | @@ -294,7 +296,7 @@ int ocfs2_read_blocks(struct inode *inod | |
79 | * previously read-ahead buffer may have | |
80 | * completed I/O while we were waiting for the | |
81 | * buffer lock. */ | |
82 | - if ((flags & OCFS2_BH_CACHED) | |
83 | + if (!(flags & OCFS2_BH_IGNORE_CACHE) | |
84 | && !(flags & OCFS2_BH_READAHEAD) | |
85 | && ocfs2_buffer_uptodate(inode, bh)) { | |
86 | unlock_buffer(bh); | |
87 | @@ -344,7 +346,8 @@ int ocfs2_read_blocks(struct inode *inod | |
88 | ||
89 | mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n", | |
90 | (unsigned long long)block, nr, | |
91 | - (!(flags & OCFS2_BH_CACHED) || ignore_cache) ? "no" : "yes", flags); | |
92 | + ((flags & OCFS2_BH_IGNORE_CACHE) || ignore_cache) ? "no" : "yes", | |
93 | + flags); | |
94 | ||
95 | bail: | |
96 | ||
97 | Index: linux-2.6.27/fs/ocfs2/buffer_head_io.h | |
98 | =================================================================== | |
99 | --- linux-2.6.27.orig/fs/ocfs2/buffer_head_io.h | |
100 | +++ linux-2.6.27/fs/ocfs2/buffer_head_io.h | |
101 | @@ -49,7 +49,7 @@ int ocfs2_read_blocks_sync(struct ocfs2_ | |
102 | int ocfs2_write_super_or_backup(struct ocfs2_super *osb, | |
103 | struct buffer_head *bh); | |
104 | ||
105 | -#define OCFS2_BH_CACHED 1 | |
106 | +#define OCFS2_BH_IGNORE_CACHE 1 | |
107 | #define OCFS2_BH_READAHEAD 8 | |
108 | ||
109 | static inline int ocfs2_read_block(struct inode *inode, u64 off, | |
110 | @@ -63,7 +63,7 @@ static inline int ocfs2_read_block(struc | |
111 | goto bail; | |
112 | } | |
113 | ||
114 | - status = ocfs2_read_blocks(inode, off, 1, bh, OCFS2_BH_CACHED); | |
115 | + status = ocfs2_read_blocks(inode, off, 1, bh, 0); | |
116 | ||
117 | bail: | |
118 | return status; | |
119 | Index: linux-2.6.27/fs/ocfs2/dir.c | |
120 | =================================================================== | |
121 | --- linux-2.6.27.orig/fs/ocfs2/dir.c | |
122 | +++ linux-2.6.27/fs/ocfs2/dir.c | |
123 | @@ -88,7 +88,7 @@ static struct buffer_head *ocfs2_bread(s | |
124 | struct buffer_head *bh = NULL; | |
125 | int tmperr; | |
126 | u64 p_blkno; | |
127 | - int readflags = OCFS2_BH_CACHED; | |
128 | + int readflags = 0; | |
129 | ||
130 | if (reada) | |
131 | readflags |= OCFS2_BH_READAHEAD; | |
132 | Index: linux-2.6.27/fs/ocfs2/inode.c | |
133 | =================================================================== | |
134 | --- linux-2.6.27.orig/fs/ocfs2/inode.c | |
135 | +++ linux-2.6.27/fs/ocfs2/inode.c | |
136 | @@ -461,7 +461,8 @@ static int ocfs2_read_locked_inode(struc | |
137 | } | |
138 | ||
139 | if (can_lock) | |
140 | - status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh, 0); | |
141 | + status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh, | |
142 | + OCFS2_BH_IGNORE_CACHE); | |
143 | else | |
144 | status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh); | |
145 | if (status < 0) { | |
146 | Index: linux-2.6.27/fs/ocfs2/journal.c | |
147 | =================================================================== | |
148 | --- linux-2.6.27.orig/fs/ocfs2/journal.c | |
149 | +++ linux-2.6.27/fs/ocfs2/journal.c | |
150 | @@ -1134,7 +1134,8 @@ static int ocfs2_read_journal_inode(stru | |
151 | } | |
152 | SET_INODE_JOURNAL(inode); | |
153 | ||
154 | - status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, bh, 0); | |
155 | + status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, bh, | |
156 | + OCFS2_BH_IGNORE_CACHE); | |
157 | if (status < 0) { | |
158 | mlog_errno(status); | |
159 | goto bail; | |
160 | Index: linux-2.6.27/fs/ocfs2/localalloc.c | |
161 | =================================================================== | |
162 | --- linux-2.6.27.orig/fs/ocfs2/localalloc.c | |
163 | +++ linux-2.6.27/fs/ocfs2/localalloc.c | |
164 | @@ -249,7 +249,7 @@ int ocfs2_load_local_alloc(struct ocfs2_ | |
165 | } | |
166 | ||
167 | status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, | |
168 | - &alloc_bh, 0); | |
169 | + &alloc_bh, OCFS2_BH_IGNORE_CACHE); | |
170 | if (status < 0) { | |
171 | mlog_errno(status); | |
172 | goto bail; | |
173 | @@ -460,7 +460,7 @@ int ocfs2_begin_local_alloc_recovery(str | |
174 | mutex_lock(&inode->i_mutex); | |
175 | ||
176 | status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, | |
177 | - &alloc_bh, 0); | |
178 | + &alloc_bh, OCFS2_BH_IGNORE_CACHE); | |
179 | if (status < 0) { | |
180 | mlog_errno(status); | |
181 | goto bail; | |
182 | Index: linux-2.6.27/fs/ocfs2/slot_map.c | |
183 | =================================================================== | |
184 | --- linux-2.6.27.orig/fs/ocfs2/slot_map.c | |
185 | +++ linux-2.6.27/fs/ocfs2/slot_map.c | |
186 | @@ -150,7 +150,8 @@ int ocfs2_refresh_slot_info(struct ocfs2 | |
187 | * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If | |
188 | * this is not true, the read of -1 (UINT64_MAX) will fail. | |
189 | */ | |
190 | - ret = ocfs2_read_blocks(si->si_inode, -1, si->si_blocks, si->si_bh, 0); | |
191 | + ret = ocfs2_read_blocks(si->si_inode, -1, si->si_blocks, si->si_bh, | |
192 | + OCFS2_BH_IGNORE_CACHE); | |
193 | if (ret == 0) { | |
194 | spin_lock(&osb->osb_lock); | |
195 | ocfs2_update_slot_info(si); | |
196 | @@ -403,7 +404,8 @@ static int ocfs2_map_slot_buffers(struct | |
197 | (unsigned long long)blkno); | |
198 | ||
199 | bh = NULL; /* Acquire a fresh bh */ | |
200 | - status = ocfs2_read_blocks(si->si_inode, blkno, 1, &bh, 0); | |
201 | + status = ocfs2_read_blocks(si->si_inode, blkno, 1, &bh, | |
202 | + OCFS2_BH_IGNORE_CACHE); | |
203 | if (status < 0) { | |
204 | mlog_errno(status); | |
205 | goto bail; |