diff options
Diffstat (limited to 'xlators/performance')
-rw-r--r-- | xlators/performance/io-cache/src/io-cache.h | 262 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/ioc-inode.c | 229 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/ioc-mem-types.h | 27 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/page.c | 963 |
4 files changed, 741 insertions, 740 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.h b/xlators/performance/io-cache/src/io-cache.h index e9cb56e0a1c..5d05264404a 100644 --- a/xlators/performance/io-cache/src/io-cache.h +++ b/xlators/performance/io-cache/src/io-cache.h @@ -49,132 +49,132 @@ struct ioc_page; struct ioc_inode; struct ioc_priority { - struct list_head list; - char *pattern; - uint32_t priority; + struct list_head list; + char *pattern; + uint32_t priority; }; /* - * ioc_waitq - this structure is used to represents the waiting + * ioc_waitq - this structure is used to represents the waiting * frames on a page * * @next: pointer to next object in waitq * @data: pointer to the frame which is waiting */ struct ioc_waitq { - struct ioc_waitq *next; - void *data; - off_t pending_offset; - size_t pending_size; + struct ioc_waitq *next; + void *data; + off_t pending_offset; + size_t pending_size; }; /* - * ioc_fill - + * ioc_fill - * */ struct ioc_fill { - struct list_head list; /* list of ioc_fill structures of a frame */ - off_t offset; - size_t size; - struct iovec *vector; - int32_t count; - struct iobref *iobref; + struct list_head list; /* list of ioc_fill structures of a frame */ + off_t offset; + size_t size; + struct iovec *vector; + int32_t count; + struct iobref *iobref; }; struct ioc_local { - mode_t mode; - int32_t flags; + mode_t mode; + int32_t flags; int32_t wbflags; - loc_t file_loc; - off_t offset; - size_t size; - int32_t op_ret; - int32_t op_errno; - struct list_head fill_list; /* list of ioc_fill structures */ - off_t pending_offset; /* + loc_t file_loc; + off_t offset; + size_t size; + int32_t op_ret; + int32_t op_errno; + struct list_head fill_list; /* list of ioc_fill structures */ + off_t pending_offset; /* * offset from this frame should * continue */ - size_t pending_size; /* + size_t pending_size; /* * size of data this frame is waiting * on */ - struct ioc_inode *inode; - int32_t wait_count; - pthread_mutex_t local_lock; - struct ioc_waitq *waitq; - void *stub; - fd_t *fd; - int32_t need_xattr; - dict_t *xattr_req; + struct ioc_inode *inode; + int32_t wait_count; + pthread_mutex_t local_lock; + struct ioc_waitq *waitq; + void *stub; + fd_t *fd; + int32_t need_xattr; + dict_t *xattr_req; }; /* - * ioc_page - structure to store page of data from file + * ioc_page - structure to store page of data from file * */ struct ioc_page { - struct list_head page_lru; - struct ioc_inode *inode; /* inode this page belongs to */ - struct ioc_priority *priority; - char dirty; - char ready; - struct iovec *vector; - int32_t count; - off_t offset; - size_t size; - struct ioc_waitq *waitq; - struct iobref *iobref; - pthread_mutex_t page_lock; + struct list_head page_lru; + struct ioc_inode *inode; /* inode this page belongs to */ + struct ioc_priority *priority; + char dirty; + char ready; + struct iovec *vector; + int32_t count; + off_t offset; + size_t size; + struct ioc_waitq *waitq; + struct iobref *iobref; + pthread_mutex_t page_lock; }; struct ioc_cache { rbthash_table_t *page_table; struct list_head page_lru; - time_t mtime; /* + time_t mtime; /* * seconds component of file mtime */ time_t mtime_nsec; /* * nanosecond component of file mtime */ - struct timeval tv; /* + struct timeval tv; /* * time-stamp at last re-validate */ }; struct ioc_inode { - struct ioc_table *table; + struct ioc_table *table; off_t ia_size; - struct ioc_cache cache; - struct list_head inode_list; /* + struct ioc_cache cache; + struct list_head inode_list; /* * list of inodes, maintained by * io-cache translator */ - struct list_head inode_lru; - struct ioc_waitq *waitq; - pthread_mutex_t inode_lock; - uint32_t weight; /* + struct list_head inode_lru; + struct ioc_waitq *waitq; + pthread_mutex_t inode_lock; + uint32_t weight; /* * weight of the inode, increases * on each read */ }; struct ioc_table { - uint64_t page_size; - uint64_t cache_size; - uint64_t cache_used; + uint64_t page_size; + uint64_t cache_size; + uint64_t cache_used; int64_t min_file_size; int64_t max_file_size; - struct list_head inodes; /* list of inodes cached */ - struct list_head active; - struct list_head *inode_lru; - struct list_head priority_list; - int32_t readv_count; - pthread_mutex_t table_lock; - xlator_t *xl; - uint32_t inode_count; - int32_t cache_timeout; - int32_t max_pri; + struct list_head inodes; /* list of inodes cached */ + struct list_head active; + struct list_head *inode_lru; + struct list_head priority_list; + int32_t readv_count; + pthread_mutex_t table_lock; + xlator_t *xl; + uint32_t inode_count; + int32_t cache_timeout; + int32_t max_pri; struct mem_pool *mem_pool; }; @@ -191,10 +191,10 @@ str_to_ptr (char *string); char * ptr_to_str (void *ptr); -int32_t +int32_t ioc_readv_disabled_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, + int32_t op_ret, int32_t op_errno, struct iovec *vector, + int32_t count, struct iatt *stbuf, struct iobref *iobref); ioc_page_t * @@ -204,11 +204,11 @@ ioc_page_t * ioc_page_create (ioc_inode_t *ioc_inode, off_t offset); void -ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, - off_t offset); +ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, + off_t offset); void ioc_wait_on_page (ioc_page_t *page, call_frame_t *frame, off_t offset, - size_t size); + size_t size); ioc_waitq_t * ioc_page_wakeup (ioc_page_t *page); @@ -230,94 +230,94 @@ ioc_waitq_return (ioc_waitq_t *waitq); int32_t ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, - size_t size); + size_t size); -#define ioc_inode_lock(ioc_inode) \ - do { \ - gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, \ - "locked inode(%p)", ioc_inode); \ - pthread_mutex_lock (&ioc_inode->inode_lock); \ - } while (0) +#define ioc_inode_lock(ioc_inode) \ + do { \ + gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, \ + "locked inode(%p)", ioc_inode); \ + pthread_mutex_lock (&ioc_inode->inode_lock); \ + } while (0) -#define ioc_inode_unlock(ioc_inode) \ - do { \ - gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, \ - "unlocked inode(%p)", ioc_inode); \ - pthread_mutex_unlock (&ioc_inode->inode_lock); \ - } while (0) +#define ioc_inode_unlock(ioc_inode) \ + do { \ + gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, \ + "unlocked inode(%p)", ioc_inode); \ + pthread_mutex_unlock (&ioc_inode->inode_lock); \ + } while (0) -#define ioc_table_lock(table) \ - do { \ - gf_log (table->xl->name, GF_LOG_TRACE, \ - "locked table(%p)", table); \ - pthread_mutex_lock (&table->table_lock); \ - } while (0) +#define ioc_table_lock(table) \ + do { \ + gf_log (table->xl->name, GF_LOG_TRACE, \ + "locked table(%p)", table); \ + pthread_mutex_lock (&table->table_lock); \ + } while (0) -#define ioc_table_unlock(table) \ - do { \ - gf_log (table->xl->name, GF_LOG_TRACE, \ - "unlocked table(%p)", table); \ - pthread_mutex_unlock (&table->table_lock); \ - } while (0) +#define ioc_table_unlock(table) \ + do { \ + gf_log (table->xl->name, GF_LOG_TRACE, \ + "unlocked table(%p)", table); \ + pthread_mutex_unlock (&table->table_lock); \ + } while (0) -#define ioc_local_lock(local) \ - do { \ - gf_log (local->inode->table->xl->name, GF_LOG_TRACE, \ - "locked local(%p)", local); \ - pthread_mutex_lock (&local->local_lock); \ - } while (0) +#define ioc_local_lock(local) \ + do { \ + gf_log (local->inode->table->xl->name, GF_LOG_TRACE, \ + "locked local(%p)", local); \ + pthread_mutex_lock (&local->local_lock); \ + } while (0) -#define ioc_local_unlock(local) \ - do { \ - gf_log (local->inode->table->xl->name, GF_LOG_TRACE, \ - "unlocked local(%p)", local); \ - pthread_mutex_unlock (&local->local_lock); \ - } while (0) +#define ioc_local_unlock(local) \ + do { \ + gf_log (local->inode->table->xl->name, GF_LOG_TRACE, \ + "unlocked local(%p)", local); \ + pthread_mutex_unlock (&local->local_lock); \ + } while (0) -#define ioc_page_lock(page) \ - do { \ - gf_log (page->inode->table->xl->name, GF_LOG_TRACE, \ - "locked page(%p)", page); \ - pthread_mutex_lock (&page->page_lock); \ - } while (0) +#define ioc_page_lock(page) \ + do { \ + gf_log (page->inode->table->xl->name, GF_LOG_TRACE, \ + "locked page(%p)", page); \ + pthread_mutex_lock (&page->page_lock); \ + } while (0) -#define ioc_page_unlock(page) \ - do { \ - gf_log (page->inode->table->xl->name, GF_LOG_TRACE, \ - "unlocked page(%p)", page); \ - pthread_mutex_unlock (&page->page_lock); \ - } while (0) +#define ioc_page_unlock(page) \ + do { \ + gf_log (page->inode->table->xl->name, GF_LOG_TRACE, \ + "unlocked page(%p)", page); \ + pthread_mutex_unlock (&page->page_lock); \ + } while (0) static inline uint64_t time_elapsed (struct timeval *now, - struct timeval *then) + struct timeval *then) { - uint64_t sec = now->tv_sec - then->tv_sec; + uint64_t sec = now->tv_sec - then->tv_sec; + + if (sec) + return sec; - if (sec) - return sec; - - return 0; + return 0; } ioc_inode_t * ioc_inode_search (ioc_table_t *table, inode_t *inode); -void +void ioc_inode_destroy (ioc_inode_t *ioc_inode); ioc_inode_t * ioc_inode_update (ioc_table_t *table, inode_t *inode, uint32_t weight); -int64_t +int64_t ioc_page_destroy (ioc_page_t *page); int64_t diff --git a/xlators/performance/io-cache/src/ioc-inode.c b/xlators/performance/io-cache/src/ioc-inode.c index bbf46d9357f..1beb9efd429 100644 --- a/xlators/performance/io-cache/src/ioc-inode.c +++ b/xlators/performance/io-cache/src/ioc-inode.c @@ -35,10 +35,10 @@ extern int ioc_log2_page_size; void * str_to_ptr (char *string) { - void *ptr = NULL; + void *ptr = NULL; ptr = (void *)strtoul (string, NULL, 16); - return ptr; + return ptr; } @@ -51,102 +51,104 @@ char * ptr_to_str (void *ptr) { int ret = 0; - char *str = NULL; - ret = gf_asprintf (&str, "%p", ptr); + char *str = NULL; + ret = gf_asprintf (&str, "%p", ptr); if (-1 == ret) { - gf_log ("ioc", GF_LOG_ERROR, + gf_log ("ioc", GF_LOG_ERROR, "asprintf failed while converting ptr to str"); return NULL; } - return str; + return str; } + void -ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, +ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, struct iatt *stbuf) { - ioc_waitq_t *waiter = NULL, *waited = NULL; - ioc_waitq_t *page_waitq = NULL; - int8_t cache_still_valid = 1; - ioc_local_t *local = NULL; - int8_t need_fault = 0; - ioc_page_t *waiter_page = NULL; + ioc_waitq_t *waiter = NULL, *waited = NULL; + ioc_waitq_t *page_waitq = NULL; + int8_t cache_still_valid = 1; + ioc_local_t *local = NULL; + int8_t need_fault = 0; + ioc_page_t *waiter_page = NULL; local = frame->local; - ioc_inode_lock (ioc_inode); - { - waiter = ioc_inode->waitq; - ioc_inode->waitq = NULL; - } - ioc_inode_unlock (ioc_inode); - - if (stbuf) - cache_still_valid = ioc_cache_still_valid (ioc_inode, stbuf); - else - cache_still_valid = 0; - - if (!waiter) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "cache validate called without any " - "page waiting to be validated"); - } - - while (waiter) { - waiter_page = waiter->data; - page_waitq = NULL; - - if (waiter_page) { - if (cache_still_valid) { - /* cache valid, wake up page */ - ioc_inode_lock (ioc_inode); - { - page_waitq = - ioc_page_wakeup (waiter_page); - } - ioc_inode_unlock (ioc_inode); - if (page_waitq) - ioc_waitq_return (page_waitq); - } else { - /* cache invalid, generate page fault and set - * page->ready = 0, to avoid double faults - */ - ioc_inode_lock (ioc_inode); - - if (waiter_page->ready) { - waiter_page->ready = 0; - need_fault = 1; - } else { - gf_log (frame->this->name, - GF_LOG_TRACE, - "validate frame(%p) is waiting" - "for in-transit page = %p", - frame, waiter_page); - } - - ioc_inode_unlock (ioc_inode); - - if (need_fault) { - need_fault = 0; - ioc_page_fault (ioc_inode, frame, - local->fd, - waiter_page->offset); - } - } - } - - waited = waiter; - waiter = waiter->next; - - waited->data = NULL; - GF_FREE (waited); - } + ioc_inode_lock (ioc_inode); + { + waiter = ioc_inode->waitq; + ioc_inode->waitq = NULL; + } + ioc_inode_unlock (ioc_inode); + + if (stbuf) + cache_still_valid = ioc_cache_still_valid (ioc_inode, stbuf); + else + cache_still_valid = 0; + + if (!waiter) { + gf_log (frame->this->name, GF_LOG_DEBUG, + "cache validate called without any " + "page waiting to be validated"); + } + + while (waiter) { + waiter_page = waiter->data; + page_waitq = NULL; + + if (waiter_page) { + if (cache_still_valid) { + /* cache valid, wake up page */ + ioc_inode_lock (ioc_inode); + { + page_waitq = + ioc_page_wakeup (waiter_page); + } + ioc_inode_unlock (ioc_inode); + if (page_waitq) + ioc_waitq_return (page_waitq); + } else { + /* cache invalid, generate page fault and set + * page->ready = 0, to avoid double faults + */ + ioc_inode_lock (ioc_inode); + + if (waiter_page->ready) { + waiter_page->ready = 0; + need_fault = 1; + } else { + gf_log (frame->this->name, + GF_LOG_TRACE, + "validate frame(%p) is waiting" + "for in-transit page = %p", + frame, waiter_page); + } + + ioc_inode_unlock (ioc_inode); + + if (need_fault) { + need_fault = 0; + ioc_page_fault (ioc_inode, frame, + local->fd, + waiter_page->offset); + } + } + } + + waited = waiter; + waiter = waiter->next; + + waited->data = NULL; + GF_FREE (waited); + } } -/* - * ioc_inode_update - create a new ioc_inode_t structure and add it to - * the table table. fill in the fields which are derived + +/* + * ioc_inode_update - create a new ioc_inode_t structure and add it to + * the table table. fill in the fields which are derived * from inode_t corresponding to the file - * + * * @table: io-table structure * @inode: inode structure * @@ -155,60 +157,59 @@ ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, ioc_inode_t * ioc_inode_update (ioc_table_t *table, inode_t *inode, uint32_t weight) { - ioc_inode_t *ioc_inode = NULL; + ioc_inode_t *ioc_inode = NULL; - ioc_inode = GF_CALLOC (1, sizeof (ioc_inode_t), - gf_ioc_mt_ioc_inode_t); + ioc_inode = GF_CALLOC (1, sizeof (ioc_inode_t), gf_ioc_mt_ioc_inode_t); if (ioc_inode == NULL) { goto out; } - - ioc_inode->table = table; - INIT_LIST_HEAD (&ioc_inode->cache.page_lru); - ioc_table_lock (table); + ioc_inode->table = table; + INIT_LIST_HEAD (&ioc_inode->cache.page_lru); + + ioc_table_lock (table); - table->inode_count++; - list_add (&ioc_inode->inode_list, &table->inodes); - list_add_tail (&ioc_inode->inode_lru, &table->inode_lru[weight]); + table->inode_count++; + list_add (&ioc_inode->inode_list, &table->inodes); + list_add_tail (&ioc_inode->inode_lru, &table->inode_lru[weight]); - gf_log (table->xl->name, - GF_LOG_TRACE, - "adding to inode_lru[%d]", weight); + gf_log (table->xl->name, + GF_LOG_TRACE, + "adding to inode_lru[%d]", weight); - ioc_table_unlock (table); + ioc_table_unlock (table); + + pthread_mutex_init (&ioc_inode->inode_lock, NULL); + ioc_inode->weight = weight; - pthread_mutex_init (&ioc_inode->inode_lock, NULL); - ioc_inode->weight = weight; - out: - return ioc_inode; + return ioc_inode; } -/* +/* * ioc_inode_destroy - destroy an ioc_inode_t object. * * @inode: inode to destroy * - * to be called only from ioc_forget. + * to be called only from ioc_forget. */ void ioc_inode_destroy (ioc_inode_t *ioc_inode) { - ioc_table_t *table = NULL; + ioc_table_t *table = NULL; table = ioc_inode->table; - ioc_table_lock (table); - table->inode_count--; - list_del (&ioc_inode->inode_list); - list_del (&ioc_inode->inode_lru); - ioc_table_unlock (table); - - ioc_inode_flush (ioc_inode); + ioc_table_lock (table); + table->inode_count--; + list_del (&ioc_inode->inode_list); + list_del (&ioc_inode->inode_lru); + ioc_table_unlock (table); + + ioc_inode_flush (ioc_inode); rbthash_table_destroy (ioc_inode->cache.page_table); - pthread_mutex_destroy (&ioc_inode->inode_lock); - GF_FREE (ioc_inode); + pthread_mutex_destroy (&ioc_inode->inode_lock); + GF_FREE (ioc_inode); } diff --git a/xlators/performance/io-cache/src/ioc-mem-types.h b/xlators/performance/io-cache/src/ioc-mem-types.h index 2cb5ea8782d..08596d5f429 100644 --- a/xlators/performance/io-cache/src/ioc-mem-types.h +++ b/xlators/performance/io-cache/src/ioc-mem-types.h @@ -1,20 +1,20 @@ /* - Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. + Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> + This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see + <http://www.gnu.org/licenses/>. */ #ifndef __IOC_MT_H__ @@ -37,4 +37,3 @@ enum gf_ioc_mem_types_ { gf_ioc_mt_end }; #endif - diff --git a/xlators/performance/io-cache/src/page.c b/xlators/performance/io-cache/src/page.c index 47a8fbb6606..38bb98fbc67 100644 --- a/xlators/performance/io-cache/src/page.c +++ b/xlators/performance/io-cache/src/page.c @@ -40,22 +40,22 @@ ioc_empty (struct ioc_cache *cache) ioc_page_t * ioc_page_get (ioc_inode_t *ioc_inode, off_t offset) { - ioc_page_t *page = NULL; - ioc_table_t *table = NULL; - off_t rounded_offset = 0; + ioc_page_t *page = NULL; + ioc_table_t *table = NULL; + off_t rounded_offset = 0; table = ioc_inode->table; rounded_offset = floor (offset, table->page_size); - + page = rbthash_get (ioc_inode->cache.page_table, &rounded_offset, sizeof (rounded_offset)); if (page != NULL) { - /* push the page to the end of the lru list */ - list_move_tail (&page->page_lru, &ioc_inode->cache.page_lru); - } + /* push the page to the end of the lru list */ + list_move_tail (&page->page_lru, &ioc_inode->cache.page_lru); + } - return page; + return page; } @@ -68,38 +68,38 @@ ioc_page_get (ioc_inode_t *ioc_inode, off_t offset) int64_t ioc_page_destroy (ioc_page_t *page) { - int64_t page_size = 0; + int64_t page_size = 0; - page_size = iobref_size (page->iobref); + page_size = iobref_size (page->iobref); - if (page->waitq) { - /* frames waiting on this page, do not destroy this page */ - page_size = -1; - } else { + if (page->waitq) { + /* frames waiting on this page, do not destroy this page */ + page_size = -1; + } else { rbthash_remove (page->inode->cache.page_table, &page->offset, sizeof (page->offset)); - list_del (&page->page_lru); - - gf_log (page->inode->table->xl->name, GF_LOG_TRACE, - "destroying page = %p, offset = %"PRId64" " - "&& inode = %p", - page, page->offset, page->inode); - - if (page->vector){ - iobref_unref (page->iobref); - GF_FREE (page->vector); - page->vector = NULL; - } - - page->inode = NULL; - } - - if (page_size != -1) { - pthread_mutex_destroy (&page->page_lock); - GF_FREE (page); - } - - return page_size; + list_del (&page->page_lru); + + gf_log (page->inode->table->xl->name, GF_LOG_TRACE, + "destroying page = %p, offset = %"PRId64" " + "&& inode = %p", + page, page->offset, page->inode); + + if (page->vector){ + iobref_unref (page->iobref); + GF_FREE (page->vector); + page->vector = NULL; + } + + page->inode = NULL; + } + + if (page_size != -1) { + pthread_mutex_destroy (&page->page_lock); + GF_FREE (page); + } + + return page_size; } /* @@ -112,69 +112,69 @@ ioc_page_destroy (ioc_page_t *page) int32_t ioc_prune (ioc_table_t *table) { - ioc_inode_t *curr = NULL, *next_ioc_inode = NULL; - ioc_page_t *page = NULL, *next = NULL; - int32_t ret = -1; - int32_t index = 0; - uint64_t size_to_prune = 0; - uint64_t size_pruned = 0; - - ioc_table_lock (table); - { - size_to_prune = table->cache_used - table->cache_size; - /* take out the least recently used inode */ - for (index=0; index < table->max_pri; index++) { - list_for_each_entry_safe (curr, next_ioc_inode, - &table->inode_lru[index], - inode_lru) { - /* prune page-by-page for this inode, till - * we reach the equilibrium */ - ioc_inode_lock (curr); - /* { */ - - list_for_each_entry_safe (page, next, - &curr->cache.page_lru, + ioc_inode_t *curr = NULL, *next_ioc_inode = NULL; + ioc_page_t *page = NULL, *next = NULL; + int32_t ret = -1; + int32_t index = 0; + uint64_t size_to_prune = 0; + uint64_t size_pruned = 0; + + ioc_table_lock (table); + { + size_to_prune = table->cache_used - table->cache_size; + /* take out the least recently used inode */ + for (index=0; index < table->max_pri; index++) { + list_for_each_entry_safe (curr, next_ioc_inode, + &table->inode_lru[index], + inode_lru) { + /* prune page-by-page for this inode, till + * we reach the equilibrium */ + ioc_inode_lock (curr); + /* { */ + + list_for_each_entry_safe (page, next, + &curr->cache.page_lru, page_lru) { - /* done with all pages, and not - * reached equilibrium yet?? - * continue with next inode in - * lru_list */ - size_pruned += page->size; - ret = ioc_page_destroy (page); - - if (ret != -1) - table->cache_used -= ret; - - gf_log (table->xl->name, - GF_LOG_TRACE, - "index = %d && table->cache_" - "used = %"PRIu64" && table->" - "cache_size = %"PRIu64, - index, table->cache_used, - table->cache_size); - - if (size_pruned >= size_to_prune) - break; - } /* list_for_each_entry_safe(page...) */ - if (ioc_empty (&curr->cache)) { - list_del_init (&curr->inode_lru); - } - - /* } */ - ioc_inode_unlock (curr); - - if (size_pruned >= size_to_prune) - break; - } /* list_for_each_entry_safe (curr...) */ - - if (size_pruned >= size_to_prune) - break; - } /* for(index=0;...) */ - - } /* ioc_inode_table locked region end */ - ioc_table_unlock (table); - - return 0; + /* done with all pages, and not + * reached equilibrium yet?? + * continue with next inode in + * lru_list */ + size_pruned += page->size; + ret = ioc_page_destroy (page); + + if (ret != -1) + table->cache_used -= ret; + + gf_log (table->xl->name, + GF_LOG_TRACE, + "index = %d && table->cache_" + "used = %"PRIu64" && table->" + "cache_size = %"PRIu64, + index, table->cache_used, + table->cache_size); + + if (size_pruned >= size_to_prune) + break; + } /* list_for_each_entry_safe(page...) */ + if (ioc_empty (&curr->cache)) { + list_del_init (&curr->inode_lru); + } + + /* } */ + ioc_inode_unlock (curr); + + if (size_pruned >= size_to_prune) + break; + } /* list_for_each_entry_safe (curr...) */ + + if (size_pruned >= size_to_prune) + break; + } /* for(index=0;...) */ + + } /* ioc_inode_table locked region end */ + ioc_table_unlock (table); + + return 0; } /* @@ -187,48 +187,47 @@ ioc_prune (ioc_table_t *table) ioc_page_t * ioc_page_create (ioc_inode_t *ioc_inode, off_t offset) { - ioc_table_t *table = NULL; - ioc_page_t *page = NULL; - off_t rounded_offset = 0; - ioc_page_t *newpage = NULL; + ioc_table_t *table = NULL; + ioc_page_t *page = NULL; + off_t rounded_offset = 0; + ioc_page_t *newpage = NULL; table = ioc_inode->table; rounded_offset = floor (offset, table->page_size); - newpage = GF_CALLOC (1, sizeof (*newpage), - gf_ioc_mt_ioc_newpage_t); + newpage = GF_CALLOC (1, sizeof (*newpage), gf_ioc_mt_ioc_newpage_t); if (newpage == NULL) { goto out; } - if (!ioc_inode) { + if (!ioc_inode) { GF_FREE (newpage); newpage = NULL; goto out; - } + } - newpage->offset = rounded_offset; - newpage->inode = ioc_inode; - pthread_mutex_init (&newpage->page_lock, NULL); + newpage->offset = rounded_offset; + newpage->inode = ioc_inode; + pthread_mutex_init (&newpage->page_lock, NULL); rbthash_insert (ioc_inode->cache.page_table, newpage, &rounded_offset, sizeof (rounded_offset)); - list_add_tail (&newpage->page_lru, &ioc_inode->cache.page_lru); + list_add_tail (&newpage->page_lru, &ioc_inode->cache.page_lru); - page = newpage; + page = newpage; - gf_log ("io-cache", GF_LOG_TRACE, - "returning new page %p", page); + gf_log ("io-cache", GF_LOG_TRACE, + "returning new page %p", page); out: - return page; + return page; } -/* - * ioc_wait_on_page - pause a frame to wait till the arrival of a page. - * here we need to handle the case when the frame who calls wait_on_page - * himself has caused page_fault +/* + * ioc_wait_on_page - pause a frame to wait till the arrival of a page. + * here we need to handle the case when the frame who calls wait_on_page + * himself has caused page_fault * * @page: page to wait on * @frame: call frame who is waiting on page @@ -236,36 +235,38 @@ out: */ void ioc_wait_on_page (ioc_page_t *page, call_frame_t *frame, off_t offset, - size_t size) + size_t size) { - ioc_waitq_t *waitq = NULL; - ioc_local_t *local = frame->local; + ioc_waitq_t *waitq = NULL; + ioc_local_t *local = NULL; - waitq = GF_CALLOC (1, sizeof (*waitq), gf_ioc_mt_ioc_waitq_t); + local = frame->local; + + waitq = GF_CALLOC (1, sizeof (*waitq), gf_ioc_mt_ioc_waitq_t); if (waitq == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; gf_log (frame->this->name, GF_LOG_ERROR, "out of memory"); goto out; - } - - gf_log (frame->this->name, GF_LOG_TRACE, - "frame(%p) waiting on page = %p, offset=%"PRId64", " - "size=%"GF_PRI_SIZET"", - frame, page, offset, size); - - waitq->data = frame; - waitq->next = page->waitq; - waitq->pending_offset = offset; - waitq->pending_size = size; - page->waitq = waitq; - /* one frame can wait only once on a given page, - * local->wait_count is number of pages a frame is waiting on */ - ioc_local_lock (local); - { - local->wait_count++; - } - ioc_local_unlock (local); + } + + gf_log (frame->this->name, GF_LOG_TRACE, + "frame(%p) waiting on page = %p, offset=%"PRId64", " + "size=%"GF_PRI_SIZET"", + frame, page, offset, size); + + waitq->data = frame; + waitq->next = page->waitq; + waitq->pending_offset = offset; + waitq->pending_size = size; + page->waitq = waitq; + /* one frame can wait only once on a given page, + * local->wait_count is number of pages a frame is waiting on */ + ioc_local_lock (local); + { + local->wait_count++; + } + ioc_local_unlock (local); out: return; @@ -273,7 +274,7 @@ out: /* - * ioc_cache_still_valid - see if cached pages ioc_inode are still valid + * ioc_cache_still_valid - see if cached pages ioc_inode are still valid * against given stbuf * * @ioc_inode: @@ -284,64 +285,64 @@ out: int8_t ioc_cache_still_valid (ioc_inode_t *ioc_inode, struct iatt *stbuf) { - int8_t cache_still_valid = 1; + int8_t cache_still_valid = 1; #if 0 - if (!stbuf || (stbuf->ia_mtime != ioc_inode->cache.mtime) || - (stbuf->st_mtim.tv_nsec != ioc_inode->stbuf.st_mtim.tv_nsec)) - cache_still_valid = 0; + if (!stbuf || (stbuf->ia_mtime != ioc_inode->cache.mtime) || + (stbuf->st_mtim.tv_nsec != ioc_inode->stbuf.st_mtim.tv_nsec)) + cache_still_valid = 0; #else - if (!stbuf || (stbuf->ia_mtime != ioc_inode->cache.mtime) + if (!stbuf || (stbuf->ia_mtime != ioc_inode->cache.mtime) || (stbuf->ia_mtime_nsec != ioc_inode->cache.mtime_nsec)) - cache_still_valid = 0; + cache_still_valid = 0; #endif #if 0 - /* talk with avati@gluster.com to enable this section */ - if (!ioc_inode->mtime && stbuf) { - cache_still_valid = 1; - ioc_inode->mtime = stbuf->ia_mtime; - } + /* talk with avati@gluster.com to enable this section */ + if (!ioc_inode->mtime && stbuf) { + cache_still_valid = 1; + ioc_inode->mtime = stbuf->ia_mtime; + } #endif - return cache_still_valid; + return cache_still_valid; } void ioc_waitq_return (ioc_waitq_t *waitq) { - ioc_waitq_t *trav = NULL; - ioc_waitq_t *next = NULL; - call_frame_t *frame = NULL; + ioc_waitq_t *trav = NULL; + ioc_waitq_t *next = NULL; + call_frame_t *frame = NULL; - for (trav = waitq; trav; trav = next) { - next = trav->next; + for (trav = waitq; trav; trav = next) { + next = trav->next; - frame = trav->data; - ioc_frame_return (frame); - GF_FREE (trav); - } + frame = trav->data; + ioc_frame_return (frame); + GF_FREE (trav); + } } int ioc_fault_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, struct iobref *iobref) + int32_t count, struct iatt *stbuf, struct iobref *iobref) { - ioc_local_t *local = NULL; - off_t offset = 0; - ioc_inode_t *ioc_inode = NULL; - ioc_table_t *table = NULL; - ioc_page_t *page = NULL; - int32_t destroy_size = 0; - size_t page_size = 0; - ioc_waitq_t *waitq = NULL; - size_t iobref_page_size = 0; - char zero_filled = 0; + ioc_local_t *local = NULL; + off_t offset = 0; + ioc_inode_t *ioc_inode = NULL; + ioc_table_t *table = NULL; + ioc_page_t *page = NULL; + int32_t destroy_size = 0; + size_t page_size = 0; + ioc_waitq_t *waitq = NULL; + size_t iobref_page_size = 0; + char zero_filled = 0; local = frame->local; offset = local->pending_offset; @@ -351,127 +352,127 @@ ioc_fault_cbk (call_frame_t *frame, void *cookie, xlator_t *this, zero_filled = ((op_ret >=0) && (stbuf->ia_mtime == 0)); - ioc_inode_lock (ioc_inode); - { - if (op_ret == -1 || - !(zero_filled || + ioc_inode_lock (ioc_inode); + { + if (op_ret == -1 || + !(zero_filled || ioc_cache_still_valid(ioc_inode, stbuf))) { - gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, - "cache for inode(%p) is invalid. flushing " - "all pages", ioc_inode); - destroy_size = __ioc_inode_flush (ioc_inode); - } - - if ((op_ret >= 0) && !zero_filled) { - ioc_inode->cache.mtime = stbuf->ia_mtime; + gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, + "cache for inode(%p) is invalid. flushing " + "all pages", ioc_inode); + destroy_size = __ioc_inode_flush (ioc_inode); + } + + if ((op_ret >= 0) && !zero_filled) { + ioc_inode->cache.mtime = stbuf->ia_mtime; ioc_inode->cache.mtime_nsec = stbuf->ia_mtime_nsec; } - gettimeofday (&ioc_inode->cache.tv, NULL); - - if (op_ret < 0) { - /* error, readv returned -1 */ - page = ioc_page_get (ioc_inode, offset); - if (page) - waitq = ioc_page_error (page, op_ret, - op_errno); - } else { - gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, - "op_ret = %d", op_ret); - page = ioc_page_get (ioc_inode, offset); - if (!page) { - /* page was flushed */ - /* some serious bug ? */ - gf_log (this->name, GF_LOG_DEBUG, - "wasted copy: %"PRId64"[+%"PRId64"] " - "ioc_inode=%p", offset, - table->page_size, ioc_inode); - } else { - if (page->vector) { - iobref_unref (page->iobref); - GF_FREE (page->vector); - page->vector = NULL; - } - - /* keep a copy of the page for our cache */ - page->vector = iov_dup (vector, count); + gettimeofday (&ioc_inode->cache.tv, NULL); + + if (op_ret < 0) { + /* error, readv returned -1 */ + page = ioc_page_get (ioc_inode, offset); + if (page) + waitq = ioc_page_error (page, op_ret, + op_errno); + } else { + gf_log (ioc_inode->table->xl->name, GF_LOG_TRACE, + "op_ret = %d", op_ret); + page = ioc_page_get (ioc_inode, offset); + if (!page) { + /* page was flushed */ + /* some serious bug ? */ + gf_log (this->name, GF_LOG_DEBUG, + "wasted copy: %"PRId64"[+%"PRId64"] " + "ioc_inode=%p", offset, + table->page_size, ioc_inode); + } else { + if (page->vector) { + iobref_unref (page->iobref); + GF_FREE (page->vector); + page->vector = NULL; + } + + /* keep a copy of the page for our cache */ + page->vector = iov_dup (vector, count); if (page->vector == NULL) { page = ioc_page_get (ioc_inode, offset); if (page != NULL) waitq = ioc_page_error (page, - -1, + -1, ENOMEM); goto unlock; } - page->count = count; - if (iobref) { - page->iobref = iobref_ref (iobref); - } else { - /* TODO: we have got a response to - * our request and no data */ - gf_log (this->name, GF_LOG_CRITICAL, - "frame>root>rsp_refs is null"); - } /* if(frame->root->rsp_refs) */ - - /* page->size should indicate exactly how - * much the readv call to the child - * translator returned. earlier op_ret - * from child translator was used, which - * gave rise to a bug where reads from - * io-cached volume were resulting in 0 - * byte replies */ - page_size = iov_length(vector, count); - page->size = page_size; + page->count = count; + if (iobref) { + page->iobref = iobref_ref (iobref); + } else { + /* TODO: we have got a response to + * our request and no data */ + gf_log (this->name, GF_LOG_CRITICAL, + "frame>root>rsp_refs is null"); + } /* if(frame->root->rsp_refs) */ + + /* page->size should indicate exactly how + * much the readv call to the child + * translator returned. earlier op_ret + * from child translator was used, which + * gave rise to a bug where reads from + * io-cached volume were resulting in 0 + * byte replies */ + page_size = iov_length(vector, count); + page->size = page_size; iobref_page_size = iobref_size (page->iobref); - if (page->waitq) { - /* wake up all the frames waiting on - * this page, including - * the frame which triggered fault */ - waitq = ioc_page_wakeup (page); - } /* if(page->waitq) */ - } /* if(!page)...else */ - } /* if(op_ret < 0)...else */ - } /* ioc_inode locked region end */ + if (page->waitq) { + /* wake up all the frames waiting on + * this page, including + * the frame which triggered fault */ + waitq = ioc_page_wakeup (page); + } /* if(page->waitq) */ + } /* if(!page)...else */ + } /* if(op_ret < 0)...else */ + } /* ioc_inode locked region end */ unlock: - ioc_inode_unlock (ioc_inode); + ioc_inode_unlock (ioc_inode); - ioc_waitq_return (waitq); + ioc_waitq_return (waitq); - if (iobref_page_size) { - ioc_table_lock (table); - { - table->cache_used += iobref_page_size; - } - ioc_table_unlock (table); - } + if (iobref_page_size) { + ioc_table_lock (table); + { + table->cache_used += iobref_page_size; + } + ioc_table_unlock (table); + } - if (destroy_size) { - ioc_table_lock (table); - { - table->cache_used -= destroy_size; - } - ioc_table_unlock (table); - } + if (destroy_size) { + ioc_table_lock (table); + { + table->cache_used -= destroy_size; + } + ioc_table_unlock (table); + } - if (ioc_need_prune (ioc_inode->table)) { - ioc_prune (ioc_inode->table); - } + if (ioc_need_prune (ioc_inode->table)) { + ioc_prune (ioc_inode->table); + } - gf_log (this->name, GF_LOG_TRACE, "fault frame %p returned", frame); - pthread_mutex_destroy (&local->local_lock); + gf_log (this->name, GF_LOG_TRACE, "fault frame %p returned", frame); + pthread_mutex_destroy (&local->local_lock); - fd_unref (local->fd); + fd_unref (local->fd); - STACK_DESTROY (frame->root); - return 0; + STACK_DESTROY (frame->root); + return 0; } /* * ioc_page_fault - - * + * * @ioc_inode: * @frame: * @fd: @@ -479,15 +480,15 @@ unlock: * */ void -ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, - off_t offset) +ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, + off_t offset) { - ioc_table_t *table = NULL; - call_frame_t *fault_frame = NULL; - ioc_local_t *fault_local = NULL; - int32_t op_ret = -1, op_errno = -1; - ioc_waitq_t *waitq = NULL; - ioc_page_t *page = NULL; + ioc_table_t *table = NULL; + call_frame_t *fault_frame = NULL; + ioc_local_t *fault_local = NULL; + int32_t op_ret = -1, op_errno = -1; + ioc_waitq_t *waitq = NULL; + ioc_page_t *page = NULL; table = ioc_inode->table; fault_frame = copy_frame (frame); @@ -500,7 +501,7 @@ ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, } fault_local = GF_CALLOC (1, sizeof (ioc_local_t), - gf_ioc_mt_ioc_local_t); + gf_ioc_mt_ioc_local_t); if (fault_local == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -510,27 +511,27 @@ ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, goto err; } - /* NOTE: copy_frame() means, the frame the fop whose fd_ref we - * are using till now won't be valid till we get reply from server. - * we unref this fd, in fault_cbk */ - fault_local->fd = fd_ref (fd); - - fault_frame->local = fault_local; - pthread_mutex_init (&fault_local->local_lock, NULL); - - INIT_LIST_HEAD (&fault_local->fill_list); - fault_local->pending_offset = offset; - fault_local->pending_size = table->page_size; - fault_local->inode = ioc_inode; - - gf_log (frame->this->name, GF_LOG_TRACE, - "stack winding page fault for offset = %"PRId64" with " - "frame %p", offset, fault_frame); - - STACK_WIND (fault_frame, ioc_fault_cbk, FIRST_CHILD(fault_frame->this), - FIRST_CHILD(fault_frame->this)->fops->readv, fd, + /* NOTE: copy_frame() means, the frame the fop whose fd_ref we + * are using till now won't be valid till we get reply from server. + * we unref this fd, in fault_cbk */ + fault_local->fd = fd_ref (fd); + + fault_frame->local = fault_local; + pthread_mutex_init (&fault_local->local_lock, NULL); + + INIT_LIST_HEAD (&fault_local->fill_list); + fault_local->pending_offset = offset; + fault_local->pending_size = table->page_size; + fault_local->inode = ioc_inode; + + gf_log (frame->this->name, GF_LOG_TRACE, + "stack winding page fault for offset = %"PRId64" with " + "frame %p", offset, fault_frame); + + STACK_WIND (fault_frame, ioc_fault_cbk, FIRST_CHILD(fault_frame->this), + FIRST_CHILD(fault_frame->this)->fops->readv, fd, table->page_size, offset); - return; + return; err: page = ioc_page_get (ioc_inode, offset); @@ -546,56 +547,56 @@ int32_t ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, size_t size) { - ioc_local_t *local = NULL; - ioc_fill_t *fill = NULL; - off_t src_offset = 0; - off_t dst_offset = 0; - ssize_t copy_size = 0; - ioc_inode_t *ioc_inode = NULL; - ioc_fill_t *new = NULL; - int8_t found = 0; - int32_t ret = 0; + ioc_local_t *local = NULL; + ioc_fill_t *fill = NULL; + off_t src_offset = 0; + off_t dst_offset = 0; + ssize_t copy_size = 0; + ioc_inode_t *ioc_inode = NULL; + ioc_fill_t *new = NULL; + int8_t found = 0; + int32_t ret = 0; local = frame->local; ioc_inode = page->inode; - gf_log (frame->this->name, GF_LOG_TRACE, - "frame (%p) offset = %"PRId64" && size = %"GF_PRI_SIZET" " - "&& page->size = %"GF_PRI_SIZET" && wait_count = %d", - frame, offset, size, page->size, local->wait_count); - - /* immediately move this page to the end of the page_lru list */ - list_move_tail (&page->page_lru, &ioc_inode->cache.page_lru); - /* fill local->pending_size bytes from local->pending_offset */ - if (local->op_ret != -1 && page->size) { - if (offset > page->offset) - /* offset is offset in file, convert it to offset in - * page */ - src_offset = offset - page->offset; - /*FIXME: since offset is the offset within page is the - * else case valid? */ - else - /* local->pending_offset is in previous page. do not - * fill until we have filled all previous pages */ - dst_offset = page->offset - offset; - - /* we have to copy from offset to either end of this page - * or till the requested size */ - copy_size = min (page->size - src_offset, - size - dst_offset); - - if (copy_size < 0) { - /* if page contains fewer bytes and the required offset - is beyond the page size in the page */ - copy_size = src_offset = 0; - } - - gf_log (page->inode->table->xl->name, GF_LOG_TRACE, - "copy_size = %"GF_PRI_SIZET" && src_offset = " - "%"PRId64" && dst_offset = %"PRId64"", - copy_size, src_offset, dst_offset); - - { + gf_log (frame->this->name, GF_LOG_TRACE, + "frame (%p) offset = %"PRId64" && size = %"GF_PRI_SIZET" " + "&& page->size = %"GF_PRI_SIZET" && wait_count = %d", + frame, offset, size, page->size, local->wait_count); + + /* immediately move this page to the end of the page_lru list */ + list_move_tail (&page->page_lru, &ioc_inode->cache.page_lru); + /* fill local->pending_size bytes from local->pending_offset */ + if (local->op_ret != -1 && page->size) { + if (offset > page->offset) + /* offset is offset in file, convert it to offset in + * page */ + src_offset = offset - page->offset; + /*FIXME: since offset is the offset within page is the + * else case valid? */ + else + /* local->pending_offset is in previous page. do not + * fill until we have filled all previous pages */ + dst_offset = page->offset - offset; + + /* we have to copy from offset to either end of this page + * or till the requested size */ + copy_size = min (page->size - src_offset, + size - dst_offset); + + if (copy_size < 0) { + /* if page contains fewer bytes and the required offset + is beyond the page size in the page */ + copy_size = src_offset = 0; + } + + gf_log (page->inode->table->xl->name, GF_LOG_TRACE, + "copy_size = %"GF_PRI_SIZET" && src_offset = " + "%"PRId64" && dst_offset = %"PRId64"", + copy_size, src_offset, dst_offset); + + { new = GF_CALLOC (1, sizeof (*new), gf_ioc_mt_ioc_fill_t); if (new == NULL) { @@ -607,17 +608,17 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, goto out; } - new->offset = page->offset; - new->size = copy_size; - new->iobref = iobref_ref (page->iobref); - new->count = iov_subset (page->vector, - page->count, - src_offset, - src_offset + copy_size, - NULL); - - new->vector = GF_CALLOC (new->count, - sizeof (struct iovec), + new->offset = page->offset; + new->size = copy_size; + new->iobref = iobref_ref (page->iobref); + new->count = iov_subset (page->vector, + page->count, + src_offset, + src_offset + copy_size, + NULL); + + new->vector = GF_CALLOC (new->count, + sizeof (struct iovec), gf_ioc_mt_iovec); if (new->vector == NULL) { local->op_ret = -1; @@ -632,50 +633,50 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, goto out; } - new->count = iov_subset (page->vector, - page->count, - src_offset, - src_offset + copy_size, - new->vector); + new->count = iov_subset (page->vector, + page->count, + src_offset, + src_offset + copy_size, + new->vector); - /* add the ioc_fill to fill_list for this frame */ - if (list_empty (&local->fill_list)) { - /* if list is empty, then this is the first - * time we are filling frame, add the - * ioc_fill_t to the end of list */ - list_add_tail (&new->list, &local->fill_list); - } else { + /* add the ioc_fill to fill_list for this frame */ + if (list_empty (&local->fill_list)) { + /* if list is empty, then this is the first + * time we are filling frame, add the + * ioc_fill_t to the end of list */ + list_add_tail (&new->list, &local->fill_list); + } else { found = 0; - /* list is not empty, we need to look for - * where this offset fits in list */ - list_for_each_entry (fill, &local->fill_list, - list) { - if (fill->offset > new->offset) { - found = 1; - break; - } - } - - if (found) { - list_add_tail (&new->list, - &fill->list); - } else { - list_add_tail (&new->list, - &local->fill_list); - } - } - } - local->op_ret += copy_size; - } + /* list is not empty, we need to look for + * where this offset fits in list */ + list_for_each_entry (fill, &local->fill_list, + list) { + if (fill->offset > new->offset) { + found = 1; + break; + } + } + + if (found) { + list_add_tail (&new->list, + &fill->list); + } else { + list_add_tail (&new->list, + &local->fill_list); + } + } + } + local->op_ret += copy_size; + } out: return ret; } /* - * ioc_frame_unwind - frame unwinds only from here + * ioc_frame_unwind - frame unwinds only from here * * @frame: call frame to unwind * @@ -686,43 +687,43 @@ out: static void ioc_frame_unwind (call_frame_t *frame) { - ioc_local_t *local = NULL; - ioc_fill_t *fill = NULL, *next = NULL; - int32_t count = 0; - struct iovec *vector = NULL; - int32_t copied = 0; - struct iobref *iobref = NULL; - struct iatt stbuf = {0,}; - int32_t op_ret = 0; + ioc_local_t *local = NULL; + ioc_fill_t *fill = NULL, *next = NULL; + int32_t count = 0; + struct iovec *vector = NULL; + int32_t copied = 0; + struct iobref *iobref = NULL; + struct iatt stbuf = {0,}; + int32_t op_ret = 0; local = frame->local; - // ioc_local_lock (local); - frame->local = NULL; - iobref = iobref_new (); + // ioc_local_lock (local); + frame->local = NULL; + iobref = iobref_new (); if (iobref == NULL) { op_ret = -1; gf_log (frame->this->name, GF_LOG_ERROR, "out of memory"); } - if (list_empty (&local->fill_list)) { - gf_log (frame->this->name, GF_LOG_TRACE, - "frame(%p) has 0 entries in local->fill_list " - "(offset = %"PRId64" && size = %"GF_PRI_SIZET")", - frame, local->offset, local->size); - } + if (list_empty (&local->fill_list)) { + gf_log (frame->this->name, GF_LOG_TRACE, + "frame(%p) has 0 entries in local->fill_list " + "(offset = %"PRId64" && size = %"GF_PRI_SIZET")", + frame, local->offset, local->size); + } - list_for_each_entry (fill, &local->fill_list, list) { - count += fill->count; - } + list_for_each_entry (fill, &local->fill_list, list) { + count += fill->count; + } - vector = GF_CALLOC (count, sizeof (*vector), gf_ioc_mt_iovec); + vector = GF_CALLOC (count, sizeof (*vector), gf_ioc_mt_iovec); if (vector == NULL) { op_ret = -1; gf_log (frame->this->name, GF_LOG_ERROR, "out of memory"); } - list_for_each_entry_safe (fill, next, &local->fill_list, list) { + list_for_each_entry_safe (fill, next, &local->fill_list, list) { if ((vector != NULL) && (iobref != NULL)) { memcpy (((char *)vector) + copied, fill->vector, @@ -733,22 +734,22 @@ ioc_frame_unwind (call_frame_t *frame) iobref_merge (iobref, fill->iobref); } - list_del (&fill->list); - iobref_unref (fill->iobref); - GF_FREE (fill->vector); - GF_FREE (fill); - } + list_del (&fill->list); + iobref_unref (fill->iobref); + GF_FREE (fill->vector); + GF_FREE (fill); + } if (op_ret != -1) { op_ret = iov_length (vector, count); } - gf_log (frame->this->name, GF_LOG_TRACE, - "frame(%p) unwinding with op_ret=%d", frame, op_ret); + gf_log (frame->this->name, GF_LOG_TRACE, + "frame(%p) unwinding with op_ret=%d", frame, op_ret); - // ioc_local_unlock (local); + // ioc_local_unlock (local); - STACK_UNWIND_STRICT (readv, frame, op_ret, local->op_errno, vector, + STACK_UNWIND_STRICT (readv, frame, op_ret, local->op_errno, vector, count, &stbuf, iobref); if (iobref != NULL) { @@ -760,8 +761,8 @@ ioc_frame_unwind (call_frame_t *frame) vector = NULL; } - pthread_mutex_destroy (&local->local_lock); - GF_FREE (local); + pthread_mutex_destroy (&local->local_lock); + GF_FREE (local); return; } @@ -775,23 +776,23 @@ ioc_frame_unwind (call_frame_t *frame) void ioc_frame_return (call_frame_t *frame) { - ioc_local_t *local = NULL; - int32_t wait_count = 0; + ioc_local_t *local = NULL; + int32_t wait_count = 0; local = frame->local; GF_ASSERT (local->wait_count > 0); - ioc_local_lock (local); - { - wait_count = --local->wait_count; - } - ioc_local_unlock (local); + ioc_local_lock (local); + { + wait_count = --local->wait_count; + } + ioc_local_unlock (local); - if (!wait_count) { - ioc_frame_unwind (frame); - } + if (!wait_count) { + ioc_frame_unwind (frame); + } - return; + return; } /* @@ -803,28 +804,28 @@ ioc_frame_return (call_frame_t *frame) ioc_waitq_t * ioc_page_wakeup (ioc_page_t *page) { - ioc_waitq_t *waitq = NULL, *trav = NULL; - call_frame_t *frame = NULL; - int32_t ret = -1; + ioc_waitq_t *waitq = NULL, *trav = NULL; + call_frame_t *frame = NULL; + int32_t ret = -1; - waitq = page->waitq; - page->waitq = NULL; + waitq = page->waitq; + page->waitq = NULL; - page->ready = 1; + page->ready = 1; - gf_log (page->inode->table->xl->name, GF_LOG_TRACE, - "page is %p && waitq = %p", page, waitq); + gf_log (page->inode->table->xl->name, GF_LOG_TRACE, + "page is %p && waitq = %p", page, waitq); - for (trav = waitq; trav; trav = trav->next) { - frame = trav->data; - ret = ioc_frame_fill (page, frame, trav->pending_offset, + for (trav = waitq; trav; trav = trav->next) { + frame = trav->data; + ret = ioc_frame_fill (page, frame, trav->pending_offset, trav->pending_size); if (ret == -1) { break; } - } - - return waitq; + } + + return waitq; } @@ -838,39 +839,39 @@ ioc_page_wakeup (ioc_page_t *page) ioc_waitq_t * ioc_page_error (ioc_page_t *page, int32_t op_ret, int32_t op_errno) { - ioc_waitq_t *waitq = NULL, *trav = NULL; - call_frame_t *frame = NULL; - int64_t ret = 0; - ioc_table_t *table = NULL; - ioc_local_t *local = NULL; - - waitq = page->waitq; - page->waitq = NULL; - - gf_log (page->inode->table->xl->name, GF_LOG_DEBUG, - "page error for page = %p & waitq = %p", page, waitq); - - for (trav = waitq; trav; trav = trav->next) { - - frame = trav->data; - - local = frame->local; - ioc_local_lock (local); - { - if (local->op_ret != -1) { - local->op_ret = op_ret; - local->op_errno = op_errno; - } - } - ioc_local_unlock (local); - } - - table = page->inode->table; - ret = ioc_page_destroy (page); - - if (ret != -1) { - table->cache_used -= ret; - } - - return waitq; + ioc_waitq_t *waitq = NULL, *trav = NULL; + call_frame_t *frame = NULL; + int64_t ret = 0; + ioc_table_t *table = NULL; + ioc_local_t *local = NULL; + + waitq = page->waitq; + page->waitq = NULL; + + gf_log (page->inode->table->xl->name, GF_LOG_DEBUG, + "page error for page = %p & waitq = %p", page, waitq); + + for (trav = waitq; trav; trav = trav->next) { + + frame = trav->data; + + local = frame->local; + ioc_local_lock (local); + { + if (local->op_ret != -1) { + local->op_ret = op_ret; + local->op_errno = op_errno; + } + } + ioc_local_unlock (local); + } + + table = page->inode->table; + ret = ioc_page_destroy (page); + + if (ret != -1) { + table->cache_used -= ret; + } + + return waitq; } |