Merge remote-tracking branch 'ovl/rename2' into for-linus
[cascardo/linux.git] / fs / ocfs2 / file.c
index 4e7b0dc..63bfc3b 100644 (file)
@@ -253,7 +253,7 @@ int ocfs2_should_update_atime(struct inode *inode,
                return 0;
        }
 
-       now = CURRENT_TIME;
+       now = current_time(inode);
        if ((now.tv_sec - inode->i_atime.tv_sec <= osb->s_atime_quantum))
                return 0;
        else
@@ -287,7 +287,7 @@ int ocfs2_update_inode_atime(struct inode *inode,
         * have i_mutex to guard against concurrent changes to other
         * inode fields.
         */
-       inode->i_atime = CURRENT_TIME;
+       inode->i_atime = current_time(inode);
        di->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
        di->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
        ocfs2_update_inode_fsync_trans(handle, inode, 0);
@@ -308,7 +308,7 @@ int ocfs2_set_inode_size(handle_t *handle,
 
        i_size_write(inode, new_i_size);
        inode->i_blocks = ocfs2_inode_sector_count(inode);
-       inode->i_ctime = inode->i_mtime = CURRENT_TIME;
+       inode->i_ctime = inode->i_mtime = current_time(inode);
 
        status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
        if (status < 0) {
@@ -429,7 +429,7 @@ static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
        }
 
        i_size_write(inode, new_i_size);
-       inode->i_ctime = inode->i_mtime = CURRENT_TIME;
+       inode->i_ctime = inode->i_mtime = current_time(inode);
 
        di = (struct ocfs2_dinode *) fe_bh->b_data;
        di->i_size = cpu_to_le64(new_i_size);
@@ -840,7 +840,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
        i_size_write(inode, abs_to);
        inode->i_blocks = ocfs2_inode_sector_count(inode);
        di->i_size = cpu_to_le64((u64)i_size_read(inode));
-       inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+       inode->i_mtime = inode->i_ctime = current_time(inode);
        di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
        di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
        di->i_mtime_nsec = di->i_ctime_nsec;
@@ -1506,7 +1506,8 @@ static int ocfs2_zero_partial_clusters(struct inode *inode,
                                       u64 start, u64 len)
 {
        int ret = 0;
-       u64 tmpend, end = start + len;
+       u64 tmpend = 0;
+       u64 end = start + len;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        unsigned int csize = osb->s_clustersize;
        handle_t *handle;
@@ -1538,18 +1539,31 @@ static int ocfs2_zero_partial_clusters(struct inode *inode,
        }
 
        /*
-        * We want to get the byte offset of the end of the 1st cluster.
+        * If start is on a cluster boundary and end is somewhere in another
+        * cluster, we have not COWed the cluster starting at start, unless
+        * end is also within the same cluster. So, in this case, we skip this
+        * first call to ocfs2_zero_range_for_truncate() truncate and move on
+        * to the next one.
         */
-       tmpend = (u64)osb->s_clustersize + (start & ~(osb->s_clustersize - 1));
-       if (tmpend > end)
-               tmpend = end;
+       if ((start & (csize - 1)) != 0) {
+               /*
+                * We want to get the byte offset of the end of the 1st
+                * cluster.
+                */
+               tmpend = (u64)osb->s_clustersize +
+                       (start & ~(osb->s_clustersize - 1));
+               if (tmpend > end)
+                       tmpend = end;
 
-       trace_ocfs2_zero_partial_clusters_range1((unsigned long long)start,
-                                                (unsigned long long)tmpend);
+               trace_ocfs2_zero_partial_clusters_range1(
+                       (unsigned long long)start,
+                       (unsigned long long)tmpend);
 
-       ret = ocfs2_zero_range_for_truncate(inode, handle, start, tmpend);
-       if (ret)
-               mlog_errno(ret);
+               ret = ocfs2_zero_range_for_truncate(inode, handle, start,
+                                                   tmpend);
+               if (ret)
+                       mlog_errno(ret);
+       }
 
        if (tmpend < end) {
                /*
@@ -1936,7 +1950,7 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
        if (change_size && i_size_read(inode) < size)
                i_size_write(inode, size);
 
-       inode->i_ctime = inode->i_mtime = CURRENT_TIME;
+       inode->i_ctime = inode->i_mtime = current_time(inode);
        ret = ocfs2_mark_inode_dirty(handle, inode, di_bh);
        if (ret < 0)
                mlog_errno(ret);