1 From: Joel Becker <joel.becker@oracle.com>
2 Subject: ocfs2: Separate out sync reads from ocfs2_read_blocks()
5 The ocfs2_read_blocks() function currently handles sync reads, cached,
6 reads, and sometimes cached reads. We're going to add some
7 functionality to it, so first we should simplify it. The uncached,
8 synchronous reads are much easer to handle as a separate function, so we
9 instroduce ocfs2_read_blocks_sync().
11 Signed-off-by: Joel Becker <joel.becker@oracle.com>
12 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
14 fs/ocfs2/buffer_head_io.c | 84 ++++++++++++++++++++++++++++++++++++++++++++-
15 fs/ocfs2/buffer_head_io.h | 2 +
16 fs/ocfs2/inode.c | 7 +++-
17 fs/ocfs2/journal.c | 5 +--
18 fs/ocfs2/resize.c | 8 ++--
19 5 files changed, 96 insertions(+), 10 deletions(-)
21 Index: linux-2.6.27/fs/ocfs2/buffer_head_io.c
22 ===================================================================
23 --- linux-2.6.27.orig/fs/ocfs2/buffer_head_io.c
24 +++ linux-2.6.27/fs/ocfs2/buffer_head_io.c
25 @@ -66,7 +66,7 @@ int ocfs2_write_block(struct ocfs2_super
26 /* remove from dirty list before I/O. */
27 clear_buffer_dirty(bh);
29 - get_bh(bh); /* for end_buffer_write_sync() */
30 + get_bh(bh); /* for end_buffer_write_sync() */
31 bh->b_end_io = end_buffer_write_sync;
34 @@ -88,6 +88,88 @@ out:
38 +int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
39 + unsigned int nr, struct buffer_head *bhs[])
43 + struct buffer_head *bh;
46 + mlog(ML_BH_IO, "No buffers will be read!\n");
50 + for (i = 0 ; i < nr ; i++) {
51 + if (bhs[i] == NULL) {
52 + bhs[i] = sb_getblk(osb->sb, block++);
53 + if (bhs[i] == NULL) {
61 + if (buffer_jbd(bh)) {
63 + "trying to sync read a jbd "
64 + "managed bh (blocknr = %llu), skipping\n",
65 + (unsigned long long)bh->b_blocknr);
69 + if (buffer_dirty(bh)) {
70 + /* This should probably be a BUG, or
71 + * at least return an error. */
73 + "trying to sync read a dirty "
74 + "buffer! (blocknr = %llu), skipping\n",
75 + (unsigned long long)bh->b_blocknr);
80 + if (buffer_jbd(bh)) {
82 + "block %llu had the JBD bit set "
83 + "while I was in lock_buffer!",
84 + (unsigned long long)bh->b_blocknr);
88 + clear_buffer_uptodate(bh);
89 + get_bh(bh); /* for end_buffer_read_sync() */
90 + bh->b_end_io = end_buffer_read_sync;
91 + submit_bh(READ, bh);
94 + for (i = nr; i > 0; i--) {
97 + if (buffer_jbd(bh)) {
99 + "the journal got the buffer while it was "
100 + "locked for io! (blocknr = %llu)\n",
101 + (unsigned long long)bh->b_blocknr);
105 + wait_on_buffer(bh);
106 + if (!buffer_uptodate(bh)) {
107 + /* Status won't be cleared from here on out,
108 + * so we can safely record this and loop back
109 + * to cleanup the other buffers. */
120 int ocfs2_read_blocks(struct ocfs2_super *osb, u64 block, int nr,
121 struct buffer_head *bhs[], int flags,
123 Index: linux-2.6.27/fs/ocfs2/buffer_head_io.h
124 ===================================================================
125 --- linux-2.6.27.orig/fs/ocfs2/buffer_head_io.h
126 +++ linux-2.6.27/fs/ocfs2/buffer_head_io.h
127 @@ -46,6 +46,8 @@ int ocfs2_read_blocks(struct ocfs2_super
128 struct buffer_head *bhs[],
130 struct inode *inode);
131 +int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
132 + unsigned int nr, struct buffer_head *bhs[]);
134 int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
135 struct buffer_head *bh);
136 Index: linux-2.6.27/fs/ocfs2/inode.c
137 ===================================================================
138 --- linux-2.6.27.orig/fs/ocfs2/inode.c
139 +++ linux-2.6.27/fs/ocfs2/inode.c
140 @@ -460,8 +460,11 @@ static int ocfs2_read_locked_inode(struc
144 - status = ocfs2_read_block(osb, args->fi_blkno, &bh, 0,
145 - can_lock ? inode : NULL);
147 + status = ocfs2_read_block(osb, args->fi_blkno, &bh, 0,
150 + status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh);
154 Index: linux-2.6.27/fs/ocfs2/journal.c
155 ===================================================================
156 --- linux-2.6.27.orig/fs/ocfs2/journal.c
157 +++ linux-2.6.27/fs/ocfs2/journal.c
158 @@ -850,9 +850,8 @@ static int ocfs2_force_read_journal(stru
160 /* We are reading journal data which should not
161 * be put in the uptodate cache */
162 - status = ocfs2_read_blocks(OCFS2_SB(inode->i_sb),
163 - p_blkno, p_blocks, bhs, 0,
165 + status = ocfs2_read_blocks_sync(OCFS2_SB(inode->i_sb),
166 + p_blkno, p_blocks, bhs);
170 Index: linux-2.6.27/fs/ocfs2/resize.c
171 ===================================================================
172 --- linux-2.6.27.orig/fs/ocfs2/resize.c
173 +++ linux-2.6.27/fs/ocfs2/resize.c
174 @@ -200,7 +200,7 @@ static int update_backups(struct inode *
175 if (cluster > clusters)
178 - ret = ocfs2_read_block(osb, blkno, &backup, 0, NULL);
179 + ret = ocfs2_read_blocks_sync(osb, blkno, 1, &backup);
183 @@ -236,8 +236,8 @@ static void ocfs2_update_super_and_backu
184 * update the superblock last.
185 * It doesn't matter if the write failed.
187 - ret = ocfs2_read_block(osb, OCFS2_SUPER_BLOCK_BLKNO,
188 - &super_bh, 0, NULL);
189 + ret = ocfs2_read_blocks_sync(osb, OCFS2_SUPER_BLOCK_BLKNO, 1,
194 @@ -540,7 +540,7 @@ int ocfs2_group_add(struct inode *inode,
198 - ret = ocfs2_read_block(osb, input->group, &group_bh, 0, NULL);
199 + ret = ocfs2_read_blocks_sync(osb, input->group, 1, &group_bh);
201 mlog(ML_ERROR, "Can't read the group descriptor # %llu "
202 "from the device.", (unsigned long long)input->group);