Merge branch 'master' into gfs2
[linux-2.6] / fs / gfs2 / ops_address.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License version 2.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/pagemap.h>
16 #include <linux/pagevec.h>
17 #include <linux/mpage.h>
18 #include <linux/fs.h>
19 #include <linux/gfs2_ondisk.h>
20
21 #include "gfs2.h"
22 #include "lm_interface.h"
23 #include "incore.h"
24 #include "bmap.h"
25 #include "glock.h"
26 #include "inode.h"
27 #include "log.h"
28 #include "meta_io.h"
29 #include "ops_address.h"
30 #include "quota.h"
31 #include "trans.h"
32 #include "rgrp.h"
33 #include "ops_file.h"
34 #include "util.h"
35 #include "glops.h"
36
37
38 static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
39                                    unsigned int from, unsigned int to)
40 {
41         struct buffer_head *head = page_buffers(page);
42         unsigned int bsize = head->b_size;
43         struct buffer_head *bh;
44         unsigned int start, end;
45
46         for (bh = head, start = 0; bh != head || !start;
47              bh = bh->b_this_page, start = end) {
48                 end = start + bsize;
49                 if (end <= from || start >= to)
50                         continue;
51                 gfs2_trans_add_bh(ip->i_gl, bh, 0);
52         }
53 }
54
55 /**
56  * gfs2_get_block - Fills in a buffer head with details about a block
57  * @inode: The inode
58  * @lblock: The block number to look up
59  * @bh_result: The buffer head to return the result in
60  * @create: Non-zero if we may add block to the file
61  *
62  * Returns: errno
63  */
64
65 int gfs2_get_block(struct inode *inode, sector_t lblock,
66                    struct buffer_head *bh_result, int create)
67 {
68         int new = create;
69         u64 dblock;
70         int error;
71         int boundary;
72
73         error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary);
74         if (error)
75                 return error;
76
77         if (!dblock)
78                 return 0;
79
80         map_bh(bh_result, inode->i_sb, dblock);
81         if (new)
82                 set_buffer_new(bh_result);
83         if (boundary)
84                 set_buffer_boundary(bh_result);
85
86         return 0;
87 }
88
89 /**
90  * get_block_noalloc - Fills in a buffer head with details about a block
91  * @inode: The inode
92  * @lblock: The block number to look up
93  * @bh_result: The buffer head to return the result in
94  * @create: Non-zero if we may add block to the file
95  *
96  * Returns: errno
97  */
98
99 static int get_block_noalloc(struct inode *inode, sector_t lblock,
100                              struct buffer_head *bh_result, int create)
101 {
102         int new = 0;
103         u64 dblock;
104         int error;
105         int boundary;
106
107         error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary);
108         if (error)
109                 return error;
110
111         if (dblock)
112                 map_bh(bh_result, inode->i_sb, dblock);
113         else if (gfs2_assert_withdraw(GFS2_SB(inode), !create))
114                 error = -EIO;
115         if (boundary)
116                 set_buffer_boundary(bh_result);
117
118         return error;
119 }
120
121 static int get_block_direct(struct inode *inode, sector_t lblock,
122                             struct buffer_head *bh_result, int create)
123 {
124         int new = 0;
125         u64 dblock;
126         int error, boundary;
127
128         error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary);
129         if (error)
130                 return error;
131
132         if (dblock) {
133                 map_bh(bh_result, inode->i_sb, dblock);
134                 if (boundary)
135                         set_buffer_boundary(bh_result);
136         }
137
138         return 0;
139 }
140 /**
141  * gfs2_writepage - Write complete page
142  * @page: Page to write
143  *
144  * Returns: errno
145  *
146  * Some of this is copied from block_write_full_page() although we still
147  * call it to do most of the work.
148  */
149
150 static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
151 {
152         struct inode *inode = page->mapping->host;
153         struct gfs2_inode *ip = GFS2_I(inode);
154         struct gfs2_sbd *sdp = GFS2_SB(inode);
155         loff_t i_size = i_size_read(inode);
156         pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
157         unsigned offset;
158         int error;
159         int done_trans = 0;
160
161         if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) {
162                 unlock_page(page);
163                 return -EIO;
164         }
165         if (current->journal_info)
166                 goto out_ignore;
167
168         /* Is the page fully outside i_size? (truncate in progress) */
169         offset = i_size & (PAGE_CACHE_SIZE-1);
170         if (page->index > end_index || (page->index == end_index && !offset)) {
171                 page->mapping->a_ops->invalidatepage(page, 0);
172                 unlock_page(page);
173                 return 0; /* don't care */
174         }
175
176         if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) {
177                 error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
178                 if (error)
179                         goto out_ignore;
180                 if (!page_has_buffers(page)) {
181                         create_empty_buffers(page, inode->i_sb->s_blocksize,
182                                              (1 << BH_Dirty)|(1 << BH_Uptodate));
183                 }
184                 gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1);
185                 done_trans = 1;
186         }
187         error = block_write_full_page(page, get_block_noalloc, wbc);
188         if (done_trans)
189                 gfs2_trans_end(sdp);
190         gfs2_meta_cache_flush(ip);
191         return error;
192
193 out_ignore:
194         redirty_page_for_writepage(wbc, page);
195         unlock_page(page);
196         return 0;
197 }
198
199 static int zero_readpage(struct page *page)
200 {
201         void *kaddr;
202
203         kaddr = kmap_atomic(page, KM_USER0);
204         memset(kaddr, 0, PAGE_CACHE_SIZE);
205         kunmap_atomic(page, KM_USER0);
206
207         SetPageUptodate(page);
208
209         return 0;
210 }
211
212 /**
213  * stuffed_readpage - Fill in a Linux page with stuffed file data
214  * @ip: the inode
215  * @page: the page
216  *
217  * Returns: errno
218  */
219
220 static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
221 {
222         struct buffer_head *dibh;
223         void *kaddr;
224         int error;
225
226         /* Only the first page of a stuffed file might contain data */
227         if (unlikely(page->index))
228                 return zero_readpage(page);
229
230         error = gfs2_meta_inode_buffer(ip, &dibh);
231         if (error)
232                 return error;
233
234         kaddr = kmap_atomic(page, KM_USER0);
235         memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode),
236                ip->i_di.di_size);
237         memset(kaddr + ip->i_di.di_size, 0, PAGE_CACHE_SIZE - ip->i_di.di_size);
238         kunmap_atomic(page, KM_USER0);
239
240         brelse(dibh);
241
242         SetPageUptodate(page);
243
244         return 0;
245 }
246
247
248 /**
249  * gfs2_readpage - readpage with locking
250  * @file: The file to read a page for. N.B. This may be NULL if we are
251  * reading an internal file.
252  * @page: The page to read
253  *
254  * Returns: errno
255  */
256
257 static int gfs2_readpage(struct file *file, struct page *page)
258 {
259         struct gfs2_inode *ip = GFS2_I(page->mapping->host);
260         struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
261         struct gfs2_holder gh;
262         int error;
263         int do_unlock = 0;
264
265         if (likely(file != &gfs2_internal_file_sentinel)) {
266                 if (file) {
267                         struct gfs2_file *gf = file->private_data;
268                         if (test_bit(GFF_EXLOCK, &gf->f_flags))
269                                 goto skip_lock;
270                 }
271                 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh);
272                 do_unlock = 1;
273                 error = gfs2_glock_nq_m_atime(1, &gh);
274                 if (unlikely(error))
275                         goto out_unlock;
276         }
277
278 skip_lock:
279         if (gfs2_is_stuffed(ip)) {
280                 error = stuffed_readpage(ip, page);
281                 unlock_page(page);
282         } else
283                 error = mpage_readpage(page, gfs2_get_block);
284
285         if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
286                 error = -EIO;
287
288         if (file != &gfs2_internal_file_sentinel) {
289                 gfs2_glock_dq_m(1, &gh);
290                 gfs2_holder_uninit(&gh);
291         }
292 out:
293         return error;
294 out_unlock:
295         unlock_page(page);
296         if (do_unlock)
297                 gfs2_holder_uninit(&gh);
298         goto out;
299 }
300
301 /**
302  * gfs2_readpages - Read a bunch of pages at once
303  *
304  * Some notes:
305  * 1. This is only for readahead, so we can simply ignore any things
306  *    which are slightly inconvenient (such as locking conflicts between
307  *    the page lock and the glock) and return having done no I/O. Its
308  *    obviously not something we'd want to do on too regular a basis.
309  *    Any I/O we ignore at this time will be done via readpage later.
310  * 2. We have to handle stuffed files here too.
311  * 3. mpage_readpages() does most of the heavy lifting in the common case.
312  * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places.
313  * 5. We use LM_FLAG_TRY_1CB here, effectively we then have lock-ahead as
314  *    well as read-ahead.
315  */
316 static int gfs2_readpages(struct file *file, struct address_space *mapping,
317                           struct list_head *pages, unsigned nr_pages)
318 {
319         struct inode *inode = mapping->host;
320         struct gfs2_inode *ip = GFS2_I(inode);
321         struct gfs2_sbd *sdp = GFS2_SB(inode);
322         struct gfs2_holder gh;
323         unsigned page_idx;
324         int ret;
325         int do_unlock = 0;
326
327         if (likely(file != &gfs2_internal_file_sentinel)) {
328                 if (file) {
329                         struct gfs2_file *gf = file->private_data;
330                         if (test_bit(GFF_EXLOCK, &gf->f_flags))
331                                 goto skip_lock;
332                 }
333                 gfs2_holder_init(ip->i_gl, LM_ST_SHARED,
334                                  LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh);
335                 do_unlock = 1;
336                 ret = gfs2_glock_nq_m_atime(1, &gh);
337                 if (ret == GLR_TRYFAILED) 
338                         goto out_noerror;
339                 if (unlikely(ret))
340                         goto out_unlock;
341         }
342 skip_lock:
343         if (gfs2_is_stuffed(ip)) {
344                 struct pagevec lru_pvec;
345                 pagevec_init(&lru_pvec, 0);
346                 for (page_idx = 0; page_idx < nr_pages; page_idx++) {
347                         struct page *page = list_entry(pages->prev, struct page, lru);
348                         prefetchw(&page->flags);
349                         list_del(&page->lru);
350                         if (!add_to_page_cache(page, mapping,
351                                                page->index, GFP_KERNEL)) {
352                                 ret = stuffed_readpage(ip, page);
353                                 unlock_page(page);
354                                 if (!pagevec_add(&lru_pvec, page))
355                                          __pagevec_lru_add(&lru_pvec);
356                         } else {
357                                 page_cache_release(page);
358                         }
359                 }
360                 pagevec_lru_add(&lru_pvec);
361                 ret = 0;
362         } else {
363                 /* What we really want to do .... */
364                 ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block);
365         }
366
367         if (do_unlock) {
368                 gfs2_glock_dq_m(1, &gh);
369                 gfs2_holder_uninit(&gh);
370         }
371 out:
372         if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
373                 ret = -EIO;
374         return ret;
375 out_noerror:
376         ret = 0;
377 out_unlock:
378         /* unlock all pages, we can't do any I/O right now */
379         for (page_idx = 0; page_idx < nr_pages; page_idx++) {
380                 struct page *page = list_entry(pages->prev, struct page, lru);
381                 list_del(&page->lru);
382                 unlock_page(page);
383                 page_cache_release(page);
384         }
385         if (do_unlock)
386                 gfs2_holder_uninit(&gh);
387         goto out;
388 }
389
390 /**
391  * gfs2_prepare_write - Prepare to write a page to a file
392  * @file: The file to write to
393  * @page: The page which is to be prepared for writing
394  * @from: From (byte range within page)
395  * @to: To (byte range within page)
396  *
397  * Returns: errno
398  */
399
400 static int gfs2_prepare_write(struct file *file, struct page *page,
401                               unsigned from, unsigned to)
402 {
403         struct gfs2_inode *ip = GFS2_I(page->mapping->host);
404         struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
405         unsigned int data_blocks, ind_blocks, rblocks;
406         int alloc_required;
407         int error = 0;
408         loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + from;
409         loff_t end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
410         struct gfs2_alloc *al;
411
412         gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME|GL_AOP, &ip->i_gh);
413         error = gfs2_glock_nq_m_atime(1, &ip->i_gh);
414         if (error)
415                 goto out_uninit;
416
417         gfs2_write_calc_reserv(ip, to - from, &data_blocks, &ind_blocks);
418
419         error = gfs2_write_alloc_required(ip, pos, from - to, &alloc_required);
420         if (error)
421                 goto out_unlock;
422
423
424         if (alloc_required) {
425                 al = gfs2_alloc_get(ip);
426
427                 error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
428                 if (error)
429                         goto out_alloc_put;
430
431                 error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid);
432                 if (error)
433                         goto out_qunlock;
434
435                 al->al_requested = data_blocks + ind_blocks;
436                 error = gfs2_inplace_reserve(ip);
437                 if (error)
438                         goto out_qunlock;
439         }
440
441         rblocks = RES_DINODE + ind_blocks;
442         if (gfs2_is_jdata(ip))
443                 rblocks += data_blocks ? data_blocks : 1;
444         if (ind_blocks || data_blocks)
445                 rblocks += RES_STATFS + RES_QUOTA;
446
447         error = gfs2_trans_begin(sdp, rblocks, 0);
448         if (error)
449                 goto out;
450
451         if (gfs2_is_stuffed(ip)) {
452                 if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) {
453                         error = gfs2_unstuff_dinode(ip, page);
454                         if (error == 0)
455                                 goto prepare_write;
456                 } else if (!PageUptodate(page))
457                         error = stuffed_readpage(ip, page);
458                 goto out;
459         }
460
461 prepare_write:
462         error = block_prepare_write(page, from, to, gfs2_get_block);
463
464 out:
465         if (error) {
466                 gfs2_trans_end(sdp);
467                 if (alloc_required) {
468                         gfs2_inplace_release(ip);
469 out_qunlock:
470                         gfs2_quota_unlock(ip);
471 out_alloc_put:
472                         gfs2_alloc_put(ip);
473                 }
474 out_unlock:
475                 gfs2_glock_dq_m(1, &ip->i_gh);
476 out_uninit:
477                 gfs2_holder_uninit(&ip->i_gh);
478         }
479
480         return error;
481 }
482
483 /**
484  * gfs2_commit_write - Commit write to a file
485  * @file: The file to write to
486  * @page: The page containing the data
487  * @from: From (byte range within page)
488  * @to: To (byte range within page)
489  *
490  * Returns: errno
491  */
492
493 static int gfs2_commit_write(struct file *file, struct page *page,
494                              unsigned from, unsigned to)
495 {
496         struct inode *inode = page->mapping->host;
497         struct gfs2_inode *ip = GFS2_I(inode);
498         struct gfs2_sbd *sdp = GFS2_SB(inode);
499         int error = -EOPNOTSUPP;
500         struct buffer_head *dibh;
501         struct gfs2_alloc *al = &ip->i_alloc;;
502
503         if (gfs2_assert_withdraw(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)))
504                 goto fail_nounlock;
505
506         error = gfs2_meta_inode_buffer(ip, &dibh);
507         if (error)
508                 goto fail_endtrans;
509
510         gfs2_trans_add_bh(ip->i_gl, dibh, 1);
511
512         if (gfs2_is_stuffed(ip)) {
513                 u64 file_size;
514                 void *kaddr;
515
516                 file_size = ((u64)page->index << PAGE_CACHE_SHIFT) + to;
517
518                 kaddr = kmap_atomic(page, KM_USER0);
519                 memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from,
520                        kaddr + from, to - from);
521                 kunmap_atomic(page, KM_USER0);
522
523                 SetPageUptodate(page);
524
525                 if (inode->i_size < file_size)
526                         i_size_write(inode, file_size);
527         } else {
528                 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED ||
529                     gfs2_is_jdata(ip))
530                         gfs2_page_add_databufs(ip, page, from, to);
531                 error = generic_commit_write(file, page, from, to);
532                 if (error)
533                         goto fail;
534         }
535
536         if (ip->i_di.di_size < inode->i_size)
537                 ip->i_di.di_size = inode->i_size;
538
539         gfs2_dinode_out(&ip->i_di, dibh->b_data);
540         brelse(dibh);
541         gfs2_trans_end(sdp);
542         if (al->al_requested) {
543                 gfs2_inplace_release(ip);
544                 gfs2_quota_unlock(ip);
545                 gfs2_alloc_put(ip);
546         }
547         gfs2_glock_dq_m(1, &ip->i_gh);
548         gfs2_holder_uninit(&ip->i_gh);
549         return 0;
550
551 fail:
552         brelse(dibh);
553 fail_endtrans:
554         gfs2_trans_end(sdp);
555         if (al->al_requested) {
556                 gfs2_inplace_release(ip);
557                 gfs2_quota_unlock(ip);
558                 gfs2_alloc_put(ip);
559         }
560         gfs2_glock_dq_m(1, &ip->i_gh);
561         gfs2_holder_uninit(&ip->i_gh);
562 fail_nounlock:
563         ClearPageUptodate(page);
564         return error;
565 }
566
567 /**
568  * gfs2_bmap - Block map function
569  * @mapping: Address space info
570  * @lblock: The block to map
571  *
572  * Returns: The disk address for the block or 0 on hole or error
573  */
574
575 static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
576 {
577         struct gfs2_inode *ip = GFS2_I(mapping->host);
578         struct gfs2_holder i_gh;
579         sector_t dblock = 0;
580         int error;
581
582         error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
583         if (error)
584                 return 0;
585
586         if (!gfs2_is_stuffed(ip))
587                 dblock = generic_block_bmap(mapping, lblock, gfs2_get_block);
588
589         gfs2_glock_dq_uninit(&i_gh);
590
591         return dblock;
592 }
593
594 static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh)
595 {
596         struct gfs2_bufdata *bd;
597
598         gfs2_log_lock(sdp);
599         bd = bh->b_private;
600         if (bd) {
601                 bd->bd_bh = NULL;
602                 bh->b_private = NULL;
603         }
604         gfs2_log_unlock(sdp);
605
606         lock_buffer(bh);
607         clear_buffer_dirty(bh);
608         bh->b_bdev = NULL;
609         clear_buffer_mapped(bh);
610         clear_buffer_req(bh);
611         clear_buffer_new(bh);
612         clear_buffer_delay(bh);
613         unlock_buffer(bh);
614 }
615
616 static void gfs2_invalidatepage(struct page *page, unsigned long offset)
617 {
618         struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
619         struct buffer_head *head, *bh, *next;
620         unsigned int curr_off = 0;
621
622         BUG_ON(!PageLocked(page));
623         if (!page_has_buffers(page))
624                 return;
625
626         bh = head = page_buffers(page);
627         do {
628                 unsigned int next_off = curr_off + bh->b_size;
629                 next = bh->b_this_page;
630
631                 if (offset <= curr_off)
632                         discard_buffer(sdp, bh);
633
634                 curr_off = next_off;
635                 bh = next;
636         } while (bh != head);
637
638         if (!offset)
639                 try_to_release_page(page, 0);
640
641         return;
642 }
643
644 static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
645                               const struct iovec *iov, loff_t offset,
646                               unsigned long nr_segs)
647 {
648         struct file *file = iocb->ki_filp;
649         struct inode *inode = file->f_mapping->host;
650         struct gfs2_inode *ip = GFS2_I(inode);
651         struct gfs2_holder gh;
652         int rv;
653
654         if (rw == READ)
655                 mutex_lock(&inode->i_mutex);
656         /*
657          * Shared lock, even if its a write, since we do no allocation
658          * on this path. All we need change is atime.
659          */
660         gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh);
661         rv = gfs2_glock_nq_m_atime(1, &gh);
662         if (rv)
663                 goto out;
664
665         if (offset > i_size_read(inode))
666                 goto out;
667
668         /*
669          * Should we return an error here? I can't see that O_DIRECT for
670          * a journaled file makes any sense. For now we'll silently fall
671          * back to buffered I/O, likewise we do the same for stuffed
672          * files since they are (a) small and (b) unaligned.
673          */
674         if (gfs2_is_jdata(ip))
675                 goto out;
676
677         if (gfs2_is_stuffed(ip))
678                 goto out;
679
680         rv = blockdev_direct_IO_own_locking(rw, iocb, inode,
681                                             inode->i_sb->s_bdev,
682                                             iov, offset, nr_segs,
683                                             get_block_direct, NULL);
684 out:
685         gfs2_glock_dq_m(1, &gh);
686         gfs2_holder_uninit(&gh);
687         if (rw == READ)
688                 mutex_unlock(&inode->i_mutex);
689
690         return rv;
691 }
692
693 /**
694  * stuck_releasepage - We're stuck in gfs2_releasepage().  Print stuff out.
695  * @bh: the buffer we're stuck on
696  *
697  */
698
699 static void stuck_releasepage(struct buffer_head *bh)
700 {
701         struct inode *inode = bh->b_page->mapping->host;
702         struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
703         struct gfs2_bufdata *bd = bh->b_private;
704         struct gfs2_glock *gl;
705 static unsigned limit = 0;
706
707         if (limit > 3)
708                 return;
709         limit++;
710
711         fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode);
712         fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n",
713                 (unsigned long long)bh->b_blocknr, atomic_read(&bh->b_count));
714         fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh));
715         fs_warn(sdp, "bh->b_private = %s\n", (bd) ? "!NULL" : "NULL");
716
717         if (!bd)
718                 return;
719
720         gl = bd->bd_gl;
721
722         fs_warn(sdp, "gl = (%u, %llu)\n", 
723                 gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number);
724
725         fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n",
726                 (list_empty(&bd->bd_list_tr)) ? "no" : "yes",
727                 (list_empty(&bd->bd_le.le_list)) ? "no" : "yes");
728
729         if (gl->gl_ops == &gfs2_inode_glops) {
730                 struct gfs2_inode *ip = gl->gl_object;
731                 unsigned int x;
732
733                 if (!ip)
734                         return;
735
736                 fs_warn(sdp, "ip = %llu %llu\n",
737                         (unsigned long long)ip->i_num.no_formal_ino,
738                         (unsigned long long)ip->i_num.no_addr);
739
740                 for (x = 0; x < GFS2_MAX_META_HEIGHT; x++)
741                         fs_warn(sdp, "ip->i_cache[%u] = %s\n",
742                                 x, (ip->i_cache[x]) ? "!NULL" : "NULL");
743         }
744 }
745
746 /**
747  * gfs2_releasepage - free the metadata associated with a page
748  * @page: the page that's being released
749  * @gfp_mask: passed from Linux VFS, ignored by us
750  *
751  * Call try_to_free_buffers() if the buffers in this page can be
752  * released.
753  *
754  * Returns: 0
755  */
756
757 int gfs2_releasepage(struct page *page, gfp_t gfp_mask)
758 {
759         struct inode *aspace = page->mapping->host;
760         struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info;
761         struct buffer_head *bh, *head;
762         struct gfs2_bufdata *bd;
763         unsigned long t = jiffies + gfs2_tune_get(sdp, gt_stall_secs) * HZ;
764
765         if (!page_has_buffers(page))
766                 goto out;
767
768         head = bh = page_buffers(page);
769         do {
770                 while (atomic_read(&bh->b_count)) {
771                         if (!atomic_read(&aspace->i_writecount))
772                                 return 0;
773
774                         if (time_after_eq(jiffies, t)) {
775                                 stuck_releasepage(bh);
776                                 /* should we withdraw here? */
777                                 return 0;
778                         }
779
780                         yield();
781                 }
782
783                 gfs2_assert_warn(sdp, !buffer_pinned(bh));
784                 gfs2_assert_warn(sdp, !buffer_dirty(bh));
785
786                 gfs2_log_lock(sdp);
787                 bd = bh->b_private;
788                 if (bd) {
789                         gfs2_assert_warn(sdp, bd->bd_bh == bh);
790                         gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr));
791                         gfs2_assert_warn(sdp, !bd->bd_ail);
792                         bd->bd_bh = NULL;
793                         if (!list_empty(&bd->bd_le.le_list))
794                                 bd = NULL;
795                         bh->b_private = NULL;
796                 }
797                 gfs2_log_unlock(sdp);
798                 if (bd)
799                         kmem_cache_free(gfs2_bufdata_cachep, bd);
800
801                 bh = bh->b_this_page;
802         } while (bh != head);
803
804 out:
805         return try_to_free_buffers(page);
806 }
807
808 const struct address_space_operations gfs2_file_aops = {
809         .writepage = gfs2_writepage,
810         .readpage = gfs2_readpage,
811         .readpages = gfs2_readpages,
812         .sync_page = block_sync_page,
813         .prepare_write = gfs2_prepare_write,
814         .commit_write = gfs2_commit_write,
815         .bmap = gfs2_bmap,
816         .invalidatepage = gfs2_invalidatepage,
817         .releasepage = gfs2_releasepage,
818         .direct_IO = gfs2_direct_IO,
819 };
820