blob: 6c6af9f5e3ab58373eb897cb1adf2093481a1295 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Petersonda6dd402007-12-11 18:49:21 -06003 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
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 Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
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 Whitehouse5c676f62006-02-27 17:23:27 -050015#include <linux/gfs2_ondisk.h>
Steven Whitehouse71b86f52006-03-28 14:14:04 -050016#include <linux/crc32.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020017#include <linux/lm_interface.h>
Steven Whitehousea25311c2006-11-23 11:06:35 -050018#include <linux/delay.h>
Steven Whitehouseec69b182007-11-09 10:01:41 +000019#include <linux/kthread.h>
20#include <linux/freezer.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000021
22#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050023#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024#include "bmap.h"
25#include "glock.h"
26#include "log.h"
27#include "lops.h"
28#include "meta_io.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050029#include "util.h"
Steven Whitehouse71b86f52006-03-28 14:14:04 -050030#include "dir.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000031
32#define PULL 1
33
David Teiglandb3b94fa2006-01-16 16:50:04 +000034/**
35 * gfs2_struct2blk - compute stuff
36 * @sdp: the filesystem
37 * @nstruct: the number of structures
38 * @ssize: the size of the structures
39 *
40 * Compute the number of log descriptor blocks needed to hold a certain number
41 * of structures of a certain size.
42 *
43 * Returns: the number of blocks needed (minimum is always 1)
44 */
45
46unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
47 unsigned int ssize)
48{
49 unsigned int blks;
50 unsigned int first, second;
51
52 blks = 1;
Steven Whitehousefaa31ce2006-09-13 11:13:27 -040053 first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize;
David Teiglandb3b94fa2006-01-16 16:50:04 +000054
55 if (nstruct > first) {
Steven Whitehouse568f4c92006-02-27 12:00:42 -050056 second = (sdp->sd_sb.sb_bsize -
57 sizeof(struct gfs2_meta_header)) / ssize;
Steven Whitehouse5c676f62006-02-27 17:23:27 -050058 blks += DIV_ROUND_UP(nstruct - first, second);
David Teiglandb3b94fa2006-01-16 16:50:04 +000059 }
60
61 return blks;
62}
63
Steven Whitehouseddacfaf2006-10-03 11:10:41 -040064/**
Steven Whitehouse1e1a3d02007-08-27 09:45:26 +010065 * gfs2_remove_from_ail - Remove an entry from the ail lists, updating counters
66 * @mapping: The associated mapping (maybe NULL)
67 * @bd: The gfs2_bufdata to remove
68 *
69 * The log lock _must_ be held when calling this function
70 *
71 */
72
Steven Whitehousef91a0d32007-10-15 16:29:05 +010073void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
Steven Whitehouse1e1a3d02007-08-27 09:45:26 +010074{
75 bd->bd_ail = NULL;
Steven Whitehouse1ad38c42007-09-03 11:01:33 +010076 list_del_init(&bd->bd_ail_st_list);
77 list_del_init(&bd->bd_ail_gl_list);
Steven Whitehouse1e1a3d02007-08-27 09:45:26 +010078 atomic_dec(&bd->bd_gl->gl_ail_count);
Steven Whitehouse1e1a3d02007-08-27 09:45:26 +010079 brelse(bd->bd_bh);
80}
81
82/**
Steven Whitehouseddacfaf2006-10-03 11:10:41 -040083 * gfs2_ail1_start_one - Start I/O on a part of the AIL
84 * @sdp: the filesystem
85 * @tr: the part of the AIL
86 *
87 */
88
89static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
Harvey Harrison2d81afb2008-05-29 18:27:51 -070090__releases(&sdp->sd_log_lock)
91__acquires(&sdp->sd_log_lock)
Steven Whitehouseddacfaf2006-10-03 11:10:41 -040092{
93 struct gfs2_bufdata *bd, *s;
94 struct buffer_head *bh;
95 int retry;
96
Steven Whitehouseddacfaf2006-10-03 11:10:41 -040097 do {
98 retry = 0;
99
100 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
101 bd_ail_st_list) {
102 bh = bd->bd_bh;
103
104 gfs2_assert(sdp, bd->bd_ail == ai);
105
106 if (!buffer_busy(bh)) {
Steven Whitehouse16615be2007-09-17 10:59:52 +0100107 if (!buffer_uptodate(bh))
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400108 gfs2_io_error_bh(sdp, bh);
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400109 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
110 continue;
111 }
112
113 if (!buffer_dirty(bh))
114 continue;
115
116 list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
117
Steven Whitehouse16615be2007-09-17 10:59:52 +0100118 get_bh(bh);
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400119 gfs2_log_unlock(sdp);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100120 lock_buffer(bh);
121 if (test_clear_buffer_dirty(bh)) {
122 bh->b_end_io = end_buffer_write_sync;
123 submit_bh(WRITE, bh);
124 } else {
125 unlock_buffer(bh);
126 brelse(bh);
127 }
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400128 gfs2_log_lock(sdp);
129
130 retry = 1;
131 break;
132 }
133 } while (retry);
134}
135
136/**
137 * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
138 * @sdp: the filesystem
139 * @ai: the AIL entry
140 *
141 */
142
143static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
144{
145 struct gfs2_bufdata *bd, *s;
146 struct buffer_head *bh;
147
148 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
149 bd_ail_st_list) {
150 bh = bd->bd_bh;
151
152 gfs2_assert(sdp, bd->bd_ail == ai);
153
154 if (buffer_busy(bh)) {
155 if (flags & DIO_ALL)
156 continue;
157 else
158 break;
159 }
160
161 if (!buffer_uptodate(bh))
162 gfs2_io_error_bh(sdp, bh);
163
164 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
165 }
166
167 return list_empty(&ai->ai_ail1_list);
168}
169
Steven Whitehousea25311c2006-11-23 11:06:35 -0500170static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000171{
Bob Peterson693ddea2007-07-24 14:07:33 -0500172 struct list_head *head;
Steven Whitehousecd915492006-09-04 12:49:07 -0400173 u64 sync_gen;
Steven Whitehouse74669412006-09-19 11:17:38 -0400174 struct list_head *first;
175 struct gfs2_ail *first_ai, *ai, *tmp;
176 int done = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000177
178 gfs2_log_lock(sdp);
Bob Peterson693ddea2007-07-24 14:07:33 -0500179 head = &sdp->sd_ail1_list;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000180 if (list_empty(head)) {
181 gfs2_log_unlock(sdp);
182 return;
183 }
184 sync_gen = sdp->sd_ail_sync_gen++;
185
186 first = head->prev;
187 first_ai = list_entry(first, struct gfs2_ail, ai_list);
188 first_ai->ai_sync_gen = sync_gen;
Steven Whitehouse74669412006-09-19 11:17:38 -0400189 gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000190
191 if (flags & DIO_ALL)
192 first = NULL;
193
Steven Whitehouse74669412006-09-19 11:17:38 -0400194 while(!done) {
Steven Whitehouse484adff2006-03-29 09:12:12 -0500195 if (first && (head->prev != first ||
196 gfs2_ail1_empty_one(sdp, first_ai, 0)))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 break;
198
Steven Whitehouse74669412006-09-19 11:17:38 -0400199 done = 1;
200 list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000201 if (ai->ai_sync_gen >= sync_gen)
202 continue;
203 ai->ai_sync_gen = sync_gen;
Steven Whitehouse74669412006-09-19 11:17:38 -0400204 gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */
205 done = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000206 break;
207 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000208 }
209
210 gfs2_log_unlock(sdp);
211}
212
Steven Whitehouseec69b182007-11-09 10:01:41 +0000213static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000214{
215 struct gfs2_ail *ai, *s;
216 int ret;
217
218 gfs2_log_lock(sdp);
219
220 list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
221 if (gfs2_ail1_empty_one(sdp, ai, flags))
222 list_move(&ai->ai_list, &sdp->sd_ail2_list);
223 else if (!(flags & DIO_ALL))
224 break;
225 }
226
227 ret = list_empty(&sdp->sd_ail1_list);
228
229 gfs2_log_unlock(sdp);
230
231 return ret;
232}
233
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400234
235/**
236 * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
237 * @sdp: the filesystem
238 * @ai: the AIL entry
239 *
240 */
241
242static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
243{
244 struct list_head *head = &ai->ai_ail2_list;
245 struct gfs2_bufdata *bd;
246
247 while (!list_empty(head)) {
248 bd = list_entry(head->prev, struct gfs2_bufdata,
249 bd_ail_st_list);
250 gfs2_assert(sdp, bd->bd_ail == ai);
Steven Whitehousef91a0d32007-10-15 16:29:05 +0100251 gfs2_remove_from_ail(bd);
Steven Whitehouseddacfaf2006-10-03 11:10:41 -0400252 }
253}
254
David Teiglandb3b94fa2006-01-16 16:50:04 +0000255static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
256{
257 struct gfs2_ail *ai, *safe;
258 unsigned int old_tail = sdp->sd_log_tail;
259 int wrap = (new_tail < old_tail);
260 int a, b, rm;
261
262 gfs2_log_lock(sdp);
263
264 list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
265 a = (old_tail <= ai->ai_first);
266 b = (ai->ai_first < new_tail);
267 rm = (wrap) ? (a || b) : (a && b);
268 if (!rm)
269 continue;
270
271 gfs2_ail2_empty_one(sdp, ai);
272 list_del(&ai->ai_list);
273 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
274 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
275 kfree(ai);
276 }
277
278 gfs2_log_unlock(sdp);
279}
280
281/**
282 * gfs2_log_reserve - Make a log reservation
283 * @sdp: The GFS2 superblock
284 * @blks: The number of blocks to reserve
285 *
Steven Whitehouse89918642007-06-01 15:19:33 +0100286 * Note that we never give out the last few blocks of the journal. Thats
Robert Peterson2332c442007-06-18 14:50:20 -0500287 * due to the fact that there is a small number of header blocks
Steven Whitehouseb0041572006-11-23 10:51:34 -0500288 * associated with each log flush. The exact number can't be known until
289 * flush time, so we ensure that we have just enough free blocks at all
290 * times to avoid running out during a log flush.
291 *
David Teiglandb3b94fa2006-01-16 16:50:04 +0000292 * Returns: errno
293 */
294
295int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
296{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000297 unsigned int try = 0;
Steven Whitehouse89918642007-06-01 15:19:33 +0100298 unsigned reserved_blks = 6 * (4096 / sdp->sd_vfs->s_blocksize);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000299
300 if (gfs2_assert_warn(sdp, blks) ||
301 gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
302 return -EINVAL;
303
Steven Whitehouse71b86f52006-03-28 14:14:04 -0500304 mutex_lock(&sdp->sd_log_reserve_mutex);
Steven Whitehouse484adff2006-03-29 09:12:12 -0500305 gfs2_log_lock(sdp);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000306 while(atomic_read(&sdp->sd_log_blks_free) <= (blks + reserved_blks)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000307 gfs2_log_unlock(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000308 gfs2_ail1_empty(sdp, 0);
Steven Whitehouseb09e5932006-04-07 11:17:32 -0400309 gfs2_log_flush(sdp, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000310
311 if (try++)
312 gfs2_ail1_start(sdp, 0);
Steven Whitehouse484adff2006-03-29 09:12:12 -0500313 gfs2_log_lock(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000314 }
Steven Whitehousefd041f02007-11-08 14:55:03 +0000315 atomic_sub(blks, &sdp->sd_log_blks_free);
Steven Whitehouse484adff2006-03-29 09:12:12 -0500316 gfs2_log_unlock(sdp);
317 mutex_unlock(&sdp->sd_log_reserve_mutex);
318
319 down_read(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000320
321 return 0;
322}
323
324/**
325 * gfs2_log_release - Release a given number of log blocks
326 * @sdp: The GFS2 superblock
327 * @blks: The number of blocks
328 *
329 */
330
331void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
332{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000333
334 gfs2_log_lock(sdp);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000335 atomic_add(blks, &sdp->sd_log_blks_free);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000336 gfs2_assert_withdraw(sdp,
Steven Whitehousefd041f02007-11-08 14:55:03 +0000337 atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000338 gfs2_log_unlock(sdp);
Steven Whitehouseed386502006-04-07 16:28:07 -0400339 up_read(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000340}
341
Steven Whitehousecd915492006-09-04 12:49:07 -0400342static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000343{
Bob Petersonda6dd402007-12-11 18:49:21 -0600344 struct gfs2_journal_extent *je;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000345
Bob Petersonda6dd402007-12-11 18:49:21 -0600346 list_for_each_entry(je, &sdp->sd_jdesc->extent_list, extent_list) {
347 if (lbn >= je->lblock && lbn < je->lblock + je->blocks)
Steven Whitehouseff91cc92007-12-14 14:04:34 +0000348 return je->dblock + lbn - je->lblock;
Bob Petersonda6dd402007-12-11 18:49:21 -0600349 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000350
Bob Petersonda6dd402007-12-11 18:49:21 -0600351 return -1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000352}
353
354/**
355 * log_distance - Compute distance between two journal blocks
356 * @sdp: The GFS2 superblock
357 * @newer: The most recent journal block of the pair
358 * @older: The older journal block of the pair
359 *
360 * Compute the distance (in the journal direction) between two
361 * blocks in the journal
362 *
363 * Returns: the distance in blocks
364 */
365
Steven Whitehousefaa31ce2006-09-13 11:13:27 -0400366static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000367 unsigned int older)
368{
369 int dist;
370
371 dist = newer - older;
372 if (dist < 0)
373 dist += sdp->sd_jdesc->jd_blocks;
374
375 return dist;
376}
377
Robert Peterson2332c442007-06-18 14:50:20 -0500378/**
379 * calc_reserved - Calculate the number of blocks to reserve when
380 * refunding a transaction's unused buffers.
381 * @sdp: The GFS2 superblock
382 *
383 * This is complex. We need to reserve room for all our currently used
384 * metadata buffers (e.g. normal file I/O rewriting file time stamps) and
385 * all our journaled data buffers for journaled files (e.g. files in the
386 * meta_fs like rindex, or files for which chattr +j was done.)
387 * If we don't reserve enough space, gfs2_log_refund and gfs2_log_flush
388 * will count it as free space (sd_log_blks_free) and corruption will follow.
389 *
390 * We can have metadata bufs and jdata bufs in the same journal. So each
391 * type gets its own log header, for which we need to reserve a block.
392 * In fact, each type has the potential for needing more than one header
393 * in cases where we have more buffers than will fit on a journal page.
394 * Metadata journal entries take up half the space of journaled buffer entries.
395 * Thus, metadata entries have buf_limit (502) and journaled buffers have
396 * databuf_limit (251) before they cause a wrap around.
397 *
398 * Also, we need to reserve blocks for revoke journal entries and one for an
399 * overall header for the lot.
400 *
401 * Returns: the number of blocks reserved
402 */
403static unsigned int calc_reserved(struct gfs2_sbd *sdp)
404{
405 unsigned int reserved = 0;
406 unsigned int mbuf_limit, metabufhdrs_needed;
407 unsigned int dbuf_limit, databufhdrs_needed;
408 unsigned int revokes = 0;
409
410 mbuf_limit = buf_limit(sdp);
411 metabufhdrs_needed = (sdp->sd_log_commited_buf +
412 (mbuf_limit - 1)) / mbuf_limit;
413 dbuf_limit = databuf_limit(sdp);
414 databufhdrs_needed = (sdp->sd_log_commited_databuf +
415 (dbuf_limit - 1)) / dbuf_limit;
416
417 if (sdp->sd_log_commited_revoke)
418 revokes = gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
419 sizeof(u64));
420
421 reserved = sdp->sd_log_commited_buf + metabufhdrs_needed +
422 sdp->sd_log_commited_databuf + databufhdrs_needed +
423 revokes;
424 /* One for the overall header */
425 if (reserved)
426 reserved++;
427 return reserved;
428}
429
David Teiglandb3b94fa2006-01-16 16:50:04 +0000430static unsigned int current_tail(struct gfs2_sbd *sdp)
431{
432 struct gfs2_ail *ai;
433 unsigned int tail;
434
435 gfs2_log_lock(sdp);
436
Steven Whitehousefaa31ce2006-09-13 11:13:27 -0400437 if (list_empty(&sdp->sd_ail1_list)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000438 tail = sdp->sd_log_head;
Steven Whitehousefaa31ce2006-09-13 11:13:27 -0400439 } else {
440 ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000441 tail = ai->ai_first;
442 }
443
444 gfs2_log_unlock(sdp);
445
446 return tail;
447}
448
Steven Whitehouse16615be2007-09-17 10:59:52 +0100449void gfs2_log_incr_head(struct gfs2_sbd *sdp)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000450{
451 if (sdp->sd_log_flush_head == sdp->sd_log_tail)
Steven Whitehouse16615be2007-09-17 10:59:52 +0100452 BUG_ON(sdp->sd_log_flush_head != sdp->sd_log_head);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000453
454 if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
455 sdp->sd_log_flush_head = 0;
456 sdp->sd_log_flush_wrapped = 1;
457 }
458}
459
460/**
Steven Whitehouse16615be2007-09-17 10:59:52 +0100461 * gfs2_log_write_endio - End of I/O for a log buffer
462 * @bh: The buffer head
463 * @uptodate: I/O Status
464 *
465 */
466
467static void gfs2_log_write_endio(struct buffer_head *bh, int uptodate)
468{
469 struct gfs2_sbd *sdp = bh->b_private;
470 bh->b_private = NULL;
471
472 end_buffer_write_sync(bh, uptodate);
473 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
474 wake_up(&sdp->sd_log_flush_wait);
475}
476
477/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
479 * @sdp: The GFS2 superblock
480 *
481 * Returns: the buffer_head
482 */
483
484struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
485{
Steven Whitehousecd915492006-09-04 12:49:07 -0400486 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000487 struct buffer_head *bh;
488
Steven Whitehouse16615be2007-09-17 10:59:52 +0100489 bh = sb_getblk(sdp->sd_vfs, blkno);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000490 lock_buffer(bh);
491 memset(bh->b_data, 0, bh->b_size);
492 set_buffer_uptodate(bh);
493 clear_buffer_dirty(bh);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100494 gfs2_log_incr_head(sdp);
495 atomic_inc(&sdp->sd_log_in_flight);
496 bh->b_private = sdp;
497 bh->b_end_io = gfs2_log_write_endio;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000498
499 return bh;
500}
501
502/**
Steven Whitehouse16615be2007-09-17 10:59:52 +0100503 * gfs2_fake_write_endio -
504 * @bh: The buffer head
505 * @uptodate: The I/O Status
506 *
507 */
508
509static void gfs2_fake_write_endio(struct buffer_head *bh, int uptodate)
510{
511 struct buffer_head *real_bh = bh->b_private;
Steven Whitehouse5a60c532007-09-26 09:39:31 +0100512 struct gfs2_bufdata *bd = real_bh->b_private;
513 struct gfs2_sbd *sdp = bd->bd_gl->gl_sbd;
Steven Whitehouse16615be2007-09-17 10:59:52 +0100514
515 end_buffer_write_sync(bh, uptodate);
516 free_buffer_head(bh);
517 unlock_buffer(real_bh);
518 brelse(real_bh);
519 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
520 wake_up(&sdp->sd_log_flush_wait);
521}
522
523/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000524 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
525 * @sdp: the filesystem
526 * @data: the data the buffer_head should point to
527 *
528 * Returns: the log buffer descriptor
529 */
530
531struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
532 struct buffer_head *real)
533{
Steven Whitehousecd915492006-09-04 12:49:07 -0400534 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000535 struct buffer_head *bh;
536
Steven Whitehouse16615be2007-09-17 10:59:52 +0100537 bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000538 atomic_set(&bh->b_count, 1);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100539 bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000540 set_bh_page(bh, real->b_page, bh_offset(real));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000541 bh->b_blocknr = blkno;
542 bh->b_size = sdp->sd_sb.sb_bsize;
543 bh->b_bdev = sdp->sd_vfs->s_bdev;
Steven Whitehouse16615be2007-09-17 10:59:52 +0100544 bh->b_private = real;
545 bh->b_end_io = gfs2_fake_write_endio;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000546
Steven Whitehouse16615be2007-09-17 10:59:52 +0100547 gfs2_log_incr_head(sdp);
548 atomic_inc(&sdp->sd_log_in_flight);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000549
550 return bh;
551}
552
Robert Peterson2332c442007-06-18 14:50:20 -0500553static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000554{
555 unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
556
557 ail2_empty(sdp, new_tail);
558
559 gfs2_log_lock(sdp);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000560 atomic_add(dist, &sdp->sd_log_blks_free);
561 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000562 gfs2_log_unlock(sdp);
563
564 sdp->sd_log_tail = new_tail;
565}
566
567/**
568 * log_write_header - Get and initialize a journal header buffer
569 * @sdp: The GFS2 superblock
570 *
571 * Returns: the initialized log buffer descriptor
572 */
573
Steven Whitehousecd915492006-09-04 12:49:07 -0400574static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000575{
Steven Whitehousecd915492006-09-04 12:49:07 -0400576 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000577 struct buffer_head *bh;
578 struct gfs2_log_header *lh;
579 unsigned int tail;
Steven Whitehousecd915492006-09-04 12:49:07 -0400580 u32 hash;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000581
David Teiglandb3b94fa2006-01-16 16:50:04 +0000582 bh = sb_getblk(sdp->sd_vfs, blkno);
583 lock_buffer(bh);
584 memset(bh->b_data, 0, bh->b_size);
585 set_buffer_uptodate(bh);
586 clear_buffer_dirty(bh);
587 unlock_buffer(bh);
588
589 gfs2_ail1_empty(sdp, 0);
590 tail = current_tail(sdp);
591
592 lh = (struct gfs2_log_header *)bh->b_data;
593 memset(lh, 0, sizeof(struct gfs2_log_header));
594 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
Steven Whitehousee3167de2006-03-30 15:46:23 -0500595 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
596 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
Steven Whitehousee0f2bf72006-07-17 09:36:28 -0400597 lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
598 lh->lh_flags = cpu_to_be32(flags);
599 lh->lh_tail = cpu_to_be32(tail);
600 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000601 hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
602 lh->lh_hash = cpu_to_be32(hash);
603
604 set_buffer_dirty(bh);
605 if (sync_dirty_buffer(bh))
606 gfs2_io_error_bh(sdp, bh);
607 brelse(bh);
608
609 if (sdp->sd_log_tail != tail)
Robert Peterson2332c442007-06-18 14:50:20 -0500610 log_pull_tail(sdp, tail);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000611 else
612 gfs2_assert_withdraw(sdp, !pull);
613
614 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
Steven Whitehouse16615be2007-09-17 10:59:52 +0100615 gfs2_log_incr_head(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000616}
617
618static void log_flush_commit(struct gfs2_sbd *sdp)
619{
Steven Whitehouse16615be2007-09-17 10:59:52 +0100620 DEFINE_WAIT(wait);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000621
Steven Whitehouse16615be2007-09-17 10:59:52 +0100622 if (atomic_read(&sdp->sd_log_in_flight)) {
623 do {
624 prepare_to_wait(&sdp->sd_log_flush_wait, &wait,
625 TASK_UNINTERRUPTIBLE);
626 if (atomic_read(&sdp->sd_log_in_flight))
627 io_schedule();
628 } while(atomic_read(&sdp->sd_log_in_flight));
629 finish_wait(&sdp->sd_log_flush_wait, &wait);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000630 }
631
Steven Whitehouse16615be2007-09-17 10:59:52 +0100632 log_write_header(sdp, 0, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000633}
634
Steven Whitehoused7b616e2007-09-02 10:48:13 +0100635static void gfs2_ordered_write(struct gfs2_sbd *sdp)
636{
637 struct gfs2_bufdata *bd;
638 struct buffer_head *bh;
639 LIST_HEAD(written);
640
641 gfs2_log_lock(sdp);
642 while (!list_empty(&sdp->sd_log_le_ordered)) {
643 bd = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_bufdata, bd_le.le_list);
644 list_move(&bd->bd_le.le_list, &written);
645 bh = bd->bd_bh;
646 if (!buffer_dirty(bh))
647 continue;
648 get_bh(bh);
649 gfs2_log_unlock(sdp);
650 lock_buffer(bh);
Steven Whitehouseb8e7cbb2007-10-17 09:04:24 +0100651 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
Steven Whitehoused7b616e2007-09-02 10:48:13 +0100652 bh->b_end_io = end_buffer_write_sync;
653 submit_bh(WRITE, bh);
654 } else {
655 unlock_buffer(bh);
656 brelse(bh);
657 }
658 gfs2_log_lock(sdp);
659 }
660 list_splice(&written, &sdp->sd_log_le_ordered);
661 gfs2_log_unlock(sdp);
662}
663
664static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
665{
666 struct gfs2_bufdata *bd;
667 struct buffer_head *bh;
668
669 gfs2_log_lock(sdp);
670 while (!list_empty(&sdp->sd_log_le_ordered)) {
671 bd = list_entry(sdp->sd_log_le_ordered.prev, struct gfs2_bufdata, bd_le.le_list);
672 bh = bd->bd_bh;
673 if (buffer_locked(bh)) {
674 get_bh(bh);
675 gfs2_log_unlock(sdp);
676 wait_on_buffer(bh);
677 brelse(bh);
678 gfs2_log_lock(sdp);
679 continue;
680 }
681 list_del_init(&bd->bd_le.le_list);
682 }
683 gfs2_log_unlock(sdp);
684}
685
David Teiglandb3b94fa2006-01-16 16:50:04 +0000686/**
Steven Whitehouseb09e5932006-04-07 11:17:32 -0400687 * gfs2_log_flush - flush incore transaction(s)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000688 * @sdp: the filesystem
689 * @gl: The glock structure to flush. If NULL, flush the whole incore log
690 *
691 */
692
Steven Whitehouse2bcd6102007-11-08 14:25:12 +0000693void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000694{
695 struct gfs2_ail *ai;
696
Steven Whitehouse484adff2006-03-29 09:12:12 -0500697 down_write(&sdp->sd_log_flush_lock);
Steven Whitehousef55ab262006-02-21 12:51:39 +0000698
Steven Whitehouse2bcd6102007-11-08 14:25:12 +0000699 /* Log might have been flushed while we waited for the flush lock */
700 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) {
701 up_write(&sdp->sd_log_flush_lock);
702 return;
Steven Whitehousef55ab262006-02-21 12:51:39 +0000703 }
704
Steven Whitehouseb09e5932006-04-07 11:17:32 -0400705 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
706 INIT_LIST_HEAD(&ai->ai_ail1_list);
707 INIT_LIST_HEAD(&ai->ai_ail2_list);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000708
Steven Whitehouse16615be2007-09-17 10:59:52 +0100709 if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
710 printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
711 sdp->sd_log_commited_buf);
712 gfs2_assert_withdraw(sdp, 0);
713 }
714 if (sdp->sd_log_num_databuf != sdp->sd_log_commited_databuf) {
715 printk(KERN_INFO "GFS2: log databuf %u %u\n",
716 sdp->sd_log_num_databuf, sdp->sd_log_commited_databuf);
717 gfs2_assert_withdraw(sdp, 0);
718 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000719 gfs2_assert_withdraw(sdp,
720 sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
721
David Teiglandb3b94fa2006-01-16 16:50:04 +0000722 sdp->sd_log_flush_head = sdp->sd_log_head;
723 sdp->sd_log_flush_wrapped = 0;
724 ai->ai_first = sdp->sd_log_flush_head;
725
Steven Whitehoused7b616e2007-09-02 10:48:13 +0100726 gfs2_ordered_write(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000727 lops_before_commit(sdp);
Steven Whitehoused7b616e2007-09-02 10:48:13 +0100728 gfs2_ordered_wait(sdp);
729
Steven Whitehouse16615be2007-09-17 10:59:52 +0100730 if (sdp->sd_log_head != sdp->sd_log_flush_head)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000731 log_flush_commit(sdp);
Robert Peterson2332c442007-06-18 14:50:20 -0500732 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
733 gfs2_log_lock(sdp);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000734 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
Robert Peterson2332c442007-06-18 14:50:20 -0500735 gfs2_log_unlock(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000736 log_write_header(sdp, 0, PULL);
Robert Peterson2332c442007-06-18 14:50:20 -0500737 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000738 lops_after_commit(sdp, ai);
Steven Whitehousefe1a6982006-10-11 13:34:59 -0400739
740 gfs2_log_lock(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000741 sdp->sd_log_head = sdp->sd_log_flush_head;
Steven Whitehousefaa31ce2006-09-13 11:13:27 -0400742 sdp->sd_log_blks_reserved = 0;
743 sdp->sd_log_commited_buf = 0;
Robert Peterson2332c442007-06-18 14:50:20 -0500744 sdp->sd_log_commited_databuf = 0;
Steven Whitehousefaa31ce2006-09-13 11:13:27 -0400745 sdp->sd_log_commited_revoke = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000746
David Teiglandb3b94fa2006-01-16 16:50:04 +0000747 if (!list_empty(&ai->ai_ail1_list)) {
748 list_add(&ai->ai_list, &sdp->sd_ail1_list);
749 ai = NULL;
750 }
751 gfs2_log_unlock(sdp);
752
David Teiglandb3b94fa2006-01-16 16:50:04 +0000753 sdp->sd_vfs->s_dirt = 0;
Steven Whitehouse484adff2006-03-29 09:12:12 -0500754 up_write(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000755
756 kfree(ai);
757}
758
759static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
760{
Robert Peterson2332c442007-06-18 14:50:20 -0500761 unsigned int reserved;
Steven Whitehouseac39aad2008-01-10 14:49:43 +0000762 unsigned int unused;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000763
764 gfs2_log_lock(sdp);
765
766 sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
Robert Peterson2332c442007-06-18 14:50:20 -0500767 sdp->sd_log_commited_databuf += tr->tr_num_databuf_new -
768 tr->tr_num_databuf_rm;
769 gfs2_assert_withdraw(sdp, (((int)sdp->sd_log_commited_buf) >= 0) ||
770 (((int)sdp->sd_log_commited_databuf) >= 0));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000771 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
772 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
Robert Peterson2332c442007-06-18 14:50:20 -0500773 reserved = calc_reserved(sdp);
Roel Kluin62be1f72008-04-17 17:25:37 +0200774 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_reserved + tr->tr_reserved >= reserved);
Steven Whitehouseac39aad2008-01-10 14:49:43 +0000775 unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved;
Steven Whitehouseac39aad2008-01-10 14:49:43 +0000776 atomic_add(unused, &sdp->sd_log_blks_free);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000777 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
Robert Peterson2332c442007-06-18 14:50:20 -0500778 sdp->sd_jdesc->jd_blocks);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000779 sdp->sd_log_blks_reserved = reserved;
780
781 gfs2_log_unlock(sdp);
782}
783
Bob Petersond0109bf2008-01-28 11:20:10 -0600784static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
785{
786 struct list_head *head = &tr->tr_list_buf;
787 struct gfs2_bufdata *bd;
788
789 gfs2_log_lock(sdp);
790 while (!list_empty(head)) {
791 bd = list_entry(head->next, struct gfs2_bufdata, bd_list_tr);
792 list_del_init(&bd->bd_list_tr);
793 tr->tr_num_buf--;
794 }
795 gfs2_log_unlock(sdp);
796 gfs2_assert_warn(sdp, !tr->tr_num_buf);
797}
798
David Teiglandb3b94fa2006-01-16 16:50:04 +0000799/**
800 * gfs2_log_commit - Commit a transaction to the log
801 * @sdp: the filesystem
802 * @tr: the transaction
803 *
804 * Returns: errno
805 */
806
807void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
808{
809 log_refund(sdp, tr);
Bob Petersond0109bf2008-01-28 11:20:10 -0600810 buf_lo_incore_commit(sdp, tr);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000811
812 sdp->sd_vfs->s_dirt = 1;
Steven Whitehouse484adff2006-03-29 09:12:12 -0500813 up_read(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000814
David Teiglandb3b94fa2006-01-16 16:50:04 +0000815 gfs2_log_lock(sdp);
Steven Whitehouseb0041572006-11-23 10:51:34 -0500816 if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks))
817 wake_up_process(sdp->sd_logd_process);
818 gfs2_log_unlock(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000819}
820
821/**
822 * gfs2_log_shutdown - write a shutdown header into a journal
823 * @sdp: the filesystem
824 *
825 */
826
827void gfs2_log_shutdown(struct gfs2_sbd *sdp)
828{
Steven Whitehouse484adff2006-03-29 09:12:12 -0500829 down_write(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000830
David Teiglandb3b94fa2006-01-16 16:50:04 +0000831 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000832 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000833 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
834 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
835 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
836 gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
837
838 sdp->sd_log_flush_head = sdp->sd_log_head;
839 sdp->sd_log_flush_wrapped = 0;
840
Robert Peterson2332c442007-06-18 14:50:20 -0500841 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT,
842 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000843
Steven Whitehousefd041f02007-11-08 14:55:03 +0000844 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
Steven Whitehousea74604b2006-04-21 15:10:46 -0400845 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
846 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000847
848 sdp->sd_log_head = sdp->sd_log_flush_head;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000849 sdp->sd_log_tail = sdp->sd_log_head;
850
Steven Whitehouse484adff2006-03-29 09:12:12 -0500851 up_write(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000852}
853
Steven Whitehousea25311c2006-11-23 11:06:35 -0500854
855/**
856 * gfs2_meta_syncfs - sync all the buffers in a filesystem
857 * @sdp: the filesystem
858 *
859 */
860
861void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
862{
863 gfs2_log_flush(sdp, NULL);
864 for (;;) {
865 gfs2_ail1_start(sdp, DIO_ALL);
866 if (gfs2_ail1_empty(sdp, DIO_ALL))
867 break;
868 msleep(10);
869 }
870}
871
Steven Whitehouseec69b182007-11-09 10:01:41 +0000872
873/**
874 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
875 * @sdp: Pointer to GFS2 superblock
876 *
877 * Also, periodically check to make sure that we're using the most recent
878 * journal index.
879 */
880
881int gfs2_logd(void *data)
882{
883 struct gfs2_sbd *sdp = data;
Steven Whitehouseec69b182007-11-09 10:01:41 +0000884 unsigned long t;
885 int need_flush;
886
887 while (!kthread_should_stop()) {
888 /* Advance the log tail */
889
890 t = sdp->sd_log_flush_time +
891 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
892
893 gfs2_ail1_empty(sdp, DIO_ALL);
894 gfs2_log_lock(sdp);
895 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
896 gfs2_log_unlock(sdp);
897 if (need_flush || time_after_eq(jiffies, t)) {
898 gfs2_log_flush(sdp, NULL);
899 sdp->sd_log_flush_time = jiffies;
900 }
901
Steven Whitehouseec69b182007-11-09 10:01:41 +0000902 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
903 if (freezing(current))
904 refrigerator();
905 schedule_timeout_interruptible(t);
906 }
907
908 return 0;
909}
910