From 933e87700e25e83bcd5e9ba4c4f580d48fcaccee Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Tue, 1 Dec 2009 12:03:08 +0000 Subject: performance/io-cache: Hold locks on inode before creating rbt tree. Lock is held before creating a RBT in inode. Also, did some re-factoring. Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 335 (Io-cache optimization) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=335 --- xlators/performance/io-cache/src/io-cache.c | 49 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'xlators/performance/io-cache/src/io-cache.c') diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 3fb4c850efd..13811b628b1 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -921,35 +921,44 @@ ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, ioc_table_lock (table); - if (!table->mem_pool) { + { + if (!table->mem_pool) { - num_pages = (table->cache_size / table->page_size) - + ((table->cache_size % table->page_size) ? 1 : 0); + num_pages = (table->cache_size / table->page_size) + + ((table->cache_size % table->page_size) + ? 1 : 0); - table->mem_pool - = mem_pool_new (rbthash_entry_t, num_pages); + table->mem_pool + = mem_pool_new (rbthash_entry_t, num_pages); - if (!table->mem_pool) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to allocate mem_pool"); - op_errno = ENOMEM; - ioc_table_unlock (table); - goto out; + if (!table->mem_pool) { + gf_log (this->name, GF_LOG_ERROR, + "Unable to allocate mem_pool"); + op_errno = ENOMEM; + ioc_table_unlock (table); + goto out; + } } } ioc_table_unlock (table); - if (!ioc_inode->cache.page_table) { - ioc_inode->cache.page_table - = rbthash_table_init (IOC_PAGE_TABLE_BUCKET_COUNT, - ioc_hashfn, NULL, 0, - table->mem_pool); - - if (ioc_inode->cache.page_table == NULL) { - op_errno = ENOMEM; - goto out; + ioc_inode_lock (ioc_inode); + { + if (!ioc_inode->cache.page_table) { + ioc_inode->cache.page_table + = rbthash_table_init + (IOC_PAGE_TABLE_BUCKET_COUNT, + ioc_hashfn, NULL, 0, + table->mem_pool); + + if (ioc_inode->cache.page_table == NULL) { + op_errno = ENOMEM; + ioc_inode_unlock (ioc_inode); + goto out; + } } } + ioc_inode_unlock (ioc_inode); if (!fd_ctx_get (fd, this, NULL)) { /* disable caching for this fd, go ahead with normal readv */ -- cgit