From 77e6caa440fb27d97fc9c6330c3598763c2351f5 Mon Sep 17 00:00:00 2001 From: Venkatesh Somyajulu Date: Wed, 12 Jun 2013 16:59:13 +0530 Subject: libglusterfs: Fix circular buffer to dump entries if count is less than 1024 Problem: To dump the values present in the circular buffer, index always moves from current index to used_len. But if circular buffer is not completely filled even once then next index to be filled and used length value are always same which means it will never dump any value. Fix: Modified the logic of buffer traversing to dump values so that it will still maintain FIFO and cover both the cases where buffer is either partially filled or being used more than once. Change-Id: If73a5e481cca1751d57aba1136c2d25d23ce073c BUG: 972459 Signed-off-by: Venkatesh Somyajulu Reviewed-on: http://review.gluster.org/5197 Reviewed-by: Jeff Darcy Tested-by: Gluster Build System Reviewed-by: Raghavendra Bhat --- libglusterfs/src/circ-buff.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/circ-buff.c b/libglusterfs/src/circ-buff.c index d3d740a41..a48c92879 100644 --- a/libglusterfs/src/circ-buff.c +++ b/libglusterfs/src/circ-buff.c @@ -50,7 +50,7 @@ __cb_add_entry_buffer (buffer_t *buffer, void *item) gf_log_callingfn ("", GF_LOG_WARNING, "getting time of" "the day failed"); buffer->w_index++; - buffer->w_index %= buffer->size_buffer - 1; + buffer->w_index %= buffer->size_buffer; //used_buffer size cannot be greater than the total buffer size if (buffer->used_len < buffer->size_buffer) @@ -90,21 +90,35 @@ void cb_buffer_dump (buffer_t *buffer, void *data, int (fn) (circular_buffer_t *buffer, void *data)) { - int i = 0; + int index = 0; circular_buffer_t *entry = NULL; int entries = 0; + int ul = 0; + int w_ind = 0; + int size_buff = 0; + int i = 0; + + ul = buffer->used_len; + w_ind = buffer->w_index; + size_buff = buffer->size_buffer; pthread_mutex_lock (&buffer->lock); { if (buffer->use_once == _gf_false) { - i = buffer->w_index; + index = (size_buff + (w_ind - ul))%size_buff; for (entries = 0; entries < buffer->used_len; entries++) { - entry = buffer->cb[i]; + entry = buffer->cb[index]; if (entry) fn (entry, data); - i++; - i %= buffer->size_buffer; + else + gf_log_callingfn ("", GF_LOG_WARNING, + "Null entry in " + "circular buffer at " + "index %d.", index); + + index++; + index %= buffer->size_buffer; } } else { for (i = 0; i < buffer->used_len ; i++) { -- cgit