David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 15 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 16 | #include <linux/crc32.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 17 | #include <linux/lm_interface.h> |
Steven Whitehouse | a25311c | 2006-11-23 11:06:35 -0500 | [diff] [blame] | 18 | #include <linux/delay.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 19 | |
| 20 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | #include "bmap.h" |
| 23 | #include "glock.h" |
| 24 | #include "log.h" |
| 25 | #include "lops.h" |
| 26 | #include "meta_io.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 27 | #include "util.h" |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 28 | #include "dir.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | |
| 30 | #define PULL 1 |
| 31 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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; |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 51 | first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 52 | |
| 53 | if (nstruct > first) { |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 54 | second = (sdp->sd_sb.sb_bsize - |
| 55 | sizeof(struct gfs2_meta_header)) / ssize; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 56 | blks += DIV_ROUND_UP(nstruct - first, second); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | return blks; |
| 60 | } |
| 61 | |
Steven Whitehouse | ddacfaf | 2006-10-03 11:10:41 -0400 | [diff] [blame] | 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 | |
Robert Peterson | 8fb6859 | 2007-06-12 11:24:36 -0500 | [diff] [blame] | 86 | if (!bh){ |
| 87 | list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); |
| 88 | continue; |
| 89 | } |
| 90 | |
Steven Whitehouse | ddacfaf | 2006-10-03 11:10:41 -0400 | [diff] [blame] | 91 | if (!buffer_busy(bh)) { |
| 92 | if (!buffer_uptodate(bh)) { |
| 93 | gfs2_log_unlock(sdp); |
| 94 | gfs2_io_error_bh(sdp, bh); |
| 95 | gfs2_log_lock(sdp); |
| 96 | } |
| 97 | list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | if (!buffer_dirty(bh)) |
| 102 | continue; |
| 103 | |
| 104 | list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); |
| 105 | |
| 106 | gfs2_log_unlock(sdp); |
| 107 | wait_on_buffer(bh); |
| 108 | ll_rw_block(WRITE, 1, &bh); |
| 109 | gfs2_log_lock(sdp); |
| 110 | |
| 111 | retry = 1; |
| 112 | break; |
| 113 | } |
| 114 | } while (retry); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced |
| 119 | * @sdp: the filesystem |
| 120 | * @ai: the AIL entry |
| 121 | * |
| 122 | */ |
| 123 | |
| 124 | static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags) |
| 125 | { |
| 126 | struct gfs2_bufdata *bd, *s; |
| 127 | struct buffer_head *bh; |
| 128 | |
| 129 | list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, |
| 130 | bd_ail_st_list) { |
| 131 | bh = bd->bd_bh; |
| 132 | |
Robert Peterson | 8fb6859 | 2007-06-12 11:24:36 -0500 | [diff] [blame] | 133 | if (!bh){ |
| 134 | list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); |
| 135 | continue; |
| 136 | } |
| 137 | |
Steven Whitehouse | ddacfaf | 2006-10-03 11:10:41 -0400 | [diff] [blame] | 138 | gfs2_assert(sdp, bd->bd_ail == ai); |
| 139 | |
| 140 | if (buffer_busy(bh)) { |
| 141 | if (flags & DIO_ALL) |
| 142 | continue; |
| 143 | else |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | if (!buffer_uptodate(bh)) |
| 148 | gfs2_io_error_bh(sdp, bh); |
| 149 | |
| 150 | list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); |
| 151 | } |
| 152 | |
| 153 | return list_empty(&ai->ai_ail1_list); |
| 154 | } |
| 155 | |
Steven Whitehouse | a25311c | 2006-11-23 11:06:35 -0500 | [diff] [blame] | 156 | static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 157 | { |
| 158 | struct list_head *head = &sdp->sd_ail1_list; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 159 | u64 sync_gen; |
Steven Whitehouse | 7466941 | 2006-09-19 11:17:38 -0400 | [diff] [blame] | 160 | struct list_head *first; |
| 161 | struct gfs2_ail *first_ai, *ai, *tmp; |
| 162 | int done = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 163 | |
| 164 | gfs2_log_lock(sdp); |
| 165 | if (list_empty(head)) { |
| 166 | gfs2_log_unlock(sdp); |
| 167 | return; |
| 168 | } |
| 169 | sync_gen = sdp->sd_ail_sync_gen++; |
| 170 | |
| 171 | first = head->prev; |
| 172 | first_ai = list_entry(first, struct gfs2_ail, ai_list); |
| 173 | first_ai->ai_sync_gen = sync_gen; |
Steven Whitehouse | 7466941 | 2006-09-19 11:17:38 -0400 | [diff] [blame] | 174 | gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 175 | |
| 176 | if (flags & DIO_ALL) |
| 177 | first = NULL; |
| 178 | |
Steven Whitehouse | 7466941 | 2006-09-19 11:17:38 -0400 | [diff] [blame] | 179 | while(!done) { |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 180 | if (first && (head->prev != first || |
| 181 | gfs2_ail1_empty_one(sdp, first_ai, 0))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 182 | break; |
| 183 | |
Steven Whitehouse | 7466941 | 2006-09-19 11:17:38 -0400 | [diff] [blame] | 184 | done = 1; |
| 185 | list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 186 | if (ai->ai_sync_gen >= sync_gen) |
| 187 | continue; |
| 188 | ai->ai_sync_gen = sync_gen; |
Steven Whitehouse | 7466941 | 2006-09-19 11:17:38 -0400 | [diff] [blame] | 189 | gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */ |
| 190 | done = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 191 | break; |
| 192 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | gfs2_log_unlock(sdp); |
| 196 | } |
| 197 | |
| 198 | int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) |
| 199 | { |
| 200 | struct gfs2_ail *ai, *s; |
| 201 | int ret; |
| 202 | |
| 203 | gfs2_log_lock(sdp); |
| 204 | |
| 205 | list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) { |
| 206 | if (gfs2_ail1_empty_one(sdp, ai, flags)) |
| 207 | list_move(&ai->ai_list, &sdp->sd_ail2_list); |
| 208 | else if (!(flags & DIO_ALL)) |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | ret = list_empty(&sdp->sd_ail1_list); |
| 213 | |
| 214 | gfs2_log_unlock(sdp); |
| 215 | |
| 216 | return ret; |
| 217 | } |
| 218 | |
Steven Whitehouse | ddacfaf | 2006-10-03 11:10:41 -0400 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced |
| 222 | * @sdp: the filesystem |
| 223 | * @ai: the AIL entry |
| 224 | * |
| 225 | */ |
| 226 | |
| 227 | static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) |
| 228 | { |
| 229 | struct list_head *head = &ai->ai_ail2_list; |
| 230 | struct gfs2_bufdata *bd; |
| 231 | |
| 232 | while (!list_empty(head)) { |
| 233 | bd = list_entry(head->prev, struct gfs2_bufdata, |
| 234 | bd_ail_st_list); |
| 235 | gfs2_assert(sdp, bd->bd_ail == ai); |
| 236 | bd->bd_ail = NULL; |
| 237 | list_del(&bd->bd_ail_st_list); |
| 238 | list_del(&bd->bd_ail_gl_list); |
| 239 | atomic_dec(&bd->bd_gl->gl_ail_count); |
Robert Peterson | 8fb6859 | 2007-06-12 11:24:36 -0500 | [diff] [blame] | 240 | if (bd->bd_bh) |
| 241 | brelse(bd->bd_bh); |
| 242 | else |
| 243 | kmem_cache_free(gfs2_bufdata_cachep, bd); |
Steven Whitehouse | ddacfaf | 2006-10-03 11:10:41 -0400 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 247 | static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) |
| 248 | { |
| 249 | struct gfs2_ail *ai, *safe; |
| 250 | unsigned int old_tail = sdp->sd_log_tail; |
| 251 | int wrap = (new_tail < old_tail); |
| 252 | int a, b, rm; |
| 253 | |
| 254 | gfs2_log_lock(sdp); |
| 255 | |
| 256 | list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) { |
| 257 | a = (old_tail <= ai->ai_first); |
| 258 | b = (ai->ai_first < new_tail); |
| 259 | rm = (wrap) ? (a || b) : (a && b); |
| 260 | if (!rm) |
| 261 | continue; |
| 262 | |
| 263 | gfs2_ail2_empty_one(sdp, ai); |
| 264 | list_del(&ai->ai_list); |
| 265 | gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list)); |
| 266 | gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list)); |
| 267 | kfree(ai); |
| 268 | } |
| 269 | |
| 270 | gfs2_log_unlock(sdp); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * gfs2_log_reserve - Make a log reservation |
| 275 | * @sdp: The GFS2 superblock |
| 276 | * @blks: The number of blocks to reserve |
| 277 | * |
Steven Whitehouse | 8991864 | 2007-06-01 15:19:33 +0100 | [diff] [blame] | 278 | * Note that we never give out the last few blocks of the journal. Thats |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 279 | * due to the fact that there is a small number of header blocks |
Steven Whitehouse | b004157 | 2006-11-23 10:51:34 -0500 | [diff] [blame] | 280 | * associated with each log flush. The exact number can't be known until |
| 281 | * flush time, so we ensure that we have just enough free blocks at all |
| 282 | * times to avoid running out during a log flush. |
| 283 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 284 | * Returns: errno |
| 285 | */ |
| 286 | |
| 287 | int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) |
| 288 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 289 | unsigned int try = 0; |
Steven Whitehouse | 8991864 | 2007-06-01 15:19:33 +0100 | [diff] [blame] | 290 | unsigned reserved_blks = 6 * (4096 / sdp->sd_vfs->s_blocksize); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 291 | |
| 292 | if (gfs2_assert_warn(sdp, blks) || |
| 293 | gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks)) |
| 294 | return -EINVAL; |
| 295 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 296 | mutex_lock(&sdp->sd_log_reserve_mutex); |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 297 | gfs2_log_lock(sdp); |
Steven Whitehouse | 8991864 | 2007-06-01 15:19:33 +0100 | [diff] [blame] | 298 | while(sdp->sd_log_blks_free <= (blks + reserved_blks)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 299 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 300 | gfs2_ail1_empty(sdp, 0); |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 301 | gfs2_log_flush(sdp, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 302 | |
| 303 | if (try++) |
| 304 | gfs2_ail1_start(sdp, 0); |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 305 | gfs2_log_lock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 306 | } |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 307 | sdp->sd_log_blks_free -= blks; |
| 308 | gfs2_log_unlock(sdp); |
| 309 | mutex_unlock(&sdp->sd_log_reserve_mutex); |
| 310 | |
| 311 | down_read(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * gfs2_log_release - Release a given number of log blocks |
| 318 | * @sdp: The GFS2 superblock |
| 319 | * @blks: The number of blocks |
| 320 | * |
| 321 | */ |
| 322 | |
| 323 | void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) |
| 324 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 325 | |
| 326 | gfs2_log_lock(sdp); |
| 327 | sdp->sd_log_blks_free += blks; |
| 328 | gfs2_assert_withdraw(sdp, |
| 329 | sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); |
| 330 | gfs2_log_unlock(sdp); |
Steven Whitehouse | ed38650 | 2006-04-07 16:28:07 -0400 | [diff] [blame] | 331 | up_read(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 334 | static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 335 | { |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 336 | struct inode *inode = sdp->sd_jdesc->jd_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 337 | int error; |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 338 | struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 }; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 339 | |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 340 | bh_map.b_size = 1 << inode->i_blkbits; |
| 341 | error = gfs2_block_map(inode, lbn, 0, &bh_map); |
Steven Whitehouse | 7a6bbac | 2006-09-18 17:18:23 -0400 | [diff] [blame] | 342 | if (error || !bh_map.b_blocknr) |
Ryusuke Konishi | aed3255 | 2006-11-28 02:53:22 +0900 | [diff] [blame] | 343 | printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, |
| 344 | (unsigned long long)bh_map.b_blocknr, lbn); |
Steven Whitehouse | 7a6bbac | 2006-09-18 17:18:23 -0400 | [diff] [blame] | 345 | gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 346 | |
Steven Whitehouse | 7a6bbac | 2006-09-18 17:18:23 -0400 | [diff] [blame] | 347 | return bh_map.b_blocknr; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /** |
| 351 | * log_distance - Compute distance between two journal blocks |
| 352 | * @sdp: The GFS2 superblock |
| 353 | * @newer: The most recent journal block of the pair |
| 354 | * @older: The older journal block of the pair |
| 355 | * |
| 356 | * Compute the distance (in the journal direction) between two |
| 357 | * blocks in the journal |
| 358 | * |
| 359 | * Returns: the distance in blocks |
| 360 | */ |
| 361 | |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 362 | static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 363 | unsigned int older) |
| 364 | { |
| 365 | int dist; |
| 366 | |
| 367 | dist = newer - older; |
| 368 | if (dist < 0) |
| 369 | dist += sdp->sd_jdesc->jd_blocks; |
| 370 | |
| 371 | return dist; |
| 372 | } |
| 373 | |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 374 | /** |
| 375 | * calc_reserved - Calculate the number of blocks to reserve when |
| 376 | * refunding a transaction's unused buffers. |
| 377 | * @sdp: The GFS2 superblock |
| 378 | * |
| 379 | * This is complex. We need to reserve room for all our currently used |
| 380 | * metadata buffers (e.g. normal file I/O rewriting file time stamps) and |
| 381 | * all our journaled data buffers for journaled files (e.g. files in the |
| 382 | * meta_fs like rindex, or files for which chattr +j was done.) |
| 383 | * If we don't reserve enough space, gfs2_log_refund and gfs2_log_flush |
| 384 | * will count it as free space (sd_log_blks_free) and corruption will follow. |
| 385 | * |
| 386 | * We can have metadata bufs and jdata bufs in the same journal. So each |
| 387 | * type gets its own log header, for which we need to reserve a block. |
| 388 | * In fact, each type has the potential for needing more than one header |
| 389 | * in cases where we have more buffers than will fit on a journal page. |
| 390 | * Metadata journal entries take up half the space of journaled buffer entries. |
| 391 | * Thus, metadata entries have buf_limit (502) and journaled buffers have |
| 392 | * databuf_limit (251) before they cause a wrap around. |
| 393 | * |
| 394 | * Also, we need to reserve blocks for revoke journal entries and one for an |
| 395 | * overall header for the lot. |
| 396 | * |
| 397 | * Returns: the number of blocks reserved |
| 398 | */ |
| 399 | static unsigned int calc_reserved(struct gfs2_sbd *sdp) |
| 400 | { |
| 401 | unsigned int reserved = 0; |
| 402 | unsigned int mbuf_limit, metabufhdrs_needed; |
| 403 | unsigned int dbuf_limit, databufhdrs_needed; |
| 404 | unsigned int revokes = 0; |
| 405 | |
| 406 | mbuf_limit = buf_limit(sdp); |
| 407 | metabufhdrs_needed = (sdp->sd_log_commited_buf + |
| 408 | (mbuf_limit - 1)) / mbuf_limit; |
| 409 | dbuf_limit = databuf_limit(sdp); |
| 410 | databufhdrs_needed = (sdp->sd_log_commited_databuf + |
| 411 | (dbuf_limit - 1)) / dbuf_limit; |
| 412 | |
| 413 | if (sdp->sd_log_commited_revoke) |
| 414 | revokes = gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, |
| 415 | sizeof(u64)); |
| 416 | |
| 417 | reserved = sdp->sd_log_commited_buf + metabufhdrs_needed + |
| 418 | sdp->sd_log_commited_databuf + databufhdrs_needed + |
| 419 | revokes; |
| 420 | /* One for the overall header */ |
| 421 | if (reserved) |
| 422 | reserved++; |
| 423 | return reserved; |
| 424 | } |
| 425 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 426 | static unsigned int current_tail(struct gfs2_sbd *sdp) |
| 427 | { |
| 428 | struct gfs2_ail *ai; |
| 429 | unsigned int tail; |
| 430 | |
| 431 | gfs2_log_lock(sdp); |
| 432 | |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 433 | if (list_empty(&sdp->sd_ail1_list)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 434 | tail = sdp->sd_log_head; |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 435 | } else { |
| 436 | ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 437 | tail = ai->ai_first; |
| 438 | } |
| 439 | |
| 440 | gfs2_log_unlock(sdp); |
| 441 | |
| 442 | return tail; |
| 443 | } |
| 444 | |
| 445 | static inline void log_incr_head(struct gfs2_sbd *sdp) |
| 446 | { |
| 447 | if (sdp->sd_log_flush_head == sdp->sd_log_tail) |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 448 | gfs2_assert_withdraw(sdp, sdp->sd_log_flush_head == sdp->sd_log_head); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 449 | |
| 450 | if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) { |
| 451 | sdp->sd_log_flush_head = 0; |
| 452 | sdp->sd_log_flush_wrapped = 1; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * gfs2_log_get_buf - Get and initialize a buffer to use for log control data |
| 458 | * @sdp: The GFS2 superblock |
| 459 | * |
| 460 | * Returns: the buffer_head |
| 461 | */ |
| 462 | |
| 463 | struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) |
| 464 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 465 | u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 466 | struct gfs2_log_buf *lb; |
| 467 | struct buffer_head *bh; |
| 468 | |
Steven Whitehouse | 4f3df04 | 2006-01-18 13:20:16 +0000 | [diff] [blame] | 469 | lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 470 | list_add(&lb->lb_list, &sdp->sd_log_flush_list); |
| 471 | |
| 472 | bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno); |
| 473 | lock_buffer(bh); |
| 474 | memset(bh->b_data, 0, bh->b_size); |
| 475 | set_buffer_uptodate(bh); |
| 476 | clear_buffer_dirty(bh); |
| 477 | unlock_buffer(bh); |
| 478 | |
| 479 | log_incr_head(sdp); |
| 480 | |
| 481 | return bh; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log |
| 486 | * @sdp: the filesystem |
| 487 | * @data: the data the buffer_head should point to |
| 488 | * |
| 489 | * Returns: the log buffer descriptor |
| 490 | */ |
| 491 | |
| 492 | struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, |
| 493 | struct buffer_head *real) |
| 494 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 495 | u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 496 | struct gfs2_log_buf *lb; |
| 497 | struct buffer_head *bh; |
| 498 | |
Steven Whitehouse | 4f3df04 | 2006-01-18 13:20:16 +0000 | [diff] [blame] | 499 | lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 500 | list_add(&lb->lb_list, &sdp->sd_log_flush_list); |
| 501 | lb->lb_real = real; |
| 502 | |
| 503 | bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); |
| 504 | atomic_set(&bh->b_count, 1); |
| 505 | bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 506 | set_bh_page(bh, real->b_page, bh_offset(real)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 507 | bh->b_blocknr = blkno; |
| 508 | bh->b_size = sdp->sd_sb.sb_bsize; |
| 509 | bh->b_bdev = sdp->sd_vfs->s_bdev; |
| 510 | |
| 511 | log_incr_head(sdp); |
| 512 | |
| 513 | return bh; |
| 514 | } |
| 515 | |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 516 | static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 517 | { |
| 518 | unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail); |
| 519 | |
| 520 | ail2_empty(sdp, new_tail); |
| 521 | |
| 522 | gfs2_log_lock(sdp); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 523 | sdp->sd_log_blks_free += dist; |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 524 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 525 | gfs2_log_unlock(sdp); |
| 526 | |
| 527 | sdp->sd_log_tail = new_tail; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * log_write_header - Get and initialize a journal header buffer |
| 532 | * @sdp: The GFS2 superblock |
| 533 | * |
| 534 | * Returns: the initialized log buffer descriptor |
| 535 | */ |
| 536 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 537 | static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 538 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 539 | u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 540 | struct buffer_head *bh; |
| 541 | struct gfs2_log_header *lh; |
| 542 | unsigned int tail; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 543 | u32 hash; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 544 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 545 | bh = sb_getblk(sdp->sd_vfs, blkno); |
| 546 | lock_buffer(bh); |
| 547 | memset(bh->b_data, 0, bh->b_size); |
| 548 | set_buffer_uptodate(bh); |
| 549 | clear_buffer_dirty(bh); |
| 550 | unlock_buffer(bh); |
| 551 | |
| 552 | gfs2_ail1_empty(sdp, 0); |
| 553 | tail = current_tail(sdp); |
| 554 | |
| 555 | lh = (struct gfs2_log_header *)bh->b_data; |
| 556 | memset(lh, 0, sizeof(struct gfs2_log_header)); |
| 557 | lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); |
Steven Whitehouse | e3167de | 2006-03-30 15:46:23 -0500 | [diff] [blame] | 558 | lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); |
| 559 | lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); |
Steven Whitehouse | e0f2bf7 | 2006-07-17 09:36:28 -0400 | [diff] [blame] | 560 | lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++); |
| 561 | lh->lh_flags = cpu_to_be32(flags); |
| 562 | lh->lh_tail = cpu_to_be32(tail); |
| 563 | lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 564 | hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header)); |
| 565 | lh->lh_hash = cpu_to_be32(hash); |
| 566 | |
| 567 | set_buffer_dirty(bh); |
| 568 | if (sync_dirty_buffer(bh)) |
| 569 | gfs2_io_error_bh(sdp, bh); |
| 570 | brelse(bh); |
| 571 | |
| 572 | if (sdp->sd_log_tail != tail) |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 573 | log_pull_tail(sdp, tail); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 574 | else |
| 575 | gfs2_assert_withdraw(sdp, !pull); |
| 576 | |
| 577 | sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); |
| 578 | log_incr_head(sdp); |
| 579 | } |
| 580 | |
| 581 | static void log_flush_commit(struct gfs2_sbd *sdp) |
| 582 | { |
| 583 | struct list_head *head = &sdp->sd_log_flush_list; |
| 584 | struct gfs2_log_buf *lb; |
| 585 | struct buffer_head *bh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 586 | |
| 587 | while (!list_empty(head)) { |
| 588 | lb = list_entry(head->next, struct gfs2_log_buf, lb_list); |
| 589 | list_del(&lb->lb_list); |
| 590 | bh = lb->lb_bh; |
| 591 | |
| 592 | wait_on_buffer(bh); |
| 593 | if (!buffer_uptodate(bh)) |
| 594 | gfs2_io_error_bh(sdp, bh); |
| 595 | if (lb->lb_real) { |
| 596 | while (atomic_read(&bh->b_count) != 1) /* Grrrr... */ |
| 597 | schedule(); |
| 598 | free_buffer_head(bh); |
| 599 | } else |
| 600 | brelse(bh); |
| 601 | kfree(lb); |
| 602 | } |
| 603 | |
| 604 | log_write_header(sdp, 0, 0); |
| 605 | } |
| 606 | |
| 607 | /** |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 608 | * gfs2_log_flush - flush incore transaction(s) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 609 | * @sdp: the filesystem |
| 610 | * @gl: The glock structure to flush. If NULL, flush the whole incore log |
| 611 | * |
| 612 | */ |
| 613 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 614 | void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 615 | { |
| 616 | struct gfs2_ail *ai; |
| 617 | |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 618 | down_write(&sdp->sd_log_flush_lock); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 619 | |
| 620 | if (gl) { |
| 621 | gfs2_log_lock(sdp); |
| 622 | if (list_empty(&gl->gl_le.le_list)) { |
| 623 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 624 | up_write(&sdp->sd_log_flush_lock); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 625 | return; |
| 626 | } |
| 627 | gfs2_log_unlock(sdp); |
| 628 | } |
| 629 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 630 | ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); |
| 631 | INIT_LIST_HEAD(&ai->ai_ail1_list); |
| 632 | INIT_LIST_HEAD(&ai->ai_ail2_list); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 633 | |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 634 | gfs2_assert_withdraw(sdp, |
| 635 | sdp->sd_log_num_buf + sdp->sd_log_num_jdata == |
| 636 | sdp->sd_log_commited_buf + |
| 637 | sdp->sd_log_commited_databuf); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 638 | gfs2_assert_withdraw(sdp, |
| 639 | sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke); |
| 640 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 641 | sdp->sd_log_flush_head = sdp->sd_log_head; |
| 642 | sdp->sd_log_flush_wrapped = 0; |
| 643 | ai->ai_first = sdp->sd_log_flush_head; |
| 644 | |
| 645 | lops_before_commit(sdp); |
| 646 | if (!list_empty(&sdp->sd_log_flush_list)) |
| 647 | log_flush_commit(sdp); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 648 | else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ |
| 649 | gfs2_log_lock(sdp); |
| 650 | sdp->sd_log_blks_free--; /* Adjust for unreserved buffer */ |
| 651 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 652 | log_write_header(sdp, 0, PULL); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 653 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 654 | lops_after_commit(sdp, ai); |
Steven Whitehouse | fe1a698 | 2006-10-11 13:34:59 -0400 | [diff] [blame] | 655 | |
| 656 | gfs2_log_lock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 657 | sdp->sd_log_head = sdp->sd_log_flush_head; |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 658 | sdp->sd_log_blks_reserved = 0; |
| 659 | sdp->sd_log_commited_buf = 0; |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 660 | sdp->sd_log_commited_databuf = 0; |
Steven Whitehouse | faa31ce | 2006-09-13 11:13:27 -0400 | [diff] [blame] | 661 | sdp->sd_log_commited_revoke = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 662 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 663 | if (!list_empty(&ai->ai_ail1_list)) { |
| 664 | list_add(&ai->ai_list, &sdp->sd_ail1_list); |
| 665 | ai = NULL; |
| 666 | } |
| 667 | gfs2_log_unlock(sdp); |
| 668 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 669 | sdp->sd_vfs->s_dirt = 0; |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 670 | up_write(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 671 | |
| 672 | kfree(ai); |
| 673 | } |
| 674 | |
| 675 | static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) |
| 676 | { |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 677 | unsigned int reserved; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 678 | unsigned int old; |
| 679 | |
| 680 | gfs2_log_lock(sdp); |
| 681 | |
| 682 | sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm; |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 683 | sdp->sd_log_commited_databuf += tr->tr_num_databuf_new - |
| 684 | tr->tr_num_databuf_rm; |
| 685 | gfs2_assert_withdraw(sdp, (((int)sdp->sd_log_commited_buf) >= 0) || |
| 686 | (((int)sdp->sd_log_commited_databuf) >= 0)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 687 | sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm; |
| 688 | gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 689 | reserved = calc_reserved(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 690 | old = sdp->sd_log_blks_free; |
| 691 | sdp->sd_log_blks_free += tr->tr_reserved - |
| 692 | (reserved - sdp->sd_log_blks_reserved); |
| 693 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 694 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 695 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= |
| 696 | sdp->sd_jdesc->jd_blocks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 697 | |
| 698 | sdp->sd_log_blks_reserved = reserved; |
| 699 | |
| 700 | gfs2_log_unlock(sdp); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * gfs2_log_commit - Commit a transaction to the log |
| 705 | * @sdp: the filesystem |
| 706 | * @tr: the transaction |
| 707 | * |
| 708 | * Returns: errno |
| 709 | */ |
| 710 | |
| 711 | void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) |
| 712 | { |
| 713 | log_refund(sdp, tr); |
| 714 | lops_incore_commit(sdp, tr); |
| 715 | |
| 716 | sdp->sd_vfs->s_dirt = 1; |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 717 | up_read(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 718 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 719 | gfs2_log_lock(sdp); |
Steven Whitehouse | b004157 | 2006-11-23 10:51:34 -0500 | [diff] [blame] | 720 | if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) |
| 721 | wake_up_process(sdp->sd_logd_process); |
| 722 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** |
| 726 | * gfs2_log_shutdown - write a shutdown header into a journal |
| 727 | * @sdp: the filesystem |
| 728 | * |
| 729 | */ |
| 730 | |
| 731 | void gfs2_log_shutdown(struct gfs2_sbd *sdp) |
| 732 | { |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 733 | down_write(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 734 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 735 | gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); |
| 736 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl); |
| 737 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 738 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_jdata); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 739 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); |
| 740 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); |
| 741 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf); |
| 742 | gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); |
| 743 | |
| 744 | sdp->sd_log_flush_head = sdp->sd_log_head; |
| 745 | sdp->sd_log_flush_wrapped = 0; |
| 746 | |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame^] | 747 | log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, |
| 748 | (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 749 | |
Steven Whitehouse | a74604b | 2006-04-21 15:10:46 -0400 | [diff] [blame] | 750 | gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); |
| 751 | gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); |
| 752 | gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 753 | |
| 754 | sdp->sd_log_head = sdp->sd_log_flush_head; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 755 | sdp->sd_log_tail = sdp->sd_log_head; |
| 756 | |
Steven Whitehouse | 484adff | 2006-03-29 09:12:12 -0500 | [diff] [blame] | 757 | up_write(&sdp->sd_log_flush_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Steven Whitehouse | a25311c | 2006-11-23 11:06:35 -0500 | [diff] [blame] | 760 | |
| 761 | /** |
| 762 | * gfs2_meta_syncfs - sync all the buffers in a filesystem |
| 763 | * @sdp: the filesystem |
| 764 | * |
| 765 | */ |
| 766 | |
| 767 | void gfs2_meta_syncfs(struct gfs2_sbd *sdp) |
| 768 | { |
| 769 | gfs2_log_flush(sdp, NULL); |
| 770 | for (;;) { |
| 771 | gfs2_ail1_start(sdp, DIO_ALL); |
| 772 | if (gfs2_ail1_empty(sdp, DIO_ALL)) |
| 773 | break; |
| 774 | msleep(10); |
| 775 | } |
| 776 | } |
| 777 | |