Merge tag 'pwm/for-4.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
[linux-2.6-microblaze.git] / fs / ocfs2 / aops.c
index 0f38163..ad15773 100644 (file)
@@ -234,7 +234,7 @@ int ocfs2_read_inline_data(struct inode *inode, struct page *page,
 
        size = i_size_read(inode);
 
-       if (size > PAGE_CACHE_SIZE ||
+       if (size > PAGE_SIZE ||
            size > ocfs2_max_inline_data_with_xattr(inode->i_sb, di)) {
                ocfs2_error(inode->i_sb,
                            "Inode %llu has with inline data has bad size: %Lu\n",
@@ -247,7 +247,7 @@ int ocfs2_read_inline_data(struct inode *inode, struct page *page,
        if (size)
                memcpy(kaddr, di->id2.i_data.id_data, size);
        /* Clear the remaining part of the page */
-       memset(kaddr + size, 0, PAGE_CACHE_SIZE - size);
+       memset(kaddr + size, 0, PAGE_SIZE - size);
        flush_dcache_page(page);
        kunmap_atomic(kaddr);
 
@@ -282,7 +282,7 @@ static int ocfs2_readpage(struct file *file, struct page *page)
 {
        struct inode *inode = page->mapping->host;
        struct ocfs2_inode_info *oi = OCFS2_I(inode);
-       loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT;
+       loff_t start = (loff_t)page->index << PAGE_SHIFT;
        int ret, unlock = 1;
 
        trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
@@ -385,7 +385,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
         * drop out in that case as it's not worth handling here.
         */
        last = list_entry(pages->prev, struct page, lru);
-       start = (loff_t)last->index << PAGE_CACHE_SHIFT;
+       start = (loff_t)last->index << PAGE_SHIFT;
        if (start >= i_size_read(inode))
                goto out_unlock;
 
@@ -511,12 +511,12 @@ static void ocfs2_figure_cluster_boundaries(struct ocfs2_super *osb,
                                            unsigned int *start,
                                            unsigned int *end)
 {
-       unsigned int cluster_start = 0, cluster_end = PAGE_CACHE_SIZE;
+       unsigned int cluster_start = 0, cluster_end = PAGE_SIZE;
 
-       if (unlikely(PAGE_CACHE_SHIFT > osb->s_clustersize_bits)) {
+       if (unlikely(PAGE_SHIFT > osb->s_clustersize_bits)) {
                unsigned int cpp;
 
-               cpp = 1 << (PAGE_CACHE_SHIFT - osb->s_clustersize_bits);
+               cpp = 1 << (PAGE_SHIFT - osb->s_clustersize_bits);
 
                cluster_start = cpos % cpp;
                cluster_start = cluster_start << osb->s_clustersize_bits;
@@ -684,13 +684,13 @@ next_bh:
        return ret;
 }
 
-#if (PAGE_CACHE_SIZE >= OCFS2_MAX_CLUSTERSIZE)
+#if (PAGE_SIZE >= OCFS2_MAX_CLUSTERSIZE)
 #define OCFS2_MAX_CTXT_PAGES   1
 #else
-#define OCFS2_MAX_CTXT_PAGES   (OCFS2_MAX_CLUSTERSIZE / PAGE_CACHE_SIZE)
+#define OCFS2_MAX_CTXT_PAGES   (OCFS2_MAX_CLUSTERSIZE / PAGE_SIZE)
 #endif
 
-#define OCFS2_MAX_CLUSTERS_PER_PAGE    (PAGE_CACHE_SIZE / OCFS2_MIN_CLUSTERSIZE)
+#define OCFS2_MAX_CLUSTERS_PER_PAGE    (PAGE_SIZE / OCFS2_MIN_CLUSTERSIZE)
 
 struct ocfs2_unwritten_extent {
        struct list_head        ue_node;
@@ -785,7 +785,7 @@ void ocfs2_unlock_and_free_pages(struct page **pages, int num_pages)
                if (pages[i]) {
                        unlock_page(pages[i]);
                        mark_page_accessed(pages[i]);
-                       page_cache_release(pages[i]);
+                       put_page(pages[i]);
                }
        }
 }
@@ -808,7 +808,7 @@ static void ocfs2_unlock_pages(struct ocfs2_write_ctxt *wc)
                        }
                }
                mark_page_accessed(wc->w_target_page);
-               page_cache_release(wc->w_target_page);
+               put_page(wc->w_target_page);
        }
        ocfs2_unlock_and_free_pages(wc->w_pages, wc->w_num_pages);
 }
@@ -857,7 +857,7 @@ static int ocfs2_alloc_write_ctxt(struct ocfs2_write_ctxt **wcp,
        wc->w_di_bh = di_bh;
        wc->w_type = type;
 
-       if (unlikely(PAGE_CACHE_SHIFT > osb->s_clustersize_bits))
+       if (unlikely(PAGE_SHIFT > osb->s_clustersize_bits))
                wc->w_large_pages = 1;
        else
                wc->w_large_pages = 0;
@@ -920,7 +920,7 @@ static void ocfs2_write_failure(struct inode *inode,
                                loff_t user_pos, unsigned user_len)
 {
        int i;
-       unsigned from = user_pos & (PAGE_CACHE_SIZE - 1),
+       unsigned from = user_pos & (PAGE_SIZE - 1),
                to = user_pos + user_len;
        struct page *tmppage;
 
@@ -960,7 +960,7 @@ static int ocfs2_prepare_page_for_write(struct inode *inode, u64 *p_blkno,
                        (page_offset(page) <= user_pos));
 
        if (page == wc->w_target_page) {
-               map_from = user_pos & (PAGE_CACHE_SIZE - 1);
+               map_from = user_pos & (PAGE_SIZE - 1);
                map_to = map_from + user_len;
 
                if (new)
@@ -1034,7 +1034,7 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
        struct inode *inode = mapping->host;
        loff_t last_byte;
 
-       target_index = user_pos >> PAGE_CACHE_SHIFT;
+       target_index = user_pos >> PAGE_SHIFT;
 
        /*
         * Figure out how many pages we'll be manipulating here. For
@@ -1053,14 +1053,14 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
                 */
                last_byte = max(user_pos + user_len, i_size_read(inode));
                BUG_ON(last_byte < 1);
-               end_index = ((last_byte - 1) >> PAGE_CACHE_SHIFT) + 1;
+               end_index = ((last_byte - 1) >> PAGE_SHIFT) + 1;
                if ((start + wc->w_num_pages) > end_index)
                        wc->w_num_pages = end_index - start;
        } else {
                wc->w_num_pages = 1;
                start = target_index;
        }
-       end_index = (user_pos + user_len - 1) >> PAGE_CACHE_SHIFT;
+       end_index = (user_pos + user_len - 1) >> PAGE_SHIFT;
 
        for(i = 0; i < wc->w_num_pages; i++) {
                index = start + i;
@@ -1082,7 +1082,7 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
                                goto out;
                        }
 
-                       page_cache_get(mmap_page);
+                       get_page(mmap_page);
                        wc->w_pages[i] = mmap_page;
                        wc->w_target_locked = true;
                } else if (index >= target_index && index <= end_index &&
@@ -1272,7 +1272,7 @@ static void ocfs2_set_target_boundaries(struct ocfs2_super *osb,
 {
        struct ocfs2_write_cluster_desc *desc;
 
-       wc->w_target_from = pos & (PAGE_CACHE_SIZE - 1);
+       wc->w_target_from = pos & (PAGE_SIZE - 1);
        wc->w_target_to = wc->w_target_from + len;
 
        if (alloc == 0)
@@ -1309,7 +1309,7 @@ static void ocfs2_set_target_boundaries(struct ocfs2_super *osb,
                                                        &wc->w_target_to);
        } else {
                wc->w_target_from = 0;
-               wc->w_target_to = PAGE_CACHE_SIZE;
+               wc->w_target_to = PAGE_SIZE;
        }
 }
 
@@ -1981,7 +1981,7 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                           struct page *page, void *fsdata)
 {
        int i, ret;
-       unsigned from, to, start = pos & (PAGE_CACHE_SIZE - 1);
+       unsigned from, to, start = pos & (PAGE_SIZE - 1);
        struct inode *inode = mapping->host;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        struct ocfs2_write_ctxt *wc = fsdata;
@@ -2027,8 +2027,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                        from = wc->w_target_from;
                        to = wc->w_target_to;
 
-                       BUG_ON(from > PAGE_CACHE_SIZE ||
-                              to > PAGE_CACHE_SIZE ||
+                       BUG_ON(from > PAGE_SIZE ||
+                              to > PAGE_SIZE ||
                               to < from);
                } else {
                        /*
@@ -2037,7 +2037,7 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                         * to flush their entire range.
                         */
                        from = 0;
-                       to = PAGE_CACHE_SIZE;
+                       to = PAGE_SIZE;
                }
 
                if (page_has_buffers(tmppage)) {
@@ -2167,19 +2167,26 @@ static int ocfs2_dio_get_block(struct inode *inode, sector_t iblock,
        mlog(0, "get block of %lu at %llu:%u req %u\n",
                        inode->i_ino, pos, len, total_len);
 
-       down_read(&oi->ip_alloc_sem);
-       /* This is the fast path for re-write. */
-       ret = ocfs2_get_block(inode, iblock, bh_result, create);
+       /*
+        * Because we need to change file size in ocfs2_dio_end_io_write(), or
+        * we may need to add it to orphan dir. So can not fall to fast path
+        * while file size will be changed.
+        */
+       if (pos + total_len <= i_size_read(inode)) {
+               down_read(&oi->ip_alloc_sem);
+               /* This is the fast path for re-write. */
+               ret = ocfs2_get_block(inode, iblock, bh_result, create);
 
-       up_read(&oi->ip_alloc_sem);
+               up_read(&oi->ip_alloc_sem);
 
-       if (buffer_mapped(bh_result) &&
-           !buffer_new(bh_result) &&
-           ret == 0)
-               goto out;
+               if (buffer_mapped(bh_result) &&
+                   !buffer_new(bh_result) &&
+                   ret == 0)
+                       goto out;
 
-       /* Clear state set by ocfs2_get_block. */
-       bh_result->b_state = 0;
+               /* Clear state set by ocfs2_get_block. */
+               bh_result->b_state = 0;
+       }
 
        dwc = ocfs2_dio_alloc_write_ctx(bh_result, &first_get_block);
        if (unlikely(dwc == NULL)) {
@@ -2334,6 +2341,10 @@ static void ocfs2_dio_end_io_write(struct inode *inode,
 
        ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
                                    &data_ac, &meta_ac);
+       if (ret) {
+               mlog_errno(ret);
+               goto unlock;
+       }
 
        credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
 
@@ -2373,14 +2384,14 @@ unlock:
        ocfs2_inode_unlock(inode, 1);
        brelse(di_bh);
 out:
-       ocfs2_run_deallocs(osb, &dealloc);
-       if (locked)
-               mutex_unlock(&inode->i_mutex);
-       ocfs2_dio_free_write_ctx(inode, dwc);
        if (data_ac)
                ocfs2_free_alloc_context(data_ac);
        if (meta_ac)
                ocfs2_free_alloc_context(meta_ac);
+       ocfs2_run_deallocs(osb, &dealloc);
+       if (locked)
+               mutex_unlock(&inode->i_mutex);
+       ocfs2_dio_free_write_ctx(inode, dwc);
 }
 
 /*