[GFS2] Mark metadata reads for blktrace
[safe/jmp/linux-2.6] / fs / gfs2 / meta_io.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License version 2.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/mm.h>
16 #include <linux/pagemap.h>
17 #include <linux/writeback.h>
18 #include <linux/swap.h>
19 #include <linux/delay.h>
20 #include <linux/bio.h>
21 #include <linux/gfs2_ondisk.h>
22 #include <linux/lm_interface.h>
23
24 #include "gfs2.h"
25 #include "incore.h"
26 #include "glock.h"
27 #include "glops.h"
28 #include "inode.h"
29 #include "log.h"
30 #include "lops.h"
31 #include "meta_io.h"
32 #include "rgrp.h"
33 #include "trans.h"
34 #include "util.h"
35 #include "ops_address.h"
36
37 #define buffer_busy(bh) \
38 ((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned)))
39 #define buffer_in_io(bh) \
40 ((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock)))
41
42 static int aspace_get_block(struct inode *inode, sector_t lblock,
43                             struct buffer_head *bh_result, int create)
44 {
45         gfs2_assert_warn(inode->i_sb->s_fs_info, 0);
46         return -EOPNOTSUPP;
47 }
48
49 static int gfs2_aspace_writepage(struct page *page,
50                                  struct writeback_control *wbc)
51 {
52         return block_write_full_page(page, aspace_get_block, wbc);
53 }
54
55 static const struct address_space_operations aspace_aops = {
56         .writepage = gfs2_aspace_writepage,
57         .releasepage = gfs2_releasepage,
58 };
59
60 /**
61  * gfs2_aspace_get - Create and initialize a struct inode structure
62  * @sdp: the filesystem the aspace is in
63  *
64  * Right now a struct inode is just a struct inode.  Maybe Linux
65  * will supply a more lightweight address space construct (that works)
66  * in the future.
67  *
68  * Make sure pages/buffers in this aspace aren't in high memory.
69  *
70  * Returns: the aspace
71  */
72
73 struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp)
74 {
75         struct inode *aspace;
76
77         aspace = new_inode(sdp->sd_vfs);
78         if (aspace) {
79                 mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS);
80                 aspace->i_mapping->a_ops = &aspace_aops;
81                 aspace->i_size = ~0ULL;
82                 aspace->i_private = NULL;
83                 insert_inode_hash(aspace);
84         }
85         return aspace;
86 }
87
88 void gfs2_aspace_put(struct inode *aspace)
89 {
90         remove_inode_hash(aspace);
91         iput(aspace);
92 }
93
94 /**
95  * gfs2_ail1_start_one - Start I/O on a part of the AIL
96  * @sdp: the filesystem
97  * @tr: the part of the AIL
98  *
99  */
100
101 void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
102 {
103         struct gfs2_bufdata *bd, *s;
104         struct buffer_head *bh;
105         int retry;
106
107         BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
108
109         do {
110                 retry = 0;
111
112                 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
113                                                  bd_ail_st_list) {
114                         bh = bd->bd_bh;
115
116                         gfs2_assert(sdp, bd->bd_ail == ai);
117
118                         if (!buffer_busy(bh)) {
119                                 if (!buffer_uptodate(bh)) {
120                                         gfs2_log_unlock(sdp);
121                                         gfs2_io_error_bh(sdp, bh);
122                                         gfs2_log_lock(sdp);
123                                 }
124                                 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
125                                 continue;
126                         }
127
128                         if (!buffer_dirty(bh))
129                                 continue;
130
131                         list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
132
133                         gfs2_log_unlock(sdp);
134                         wait_on_buffer(bh);
135                         ll_rw_block(WRITE, 1, &bh);
136                         gfs2_log_lock(sdp);
137
138                         retry = 1;
139                         break;
140                 }
141         } while (retry);
142 }
143
144 /**
145  * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
146  * @sdp: the filesystem
147  * @ai: the AIL entry
148  *
149  */
150
151 int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
152 {
153         struct gfs2_bufdata *bd, *s;
154         struct buffer_head *bh;
155
156         list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
157                                          bd_ail_st_list) {
158                 bh = bd->bd_bh;
159
160                 gfs2_assert(sdp, bd->bd_ail == ai);
161
162                 if (buffer_busy(bh)) {
163                         if (flags & DIO_ALL)
164                                 continue;
165                         else
166                                 break;
167                 }
168
169                 if (!buffer_uptodate(bh))
170                         gfs2_io_error_bh(sdp, bh);
171
172                 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
173         }
174
175         return list_empty(&ai->ai_ail1_list);
176 }
177
178 /**
179  * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
180  * @sdp: the filesystem
181  * @ai: the AIL entry
182  *
183  */
184
185 void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
186 {
187         struct list_head *head = &ai->ai_ail2_list;
188         struct gfs2_bufdata *bd;
189
190         while (!list_empty(head)) {
191                 bd = list_entry(head->prev, struct gfs2_bufdata,
192                                 bd_ail_st_list);
193                 gfs2_assert(sdp, bd->bd_ail == ai);
194                 bd->bd_ail = NULL;
195                 list_del(&bd->bd_ail_st_list);
196                 list_del(&bd->bd_ail_gl_list);
197                 atomic_dec(&bd->bd_gl->gl_ail_count);
198                 brelse(bd->bd_bh);
199         }
200 }
201
202 /**
203  * ail_empty_gl - remove all buffers for a given lock from the AIL
204  * @gl: the glock
205  *
206  * None of the buffers should be dirty, locked, or pinned.
207  */
208
209 void gfs2_ail_empty_gl(struct gfs2_glock *gl)
210 {
211         struct gfs2_sbd *sdp = gl->gl_sbd;
212         unsigned int blocks;
213         struct list_head *head = &gl->gl_ail_list;
214         struct gfs2_bufdata *bd;
215         struct buffer_head *bh;
216         u64 blkno;
217         int error;
218
219         blocks = atomic_read(&gl->gl_ail_count);
220         if (!blocks)
221                 return;
222
223         error = gfs2_trans_begin(sdp, 0, blocks);
224         if (gfs2_assert_withdraw(sdp, !error))
225                 return;
226
227         gfs2_log_lock(sdp);
228         while (!list_empty(head)) {
229                 bd = list_entry(head->next, struct gfs2_bufdata,
230                                 bd_ail_gl_list);
231                 bh = bd->bd_bh;
232                 blkno = bh->b_blocknr;
233                 gfs2_assert_withdraw(sdp, !buffer_busy(bh));
234
235                 bd->bd_ail = NULL;
236                 list_del(&bd->bd_ail_st_list);
237                 list_del(&bd->bd_ail_gl_list);
238                 atomic_dec(&gl->gl_ail_count);
239                 brelse(bh);
240                 gfs2_log_unlock(sdp);
241
242                 gfs2_trans_add_revoke(sdp, blkno);
243
244                 gfs2_log_lock(sdp);
245         }
246         gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
247         gfs2_log_unlock(sdp);
248
249         gfs2_trans_end(sdp);
250         gfs2_log_flush(sdp, NULL);
251 }
252
253 /**
254  * gfs2_meta_inval - Invalidate all buffers associated with a glock
255  * @gl: the glock
256  *
257  */
258
259 void gfs2_meta_inval(struct gfs2_glock *gl)
260 {
261         struct gfs2_sbd *sdp = gl->gl_sbd;
262         struct inode *aspace = gl->gl_aspace;
263         struct address_space *mapping = gl->gl_aspace->i_mapping;
264
265         gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
266
267         atomic_inc(&aspace->i_writecount);
268         truncate_inode_pages(mapping, 0);
269         atomic_dec(&aspace->i_writecount);
270
271         gfs2_assert_withdraw(sdp, !mapping->nrpages);
272 }
273
274 /**
275  * gfs2_meta_sync - Sync all buffers associated with a glock
276  * @gl: The glock
277  *
278  */
279
280 void gfs2_meta_sync(struct gfs2_glock *gl)
281 {
282         struct address_space *mapping = gl->gl_aspace->i_mapping;
283         int error;
284
285         filemap_fdatawrite(mapping);
286         error = filemap_fdatawait(mapping);
287
288         if (error)
289                 gfs2_io_error(gl->gl_sbd);
290 }
291
292 /**
293  * getbuf - Get a buffer with a given address space
294  * @sdp: the filesystem
295  * @aspace: the address space
296  * @blkno: the block number (filesystem scope)
297  * @create: 1 if the buffer should be created
298  *
299  * Returns: the buffer
300  */
301
302 static struct buffer_head *getbuf(struct gfs2_sbd *sdp, struct inode *aspace,
303                                   u64 blkno, int create)
304 {
305         struct page *page;
306         struct buffer_head *bh;
307         unsigned int shift;
308         unsigned long index;
309         unsigned int bufnum;
310
311         shift = PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift;
312         index = blkno >> shift;             /* convert block to page */
313         bufnum = blkno - (index << shift);  /* block buf index within page */
314
315         if (create) {
316                 for (;;) {
317                         page = grab_cache_page(aspace->i_mapping, index);
318                         if (page)
319                                 break;
320                         yield();
321                 }
322         } else {
323                 page = find_lock_page(aspace->i_mapping, index);
324                 if (!page)
325                         return NULL;
326         }
327
328         if (!page_has_buffers(page))
329                 create_empty_buffers(page, sdp->sd_sb.sb_bsize, 0);
330
331         /* Locate header for our buffer within our page */
332         for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page)
333                 /* Do nothing */;
334         get_bh(bh);
335
336         if (!buffer_mapped(bh))
337                 map_bh(bh, sdp->sd_vfs, blkno);
338
339         unlock_page(page);
340         mark_page_accessed(page);
341         page_cache_release(page);
342
343         return bh;
344 }
345
346 static void meta_prep_new(struct buffer_head *bh)
347 {
348         struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
349
350         lock_buffer(bh);
351         clear_buffer_dirty(bh);
352         set_buffer_uptodate(bh);
353         unlock_buffer(bh);
354
355         mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
356 }
357
358 /**
359  * gfs2_meta_new - Get a block
360  * @gl: The glock associated with this block
361  * @blkno: The block number
362  *
363  * Returns: The buffer
364  */
365
366 struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
367 {
368         struct buffer_head *bh;
369         bh = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE);
370         meta_prep_new(bh);
371         return bh;
372 }
373
374 /**
375  * gfs2_meta_read - Read a block from disk
376  * @gl: The glock covering the block
377  * @blkno: The block number
378  * @flags: flags
379  * @bhp: the place where the buffer is returned (NULL on failure)
380  *
381  * Returns: errno
382  */
383
384 int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
385                    struct buffer_head **bhp)
386 {
387         *bhp = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE);
388         if (!buffer_uptodate(*bhp))
389                 ll_rw_block(READ_META, 1, bhp);
390         if (flags & DIO_WAIT) {
391                 int error = gfs2_meta_wait(gl->gl_sbd, *bhp);
392                 if (error) {
393                         brelse(*bhp);
394                         return error;
395                 }
396         }
397
398         return 0;
399 }
400
401 /**
402  * gfs2_meta_wait - Reread a block from disk
403  * @sdp: the filesystem
404  * @bh: The block to wait for
405  *
406  * Returns: errno
407  */
408
409 int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
410 {
411         if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
412                 return -EIO;
413
414         wait_on_buffer(bh);
415
416         if (!buffer_uptodate(bh)) {
417                 struct gfs2_trans *tr = current->journal_info;
418                 if (tr && tr->tr_touched)
419                         gfs2_io_error_bh(sdp, bh);
420                 return -EIO;
421         }
422         if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
423                 return -EIO;
424
425         return 0;
426 }
427
428 /**
429  * gfs2_attach_bufdata - attach a struct gfs2_bufdata structure to a buffer
430  * @gl: the glock the buffer belongs to
431  * @bh: The buffer to be attached to
432  * @meta: Flag to indicate whether its metadata or not
433  */
434
435 void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
436                          int meta)
437 {
438         struct gfs2_bufdata *bd;
439
440         if (meta)
441                 lock_page(bh->b_page);
442
443         if (bh->b_private) {
444                 if (meta)
445                         unlock_page(bh->b_page);
446                 return;
447         }
448
449         bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL),
450         memset(bd, 0, sizeof(struct gfs2_bufdata));
451         bd->bd_bh = bh;
452         bd->bd_gl = gl;
453
454         INIT_LIST_HEAD(&bd->bd_list_tr);
455         if (meta)
456                 lops_init_le(&bd->bd_le, &gfs2_buf_lops);
457         else
458                 lops_init_le(&bd->bd_le, &gfs2_databuf_lops);
459         bh->b_private = bd;
460
461         if (meta)
462                 unlock_page(bh->b_page);
463 }
464
465 /**
466  * gfs2_pin - Pin a buffer in memory
467  * @sdp: the filesystem the buffer belongs to
468  * @bh: The buffer to be pinned
469  *
470  */
471
472 void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh)
473 {
474         struct gfs2_bufdata *bd = bh->b_private;
475
476         gfs2_assert_withdraw(sdp, test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags));
477
478         if (test_set_buffer_pinned(bh))
479                 gfs2_assert_withdraw(sdp, 0);
480
481         wait_on_buffer(bh);
482
483         /* If this buffer is in the AIL and it has already been written
484            to in-place disk block, remove it from the AIL. */
485
486         gfs2_log_lock(sdp);
487         if (bd->bd_ail && !buffer_in_io(bh))
488                 list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list);
489         gfs2_log_unlock(sdp);
490
491         clear_buffer_dirty(bh);
492         wait_on_buffer(bh);
493
494         if (!buffer_uptodate(bh))
495                 gfs2_io_error_bh(sdp, bh);
496
497         get_bh(bh);
498 }
499
500 /**
501  * gfs2_unpin - Unpin a buffer
502  * @sdp: the filesystem the buffer belongs to
503  * @bh: The buffer to unpin
504  * @ai:
505  *
506  */
507
508 void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
509                 struct gfs2_ail *ai)
510 {
511         struct gfs2_bufdata *bd = bh->b_private;
512
513         gfs2_assert_withdraw(sdp, buffer_uptodate(bh));
514
515         if (!buffer_pinned(bh))
516                 gfs2_assert_withdraw(sdp, 0);
517
518         mark_buffer_dirty(bh);
519         clear_buffer_pinned(bh);
520
521         gfs2_log_lock(sdp);
522         if (bd->bd_ail) {
523                 list_del(&bd->bd_ail_st_list);
524                 brelse(bh);
525         } else {
526                 struct gfs2_glock *gl = bd->bd_gl;
527                 list_add(&bd->bd_ail_gl_list, &gl->gl_ail_list);
528                 atomic_inc(&gl->gl_ail_count);
529         }
530         bd->bd_ail = ai;
531         list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list);
532         gfs2_log_unlock(sdp);
533 }
534
535 /**
536  * gfs2_meta_wipe - make inode's buffers so they aren't dirty/pinned anymore
537  * @ip: the inode who owns the buffers
538  * @bstart: the first buffer in the run
539  * @blen: the number of buffers in the run
540  *
541  */
542
543 void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
544 {
545         struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
546         struct inode *aspace = ip->i_gl->gl_aspace;
547         struct buffer_head *bh;
548
549         while (blen) {
550                 bh = getbuf(sdp, aspace, bstart, NO_CREATE);
551                 if (bh) {
552                         struct gfs2_bufdata *bd = bh->b_private;
553
554                         if (test_clear_buffer_pinned(bh)) {
555                                 struct gfs2_trans *tr = current->journal_info;
556                                 gfs2_log_lock(sdp);
557                                 list_del_init(&bd->bd_le.le_list);
558                                 gfs2_assert_warn(sdp, sdp->sd_log_num_buf);
559                                 sdp->sd_log_num_buf--;
560                                 gfs2_log_unlock(sdp);
561                                 tr->tr_num_buf_rm++;
562                                 brelse(bh);
563                         }
564                         if (bd) {
565                                 gfs2_log_lock(sdp);
566                                 if (bd->bd_ail) {
567                                         u64 blkno = bh->b_blocknr;
568                                         bd->bd_ail = NULL;
569                                         list_del(&bd->bd_ail_st_list);
570                                         list_del(&bd->bd_ail_gl_list);
571                                         atomic_dec(&bd->bd_gl->gl_ail_count);
572                                         brelse(bh);
573                                         gfs2_log_unlock(sdp);
574                                         gfs2_trans_add_revoke(sdp, blkno);
575                                 } else
576                                         gfs2_log_unlock(sdp);
577                         }
578
579                         lock_buffer(bh);
580                         clear_buffer_dirty(bh);
581                         clear_buffer_uptodate(bh);
582                         unlock_buffer(bh);
583
584                         brelse(bh);
585                 }
586
587                 bstart++;
588                 blen--;
589         }
590 }
591
592 /**
593  * gfs2_meta_cache_flush - get rid of any references on buffers for this inode
594  * @ip: The GFS2 inode
595  *
596  * This releases buffers that are in the most-recently-used array of
597  * blocks used for indirect block addressing for this inode.
598  */
599
600 void gfs2_meta_cache_flush(struct gfs2_inode *ip)
601 {
602         struct buffer_head **bh_slot;
603         unsigned int x;
604
605         spin_lock(&ip->i_spin);
606
607         for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) {
608                 bh_slot = &ip->i_cache[x];
609                 if (!*bh_slot)
610                         break;
611                 brelse(*bh_slot);
612                 *bh_slot = NULL;
613         }
614
615         spin_unlock(&ip->i_spin);
616 }
617
618 /**
619  * gfs2_meta_indirect_buffer - Get a metadata buffer
620  * @ip: The GFS2 inode
621  * @height: The level of this buf in the metadata (indir addr) tree (if any)
622  * @num: The block number (device relative) of the buffer
623  * @new: Non-zero if we may create a new buffer
624  * @bhp: the buffer is returned here
625  *
626  * Try to use the gfs2_inode's MRU metadata tree cache.
627  *
628  * Returns: errno
629  */
630
631 int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
632                               int new, struct buffer_head **bhp)
633 {
634         struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
635         struct gfs2_glock *gl = ip->i_gl;
636         struct buffer_head *bh = NULL, **bh_slot = ip->i_cache + height;
637         int in_cache = 0;
638
639         spin_lock(&ip->i_spin);
640         if (*bh_slot && (*bh_slot)->b_blocknr == num) {
641                 bh = *bh_slot;
642                 get_bh(bh);
643                 in_cache = 1;
644         }
645         spin_unlock(&ip->i_spin);
646
647         if (!bh)
648                 bh = getbuf(gl->gl_sbd, gl->gl_aspace, num, CREATE);
649
650         if (!bh)
651                 return -ENOBUFS;
652
653         if (new) {
654                 if (gfs2_assert_warn(sdp, height))
655                         goto err;
656                 meta_prep_new(bh);
657                 gfs2_trans_add_bh(ip->i_gl, bh, 1);
658                 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
659                 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
660         } else {
661                 u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI;
662                 if (!buffer_uptodate(bh)) {
663                         ll_rw_block(READ_META, 1, &bh);
664                         if (gfs2_meta_wait(sdp, bh))
665                                 goto err;
666                 }
667                 if (gfs2_metatype_check(sdp, bh, mtype))
668                         goto err;
669         }
670
671         if (!in_cache) {
672                 spin_lock(&ip->i_spin);
673                 if (*bh_slot)
674                         brelse(*bh_slot);
675                 *bh_slot = bh;
676                 get_bh(bh);
677                 spin_unlock(&ip->i_spin);
678         }
679
680         *bhp = bh;
681         return 0;
682 err:
683         brelse(bh);
684         return -EIO;
685 }
686
687 /**
688  * gfs2_meta_ra - start readahead on an extent of a file
689  * @gl: the glock the blocks belong to
690  * @dblock: the starting disk block
691  * @extlen: the number of blocks in the extent
692  *
693  * returns: the first buffer in the extent
694  */
695
696 struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
697 {
698         struct gfs2_sbd *sdp = gl->gl_sbd;
699         struct inode *aspace = gl->gl_aspace;
700         struct buffer_head *first_bh, *bh;
701         u32 max_ra = gfs2_tune_get(sdp, gt_max_readahead) >>
702                           sdp->sd_sb.sb_bsize_shift;
703
704         BUG_ON(!extlen);
705
706         if (max_ra < 1)
707                 max_ra = 1;
708         if (extlen > max_ra)
709                 extlen = max_ra;
710
711         first_bh = getbuf(sdp, aspace, dblock, CREATE);
712
713         if (buffer_uptodate(first_bh))
714                 goto out;
715         if (!buffer_locked(first_bh))
716                 ll_rw_block(READ_META, 1, &first_bh);
717
718         dblock++;
719         extlen--;
720
721         while (extlen) {
722                 bh = getbuf(sdp, aspace, dblock, CREATE);
723
724                 if (!buffer_uptodate(bh) && !buffer_locked(bh))
725                         ll_rw_block(READA, 1, &bh);
726                 brelse(bh);
727                 dblock++;
728                 extlen--;
729                 if (!buffer_locked(first_bh) && buffer_uptodate(first_bh))
730                         goto out;
731         }
732
733         wait_on_buffer(first_bh);
734 out:
735         return first_bh;
736 }
737
738 /**
739  * gfs2_meta_syncfs - sync all the buffers in a filesystem
740  * @sdp: the filesystem
741  *
742  */
743
744 void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
745 {
746         gfs2_log_flush(sdp, NULL);
747         for (;;) {
748                 gfs2_ail1_start(sdp, DIO_ALL);
749                 if (gfs2_ail1_empty(sdp, DIO_ALL))
750                         break;
751                 msleep(10);
752         }
753 }
754