Blame view

fs/gfs2/meta_io.c 10.7 KB
b3b94faa5   David Teigland   [GFS2] The core o...
1
2
  /*
   * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
091806edd   Bob Peterson   [GFS2] filesystem...
3
   * Copyright (C) 2004-2008 Red Hat, Inc.  All rights reserved.
b3b94faa5   David Teigland   [GFS2] The core o...
4
5
6
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa09   Steven Whitehouse   [GFS2] Update cop...
7
   * of the GNU General Public License version 2.
b3b94faa5   David Teigland   [GFS2] The core o...
8
9
10
11
12
13
14
15
16
17
18
19
   */
  
  #include <linux/sched.h>
  #include <linux/slab.h>
  #include <linux/spinlock.h>
  #include <linux/completion.h>
  #include <linux/buffer_head.h>
  #include <linux/mm.h>
  #include <linux/pagemap.h>
  #include <linux/writeback.h>
  #include <linux/swap.h>
  #include <linux/delay.h>
2e565bb69   Steven Whitehouse   [GFS2] Mark metad...
20
  #include <linux/bio.h>
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
21
  #include <linux/gfs2_ondisk.h>
b3b94faa5   David Teigland   [GFS2] The core o...
22
23
  
  #include "gfs2.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
24
  #include "incore.h"
b3b94faa5   David Teigland   [GFS2] The core o...
25
26
27
28
29
30
31
32
  #include "glock.h"
  #include "glops.h"
  #include "inode.h"
  #include "log.h"
  #include "lops.h"
  #include "meta_io.h"
  #include "rgrp.h"
  #include "trans.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
33
  #include "util.h"
627c10b7e   Steven Whitehouse   GFS2: Improve tra...
34
  #include "trace_gfs2.h"
b3b94faa5   David Teigland   [GFS2] The core o...
35

4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
36
  static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wbc)
b3b94faa5   David Teigland   [GFS2] The core o...
37
  {
4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
38
39
  	struct buffer_head *bh, *head;
  	int nr_underway = 0;
7637241e6   Jens Axboe   writeback: add wb...
40
  	int write_flags = REQ_META | REQ_PRIO | wbc_to_write_flags(wbc);
b3b94faa5   David Teigland   [GFS2] The core o...
41

4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
42
43
44
45
46
47
48
49
50
51
52
53
  	BUG_ON(!PageLocked(page));
  	BUG_ON(!page_has_buffers(page));
  
  	head = page_buffers(page);
  	bh = head;
  
  	do {
  		if (!buffer_mapped(bh))
  			continue;
  		/*
  		 * If it's a fully non-blocking write attempt and we cannot
  		 * lock the buffer then redirty the page.  Note that this can
e76e0ec98   Artem Bityutskiy   gfs2: nuke pdflus...
54
  		 * potentially cause a busy-wait loop from flusher thread and kswapd
4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
55
56
57
  		 * activity, but those code paths have their own higher-level
  		 * throttling.
  		 */
1b430beee   Wu Fengguang   writeback: remove...
58
  		if (wbc->sync_mode != WB_SYNC_NONE) {
4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  			lock_buffer(bh);
  		} else if (!trylock_buffer(bh)) {
  			redirty_page_for_writepage(wbc, page);
  			continue;
  		}
  		if (test_clear_buffer_dirty(bh)) {
  			mark_buffer_async_write(bh);
  		} else {
  			unlock_buffer(bh);
  		}
  	} while ((bh = bh->b_this_page) != head);
  
  	/*
  	 * The page and its buffers are protected by PageWriteback(), so we can
  	 * drop the bh refcounts early.
  	 */
  	BUG_ON(PageWriteback(page));
  	set_page_writeback(page);
  
  	do {
  		struct buffer_head *next = bh->b_this_page;
  		if (buffer_async_write(bh)) {
2a222ca99   Mike Christie   fs: have submit_b...
81
  			submit_bh(REQ_OP_WRITE, write_flags, bh);
4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
82
83
84
85
86
  			nr_underway++;
  		}
  		bh = next;
  	} while (bh != head);
  	unlock_page(page);
4a0f9a321   Steven Whitehouse   GFS2: Optimise wr...
87
88
  	if (nr_underway == 0)
  		end_page_writeback(page);
eaefbf968   Bob Peterson   GFS2: Eliminate u...
89
  	return 0;
b3b94faa5   David Teigland   [GFS2] The core o...
90
  }
009d85183   Steven Whitehouse   GFS2: Metadata ad...
91
  const struct address_space_operations gfs2_meta_aops = {
b3b94faa5   David Teigland   [GFS2] The core o...
92
  	.writepage = gfs2_aspace_writepage,
4340fe625   Steven Whitehouse   [GFS2] Add genera...
93
  	.releasepage = gfs2_releasepage,
b3b94faa5   David Teigland   [GFS2] The core o...
94
  };
1b2ad4121   Steven Whitehouse   GFS2: Fix address...
95
96
97
98
  const struct address_space_operations gfs2_rgrp_aops = {
  	.writepage = gfs2_aspace_writepage,
  	.releasepage = gfs2_releasepage,
  };
b3b94faa5   David Teigland   [GFS2] The core o...
99
  /**
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
100
   * gfs2_getbuf - Get a buffer with a given address space
cb4c03131   Steven Whitehouse   [GFS2] Reduce num...
101
   * @gl: the glock
b3b94faa5   David Teigland   [GFS2] The core o...
102
103
104
105
106
   * @blkno: the block number (filesystem scope)
   * @create: 1 if the buffer should be created
   *
   * Returns: the buffer
   */
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
107
  struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
b3b94faa5   David Teigland   [GFS2] The core o...
108
  {
009d85183   Steven Whitehouse   GFS2: Metadata ad...
109
  	struct address_space *mapping = gfs2_glock2aspace(gl);
15562c439   Bob Peterson   GFS2: Move glock ...
110
  	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
b3b94faa5   David Teigland   [GFS2] The core o...
111
112
113
114
115
  	struct page *page;
  	struct buffer_head *bh;
  	unsigned int shift;
  	unsigned long index;
  	unsigned int bufnum;
70d4ee94b   Steven Whitehouse   GFS2: Use only a ...
116
117
  	if (mapping == NULL)
  		mapping = &sdp->sd_aspace;
09cbfeaf1   Kirill A. Shutemov   mm, fs: get rid o...
118
  	shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
b3b94faa5   David Teigland   [GFS2] The core o...
119
120
121
122
123
  	index = blkno >> shift;             /* convert block to page */
  	bufnum = blkno - (index << shift);  /* block buf index within page */
  
  	if (create) {
  		for (;;) {
cb4c03131   Steven Whitehouse   [GFS2] Reduce num...
124
  			page = grab_cache_page(mapping, index);
b3b94faa5   David Teigland   [GFS2] The core o...
125
126
127
128
129
  			if (page)
  				break;
  			yield();
  		}
  	} else {
2457aec63   Mel Gorman   mm: non-atomicall...
130
131
  		page = find_get_page_flags(mapping, index,
  						FGP_LOCK|FGP_ACCESSED);
b3b94faa5   David Teigland   [GFS2] The core o...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  		if (!page)
  			return NULL;
  	}
  
  	if (!page_has_buffers(page))
  		create_empty_buffers(page, sdp->sd_sb.sb_bsize, 0);
  
  	/* Locate header for our buffer within our page */
  	for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page)
  		/* Do nothing */;
  	get_bh(bh);
  
  	if (!buffer_mapped(bh))
  		map_bh(bh, sdp->sd_vfs, blkno);
  
  	unlock_page(page);
09cbfeaf1   Kirill A. Shutemov   mm, fs: get rid o...
148
  	put_page(page);
b3b94faa5   David Teigland   [GFS2] The core o...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  
  	return bh;
  }
  
  static void meta_prep_new(struct buffer_head *bh)
  {
  	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
  
  	lock_buffer(bh);
  	clear_buffer_dirty(bh);
  	set_buffer_uptodate(bh);
  	unlock_buffer(bh);
  
  	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
  }
  
  /**
   * gfs2_meta_new - Get a block
   * @gl: The glock associated with this block
   * @blkno: The block number
   *
   * Returns: The buffer
   */
cd915493f   Steven Whitehouse   [GFS2] Change all...
172
  struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
b3b94faa5   David Teigland   [GFS2] The core o...
173
174
  {
  	struct buffer_head *bh;
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
175
  	bh = gfs2_getbuf(gl, blkno, CREATE);
b3b94faa5   David Teigland   [GFS2] The core o...
176
177
178
  	meta_prep_new(bh);
  	return bh;
  }
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
179
  static void gfs2_meta_read_endio(struct bio *bio)
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
180
  {
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
181
182
183
184
185
186
187
188
189
190
191
192
193
  	struct bio_vec *bvec;
  	int i;
  
  	bio_for_each_segment_all(bvec, bio, i) {
  		struct page *page = bvec->bv_page;
  		struct buffer_head *bh = page_buffers(page);
  		unsigned int len = bvec->bv_len;
  
  		while (bh_offset(bh) < bvec->bv_offset)
  			bh = bh->b_this_page;
  		do {
  			struct buffer_head *next = bh->b_this_page;
  			len -= bh->b_size;
4e4cbee93   Christoph Hellwig   block: switch bio...
194
  			bh->b_end_io(bh, !bio->bi_status);
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
195
196
197
198
199
  			bh = next;
  		} while (bh && len);
  	}
  	bio_put(bio);
  }
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
200

39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
201
202
203
204
  /*
   * Submit several consecutive buffer head I/O requests as a single bio I/O
   * request.  (See submit_bh_wbc.)
   */
e1b1afa6f   Mike Christie   gfs2: use bio op ...
205
206
  static void gfs2_submit_bhs(int op, int op_flags, struct buffer_head *bhs[],
  			    int num)
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
207
  {
23e5671a7   Andreas Gruenbacher   gfs2: Fix extende...
208
209
210
211
212
213
  	while (num > 0) {
  		struct buffer_head *bh = *bhs;
  		struct bio *bio;
  
  		bio = bio_alloc(GFP_NOIO, num);
  		bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
74d46992e   Christoph Hellwig   block: replace bi...
214
  		bio_set_dev(bio, bh->b_bdev);
23e5671a7   Andreas Gruenbacher   gfs2: Fix extende...
215
216
217
218
219
220
221
222
223
224
225
226
  		while (num > 0) {
  			bh = *bhs;
  			if (!bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh))) {
  				BUG_ON(bio->bi_iter.bi_size == 0);
  				break;
  			}
  			bhs++;
  			num--;
  		}
  		bio->bi_end_io = gfs2_meta_read_endio;
  		bio_set_op_attrs(bio, op, op_flags);
  		submit_bio(bio);
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
227
  	}
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
228
  }
b3b94faa5   David Teigland   [GFS2] The core o...
229
230
231
232
  /**
   * gfs2_meta_read - Read a block from disk
   * @gl: The glock covering the block
   * @blkno: The block number
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
233
   * @flags: flags
b3b94faa5   David Teigland   [GFS2] The core o...
234
235
236
237
   * @bhp: the place where the buffer is returned (NULL on failure)
   *
   * Returns: errno
   */
cd915493f   Steven Whitehouse   [GFS2] Change all...
238
  int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
239
  		   int rahead, struct buffer_head **bhp)
b3b94faa5   David Teigland   [GFS2] The core o...
240
  {
15562c439   Bob Peterson   GFS2: Move glock ...
241
  	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
242
243
  	struct buffer_head *bh, *bhs[2];
  	int num = 0;
c969f58ca   Steven Whitehouse   GFS2: Update the ...
244

44b8db138   Masatake YAMATO   GFS2: Fixing doub...
245
246
  	if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
  		*bhp = NULL;
c969f58ca   Steven Whitehouse   GFS2: Update the ...
247
  		return -EIO;
44b8db138   Masatake YAMATO   GFS2: Fixing doub...
248
  	}
c969f58ca   Steven Whitehouse   GFS2: Update the ...
249
250
251
252
253
254
  
  	*bhp = bh = gfs2_getbuf(gl, blkno, CREATE);
  
  	lock_buffer(bh);
  	if (buffer_uptodate(bh)) {
  		unlock_buffer(bh);
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
255
256
257
258
259
  		flags &= ~DIO_WAIT;
  	} else {
  		bh->b_end_io = end_buffer_read_sync;
  		get_bh(bh);
  		bhs[num++] = bh;
c969f58ca   Steven Whitehouse   GFS2: Update the ...
260
  	}
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
261
262
263
264
265
266
267
268
269
270
271
272
273
  
  	if (rahead) {
  		bh = gfs2_getbuf(gl, blkno + 1, CREATE);
  
  		lock_buffer(bh);
  		if (buffer_uptodate(bh)) {
  			unlock_buffer(bh);
  			brelse(bh);
  		} else {
  			bh->b_end_io = end_buffer_read_sync;
  			bhs[num++] = bh;
  		}
  	}
70fd76140   Christoph Hellwig   block,fs: use REQ...
274
  	gfs2_submit_bhs(REQ_OP_READ, REQ_META | REQ_PRIO, bhs, num);
c969f58ca   Steven Whitehouse   GFS2: Update the ...
275
276
  	if (!(flags & DIO_WAIT))
  		return 0;
39b0555f7   Andreas Gruenbacher   gfs2: Extended at...
277
  	bh = *bhp;
c969f58ca   Steven Whitehouse   GFS2: Update the ...
278
279
280
  	wait_on_buffer(bh);
  	if (unlikely(!buffer_uptodate(bh))) {
  		struct gfs2_trans *tr = current->journal_info;
9862ca056   Bob Peterson   GFS2: Switch tr_t...
281
  		if (tr && test_bit(TR_TOUCHED, &tr->tr_flags))
c969f58ca   Steven Whitehouse   GFS2: Update the ...
282
283
  			gfs2_io_error_bh(sdp, bh);
  		brelse(bh);
44b8db138   Masatake YAMATO   GFS2: Fixing doub...
284
  		*bhp = NULL;
c969f58ca   Steven Whitehouse   GFS2: Update the ...
285
  		return -EIO;
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
286
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
287

7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
288
  	return 0;
b3b94faa5   David Teigland   [GFS2] The core o...
289
290
291
  }
  
  /**
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
292
   * gfs2_meta_wait - Reread a block from disk
b3b94faa5   David Teigland   [GFS2] The core o...
293
   * @sdp: the filesystem
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
294
   * @bh: The block to wait for
b3b94faa5   David Teigland   [GFS2] The core o...
295
296
297
   *
   * Returns: errno
   */
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
298
  int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
b3b94faa5   David Teigland   [GFS2] The core o...
299
300
301
  {
  	if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  		return -EIO;
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
302
  	wait_on_buffer(bh);
b3b94faa5   David Teigland   [GFS2] The core o...
303

7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
304
305
  	if (!buffer_uptodate(bh)) {
  		struct gfs2_trans *tr = current->journal_info;
9862ca056   Bob Peterson   GFS2: Switch tr_t...
306
  		if (tr && test_bit(TR_TOUCHED, &tr->tr_flags))
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
307
308
  			gfs2_io_error_bh(sdp, bh);
  		return -EIO;
b3b94faa5   David Teigland   [GFS2] The core o...
309
  	}
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
310
311
  	if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  		return -EIO;
b3b94faa5   David Teigland   [GFS2] The core o...
312
313
314
  
  	return 0;
  }
68cd4ce2c   Bob Peterson   GFS2: Refactor gf...
315
  void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
16615be18   Steven Whitehouse   [GFS2] Clean up j...
316
  {
009d85183   Steven Whitehouse   GFS2: Metadata ad...
317
318
  	struct address_space *mapping = bh->b_page->mapping;
  	struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
16615be18   Steven Whitehouse   [GFS2] Clean up j...
319
  	struct gfs2_bufdata *bd = bh->b_private;
68cd4ce2c   Bob Peterson   GFS2: Refactor gf...
320
  	struct gfs2_trans *tr = current->journal_info;
502be2a32   Bob Peterson   GFS2: Fix slab me...
321
  	int was_pinned = 0;
009d85183   Steven Whitehouse   GFS2: Metadata ad...
322

16615be18   Steven Whitehouse   [GFS2] Clean up j...
323
  	if (test_clear_buffer_pinned(bh)) {
627c10b7e   Steven Whitehouse   GFS2: Improve tra...
324
  		trace_gfs2_pin(bd, 0);
5e687eac1   Benjamin Marzinski   GFS2: Various gfs...
325
  		atomic_dec(&sdp->sd_log_pinned);
c0752aa7e   Bob Peterson   GFS2: eliminate l...
326
  		list_del_init(&bd->bd_list);
68cd4ce2c   Bob Peterson   GFS2: Refactor gf...
327
  		if (meta == REMOVE_META)
16615be18   Steven Whitehouse   [GFS2] Clean up j...
328
  			tr->tr_num_buf_rm++;
022ef4fee   Steven Whitehouse   GFS2: Move log bu...
329
  		else
16615be18   Steven Whitehouse   [GFS2] Clean up j...
330
  			tr->tr_num_databuf_rm++;
9862ca056   Bob Peterson   GFS2: Switch tr_t...
331
  		set_bit(TR_TOUCHED, &tr->tr_flags);
502be2a32   Bob Peterson   GFS2: Fix slab me...
332
  		was_pinned = 1;
16615be18   Steven Whitehouse   [GFS2] Clean up j...
333
334
335
  		brelse(bh);
  	}
  	if (bd) {
c618e87a5   Steven Whitehouse   GFS2: Update to A...
336
  		spin_lock(&sdp->sd_ail_lock);
16ca9412d   Benjamin Marzinski   GFS2: replace gfs...
337
  		if (bd->bd_tr) {
16615be18   Steven Whitehouse   [GFS2] Clean up j...
338
  			gfs2_trans_add_revoke(sdp, bd);
502be2a32   Bob Peterson   GFS2: Fix slab me...
339
340
341
  		} else if (was_pinned) {
  			bh->b_private = NULL;
  			kmem_cache_free(gfs2_bufdata_cachep, bd);
16615be18   Steven Whitehouse   [GFS2] Clean up j...
342
  		}
c618e87a5   Steven Whitehouse   GFS2: Update to A...
343
  		spin_unlock(&sdp->sd_ail_lock);
16615be18   Steven Whitehouse   [GFS2] Clean up j...
344
345
346
347
  	}
  	clear_buffer_dirty(bh);
  	clear_buffer_uptodate(bh);
  }
b3b94faa5   David Teigland   [GFS2] The core o...
348
  /**
b3b94faa5   David Teigland   [GFS2] The core o...
349
350
351
352
353
354
   * gfs2_meta_wipe - make inode's buffers so they aren't dirty/pinned anymore
   * @ip: the inode who owns the buffers
   * @bstart: the first buffer in the run
   * @blen: the number of buffers in the run
   *
   */
cd915493f   Steven Whitehouse   [GFS2] Change all...
355
  void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
b3b94faa5   David Teigland   [GFS2] The core o...
356
  {
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
357
  	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
358
359
360
  	struct buffer_head *bh;
  
  	while (blen) {
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
361
  		bh = gfs2_getbuf(ip->i_gl, bstart, NO_CREATE);
b3b94faa5   David Teigland   [GFS2] The core o...
362
  		if (bh) {
1ad38c437   Steven Whitehouse   [GFS2] Clean up g...
363
364
  			lock_buffer(bh);
  			gfs2_log_lock(sdp);
68cd4ce2c   Bob Peterson   GFS2: Refactor gf...
365
  			gfs2_remove_from_journal(bh, REMOVE_META);
1ad38c437   Steven Whitehouse   [GFS2] Clean up g...
366
  			gfs2_log_unlock(sdp);
b3b94faa5   David Teigland   [GFS2] The core o...
367
  			unlock_buffer(bh);
b3b94faa5   David Teigland   [GFS2] The core o...
368
369
370
371
372
373
374
375
376
  			brelse(bh);
  		}
  
  		bstart++;
  		blen--;
  	}
  }
  
  /**
b3b94faa5   David Teigland   [GFS2] The core o...
377
378
379
380
   * gfs2_meta_indirect_buffer - Get a metadata buffer
   * @ip: The GFS2 inode
   * @height: The level of this buf in the metadata (indir addr) tree (if any)
   * @num: The block number (device relative) of the buffer
b3b94faa5   David Teigland   [GFS2] The core o...
381
382
   * @bhp: the buffer is returned here
   *
b3b94faa5   David Teigland   [GFS2] The core o...
383
384
   * Returns: errno
   */
cd915493f   Steven Whitehouse   [GFS2] Change all...
385
  int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
f2f9c8124   Bob Peterson   GFS2: Eliminate u...
386
  			      struct buffer_head **bhp)
b3b94faa5   David Teigland   [GFS2] The core o...
387
  {
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
388
389
  	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  	struct gfs2_glock *gl = ip->i_gl;
f91a0d3e2   Steven Whitehouse   [GFS2] Remove use...
390
391
  	struct buffer_head *bh;
  	int ret = 0;
f2f9c8124   Bob Peterson   GFS2: Eliminate u...
392
  	u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI;
c8d577038   Andreas Gruenbacher   gfs2: Extended at...
393
394
395
396
  	int rahead = 0;
  
  	if (num == ip->i_no_addr)
  		rahead = ip->i_rahead;
b3b94faa5   David Teigland   [GFS2] The core o...
397

c8d577038   Andreas Gruenbacher   gfs2: Extended at...
398
  	ret = gfs2_meta_read(gl, num, DIO_WAIT, rahead, &bh);
f2f9c8124   Bob Peterson   GFS2: Eliminate u...
399
400
401
  	if (ret == 0 && gfs2_metatype_check(sdp, bh, mtype)) {
  		brelse(bh);
  		ret = -EIO;
61eaadcd5   Bob Peterson   GFS2: Prevent dou...
402
403
  	} else {
  		*bhp = bh;
b3b94faa5   David Teigland   [GFS2] The core o...
404
  	}
f91a0d3e2   Steven Whitehouse   [GFS2] Remove use...
405
  	return ret;
b3b94faa5   David Teigland   [GFS2] The core o...
406
407
408
409
410
411
412
413
  }
  
  /**
   * gfs2_meta_ra - start readahead on an extent of a file
   * @gl: the glock the blocks belong to
   * @dblock: the starting disk block
   * @extlen: the number of blocks in the extent
   *
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
414
   * returns: the first buffer in the extent
b3b94faa5   David Teigland   [GFS2] The core o...
415
   */
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
416
  struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
b3b94faa5   David Teigland   [GFS2] The core o...
417
  {
15562c439   Bob Peterson   GFS2: Move glock ...
418
  	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
b3b94faa5   David Teigland   [GFS2] The core o...
419
  	struct buffer_head *first_bh, *bh;
cd915493f   Steven Whitehouse   [GFS2] Change all...
420
  	u32 max_ra = gfs2_tune_get(sdp, gt_max_readahead) >>
568f4c965   Steven Whitehouse   [GFS2] 80 Column ...
421
  			  sdp->sd_sb.sb_bsize_shift;
b3b94faa5   David Teigland   [GFS2] The core o...
422

7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
423
424
425
426
  	BUG_ON(!extlen);
  
  	if (max_ra < 1)
  		max_ra = 1;
b3b94faa5   David Teigland   [GFS2] The core o...
427
428
  	if (extlen > max_ra)
  		extlen = max_ra;
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
429
  	first_bh = gfs2_getbuf(gl, dblock, CREATE);
b3b94faa5   David Teigland   [GFS2] The core o...
430
431
432
  
  	if (buffer_uptodate(first_bh))
  		goto out;
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
433
  	if (!buffer_locked(first_bh))
e477b24b5   Coly Li   gfs2: add flag RE...
434
  		ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &first_bh);
b3b94faa5   David Teigland   [GFS2] The core o...
435
436
437
438
439
  
  	dblock++;
  	extlen--;
  
  	while (extlen) {
6802e3400   Steven Whitehouse   [GFS2] Clean up t...
440
  		bh = gfs2_getbuf(gl, dblock, CREATE);
b3b94faa5   David Teigland   [GFS2] The core o...
441

7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
442
  		if (!buffer_uptodate(bh) && !buffer_locked(bh))
e477b24b5   Coly Li   gfs2: add flag RE...
443
444
445
  			ll_rw_block(REQ_OP_READ,
  				    REQ_RAHEAD | REQ_META | REQ_PRIO,
  				    1, &bh);
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
446
  		brelse(bh);
b3b94faa5   David Teigland   [GFS2] The core o...
447
448
  		dblock++;
  		extlen--;
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
449
450
  		if (!buffer_locked(first_bh) && buffer_uptodate(first_bh))
  			goto out;
b3b94faa5   David Teigland   [GFS2] The core o...
451
  	}
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
452
  	wait_on_buffer(first_bh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
453
  out:
7276b3b0c   Steven Whitehouse   [GFS2] Tidy up me...
454
  	return first_bh;
b3b94faa5   David Teigland   [GFS2] The core o...
455
  }