]>
Commit | Line | Data |
---|---|---|
b3b94faa DT |
1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3 | * Copyright (C) 2004-2005 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 v.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> | |
5c676f6d | 15 | #include <linux/gfs2_ondisk.h> |
71b86f56 | 16 | #include <linux/crc32.h> |
b3b94faa DT |
17 | #include <asm/semaphore.h> |
18 | ||
19 | #include "gfs2.h" | |
5c676f6d SW |
20 | #include "lm_interface.h" |
21 | #include "incore.h" | |
b3b94faa DT |
22 | #include "bmap.h" |
23 | #include "glock.h" | |
24 | #include "log.h" | |
25 | #include "lops.h" | |
26 | #include "meta_io.h" | |
5c676f6d | 27 | #include "util.h" |
71b86f56 | 28 | #include "dir.h" |
b3b94faa DT |
29 | |
30 | #define PULL 1 | |
31 | ||
b3b94faa DT |
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; | |
568f4c96 SW |
51 | first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / |
52 | ssize; | |
b3b94faa DT |
53 | |
54 | if (nstruct > first) { | |
568f4c96 SW |
55 | second = (sdp->sd_sb.sb_bsize - |
56 | sizeof(struct gfs2_meta_header)) / ssize; | |
5c676f6d | 57 | blks += DIV_ROUND_UP(nstruct - first, second); |
b3b94faa DT |
58 | } |
59 | ||
60 | return blks; | |
61 | } | |
62 | ||
63 | void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) | |
64 | { | |
65 | struct list_head *head = &sdp->sd_ail1_list; | |
66 | uint64_t sync_gen; | |
67 | struct list_head *first, *tmp; | |
68 | struct gfs2_ail *first_ai, *ai; | |
69 | ||
70 | gfs2_log_lock(sdp); | |
71 | if (list_empty(head)) { | |
72 | gfs2_log_unlock(sdp); | |
73 | return; | |
74 | } | |
75 | sync_gen = sdp->sd_ail_sync_gen++; | |
76 | ||
77 | first = head->prev; | |
78 | first_ai = list_entry(first, struct gfs2_ail, ai_list); | |
79 | first_ai->ai_sync_gen = sync_gen; | |
80 | gfs2_ail1_start_one(sdp, first_ai); | |
81 | ||
82 | if (flags & DIO_ALL) | |
83 | first = NULL; | |
84 | ||
85 | for (;;) { | |
484adff8 SW |
86 | if (first && (head->prev != first || |
87 | gfs2_ail1_empty_one(sdp, first_ai, 0))) | |
b3b94faa DT |
88 | break; |
89 | ||
90 | for (tmp = head->prev; tmp != head; tmp = tmp->prev) { | |
91 | ai = list_entry(tmp, struct gfs2_ail, ai_list); | |
92 | if (ai->ai_sync_gen >= sync_gen) | |
93 | continue; | |
94 | ai->ai_sync_gen = sync_gen; | |
95 | gfs2_ail1_start_one(sdp, ai); | |
96 | break; | |
97 | } | |
98 | ||
99 | if (tmp == head) | |
100 | break; | |
101 | } | |
102 | ||
103 | gfs2_log_unlock(sdp); | |
104 | } | |
105 | ||
106 | int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) | |
107 | { | |
108 | struct gfs2_ail *ai, *s; | |
109 | int ret; | |
110 | ||
111 | gfs2_log_lock(sdp); | |
112 | ||
113 | list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) { | |
114 | if (gfs2_ail1_empty_one(sdp, ai, flags)) | |
115 | list_move(&ai->ai_list, &sdp->sd_ail2_list); | |
116 | else if (!(flags & DIO_ALL)) | |
117 | break; | |
118 | } | |
119 | ||
120 | ret = list_empty(&sdp->sd_ail1_list); | |
121 | ||
122 | gfs2_log_unlock(sdp); | |
123 | ||
124 | return ret; | |
125 | } | |
126 | ||
127 | static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) | |
128 | { | |
129 | struct gfs2_ail *ai, *safe; | |
130 | unsigned int old_tail = sdp->sd_log_tail; | |
131 | int wrap = (new_tail < old_tail); | |
132 | int a, b, rm; | |
133 | ||
134 | gfs2_log_lock(sdp); | |
135 | ||
136 | list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) { | |
137 | a = (old_tail <= ai->ai_first); | |
138 | b = (ai->ai_first < new_tail); | |
139 | rm = (wrap) ? (a || b) : (a && b); | |
140 | if (!rm) | |
141 | continue; | |
142 | ||
143 | gfs2_ail2_empty_one(sdp, ai); | |
144 | list_del(&ai->ai_list); | |
145 | gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list)); | |
146 | gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list)); | |
147 | kfree(ai); | |
148 | } | |
149 | ||
150 | gfs2_log_unlock(sdp); | |
151 | } | |
152 | ||
153 | /** | |
154 | * gfs2_log_reserve - Make a log reservation | |
155 | * @sdp: The GFS2 superblock | |
156 | * @blks: The number of blocks to reserve | |
157 | * | |
158 | * Returns: errno | |
159 | */ | |
160 | ||
161 | int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) | |
162 | { | |
b3b94faa DT |
163 | unsigned int try = 0; |
164 | ||
165 | if (gfs2_assert_warn(sdp, blks) || | |
166 | gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks)) | |
167 | return -EINVAL; | |
168 | ||
71b86f56 | 169 | mutex_lock(&sdp->sd_log_reserve_mutex); |
484adff8 SW |
170 | gfs2_log_lock(sdp); |
171 | while(sdp->sd_log_blks_free <= blks) { | |
b3b94faa | 172 | gfs2_log_unlock(sdp); |
b3b94faa | 173 | gfs2_ail1_empty(sdp, 0); |
b09e593d | 174 | gfs2_log_flush(sdp, NULL); |
b3b94faa DT |
175 | |
176 | if (try++) | |
177 | gfs2_ail1_start(sdp, 0); | |
484adff8 | 178 | gfs2_log_lock(sdp); |
b3b94faa | 179 | } |
484adff8 | 180 | sdp->sd_log_blks_free -= blks; |
b09e593d | 181 | /* printk(KERN_INFO "reserved %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ |
484adff8 SW |
182 | gfs2_log_unlock(sdp); |
183 | mutex_unlock(&sdp->sd_log_reserve_mutex); | |
184 | ||
185 | down_read(&sdp->sd_log_flush_lock); | |
b3b94faa DT |
186 | |
187 | return 0; | |
188 | } | |
189 | ||
190 | /** | |
191 | * gfs2_log_release - Release a given number of log blocks | |
192 | * @sdp: The GFS2 superblock | |
193 | * @blks: The number of blocks | |
194 | * | |
195 | */ | |
196 | ||
197 | void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) | |
198 | { | |
b3b94faa DT |
199 | |
200 | gfs2_log_lock(sdp); | |
201 | sdp->sd_log_blks_free += blks; | |
b09e593d | 202 | /* printk(KERN_INFO "released %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ |
b3b94faa DT |
203 | gfs2_assert_withdraw(sdp, |
204 | sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); | |
205 | gfs2_log_unlock(sdp); | |
ed386507 | 206 | up_read(&sdp->sd_log_flush_lock); |
b3b94faa DT |
207 | } |
208 | ||
209 | static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) | |
210 | { | |
211 | int new = 0; | |
212 | uint64_t dbn; | |
213 | int error; | |
214 | ||
5c676f6d | 215 | error = gfs2_block_map(sdp->sd_jdesc->jd_inode->u.generic_ip, |
568f4c96 | 216 | lbn, &new, &dbn, NULL); |
b3b94faa DT |
217 | gfs2_assert_withdraw(sdp, !error && dbn); |
218 | ||
219 | return dbn; | |
220 | } | |
221 | ||
222 | /** | |
223 | * log_distance - Compute distance between two journal blocks | |
224 | * @sdp: The GFS2 superblock | |
225 | * @newer: The most recent journal block of the pair | |
226 | * @older: The older journal block of the pair | |
227 | * | |
228 | * Compute the distance (in the journal direction) between two | |
229 | * blocks in the journal | |
230 | * | |
231 | * Returns: the distance in blocks | |
232 | */ | |
233 | ||
234 | static inline unsigned int log_distance(struct gfs2_sbd *sdp, | |
235 | unsigned int newer, | |
236 | unsigned int older) | |
237 | { | |
238 | int dist; | |
239 | ||
240 | dist = newer - older; | |
241 | if (dist < 0) | |
242 | dist += sdp->sd_jdesc->jd_blocks; | |
243 | ||
244 | return dist; | |
245 | } | |
246 | ||
247 | static unsigned int current_tail(struct gfs2_sbd *sdp) | |
248 | { | |
249 | struct gfs2_ail *ai; | |
250 | unsigned int tail; | |
251 | ||
252 | gfs2_log_lock(sdp); | |
253 | ||
254 | if (list_empty(&sdp->sd_ail1_list)) | |
255 | tail = sdp->sd_log_head; | |
256 | else { | |
257 | ai = list_entry(sdp->sd_ail1_list.prev, | |
258 | struct gfs2_ail, ai_list); | |
259 | tail = ai->ai_first; | |
260 | } | |
261 | ||
262 | gfs2_log_unlock(sdp); | |
263 | ||
264 | return tail; | |
265 | } | |
266 | ||
267 | static inline void log_incr_head(struct gfs2_sbd *sdp) | |
268 | { | |
269 | if (sdp->sd_log_flush_head == sdp->sd_log_tail) | |
270 | gfs2_assert_withdraw(sdp, | |
271 | sdp->sd_log_flush_head == sdp->sd_log_head); | |
272 | ||
273 | if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) { | |
274 | sdp->sd_log_flush_head = 0; | |
275 | sdp->sd_log_flush_wrapped = 1; | |
276 | } | |
277 | } | |
278 | ||
279 | /** | |
280 | * gfs2_log_get_buf - Get and initialize a buffer to use for log control data | |
281 | * @sdp: The GFS2 superblock | |
282 | * | |
283 | * Returns: the buffer_head | |
284 | */ | |
285 | ||
286 | struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) | |
287 | { | |
288 | uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); | |
289 | struct gfs2_log_buf *lb; | |
290 | struct buffer_head *bh; | |
291 | ||
4f3df041 | 292 | lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); |
b3b94faa DT |
293 | list_add(&lb->lb_list, &sdp->sd_log_flush_list); |
294 | ||
295 | bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno); | |
296 | lock_buffer(bh); | |
297 | memset(bh->b_data, 0, bh->b_size); | |
298 | set_buffer_uptodate(bh); | |
299 | clear_buffer_dirty(bh); | |
300 | unlock_buffer(bh); | |
301 | ||
302 | log_incr_head(sdp); | |
303 | ||
304 | return bh; | |
305 | } | |
306 | ||
307 | /** | |
308 | * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log | |
309 | * @sdp: the filesystem | |
310 | * @data: the data the buffer_head should point to | |
311 | * | |
312 | * Returns: the log buffer descriptor | |
313 | */ | |
314 | ||
315 | struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, | |
316 | struct buffer_head *real) | |
317 | { | |
318 | uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); | |
319 | struct gfs2_log_buf *lb; | |
320 | struct buffer_head *bh; | |
321 | ||
4f3df041 | 322 | lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); |
b3b94faa DT |
323 | list_add(&lb->lb_list, &sdp->sd_log_flush_list); |
324 | lb->lb_real = real; | |
325 | ||
326 | bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); | |
327 | atomic_set(&bh->b_count, 1); | |
328 | bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate); | |
18ec7d5c | 329 | set_bh_page(bh, real->b_page, bh_offset(real)); |
b3b94faa DT |
330 | bh->b_blocknr = blkno; |
331 | bh->b_size = sdp->sd_sb.sb_bsize; | |
332 | bh->b_bdev = sdp->sd_vfs->s_bdev; | |
333 | ||
334 | log_incr_head(sdp); | |
335 | ||
336 | return bh; | |
337 | } | |
338 | ||
339 | static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) | |
340 | { | |
341 | unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail); | |
342 | ||
343 | ail2_empty(sdp, new_tail); | |
344 | ||
345 | gfs2_log_lock(sdp); | |
346 | sdp->sd_log_blks_free += dist - ((pull) ? 1 : 0); | |
b09e593d | 347 | /* printk(KERN_INFO "pull tail refunding %u blocks (%u left) pull=%d\n", dist - ((pull) ? 1 : 0), sdp->sd_log_blks_free, pull); */ |
b3b94faa DT |
348 | gfs2_assert_withdraw(sdp, |
349 | sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); | |
350 | gfs2_log_unlock(sdp); | |
351 | ||
352 | sdp->sd_log_tail = new_tail; | |
353 | } | |
354 | ||
355 | /** | |
356 | * log_write_header - Get and initialize a journal header buffer | |
357 | * @sdp: The GFS2 superblock | |
358 | * | |
359 | * Returns: the initialized log buffer descriptor | |
360 | */ | |
361 | ||
362 | static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) | |
363 | { | |
364 | uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); | |
365 | struct buffer_head *bh; | |
366 | struct gfs2_log_header *lh; | |
367 | unsigned int tail; | |
368 | uint32_t hash; | |
369 | ||
b09e593d SW |
370 | /* printk(KERN_INFO "log write header start (flags=%08x, pull=%d)\n", flags, pull); */ |
371 | ||
b3b94faa DT |
372 | bh = sb_getblk(sdp->sd_vfs, blkno); |
373 | lock_buffer(bh); | |
374 | memset(bh->b_data, 0, bh->b_size); | |
375 | set_buffer_uptodate(bh); | |
376 | clear_buffer_dirty(bh); | |
377 | unlock_buffer(bh); | |
378 | ||
379 | gfs2_ail1_empty(sdp, 0); | |
380 | tail = current_tail(sdp); | |
381 | ||
382 | lh = (struct gfs2_log_header *)bh->b_data; | |
383 | memset(lh, 0, sizeof(struct gfs2_log_header)); | |
384 | lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); | |
e3167ded SW |
385 | lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); |
386 | lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); | |
b3b94faa DT |
387 | lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++); |
388 | lh->lh_flags = be32_to_cpu(flags); | |
389 | lh->lh_tail = be32_to_cpu(tail); | |
390 | lh->lh_blkno = be32_to_cpu(sdp->sd_log_flush_head); | |
391 | hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header)); | |
392 | lh->lh_hash = cpu_to_be32(hash); | |
393 | ||
394 | set_buffer_dirty(bh); | |
395 | if (sync_dirty_buffer(bh)) | |
396 | gfs2_io_error_bh(sdp, bh); | |
397 | brelse(bh); | |
398 | ||
399 | if (sdp->sd_log_tail != tail) | |
400 | log_pull_tail(sdp, tail, pull); | |
401 | else | |
402 | gfs2_assert_withdraw(sdp, !pull); | |
403 | ||
404 | sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); | |
405 | log_incr_head(sdp); | |
b09e593d SW |
406 | |
407 | /* printk(KERN_INFO "log write header out\n"); */ | |
b3b94faa DT |
408 | } |
409 | ||
410 | static void log_flush_commit(struct gfs2_sbd *sdp) | |
411 | { | |
412 | struct list_head *head = &sdp->sd_log_flush_list; | |
413 | struct gfs2_log_buf *lb; | |
414 | struct buffer_head *bh; | |
f4154ea0 | 415 | #if 0 |
b3b94faa DT |
416 | unsigned int d; |
417 | ||
418 | d = log_distance(sdp, sdp->sd_log_flush_head, sdp->sd_log_head); | |
419 | ||
420 | gfs2_assert_withdraw(sdp, d + 1 == sdp->sd_log_blks_reserved); | |
f4154ea0 | 421 | #endif |
b3b94faa DT |
422 | |
423 | while (!list_empty(head)) { | |
424 | lb = list_entry(head->next, struct gfs2_log_buf, lb_list); | |
425 | list_del(&lb->lb_list); | |
426 | bh = lb->lb_bh; | |
427 | ||
428 | wait_on_buffer(bh); | |
429 | if (!buffer_uptodate(bh)) | |
430 | gfs2_io_error_bh(sdp, bh); | |
431 | if (lb->lb_real) { | |
432 | while (atomic_read(&bh->b_count) != 1) /* Grrrr... */ | |
433 | schedule(); | |
434 | free_buffer_head(bh); | |
435 | } else | |
436 | brelse(bh); | |
437 | kfree(lb); | |
438 | } | |
439 | ||
440 | log_write_header(sdp, 0, 0); | |
441 | } | |
442 | ||
443 | /** | |
b09e593d | 444 | * gfs2_log_flush - flush incore transaction(s) |
b3b94faa DT |
445 | * @sdp: the filesystem |
446 | * @gl: The glock structure to flush. If NULL, flush the whole incore log | |
447 | * | |
448 | */ | |
449 | ||
b09e593d | 450 | void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) |
b3b94faa DT |
451 | { |
452 | struct gfs2_ail *ai; | |
453 | ||
484adff8 | 454 | down_write(&sdp->sd_log_flush_lock); |
f55ab26a SW |
455 | |
456 | if (gl) { | |
457 | gfs2_log_lock(sdp); | |
458 | if (list_empty(&gl->gl_le.le_list)) { | |
459 | gfs2_log_unlock(sdp); | |
484adff8 | 460 | up_write(&sdp->sd_log_flush_lock); |
f55ab26a SW |
461 | return; |
462 | } | |
463 | gfs2_log_unlock(sdp); | |
464 | } | |
465 | ||
b09e593d SW |
466 | ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); |
467 | INIT_LIST_HEAD(&ai->ai_ail1_list); | |
468 | INIT_LIST_HEAD(&ai->ai_ail2_list); | |
b3b94faa DT |
469 | |
470 | gfs2_assert_withdraw(sdp, | |
471 | sdp->sd_log_num_buf == sdp->sd_log_commited_buf); | |
472 | gfs2_assert_withdraw(sdp, | |
473 | sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke); | |
474 | ||
b3b94faa DT |
475 | sdp->sd_log_flush_head = sdp->sd_log_head; |
476 | sdp->sd_log_flush_wrapped = 0; | |
477 | ai->ai_first = sdp->sd_log_flush_head; | |
478 | ||
479 | lops_before_commit(sdp); | |
480 | if (!list_empty(&sdp->sd_log_flush_list)) | |
481 | log_flush_commit(sdp); | |
482 | else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle) | |
483 | log_write_header(sdp, 0, PULL); | |
484 | lops_after_commit(sdp, ai); | |
b3b94faa | 485 | sdp->sd_log_head = sdp->sd_log_flush_head; |
b09e593d SW |
486 | |
487 | /* printk(KERN_INFO "sd_log_num_hdrs %u\n", sdp->sd_log_num_hdrs); */ | |
f4154ea0 | 488 | sdp->sd_log_blks_free -= sdp->sd_log_num_hdrs; |
b3b94faa DT |
489 | |
490 | sdp->sd_log_blks_reserved = | |
491 | sdp->sd_log_commited_buf = | |
b09e593d | 492 | sdp->sd_log_num_hdrs = |
b3b94faa DT |
493 | sdp->sd_log_commited_revoke = 0; |
494 | ||
495 | gfs2_log_lock(sdp); | |
496 | if (!list_empty(&ai->ai_ail1_list)) { | |
497 | list_add(&ai->ai_list, &sdp->sd_ail1_list); | |
498 | ai = NULL; | |
499 | } | |
500 | gfs2_log_unlock(sdp); | |
501 | ||
b3b94faa | 502 | sdp->sd_vfs->s_dirt = 0; |
484adff8 | 503 | up_write(&sdp->sd_log_flush_lock); |
b3b94faa DT |
504 | |
505 | kfree(ai); | |
506 | } | |
507 | ||
508 | static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) | |
509 | { | |
510 | unsigned int reserved = 1; | |
511 | unsigned int old; | |
512 | ||
513 | gfs2_log_lock(sdp); | |
514 | ||
515 | sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm; | |
516 | gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_buf) >= 0); | |
517 | sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm; | |
518 | gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); | |
519 | ||
520 | if (sdp->sd_log_commited_buf) | |
f4154ea0 | 521 | reserved += sdp->sd_log_commited_buf; |
b3b94faa DT |
522 | if (sdp->sd_log_commited_revoke) |
523 | reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, | |
524 | sizeof(uint64_t)); | |
525 | ||
526 | old = sdp->sd_log_blks_free; | |
527 | sdp->sd_log_blks_free += tr->tr_reserved - | |
528 | (reserved - sdp->sd_log_blks_reserved); | |
529 | ||
b09e593d | 530 | gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old); |
b3b94faa | 531 | gfs2_assert_withdraw(sdp, |
f4154ea0 SW |
532 | sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks + |
533 | sdp->sd_log_num_hdrs); | |
b3b94faa DT |
534 | |
535 | sdp->sd_log_blks_reserved = reserved; | |
536 | ||
537 | gfs2_log_unlock(sdp); | |
538 | } | |
539 | ||
540 | /** | |
541 | * gfs2_log_commit - Commit a transaction to the log | |
542 | * @sdp: the filesystem | |
543 | * @tr: the transaction | |
544 | * | |
545 | * Returns: errno | |
546 | */ | |
547 | ||
548 | void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) | |
549 | { | |
550 | log_refund(sdp, tr); | |
551 | lops_incore_commit(sdp, tr); | |
552 | ||
553 | sdp->sd_vfs->s_dirt = 1; | |
484adff8 | 554 | up_read(&sdp->sd_log_flush_lock); |
b3b94faa | 555 | |
b3b94faa DT |
556 | gfs2_log_lock(sdp); |
557 | if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { | |
558 | gfs2_log_unlock(sdp); | |
b09e593d | 559 | gfs2_log_flush(sdp, NULL); |
b3b94faa DT |
560 | } else |
561 | gfs2_log_unlock(sdp); | |
562 | } | |
563 | ||
564 | /** | |
565 | * gfs2_log_shutdown - write a shutdown header into a journal | |
566 | * @sdp: the filesystem | |
567 | * | |
568 | */ | |
569 | ||
570 | void gfs2_log_shutdown(struct gfs2_sbd *sdp) | |
571 | { | |
484adff8 | 572 | down_write(&sdp->sd_log_flush_lock); |
b3b94faa | 573 | |
b3b94faa DT |
574 | gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); |
575 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl); | |
576 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); | |
18ec7d5c | 577 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_jdata); |
b3b94faa DT |
578 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); |
579 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); | |
580 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf); | |
190562bd | 581 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_hdrs); |
b3b94faa DT |
582 | gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); |
583 | ||
584 | sdp->sd_log_flush_head = sdp->sd_log_head; | |
585 | sdp->sd_log_flush_wrapped = 0; | |
586 | ||
587 | log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0); | |
588 | ||
f4154ea0 | 589 | /* printk(KERN_INFO "sd_log_blks_free %u, sd_jdesc->jd_blocks %u\n", sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); */ |
a74604be SW |
590 | gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); |
591 | gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); | |
592 | gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); | |
b3b94faa DT |
593 | |
594 | sdp->sd_log_head = sdp->sd_log_flush_head; | |
b3b94faa DT |
595 | sdp->sd_log_tail = sdp->sd_log_head; |
596 | ||
484adff8 | 597 | up_write(&sdp->sd_log_flush_lock); |
b3b94faa DT |
598 | } |
599 |