Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/ocfs2
[safe/jmp/linux-2.6] / fs / exofs / inode.c
index 0163546..76d2a79 100644 (file)
@@ -31,6 +31,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <linux/slab.h>
 #include <linux/writeback.h>
 #include <linux/buffer_head.h>
 #include <scsi/scsi_device.h>
 
 enum { BIO_MAX_PAGES_KMALLOC =
                (PAGE_SIZE - sizeof(struct bio)) / sizeof(struct bio_vec),
+       MAX_PAGES_KMALLOC =
+               PAGE_SIZE / sizeof(struct page *),
 };
 
 struct page_collect {
        struct exofs_sb_info *sbi;
-       struct request_queue *req_q;
        struct inode *inode;
        unsigned expected_pages;
        struct exofs_io_state *ios;
 
-       struct bio *bio;
+       struct page **pages;
+       unsigned alloc_pages;
        unsigned nr_pages;
        unsigned long length;
        loff_t pg_first; /* keep 64bit also in 32-arches */
@@ -62,15 +65,12 @@ static void _pcol_init(struct page_collect *pcol, unsigned expected_pages,
        struct exofs_sb_info *sbi = inode->i_sb->s_fs_info;
 
        pcol->sbi = sbi;
-       /* Create master bios on first Q, later on cloning, each clone will be
-        * allocated on it's destination Q
-        */
-       pcol->req_q = osd_request_queue(sbi->layout.s_ods[0]);
        pcol->inode = inode;
        pcol->expected_pages = expected_pages;
 
        pcol->ios = NULL;
-       pcol->bio = NULL;
+       pcol->pages = NULL;
+       pcol->alloc_pages = 0;
        pcol->nr_pages = 0;
        pcol->length = 0;
        pcol->pg_first = -1;
@@ -80,7 +80,8 @@ static void _pcol_reset(struct page_collect *pcol)
 {
        pcol->expected_pages -= min(pcol->nr_pages, pcol->expected_pages);
 
-       pcol->bio = NULL;
+       pcol->pages = NULL;
+       pcol->alloc_pages = 0;
        pcol->nr_pages = 0;
        pcol->length = 0;
        pcol->pg_first = -1;
@@ -90,13 +91,13 @@ static void _pcol_reset(struct page_collect *pcol)
         * it might not end here. don't be left with nothing
         */
        if (!pcol->expected_pages)
-               pcol->expected_pages = BIO_MAX_PAGES_KMALLOC;
+               pcol->expected_pages = MAX_PAGES_KMALLOC;
 }
 
 static int pcol_try_alloc(struct page_collect *pcol)
 {
-       int pages = min_t(unsigned, pcol->expected_pages,
-                         BIO_MAX_PAGES_KMALLOC);
+       unsigned pages = min_t(unsigned, pcol->expected_pages,
+                         MAX_PAGES_KMALLOC);
 
        if (!pcol->ios) { /* First time allocate io_state */
                int ret = exofs_get_io_state(&pcol->sbi->layout, &pcol->ios);
@@ -105,23 +106,28 @@ static int pcol_try_alloc(struct page_collect *pcol)
                        return ret;
        }
 
+       /* TODO: easily support bio chaining */
+       pages =  min_t(unsigned, pages,
+                      pcol->sbi->layout.group_width * BIO_MAX_PAGES_KMALLOC);
+
        for (; pages; pages >>= 1) {
-               pcol->bio = bio_kmalloc(GFP_KERNEL, pages);
-               if (likely(pcol->bio))
+               pcol->pages = kmalloc(pages * sizeof(struct page *),
+                                     GFP_KERNEL);
+               if (likely(pcol->pages)) {
+                       pcol->alloc_pages = pages;
                        return 0;
+               }
        }
 
-       EXOFS_ERR("Failed to bio_kmalloc expected_pages=%u\n",
+       EXOFS_ERR("Failed to kmalloc expected_pages=%u\n",
                  pcol->expected_pages);
        return -ENOMEM;
 }
 
 static void pcol_free(struct page_collect *pcol)
 {
-       if (pcol->bio) {
-               bio_put(pcol->bio);
-               pcol->bio = NULL;
-       }
+       kfree(pcol->pages);
+       pcol->pages = NULL;
 
        if (pcol->ios) {
                exofs_put_io_state(pcol->ios);
@@ -132,11 +138,10 @@ static void pcol_free(struct page_collect *pcol)
 static int pcol_add_page(struct page_collect *pcol, struct page *page,
                         unsigned len)
 {
-       int added_len = bio_add_pc_page(pcol->req_q, pcol->bio, page, len, 0);
-       if (unlikely(len != added_len))
+       if (unlikely(pcol->nr_pages >= pcol->alloc_pages))
                return -ENOMEM;
 
-       ++pcol->nr_pages;
+       pcol->pages[pcol->nr_pages++] = page;
        pcol->length += len;
        return 0;
 }
@@ -181,7 +186,6 @@ static void update_write_page(struct page *page, int ret)
  */
 static int __readpages_done(struct page_collect *pcol, bool do_unlock)
 {
-       struct bio_vec *bvec;
        int i;
        u64 resid;
        u64 good_bytes;
@@ -198,8 +202,8 @@ static int __readpages_done(struct page_collect *pcol, bool do_unlock)
                     pcol->inode->i_ino, _LLU(good_bytes), pcol->length,
                     pcol->nr_pages);
 
-       __bio_for_each_segment(bvec, pcol->bio, i, 0) {
-               struct page *page = bvec->bv_page;
+       for (i = 0; i < pcol->nr_pages; i++) {
+               struct page *page = pcol->pages[i];
                struct inode *inode = page->mapping->host;
                int page_stat;
 
@@ -218,7 +222,7 @@ static int __readpages_done(struct page_collect *pcol, bool do_unlock)
                ret = update_read_page(page, page_stat);
                if (do_unlock)
                        unlock_page(page);
-               length += bvec->bv_len;
+               length += PAGE_SIZE;
        }
 
        pcol_free(pcol);
@@ -238,11 +242,10 @@ static void readpages_done(struct exofs_io_state *ios, void *p)
 
 static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw)
 {
-       struct bio_vec *bvec;
        int i;
 
-       __bio_for_each_segment(bvec, pcol->bio, i, 0) {
-               struct page *page = bvec->bv_page;
+       for (i = 0; i < pcol->nr_pages; i++) {
+               struct page *page = pcol->pages[i];
 
                if (rw == READ)
                        update_read_page(page, ret);
@@ -260,13 +263,14 @@ static int read_exec(struct page_collect *pcol, bool is_sync)
        struct page_collect *pcol_copy = NULL;
        int ret;
 
-       if (!pcol->bio)
+       if (!pcol->pages)
                return 0;
 
        /* see comment in _readpage() about sync reads */
        WARN_ON(is_sync && (pcol->nr_pages != 1));
 
-       ios->bio = pcol->bio;
+       ios->pages = pcol->pages;
+       ios->nr_pages = pcol->nr_pages;
        ios->length = pcol->length;
        ios->offset = pcol->pg_first << PAGE_CACHE_SHIFT;
 
@@ -366,7 +370,7 @@ try_again:
                goto try_again;
        }
 
-       if (!pcol->bio) {
+       if (!pcol->pages) {
                ret = pcol_try_alloc(pcol);
                if (unlikely(ret))
                        goto fail;
@@ -448,7 +452,6 @@ static int exofs_readpage(struct file *file, struct page *page)
 static void writepages_done(struct exofs_io_state *ios, void *p)
 {
        struct page_collect *pcol = p;
-       struct bio_vec *bvec;
        int i;
        u64 resid;
        u64  good_bytes;
@@ -467,8 +470,8 @@ static void writepages_done(struct exofs_io_state *ios, void *p)
                     pcol->inode->i_ino, _LLU(good_bytes), pcol->length,
                     pcol->nr_pages);
 
-       __bio_for_each_segment(bvec, pcol->bio, i, 0) {
-               struct page *page = bvec->bv_page;
+       for (i = 0; i < pcol->nr_pages; i++) {
+               struct page *page = pcol->pages[i];
                struct inode *inode = page->mapping->host;
                int page_stat;
 
@@ -485,7 +488,7 @@ static void writepages_done(struct exofs_io_state *ios, void *p)
                EXOFS_DBGMSG2("    writepages_done(0x%lx, 0x%lx) status=%d\n",
                             inode->i_ino, page->index, page_stat);
 
-               length += bvec->bv_len;
+               length += PAGE_SIZE;
        }
 
        pcol_free(pcol);
@@ -500,7 +503,7 @@ static int write_exec(struct page_collect *pcol)
        struct page_collect *pcol_copy = NULL;
        int ret;
 
-       if (!pcol->bio)
+       if (!pcol->pages)
                return 0;
 
        pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL);
@@ -512,9 +515,8 @@ static int write_exec(struct page_collect *pcol)
 
        *pcol_copy = *pcol;
 
-       pcol_copy->bio->bi_rw |= (1 << BIO_RW); /* FIXME: bio_set_dir() */
-
-       ios->bio = pcol_copy->bio;
+       ios->pages = pcol_copy->pages;
+       ios->nr_pages = pcol_copy->nr_pages;
        ios->offset = pcol_copy->pg_first << PAGE_CACHE_SHIFT;
        ios->length = pcol_copy->length;
        ios->done = writepages_done;
@@ -605,7 +607,7 @@ try_again:
                goto try_again;
        }
 
-       if (!pcol->bio) {
+       if (!pcol->pages) {
                ret = pcol_try_alloc(pcol);
                if (unlikely(ret))
                        goto fail;
@@ -869,18 +871,17 @@ static const struct osd_attr g_attr_inode_dir_layout = ATTR_DEF(
        0);
 
 /*
- * Read an inode from the OSD, and return it as is.  We also return the size
- * attribute in the 'obj_size' argument.
+ * Read the Linux inode info from the OSD, and return it as is. In exofs the
+ * inode info is in an application specific page/attribute of the osd-object.
  */
 static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi,
-                   struct exofs_fcb *inode, uint64_t *obj_size)
+                   struct exofs_fcb *inode)
 {
        struct exofs_sb_info *sbi = sb->s_fs_info;
        struct osd_attr attrs[] = {
                [0] = g_attr_inode_data,
                [1] = g_attr_inode_file_layout,
                [2] = g_attr_inode_dir_layout,
-               [3] = g_attr_logical_length,
        };
        struct exofs_io_state *ios;
        struct exofs_on_disk_inode_layout *layout;
@@ -903,8 +904,18 @@ static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi,
        ios->in_attr_len = ARRAY_SIZE(attrs);
 
        ret = exofs_sbi_read(ios);
-       if (ret)
+       if (unlikely(ret)) {
+               EXOFS_ERR("object(0x%llx) corrupted, return empty file=>%d\n",
+                         _LLU(ios->obj.id), ret);
+               memset(inode, 0, sizeof(*inode));
+               inode->i_mode = 0040000 | (0777 & ~022);
+               /* If object is lost on target we might as well enable it's
+                * delete.
+                */
+               if ((ret == -ENOENT) || (ret == -EINVAL))
+                       ret = 0;
                goto out;
+       }
 
        ret = extract_attr_from_ios(ios, &attrs[0]);
        if (ret) {
@@ -944,15 +955,6 @@ static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi,
                }
        }
 
-       *obj_size = ~0;
-       ret = extract_attr_from_ios(ios, &attrs[3]);
-       if (ret) {
-               EXOFS_ERR("%s: extract_attr of logical_length failed\n",
-                         __func__);
-               goto out;
-       }
-       *obj_size = get_unaligned_be64(attrs[3].val_ptr);
-
 out:
        exofs_put_io_state(ios);
        return ret;
@@ -971,7 +973,6 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino)
        struct exofs_i_info *oi;
        struct exofs_fcb fcb;
        struct inode *inode;
-       uint64_t obj_size;
        int ret;
 
        inode = iget_locked(sb, ino);
@@ -983,7 +984,7 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino)
        __oi_init(oi);
 
        /* read the inode from the osd */
-       ret = exofs_get_inode(sb, oi, &fcb, &obj_size);
+       ret = exofs_get_inode(sb, oi, &fcb);
        if (ret)
                goto bad_inode;
 
@@ -1004,13 +1005,6 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino)
        inode->i_blkbits = EXOFS_BLKSHIFT;
        inode->i_generation = le32_to_cpu(fcb.i_generation);
 
-       if ((inode->i_size != obj_size) &&
-               (!exofs_inode_is_fast_symlink(inode))) {
-               EXOFS_ERR("WARNING: Size of inode=%llu != object=%llu\n",
-                         inode->i_size, _LLU(obj_size));
-               /* FIXME: call exofs_inode_recovery() */
-       }
-
        oi->i_dir_start_lookup = 0;
 
        if ((inode->i_nlink == 0) && (inode->i_mode == 0)) {
@@ -1287,9 +1281,9 @@ out:
        return ret;
 }
 
-int exofs_write_inode(struct inode *inode, int wait)
+int exofs_write_inode(struct inode *inode, struct writeback_control *wbc)
 {
-       return exofs_update_inode(inode, wait);
+       return exofs_update_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
 }
 
 /*