ocfs2: return the physical address in ocfs2_write_cluster
authorRyan Ding <ryan.ding@oracle.com>
Fri, 25 Mar 2016 21:21:03 +0000 (14:21 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 25 Mar 2016 23:37:42 +0000 (16:37 -0700)
To support direct io in ocfs2_write_begin_nolock & ocfs2_write_end_nolock.

Direct io needs to get the physical address from write_begin, to map the
user page.  This patch is to change the arg 'phys' of
ocfs2_write_cluster to a pointer, so it can be retrieved to write_begin.
And we can retrieve it to the direct io procedure.

Signed-off-by: Ryan Ding <ryan.ding@oracle.com>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <joseph.qi@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/aops.c

index 4ad77453438a8df3640fca99ceaffb5b5d5913af..7b268c357cf34c20b4b6dc2da0b74d7b16df0e0c 100644 (file)
@@ -1596,7 +1596,7 @@ out:
  * Prepare a single cluster for write one cluster into the file.
  */
 static int ocfs2_write_cluster(struct address_space *mapping,
  * Prepare a single cluster for write one cluster into the file.
  */
 static int ocfs2_write_cluster(struct address_space *mapping,
-                              u32 phys, unsigned int new,
+                              u32 *phys, unsigned int new,
                               unsigned int clear_unwritten,
                               unsigned int should_zero,
                               struct ocfs2_alloc_context *data_ac,
                               unsigned int clear_unwritten,
                               unsigned int should_zero,
                               struct ocfs2_alloc_context *data_ac,
@@ -1605,9 +1605,10 @@ static int ocfs2_write_cluster(struct address_space *mapping,
                               loff_t user_pos, unsigned user_len)
 {
        int ret, i;
                               loff_t user_pos, unsigned user_len)
 {
        int ret, i;
-       u64 v_blkno, p_blkno;
+       u64 p_blkno;
        struct inode *inode = mapping->host;
        struct ocfs2_extent_tree et;
        struct inode *inode = mapping->host;
        struct ocfs2_extent_tree et;
+       int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
 
        if (new) {
                u32 tmp_pos;
 
        if (new) {
                u32 tmp_pos;
@@ -1641,7 +1642,7 @@ static int ocfs2_write_cluster(struct address_space *mapping,
                ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode),
                                              wc->w_di_bh);
                ret = ocfs2_mark_extent_written(inode, &et,
                ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode),
                                              wc->w_di_bh);
                ret = ocfs2_mark_extent_written(inode, &et,
-                                               wc->w_handle, cpos, 1, phys,
+                                               wc->w_handle, cpos, 1, *phys,
                                                meta_ac, &wc->w_dealloc);
                if (ret < 0) {
                        mlog_errno(ret);
                                                meta_ac, &wc->w_dealloc);
                if (ret < 0) {
                        mlog_errno(ret);
@@ -1649,26 +1650,23 @@ static int ocfs2_write_cluster(struct address_space *mapping,
                }
        }
 
                }
        }
 
-       if (should_zero)
-               v_blkno = ocfs2_clusters_to_blocks(inode->i_sb, cpos);
-       else
-               v_blkno = user_pos >> inode->i_sb->s_blocksize_bits;
-
        /*
         * The only reason this should fail is due to an inability to
         * find the extent added.
         */
        /*
         * The only reason this should fail is due to an inability to
         * find the extent added.
         */
-       ret = ocfs2_extent_map_get_blocks(inode, v_blkno, &p_blkno, NULL,
-                                         NULL);
+       ret = ocfs2_get_clusters(inode, cpos, phys, NULL, NULL);
        if (ret < 0) {
                mlog(ML_ERROR, "Get physical blkno failed for inode %llu, "
        if (ret < 0) {
                mlog(ML_ERROR, "Get physical blkno failed for inode %llu, "
-                           "at logical block %llu",
-                           (unsigned long long)OCFS2_I(inode)->ip_blkno,
-                           (unsigned long long)v_blkno);
+                           "at logical cluster %u",
+                           (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos);
                goto out;
        }
 
                goto out;
        }
 
-       BUG_ON(p_blkno == 0);
+       BUG_ON(*phys == 0);
+
+       p_blkno = ocfs2_clusters_to_blocks(inode->i_sb, *phys);
+       if (!should_zero)
+               p_blkno += (user_pos >> inode->i_sb->s_blocksize_bits) & (u64)(bpc - 1);
 
        for(i = 0; i < wc->w_num_pages; i++) {
                int tmpret;
 
        for(i = 0; i < wc->w_num_pages; i++) {
                int tmpret;
@@ -1725,7 +1723,7 @@ static int ocfs2_write_cluster_by_desc(struct address_space *mapping,
                if ((cluster_off + local_len) > osb->s_clustersize)
                        local_len = osb->s_clustersize - cluster_off;
 
                if ((cluster_off + local_len) > osb->s_clustersize)
                        local_len = osb->s_clustersize - cluster_off;
 
-               ret = ocfs2_write_cluster(mapping, desc->c_phys,
+               ret = ocfs2_write_cluster(mapping, &desc->c_phys,
                                          desc->c_new,
                                          desc->c_clear_unwritten,
                                          desc->c_needs_zero,
                                          desc->c_new,
                                          desc->c_clear_unwritten,
                                          desc->c_needs_zero,