[Ocfs2-tools-devel] [PATCH 1/2] Implement cache sharing for io channels
Jan Kara
jack at suse.cz
Tue Aug 11 05:06:18 PDT 2009
Implement function io_share_cache() to allow sharing of caches for two
io channels.
Signed-off-by: Jan Kara <jack at suse.cz>
---
include/ocfs2/ocfs2.h | 1 +
libocfs2/unix_io.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 8bf22c9..2b7dc54 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -248,6 +248,7 @@ errcode_t io_write_block_nocache(io_channel *channel, int64_t blkno, int count,
errcode_t io_init_cache(io_channel *channel, size_t nr_blocks);
void io_set_nocache(io_channel *channel, bool nocache);
errcode_t io_init_cache_size(io_channel *channel, size_t bytes);
+errcode_t io_share_cache(io_channel *from, io_channel *to);
errcode_t io_mlock_cache(io_channel *channel);
void io_destroy_cache(io_channel *channel);
diff --git a/libocfs2/unix_io.c b/libocfs2/unix_io.c
index ccdaf93..4d16b0c 100644
--- a/libocfs2/unix_io.c
+++ b/libocfs2/unix_io.c
@@ -84,6 +84,7 @@ struct io_cache {
char *ic_data_buffer;
unsigned long ic_data_buffer_len;
int ic_locked;
+ int ic_use_count;
};
struct _io_channel {
@@ -479,7 +480,8 @@ static void io_free_cache(struct io_cache *ic)
void io_destroy_cache(io_channel *channel)
{
if (channel->io_cache) {
- io_free_cache(channel->io_cache);
+ if (!--channel->io_cache->ic_use_count)
+ io_free_cache(channel->io_cache);
channel->io_cache = NULL;
}
}
@@ -562,6 +564,7 @@ errcode_t io_init_cache(io_channel *channel, size_t nr_blocks)
list_add_tail(&icb_list[i].icb_list, &ic->ic_lru);
}
+ ic->ic_use_count = 1;
channel->io_cache = ic;
out:
@@ -581,6 +584,17 @@ errcode_t io_init_cache_size(io_channel *channel, size_t bytes)
}
+errcode_t io_share_cache(io_channel *from, io_channel *to)
+{
+ if (!from->io_cache)
+ return OCFS2_ET_INTERNAL_FAILURE;
+ if (to->io_cache)
+ return OCFS2_ET_INTERNAL_FAILURE;
+ to->io_cache = from->io_cache;
+ from->io_cache->ic_use_count++;
+ return 0;
+}
+
static errcode_t io_validate_o_direct(io_channel *channel)
{
errcode_t ret = OCFS2_ET_UNEXPECTED_BLOCK_SIZE;
--
1.6.0.2
More information about the Ocfs2-tools-devel
mailing list