]> err.no Git - linux-2.6/blobdiff - fs/gfs2/ops_address.c
kconfig: use C89 random functions in conf.c
[linux-2.6] / fs / gfs2 / ops_address.c
index 48913e569907d32a88d50ec0c6a0ae379f2958b4..38dbe99a30ede1ac388596278ef02ca9e9590bae 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/swap.h>
 #include <linux/gfs2_ondisk.h>
 #include <linux/lm_interface.h>
-#include <linux/swap.h>
+#include <linux/backing-dev.h>
 #include <linux/pagevec.h>
 
 #include "gfs2.h"
@@ -58,22 +58,6 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
        }
 }
 
-/**
- * gfs2_get_block - Fills in a buffer head with details about a block
- * @inode: The inode
- * @lblock: The block number to look up
- * @bh_result: The buffer head to return the result in
- * @create: Non-zero if we may add block to the file
- *
- * Returns: errno
- */
-
-int gfs2_get_block(struct inode *inode, sector_t lblock,
-                  struct buffer_head *bh_result, int create)
-{
-       return gfs2_block_map(inode, lblock, create, bh_result);
-}
-
 /**
  * gfs2_get_block_noalloc - Fills in a buffer head with details about a block
  * @inode: The inode
@@ -89,7 +73,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
 {
        int error;
 
-       error = gfs2_block_map(inode, lblock, 0, bh_result);
+       error = gfs2_block_map(inode, lblock, bh_result, 0);
        if (error)
                return error;
        if (!buffer_mapped(bh_result))
@@ -100,7 +84,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
 static int gfs2_get_block_direct(struct inode *inode, sector_t lblock,
                                 struct buffer_head *bh_result, int create)
 {
-       return gfs2_block_map(inode, lblock, 0, bh_result);
+       return gfs2_block_map(inode, lblock, bh_result, 0);
 }
 
 /**
@@ -504,7 +488,7 @@ static int __gfs2_readpage(void *file, struct page *page)
                error = stuffed_readpage(ip, page);
                unlock_page(page);
        } else {
-               error = mpage_readpage(page, gfs2_get_block);
+               error = mpage_readpage(page, gfs2_block_map);
        }
 
        if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
@@ -598,7 +582,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
  *    Any I/O we ignore at this time will be done via readpage later.
  * 2. We don't handle stuffed files here we let readpage do the honours.
  * 3. mpage_readpages() does most of the heavy lifting in the common case.
- * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places.
+ * 4. gfs2_block_map() is relied upon to set BH_Boundary in the right places.
  */
 
 static int gfs2_readpages(struct file *file, struct address_space *mapping,
@@ -615,7 +599,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
        if (unlikely(ret))
                goto out_uninit;
        if (!gfs2_is_stuffed(ip))
-               ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block);
+               ret = mpage_readpages(mapping, pages, nr_pages, gfs2_block_map);
        gfs2_glock_dq(&gh);
 out_uninit:
        gfs2_holder_uninit(&gh);
@@ -657,20 +641,11 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
        if (unlikely(error))
                goto out_uninit;
 
-       error = -ENOMEM;
-       page = __grab_cache_page(mapping, index);
-       *pagep = page;
-       if (!page)
-               goto out_unlock;
-
        gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
-
        error = gfs2_write_alloc_required(ip, pos, len, &alloc_required);
        if (error)
-               goto out_putpage;
-
+               goto out_unlock;
 
-       ip->i_alloc.al_requested = 0;
        if (alloc_required) {
                al = gfs2_alloc_get(ip);
 
@@ -699,40 +674,47 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
        if (error)
                goto out_trans_fail;
 
+       error = -ENOMEM;
+       page = __grab_cache_page(mapping, index);
+       *pagep = page;
+       if (unlikely(!page))
+               goto out_endtrans;
+
        if (gfs2_is_stuffed(ip)) {
+               error = 0;
                if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) {
                        error = gfs2_unstuff_dinode(ip, page);
                        if (error == 0)
                                goto prepare_write;
-               } else if (!PageUptodate(page))
+               } else if (!PageUptodate(page)) {
                        error = stuffed_readpage(ip, page);
+               }
                goto out;
        }
 
 prepare_write:
-       error = block_prepare_write(page, from, to, gfs2_get_block);
-
+       error = block_prepare_write(page, from, to, gfs2_block_map);
 out:
-       if (error) {
-               gfs2_trans_end(sdp);
+       if (error == 0)
+               return 0;
+
+       page_cache_release(page);
+       if (pos + len > ip->i_inode.i_size)
+               vmtruncate(&ip->i_inode, ip->i_inode.i_size);
+out_endtrans:
+       gfs2_trans_end(sdp);
 out_trans_fail:
-               if (alloc_required) {
-                       gfs2_inplace_release(ip);
+       if (alloc_required) {
+               gfs2_inplace_release(ip);
 out_qunlock:
-                       gfs2_quota_unlock(ip);
+               gfs2_quota_unlock(ip);
 out_alloc_put:
-                       gfs2_alloc_put(ip);
-               }
-out_putpage:
-               page_cache_release(page);
-               if (pos + len > ip->i_inode.i_size)
-                       vmtruncate(&ip->i_inode, ip->i_inode.i_size);
+               gfs2_alloc_put(ip);
+       }
 out_unlock:
-               gfs2_glock_dq_m(1, &ip->i_gh);
+       gfs2_glock_dq(&ip->i_gh);
 out_uninit:
-               gfs2_holder_uninit(&ip->i_gh);
-       }
-
+       gfs2_holder_uninit(&ip->i_gh);
        return error;
 }
 
@@ -840,7 +822,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
        struct gfs2_inode *ip = GFS2_I(inode);
        struct gfs2_sbd *sdp = GFS2_SB(inode);
        struct buffer_head *dibh;
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_dinode *di;
        unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
        unsigned int to = from + len;
@@ -865,14 +847,11 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
 
        ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
 
-       if (likely(ret >= 0)) {
-               copied = ret;
-               if  ((pos + copied) > inode->i_size) {
-                       di = (struct gfs2_dinode *)dibh->b_data;
-                       ip->i_di.di_size = inode->i_size;
-                       di->di_size = cpu_to_be64(inode->i_size);
-                       mark_inode_dirty(inode);
-               }
+       if (likely(ret >= 0) && (inode->i_size > ip->i_di.di_size)) {
+               di = (struct gfs2_dinode *)dibh->b_data;
+               ip->i_di.di_size = inode->i_size;
+               di->di_size = cpu_to_be64(inode->i_size);
+               mark_inode_dirty(inode);
        }
 
        if (inode == sdp->sd_rindex)
@@ -881,7 +860,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
        brelse(dibh);
        gfs2_trans_end(sdp);
 failed:
-       if (al->al_requested) {
+       if (al) {
                gfs2_inplace_release(ip);
                gfs2_quota_unlock(ip);
                gfs2_alloc_put(ip);
@@ -924,7 +903,7 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
                return 0;
 
        if (!gfs2_is_stuffed(ip))
-               dblock = generic_block_bmap(mapping, lblock, gfs2_get_block);
+               dblock = generic_block_bmap(mapping, lblock, gfs2_block_map);
 
        gfs2_glock_dq_uninit(&i_gh);
 
@@ -1115,6 +1094,7 @@ static const struct address_space_operations gfs2_writeback_aops = {
        .invalidatepage = gfs2_invalidatepage,
        .releasepage = gfs2_releasepage,
        .direct_IO = gfs2_direct_IO,
+       .migratepage = buffer_migrate_page,
 };
 
 static const struct address_space_operations gfs2_ordered_aops = {
@@ -1129,6 +1109,7 @@ static const struct address_space_operations gfs2_ordered_aops = {
        .invalidatepage = gfs2_invalidatepage,
        .releasepage = gfs2_releasepage,
        .direct_IO = gfs2_direct_IO,
+       .migratepage = buffer_migrate_page,
 };
 
 static const struct address_space_operations gfs2_jdata_aops = {