[Ocfs2-tools-devel] [PATCH 1/2] fsck.ocfs2: Use aligned size when do copy_clone.v2
Tao Ma
tao.ma at oracle.com
Sun Oct 11 19:18:11 PDT 2009
Actually ocfs2_file_read and ocfs2_file_write only accept
aligned size as the parameter. So when the file size isn't
aligned, align it first.
Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
fsck.ocfs2/pass1b.c | 8 ++++----
include/ocfs2/ocfs2.h | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/fsck.ocfs2/pass1b.c b/fsck.ocfs2/pass1b.c
index 01b5015..4cbae0c 100644
--- a/fsck.ocfs2/pass1b.c
+++ b/fsck.ocfs2/pass1b.c
@@ -1090,7 +1090,7 @@ static errcode_t copy_clone(ocfs2_filesys *fs, ocfs2_cached_inode *orig_ci,
uint64_t offset = 0;
uint64_t filesize = orig_ci->ci_inode->i_size;
unsigned int iosize = 1024 * 1024; /* Let's read in 1MB hunks */
- unsigned int got, wrote;
+ unsigned int got, wrote, write_len;
ret = ocfs2_malloc_blocks(fs->fs_io, iosize / fs->fs_blocksize,
&buf);
@@ -1100,15 +1100,15 @@ static errcode_t copy_clone(ocfs2_filesys *fs, ocfs2_cached_inode *orig_ci,
}
while (offset < filesize) {
- if ((filesize - offset) < iosize)
- iosize = filesize - offset;
ret = ocfs2_file_read(orig_ci, buf, iosize, offset, &got);
if (ret) {
com_err(whoami, ret, "while reading inode to clone");
break;
}
- ret = ocfs2_file_write(clone_ci, buf, iosize, offset, &wrote);
+ write_len = ocfs2_align_bytes_to_blocks(fs, got);
+ ret = ocfs2_file_write(clone_ci, buf, write_len,
+ offset, &wrote);
if (ret) {
com_err(whoami, ret, "while writing clone data");
break;
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 579ad2b..992d2f2 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -967,6 +967,24 @@ static inline uint64_t ocfs2_blocks_in_bytes(ocfs2_filesys *fs,
return ret >> OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
}
+static inline uint64_t ocfs2_align_bytes_to_clusters(ocfs2_filesys *fs,
+ uint64_t bytes)
+{
+ uint32_t clusters;
+
+ clusters = ocfs2_clusters_in_bytes(fs, bytes);
+ return (uint64_t)clusters <<
+ OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+}
+
+static inline uint64_t ocfs2_align_bytes_to_blocks(ocfs2_filesys *fs,
+ uint64_t bytes)
+{
+ uint64_t blocks;
+
+ blocks = ocfs2_blocks_in_bytes(fs, bytes);
+ return blocks << OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+}
/* given a cluster offset, calculate which block group it belongs to
* and return that block offset. */
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list