aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2008-10-09 20:20:34 -0400
committerMark Fasheh <mfasheh@suse.com>2008-10-14 14:58:22 -0400
commitd4a8c93c8248534bdedb07f83c9aebd6f7d1d579 (patch)
treef978a7b36d515c29657f271ca5b70281c911a82f /fs
parent5e0b3dec0107540244ba343f983ef4f972db20de (diff)
ocfs2: Make cached block reads the common case.
ocfs2_read_blocks() currently requires the CACHED flag for cached I/O. However, that's the common case. Let's flip it around and provide an IGNORE_CACHE flag for the special users. This has the added benefit of cleaning up the code some (ignore_cache takes on its special meaning earlier in the loop). Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ocfs2/buffer_head_io.c19
-rw-r--r--fs/ocfs2/buffer_head_io.h4
-rw-r--r--fs/ocfs2/dir.c2
-rw-r--r--fs/ocfs2/inode.c3
-rw-r--r--fs/ocfs2/journal.c3
-rw-r--r--fs/ocfs2/localalloc.c4
-rw-r--r--fs/ocfs2/slot_map.c6
7 files changed, 24 insertions, 17 deletions
diff --git a/fs/ocfs2/buffer_head_io.c b/fs/ocfs2/buffer_head_io.c
index 718dbe5607ca..7e947c672469 100644
--- a/fs/ocfs2/buffer_head_io.c
+++ b/fs/ocfs2/buffer_head_io.c
@@ -181,7 +181,8 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
181 inode, (unsigned long long)block, nr, flags); 181 inode, (unsigned long long)block, nr, flags);
182 182
183 BUG_ON(!inode); 183 BUG_ON(!inode);
184 BUG_ON((flags & OCFS2_BH_READAHEAD) && !(flags & OCFS2_BH_CACHED)); 184 BUG_ON((flags & OCFS2_BH_READAHEAD) &&
185 (flags & OCFS2_BH_IGNORE_CACHE));
185 186
186 if (bhs == NULL) { 187 if (bhs == NULL) {
187 status = -EINVAL; 188 status = -EINVAL;
@@ -214,7 +215,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
214 } 215 }
215 } 216 }
216 bh = bhs[i]; 217 bh = bhs[i];
217 ignore_cache = 0; 218 ignore_cache = (flags & OCFS2_BH_IGNORE_CACHE);
218 219
219 /* There are three read-ahead cases here which we need to 220 /* There are three read-ahead cases here which we need to
220 * be concerned with. All three assume a buffer has 221 * be concerned with. All three assume a buffer has
@@ -240,26 +241,27 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
240 * before our is-it-in-flight check. 241 * before our is-it-in-flight check.
241 */ 242 */
242 243
243 if (flags & OCFS2_BH_CACHED && 244 if (!ignore_cache && !ocfs2_buffer_uptodate(inode, bh)) {
244 !ocfs2_buffer_uptodate(inode, bh)) {
245 mlog(ML_UPTODATE, 245 mlog(ML_UPTODATE,
246 "bh (%llu), inode %llu not uptodate\n", 246 "bh (%llu), inode %llu not uptodate\n",
247 (unsigned long long)bh->b_blocknr, 247 (unsigned long long)bh->b_blocknr,
248 (unsigned long long)OCFS2_I(inode)->ip_blkno); 248 (unsigned long long)OCFS2_I(inode)->ip_blkno);
249 /* We're using ignore_cache here to say
250 * "go to disk" */
249 ignore_cache = 1; 251 ignore_cache = 1;
250 } 252 }
251 253
252 /* XXX: Can we ever get this and *not* have the cached 254 /* XXX: Can we ever get this and *not* have the cached
253 * flag set? */ 255 * flag set? */
254 if (buffer_jbd(bh)) { 256 if (buffer_jbd(bh)) {
255 if (!(flags & OCFS2_BH_CACHED) || ignore_cache) 257 if (ignore_cache)
256 mlog(ML_BH_IO, "trying to sync read a jbd " 258 mlog(ML_BH_IO, "trying to sync read a jbd "
257 "managed bh (blocknr = %llu)\n", 259 "managed bh (blocknr = %llu)\n",
258 (unsigned long long)bh->b_blocknr); 260 (unsigned long long)bh->b_blocknr);
259 continue; 261 continue;
260 } 262 }
261 263
262 if (!(flags & OCFS2_BH_CACHED) || ignore_cache) { 264 if (ignore_cache) {
263 if (buffer_dirty(bh)) { 265 if (buffer_dirty(bh)) {
264 /* This should probably be a BUG, or 266 /* This should probably be a BUG, or
265 * at least return an error. */ 267 * at least return an error. */
@@ -294,7 +296,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
294 * previously read-ahead buffer may have 296 * previously read-ahead buffer may have
295 * completed I/O while we were waiting for the 297 * completed I/O while we were waiting for the
296 * buffer lock. */ 298 * buffer lock. */
297 if ((flags & OCFS2_BH_CACHED) 299 if (!(flags & OCFS2_BH_IGNORE_CACHE)
298 && !(flags & OCFS2_BH_READAHEAD) 300 && !(flags & OCFS2_BH_READAHEAD)
299 && ocfs2_buffer_uptodate(inode, bh)) { 301 && ocfs2_buffer_uptodate(inode, bh)) {
300 unlock_buffer(bh); 302 unlock_buffer(bh);
@@ -344,7 +346,8 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
344 346
345 mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n", 347 mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n",
346 (unsigned long long)block, nr, 348 (unsigned long long)block, nr,
347 (!(flags & OCFS2_BH_CACHED) || ignore_cache) ? "no" : "yes", flags); 349 ((flags & OCFS2_BH_IGNORE_CACHE) || ignore_cache) ? "no" : "yes",
350 flags);
348 351
349bail: 352bail:
350 353
diff --git a/fs/ocfs2/buffer_head_io.h b/fs/ocfs2/buffer_head_io.h
index a2ef9e5f8bfe..75e1dcb1ade7 100644
--- a/fs/ocfs2/buffer_head_io.h
+++ b/fs/ocfs2/buffer_head_io.h
@@ -49,7 +49,7 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
49int ocfs2_write_super_or_backup(struct ocfs2_super *osb, 49int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
50 struct buffer_head *bh); 50 struct buffer_head *bh);
51 51
52#define OCFS2_BH_CACHED 1 52#define OCFS2_BH_IGNORE_CACHE 1
53#define OCFS2_BH_READAHEAD 8 53#define OCFS2_BH_READAHEAD 8
54 54
55static inline int ocfs2_read_block(struct inode *inode, u64 off, 55static inline int ocfs2_read_block(struct inode *inode, u64 off,
@@ -63,7 +63,7 @@ static inline int ocfs2_read_block(struct inode *inode, u64 off,
63 goto bail; 63 goto bail;
64 } 64 }
65 65
66 status = ocfs2_read_blocks(inode, off, 1, bh, OCFS2_BH_CACHED); 66 status = ocfs2_read_blocks(inode, off, 1, bh, 0);
67 67
68bail: 68bail:
69 return status; 69 return status;
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 60be3ba1f5dc..026e6eb85187 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -88,7 +88,7 @@ static struct buffer_head *ocfs2_bread(struct inode *inode,
88 struct buffer_head *bh = NULL; 88 struct buffer_head *bh = NULL;
89 int tmperr; 89 int tmperr;
90 u64 p_blkno; 90 u64 p_blkno;
91 int readflags = OCFS2_BH_CACHED; 91 int readflags = 0;
92 92
93 if (reada) 93 if (reada)
94 readflags |= OCFS2_BH_READAHEAD; 94 readflags |= OCFS2_BH_READAHEAD;
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 8381c26b21a8..4903688f72a9 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -461,7 +461,8 @@ static int ocfs2_read_locked_inode(struct inode *inode,
461 } 461 }
462 462
463 if (can_lock) 463 if (can_lock)
464 status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh, 0); 464 status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh,
465 OCFS2_BH_IGNORE_CACHE);
465 else 466 else
466 status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh); 467 status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh);
467 if (status < 0) { 468 if (status < 0) {
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index d161fe5e3bde..81e40677eecb 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -1134,7 +1134,8 @@ static int ocfs2_read_journal_inode(struct ocfs2_super *osb,
1134 } 1134 }
1135 SET_INODE_JOURNAL(inode); 1135 SET_INODE_JOURNAL(inode);
1136 1136
1137 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, bh, 0); 1137 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, bh,
1138 OCFS2_BH_IGNORE_CACHE);
1138 if (status < 0) { 1139 if (status < 0) {
1139 mlog_errno(status); 1140 mlog_errno(status);
1140 goto bail; 1141 goto bail;
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 3ea740d15feb..687b28713c32 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -249,7 +249,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb)
249 } 249 }
250 250
251 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, 251 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1,
252 &alloc_bh, 0); 252 &alloc_bh, OCFS2_BH_IGNORE_CACHE);
253 if (status < 0) { 253 if (status < 0) {
254 mlog_errno(status); 254 mlog_errno(status);
255 goto bail; 255 goto bail;
@@ -460,7 +460,7 @@ int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb,
460 mutex_lock(&inode->i_mutex); 460 mutex_lock(&inode->i_mutex);
461 461
462 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, 462 status = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1,
463 &alloc_bh, 0); 463 &alloc_bh, OCFS2_BH_IGNORE_CACHE);
464 if (status < 0) { 464 if (status < 0) {
465 mlog_errno(status); 465 mlog_errno(status);
466 goto bail; 466 goto bail;
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
index 357d3fe18c3f..bdda2d8f8508 100644
--- a/fs/ocfs2/slot_map.c
+++ b/fs/ocfs2/slot_map.c
@@ -150,7 +150,8 @@ int ocfs2_refresh_slot_info(struct ocfs2_super *osb)
150 * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If 150 * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If
151 * this is not true, the read of -1 (UINT64_MAX) will fail. 151 * this is not true, the read of -1 (UINT64_MAX) will fail.
152 */ 152 */
153 ret = ocfs2_read_blocks(si->si_inode, -1, si->si_blocks, si->si_bh, 0); 153 ret = ocfs2_read_blocks(si->si_inode, -1, si->si_blocks, si->si_bh,
154 OCFS2_BH_IGNORE_CACHE);
154 if (ret == 0) { 155 if (ret == 0) {
155 spin_lock(&osb->osb_lock); 156 spin_lock(&osb->osb_lock);
156 ocfs2_update_slot_info(si); 157 ocfs2_update_slot_info(si);
@@ -403,7 +404,8 @@ static int ocfs2_map_slot_buffers(struct ocfs2_super *osb,
403 (unsigned long long)blkno); 404 (unsigned long long)blkno);
404 405
405 bh = NULL; /* Acquire a fresh bh */ 406 bh = NULL; /* Acquire a fresh bh */
406 status = ocfs2_read_blocks(si->si_inode, blkno, 1, &bh, 0); 407 status = ocfs2_read_blocks(si->si_inode, blkno, 1, &bh,
408 OCFS2_BH_IGNORE_CACHE);
407 if (status < 0) { 409 if (status < 0) {
408 mlog_errno(status); 410 mlog_errno(status);
409 goto bail; 411 goto bail;