[Ocfs2-tools-devel] [PATCH 14/50] ocfs2: Integrate CoW in file write.

Tao Ma tao.ma at oracle.com
Mon Jan 11 07:31:00 PST 2010


Call ocfs2_refcount_cow first to CoW refcounted clusters
in ocfs2_file_block_write.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 libocfs2/fileio.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/libocfs2/fileio.c b/libocfs2/fileio.c
index c4664ec..d5860c5 100644
--- a/libocfs2/fileio.c
+++ b/libocfs2/fileio.c
@@ -33,6 +33,7 @@
 #include <inttypes.h>
 
 #include "ocfs2/ocfs2.h"
+#include "refcount.h"
 
 struct read_whole_context {
 	char		*buf;
@@ -325,6 +326,17 @@ static errcode_t ocfs2_file_block_write(ocfs2_cached_inode *ci,
 	if (v_blkno + wanted_blocks > num_blocks)
 		wanted_blocks = (uint32_t) (num_blocks - v_blkno);
 
+	if (ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)) &&
+	    (ci->ci_inode->i_dyn_features & OCFS2_HAS_REFCOUNT_FL)) {
+		cluster_begin = ocfs2_blocks_to_clusters(fs, v_blkno);
+		cluster_end = ocfs2_blocks_to_clusters(fs,
+					       v_blkno + wanted_blocks - 1);
+		n_clusters = cluster_end - cluster_begin + 1;
+		ret = ocfs2_refcount_cow(ci, cluster_begin, n_clusters, UINT_MAX);
+		if (ret)
+			return ret;
+	}
+
 	while(wanted_blocks) {
 		ret = ocfs2_extent_map_get_blocks(ci, v_blkno, 1,
 						  &p_blkno, &contig_blocks,
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list