[Ocfs2-tools-devel] [PATCH 05/11] Add ocfs2_cached_inode_insert_extent in libocfs2.
Tao Ma
tao.ma at oracle.com
Tue Jul 22 15:52:24 PDT 2008
Abstract the work of ocfs2_insert_extent to another function named
ocfs2_cached_inode_insert_extent. With this new added function,
we move the read/write of ocfs2_dinode out so that inline data
can be removed safely after it has been written to extent list.
The caller can use ocfs2_cached_inode_insert_extent if they use
ocfs2_cached_inode while others can still use ocfs2_insert_extent
if they just want to use i_blkno to manipulate extent list.
Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
include/ocfs2/ocfs2.h | 3 ++
libocfs2/extend_file.c | 63 +++++++++++++++++++++++++++++-------------------
libocfs2/fileio.c | 14 ++++------
3 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 296a135..9d0f61b 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -475,6 +475,9 @@ errcode_t ocfs2_new_dir_block(ocfs2_filesys *fs, uint64_t dir_ino,
errcode_t ocfs2_insert_extent(ocfs2_filesys *fs, uint64_t ino, uint32_t cpos,
uint64_t c_blkno, uint32_t clusters,
uint16_t flag);
+errcode_t ocfs2_cached_inode_insert_extent(ocfs2_cached_inode *ci,
+ uint32_t cpos, uint64_t c_blkno,
+ uint32_t clusters, uint16_t flag);
errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode);
errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino, int mode, int flags);
diff --git a/libocfs2/extend_file.c b/libocfs2/extend_file.c
index 0b7310f..88d16c4 100644
--- a/libocfs2/extend_file.c
+++ b/libocfs2/extend_file.c
@@ -3310,22 +3310,42 @@ errcode_t ocfs2_insert_extent(ocfs2_filesys *fs, uint64_t ino, uint32_t cpos,
uint16_t flag)
{
errcode_t ret;
+ ocfs2_cached_inode *ci = NULL;
+
+ ret = ocfs2_read_cached_inode(fs, ino, &ci);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_cached_inode_insert_extent(ci, cpos, c_blkno,
+ clusters, flag);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_write_cached_inode(fs, ci);
+
+bail:
+ if (ci)
+ ocfs2_free_cached_inode(fs, ci);
+
+ return ret;
+}
+
+errcode_t ocfs2_cached_inode_insert_extent(ocfs2_cached_inode *ci,
+ uint32_t cpos, uint64_t c_blkno,
+ uint32_t clusters, uint16_t flag)
+{
+ errcode_t ret;
struct insert_ctxt ctxt;
struct ocfs2_insert_type insert = {0, };
- char *di_buf = NULL, *last_eb = NULL;
+ char *last_eb = NULL;
char *backup_buf = NULL;
+ char *di_buf = NULL;
int free_records = 0;
-
- ret = ocfs2_malloc_block(fs->fs_io, &di_buf);
- if (ret)
- return ret;
+ ocfs2_filesys *fs = ci->ci_fs;
ctxt.fs = fs;
- ctxt.di = (struct ocfs2_dinode *)di_buf;
-
- ret = ocfs2_read_inode(fs, ino, di_buf);
- if (ret)
- goto bail;
+ ctxt.di = ci->ci_inode;
+ di_buf = (char *)ctxt.di;
/* In order to orderize the written block sequence and avoid
* the corruption for the inode, we duplicate the extent block
@@ -3380,8 +3400,6 @@ errcode_t ocfs2_insert_extent(ocfs2_filesys *fs, uint64_t ino, uint32_t cpos,
if (ret)
goto bail;
- ret = ocfs2_write_inode(fs, ino, di_buf);
-
bail:
if (backup_buf) {
/* we have duplicated the extent block during the insertion.
@@ -3397,8 +3415,6 @@ bail:
if (last_eb)
ocfs2_free(&last_eb);
- if (di_buf)
- ocfs2_free(&di_buf);
return ret;
}
@@ -3844,8 +3860,9 @@ errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
break;
cpos = ocfs2_blocks_to_clusters(fs, v_blkno);
- ret = ocfs2_insert_extent(fs, ino, cpos, p_blkno, n_clusters,
- OCFS2_EXT_UNWRITTEN);
+ ret = ocfs2_cached_inode_insert_extent(ci, cpos,
+ p_blkno, n_clusters,
+ OCFS2_EXT_UNWRITTEN);
if (ret) {
/*
* XXX: We don't wan't to overwrite the error
@@ -3856,20 +3873,16 @@ errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
goto out;
}
+ /* save up what we have done. */
+ ret = ocfs2_write_cached_inode(fs, ci);
+ if (ret)
+ goto out;
+
v_blkno = ocfs2_clusters_to_blocks(fs, cpos + n_clusters);
}
if (ci->ci_inode->i_size <= offset + len) {
- /*
- * We have to reread the dinode since it is modified in
- * ocfs2_insert_extent.
- */
- ocfs2_free_cached_inode(fs, ci);
- ret = ocfs2_read_cached_inode(fs, ino, &ci);
- if (ret)
- goto out;
ci->ci_inode->i_size = offset + len;
-
ret = ocfs2_write_cached_inode(fs, ci);
}
diff --git a/libocfs2/fileio.c b/libocfs2/fileio.c
index 2df3449..9005d6e 100644
--- a/libocfs2/fileio.c
+++ b/libocfs2/fileio.c
@@ -345,7 +345,7 @@ errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
return ret;
if (insert) {
- ret = ocfs2_insert_extent(fs, ci->ci_blkno,
+ ret = ocfs2_cached_inode_insert_extent(ci,
ocfs2_blocks_to_clusters(fs,v_blkno),
p_start, n_clusters, 0);
if (ret) {
@@ -358,13 +358,11 @@ errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
return ret;
}
- /*
- * since the inode information has been changed, we
- * may need to reinitialize it and test whether we can
- * really find the inserted extents.
- */
- ocfs2_free_cached_inode(fs, ci);
- ret = ocfs2_read_cached_inode(fs,ino, &ci);
+ /* save up what we have done. */
+ ret = ocfs2_write_cached_inode(fs, ci);
+ if (ret)
+ return ret;
+
ret = ocfs2_extent_map_get_blocks(ci, v_blkno, 1,
&p_blkno, NULL, NULL);
/* now we shouldn't find a hole. */
--
1.5.4.GIT
More information about the Ocfs2-tools-devel
mailing list