Make Store::n_disks unsigned

Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/011e6cee
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/011e6cee
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/011e6cee

Branch: refs/heads/sphinx-docs
Commit: 011e6cee979166118677b1aabef76422ec9e944d
Parents: e574dd3
Author: James Peach <[email protected]>
Authored: Sat Apr 27 19:39:09 2013 -0700
Committer: James Peach <[email protected]>
Committed: Sat Apr 27 19:44:17 2013 -0700

----------------------------------------------------------------------
 iocore/cache/Cache.cc       |    3 +-
 iocore/cache/I_Store.h      |   15 ++++++----
 iocore/cache/Store.cc       |   59 ++++++++++++++++++++------------------
 iocore/hostdb/MultiCache.cc |   27 ++++++++++-------
 4 files changed, 57 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/011e6cee/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index bc273d3..580d49b 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -597,7 +597,6 @@ CacheProcessor::start_internal(int flags)
   start_internal_flags = flags;
   clear = !!(flags & PROCESSOR_RECONFIGURE) || auto_clear_flag;
   fix = !!(flags & PROCESSOR_FIX);
-  int i;
   start_done = 0;
   int diskok = 1;
 
@@ -610,7 +609,7 @@ CacheProcessor::start_internal(int flags)
   ink_aio_set_callback(new AIO_Callback_handler());
   Span *sd;
   config_volumes.read_config_file();
-  for (i = 0; i < theCacheStore.n_disks; i++) {
+  for (unsigned i = 0; i < theCacheStore.n_disks; i++) {
     sd = theCacheStore.disk[i];
     char path[PATH_NAME_MAX];
     int opts = DEFAULT_CACHE_OPTIONS;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/011e6cee/iocore/cache/I_Store.h
----------------------------------------------------------------------
diff --git a/iocore/cache/I_Store.h b/iocore/cache/I_Store.h
index 55ea839..0188b1d 100644
--- a/iocore/cache/I_Store.h
+++ b/iocore/cache/I_Store.h
@@ -132,22 +132,25 @@ struct Store
   void add(Store & s);
   void dup(Store & s);
   void sort();
-  void extend(int i)
+  void extend(unsigned i)
   {
     if (i > n_disks) {
       disk = (Span **)ats_realloc(disk, i * sizeof(Span *));
-      for (int j = n_disks; j < i; j++)
+      for (unsigned j = n_disks; j < i; j++) {
         disk[j] = NULL;
+      }
       n_disks = i;
     }
   }
 
   // Non Thread-safe operations
-  unsigned int total_blocks(int after = 0) {
+  unsigned int total_blocks(unsigned after = 0) {
     int64_t t = 0;
-    for (int i = after; i < n_disks; i++)
-      if (disk[i])
+    for (unsigned i = after; i < n_disks; i++) {
+      if (disk[i]) {
         t += disk[i]->total_blocks();
+      }
+    }
     return (unsigned int) t;
   }
   // 0 on success -1 on failure
@@ -162,7 +165,7 @@ struct Store
   Store();
   ~Store();
 
-  int n_disks;
+  unsigned n_disks;
   Span **disk;
 
   //

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/011e6cee/iocore/cache/Store.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index eb75feb..9076dc1 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -54,8 +54,9 @@ void
 Store::add(Store & s)
 {
   // assume on different disks
-  for (int i = 0; i < s.n_disks; i++)
+  for (unsigned i = 0; i < s.n_disks; i++) {
     add(s.disk[i]);
+  }
   s.n_disks = 0;
   s.delete_all();
 }
@@ -68,9 +69,9 @@ Store::add(Store & s)
 void
 Store::free(Store & s)
 {
-  for (int i = 0; i < s.n_disks; i++)
+  for (unsigned i = 0; i < s.n_disks; i++) {
     for (Span * sd = s.disk[i]; sd; sd = sd->link.next) {
-      for (int j = 0; j < n_disks; j++)
+      for (unsigned j = 0; j < n_disks; j++)
         for (Span * d = disk[j]; d; d = d->link.next)
           if (!strcmp(sd->pathname, d->pathname)) {
             if (sd->offset < d->offset)
@@ -81,6 +82,7 @@ Store::free(Store & s)
       ink_release_assert(!"Store::free failed");
     Lfound:;
     }
+  }
 }
 
 void
@@ -88,19 +90,18 @@ Store::sort()
 {
   Span **vec = (Span **) alloca(sizeof(Span *) * n_disks);
   memset(vec, 0, sizeof(Span *) * n_disks);
-  int i;
-  for (i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     vec[i] = disk[i];
     disk[i] = NULL;
   }
 
   // sort by device
 
-  int n = 0;
-  for (i = 0; i < n_disks; i++) {
+  unsigned n = 0;
+  for (unsigned i = 0; i < n_disks; i++) {
     for (Span * sd = vec[i]; sd; sd = vec[i]) {
       vec[i] = vec[i]->link.next;
-      for (int d = 0; d < n; d++) {
+      for (unsigned d = 0; d < n; d++) {
         if (sd->disk_id == disk[d]->disk_id) {
           sd->link.next = disk[d];
           disk[d] = sd;
@@ -115,7 +116,7 @@ Store::sort()
 
   // sort by pathname x offset
 
-  for (i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
   Lagain:
     Span * prev = 0;
     for (Span * sd = disk[i]; sd;) {
@@ -141,7 +142,7 @@ Store::sort()
 
   // merge adjacent spans
 
-  for (i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     for (Span * sd = disk[i]; sd;) {
       Span *next = sd->link.next;
       if (next && !strcmp(sd->pathname, next->pathname)) {
@@ -183,9 +184,10 @@ Span::path(char *filename, int64_t * aoffset, char *buf, 
int buflen)
 void
 Store::delete_all()
 {
-  for (int i = 0; i < n_disks; i++)
+  for (unsigned i = 0; i < n_disks; i++) {
     if (disk[i])
       delete disk[i];
+  }
   n_disks = 0;
   ats_free(disk);
   disk = NULL;
@@ -223,7 +225,7 @@ Store::remove(char *n)
 {
   bool found = false;
 Lagain:
-  for (int i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     Span *p = NULL;
     for (Span * sd = disk[i]; sd; sd = sd->link.next) {
       if (!strcmp(n, sd->pathname)) {
@@ -357,7 +359,7 @@ Lfail:;
 int
 Store::write_config_data(int fd)
 {
-  for (int i = 0; i < n_disks; i++)
+  for (unsigned i = 0; i < n_disks; i++)
     for (Span * sd = disk[i]; sd; sd = sd->link.next) {
       char buf[PATH_NAME_MAX + 64];
       snprintf(buf, sizeof(buf), "%s %" PRId64 "\n", sd->pathname, (int64_t) 
sd->blocks * (int64_t) STORE_BLOCK_SIZE);
@@ -772,10 +774,11 @@ Span::init(char *filename, int64_t size)
 void
 Store::normalize()
 {
-  int ndisks = 0;
-  for (int i = 0; i < n_disks; i++)
+  unsigned ndisks = 0;
+  for (unsigned i = 0; i < n_disks; i++) {
     if (disk[i])
       disk[ndisks++] = disk[i];
+  }
   n_disks = ndisks;
 }
 
@@ -821,7 +824,7 @@ Store::spread_alloc(Store & s, unsigned int blocks, bool 
mmapable)
   // Count the eligable disks..
   //
   int mmapable_disks = 0;
-  for (int k = 0; k < n_disks; k++) {
+  for (unsigned k = 0; k < n_disks; k++) {
     if (disk[k]->is_mmapable()) {
       mmapable_disks++;
     }
@@ -838,7 +841,7 @@ Store::spread_alloc(Store & s, unsigned int blocks, bool 
mmapable)
 
   int disks_left = spread_over;
 
-  for (int i = 0; blocks && i < n_disks; i++) {
+  for (unsigned i = 0; blocks && i < n_disks; i++) {
     if (!(mmapable && !disk[i]->is_mmapable())) {
       unsigned int target = blocks / disks_left;
       if (blocks - target > total_blocks(i + 1))
@@ -852,11 +855,10 @@ Store::spread_alloc(Store & s, unsigned int blocks, bool 
mmapable)
 void
 Store::try_realloc(Store & s, Store & diff)
 {
-  int i = 0;
-  for (i = 0; i < s.n_disks; i++) {
+  for (unsigned i = 0; i < s.n_disks; i++) {
     Span *prev = 0;
     for (Span * sd = s.disk[i]; sd;) {
-      for (int j = 0; j < n_disks; j++)
+      for (unsigned j = 0; j < n_disks; j++)
         for (Span * d = disk[j]; d; d = d->link.next)
           if (!strcmp(sd->pathname, d->pathname)) {
             if (sd->offset >= d->offset && (sd->end() <= d->end())) {
@@ -908,7 +910,7 @@ void
 Store::alloc(Store & s, unsigned int blocks, bool one_only, bool mmapable)
 {
   unsigned int oblocks = blocks;
-  for (int i = 0; blocks && i < n_disks; i++) {
+  for (unsigned i = 0; blocks && i < n_disks; i++) {
     if (!(mmapable && !disk[i]->is_mmapable())) {
       blocks -= try_alloc(s, disk[i], blocks, one_only);
       if (one_only && oblocks != blocks)
@@ -960,11 +962,12 @@ Store::write(int fd, char *name)
   if (ink_file_fd_writestring(fd, buf) == -1)
     return (-1);
 
-  for (int i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     int n = 0;
     Span *sd = NULL;
-    for (sd = disk[i]; sd; sd = sd->link.next)
+    for (sd = disk[i]; sd; sd = sd->link.next) {
       n++;
+    }
 
     snprintf(buf, sizeof(buf), "%d\n", n);
     if (ink_file_fd_writestring(fd, buf) == -1)
@@ -1052,8 +1055,7 @@ Store::read(int fd, char *aname)
   if (!disk)
     return -1;
   memset(disk, 0, sizeof(Span *) * n_disks);
-  int i;
-  for (i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     int n = 0;
 
     if (ink_file_fd_readline(fd, PATH_NAME_MAX, buf) <= 0)
@@ -1079,7 +1081,7 @@ Store::read(int fd, char *aname)
   }
   return 0;
 Lbail:
-  for (i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     if (disk[i])
       delete disk[i];
   }
@@ -1101,8 +1103,9 @@ Store::dup(Store & s)
 {
   s.n_disks = n_disks;
   s.disk = (Span **)ats_malloc(sizeof(Span *) * n_disks);
-  for (int i = 0; i < n_disks; i++)
+  for (unsigned i = 0; i < n_disks; i++) {
     s.disk[i] = disk[i]->dup();
+  }
 }
 
 int
@@ -1110,7 +1113,7 @@ Store::clear(char *filename, bool clear_dirs)
 {
   char z[STORE_BLOCK_SIZE];
   memset(z, 0, STORE_BLOCK_SIZE);
-  for (int i = 0; i < n_disks; i++) {
+  for (unsigned i = 0; i < n_disks; i++) {
     Span *ds = disk[i];
     for (int j = 0; j < disk[i]->paths(); j++) {
       char path[PATH_NAME_MAX + 1];

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/011e6cee/iocore/hostdb/MultiCache.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/MultiCache.cc b/iocore/hostdb/MultiCache.cc
index 8548b96..00af859 100644
--- a/iocore/hostdb/MultiCache.cc
+++ b/iocore/hostdb/MultiCache.cc
@@ -57,11 +57,12 @@ store_verify(Store *store)
 {
   if (!store)
     return 0;
-  for (int i = 0; i < store->n_disks; i++)
+  for (unsigned i = 0; i < store->n_disks; i++) {
     for (Span * sd = store->disk[i]; sd; sd = sd->link.next) {
       if (!sd->file_pathname && sd->offset)
         return 0;
     }
+  }
   return 1;
 }
 
@@ -231,7 +232,7 @@ MultiCacheBase::mmap_region(int blocks, int *fds, char 
*cur, bool private_flag,
     return cur;
   int p = 0;
   char *res = 0;
-  for (int i = 0; i < store->n_disks; i++) {
+  for (unsigned i = 0; i < store->n_disks; i++) {
     unsigned int target = blocks / (store->n_disks - i);
     unsigned int following = store->total_blocks(i + 1);
     if (blocks - target > following)
@@ -302,13 +303,12 @@ MultiCacheBase::mmap_data(bool private_flag, bool 
zero_fill)
 {
   int fds[MULTI_CACHE_MAX_FILES] = { 0 };
   int n_fds = 0;
-  int i = 0;
 
   // open files
   //
   if (!store || !store->n_disks)
     goto Lalloc;
-  for (i = 0; i < store->n_disks; i++) {
+  for (unsigned i = 0; i < store->n_disks; i++) {
     Span *ds = store->disk[i];
     for (int j = 0; j < store->disk[i]->paths(); j++) {
       char path[PATH_NAME_MAX + 1];
@@ -430,14 +430,15 @@ MultiCacheBase::mmap_data(bool private_flag, bool 
zero_fill)
   }
 
 
-  for (i = 0; i < n_fds; i++)
+  for (int i = 0; i < n_fds; i++) {
     if (fds[i] >= 0)
       ink_assert(!socketManager.close(fds[i]));
+  }
+
   return 0;
 Lalloc:
   {
-    if (data)
-      free(data);
+    free(data);
     char *cur = 0;
 
     data = (char *)ats_memalign(ats_pagesize(), totalsize);
@@ -451,15 +452,20 @@ Lalloc:
       cur += bytes_to_blocks(heap_size) * STORE_BLOCK_SIZE;
     }
     mapped_header = (MultiCacheHeader *) cur;
-    for (i = 0; i < n_fds; i++)
+    for (int i = 0; i < n_fds; i++) {
       if (fds[i] >= 0)
         socketManager.close(fds[i]);
+    }
+
     return 0;
   }
+
 Labort:
-  for (i = 0; i < n_fds; i++)
+  for (int i = 0; i < n_fds; i++) {
     if (fds[i] >= 0)
       socketManager.close(fds[i]);
+  }
+
   return -1;
 }
 
@@ -1399,8 +1405,7 @@ stealStore(Store & s, int blocks)
   }
   // grab some end portion of some block... so as not to damage the
   // pool header
-  int d = 0;
-  while (d < s.n_disks) {
+  for (unsigned d = 0; d < s.n_disks; ) {
     Span *ds = s.disk[d];
     while (ds) {
       if (!blocks)

Reply via email to