]> err.no Git - linux-2.6/blob - fs/gfs2/log.c
[GFS2] Move gfs2_meta_syncfs() into log.c
[linux-2.6] / fs / gfs2 / log.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/gfs2_ondisk.h>
16 #include <linux/crc32.h>
17 #include <linux/lm_interface.h>
18 #include <linux/delay.h>
19
20 #include "gfs2.h"
21 #include "incore.h"
22 #include "bmap.h"
23 #include "glock.h"
24 #include "log.h"
25 #include "lops.h"
26 #include "meta_io.h"
27 #include "util.h"
28 #include "dir.h"
29
30 #define PULL 1
31
32 /**
33  * gfs2_struct2blk - compute stuff
34  * @sdp: the filesystem
35  * @nstruct: the number of structures
36  * @ssize: the size of the structures
37  *
38  * Compute the number of log descriptor blocks needed to hold a certain number
39  * of structures of a certain size.
40  *
41  * Returns: the number of blocks needed (minimum is always 1)
42  */
43
44 unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
45                              unsigned int ssize)
46 {
47         unsigned int blks;
48         unsigned int first, second;
49
50         blks = 1;
51         first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize;
52
53         if (nstruct > first) {
54                 second = (sdp->sd_sb.sb_bsize -
55                           sizeof(struct gfs2_meta_header)) / ssize;
56                 blks += DIV_ROUND_UP(nstruct - first, second);
57         }
58
59         return blks;
60 }
61
62 /**
63  * gfs2_ail1_start_one - Start I/O on a part of the AIL
64  * @sdp: the filesystem
65  * @tr: the part of the AIL
66  *
67  */
68
69 static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
70 {
71         struct gfs2_bufdata *bd, *s;
72         struct buffer_head *bh;
73         int retry;
74
75         BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
76
77         do {
78                 retry = 0;
79
80                 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
81                                                  bd_ail_st_list) {
82                         bh = bd->bd_bh;
83
84                         gfs2_assert(sdp, bd->bd_ail == ai);
85
86                         if (!buffer_busy(bh)) {
87                                 if (!buffer_uptodate(bh)) {
88                                         gfs2_log_unlock(sdp);
89                                         gfs2_io_error_bh(sdp, bh);
90                                         gfs2_log_lock(sdp);
91                                 }
92                                 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
93                                 continue;
94                         }
95
96                         if (!buffer_dirty(bh))
97                                 continue;
98
99                         list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
100
101                         gfs2_log_unlock(sdp);
102                         wait_on_buffer(bh);
103                         ll_rw_block(WRITE, 1, &bh);
104                         gfs2_log_lock(sdp);
105
106                         retry = 1;
107                         break;
108                 }
109         } while (retry);
110 }
111
112 /**
113  * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
114  * @sdp: the filesystem
115  * @ai: the AIL entry
116  *
117  */
118
119 static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
120 {
121         struct gfs2_bufdata *bd, *s;
122         struct buffer_head *bh;
123
124         list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
125                                          bd_ail_st_list) {
126                 bh = bd->bd_bh;
127
128                 gfs2_assert(sdp, bd->bd_ail == ai);
129
130                 if (buffer_busy(bh)) {
131                         if (flags & DIO_ALL)
132                                 continue;
133                         else
134                                 break;
135                 }
136
137                 if (!buffer_uptodate(bh))
138                         gfs2_io_error_bh(sdp, bh);
139
140                 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
141         }
142
143         return list_empty(&ai->ai_ail1_list);
144 }
145
146 static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
147 {
148         struct list_head *head = &sdp->sd_ail1_list;
149         u64 sync_gen;
150         struct list_head *first;
151         struct gfs2_ail *first_ai, *ai, *tmp;
152         int done = 0;
153
154         gfs2_log_lock(sdp);
155         if (list_empty(head)) {
156                 gfs2_log_unlock(sdp);
157                 return;
158         }
159         sync_gen = sdp->sd_ail_sync_gen++;
160
161         first = head->prev;
162         first_ai = list_entry(first, struct gfs2_ail, ai_list);
163         first_ai->ai_sync_gen = sync_gen;
164         gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */
165
166         if (flags & DIO_ALL)
167                 first = NULL;
168
169         while(!done) {
170                 if (first && (head->prev != first ||
171                               gfs2_ail1_empty_one(sdp, first_ai, 0)))
172                         break;
173
174                 done = 1;
175                 list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) {
176                         if (ai->ai_sync_gen >= sync_gen)
177                                 continue;
178                         ai->ai_sync_gen = sync_gen;
179                         gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */
180                         done = 0;
181                         break;
182                 }
183         }
184
185         gfs2_log_unlock(sdp);
186 }
187
188 int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
189 {
190         struct gfs2_ail *ai, *s;
191         int ret;
192
193         gfs2_log_lock(sdp);
194
195         list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
196                 if (gfs2_ail1_empty_one(sdp, ai, flags))
197                         list_move(&ai->ai_list, &sdp->sd_ail2_list);
198                 else if (!(flags & DIO_ALL))
199                         break;
200         }
201
202         ret = list_empty(&sdp->sd_ail1_list);
203
204         gfs2_log_unlock(sdp);
205
206         return ret;
207 }
208
209
210 /**
211  * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
212  * @sdp: the filesystem
213  * @ai: the AIL entry
214  *
215  */
216
217 static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
218 {
219         struct list_head *head = &ai->ai_ail2_list;
220         struct gfs2_bufdata *bd;
221
222         while (!list_empty(head)) {
223                 bd = list_entry(head->prev, struct gfs2_bufdata,
224                                 bd_ail_st_list);
225                 gfs2_assert(sdp, bd->bd_ail == ai);
226                 bd->bd_ail = NULL;
227                 list_del(&bd->bd_ail_st_list);
228                 list_del(&bd->bd_ail_gl_list);
229                 atomic_dec(&bd->bd_gl->gl_ail_count);
230                 brelse(bd->bd_bh);
231         }
232 }
233
234 static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
235 {
236         struct gfs2_ail *ai, *safe;
237         unsigned int old_tail = sdp->sd_log_tail;
238         int wrap = (new_tail < old_tail);
239         int a, b, rm;
240
241         gfs2_log_lock(sdp);
242
243         list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
244                 a = (old_tail <= ai->ai_first);
245                 b = (ai->ai_first < new_tail);
246                 rm = (wrap) ? (a || b) : (a && b);
247                 if (!rm)
248                         continue;
249
250                 gfs2_ail2_empty_one(sdp, ai);
251                 list_del(&ai->ai_list);
252                 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
253                 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
254                 kfree(ai);
255         }
256
257         gfs2_log_unlock(sdp);
258 }
259
260 /**
261  * gfs2_log_reserve - Make a log reservation
262  * @sdp: The GFS2 superblock
263  * @blks: The number of blocks to reserve
264  *
265  * Note that we never give out the last 6 blocks of the journal. Thats
266  * due to the fact that there is are a small number of header blocks
267  * associated with each log flush. The exact number can't be known until
268  * flush time, so we ensure that we have just enough free blocks at all
269  * times to avoid running out during a log flush.
270  *
271  * Returns: errno
272  */
273
274 int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
275 {
276         unsigned int try = 0;
277
278         if (gfs2_assert_warn(sdp, blks) ||
279             gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
280                 return -EINVAL;
281
282         mutex_lock(&sdp->sd_log_reserve_mutex);
283         gfs2_log_lock(sdp);
284         while(sdp->sd_log_blks_free <= (blks + 6)) {
285                 gfs2_log_unlock(sdp);
286                 gfs2_ail1_empty(sdp, 0);
287                 gfs2_log_flush(sdp, NULL);
288
289                 if (try++)
290                         gfs2_ail1_start(sdp, 0);
291                 gfs2_log_lock(sdp);
292         }
293         sdp->sd_log_blks_free -= blks;
294         gfs2_log_unlock(sdp);
295         mutex_unlock(&sdp->sd_log_reserve_mutex);
296
297         down_read(&sdp->sd_log_flush_lock);
298
299         return 0;
300 }
301
302 /**
303  * gfs2_log_release - Release a given number of log blocks
304  * @sdp: The GFS2 superblock
305  * @blks: The number of blocks
306  *
307  */
308
309 void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
310 {
311
312         gfs2_log_lock(sdp);
313         sdp->sd_log_blks_free += blks;
314         gfs2_assert_withdraw(sdp,
315                              sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks);
316         gfs2_log_unlock(sdp);
317         up_read(&sdp->sd_log_flush_lock);
318 }
319
320 static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
321 {
322         struct inode *inode = sdp->sd_jdesc->jd_inode;
323         int error;
324         struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
325
326         bh_map.b_size = 1 << inode->i_blkbits;
327         error = gfs2_block_map(inode, lbn, 0, &bh_map);
328         if (error || !bh_map.b_blocknr)
329                 printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, bh_map.b_blocknr, lbn);
330         gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr);
331
332         return bh_map.b_blocknr;
333 }
334
335 /**
336  * log_distance - Compute distance between two journal blocks
337  * @sdp: The GFS2 superblock
338  * @newer: The most recent journal block of the pair
339  * @older: The older journal block of the pair
340  *
341  *   Compute the distance (in the journal direction) between two
342  *   blocks in the journal
343  *
344  * Returns: the distance in blocks
345  */
346
347 static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer,
348                                         unsigned int older)
349 {
350         int dist;
351
352         dist = newer - older;
353         if (dist < 0)
354                 dist += sdp->sd_jdesc->jd_blocks;
355
356         return dist;
357 }
358
359 static unsigned int current_tail(struct gfs2_sbd *sdp)
360 {
361         struct gfs2_ail *ai;
362         unsigned int tail;
363
364         gfs2_log_lock(sdp);
365
366         if (list_empty(&sdp->sd_ail1_list)) {
367                 tail = sdp->sd_log_head;
368         } else {
369                 ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list);
370                 tail = ai->ai_first;
371         }
372
373         gfs2_log_unlock(sdp);
374
375         return tail;
376 }
377
378 static inline void log_incr_head(struct gfs2_sbd *sdp)
379 {
380         if (sdp->sd_log_flush_head == sdp->sd_log_tail)
381                 gfs2_assert_withdraw(sdp, sdp->sd_log_flush_head == sdp->sd_log_head);
382
383         if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
384                 sdp->sd_log_flush_head = 0;
385                 sdp->sd_log_flush_wrapped = 1;
386         }
387 }
388
389 /**
390  * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
391  * @sdp: The GFS2 superblock
392  *
393  * Returns: the buffer_head
394  */
395
396 struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
397 {
398         u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
399         struct gfs2_log_buf *lb;
400         struct buffer_head *bh;
401
402         lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL);
403         list_add(&lb->lb_list, &sdp->sd_log_flush_list);
404
405         bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno);
406         lock_buffer(bh);
407         memset(bh->b_data, 0, bh->b_size);
408         set_buffer_uptodate(bh);
409         clear_buffer_dirty(bh);
410         unlock_buffer(bh);
411
412         log_incr_head(sdp);
413
414         return bh;
415 }
416
417 /**
418  * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
419  * @sdp: the filesystem
420  * @data: the data the buffer_head should point to
421  *
422  * Returns: the log buffer descriptor
423  */
424
425 struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
426                                       struct buffer_head *real)
427 {
428         u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
429         struct gfs2_log_buf *lb;
430         struct buffer_head *bh;
431
432         lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL);
433         list_add(&lb->lb_list, &sdp->sd_log_flush_list);
434         lb->lb_real = real;
435
436         bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
437         atomic_set(&bh->b_count, 1);
438         bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate);
439         set_bh_page(bh, real->b_page, bh_offset(real));
440         bh->b_blocknr = blkno;
441         bh->b_size = sdp->sd_sb.sb_bsize;
442         bh->b_bdev = sdp->sd_vfs->s_bdev;
443
444         log_incr_head(sdp);
445
446         return bh;
447 }
448
449 static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull)
450 {
451         unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
452
453         ail2_empty(sdp, new_tail);
454
455         gfs2_log_lock(sdp);
456         sdp->sd_log_blks_free += dist - (pull ? 1 : 0);
457         gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks);
458         gfs2_log_unlock(sdp);
459
460         sdp->sd_log_tail = new_tail;
461 }
462
463 /**
464  * log_write_header - Get and initialize a journal header buffer
465  * @sdp: The GFS2 superblock
466  *
467  * Returns: the initialized log buffer descriptor
468  */
469
470 static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
471 {
472         u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
473         struct buffer_head *bh;
474         struct gfs2_log_header *lh;
475         unsigned int tail;
476         u32 hash;
477
478         bh = sb_getblk(sdp->sd_vfs, blkno);
479         lock_buffer(bh);
480         memset(bh->b_data, 0, bh->b_size);
481         set_buffer_uptodate(bh);
482         clear_buffer_dirty(bh);
483         unlock_buffer(bh);
484
485         gfs2_ail1_empty(sdp, 0);
486         tail = current_tail(sdp);
487
488         lh = (struct gfs2_log_header *)bh->b_data;
489         memset(lh, 0, sizeof(struct gfs2_log_header));
490         lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
491         lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
492         lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
493         lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
494         lh->lh_flags = cpu_to_be32(flags);
495         lh->lh_tail = cpu_to_be32(tail);
496         lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
497         hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
498         lh->lh_hash = cpu_to_be32(hash);
499
500         set_buffer_dirty(bh);
501         if (sync_dirty_buffer(bh))
502                 gfs2_io_error_bh(sdp, bh);
503         brelse(bh);
504
505         if (sdp->sd_log_tail != tail)
506                 log_pull_tail(sdp, tail, pull);
507         else
508                 gfs2_assert_withdraw(sdp, !pull);
509
510         sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
511         log_incr_head(sdp);
512 }
513
514 static void log_flush_commit(struct gfs2_sbd *sdp)
515 {
516         struct list_head *head = &sdp->sd_log_flush_list;
517         struct gfs2_log_buf *lb;
518         struct buffer_head *bh;
519
520         while (!list_empty(head)) {
521                 lb = list_entry(head->next, struct gfs2_log_buf, lb_list);
522                 list_del(&lb->lb_list);
523                 bh = lb->lb_bh;
524
525                 wait_on_buffer(bh);
526                 if (!buffer_uptodate(bh))
527                         gfs2_io_error_bh(sdp, bh);
528                 if (lb->lb_real) {
529                         while (atomic_read(&bh->b_count) != 1)  /* Grrrr... */
530                                 schedule();
531                         free_buffer_head(bh);
532                 } else
533                         brelse(bh);
534                 kfree(lb);
535         }
536
537         log_write_header(sdp, 0, 0);
538 }
539
540 /**
541  * gfs2_log_flush - flush incore transaction(s)
542  * @sdp: the filesystem
543  * @gl: The glock structure to flush.  If NULL, flush the whole incore log
544  *
545  */
546
547 void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
548 {
549         struct gfs2_ail *ai;
550
551         down_write(&sdp->sd_log_flush_lock);
552
553         if (gl) {
554                 gfs2_log_lock(sdp);
555                 if (list_empty(&gl->gl_le.le_list)) {
556                         gfs2_log_unlock(sdp);
557                         up_write(&sdp->sd_log_flush_lock);
558                         return;
559                 }
560                 gfs2_log_unlock(sdp);
561         }
562
563         ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
564         INIT_LIST_HEAD(&ai->ai_ail1_list);
565         INIT_LIST_HEAD(&ai->ai_ail2_list);
566
567         gfs2_assert_withdraw(sdp, sdp->sd_log_num_buf == sdp->sd_log_commited_buf);
568         gfs2_assert_withdraw(sdp,
569                         sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
570
571         sdp->sd_log_flush_head = sdp->sd_log_head;
572         sdp->sd_log_flush_wrapped = 0;
573         ai->ai_first = sdp->sd_log_flush_head;
574
575         lops_before_commit(sdp);
576         if (!list_empty(&sdp->sd_log_flush_list))
577                 log_flush_commit(sdp);
578         else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle)
579                 log_write_header(sdp, 0, PULL);
580         lops_after_commit(sdp, ai);
581
582         gfs2_log_lock(sdp);
583         sdp->sd_log_head = sdp->sd_log_flush_head;
584         sdp->sd_log_blks_free -= sdp->sd_log_num_hdrs;
585         sdp->sd_log_blks_reserved = 0;
586         sdp->sd_log_commited_buf = 0;
587         sdp->sd_log_num_hdrs = 0;
588         sdp->sd_log_commited_revoke = 0;
589
590         if (!list_empty(&ai->ai_ail1_list)) {
591                 list_add(&ai->ai_list, &sdp->sd_ail1_list);
592                 ai = NULL;
593         }
594         gfs2_log_unlock(sdp);
595
596         sdp->sd_vfs->s_dirt = 0;
597         up_write(&sdp->sd_log_flush_lock);
598
599         kfree(ai);
600 }
601
602 static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
603 {
604         unsigned int reserved = 0;
605         unsigned int old;
606
607         gfs2_log_lock(sdp);
608
609         sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
610         gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_buf) >= 0);
611         sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
612         gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
613
614         if (sdp->sd_log_commited_buf)
615                 reserved += sdp->sd_log_commited_buf;
616         if (sdp->sd_log_commited_revoke)
617                 reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
618                                             sizeof(u64));
619         if (reserved)
620                 reserved++;
621
622         old = sdp->sd_log_blks_free;
623         sdp->sd_log_blks_free += tr->tr_reserved -
624                                  (reserved - sdp->sd_log_blks_reserved);
625
626         gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old);
627         gfs2_assert_withdraw(sdp,
628                              sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks +
629                              sdp->sd_log_num_hdrs);
630
631         sdp->sd_log_blks_reserved = reserved;
632
633         gfs2_log_unlock(sdp);
634 }
635
636 /**
637  * gfs2_log_commit - Commit a transaction to the log
638  * @sdp: the filesystem
639  * @tr: the transaction
640  *
641  * Returns: errno
642  */
643
644 void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
645 {
646         log_refund(sdp, tr);
647         lops_incore_commit(sdp, tr);
648
649         sdp->sd_vfs->s_dirt = 1;
650         up_read(&sdp->sd_log_flush_lock);
651
652         gfs2_log_lock(sdp);
653         if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks))
654                 wake_up_process(sdp->sd_logd_process);
655         gfs2_log_unlock(sdp);
656 }
657
658 /**
659  * gfs2_log_shutdown - write a shutdown header into a journal
660  * @sdp: the filesystem
661  *
662  */
663
664 void gfs2_log_shutdown(struct gfs2_sbd *sdp)
665 {
666         down_write(&sdp->sd_log_flush_lock);
667
668         gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
669         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl);
670         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
671         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_jdata);
672         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
673         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
674         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
675         gfs2_assert_withdraw(sdp, !sdp->sd_log_num_hdrs);
676         gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
677
678         sdp->sd_log_flush_head = sdp->sd_log_head;
679         sdp->sd_log_flush_wrapped = 0;
680
681         log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0);
682
683         gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks);
684         gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
685         gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
686
687         sdp->sd_log_head = sdp->sd_log_flush_head;
688         sdp->sd_log_tail = sdp->sd_log_head;
689
690         up_write(&sdp->sd_log_flush_lock);
691 }
692
693
694 /**
695  * gfs2_meta_syncfs - sync all the buffers in a filesystem
696  * @sdp: the filesystem
697  *
698  */
699
700 void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
701 {
702         gfs2_log_flush(sdp, NULL);
703         for (;;) {
704                 gfs2_ail1_start(sdp, DIO_ALL);
705                 if (gfs2_ail1_empty(sdp, DIO_ALL))
706                         break;
707                 msleep(10);
708         }
709 }
710