[Ocfs2-tools-devel] [PATCH 2/2] o2image: allocate bitmap blocks only for metadata blocks when installing image file
piaojun
piaojun at huawei.com
Sat Apr 7 18:37:14 PDT 2018
We should only allocate bitmap blocks for metadata blocks, as user data
blocks won't be accessed during installing image file.
Signed-off-by: Jun Piao <piaojun at huawei.com>
---
libocfs2/image.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/libocfs2/image.c b/libocfs2/image.c
index 68f4fda..8814a56 100644
--- a/libocfs2/image.c
+++ b/libocfs2/image.c
@@ -114,7 +114,7 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
int i, j, fd;
ssize_t count;
errcode_t ret;
- char *blk = NULL;
+ char *blk = NULL, *buf = NULL;
ret = ocfs2_malloc0(sizeof(struct ocfs2_image_state), &ofs->ost);
if (ret)
@@ -125,6 +125,10 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
if (ret)
goto out;
+ ret = ocfs2_malloc0(ost->ost_bmpblksz, &buf);
+ if (ret)
+ goto out;
+
/* read ocfs2 image header */
ret = io_read_block(ofs->fs_io, 0, 1, blk);
if (ret)
@@ -165,6 +169,13 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
* we don't use io_read_block as ocfs2 image bitmap block size
* could be different from filesystem block size
*/
+ ret = posix_memalign((void **)&ost->ost_bmparr[i].arr_map,
+ OCFS2_MAX_BLOCKSIZE, ost->ost_bmpblksz);
+ if (ret) {
+ ret = OCFS2_ET_NO_MEMORY;
+ goto out;
+ }
+
count = pread64(fd, ost->ost_bmparr[i].arr_map,
ost->ost_bmpblksz, blk_off);
if (count < 0) {
@@ -172,6 +183,16 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
goto out;
}
+ /*
+ * we do not need 'arr_map' which none bit is set,
+ * so free it to save memory.
+ */
+ if (!memcmp(ost->ost_bmparr[i].arr_map, buf,
+ ost->ost_bmpblksz)) {
+ ocfs2_free(&ost->ost_bmparr[i].arr_map);
+ continue;
+ }
+
/* add bits set in this bitmap */
for (j = 0; j < (ost->ost_bmpblksz * 8); j++)
if (ocfs2_test_bit(j, ost->ost_bmparr[i].arr_map))
@@ -183,6 +204,8 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
out:
if (blk)
ocfs2_free(&blk);
+ if (buf)
+ ocfs2_free(&buf);
if (ret) {
ocfs2_image_free_bitmap(ofs);
ocfs2_free(&ofs->ost);
--
More information about the Ocfs2-tools-devel
mailing list