Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[safe/jmp/linux-2.6] / fs / ufs / util.c
index f9556bc..85a7fc9 100644 (file)
@@ -8,21 +8,13 @@
  
 #include <linux/string.h>
 #include <linux/slab.h>
-#include <linux/ufs_fs.h>
 #include <linux/buffer_head.h>
 
+#include "ufs_fs.h"
+#include "ufs.h"
 #include "swab.h"
 #include "util.h"
 
-#undef UFS_UTILS_DEBUG
-
-#ifdef UFS_UTILS_DEBUG
-#define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
-#else
-#define UFSD(x)
-#endif
-
-
 struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
        struct super_block *sb, u64 fragment, u64 size)
 {
@@ -121,13 +113,12 @@ void ubh_mark_buffer_uptodate (struct ufs_buffer_head * ubh, int flag)
        }
 }
 
-void ubh_ll_rw_block (int rw, unsigned nr, struct ufs_buffer_head * ubh[])
+void ubh_ll_rw_block(int rw, struct ufs_buffer_head *ubh)
 {
-       unsigned i;
        if (!ubh)
                return;
-       for ( i = 0; i < nr; i++ )
-               ll_rw_block (rw, ubh[i]->count, ubh[i]->bh);
+
+       ll_rw_block(rw, ubh->count, ubh->bh);
 }
 
 void ubh_wait_on_buffer (struct ufs_buffer_head * ubh)
@@ -194,14 +185,13 @@ void _ubh_memcpyubh_(struct ufs_sb_private_info * uspi,
 dev_t
 ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
 {
-       __fs32 fs32;
+       __u32 fs32;
        dev_t dev;
 
        if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
-               fs32 = ufsi->i_u1.i_data[1];
+               fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[1]);
        else
-               fs32 = ufsi->i_u1.i_data[0];
-       fs32 = fs32_to_cpu(sb, fs32);
+               fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[0]);
        switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
        case UFS_ST_SUNx86:
        case UFS_ST_SUN:
@@ -222,7 +212,7 @@ ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
 void
 ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev)
 {
-       __fs32 fs32;
+       __u32 fs32;
 
        switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
        case UFS_ST_SUNx86:
@@ -237,9 +227,61 @@ ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev
                fs32 = old_encode_dev(dev);
                break;
        }
-       fs32 = cpu_to_fs32(sb, fs32);
        if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
-               ufsi->i_u1.i_data[1] = fs32;
+               ufsi->i_u1.i_data[1] = cpu_to_fs32(sb, fs32);
        else
-               ufsi->i_u1.i_data[0] = fs32;
+               ufsi->i_u1.i_data[0] = cpu_to_fs32(sb, fs32);
+}
+
+/**
+ * ufs_get_locked_page() - locate, pin and lock a pagecache page, if not exist
+ * read it from disk.
+ * @mapping: the address_space to search
+ * @index: the page index
+ *
+ * Locates the desired pagecache page, if not exist we'll read it,
+ * locks it, increments its reference
+ * count and returns its address.
+ *
+ */
+
+struct page *ufs_get_locked_page(struct address_space *mapping,
+                                pgoff_t index)
+{
+       struct page *page;
+
+       page = find_lock_page(mapping, index);
+       if (!page) {
+               page = read_mapping_page(mapping, index, NULL);
+
+               if (IS_ERR(page)) {
+                       printk(KERN_ERR "ufs_change_blocknr: "
+                              "read_mapping_page error: ino %lu, index: %lu\n",
+                              mapping->host->i_ino, index);
+                       goto out;
+               }
+
+               lock_page(page);
+
+               if (unlikely(page->mapping == NULL)) {
+                       /* Truncate got there first */
+                       unlock_page(page);
+                       page_cache_release(page);
+                       page = NULL;
+                       goto out;
+               }
+
+               if (!PageUptodate(page) || PageError(page)) {
+                       unlock_page(page);
+                       page_cache_release(page);
+
+                       printk(KERN_ERR "ufs_change_blocknr: "
+                              "can not read page: ino %lu, index: %lu\n",
+                              mapping->host->i_ino, index);
+
+                       page = ERR_PTR(-EIO);
+               }
+       }
+out:
+       return page;
 }